Whamcloud - gitweb
EX-8027 pcc: wait for attach finished for detach command
authorQian Yingjin <qian@ddn.com>
Thu, 14 Sep 2023 06:43:32 +0000 (02:43 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 27 Oct 2023 21:50:14 +0000 (21:50 +0000)
When detach a file from a PCC backend, this file may be still
attaching state. At this time, we add a flag to wait for the
attach finished (PCC_DEATCH_FL_ATTACHING_WAIT). After that, retry
the detach.

Change-Id: If85d95be744e3f7d6a07f880e78de5b68b579ed6
Signed-off-by: Qian Yingjin <qian@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52373
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/pcc.c
lustre/utils/libhsm_scanner.h
lustre/utils/liblustreapi_pcc.c

index b8ec843..647ae96 100644 (file)
@@ -2871,6 +2871,8 @@ enum lu_pcc_detach_flags {
        PCC_DETACH_FL_CACHE_REMOVED     = 0x08,
        /* Indicate the file is being attached */
        PCC_DETACH_FL_ATTACHING         = 0x10,
+       /* Indicate to wait the attach process finished */
+       PCC_DETACH_FL_ATTACHING_WAIT    = 0x20,
 };
 
 struct lu_pcc_detach_fid {
index 0f8562c..12d0705 100644 (file)
 #include "pcc.h"
 #include <linux/namei.h>
 #include <linux/file.h>
+#include <linux/delay.h>
 #include <lustre_compat.h>
 #include "llite_internal.h"
 
@@ -4524,9 +4525,20 @@ int pcc_ioctl_detach(struct inode *inode, __u32 *flags)
 
        ENTRY;
 
+repeat:
        pcc_inode_lock(inode);
        pcci = ll_i2pcci(inode);
        if (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING) {
+               if (*flags & PCC_DETACH_FL_ATTACHING_WAIT) {
+                       pcc_inode_unlock(inode);
+                       /*
+                        * TODO: Add a flag to indicate aborting the PCC
+                        * attach process.
+                        */
+                       while (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING)
+                               msleep(125);
+                       GOTO(repeat, rc);
+               }
                *flags |= PCC_DETACH_FL_ATTACHING;
                GOTO(out_unlock, rc = 0);
        }
index 4dea572..3d33096 100644 (file)
@@ -44,6 +44,7 @@ struct hsm_scan_control {
        hsm_scan_func_t          hsc_func;
        int                      hsc_errnum;
        int                      hsc_mntfd;
+       __u32                    hsc_flags;
 };
 
 int hsm_scan_process(struct hsm_scan_control *hsc);
index b7a2647..78230a7 100644 (file)
@@ -573,7 +573,7 @@ static int llapi_pcc_scan_detach(const char *pname, const char *fname,
        int rc;
 
        /* It is the saved lov file when archive on HSM backend. */
-       detach.pccd_flags = PCC_DETACH_FL_UNCACHE;
+       detach.pccd_flags = hsc->hsc_flags | PCC_DETACH_FL_UNCACHE;
        lov_file = endswith(fname, ".lov");
        if (lov_file) {
                size_t len;
@@ -652,15 +652,18 @@ static int llapi_pcc_del_internal(const char *mntpath, const char *pccpath,
                .hsc_mntfd = -1,
                .hsc_func = llapi_pcc_scan_detach,
                .hsc_errnum = 0,
+               .hsc_flags = 0,
        };
        char cmd[PATH_MAX];
        int rc;
 
-       if (flags & PCC_CLEANUP_FL_WAIT)
+       if (flags & PCC_CLEANUP_FL_WAIT) {
                snprintf(cmd, sizeof(cmd), "%s %s",
                         PCC_CMDNAME_DEL_WAIT, pccpath);
-       else
+               hsc.hsc_flags = PCC_DETACH_FL_ATTACHING_WAIT;
+       } else {
                snprintf(cmd, sizeof(cmd), "%s %s", PCC_CMDNAME_DEL, pccpath);
+       }
 
        rc = llapi_pccdev_set(mntpath, cmd);
        if (rc < 0) {