From: Thomas Bertschinger Date: Tue, 31 Oct 2023 19:59:18 +0000 (-0600) Subject: LU-17245 utils: fix lfs error messages with multiple paths X-Git-Tag: 2.15.60~10 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=0d5f685d036c32f47cf837c1fb0894a41212898f;p=fs%2Flustre-release.git LU-17245 utils: fix lfs error messages with multiple paths When using some lfs utilities (find, getstripe) with multiple paths, if a subset of the paths has an error, for example due to a typo, the error message produced can be misleading. For "getstripe" it refers to the last file on the command line regardless of which file had the error, and for "find" it prints out the right filename but uses the error code from the last file on the command line. This cleans up these error messages for "lfs find" and "lfs getstripe". This also adjusts "lfs setdirstripe" to continue for subsequent files if it encounters an error for earlier files on the command line. Signed-off-by: Thomas Bertschinger Fixes: bc500536b6dd ("LU-930 utils: fix 'lfs find' error message") Fixes: 4affa48f676b ("LU-5170 utils: Continue on error when multiple files requested") Fixes: a24f61532927 ("LU-11213 dne: add new dir hash type "space"") Change-Id: I9cdd007912ffb4f6ebc31e422851977e49186ae7 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52942 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index ced10df..c5c00df 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -1799,6 +1799,11 @@ test_27ga() { $LFS getstripe -m $DIR/$tdir/$tfile $DIR/$tdir/$tfile.2 local rc=$? (( rc == 2 )) || error "getstripe did not return ENOENT" + + local err_msg=$($LFS getstripe $DIR/$tdir/typo $DIR/$tdir/$tfile \ + 2>&1 > /dev/null) + [[ $err_msg =~ "typo" ]] || + error "expected message with correct filename, got '$err_msg'" } run_test 27ga "$LFS getstripe with missing file (should return error)" @@ -8979,6 +8984,7 @@ test_56ef() { local dir1=$dir/d1 local dir2=$dir/d2 local nfiles + local err_msg test_mkdir -p $dir @@ -8999,6 +9005,10 @@ test_56ef() { nfiles=$($LFS find -type f $dir1 $dir2 | wc -l) (( $nfiles == 2 )) || error "(3) lfs find expected 2 files, got $nfiles" + + err_msg=$($LFS find $dir1/typo $dir1/f 2>&1 > /dev/null) + [[ $err_msg =~ "No such file or directory" ]] || + error "expected standard error message, got: '$err_msg'" } run_test 56ef "lfs find with multiple paths" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index c212c5e..42e03b0 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -5225,7 +5225,6 @@ static int lfs_find(int argc, char **argv) int optidx = 0; int pathstart = -1; int pathend = -1; - int pathbad = -1; int neg_opt = 0; time_t *xtime; int *xsign; @@ -6027,16 +6026,15 @@ err_free: do { rc = llapi_find(argv[pathstart], ¶m); - if (rc && !ret) { - ret = rc; - pathbad = pathstart; + if (rc) { + if (!ret) + ret = rc; + + fprintf(stderr, "%s: failed for '%s': %s\n", + progname, argv[pathstart], strerror(-rc)); } } while (++pathstart < pathend); - if (ret) - fprintf(stderr, "%s: failed for '%s': %s\n", - progname, argv[pathbad], strerror(-rc)); - err: if (param.fp_obd_uuid && param.fp_num_alloc_obds) free(param.fp_obd_uuid); @@ -6454,7 +6452,7 @@ static int lfs_getstripe_internal(int argc, char **argv, rc2 = llapi_getstripe(argv[pathstart], param); if (rc2) { fprintf(stderr, "%s: %s for '%s' failed: %s\n", - progname, argv[0], argv[optind - 1], + progname, argv[0], argv[pathstart], strerror(-rc2)); if (!rc) rc = rc2; @@ -7383,7 +7381,7 @@ static int lfs_setdirstripe(int argc, char **argv) fprintf(stderr, "%s setdirstripe: cannot create dir '%s': %s\n", progname, dname, strerror(-result)); - } while (!result && (dname = argv[++optind])); + } while ((dname = argv[++optind])); if (mode_opt) umask(previous_mode);