From 225e7b8c70fb68bc3aa3a6d88c5e9bda322c9cc9 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Thu, 30 May 2019 22:46:09 +0800 Subject: [PATCH] LU-12361 lov: fix wrong calculated length for fiemap 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 Reviewed-on: https://review.whamcloud.com/34998 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Gu Zheng Reviewed-by: Oleg Drokin --- lustre/lov/lov_object.c | 4 ++-- lustre/lov/lov_offset.c | 2 ++ lustre/tests/sanity.sh | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lustre/lov/lov_object.c b/lustre/lov/lov_object.c index 884f744..08e9dd1 100644 --- a/lustre/lov/lov_object.c +++ b/lustre/lov/lov_object.c @@ -1691,7 +1691,7 @@ int fiemap_for_stripe(const struct lu_env *env, struct cl_object *obj, 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; @@ -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; - 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; diff --git a/lustre/lov/lov_offset.c b/lustre/lov/lov_offset.c index 6ed52e2..0c9d668 100644 --- a/lustre/lov/lov_offset.c +++ b/lustre/lov/lov_offset.c @@ -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. + * + * 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) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 6522197..bac8c63 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -21163,6 +21163,15 @@ test_813() { } 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 # -- 1.8.3.1