From b1739ba3fadcc7cf0f330f6984bd51d3d801247d Mon Sep 17 00:00:00 2001 From: Lei Feng Date: Thu, 3 Aug 2023 17:44:15 +0800 Subject: [PATCH] LU-17013 lov: fill FIEMAP_EXTENT_LAST flag If file has N extents and get the fiemap with exactly N extent slots, the last extent will miss FIEMAP_EXTENT_LAST flag. Fix it. Signed-off-by: Lei Feng Test-Parameters: testlist=sanityn env=ONLY=71a+71b+71c Change-Id: I4556b31f0d04bdf8e83f323e83b871b093beaa5e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51863 Tested-by: Maloo Tested-by: jenkins Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Zhenyu Xu --- lustre/lov/lov_object.c | 3 ++- lustre/tests/sanityn.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lustre/lov/lov_object.c b/lustre/lov/lov_object.c index 82673f3..1aeb6a8 100644 --- a/lustre/lov/lov_object.c +++ b/lustre/lov/lov_object.c @@ -2188,7 +2188,8 @@ finish: cur_ext = 0; /* done all the processing */ - if (entry > end_entry) + if (entry > end_entry || + (fs.fs_enough && fs.fs_finish_stripe && entry == end_entry)) fiemap->fm_extents[cur_ext].fe_flags |= FIEMAP_EXTENT_LAST; /* Indicate that we are returning device offsets unless file just has diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index fb77297..f7230e4 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -1464,7 +1464,7 @@ test_33d() { touch $DIR/$tdir/d1/tgt" \ "ln $DIR2/$tdir/d1/tgt $DIR2/$tdir/d2/src" fi - + op_trigger_cos "remote directory create" "$LFS mkdir -i 0 $DIR/$tdir" \ "$LFS mkdir -i 1 $DIR2/$tdir/subdir" op_trigger_cos "cross-MDT rename" \ @@ -3858,6 +3858,47 @@ test_71b() { } run_test 71b "check fiemap support for stripecount > 1" +_check_last_flag_with_filefrag() +{ + local file=$1 + local count=$2 + local i + local offset + + echo "check last flag for file with $count extents" + rm -f $file + for ((i=0; i<$count; i++)); do + offset=$((i * 256)) + dd if=/dev/zero of=$file bs=4K count=1 seek=$offset 2> /dev/null + done + + filefrag -s -v $file | grep "last" || + error "test file with $i extents failed" + + rm -f $file +} + +test_71c() { + local file="$DIR1/$tdir/$tfile" + + (( $CLIENT_VERSION >= $(version_code 2.15.57) )) || + skip "Need client version >= 2.15.57" + [ $(facet_fstype ost1) = "ldiskfs" ] || + skip "support only ldiskfs ost" + filefrag -V | grep wc || + skip "need whamcloud version of e2fsprogs" + + mkdir -p $DIR1/$tdir + + # filefrag uses u64[2028] buffer to fetch fiemap. The number of extents + # in the buffer is (8 * 2048 - 32) / 56 = 292. Test file with 291, 292 + # and 293 extents + _check_last_flag_with_filefrag $file 291 + _check_last_flag_with_filefrag $file 292 + _check_last_flag_with_filefrag $file 293 +} +run_test 71c "check FIEMAP_EXTENT_LAST flag with different extents number" + test_72() { local p="$TMP/sanityN-$TESTNAME.parameters" local tlink1 -- 1.8.3.1