Whamcloud - gitweb
EX-5128 pcc: avoid to specify attach ID for every pin
authorQian Yingjin <qian@ddn.com>
Thu, 21 Apr 2022 08:23:16 +0000 (04:23 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 25 Apr 2022 23:41:55 +0000 (23: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_205.

Change-Id: I04e2b3d9ca360ae40f3723d7cd9bd78b22602123
Signed-off-by: Qian Yingjin <qian@ddn.com>
Reviewed-on: https://review.whamcloud.com/47105
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Feng, Lei <flei@whamcloud.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 b7bdeca..73eb7f3 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 9f74fa9..d476490 100644 (file)
@@ -661,7 +661,8 @@ int llapi_pcc_del(const char *mntpath, const char *pccpath, __u32 flags);
 int llapi_pcc_clear(const char *mntpath, __u32 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 de71611..fefe1a0 100644 (file)
@@ -4566,6 +4566,41 @@ test_204() {
 }
 run_test 204 "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
+
+       (( $MDS1_VERSION >= $(version_code 2.14.0.38) )) ||
+               skip "Need server version at least 2.14.0.38"
+
+       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 $SECONDS
 check_and_cleanup_lustre
 exit_status
index 878dfca..69b8ba1 100644 (file)
@@ -12339,11 +12339,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]);
@@ -12362,6 +12357,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",
@@ -12409,11 +12417,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]);
@@ -12432,6 +12435,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 b329538..1395e5f 100644 (file)
@@ -690,15 +690,18 @@ 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 {
        enum pcc_cmd_t   pch_cmd;
+       enum lu_pcc_type pch_type;
        bool             pch_iter_cont;
        bool             pch_flags;
        const char      *pch_mntpath;
        const char      *pch_pccpath;
        pcc_handler_t    pch_cb;
+       __u32            pch_id;
 };
 
 static int llapi_pcc_yaml_cb_helper(struct pcc_cmd_handler *pch)
@@ -752,11 +755,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);
@@ -834,6 +838,41 @@ int llapi_pcc_clear(const char *mntpath, __u32 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)