Whamcloud - gitweb
LU-4423 lov: use correct env in lov_io_data_version_end()
[fs/lustre-release.git] / lustre / lov / lov_io.c
index 81fc4c1..7ac4590 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2016, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -365,6 +365,16 @@ static int lov_io_mirror_init(struct lov_io *lio, struct lov_object *obj,
                       PFID(lu_object_fid(lov2lu(obj))),
                       lio->lis_pos, lio->lis_endpos);
 
+               if (cl_io_is_trunc(io)) {
+                       /**
+                        * for truncate, we uses [size, EOF) to judge whether
+                        * a write intent needs to be send, but we need to
+                        * restore the write extent to [0, size).
+                        */
+                       io->ci_write_intent.e_start = 0;
+                       io->ci_write_intent.e_end =
+                                       io->u.ci_setattr.sa_attr.lvb_size;
+               }
                /* stop cl_io_init() loop */
                RETURN(1);
        }
@@ -449,7 +459,6 @@ static int lov_io_mirror_init(struct lov_io *lio, struct lov_object *obj,
 static int lov_io_slice_init(struct lov_io *lio,
                             struct lov_object *obj, struct cl_io *io)
 {
-       struct lu_extent ext;
        int index;
        int result = 0;
        ENTRY;
@@ -539,21 +548,20 @@ static int lov_io_slice_init(struct lov_io *lio,
              (cl_io_is_trunc(io) && io->u.ci_setattr.sa_attr.lvb_size > 0)))
                GOTO(out, result = 0);
 
-       ext.e_start = lio->lis_pos;
-       ext.e_end = lio->lis_endpos;
-
        /* for truncate, it only needs to instantiate the components
         * before the truncated size. */
        if (cl_io_is_trunc(io)) {
-               ext.e_start = 0;
-               ext.e_end = io->u.ci_setattr.sa_attr.lvb_size;
+               io->ci_write_intent.e_start = 0;
+               io->ci_write_intent.e_end = io->u.ci_setattr.sa_attr.lvb_size;
+       } else {
+               io->ci_write_intent.e_start = lio->lis_pos;
+               io->ci_write_intent.e_end = lio->lis_endpos;
        }
 
        index = 0;
-       lov_foreach_io_layout(index, lio, &ext) {
+       lov_foreach_io_layout(index, lio, &io->ci_write_intent) {
                if (!lsm_entry_inited(obj->lo_lsm, index)) {
                        io->ci_need_write_intent = 1;
-                       io->ci_write_intent = ext;
                        break;
                }
        }
@@ -948,7 +956,7 @@ lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
        list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
                struct cl_data_version_io *sdv = &sub->sub_io.u.ci_data_version;
 
-               lov_io_end_wrapper(env, &sub->sub_io);
+               lov_io_end_wrapper(sub->sub_env, &sub->sub_io);
 
                pdv->dv_data_version += sdv->dv_data_version;
                if (pdv->dv_layout_version > sdv->dv_layout_version)