Whamcloud - gitweb
EX-8236 pcc: abort in-progress attach by PCC detach command
authorQian Yingjin <qian@ddn.com>
Thu, 14 Sep 2023 09:23:41 +0000 (05:23 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 27 Oct 2023 21:50:37 +0000 (21:50 +0000)
A user may want to abort in-progress attach for some purposes such
as freeing space for PCC backend.
To support this operation, we add an "abort" option for PCC detach
command to abort the in-progress attach.

Change-Id: I49fb1c42838f8d7e9728a5c4c6f3d60e959b233b
Signed-off-by: Qian Yingjin <qian@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52375
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/doc/lfs-pcc-detach.1
lustre/doc/llapi_pcc_detach_fid_fd.3
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/pcc.c
lustre/utils/lfs.c

index a2c698d..3a84c7f 100644 (file)
@@ -2,9 +2,9 @@
 .SH NAME
 lfs pcc detach|detach_fid \- Detach given files from PCC
 .SH SYNOPSIS
-.B lfs pcc detach \fR[\fB--keep\fR|\fB-k\fR] [\fB--wait\fR|\fB-w\fR] \fR<\fIFILE ...\fR>
+.B lfs pcc detach \fR[\fB--keep\fR|\fB-k\fR] [\fB--wait\fR|\fB-w\fR] [\fB--abort\fR|\fB-a\fR] \fR<\fIFILE ...\fR>
 .br
-.B lfs pcc detach_fid \fR[\fB--keep\fR|\fB-k\fR] [\fB--wait\fR|\fB-w\fR]\fB \fR<\fB--mnt\fR|\fB-m \fIMNTPATH\fR> <\fIFID ...\fR>
+.B lfs pcc detach_fid \fR[\fB--keep\fR|\fB-k\fR] [\fB--wait\fR|\fB-w\fR] [\fB--abort\fR|\fB-a\fR] \fR<\fB--mnt\fR|\fB-m \fIMNTPATH\fR> <\fIFID ...\fR>
 .SH DESCRIPTION
 Detach specified
 .I FILE
@@ -22,7 +22,10 @@ It allows the detached file to be attached
 automatically at next open if the cached copy of the file is still valid.
 .TP
 .BR --wait | -w
-Indicate to wait for the in-pregress attach finished during detach.
+Indicate to wait for the in-progress attach finished during detach.
+.TP
+.BR --abort | -a
+Indicate to abort the in-progress attach during detach.
 .TP
 .BR --mnt | -m
 Specify the Lustre client mountpoint for the file
index ec1db0c..9b4fa2f 100644 (file)
@@ -50,6 +50,7 @@ data structure, which contains the following values:
        PCC_DETACH_FL_CACHE_REMOVED     = 0x08,
        PCC_DETACH_FL_ATTACHING         = 0x10,
        PCC_DETACH_FL_ATTACHING_WAIT    = 0x20,
+       PCC_DETACH_FL_ATTACH_ABORT      = 0x40,
 .fi
 .TP
 PCC_DETACH_FL_NONE
@@ -73,6 +74,9 @@ indicates that the file is being attached.
 .TP
 PCC_DETACH_FL_ATTACHING_WAIT
 indicates to wait the in-progress attach finished.
+.TP
+PCC_DETACH_FL_ATTACH_ABORT
+indicates to abort the in-progress attach during detach.
 .SH RETURN VALUES
 .LP
 .BR llapi_pcc_detach_fid_fd() ,
index 647ae96..6b4b00a 100644 (file)
@@ -2873,6 +2873,8 @@ enum lu_pcc_detach_flags {
        PCC_DETACH_FL_ATTACHING         = 0x10,
        /* Indicate to wait the attach process finished */
        PCC_DETACH_FL_ATTACHING_WAIT    = 0x20,
+       /* Indicate to abort the in-progress attach during detach */
+       PCC_DETACH_FL_ATTACH_ABORT      = 0x40,
 };
 
 struct lu_pcc_detach_fid {
@@ -2895,6 +2897,8 @@ enum lu_pcc_state_flags {
        PCC_STATE_FL_UNLINKED           = 0x04,
        /* The file is detached, but PCC copy is still valid cached */
        PCC_STATE_FL_CACHE_VALID        = 0x08,
+       /* The user tries to abort the in-progress attach */
+       PCC_STATE_FL_ATTACH_ABORTING    = 0x10,
 };
 
 struct lu_pcc_state {
index 12d0705..2bdd8b3 100644 (file)
@@ -3835,6 +3835,7 @@ static ssize_t pcc_copy_data_buffered(struct file *src, struct file *dst)
 {
        size_t buf_len = PCC_COPY_BUFFER_BYTES;
        struct inode *inode = file_inode(src);
+       struct ll_inode_info *lli = ll_i2info(inode);
        loff_t offset = 0;
        ssize_t rc = 0;
        ssize_t rc2;
@@ -3860,6 +3861,9 @@ static ssize_t pcc_copy_data_buffered(struct file *src, struct file *dst)
                if (signal_pending(current))
                        GOTO(out_free, rc = -EINTR);
 
+               if (lli->lli_pcc_state & PCC_STATE_FL_ATTACH_ABORTING)
+                       GOTO(out_free, rc = -ECANCELED);
+
                pos = offset;
                if (inode && IS_ENCRYPTED(inode))
                        /* Setting the S_PCCCOPY flag prevents the Lustre file
@@ -4525,18 +4529,22 @@ int pcc_ioctl_detach(struct inode *inode, __u32 *flags)
 
        ENTRY;
 
-repeat:
        pcc_inode_lock(inode);
+repeat:
        pcci = ll_i2pcci(inode);
        if (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING) {
-               if (*flags & PCC_DETACH_FL_ATTACHING_WAIT) {
+               if (*flags & (PCC_DETACH_FL_ATTACHING_WAIT |
+                             PCC_DETACH_FL_ATTACH_ABORT)) {
+                       if (*flags & PCC_DETACH_FL_ATTACH_ABORT)
+                               lli->lli_pcc_state |=
+                                       PCC_STATE_FL_ATTACH_ABORTING;
                        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);
+                       pcc_inode_lock(inode);
+                       if (*flags & PCC_DETACH_FL_ATTACH_ABORT)
+                               lli->lli_pcc_state &=
+                                       ~PCC_STATE_FL_ATTACH_ABORTING;
                        GOTO(repeat, rc);
                }
                *flags |= PCC_DETACH_FL_ATTACHING;
index 088bdd9..8d6b399 100644 (file)
@@ -13259,10 +13259,11 @@ static int lfs_pcc_attach_fid(int argc, char **argv)
 static int lfs_pcc_detach(int argc, char **argv)
 {
        struct option long_opts[] = {
-       { .val = 'k',   .name = "keep", .has_arg = no_argument },
-       { .val = 'w',   .name = "wait", .has_arg = no_argument },
+       { .val = 'k',   .name = "keep",         .has_arg = no_argument },
+       { .val = 'w',   .name = "wait",         .has_arg = no_argument },
+       { .val = 'a',   .name = "abort",        .has_arg = no_argument },
        { .name = NULL } };
-       char                     short_opts[] = "kw";
+       char                     short_opts[] = "kwa";
        int                      c;
        int                      rc = 0;
        const char              *path;
@@ -13279,6 +13280,9 @@ static int lfs_pcc_detach(int argc, char **argv)
                case 'w':
                        detach_flags |= PCC_DETACH_FL_ATTACHING_WAIT;
                        break;
+               case 'a':
+                       detach_flags |= PCC_DETACH_FL_ATTACH_ABORT;
+                       break;
                case '?':
                        return CMD_HELP;
                default:
@@ -13320,11 +13324,12 @@ static int lfs_pcc_detach(int argc, char **argv)
 static int lfs_pcc_detach_fid(int argc, char **argv)
 {
        struct option long_opts[] = {
-       { .val = 'k',   .name = "keep", .has_arg = no_argument },
-       { .val = 'w',   .name = "wait", .has_arg = no_argument },
-       { .val = 'm',   .name = "mnt",  .has_arg = required_argument },
+       { .val = 'k',   .name = "keep",         .has_arg = no_argument },
+       { .val = 'w',   .name = "wait",         .has_arg = no_argument },
+       { .val = 'a',   .name = "abort",        .has_arg = no_argument },
+       { .val = 'm',   .name = "mnt",          .has_arg = required_argument },
        { .name = NULL } };
-       char short_opts[] = "kwm:";
+       char short_opts[] = "kwam:";
        const char *mntpath = NULL;
        const char *fidstr;
        __u32 detach_flags = PCC_DETACH_FL_UNCACHE;
@@ -13342,6 +13347,9 @@ static int lfs_pcc_detach_fid(int argc, char **argv)
                case 'w':
                        detach_flags |= PCC_DETACH_FL_ATTACHING_WAIT;
                        break;
+               case 'a':
+                       detach_flags |= PCC_DETACH_FL_ATTACH_ABORT;
+                       break;
                case 'm':
                        mntpath = optarg;
                        break;