Whamcloud - gitweb
LU-10499 pcc: avoid to specify attach ID for every pin 61/54461/5
authorQian Yingjin <qian@ddn.com>
Thu, 21 Apr 2022 08:23:16 +0000 (04:23 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 22 Jan 2025 18:41:13 +0000 (18:41 +0000)
In this patch, it avoids the need to specify "-i <attach_id>" for
every pin/unpin operation as in the very common case there is only
a single cache for that client.
If attach ID is not specified, it will select the first dataset
on the client as PCC backend.

Add the test case: sanity-pcc test_204b.

EX-bug-id: EX-5128
Change-Id: I04e2b3d9ca360ae40f3723d7cd9bd78b22602123
Signed-off-by: Qian Yingjin <qian@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54461
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Feng Lei <flei@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/doc/lfs-pcc-attach.1
lustre/doc/lfs-pcc-pin.1
lustre/include/lustre/lustreapi.h
lustre/tests/sanity-pcc.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi_pcc.c

index a5f0d87..33aa641 100644 (file)
@@ -19,7 +19,7 @@ to choose which backend for the cached
 .IR FILE .
 If
 .I ID
-is not specified, then use the first archive attached to the mounted
+is not specified, use the first archive attached to the mounted
 filesystem by default.
 .TP
 .BR --mnt | -m
index e6ee72d..2caf6ac 100644 (file)
@@ -15,6 +15,10 @@ cache storage by \fBlpcc_purge\fR.
 The ARCHIVE
 .I ID
 to be pinned or un-pinned.
+If
+.I ID
+is not specified, use the first archive attached to the mounted
+filesystem by default.
 
 .SH EXAMPLES
 .TP
index 2455e71..a8e4951 100644 (file)
@@ -747,7 +747,8 @@ int llapi_pcc_del(const char *mntpath, const char *pccpath,
 int llapi_pcc_clear(const char *mntpath, enum lu_pcc_cleanup_flags flags);
 int llapi_pcc_pin_file(const char *path, __u32 id);
 int llapi_pcc_unpin_file(const char *path, __u32 id);
-
+int llapi_pcc_backend_id_get(const char *path, enum lu_pcc_type type,
+                            __u32 *id);
 /** @} llapi */
 
 /* llapi_layout user interface */
index 11de54e..9f2cb6c 100755 (executable)
@@ -4619,7 +4619,7 @@ test_203() {
 }
 run_test 203 "Verify attach/hit bytes statistics data"
 
-test_204() {
+test_204a() {
        local loopfile="$TMP/$tfile"
        local mntpt="/mnt/pcc.$tdir"
        local hsm_root="$mntpt/$tdir"
@@ -4689,7 +4689,45 @@ test_204() {
        do_facet $SINGLEAGT cat $file
        check_lpcc_state $file "readonly"
 }
-run_test 204 "pin/unpin pcc flag"
+run_test 204a "pin/unpin pcc flag"
+
+test_204b() {
+       local loopfile="$TMP/$tfile"
+       local mntpt="/mnt/pcc.$tdir"
+       local hsm_root="$mntpt/$tdir"
+       local file=$DIR/$tfile
+       local xattrname="trusted.pin"
+       local xattrvalue
+       local fid
+
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
+               skip "Server does not support PCC-RO"
+
+       (( $MDS1_VERSION >= $(version_code 2.15.61) )) ||
+               skip "Need server version at least 2.15.61"
+
+       do_facet $SINGLEAGT echo -n attach_id_not_specified > $file ||
+               error "dd write $file failed"
+       do_facet $SINGLEAGT $LFS pcc pin $file &&
+               error "Pin should fail for a client without any PCC backend"
+
+       setup_loopdev $SINGLEAGT $loopfile $mntpt 60
+       do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed"
+       setup_pcc_mapping $SINGLEAGT \
+               "projid={100}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1"
+
+       do_facet $SINGLEAGT $LFS pcc pin $file || error "failed to pin $file"
+       do_facet $SINGLEAGT getfattr $file -n $xattrname
+       xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+       [[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
+               error "incorrect xattr $xattrname=$xattrvalue"
+
+       do_facet $SINGLEAGT $LFS pcc unpin $file || error "failed to PCC unpin $file"
+       do_facet $SINGLEAGT getfattr $file -n $xattrname
+       xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+       [[ -z "$xattrvalue" ]] || error "incorrect xattr $xattrname=$xattrvalue"
+}
+run_test 204b "PCC pin/unpin without attach ID specified"
 
 complete_test $SECONDS
 check_and_cleanup_lustre
index ff0633a..851bc80 100755 (executable)
@@ -14485,11 +14485,6 @@ static int lfs_pcc_pin(int argc, char **argv)
        }
 
        /* check parameters */
-       if (id == 0) {
-               fprintf(stderr, "%s: must specify -i|--id option\n",
-                       argv[0]);
-               return CMD_HELP;
-       }
        if (argc <= 1) {
                fprintf(stderr, "%s: must specify one or more file names\n",
                        argv[0]);
@@ -14508,6 +14503,19 @@ static int lfs_pcc_pin(int argc, char **argv)
                        continue;
                }
 
+               if (id == 0) {
+                       rc2 = llapi_pcc_backend_id_get(fullpath,
+                                                      LU_PCC_READONLY, &id);
+                       if (rc2 < 0) {
+                               fprintf(stderr,
+                                       "%s: failed to get id for '%s': %s\n",
+                                       argv[0], path, strerror(-rc2));
+                               if (rc == 0)
+                                       rc = rc2;
+                               continue;
+                       }
+               }
+
                rc2 = llapi_pcc_pin_file(fullpath, id);
                if (rc2 < 0) {
                        fprintf(stderr, "%s: cannot pin '%s' for PCC: %s\n",
@@ -14555,11 +14563,6 @@ static int lfs_pcc_unpin(int argc, char **argv)
                }
        }
        /* check parameters */
-       if (id == 0) {
-               fprintf(stderr, "%s: must specify -i|--id option\n",
-                       argv[0]);
-               return CMD_HELP;
-       }
        if (argc <= 1) {
                fprintf(stderr, "%s: must specify one or more file names\n",
                        argv[0]);
@@ -14578,6 +14581,19 @@ static int lfs_pcc_unpin(int argc, char **argv)
                        continue;
                }
 
+               if (id == 0) {
+                       rc2 = llapi_pcc_backend_id_get(fullpath,
+                                                      LU_PCC_READONLY, &id);
+                       if (rc2 < 0) {
+                               fprintf(stderr,
+                                       "%s: failed to get id for '%s': %s\n",
+                                       argv[0], path, strerror(-rc2));
+                               if (rc == 0)
+                                       rc = rc2;
+                               continue;
+                       }
+               }
+
                rc2 = llapi_pcc_unpin_file(fullpath, id);
                if (rc2 < 0) {
                        fprintf(stderr, "%s: cannot unpin '%s' for PCC: %s\n",
index 2fb354c..0e4f48f 100644 (file)
@@ -684,6 +684,7 @@ typedef int (*pcc_handler_t)(struct cYAML *node, struct pcc_cmd_handler *pch);
 enum pcc_cmd_t {
        PCC_CMD_DEL,
        PCC_CMD_CLEAR,
+       PCC_CMD_BACKEND_SELECT,
 };
 
 struct pcc_cmd_handler {
@@ -748,11 +749,12 @@ static int llapi_pcc_yaml_cb_helper(struct pcc_cmd_handler *pch)
                        rc = ret;
        }
 
+out_free:
        /* Not found the given PCC backend on the client. */
-       if (pch->pch_iter_cont && pch->pch_cmd == PCC_CMD_DEL)
+       if (pch->pch_iter_cont && (pch->pch_cmd == PCC_CMD_DEL ||
+           pch->pch_cmd == PCC_CMD_BACKEND_SELECT))
                rc = -ENOENT;
 
-out_free:
        if (tree)
                cYAML_free_tree(tree);
        cfs_free_param_data(&path);
@@ -831,6 +833,41 @@ int llapi_pcc_clear(const char *mntpath, enum lu_pcc_cleanup_flags flags)
        return llapi_pcc_yaml_cb_helper(&pch);
 }
 
+static int llapi_pcc_yaml_backend_get(struct cYAML *node,
+                                     struct pcc_cmd_handler *pch)
+{
+       struct cYAML *pccid;
+
+       /* TODO: check the flags of PCC backends. */
+       pccid = cYAML_get_object_item(node, pch->pch_type == LU_PCC_READWRITE ?
+                                     PCC_YAML_RWID : PCC_YAML_ROID);
+       if (!pccid || pccid->cy_valueint == 0)
+               return 0;
+
+       pch->pch_iter_cont = false;
+       pch->pch_id = pccid->cy_valueint;
+       return 0;
+}
+
+int llapi_pcc_backend_id_get(const char *path, enum lu_pcc_type type, __u32 *id)
+{
+       struct pcc_cmd_handler pch;
+       int rc;
+
+       memset(&pch, 0, sizeof(pch));
+       pch.pch_cmd = PCC_CMD_BACKEND_SELECT;
+       pch.pch_iter_cont = true;
+       pch.pch_mntpath = path;
+       pch.pch_type = type;
+       pch.pch_cb = llapi_pcc_yaml_backend_get;
+
+       rc = llapi_pcc_yaml_cb_helper(&pch);
+       if (rc == 0)
+               *id = pch.pch_id;
+
+       return rc;
+}
+
 #define PIN_YAML_HSM_STR       "hsm"
 
 static int verify_pin_xattr_object(struct cYAML *yaml)