Whamcloud - gitweb
EX-3409 pcc: add owner capacity check for open attach
authorQian Yingjin <qian@ddn.com>
Thu, 1 Jul 2021 07:49:58 +0000 (15:49 +0800)
committerLi Xi <lixi@ddn.com>
Tue, 20 Jul 2021 14:29:50 +0000 (14:29 +0000)
This patch adds owner and capacity check when try to auto attach
at the open() time.
Add sanity-pcc test_43.

For the command "lfs pcc attach_fid", make it more convenient by
the way that the parameter "-m" is not mandatory required when
specifying the mount point.

Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: Icb8cbddb64c5712e2db970120b06fc1a0216c332
Reviewed-on: https://review.whamcloud.com/44123
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Feng, Lei <flei@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh
lustre/utils/lfs.c

index 9c34d87..3e9c2fa 100644 (file)
@@ -2214,7 +2214,7 @@ int pcc_file_open(struct inode *inode, struct file *file)
                if (pcc_may_auto_attach(inode, PIT_OPEN))
                        rc = pcc_try_auto_attach(inode, &cached, PIT_OPEN);
 
-               if (rc == 0 && !cached)
+               if (rc == 0 && !cached && inode_owner_or_capable(inode))
                        rc = pcc_try_readonly_open_attach(inode, file, &cached);
 
                if (rc < 0 || !cached)
index f1b685e..16bb1d9 100644 (file)
@@ -3323,6 +3323,29 @@ test_42() {
 }
 run_test 42 "PCC attach without attach ID specified"
 
+test_43() {
+       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 \
+               "size\<{100M}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1"
+       do_facet $SINGLEAGT $LCTL pcc list $MOUNT
+
+       echo "attach_root_user_data" > $file || error "echo $file failed"
+
+       do_facet $SINGLEAGT $LFS pcc state $file
+       # Attach by non-root user should fail.
+       do_facet $SINGLEAGT $RUNAS $LFS pcc attach -r $file &&
+               error "PCC attach -r $file should fail for non-root user"
+       do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
+       check_lpcc_state $file "none"
+}
+run_test 43 "Auto attach at open() should add capacity owner check"
+
 test_99() {
        local loopfile="$TMP/$tfile"
        local mntpt="/mnt/pcc.$tdir"
index 1358dc8..8c69747 100644 (file)
@@ -11589,9 +11589,12 @@ static int lfs_pcc_attach_fid(int argc, char **argv)
        }
 
        if (!mntpath) {
-               fprintf(stderr, "%s: must specify Lustre mount point\n",
-                       argv[0]);
-               return CMD_HELP;
+               if (argc <= optind) {
+                       fprintf(stderr, "%s: must specify Lustre mount point\n",
+                               argv[0]);
+                       return CMD_HELP;
+               }
+               mntpath = argv[optind++];
        }
 
        if (argc <= optind) {