From 6654057165226980ba4aaf205f7689f31d3375b2 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Tue, 14 Mar 2023 10:02:12 +0800 Subject: [PATCH] LU-16637 llite: call truncate_inode_pages() under inode lock truncate_inode_pages() is required to be called under (and serialised by) inode lock. Lustre-change: https://review.whamcloud.com/50284 Lustre-commit: ef9be34478036db0544753e33030fff7e32bfe44 Signed-off-by: Bobi Jam Change-Id: I0f1a09c8756522f87a2e5d8030d12f80e2f630b4 Reviewed-by: Patrick Farrell Reviewed-by: Andreas Dilger Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50365 Tested-by: jenkins Tested-by: Maloo --- lustre/llite/llite_internal.h | 2 +- lustre/llite/llite_lib.c | 13 +++++++++---- lustre/llite/vvp_object.c | 9 ++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index f0eb8f0..e3a6651 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1360,7 +1360,7 @@ int ll_update_inode(struct inode *inode, struct lustre_md *md); void ll_update_inode_flags(struct inode *inode, int ext_flags); void ll_update_dir_depth(struct inode *dir, struct inode *inode); int ll_read_inode2(struct inode *inode, void *opaque); -void ll_truncate_inode_pages_final(struct inode *inode); +void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io); void ll_delete_inode(struct inode *inode); int ll_iocontrol(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 16c1d47..65725c1 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -2747,12 +2747,15 @@ void ll_update_dir_depth(struct inode *dir, struct inode *inode) PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth); } -void ll_truncate_inode_pages_final(struct inode *inode) +void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io) { struct address_space *mapping = &inode->i_data; unsigned long nrpages; unsigned long flags; + LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n", + io, io ? io->ci_type : 0); + truncate_inode_pages_final(mapping); /* Workaround for LU-118: Note nrpages may not be totally updated when @@ -2769,10 +2772,12 @@ void ll_truncate_inode_pages_final(struct inode *inode) ll_xa_unlock_irqrestore(&mapping->i_pages, flags); } /* Workaround end */ - LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, " + LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu " + "io %p (io_type %d), " "see https://jira.whamcloud.com/browse/LU-118\n", ll_i2sbi(inode)->ll_fsname, - PFID(ll_inode2fid(inode)), inode, nrpages); + PFID(ll_inode2fid(inode)), inode, nrpages, + io, io ? io->ci_type : 0); } int ll_read_inode2(struct inode *inode, void *opaque) @@ -2846,7 +2851,7 @@ void ll_delete_inode(struct inode *inode) CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1); } - ll_truncate_inode_pages_final(inode); + ll_truncate_inode_pages_final(inode, NULL); ll_clear_inode(inode); clear_inode(inode); diff --git a/lustre/llite/vvp_object.c b/lustre/llite/vvp_object.c index a2aa79a..f722780 100644 --- a/lustre/llite/vvp_object.c +++ b/lustre/llite/vvp_object.c @@ -157,6 +157,7 @@ static int vvp_conf_set(const struct lu_env *env, struct cl_object *obj, static int vvp_prune(const struct lu_env *env, struct cl_object *obj) { + struct cl_io *io = vvp_env_io(env)->vui_cl.cis_io; struct inode *inode = vvp_object_inode(obj); int rc; ENTRY; @@ -168,9 +169,15 @@ static int vvp_prune(const struct lu_env *env, struct cl_object *obj) RETURN(rc); } - ll_truncate_inode_pages_final(inode); + if (io != NULL) + inode_lock(inode); + + ll_truncate_inode_pages_final(inode, io); clear_bit(AS_EXITING, &inode->i_mapping->flags); + if (io != NULL) + inode_unlock(inode); + RETURN(0); } -- 1.8.3.1