Whamcloud - gitweb
EX-4015 lipe: cache layout in loa
authorJohn L. Hammond <jhammond@whamcloud.com>
Thu, 17 Feb 2022 19:51:32 +0000 (13:51 -0600)
committerJohn L. Hammond <jhammond@whamcloud.com>
Thu, 10 Mar 2022 17:24:59 +0000 (17:24 +0000)
In ldiskfs_read_attr_lov(), cache the decoded llapi_layout() in the
current object attrs. Then resue this layout in lov-pools. Add
lov-ost-indexes to return a list of all object OST indexes for the
current file.

Test-Parameters: trivial testlist=sanity-lipe-scan3 facet=mds1
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: I3451857fc25f1f9507b6e185bad39fcb3f0e6f22
Reviewed-on: https://review.whamcloud.com/46546
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lipe/src/lipe_scan3/ls3_main.c
lipe/src/lipe_scan3/ls3_object_attrs.c
lipe/src/lipe_scan3/ls3_object_attrs.h
lipe/src/lipe_scan3/ls3_scan.c
lipe/src/lipe_scan3/tests/lipe.scm
lustre/tests/sanity-lipe-scan3.sh

index 32ebfd2..e5fa5b3 100644 (file)
@@ -656,8 +656,8 @@ out:
 }
 #undef FUNC_NAME
 
-SCM_DEFINE(ls3_scm_pools_list, "pools", 0, 0, 0,
-          (), "return pools of current file")
+SCM_DEFINE(ls3_scm_lov_pools_list, "lov-pools", 0, 0, 0,
+          (), "return all pools from LOV of current file")
 {
        struct ls3_object_attrs *loa = ls3_attrs_try(LS3_OBJECT_ATTR_LOV);
        struct llapi_layout *ll = NULL;
@@ -670,12 +670,8 @@ SCM_DEFINE(ls3_scm_pools_list, "pools", 0, 0, 0,
                return SCM_EOL;
 
        /* XXX llapi_layout_*() functions return -1 on error and set errno. */
-       errno = 0;
-       ll = llapi_layout_get_by_xattr(loa->loa_lum, loa->loa_lum_size, 0);
-       if (ll == NULL) {
-               rc = -1;
-               goto out;
-       }
+       assert(loa->loa_layout != NULL);
+       ll = loa->loa_layout;
 
        rc = llapi_layout_comp_use(ll, LLAPI_LAYOUT_COMP_USE_LAST);
        if (rc < 0)
@@ -696,8 +692,57 @@ SCM_DEFINE(ls3_scm_pools_list, "pools", 0, 0, 0,
                        goto out;
        }
 out:
-       llapi_layout_free(ll);
+       if (rc < 0)
+               ls3_throw_read_attr_error(LS3_OBJECT_ATTR_LOV,
+                                         errno != 0 ? errno : EINVAL);
+
+       return lis;
+}
+
+SCM_DEFINE(ls3_scm_lov_ost_indexes_list, "lov-ost-indexes", 0, 0, 0,
+          (), "return all object OST indexes for current file")
+{
+       struct ls3_object_attrs *loa = ls3_attrs_try(LS3_OBJECT_ATTR_LOV);
+       struct llapi_layout *ll = NULL;
+       SCM lis = SCM_EOL;
+       int rc;
+
+       /* TODO Distinguish between missing xattr and other error. */
+       if (!(loa->loa_attr_bits & LS3_OBJECT_ATTR_LOV))
+               return SCM_EOL;
+
+       /* XXX llapi_layout_*() functions return -1 on error and set errno. */
+       assert(loa->loa_layout != NULL);
+       ll = loa->loa_layout;
 
+       rc = llapi_layout_comp_use(ll, LLAPI_LAYOUT_COMP_USE_LAST);
+       if (rc < 0)
+               goto out;
+
+       while (rc == 0) {
+               uint64_t stripe_count;
+               uint64_t i;
+
+               rc = llapi_layout_stripe_count_get(ll, &stripe_count);
+               if (rc < 0)
+                       goto out;
+
+               /* XXX We build the list in reverse order. */
+               for (i = stripe_count; i != 0; i--) {
+                       uint64_t ost_index = -1;
+
+                       rc = llapi_layout_ost_index_get(ll, i - 1, &ost_index);
+                       if (rc < 0)
+                               goto out;
+
+                       lis = scm_cons(scm_from_uint64(ost_index), lis);
+               }
+
+               rc = llapi_layout_comp_use(ll, LLAPI_LAYOUT_COMP_USE_PREV);
+               if (rc < 0)
+                       goto out;
+       }
+out:
        if (rc < 0)
                ls3_throw_read_attr_error(LS3_OBJECT_ATTR_LOV,
                                          errno != 0 ? errno : EINVAL);
@@ -1055,7 +1100,8 @@ static void ls3_scm_init(void *unused)
        "relative-paths",
        "xattrs",
        "xattr-ref",
-       "pools",
+       "lov-ost-indexes",
+       "lov-pools",
        "print-json",
        "print-file-fid",
        "print-self-fid",
index 872fbfb..76dc162 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/lustre/lustre_fid.h>
 #include <linux/lustre/lustre_idl.h>
 #include <linux/lustre/lustre_ioctl.h>
+#include <lustre/lustreapi.h>
 #include "list.h"
 #include "ls3_debug.h"
 #include "ls3_scan.h"
@@ -404,6 +405,8 @@ void lipe_object_attrs_reset(struct ls3_object_attrs *loa)
        lipe_object_attrs_links_fini(loa);
        lipe_object_attrs_paths_fini(loa);
        lipe_object_attrs_xattrs_fini(loa);
+       llapi_layout_free(loa->loa_layout);
+       loa->loa_layout = NULL;
 }
 
 int lipe_object_attrs_init(struct ls3_object_attrs *loa)
@@ -434,6 +437,7 @@ void lipe_object_attrs_fini(struct ls3_object_attrs *loa)
        free(loa->loa_lum);
        free(loa->loa_link_buf);
        free(loa->loa_lmv_buf);
+       llapi_layout_free(loa->loa_layout);
 }
 
 static int lipe_object_attrs_add_link(struct ls3_object_attrs *attrs,
index 73bea61..76a0feb 100644 (file)
@@ -169,6 +169,7 @@ struct ls3_object_attrs {
        size_t                   loa_lmv_buf_size;
        struct lov_user_md      *loa_lum;
        int                      loa_lum_size;
+       struct llapi_layout     *loa_layout; /* LS3_OBJECT_ATTR_LOV */
        struct hsm_user_state    loa_hsm_state;
        struct lustre_som_attrs  loa_som;
        /* The entry number. If inode is not directory, value is zero */
index dfa3abb..808fabc 100644 (file)
@@ -376,7 +376,6 @@ static int ldiskfs_read_attr_lov(struct ls3_instance *li,
                                 struct ls3_object_attrs *loa)
 {
        struct lov_user_md *lum = loa->loa_lum;
-       struct llapi_layout *layout = NULL;
        int size;
        int rc;
 
@@ -387,8 +386,8 @@ static int ldiskfs_read_attr_lov(struct ls3_instance *li,
        if (rc < 0)
                goto out;
 
-       layout = llapi_layout_get_by_xattr(lum, size, 0);
-       if (layout == NULL) {
+       loa->loa_layout = llapi_layout_get_by_xattr(lum, size, 0);
+       if (loa->loa_layout == NULL) {
                LS3_ERROR_OBJ(lo, "cannot decode '%s' xattr: rc = %d\n",
                              XATTR_NAME_LOV, rc);
                rc = -errno;
@@ -397,8 +396,6 @@ static int ldiskfs_read_attr_lov(struct ls3_instance *li,
 
        loa->loa_attr_bits |= LS3_OBJECT_ATTR_LOV;
 out:
-       llapi_layout_free(layout);
-
        return rc;
 }
 
index 78f1bb6..4316c77 100644 (file)
@@ -46,7 +46,8 @@
           file-fid
           self-fid
           links
-          pools
+          lov-pools
+          lov-ost-indexes
           xattrs
 
           absolute-paths
index 86fddbc..5d5bada 100644 (file)
@@ -16,8 +16,8 @@ FAIL_ON_ERROR=false
 
 declare -r ROOT_FID="[0x200000007:0x1:0x0]"
 
-# bug number for skipped test:
-ALWAYS_EXCEPT="$SANITY_LIPE_SCAN3_EXCEPT"
+# bug number for skipped test:           DCO-8906
+ALWAYS_EXCEPT="$SANITY_LIPE_SCAN3_EXCEPT 130"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 (( OSTCOUNT >= 2 )) || skip_env "need at least 2 OSTs"
@@ -34,6 +34,9 @@ for t in lipe_scan3; do
 done
 
 which jq || skip_env "jq is not installed"
+which yq || skip_env "yq is not installed"
+jq --version
+yq --version
 
 build_test_filter
 check_and_setup_lustre
@@ -320,7 +323,7 @@ test_100() {
                expect_print lipe_scan3_format "$device" "($proc)"
        done
 
-       for proc in absolute-paths relative-paths links pools xattrs; do
+       for proc in absolute-paths relative-paths links lov-pools lov-ost-indexes xattrs; do
                expect_print lipe_scan3_format "$device" "($proc)"
        done
 }
@@ -641,14 +644,17 @@ test_130() {
        local facet=mds1
        local device="$(facet_device $facet)"
        local file=$MOUNT/$tfile
-       local fd
+       local -a ost_indexes
 
-       init_lipe_scan3_env_file "$file"
+       init_lipe_scan3_env
+       $LFS setstripe -c -1 "$file"
        echo XXX > "$file"
+       ost_indexes=($($LFS getstripe --yaml "$file" | yq '.lmm_objects[] | .l_ost_idx'))
 
-       expect_expr "$device" '(pools)' '()'
+       expect_expr "$device" '(lov-pools)' '()'
+       expect_expr "$device" '(lov-ost-indexes)' "(${ost_indexes[*]})"
 }
-run_test 130 "lipe_scan3 pools does the right thing"
+run_test 130 "lipe_scan3 lov-pools and lov-ost-indexes do the right thing"
 
 test_200() {
        local facet=mds1