From 7cce3772e267afee328d63da9367875c63e6ad43 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Thu, 1 Jul 2021 15:49:58 +0800 Subject: [PATCH] EX-3409 pcc: add owner capacity check for open attach 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 Change-Id: Icb8cbddb64c5712e2db970120b06fc1a0216c332 Reviewed-on: https://review.whamcloud.com/44123 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Feng, Lei Reviewed-by: Li Xi --- lustre/llite/pcc.c | 2 +- lustre/tests/sanity-pcc.sh | 23 +++++++++++++++++++++++ lustre/utils/lfs.c | 9 ++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 9c34d87..3e9c2fa 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -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) diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index f1b685e..16bb1d9f 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -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" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 1358dc8..8c69747 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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) { -- 1.8.3.1