From 28632b1ff7f112fc7b00f6ddba15c9c5c0ee332a Mon Sep 17 00:00:00 2001 From: Alexandre Ioffe Date: Tue, 21 Mar 2023 20:22:46 -0700 Subject: [PATCH] EX-7013 lipe: printf formats added to lipe_find3 Printf formats added to lipe_find3: %LS, %Lc, %LN, %LF, %{stripe-size}. Sanity-lipe-find3 updated to test these new formats. Test-Parameters: trivial testlist=sanity-lipe-find3,sanity-lipe-scan3 Signed-off-by: Alexandre Ioffe Change-Id: I6377e131961634572a246909587f81da9190dd28 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50366 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Colin Faber Reviewed-by: Andreas Dilger --- lipe/man/lipe_find3.1 | 8 +++++--- lipe/src/lipe_find3/lf3_parse_format.c | 19 +++++++++++++++++++ lipe/src/lipe_scan3/ls3_main.c | 26 ++++++++++++++++++++++++++ lustre/tests/sanity-lipe-find3.sh | 21 +++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/lipe/man/lipe_find3.1 b/lipe/man/lipe_find3.1 index 95b3daa..198d50c 100644 --- a/lipe/man/lipe_find3.1 +++ b/lipe/man/lipe_find3.1 @@ -273,14 +273,16 @@ 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} +.IP %{fid}, %LF file FID .IP %{projid} numerical project ID -.IP %{mirror-count} +.IP %{mirror-count}, %LN FLR mirror count -.IP %{stripe-count} +.IP %{stripe-count}, %Lc stripe count of last instantiated component +.IP %{stripe-size}, %LS +stripe size of last instantiated component .IP %{xattr:NAME} contents of NAME xattr as a string .RE diff --git a/lipe/src/lipe_find3/lf3_parse_format.c b/lipe/src/lipe_find3/lf3_parse_format.c index 347f09e..f015004 100644 --- a/lipe/src/lipe_find3/lf3_parse_format.c +++ b/lipe/src/lipe_find3/lf3_parse_format.c @@ -242,6 +242,23 @@ width: case 'l': /* symlink target or empty string if not symlink */ LF3_EMIT_U(c); break; + case 'L': /* formats like lfs find */ + c = fmt[n++]; + switch (c) { + case 'S': + LF3_EMIT_N('d', "(lov-stripe-size)"); + break; + case 'c': + LF3_EMIT_N('d', "(lov-stripe-count)"); + break; + case 'N': + LF3_EMIT_N('d', "(lov-mirror-count)"); + break; + case 'F': + LF3_EMIT_S('a', "(file-fid)"); + break; + } + break; case 'm': /* File's permission bits (in octal). */ LF3_EMIT_N('o', "(logand (mode) #o07777)"); /* FIXME octal. */ break; @@ -296,6 +313,8 @@ width: // pools if (strcmp(ext, "fid") == 0) LF3_EMIT_S('a', "(file-fid)"); + else if (strcmp(ext, "stripe-size") == 0) + LF3_EMIT_N('d', "(lov-stripe-size)", ext); else if (strcmp(ext, "stripe-count") == 0) LF3_EMIT_N('d', "(lov-stripe-count)", ext); else if (strcmp(ext, "mirror-count") == 0) diff --git a/lipe/src/lipe_scan3/ls3_main.c b/lipe/src/lipe_scan3/ls3_main.c index 6b303ff..9c07be4 100644 --- a/lipe/src/lipe_scan3/ls3_main.c +++ b/lipe/src/lipe_scan3/ls3_main.c @@ -845,6 +845,31 @@ out: return scm_from_uint64(count); } +SCM_DEFINE(ls3_scm_lov_stripe_size, "lov-stripe-size", 0, 0, 0, + (), "return stripe size of current file") +{ + struct ls3_object_attrs *loa = ls3_attrs_try(LS3_OBJECT_ATTR_LOV); + uint64_t stripe_size = 0; + int rc; + + /* TODO Distinguish between missing xattr and other error. */ + if (loa->loa_layout == NULL) + return scm_from_int(0); + + /* XXX llapi_layout_*() functions return -1 on error and set errno. */ + rc = llapi_layout_get_last_init_comp(loa->loa_layout); + if (rc < 0) + goto out; + + rc = llapi_layout_stripe_size_get(loa->loa_layout, &stripe_size); +out: + if (rc < 0) + ls3_throw_read_attr_error(LS3_OBJECT_ATTR_LOV, + errno != 0 ? errno : EINVAL); + + return scm_from_uint64(stripe_size); +} + SCM_DEFINE(ls3_scm_lov_pools_list, "lov-pools", 0, 0, 0, (), "return all pools from LOV of current file") { @@ -1345,6 +1370,7 @@ static void ls3_module_init(void *unused) "xattr-ref", "lov-mirror-count", "lov-stripe-count", + "lov-stripe-size", "lov-ost-indexes", "lov-pools", "print-json", diff --git a/lustre/tests/sanity-lipe-find3.sh b/lustre/tests/sanity-lipe-find3.sh index 6846e03..44a9f2f 100644 --- a/lustre/tests/sanity-lipe-find3.sh +++ b/lustre/tests/sanity-lipe-find3.sh @@ -998,6 +998,8 @@ test_116() { for x in 1 2 3; do expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ -mirror-count $x -printf '%{mirror-count} %{fid}' + expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ + -mirror-count $x -printf '%LN %{fid}' done expect_empty lipe_find3_facet mds1 -mirror-count 4 \ @@ -1016,6 +1018,8 @@ test_116() { for x in 1 2 3; do expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ -stripe-count $x -printf '%{stripe-count} %{fid}' + expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ + -stripe-count $x -printf '%Lc %{fid}' done expect_empty lipe_find3_facet mds1 -stripe-count 4 -printf '%{fid}' @@ -1052,6 +1056,23 @@ test_116() { -xattr user.$x -printf "${format}" done + rm $file* + + for x in 65536 131072 196608; do + $LFS setstripe -i 0 -c 1 --stripe-size $x "$file-4-$x" || + error "cannot setstripe size $x for file $file-4-$x" + fid[${x}]=$($LFS path2fid "$file-4-$x") + echo XXX > "$file-4-$x" + done + sync + + for x in 65536 131072 196608; do + expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ + -name $tfile-4-$x -printf '%{stripe-size} %{fid}' + expect1 "$x ${fid[${x}]}" lipe_find3_facet mds1 \ + -name $tfile-4-$x -printf '%LS %{fid}' + done + init_lipe_find3_env } run_test 116 "lipe_find3 verify printf formats" -- 1.8.3.1