From 80094070c66338d70f01fe6f279f3314bd0849d7 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Thu, 14 Sep 2023 02:43:32 -0400 Subject: [PATCH] EX-8027 pcc: wait for attach finished for detach command 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 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52373 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/uapi/linux/lustre/lustre_user.h | 2 ++ lustre/llite/pcc.c | 12 ++++++++++++ lustre/utils/libhsm_scanner.h | 1 + lustre/utils/liblustreapi_pcc.c | 9 ++++++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index b8ec843..647ae96 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -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 { diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 0f8562c..12d0705 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -107,6 +107,7 @@ #include "pcc.h" #include #include +#include #include #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); } diff --git a/lustre/utils/libhsm_scanner.h b/lustre/utils/libhsm_scanner.h index 4dea572..3d33096 100644 --- a/lustre/utils/libhsm_scanner.h +++ b/lustre/utils/libhsm_scanner.h @@ -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); diff --git a/lustre/utils/liblustreapi_pcc.c b/lustre/utils/liblustreapi_pcc.c index b7a2647..78230a7 100644 --- a/lustre/utils/liblustreapi_pcc.c +++ b/lustre/utils/liblustreapi_pcc.c @@ -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) { -- 1.8.3.1