From 53b6437250b4959c0229f9d6325c1a7cf78c4576 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Thu, 21 Apr 2022 04:23:16 -0400 Subject: [PATCH] EX-5128 pcc: avoid to specify attach ID for every pin In this patch, it avoids the need to specify "-i " 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 Reviewed-on: https://review.whamcloud.com/47105 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Feng, Lei Reviewed-by: Andreas Dilger --- lustre/doc/lfs-pcc-attach.1 | 2 +- lustre/doc/lfs-pcc-pin.1 | 4 ++++ lustre/include/lustre/lustreapi.h | 3 ++- lustre/tests/sanity-pcc.sh | 35 +++++++++++++++++++++++++++++++ lustre/utils/lfs.c | 36 +++++++++++++++++++++++--------- lustre/utils/liblustreapi_pcc.c | 43 +++++++++++++++++++++++++++++++++++++-- 6 files changed, 109 insertions(+), 14 deletions(-) diff --git a/lustre/doc/lfs-pcc-attach.1 b/lustre/doc/lfs-pcc-attach.1 index b7bdeca..73eb7f3 100644 --- a/lustre/doc/lfs-pcc-attach.1 +++ b/lustre/doc/lfs-pcc-attach.1 @@ -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 diff --git a/lustre/doc/lfs-pcc-pin.1 b/lustre/doc/lfs-pcc-pin.1 index e6ee72da..2caf6ac 100644 --- a/lustre/doc/lfs-pcc-pin.1 +++ b/lustre/doc/lfs-pcc-pin.1 @@ -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 diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 9f74fa9..d476490 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -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 */ diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index de71611..fefe1a0 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -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 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 878dfca..69b8ba1 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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", diff --git a/lustre/utils/liblustreapi_pcc.c b/lustre/utils/liblustreapi_pcc.c index b329538..1395e5f 100644 --- a/lustre/utils/liblustreapi_pcc.c +++ b/lustre/utils/liblustreapi_pcc.c @@ -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) -- 1.8.3.1