Whamcloud - gitweb
LU-12361 lov: fix wrong calculated length for fiemap 98/34998/3
authorWang Shilong <wshilong@ddn.com>
Thu, 30 May 2019 14:46:09 +0000 (22:46 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 4 Jun 2019 05:27:23 +0000 (05:27 +0000)
lov_stripe_intersects() will return a closed interval
[@obd_start, @obd_end], so to calcuate length of interval we need

 @obd_end - @obd_start + 1

rather than

 @obd_end - @obd_start

Wrong extent length will make us return wrong fiemap information.

Change-Id: I30deb17cf5fa80a6d3046098fbac0d3faa01ad1c
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/34998
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Gu Zheng <gzheng@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/lov/lov_object.c
lustre/lov/lov_offset.c
lustre/tests/sanity.sh

index 884f744..08e9dd1 100644 (file)
@@ -1691,7 +1691,7 @@ int fiemap_for_stripe(const struct lu_env *env, struct cl_object *obj,
        if (lun_start == lun_end)
                return 0;
 
        if (lun_start == lun_end)
                return 0;
 
-       req_fm_len = obd_object_end - lun_start;
+       req_fm_len = obd_object_end - lun_start + 1;
        fs->fs_fm->fm_length = 0;
        len_mapped_single_call = 0;
 
        fs->fs_fm->fm_length = 0;
        len_mapped_single_call = 0;
 
@@ -1734,7 +1734,7 @@ int fiemap_for_stripe(const struct lu_env *env, struct cl_object *obj,
                        fs->fs_fm->fm_mapped_extents = 1;
 
                        fm_ext[0].fe_logical = lun_start;
                        fs->fs_fm->fm_mapped_extents = 1;
 
                        fm_ext[0].fe_logical = lun_start;
-                       fm_ext[0].fe_length = obd_object_end - lun_start;
+                       fm_ext[0].fe_length = obd_object_end - lun_start + 1;
                        fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
 
                        goto inactive_tgt;
                        fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
 
                        goto inactive_tgt;
index 6ed52e2..0c9d668 100644 (file)
@@ -237,6 +237,8 @@ loff_t lov_size_to_stripe(struct lov_stripe_md *lsm, int index, u64 file_size,
  * given an extent in an lov and a stripe, calculate the extent of the stripe
  * that is contained within the lov extent.  this returns true if the given
  * stripe does intersect with the lov extent.
  * given an extent in an lov and a stripe, calculate the extent of the stripe
  * that is contained within the lov extent.  this returns true if the given
  * stripe does intersect with the lov extent.
+ *
+ * Closed interval [@obd_start, @obd_end] will be returned.
  */
 int lov_stripe_intersects(struct lov_stripe_md *lsm, int index, int stripeno,
                          struct lu_extent *ext, u64 *obd_start, u64 *obd_end)
  */
 int lov_stripe_intersects(struct lov_stripe_md *lsm, int index, int stripeno,
                          struct lu_extent *ext, u64 *obd_start, u64 *obd_end)
index 6522197..bac8c63 100755 (executable)
@@ -21163,6 +21163,15 @@ test_813() {
 }
 run_test 813 "File heat verfication"
 
 }
 run_test 813 "File heat verfication"
 
+test_814()
+{
+       dd of=$DIR/$tfile seek=128 bs=1k < /dev/null
+       echo -n y >> $DIR/$tfile
+       cp --sparse=always $DIR/$tfile $DIR/${tfile}.cp || error "copy failed"
+       diff $DIR/$tfile $DIR/${tfile}.cp || error "files should be same"
+}
+run_test 814 "sparse cp works as expected (LU-12361)"
+
 #
 # tests that do cleanup/setup should be run at the end
 #
 #
 # tests that do cleanup/setup should be run at the end
 #