From 2838e47407078ef6ab7653daa54fc39d37921f2b 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. Lustre-change: https://review.whamcloud.com/51863 Lustre-commit: TBD (from 264ab0c258adbce93d582e5e97f05ff7bf87c18a) Signed-off-by: Lei Feng Test-Parameters: trivial testlist=sanityn env=ONLY="71a 71b 71c" Change-Id: I4556b31f0d04bdf8e83f323e83b871b093beaa5e Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52114 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/lov/lov_object.c | 3 ++- lustre/tests/sanityn.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lustre/lov/lov_object.c b/lustre/lov/lov_object.c index 778157d..24daba6 100644 --- a/lustre/lov/lov_object.c +++ b/lustre/lov/lov_object.c @@ -2239,7 +2239,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 d509f78..fb4a7bf 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -3671,6 +3671,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.14.0.98) )) || + skip "Need client version >= 2.14.0.98" + [ $(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