Whamcloud - gitweb
EX-3825 pcc: Check if PCC copy is unlinked for state output
authorQian Yingjin <qian@ddn.com>
Wed, 29 Sep 2021 03:35:30 +0000 (11:35 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Sun, 10 Oct 2021 22:03:30 +0000 (22:03 +0000)
In this patch, it adds support for the command "lfs pcc state" to
check whether the PCC copy is in the local client cache or
unlinked improperly.

Test-Parameters: testlist=sanity-pcc env=ONLY=48
Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: Ic50c901df78adfaf5b56990120f832e5d74a117c
Reviewed-on: https://review.whamcloud.com/45082
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh
lustre/utils/lfs.c

index dae4f38..1feeede 100644 (file)
@@ -2793,6 +2793,8 @@ enum lu_pcc_state_flags {
        PCC_STATE_FL_ATTR_VALID         = 0x01,
        /* The file is being attached into PCC */
        PCC_STATE_FL_ATTACHING          = 0x02,
+       /* The PCC copy is unlinked */
+       PCC_STATE_FL_UNLINKED           = 0x04,
 };
 
 struct lu_pcc_state {
index 62e1cb6..89a471f 100644 (file)
@@ -2329,10 +2329,14 @@ void pcc_file_release(struct inode *inode, struct file *file)
                goto out;
 
        pcci = ll_i2pcci(inode);
-       LASSERT(pcci);
-       path = &pcci->pcci_path;
-       CDEBUG(D_CACHE, "releasing pcc file \"%pd\"\n", path->dentry);
-       pcc_inode_put(pcci);
+       if (pcci) {
+               path = &pcci->pcci_path;
+               CDEBUG(D_CACHE, "releasing pcc file \"%pd\"\n", path->dentry);
+               pcc_inode_put(pcci);
+       } else {
+               CDEBUG(D_CACHE, "PCC copy "DFID" was unlinked?\n",
+                      PFID(ll_inode2fid(inode)));
+       }
 
        LASSERT(file_count(pccf->pccf_file) > 0);
        fput(pccf->pccf_file);
@@ -4082,6 +4086,12 @@ int pcc_ioctl_state(struct file *file, struct inode *inode,
        if (IS_ERR(path))
                GOTO(out_unlock, rc = PTR_ERR(path));
 
+       if (!pcci->pcci_path.dentry->d_inode ||
+           pcci->pcci_path.dentry->d_inode->i_nlink == 0) {
+               state->pccs_flags |= PCC_STATE_FL_UNLINKED;
+               pcc_inode_detach_put(inode);
+       }
+
        if (strlcpy(state->pccs_path, path, buf_len) >= buf_len)
                GOTO(out_unlock, rc = -ENAMETOOLONG);
 
index 37ecbc8..5169a1d 100644 (file)
@@ -2769,11 +2769,14 @@ test_32() {
        sleep 3
        do_facet $SINGLEAGT rm $lpcc_path || error "rm $lpcc_path failed"
        rmultiop_stop $agt_host || error "multiop $file read failed"
+
+       # file will be detached in @pcc_ioctl_state()
        check_lpcc_state $file "readonly"
 
        local content=$(do_facet $SINGLEAGT cat $file)
        [[ $content == "roattach_removed" ]] || error "data mismatch: $content"
-       check_lpcc_state $file "readonly"
+       check_lpcc_state $file "none"
+       lctl dk > log2
        do_facet $SINGLEAGT $LFS pcc detach -k $file ||
                error "RO-PCC detach $file failed"
        check_lpcc_state $file "none"
@@ -2781,10 +2784,11 @@ test_32() {
        do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
                error "RO-PCC attach $file failed"
        do_facet $SINGLEAGT rm $lpcc_path || error "rm $lpcc_path failed"
+       # file will be detached in @pcc_ioctl_state()
        check_lpcc_state $file "readonly"
        content=$(do_facet $SINGLEAGT cat $file)
        [[ $content == "roattach_removed" ]] || error "data mismatch: $content"
-       check_lpcc_state $file "readonly"
+       check_lpcc_state $file "none"
        do_facet $SINGLEAGT $LFS pcc detach -k $file ||
                error "RO-PCC detach $file failed"
        check_lpcc_state $file "none"
@@ -3583,6 +3587,31 @@ test_47() {
 }
 run_test 47 "mtime should be kept once file attached into PCC"
 
+test_48() {
+       local loopfile="$TMP/$tfile"
+       local mntpt="/mnt/pcc.$tdir"
+       local hsm_root="$mntpt/$tdir"
+       local file=$DIR/$tfile
+       local -a lpcc_path
+
+       setup_loopdev client $loopfile $mntpt 60
+       mkdir $hsm_root || error "mkdir $hsm_root failed"
+       setup_pcc_mapping client \
+               "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1"
+
+       echo "QQQQQ" > $file || error "echo $file failed"
+       lpcc_path=$(lpcc_fid2path $hsm_root $file)
+       cat $file || error "cat $file failed"
+       check_lpcc_state $file "readonly" client
+
+       rm $lpcc_path || error "rm $lpcc_path failed"
+       $LFS pcc state $file | grep "(unlinked)" || error "$file not unlinked"
+       [[ "$(cat $file)" =~ "QQQQQ" ]] || error "read $file content failed"
+       check_lpcc_state $file "readonly" client
+       $LFS pcc detach $file || error "detach '$file' failed"
+}
+run_test 48 "PCC state should check whether the file in in local PCC cache"
+
 test_96() {
        local loopfile="$TMP/$tfile"
        local mntpt="/mnt/pcc.$tdir"
index e372de5..3491d6a 100644 (file)
@@ -11978,6 +11978,8 @@ static int lfs_pcc_state(int argc, char **argv)
                }
 
                printf(", PCC_file: %s", state.pccs_path);
+               if (state.pccs_flags & PCC_STATE_FL_UNLINKED)
+                       printf(" (unlinked)");
                printf(", open_count: %u", state.pccs_open_count);
                printf(", flags: %x", state.pccs_flags);
                printf("\n");