Whamcloud - gitweb
EX-3292 pcc: avoid to specify ID for every attach
authorQian Yingjin <qian@ddn.com>
Tue, 8 Jun 2021 09:54:49 +0000 (17:54 +0800)
committerLi Xi <lixi@ddn.com>
Tue, 13 Jul 2021 08:15:57 +0000 (08:15 +0000)
In this patch, it avoids the need to specify "-i <attach_id>" 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 <qian@ddn.com>
Change-Id: Icd23eda5dca4711f9bb7af940f6cef5ddb97ce69
Reviewed-on: https://review.whamcloud.com/43946
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Feng, Lei <flei@whamcloud.com>
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh
lustre/utils/lfs.c

index 0fb8875..68ce3fa 100644 (file)
@@ -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;
index 1d858fc..f1b685e 100644 (file)
@@ -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"
index 1a49939..1358dc8 100644 (file)
@@ -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");
        }