From 6b8270f4a932d8e2c0875444f7ad5e33f766d153 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Tue, 11 May 2021 11:38:36 +0800 Subject: [PATCH] LU-10499 pcc: keep PCC copy when it is being attached When detach a file from PCC backend via FID, if the file is being attached, it should not purge the coresponding PCC copy from the PCC backend. Just keep the PCC copy to finish the attach process. EX-3144 pcc: revalidate the pointer after attach In this patch, we also fix a bug during PCC open attach. It refreshes @pcci pointer since the lock may be released in @pcc_try_readonly_open_attach(). Was-Change-Id: I470358dfde525e08e7110e862b30b527e5db94fe EX-bug-id: EX-3133 EX-3144 Signed-off-by: Qian Yingjin Change-Id: I8a8f7c6986d51eaf9b2516e5dd5a6f21aa38b7db Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54389 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Li Xi Reviewed-by: Oleg Drokin --- lustre/include/uapi/linux/lustre/lustre_user.h | 2 ++ lustre/llite/pcc.c | 11 +++++++---- lustre/utils/liblustreapi_pcc.c | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 3904e44..46cede1 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -3004,6 +3004,8 @@ enum lu_pcc_detach_flags { PCC_DETACH_FL_KNOWN_READONLY = 0x04, /* Indicate PCC cached copy is removed */ PCC_DETACH_FL_CACHE_REMOVED = 0x08, + /* Indicate the file is being attached */ + PCC_DETACH_FL_ATTACHING = 0x10, }; struct lu_pcc_detach_fid { diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index dd08925..a1a1df0 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -2262,8 +2262,7 @@ int pcc_file_open(struct inode *inode, struct file *file) if (rc < 0 || !cached) GOTO(out_unlock, rc); - if (!pcci) - pcci = ll_i2pcci(inode); + pcci = ll_i2pcci(inode); } pcc_inode_get(pcci); @@ -3925,8 +3924,12 @@ int pcc_ioctl_detach(struct inode *inode, __u32 *flags) pcc_inode_lock(inode); pcci = lli->lli_pcc_inode; - if (!pcci || lli->lli_pcc_state & PCC_STATE_FL_ATTACHING || - !pcc_inode_has_layout(pcci)) + if (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING) { + *flags |= PCC_DETACH_FL_ATTACHING; + GOTO(out_unlock, rc = 0); + } + + if (!pcci || !pcc_inode_has_layout(pcci)) GOTO(out_unlock, rc = 0); LASSERT(atomic_read(&pcci->pcci_refcount) > 0); diff --git a/lustre/utils/liblustreapi_pcc.c b/lustre/utils/liblustreapi_pcc.c index 9e6710b..0376e76 100644 --- a/lustre/utils/liblustreapi_pcc.c +++ b/lustre/utils/liblustreapi_pcc.c @@ -609,6 +609,9 @@ static int llapi_pcc_scan_detach(const char *pname, const char *fname, llapi_printf(LLAPI_MSG_DEBUG, "Detach and remove the PCC cached file: %s\n", fidname); + } else if (detach.pccd_flags & PCC_DETACH_FL_ATTACHING) { + llapi_printf(LLAPI_MSG_DEBUG, + "'%s' is being attached, skip it", fidname); } else { snprintf(fullname, sizeof(fullname), "%s/%s", pname, fidname); llapi_printf(LLAPI_MSG_DEBUG, -- 1.8.3.1