From c00e72b938c2f927d91f21acae5943aa4b214898 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sat, 4 Nov 2023 23:44:02 -0600 Subject: [PATCH] LU-17263 utils: 'lfs find -size' to use 512-byte units Change the 'lfs find -size' argument to 512-byte blocks by default if no unit is given. This better matches find(1) and avoids confusion when converting "find" arguments to "lfs find". Accept the 'c' suffix like find(1) to specify a number of characters (bytes). Most users/scripts will specify a unit, so it is expected not to cause significant upset with this change. Signed-off-by: Andreas Dilger Change-Id: I3124e667acc06928f41a3d3006e1d9b4a43ebbe5 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52994 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Anjus George Reviewed-by: Oleg Drokin --- lustre/doc/lfs-find.1 | 3 ++- lustre/tests/sanity.sh | 32 ++++++++++++++++---------------- lustre/utils/lfs.c | 1 + 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lustre/doc/lfs-find.1 b/lustre/doc/lfs-find.1 index d9f8726..bfd7f3d 100644 --- a/lustre/doc/lfs-find.1 +++ b/lustre/doc/lfs-find.1 @@ -422,7 +422,8 @@ instantiated component. File has specified numeric project ID. .TP .BR --size | -s -File size is \fIn\fR bytes, or \fBK\fRibi-, \fBM\fRebi-, +File size is \fIn\fR 512-byte blocks (if no unit is given), or +\fIn\fR \fBc\fRhars (bytes), \fBK\fRibi-, \fBM\fRebi-, \fBG\fRibi-, \fBT\fRebi-, \fBP\fRebi-, or \fBE\fRbi-bytes if a suffix is given. .TP diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index d99d0b6..3dd3351 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -7112,21 +7112,21 @@ test_56r() { echo "test" > $dir/$tfile echo "test2" > $dir/$tfile.2 && sync expected=1 - cmd="$LFS find -size 5 -type f -lazy $dir" + cmd="$LFS find -size 5c -type f -lazy $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" - cmd="$LFS find -size 5 -type f $dir" + cmd="$LFS find -size 5c -type f $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" expected=1 - cmd="$LFS find -size +5 -type f -lazy $dir" + cmd="$LFS find -size +5c -type f -lazy $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" - cmd="$LFS find -size +5 -type f $dir" + cmd="$LFS find -size +5c -type f $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" @@ -7142,21 +7142,21 @@ test_56r() { error "'$cmd' wrong: found $nums, expected $expected" expected=2 - cmd="$LFS find ! -size -5 -type f -lazy $dir" + cmd="$LFS find ! -size -5c -type f -lazy $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" - cmd="$LFS find ! -size -5 -type f $dir" + cmd="$LFS find ! -size -5c -type f $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" expected=12 - cmd="$LFS find -size -5 -type f -lazy $dir" + cmd="$LFS find -size -5c -type f -lazy $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" - cmd="$LFS find -size -5 -type f $dir" + cmd="$LFS find -size -5c -type f $dir" nums=$($cmd | wc -l) [ $nums -eq $expected ] || error "'$cmd' wrong: found $nums, expected $expected" @@ -7218,17 +7218,17 @@ test_56ra() { cancel_lru_locks $OSC cat $dir/$tfile $dir/$tfile.2 > /dev/null - test_56ra_sub 1 0 "$LFS find -size 5 -type f -lazy $dir" - test_56ra_sub 1 14 "$LFS find -size 5 -type f $dir" - test_56ra_sub 1 0 "$LFS find -size +5 -type f -lazy $dir" - test_56ra_sub 1 14 "$LFS find -size +5 -type f $dir" + test_56ra_sub 1 0 "$LFS find -size 5c -type f -lazy $dir" + test_56ra_sub 1 14 "$LFS find -size 5c -type f $dir" + test_56ra_sub 1 0 "$LFS find -size +5c -type f -lazy $dir" + test_56ra_sub 1 14 "$LFS find -size +5c -type f $dir" test_56ra_sub 2 0 "$LFS find -size +0 -type f -lazy $dir" test_56ra_sub 2 14 "$LFS find -size +0 -type f $dir" - test_56ra_sub 2 0 "$LFS find ! -size -5 -type f -lazy $dir" - test_56ra_sub 2 14 "$LFS find ! -size -5 -type f $dir" - test_56ra_sub 12 0 "$LFS find -size -5 -type f -lazy $dir" - test_56ra_sub 12 14 "$LFS find -size -5 -type f $dir" + test_56ra_sub 2 0 "$LFS find ! -size -5c -type f -lazy $dir" + test_56ra_sub 2 14 "$LFS find ! -size -5c -type f $dir" + test_56ra_sub 12 0 "$LFS find -size -5c -type f -lazy $dir" + test_56ra_sub 12 14 "$LFS find -size -5c -type f $dir" } run_test 56ra "check lfs find -size -lazy works for data on OSTs" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index c81df64..c212c5e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -5880,6 +5880,7 @@ err_free: optarg++; } + param.fp_size_units = 512; ret = llapi_parse_size(optarg, ¶m.fp_size, ¶m.fp_size_units, 0); if (ret) { -- 1.8.3.1