From d18173b952a875220c8f23fcf05fe9f6fed9d3e4 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Tue, 8 Jun 2021 17:54:49 +0800 Subject: [PATCH] EX-3292 pcc: avoid to specify ID for every attach In this patch, it avoids the need to specify "-i " for every attach 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. And the new format of PCC state is as follows: file: /mnt/lustre/f42.sanity-pcc, type: readonly, PCC_file: /d42.sanity-pcc/0402/0x200000401:0x3:0x0, open_count: 0, flags: 0 Signed-off-by: Qian Yingjin Change-Id: Icd23eda5dca4711f9bb7af940f6cef5ddb97ce69 Reviewed-on: https://review.whamcloud.com/43946 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Feng, Lei --- lustre/llite/pcc.c | 14 +++++++------- lustre/tests/sanity-pcc.sh | 21 +++++++++++++++++++++ lustre/utils/lfs.c | 14 ++------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 0fb8875..68ce3fa 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -1091,20 +1091,20 @@ pcc_dataset_get(struct pcc_super *super, enum lu_pcc_type type, __u32 id) struct pcc_dataset *dataset; struct pcc_dataset *selected = NULL; - if (id == 0) - return NULL; - /* * archive ID (read-write ID) or read-only ID is unique in the list, * we just return last added one as first priority. + * @id == 0, it will select the first one as candidate dataset. */ down_read(&super->pccs_rw_sem); list_for_each_entry(dataset, &super->pccs_datasets, pccd_linkage) { - if (type == LU_PCC_READWRITE && (dataset->pccd_rwid != id || - !(dataset->pccd_flags & PCC_DATASET_RWPCC))) + if (type == LU_PCC_READWRITE && + (!(dataset->pccd_rwid == id || id == 0) || + !(dataset->pccd_flags & PCC_DATASET_RWPCC))) continue; - if (type == LU_PCC_READONLY && (dataset->pccd_roid != id || - !(dataset->pccd_flags & PCC_DATASET_ROPCC))) + if (type == LU_PCC_READONLY && + (!(dataset->pccd_roid == id || id == 0) || + !(dataset->pccd_flags & PCC_DATASET_ROPCC))) continue; atomic_inc(&dataset->pccd_refcount); selected = dataset; diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index 1d858fc..f1b685e 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -3302,6 +3302,27 @@ test_41() { } run_test 41 "Test mtime rule for PCC-RO open attach with O_RDONLY mode" +test_42() { + local loopfile="$TMP/$tfile" + local mntpt="/mnt/pcc.$tdir" + local hsm_root="$mntpt/$tdir" + local file=$DIR/$tfile + + 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 $LCTL pcc list $MOUNT + + do_facet $SINGLEAGT echo -n attach_id_not_specified > $file || + error "Write $file failed" + do_facet $SINGLEAGT $LFS pcc attach -r $file || + error "PCC attach -r $file failed" + do_facet $SINGLEAGT $LFS pcc state $file + check_lpcc_state $file "readonly" +} +run_test 42 "PCC attach without attach ID specified" + test_99() { local loopfile="$TMP/$tfile" local mntpt="/mnt/pcc.$tdir" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 1a49939..1358dc8 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -11514,11 +11514,6 @@ static int lfs_pcc_attach(int argc, char **argv) } } - if (attach_id == 0) { - fprintf(stderr, "%s: must specify attach ID\n", argv[0]); - return CMD_HELP; - } - if (argc <= optind) { fprintf(stderr, "%s: must specify one or more file names\n", argv[0]); @@ -11593,11 +11588,6 @@ static int lfs_pcc_attach_fid(int argc, char **argv) } } - if (attach_id == 0) { - fprintf(stderr, "%s: must specify an archive ID\n", argv[0]); - return CMD_HELP; - } - if (!mntpath) { fprintf(stderr, "%s: must specify Lustre mount point\n", argv[0]); @@ -11792,8 +11782,8 @@ static int lfs_pcc_state(int argc, char **argv) continue; } - printf(", PCC file: %s", state.pccs_path); - printf(", user number: %u", state.pccs_open_count); + printf(", PCC_file: %s", state.pccs_path); + printf(", open_count: %u", state.pccs_open_count); printf(", flags: %x", state.pccs_flags); printf("\n"); } -- 1.8.3.1