Whamcloud - gitweb
LU-4423 lov: check return value of lov_sub_get()
[fs/lustre-release.git] / lustre / lov / lov_io.c
index 9d62e2c..56e1ba1 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,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, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  *  @{
  */
 
-static inline void lov_sub_enter(struct lov_io_sub *sub)
-{
-        sub->sub_reenter++;
-}
-static inline void lov_sub_exit(struct lov_io_sub *sub)
-{
-        sub->sub_reenter--;
-}
-
 static void lov_io_sub_fini(const struct lu_env *env, struct lov_io *lio,
                             struct lov_io_sub *sub)
 {
         ENTRY;
         if (sub->sub_io != NULL) {
-                if (sub->sub_io_initialized) {
-                        lov_sub_enter(sub);
-                        cl_io_fini(sub->sub_env, sub->sub_io);
-                        lov_sub_exit(sub);
-                        sub->sub_io_initialized = 0;
-                        lio->lis_active_subios--;
-                }
+               if (sub->sub_io_initialized) {
+                       cl_io_fini(sub->sub_env, sub->sub_io);
+                       sub->sub_io_initialized = 0;
+                       lio->lis_active_subios--;
+               }
                 if (sub->sub_stripe == lio->lis_single_subio_index)
                         lio->lis_single_subio_index = -1;
                 else if (!sub->sub_borrowed)
@@ -88,11 +73,15 @@ 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;
                 if (cl_io_is_trunc(io)) {
                         loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
 
@@ -101,6 +90,12 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
                 }
                 break;
         }
+       case CIT_DATA_VERSION: {
+               io->u.ci_data_version.dv_data_version = 0;
+               io->u.ci_data_version.dv_flags =
+                       parent->u.ci_data_version.dv_flags;
+               break;
+       }
         case CIT_FAULT: {
                 struct cl_object *obj = parent->ci_obj;
                 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
@@ -113,7 +108,6 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
        case CIT_FSYNC: {
                io->u.ci_fsync.fi_start = start;
                io->u.ci_fsync.fi_end = end;
-               io->u.ci_fsync.fi_capa = parent->u.ci_fsync.fi_capa;
                io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
                io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
                break;
@@ -121,97 +115,87 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
        case CIT_READ:
        case CIT_WRITE: {
                io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
-                if (cl_io_is_append(parent)) {
-                        io->u.ci_wr.wr_append = 1;
-                } else {
-                        io->u.ci_rw.crw_pos = start;
-                        io->u.ci_rw.crw_count = end - start;
-                }
-                break;
-        }
-        default:
-                break;
-        }
+               if (cl_io_is_append(parent)) {
+                       io->u.ci_wr.wr_append = 1;
+               } else {
+                       io->u.ci_rw.crw_pos = start;
+                       io->u.ci_rw.crw_count = end - start;
+               }
+               break;
+       }
+       case CIT_LADVISE: {
+               io->u.ci_ladvise.li_start = start;
+               io->u.ci_ladvise.li_end = end;
+               io->u.ci_ladvise.li_fid = parent->u.ci_ladvise.li_fid;
+               io->u.ci_ladvise.li_advice = parent->u.ci_ladvise.li_advice;
+               io->u.ci_ladvise.li_flags = parent->u.ci_ladvise.li_flags;
+               break;
+       }
+       default:
+               break;
+       }
 }
 
 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
                            struct lov_io_sub *sub)
 {
-        struct lov_object *lov = lio->lis_object;
-        struct lov_device *ld  = lu2lov_dev(lov2cl(lov)->co_lu.lo_dev);
-        struct cl_io      *sub_io;
-        struct cl_object  *sub_obj;
-        struct cl_io      *io  = lio->lis_cl.cis_io;
-
-        int stripe = sub->sub_stripe;
-        int result;
+       struct lov_object *lov = lio->lis_object;
+       struct cl_io *sub_io;
+       struct cl_object *sub_obj;
+       struct cl_io *io = lio->lis_cl.cis_io;
+       int stripe = sub->sub_stripe;
+       int rc;
 
         LASSERT(sub->sub_io == NULL);
         LASSERT(sub->sub_env == NULL);
         LASSERT(sub->sub_stripe < lio->lis_stripe_count);
         ENTRY;
 
-        result = 0;
+       if (unlikely(lov_r0(lov)->lo_sub[stripe] == NULL))
+               RETURN(-EIO);
+
         sub->sub_io_initialized = 0;
         sub->sub_borrowed = 0;
 
-        if (lio->lis_mem_frozen) {
-               LASSERT(mutex_is_locked(&ld->ld_mutex));
-                sub->sub_io  = &ld->ld_emrg[stripe]->emrg_subio;
-                sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
-                sub->sub_borrowed = 1;
-        } else {
-                void *cookie;
-
-                /* obtain new environment */
-                cookie = cl_env_reenter();
-                sub->sub_env = cl_env_get(&sub->sub_refcheck);
-                cl_env_reexit(cookie);
-                if (IS_ERR(sub->sub_env))
-                        result = PTR_ERR(sub->sub_env);
-
-                if (result == 0) {
-                        /*
-                         * First sub-io. Use ->lis_single_subio to
-                         * avoid dynamic allocation.
-                         */
-                        if (lio->lis_active_subios == 0) {
-                                sub->sub_io = &lio->lis_single_subio;
-                                lio->lis_single_subio_index = stripe;
-                        } else {
-                                OBD_ALLOC_PTR(sub->sub_io);
-                                if (sub->sub_io == NULL)
-                                        result = -ENOMEM;
-                        }
-                }
-        }
+       /* obtain new environment */
+       sub->sub_env = cl_env_get(&sub->sub_refcheck);
+       if (IS_ERR(sub->sub_env))
+               GOTO(fini_lov_io, rc = PTR_ERR(sub->sub_env));
 
-        if (result == 0) {
-                sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
-                sub_io  = sub->sub_io;
-
-                sub_io->ci_obj    = sub_obj;
-                sub_io->ci_result = 0;
-
-                sub_io->ci_parent  = io;
-                sub_io->ci_lockreq = io->ci_lockreq;
-                sub_io->ci_type    = io->ci_type;
-                sub_io->ci_no_srvlock = io->ci_no_srvlock;
-               sub_io->ci_noatime = io->ci_noatime;
-
-                lov_sub_enter(sub);
-                result = cl_io_sub_init(sub->sub_env, sub_io,
-                                        io->ci_type, sub_obj);
-                lov_sub_exit(sub);
-                if (result >= 0) {
-                        lio->lis_active_subios++;
-                        sub->sub_io_initialized = 1;
-                        result = 0;
-                }
-        }
-        if (result != 0)
-                lov_io_sub_fini(env, lio, sub);
-        RETURN(result);
+       /*
+        * First sub-io. Use ->lis_single_subio to
+        * avoid dynamic allocation.
+        */
+       if (lio->lis_active_subios == 0) {
+               sub->sub_io = &lio->lis_single_subio;
+               lio->lis_single_subio_index = stripe;
+       } else {
+               OBD_ALLOC_PTR(sub->sub_io);
+               if (sub->sub_io == NULL)
+                       GOTO(fini_lov_io, rc = -ENOMEM);
+       }
+
+       sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
+       sub_io = sub->sub_io;
+
+       sub_io->ci_obj = sub_obj;
+       sub_io->ci_result = 0;
+       sub_io->ci_parent = io;
+       sub_io->ci_lockreq = io->ci_lockreq;
+       sub_io->ci_type = io->ci_type;
+       sub_io->ci_no_srvlock = io->ci_no_srvlock;
+       sub_io->ci_noatime = io->ci_noatime;
+
+       rc = cl_io_sub_init(sub->sub_env, sub_io, io->ci_type, sub_obj);
+       if (rc >= 0) {
+               lio->lis_active_subios++;
+               sub->sub_io_initialized = 1;
+               rc = 0;
+       }
+fini_lov_io:
+       if (rc != 0)
+               lov_io_sub_fini(env, lio, sub);
+       RETURN(rc);
 }
 
 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
@@ -228,16 +212,11 @@ struct lov_io_sub *lov_sub_get(const struct lu_env *env,
                 rc = lov_io_sub_init(env, lio, sub);
         } else
                 rc = 0;
-        if (rc == 0)
-                lov_sub_enter(sub);
-        else
-                sub = ERR_PTR(rc);
-        RETURN(sub);
-}
 
-void lov_sub_put(struct lov_io_sub *sub)
-{
-        lov_sub_exit(sub);
+       if (rc < 0)
+               sub = ERR_PTR(rc);
+
+       RETURN(sub);
 }
 
 /*****************************************************************************
@@ -248,36 +227,16 @@ void lov_sub_put(struct lov_io_sub *sub)
 
 int lov_page_stripe(const struct cl_page *page)
 {
-       struct lovsub_object *subobj;
        const struct cl_page_slice *slice;
        ENTRY;
 
-       slice = cl_page_at(page, &lovsub_device_type);
+       slice = cl_page_at(page, &lov_device_type);
        LASSERT(slice != NULL);
        LASSERT(slice->cpl_obj != NULL);
 
-       subobj = cl2lovsub(slice->cpl_obj);
-       RETURN(subobj->lso_index);
-}
-
-struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
-                                  const struct cl_page_slice *slice)
-{
-       struct lov_stripe_md *lsm  = lio->lis_object->lo_lsm;
-       struct cl_page       *page = slice->cpl_page;
-       int stripe;
-
-        LASSERT(lio->lis_cl.cis_io != NULL);
-        LASSERT(cl2lov(slice->cpl_obj) == lio->lis_object);
-        LASSERT(lsm != NULL);
-        LASSERT(lio->lis_nr_subios > 0);
-        ENTRY;
-
-        stripe = lov_page_stripe(page);
-        RETURN(lov_sub_get(env, lio, stripe));
+       RETURN(cl2lov_page(slice)->lps_stripe);
 }
 
-
 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
                              struct cl_io *io)
 {
@@ -288,24 +247,25 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
        LASSERT(lio->lis_object != NULL);
        lsm = lio->lis_object->lo_lsm;
 
-        /*
-         * Need to be optimized, we can't afford to allocate a piece of memory
-         * when writing a page. -jay
-         */
-        OBD_ALLOC_LARGE(lio->lis_subs,
-                        lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
-        if (lio->lis_subs != NULL) {
-                lio->lis_nr_subios = lio->lis_stripe_count;
-                lio->lis_single_subio_index = -1;
-                lio->lis_active_subios = 0;
-                result = 0;
-        } else
-                result = -ENOMEM;
-        RETURN(result);
+       /*
+        * Need to be optimized, we can't afford to allocate a piece of memory
+        * when writing a page. -jay
+        */
+       OBD_ALLOC_LARGE(lio->lis_subs,
+                       lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
+       if (lio->lis_subs != NULL) {
+               lio->lis_nr_subios = lio->lis_stripe_count;
+               lio->lis_single_subio_index = -1;
+               lio->lis_active_subios = 0;
+               result = 0;
+       } else
+               result = -ENOMEM;
+
+       RETURN(result);
 }
 
-static void lov_io_slice_init(struct lov_io *lio,
-                              struct lov_object *obj, struct cl_io *io)
+static int lov_io_slice_init(struct lov_io *lio,
+                            struct lov_object *obj, struct cl_io *io)
 {
        ENTRY;
 
@@ -323,6 +283,13 @@ static void lov_io_slice_init(struct lov_io *lio,
                 lio->lis_io_endpos = lio->lis_endpos;
                 if (cl_io_is_append(io)) {
                         LASSERT(io->ci_type == CIT_WRITE);
+
+                       /* If there is LOV EA hole, then we may cannot locate
+                        * the current file-tail exactly. */
+                       if (unlikely(obj->lo_lsm->lsm_pattern &
+                                    LOV_PATTERN_F_HOLE))
+                               RETURN(-EIO);
+
                         lio->lis_pos = 0;
                         lio->lis_endpos = OBD_OBJECT_EOF;
                 }
@@ -336,6 +303,11 @@ static void lov_io_slice_init(struct lov_io *lio,
                 lio->lis_endpos = OBD_OBJECT_EOF;
                 break;
 
+       case CIT_DATA_VERSION:
+               lio->lis_pos = 0;
+               lio->lis_endpos = OBD_OBJECT_EOF;
+               break;
+
         case CIT_FAULT: {
                 pgoff_t index = io->u.ci_fault.ft_index;
                 lio->lis_pos = cl_offset(io->ci_obj, index);
@@ -349,6 +321,12 @@ static void lov_io_slice_init(struct lov_io *lio,
                break;
        }
 
+       case CIT_LADVISE: {
+               lio->lis_pos = io->u.ci_ladvise.li_start;
+               lio->lis_endpos = io->u.ci_ladvise.li_end;
+               break;
+       }
+
         case CIT_MISC:
                 lio->lis_pos = 0;
                 lio->lis_endpos = OBD_OBJECT_EOF;
@@ -358,7 +336,7 @@ static void lov_io_slice_init(struct lov_io *lio,
                 LBUG();
         }
 
-        EXIT;
+       RETURN(0);
 }
 
 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
@@ -367,22 +345,22 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
        struct lov_object *lov = cl2lov(ios->cis_obj);
        int i;
 
-        ENTRY;
-        if (lio->lis_subs != NULL) {
-                for (i = 0; i < lio->lis_nr_subios; i++)
-                        lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
-                OBD_FREE_LARGE(lio->lis_subs,
-                         lio->lis_nr_subios * sizeof lio->lis_subs[0]);
-                lio->lis_nr_subios = 0;
-        }
+       ENTRY;
+       if (lio->lis_subs != NULL) {
+               for (i = 0; i < lio->lis_nr_subios; i++)
+                       lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
+               OBD_FREE_LARGE(lio->lis_subs,
+                        lio->lis_nr_subios * sizeof lio->lis_subs[0]);
+               lio->lis_nr_subios = 0;
+       }
 
-       LASSERT(cfs_atomic_read(&lov->lo_active_ios) > 0);
-       if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
+       LASSERT(atomic_read(&lov->lo_active_ios) > 0);
+       if (atomic_dec_and_test(&lov->lo_active_ios))
                wake_up_all(&lov->lo_waitq);
        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;
@@ -394,10 +372,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;
 
@@ -408,24 +386,35 @@ static int lov_io_iter_init(const struct lu_env *env,
                                            endpos, &start, &end))
                         continue;
 
-                end = lov_offset_mod(end, +1);
-                sub = lov_sub_get(env, lio, stripe);
-                if (!IS_ERR(sub)) {
-                        lov_io_sub_inherit(sub->sub_io, lio, stripe,
-                                           start, end);
-                        rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
-                        lov_sub_put(sub);
-                        CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
-                               stripe, start, end);
-                } else
-                        rc = PTR_ERR(sub);
-
-                if (!rc)
-                        cfs_list_add_tail(&sub->sub_linkage, &lio->lis_active);
-                else
-                        break;
-        }
-        RETURN(rc);
+               if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
+                       if (ios->cis_io->ci_type == CIT_READ ||
+                           ios->cis_io->ci_type == CIT_WRITE ||
+                           ios->cis_io->ci_type == CIT_FAULT)
+                               RETURN(-EIO);
+
+                       continue;
+               }
+
+               end = lov_offset_mod(end, +1);
+               sub = lov_sub_get(env, lio, stripe);
+               if (IS_ERR(sub)) {
+                       rc = PTR_ERR(sub);
+                       break;
+               }
+
+               lov_io_sub_inherit(sub->sub_io, lio, stripe, start, end);
+               rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
+               if (rc != 0)
+                       cl_io_iter_fini(sub->sub_env, sub->sub_io);
+               if (rc != 0)
+                       break;
+
+               CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
+                      stripe, start, end);
+
+               list_add_tail(&sub->sub_linkage, &lio->lis_active);
+       }
+       RETURN(rc);
 }
 
 static int lov_io_rw_iter_init(const struct lu_env *env,
@@ -454,8 +443,8 @@ static int lov_io_rw_iter_init(const struct lu_env *env,
                                               next) - io->u.ci_rw.crw_pos;
                 lio->lis_pos    = io->u.ci_rw.crw_pos;
                 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
-               CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
-                      LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
+               CDEBUG(D_VFSTRACE, "stripe: %llu chunk: [%llu, %llu) "
+                      "%llu\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
                       (__u64)lio->lis_io_endpos);
        }
        /*
@@ -472,13 +461,11 @@ static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
         struct lov_io_sub *sub;
         int rc = 0;
 
-        ENTRY;
-        cfs_list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
-                lov_sub_enter(sub);
-                rc = iofunc(sub->sub_env, sub->sub_io);
-                lov_sub_exit(sub);
-                if (rc)
-                        break;
+       ENTRY;
+       list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
+               rc = iofunc(sub->sub_env, sub->sub_io);
+               if (rc)
+                       break;
 
                if (parent->ci_result == 0)
                        parent->ci_result = sub->sub_io->ci_result;
@@ -533,6 +520,27 @@ static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
         LASSERT(rc == 0);
 }
 
+static void
+lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
+{
+       struct lov_io *lio = cl2lov_io(env, ios);
+       struct cl_io *parent = lio->lis_cl.cis_io;
+       struct lov_io_sub *sub;
+
+       ENTRY;
+       list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
+               lov_io_end_wrapper(env, sub->sub_io);
+
+               parent->u.ci_data_version.dv_data_version +=
+                       sub->sub_io->u.ci_data_version.dv_data_version;
+
+               if (parent->ci_result == 0)
+                       parent->ci_result = sub->sub_io->ci_result;
+       }
+
+       EXIT;
+}
+
 static void lov_io_iter_fini(const struct lu_env *env,
                              const struct cl_io_slice *ios)
 {
@@ -542,8 +550,8 @@ static void lov_io_iter_fini(const struct lu_env *env,
         ENTRY;
         rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
         LASSERT(rc == 0);
-        while (!cfs_list_empty(&lio->lis_active))
-                cfs_list_del_init(lio->lis_active.next);
+       while (!list_empty(&lio->lis_active))
+               list_del_init(lio->lis_active.next);
         EXIT;
 }
 
@@ -558,6 +566,66 @@ 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);
+       if (IS_ERR(sub))
+               return PTR_ERR(sub);
+
+       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);
+
+       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_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
@@ -589,15 +657,14 @@ static int lov_io_submit(const struct lu_env *env,
         if (lio->lis_active_subios == 1) {
                 int idx = lio->lis_single_subio_index;
 
-                LASSERT(idx < lio->lis_nr_subios);
-                sub = lov_sub_get(env, lio, idx);
-                LASSERT(!IS_ERR(sub));
-                LASSERT(sub->sub_io == &lio->lis_single_subio);
-                rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
+               LASSERT(idx < lio->lis_nr_subios);
+               sub = lov_sub_get(env, lio, idx);
+               LASSERT(!IS_ERR(sub));
+               LASSERT(sub->sub_io == &lio->lis_single_subio);
+               rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
                                     crt, queue);
-                lov_sub_put(sub);
-                RETURN(rc);
-        }
+               RETURN(rc);
+       }
 
         LASSERT(lio->lis_subs != NULL);
 
@@ -623,7 +690,6 @@ static int lov_io_submit(const struct lu_env *env,
                if (!IS_ERR(sub)) {
                         rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
                                             crt, cl2q);
-                       lov_sub_put(sub);
                } else {
                        rc = PTR_ERR(sub);
                }
@@ -663,7 +729,6 @@ static int lov_io_commit_async(const struct lu_env *env,
                LASSERT(sub->sub_io == &lio->lis_single_subio);
                rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
                                        from, to, cb);
-               lov_sub_put(sub);
                RETURN(rc);
        }
 
@@ -694,7 +759,6 @@ static int lov_io_commit_async(const struct lu_env *env,
                if (!IS_ERR(sub)) {
                        rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
                                                plist, from, stripe_to, cb);
-                       lov_sub_put(sub);
                } else {
                        rc = PTR_ERR(sub);
                        break;
@@ -724,13 +788,12 @@ static int lov_io_fault_start(const struct lu_env *env,
         struct lov_io      *lio;
         struct lov_io_sub  *sub;
 
-        ENTRY;
-        fio = &ios->cis_io->u.ci_fault;
-        lio = cl2lov_io(env, ios);
-        sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
-        sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
-        lov_sub_put(sub);
-        RETURN(lov_io_start(env, ios));
+       ENTRY;
+       fio = &ios->cis_io->u.ci_fault;
+       lio = cl2lov_io(env, ios);
+       sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
+       sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
+       RETURN(lov_io_start(env, ios));
 }
 
 static void lov_io_fsync_end(const struct lu_env *env,
@@ -742,12 +805,10 @@ static void lov_io_fsync_end(const struct lu_env *env,
        ENTRY;
 
        *written = 0;
-       cfs_list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
+       list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
                struct cl_io *subio = sub->sub_io;
 
-               lov_sub_enter(sub);
                lov_io_end_wrapper(sub->sub_env, subio);
-               lov_sub_exit(sub);
 
                if (subio->ci_result == 0)
                        *written += subio->u.ci_fsync.fi_nr_written;
@@ -784,6 +845,15 @@ static const struct cl_io_operations lov_io_ops = {
                         .cio_start     = lov_io_start,
                         .cio_end       = lov_io_end
                 },
+               [CIT_DATA_VERSION] = {
+                       .cio_fini       = lov_io_fini,
+                       .cio_iter_init  = lov_io_iter_init,
+                       .cio_iter_fini  = lov_io_iter_fini,
+                       .cio_lock       = lov_io_lock,
+                       .cio_unlock     = lov_io_unlock,
+                       .cio_start      = lov_io_start,
+                       .cio_end        = lov_io_data_version_end,
+               },
                 [CIT_FAULT] = {
                         .cio_fini      = lov_io_fini,
                         .cio_iter_init = lov_io_iter_init,
@@ -802,10 +872,20 @@ static const struct cl_io_operations lov_io_ops = {
                        .cio_start     = lov_io_start,
                        .cio_end       = lov_io_fsync_end
                },
+               [CIT_LADVISE] = {
+                       .cio_fini      = lov_io_fini,
+                       .cio_iter_init = lov_io_iter_init,
+                       .cio_iter_fini = lov_io_iter_fini,
+                       .cio_lock      = lov_io_lock,
+                       .cio_unlock    = lov_io_unlock,
+                       .cio_start     = lov_io_start,
+                       .cio_end       = lov_io_end
+               },
                [CIT_MISC] = {
                        .cio_fini      = lov_io_fini
                }
        },
+       .cio_read_ahead                = lov_io_read_ahead,
        .cio_submit                    = lov_io_submit,
        .cio_commit_async              = lov_io_commit_async,
 };
@@ -822,11 +902,18 @@ static void lov_empty_io_fini(const struct lu_env *env,
        struct lov_object *lov = cl2lov(ios->cis_obj);
        ENTRY;
 
-       if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
+       if (atomic_dec_and_test(&lov->lo_active_ios))
                wake_up_all(&lov->lo_waitq);
        EXIT;
 }
 
+static int lov_empty_io_submit(const struct lu_env *env,
+                              const struct cl_io_slice *ios,
+                              enum cl_req_type crt, struct cl_2queue *queue)
+{
+       return -EBADF;
+}
+
 static void lov_empty_impossible(const struct lu_env *env,
                                  struct cl_io_slice *ios)
 {
@@ -873,31 +960,37 @@ static const struct cl_io_operations lov_empty_io_ops = {
                [CIT_FSYNC] = {
                        .cio_fini      = lov_empty_io_fini
                },
+               [CIT_LADVISE] = {
+                       .cio_fini   = lov_empty_io_fini
+               },
                [CIT_MISC] = {
                        .cio_fini      = lov_empty_io_fini
                }
        },
-       .cio_submit                    = LOV_EMPTY_IMPOSSIBLE,
+       .cio_submit                    = lov_empty_io_submit,
        .cio_commit_async              = LOV_EMPTY_IMPOSSIBLE
 };
 
 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
-                      struct cl_io *io)
+                     struct cl_io *io)
 {
-        struct lov_io       *lio = lov_env_io(env);
-        struct lov_object   *lov = cl2lov(obj);
+       struct lov_io       *lio = lov_env_io(env);
+       struct lov_object   *lov = cl2lov(obj);
 
-        ENTRY;
-        CFS_INIT_LIST_HEAD(&lio->lis_active);
-        lov_io_slice_init(lio, lov, io);
-        if (io->ci_result == 0) {
-                io->ci_result = lov_io_subio_init(env, lio, io);
-                if (io->ci_result == 0) {
-                        cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
-                       cfs_atomic_inc(&lov->lo_active_ios);
+       ENTRY;
+       INIT_LIST_HEAD(&lio->lis_active);
+       io->ci_result = lov_io_slice_init(lio, lov, io);
+       if (io->ci_result != 0)
+               RETURN(io->ci_result);
+
+       if (io->ci_result == 0) {
+               io->ci_result = lov_io_subio_init(env, lio, io);
+               if (io->ci_result == 0) {
+                       cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
+                       atomic_inc(&lov->lo_active_ios);
                }
-        }
-        RETURN(io->ci_result);
+       }
+       RETURN(io->ci_result);
 }
 
 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
@@ -917,25 +1010,27 @@ int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
                result = 0;
                break;
        case CIT_FSYNC:
+       case CIT_LADVISE:
        case CIT_SETATTR:
+       case CIT_DATA_VERSION:
                result = +1;
                break;
-        case CIT_WRITE:
-                result = -EBADF;
-                break;
-        case CIT_FAULT:
-                result = -EFAULT;
-                CERROR("Page fault on a file without stripes: "DFID"\n",
-                       PFID(lu_object_fid(&obj->co_lu)));
-                break;
-        }
-        if (result == 0) {
-                cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
-               cfs_atomic_inc(&lov->lo_active_ios);
+       case CIT_WRITE:
+               result = -EBADF;
+               break;
+       case CIT_FAULT:
+               result = -EFAULT;
+               CERROR("Page fault on a file without stripes: "DFID"\n",
+                      PFID(lu_object_fid(&obj->co_lu)));
+               break;
+       }
+       if (result == 0) {
+               cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
+               atomic_inc(&lov->lo_active_ios);
        }
 
        io->ci_result = result < 0 ? result : 0;
-       RETURN(result != 0);
+       RETURN(result);
 }
 
 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
@@ -952,8 +1047,12 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
        switch (io->ci_type) {
        default:
                LASSERTF(0, "invalid type %d\n", io->ci_type);
+               result = -EOPNOTSUPP;
+               break;
        case CIT_MISC:
        case CIT_FSYNC:
+       case CIT_LADVISE:
+       case CIT_DATA_VERSION:
                result = 1;
                break;
        case CIT_SETATTR:
@@ -962,9 +1061,11 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
                 * - in setattr, for truncate
                 */
                /* the truncate is for size > 0 so triggers a restore */
-               if (cl_io_is_trunc(io))
+               if (cl_io_is_trunc(io)) {
                        io->ci_restore_needed = 1;
-               result = -ENODATA;
+                       result = -ENODATA;
+               } else
+                       result = 1;
                break;
        case CIT_READ:
        case CIT_WRITE:
@@ -973,12 +1074,13 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
                result = -ENODATA;
                break;
        }
+
        if (result == 0) {
                cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
-               cfs_atomic_inc(&lov->lo_active_ios);
+               atomic_inc(&lov->lo_active_ios);
        }
 
        io->ci_result = result < 0 ? result : 0;
-       RETURN(result != 0);
+       RETURN(result);
 }
 /** @} lov */