Whamcloud - gitweb
LU-10499 pcc: Check if PCC copy is unlinked for state output 51/54451/8
authorQian Yingjin <qian@ddn.com>
Wed, 29 Sep 2021 03:35:30 +0000 (11:35 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 2 Dec 2024 05:42:14 +0000 (05:42 +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.

Do not print an error message if "lfs pcc detach" tries to detach
a file that is already removed from the cache.  This might happen
for a wide variety of reasons (external cache cleanup process, etc).

EX-bug-id: EX-3825
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/c/fs/lustre-release/+/54451
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh
lustre/utils/lfs.c

index 64e47e8..308256e 100644 (file)
@@ -2401,10 +2401,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);
@@ -3235,8 +3239,8 @@ static int pcc_inode_remove(struct inode *inode, struct dentry *pcc_dentry)
        int rc;
 
        rc = vfs_unlink(&nop_mnt_idmap, d_inode(parent), pcc_dentry);
-       if (rc)
-               CWARN("%s: failed to unlink PCC file %pd, rc = %d\n",
+       if (rc && rc != -ENOENT)
+               CWARN("%s: failed to unlink PCC file %pd: rc = %d\n",
                      ll_i2sbi(inode)->ll_fsname, pcc_dentry, rc);
 
        dput(parent);
@@ -4208,6 +4212,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 (strscpy(state->pccs_path, path, buf_len) < 0)
                GOTO(out_unlock, rc = -ENAMETOOLONG);
 
index 28870a6..ef66f74 100755 (executable)
@@ -2807,11 +2807,13 @@ 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"
        do_facet $SINGLEAGT $LFS pcc detach -k $file ||
                error "RO-PCC detach $file failed"
        check_lpcc_state $file "none"
@@ -2819,10 +2821,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"
@@ -3653,6 +3656,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 local PCC cache"
+
 test_96() {
        local loopfile="$TMP/$tfile"
        local mntpt="/mnt/pcc.$tdir"
index 0843b0f..054ad65 100755 (executable)
@@ -14154,10 +14154,9 @@ static int lfs_pcc_detach(int argc, char **argv)
                }
 
                rc2 = llapi_pcc_detach_file(fullpath, detach_flags);
-               if (rc2 < 0) {
+               if (rc2 < 0 && rc2 != -ENOENT) {
                        rc2 = -errno;
-                       fprintf(stderr,
-                               "%s: cannot detach '%s' from PCC: %s\n",
+                       fprintf(stderr, "%s: cannot detach '%s' from PCC: %s\n",
                                argv[0], path, strerror(errno));
                        if (rc == 0)
                                rc = rc2;
@@ -14293,6 +14292,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");