From add0aa8a89f8711c13ebb5f0ca22eaf18f95685c Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Thu, 6 Apr 2023 03:00:45 -0400 Subject: [PATCH] LU-16721 lfs: Fix path2fid segfault This patch fixes segfault when calling path2fid under interactive mode. Before Patch ============ lfs > path2fid /mnt/lustre/a [0x200000401:0x1:0x0] Segmentation fault After Patch ============ $ lfs lfs > path2fid /mnt/lustre/a [0x200000401:0x1:0x0] lfs > path2fid --parent /mnt/lustre/a [0x200000007:0x1:0x0]/a lfs > Testcase sanity/154h added. Test-Parameters: trivial testlist=sanity Signed-off-by: Arshad Hussain Change-Id: I4693e0d476e9e7f570f45fd7a31d275d549245aa Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50557 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- lustre/tests/sanity.sh | 20 ++++++++++++++++++++ lustre/utils/lfs.c | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 0858a23..d8d99db 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -16250,6 +16250,26 @@ test_154g() } run_test 154g "various llapi FID tests" +test_154h() +{ + (( $CLIENT_VERSION >= $(version_code 2.15.55.1) )) || + skip "Need client at least version 2.15.55.1" + + # Create an empty file + touch $DIR/$tfile + + # Get FID (interactive mode) and save under $TMP/$tfile.log + $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log + path2fid $DIR/$tfile + EOF + + fid=$(cat $TMP/$tfile.log) + # $fid should not be empty + [[ ! -z $fid ]] || error "FID is empty" + $LFS rmfid $DIR "$fid" || error "rmfid failed for $fid" +} +run_test 154h "Verify interactive path2fid" + test_155_small_load() { local temp=$TMP/$tfile local file=$DIR/$tfile diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 7c36bdc..4521b77 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -9818,7 +9818,7 @@ static int lfs_path2fid(int argc, char **argv) } rc = 0; - for (path = argv + optind; *path != NULL; path++) { + for (path = argv + optind; optind < argc; path++, optind++) { int err = 0; if (!show_parents) { -- 1.8.3.1