From 91da7be2102f273b26c5e5e75022b35842f7e2e2 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Thu, 14 Sep 2023 05:23:41 -0400 Subject: [PATCH] EX-8236 pcc: abort in-progress attach by PCC detach command 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 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52375 Tested-by: jenkins Tested-by: Andreas Dilger Reviewed-by: Andreas Dilger --- lustre/doc/lfs-pcc-detach.1 | 9 ++++++--- lustre/doc/llapi_pcc_detach_fid_fd.3 | 4 ++++ lustre/include/uapi/linux/lustre/lustre_user.h | 4 ++++ lustre/llite/pcc.c | 20 ++++++++++++++------ lustre/utils/lfs.c | 22 +++++++++++++++------- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/lustre/doc/lfs-pcc-detach.1 b/lustre/doc/lfs-pcc-detach.1 index a2c698d..3a84c7f 100644 --- a/lustre/doc/lfs-pcc-detach.1 +++ b/lustre/doc/lfs-pcc-detach.1 @@ -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 diff --git a/lustre/doc/llapi_pcc_detach_fid_fd.3 b/lustre/doc/llapi_pcc_detach_fid_fd.3 index ec1db0c..9b4fa2f 100644 --- a/lustre/doc/llapi_pcc_detach_fid_fd.3 +++ b/lustre/doc/llapi_pcc_detach_fid_fd.3 @@ -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() , diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 647ae96..6b4b00a 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -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 { diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 12d0705..2bdd8b3 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -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; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 088bdd9..8d6b399 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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; -- 1.8.3.1