Whamcloud - gitweb
EX-7013 lipe: printf formats added to lipe_find3
authorAlexandre Ioffe <aioffe@ddn.com>
Thu, 16 Mar 2023 07:25:39 +0000 (00:25 -0700)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 21 Mar 2023 20:58:10 +0000 (20:58 +0000)
Printf formats added to lipe_find3: fid, mirror-count,
stripe-count. Sanity-lipe-find3 updated with printf
format tests

Test-Parameters: trivial testlist=sanity-lipe-find3,sanity-lipe-scan3
Signed-off-by: Alexandre Ioffe <aioffe@ddn.com>
Change-Id: Ic5b0d6786c705e51d809eba19e123287d2794740
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50313
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Colin Faber <cfaber@ddn.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/man/lipe_find3.1
lipe/src/lipe_find3/lf3_parse_format.c
lustre/tests/sanity-lipe-find3.sh

index 281aeb7..95b3daa 100644 (file)
@@ -273,8 +273,14 @@ Print \fIformat\fP to the standard output, interpreting '\e' escapes
 and '%' directives. The supported directives include most supported by
 \fBfind\fP(1) and the following extensions:
 .RS
+.IP %{fid}
+file FID
 .IP %{projid}
 numerical project ID
+.IP %{mirror-count}
+FLR mirror count
+.IP %{stripe-count}
+stripe count of last instantiated component
 .IP %{xattr:NAME}
 contents of NAME xattr as a string
 .RE
index 58fb18c..347f09e 100644 (file)
@@ -294,19 +294,14 @@ width:
                // parent-fid
                // parent-fids
                // pools
-       /* TODO
-        *      if (strcmp(ext, "fid") == 0)
-        *              LF3_EMIT_S('a', "(fid)");
-        *      else
-        */
-                    if (strcmp(ext, "projid") == 0)
-                               LF3_EMIT_N('d', "(%s)", ext);
-       /* TODO
-        *      else if (strcmp(ext, "projid") == 0 ||
-        *              strcmp(ext, "stripe-count") == 0 ||
-        *              strcmp(ext, "mirror-count") == 0)
-        *              LF3_EMIT_N('d', "(%s)", ext);
-        */
+               if (strcmp(ext, "fid") == 0)
+                       LF3_EMIT_S('a', "(file-fid)");
+               else if (strcmp(ext, "stripe-count") == 0)
+                       LF3_EMIT_N('d', "(lov-stripe-count)", ext);
+               else if (strcmp(ext, "mirror-count") == 0)
+                       LF3_EMIT_N('d', "(lov-mirror-count)", ext);
+               else if (strcmp(ext, "projid") == 0)
+                       LF3_EMIT_N('d', "(%s)", ext);
                else if (strstartswith(ext, "xattr:"))
                        LF3_EMIT_S('a', "(or (xattr-ref-string %Q) %Q)", ext + strlen("xattr:"), "");
                else
index 4456fbe..6846e03 100644 (file)
@@ -981,6 +981,81 @@ test_115() {
 }
 run_test 115 "lipe_find3 -path and -ipath with UTF-8"
 
+test_116() {
+       local file=$MOUNT/$tfile
+       declare -a fid
+       local x
+
+       init_lipe_find3_env
+
+       for x in 1 2 3; do
+               $LFS mirror create --mirror-count=$x "$file-$x" ||
+                       error "cannot create mirror for $file-$x"
+               fid[${x}]=$($LFS path2fid "$file-"${x})
+       done
+       sync
+
+       for x in 1 2 3; do
+               expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \
+                       -mirror-count $x -printf  '%{mirror-count} %{fid}'
+       done
+
+       expect_empty lipe_find3_facet mds1 -mirror-count 4 \
+               -printf  '%{mirror-count}'
+
+       rm $file*
+
+       for x in 1 2 3; do
+               $LFS setstripe -i 0 -c $x "$file-1-$x" ||
+                       error "cannot setstripe $x for file $file-1-$x"
+               fid[${x}]=$($LFS path2fid "$file-1-$x")
+               echo XXX > "$file-1-$x"
+       done
+       sync
+
+       for x in 1 2 3; do
+               expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \
+                       -stripe-count $x -printf '%{stripe-count} %{fid}'
+       done
+
+       expect_empty lipe_find3_facet mds1 -stripe-count 4 -printf '%{fid}'
+
+       rm $file*
+
+       for x in 1001 1002 1003; do
+               touch "$file-2-$x"
+               $LFS project -p $x $file-2-$x ||
+                       error "cannot set project $x for file $file-2-$x"
+               fid[${x}]=$($LFS path2fid "$file-2-$x")
+       done
+       sync
+
+       for x in 1001 1002 1003; do
+               expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \
+                       -projid $x -printf '%{projid} %{fid}'
+       done
+
+       expect_empty lipe_find3_facet mds1 -projid 1 -printf '%{projid} %{fid}'
+
+       rm $file*
+
+       for x in 1 2 3; do
+               touch "$file-3-$x"
+               setfattr -n user.$x -v $x "$file-3-$x"
+               fid[${x}]=$($LFS path2fid "$file-3-$x")
+       done
+       sync
+
+       for x in 1 2 3; do
+               local format='%{xattr:user.'"$x"'} %{fid}'
+               expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \
+                       -xattr user.$x -printf "${format}"
+       done
+
+       init_lipe_find3_env
+}
+run_test 116 "lipe_find3 verify printf formats"
+
 test_130() {
        local file=$MOUNT/$tfile
        local xtime