Whamcloud - gitweb
LU-5478 lustre: get rid of obd_* typedefs
[fs/lustre-release.git] / lustre / lov / lov_io.c
index bdb8140..b8edb13 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -88,11 +88,16 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
        struct lov_stripe_md *lsm    = lio->lis_object->lo_lsm;
        struct cl_io         *parent = lio->lis_cl.cis_io;
 
-        switch(io->ci_type) {
-        case CIT_SETATTR: {
-                io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
-                io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
-                io->u.ci_setattr.sa_capa = parent->u.ci_setattr.sa_capa;
+       switch (io->ci_type) {
+       case CIT_SETATTR: {
+               io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
+               io->u.ci_setattr.sa_attr_flags =
+                       parent->u.ci_setattr.sa_attr_flags;
+               io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
+               io->u.ci_setattr.sa_stripe_index = stripe;
+               io->u.ci_setattr.sa_parent_fid =
+                                       parent->u.ci_setattr.sa_parent_fid;
+               io->u.ci_setattr.sa_capa = parent->u.ci_setattr.sa_capa;
                 if (cl_io_is_trunc(io)) {
                         loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
 
@@ -390,7 +395,7 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
        EXIT;
 }
 
-static obd_off lov_offset_mod(obd_off val, int delta)
+static loff_t lov_offset_mod(loff_t val, int delta)
 {
         if (val != OBD_OBJECT_EOF)
                 val += delta;
@@ -402,10 +407,10 @@ static int lov_io_iter_init(const struct lu_env *env,
 {
        struct lov_io        *lio = cl2lov_io(env, ios);
        struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
-        struct lov_io_sub    *sub;
-        obd_off endpos;
-        obd_off start;
-        obd_off end;
+       struct lov_io_sub    *sub;
+       loff_t endpos;
+       loff_t start;
+       loff_t end;
         int stripe;
         int rc = 0;
 
@@ -575,6 +580,65 @@ static void lov_io_unlock(const struct lu_env *env,
         EXIT;
 }
 
+static int lov_io_read_ahead(const struct lu_env *env,
+                            const struct cl_io_slice *ios,
+                            pgoff_t start, struct cl_read_ahead *ra)
+{
+       struct lov_io           *lio = cl2lov_io(env, ios);
+       struct lov_object       *loo = lio->lis_object;
+       struct cl_object        *obj = lov2cl(loo);
+       struct lov_layout_raid0 *r0 = lov_r0(loo);
+       struct lov_io_sub       *sub;
+       loff_t                   suboff;
+       pgoff_t                  ra_end;
+       unsigned int             pps; /* pages per stripe */
+       int                      stripe;
+       int                      rc;
+       ENTRY;
+
+       stripe = lov_stripe_number(loo->lo_lsm, cl_offset(obj, start));
+       if (unlikely(r0->lo_sub[stripe] == NULL))
+               RETURN(-EIO);
+
+       sub = lov_sub_get(env, lio, stripe);
+
+       lov_stripe_offset(loo->lo_lsm, cl_offset(obj, start), stripe, &suboff);
+       rc = cl_io_read_ahead(sub->sub_env, sub->sub_io,
+                             cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
+                             ra);
+       lov_sub_put(sub);
+
+       CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
+              PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
+       if (rc != 0)
+               RETURN(rc);
+
+       /**
+        * Adjust the stripe index by layout of raid0. ra->cra_end is the maximum
+        * page index covered by an underlying DLM lock.
+        * This function converts cra_end from stripe level to file level, and
+        * make sure it's not beyond stripe boundary.
+        */
+       if (r0->lo_nr == 1) /* single stripe file */
+               RETURN(0);
+
+       /* cra_end is stripe level, convert it into file level */
+       ra_end = ra->cra_end;
+       if (ra_end != CL_PAGE_EOF)
+               ra_end = lov_stripe_pgoff(loo->lo_lsm, ra_end, stripe);
+
+       pps = loo->lo_lsm->lsm_stripe_size >> PAGE_CACHE_SHIFT;
+
+       CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, "
+              "stripe_size = %u, stripe no = %u, start index = %lu\n",
+              PFID(lu_object_fid(lov2lu(loo))), ra_end, pps,
+              loo->lo_lsm->lsm_stripe_size, stripe, start);
+
+       /* never exceed the end of the stripe */
+       ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
+       RETURN(0);
+}
+
 /**
  * lov implementation of cl_operations::cio_submit() method. It takes a list
  * of pages in \a queue, splits it into per-stripe sub-lists, invokes
@@ -823,6 +887,7 @@ static const struct cl_io_operations lov_io_ops = {
                        .cio_fini      = lov_io_fini
                }
        },
+       .cio_read_ahead                = lov_io_read_ahead,
        .cio_submit                    = lov_io_submit,
        .cio_commit_async              = lov_io_commit_async,
 };