From: Sebastien Buisson Date: Fri, 9 Jul 2021 13:41:34 +0000 (+0200) Subject: LU-14677 llite: move env contexts to ll_inode_info level X-Git-Tag: 2.14.55~20 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=957e7de61ec129013ba0df90c3abe64ff024e438 LU-14677 llite: move env contexts to ll_inode_info level Contrary to file, inode is always available, so move the list of env contexts from the file data to the ll_inode_info level. This is needed because we will have to handle env properties in ll_get_context() and ll_xattr_list()/ll_listxattr(). This also requires changing lli_lock from a spinlock to an rwlock. Signed-off-by: Sebastien Buisson Change-Id: I478d2a8eabfcb09074ba52601f05840d047a6da2 Reviewed-on: https://review.whamcloud.com/44198 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/acl.c b/lustre/llite/acl.c index 515ac72..7e5b1f0 100644 --- a/lustre/llite/acl.c +++ b/lustre/llite/acl.c @@ -44,10 +44,10 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type) struct posix_acl *acl = NULL; ENTRY; - spin_lock(&lli->lli_lock); + read_lock(&lli->lli_lock); /* VFS' acl_permission_check->check_acl will release the refcount */ acl = posix_acl_dup(lli->lli_posix_acl); - spin_unlock(&lli->lli_lock); + read_unlock(&lli->lli_lock); RETURN(acl); } diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 0021c76..98f5de3 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -758,10 +758,6 @@ static int ll_local_open(struct file *file, struct lookup_intent *it, /* turn off the kernel's read-ahead */ file->f_ra.ra_pages = 0; - /* ll_cl_context initialize */ - rwlock_init(&fd->fd_lock); - INIT_LIST_HEAD(&fd->fd_lccs); - RETURN(0); } @@ -1706,9 +1702,9 @@ restart: range_locked = true; } - ll_cl_add(file, env, io, LCC_RW); + ll_cl_add(inode, env, io, LCC_RW); rc = cl_io_loop(env, io); - ll_cl_remove(file, env); + ll_cl_remove(inode, env); if (range_locked && !is_parallel_dio) { CDEBUG(D_VFSTRACE, "Range unlock "RL_FMT"\n", diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index f567d16..e2b9174 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -115,7 +115,7 @@ struct ll_trunc_sem { struct ll_inode_info { __u32 lli_inode_magic; - spinlock_t lli_lock; + rwlock_t lli_lock; volatile unsigned long lli_flags; struct posix_acl *lli_posix_acl; @@ -269,6 +269,7 @@ struct ll_inode_info { struct rw_semaphore lli_xattrs_list_rwsem; struct mutex lli_xattrs_enq_lock; struct list_head lli_xattrs; /* ll_xattr_entry->xe_list */ + struct list_head lli_lccs; /* list of ll_cl_context */ }; static inline void ll_trunc_sem_init(struct ll_trunc_sem *sem) @@ -364,11 +365,11 @@ static inline void lli_clear_acl(struct ll_inode_info *lli) static inline void lli_replace_acl(struct ll_inode_info *lli, struct lustre_md *md) { - spin_lock(&lli->lli_lock); + write_lock(&lli->lli_lock); if (lli->lli_posix_acl) posix_acl_release(lli->lli_posix_acl); lli->lli_posix_acl = md->posix_acl; - spin_unlock(&lli->lli_lock); + write_unlock(&lli->lli_lock); } #else static inline void lli_clear_acl(struct ll_inode_info *lli) @@ -929,8 +930,6 @@ struct ll_file_data { * false: unknown failure, should report. */ bool fd_write_failed; bool ll_lock_no_expand; - rwlock_t fd_lock; /* protect lcc list */ - struct list_head fd_lccs; /* list of ll_cl_context */ /* Used by mirrored file to lead IOs to a specific mirror, usually * for mirror resync. 0 means default. */ __u32 fd_designated_mirror; @@ -1095,10 +1094,10 @@ void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras); int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io); enum lcc_type; -void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io, +void ll_cl_add(struct inode *inode, const struct lu_env *env, struct cl_io *io, enum lcc_type type); -void ll_cl_remove(struct file *file, const struct lu_env *env); -struct ll_cl_context *ll_cl_find(struct file *file); +void ll_cl_remove(struct inode *inode, const struct lu_env *env); +struct ll_cl_context *ll_cl_find(struct inode *inode); extern const struct address_space_operations ll_aops; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 5c88bb2..2df83df 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -1109,7 +1109,7 @@ void ll_lli_init(struct ll_inode_info *lli) { lli->lli_inode_magic = LLI_INODE_MAGIC; lli->lli_flags = 0; - spin_lock_init(&lli->lli_lock); + rwlock_init(&lli->lli_lock); lli->lli_posix_acl = NULL; /* Do not set lli_fid, it has been initialized already. */ fid_zero(&lli->lli_pfid); @@ -1161,6 +1161,8 @@ void ll_lli_init(struct ll_inode_info *lli) } mutex_init(&lli->lli_layout_mutex); memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid)); + /* ll_cl_context initialize */ + INIT_LIST_HEAD(&lli->lli_lccs); } #define MAX_STRING_SIZE 128 diff --git a/lustre/llite/llite_mmap.c b/lustre/llite/llite_mmap.c index 963aa07..982002c 100644 --- a/lustre/llite/llite_mmap.c +++ b/lustre/llite/llite_mmap.c @@ -263,6 +263,7 @@ static inline int to_fault_error(int result) */ static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) { + struct inode *inode = file_inode(vma->vm_file); struct lu_env *env; struct cl_io *io; struct vvp_io *vio = NULL; @@ -276,15 +277,15 @@ static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) if (IS_ERR(env)) RETURN(PTR_ERR(env)); - if (ll_sbi_has_fast_read(ll_i2sbi(file_inode(vma->vm_file)))) { + if (ll_sbi_has_fast_read(ll_i2sbi(inode))) { /* do fast fault */ bool has_retry = vmf->flags & FAULT_FLAG_RETRY_NOWAIT; /* To avoid loops, instruct downstream to not drop mmap_sem */ vmf->flags |= FAULT_FLAG_RETRY_NOWAIT; - ll_cl_add(vma->vm_file, env, NULL, LCC_MMAP); + ll_cl_add(inode, env, NULL, LCC_MMAP); fault_ret = ll_filemap_fault(vma, vmf); - ll_cl_remove(vma->vm_file, env); + ll_cl_remove(inode, env); if (!has_retry) vmf->flags &= ~FAULT_FLAG_RETRY_NOWAIT; @@ -306,8 +307,6 @@ static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) result = io->ci_result; if (result == 0) { - struct file *vm_file = vma->vm_file; - vio = vvp_env_io(env); vio->u.fault.ft_vma = vma; vio->u.fault.ft_vmpage = NULL; @@ -315,15 +314,13 @@ static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) vio->u.fault.ft_flags = 0; vio->u.fault.ft_flags_valid = 0; - get_file(vm_file); - /* May call ll_readpage() */ - ll_cl_add(vm_file, env, io, LCC_MMAP); + ll_cl_add(inode, env, io, LCC_MMAP); result = cl_io_loop(env, io); - ll_cl_remove(vm_file, env); - fput(vm_file); + ll_cl_remove(inode, env); + /* ft_flags are only valid if we reached * the call to filemap_fault */ if (vio->u.fault.ft_flags_valid) diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 3d69fec..1af37f2 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -1566,28 +1566,28 @@ int ll_writepages(struct address_space *mapping, struct writeback_control *wbc) RETURN(result); } -struct ll_cl_context *ll_cl_find(struct file *file) +struct ll_cl_context *ll_cl_find(struct inode *inode) { - struct ll_file_data *fd = file->private_data; + struct ll_inode_info *lli = ll_i2info(inode); struct ll_cl_context *lcc; struct ll_cl_context *found = NULL; - read_lock(&fd->fd_lock); - list_for_each_entry(lcc, &fd->fd_lccs, lcc_list) { + read_lock(&lli->lli_lock); + list_for_each_entry(lcc, &lli->lli_lccs, lcc_list) { if (lcc->lcc_cookie == current) { found = lcc; break; } } - read_unlock(&fd->fd_lock); + read_unlock(&lli->lli_lock); return found; } -void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io, +void ll_cl_add(struct inode *inode, const struct lu_env *env, struct cl_io *io, enum lcc_type type) { - struct ll_file_data *fd = file->private_data; + struct ll_inode_info *lli = ll_i2info(inode); struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx; memset(lcc, 0, sizeof(*lcc)); @@ -1597,19 +1597,19 @@ void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io, lcc->lcc_io = io; lcc->lcc_type = type; - write_lock(&fd->fd_lock); - list_add(&lcc->lcc_list, &fd->fd_lccs); - write_unlock(&fd->fd_lock); + write_lock(&lli->lli_lock); + list_add(&lcc->lcc_list, &lli->lli_lccs); + write_unlock(&lli->lli_lock); } -void ll_cl_remove(struct file *file, const struct lu_env *env) +void ll_cl_remove(struct inode *inode, const struct lu_env *env) { - struct ll_file_data *fd = file->private_data; + struct ll_inode_info *lli = ll_i2info(inode); struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx; - write_lock(&fd->fd_lock); + write_lock(&lli->lli_lock); list_del_init(&lcc->lcc_list); - write_unlock(&fd->fd_lock); + write_unlock(&lli->lli_lock); } int ll_io_read_page(const struct lu_env *env, struct cl_io *io, @@ -1824,7 +1824,7 @@ int ll_readpage(struct file *file, struct page *vmpage) int result; ENTRY; - lcc = ll_cl_find(file); + lcc = ll_cl_find(inode); if (lcc != NULL) { env = lcc->lcc_env; io = lcc->lcc_io; diff --git a/lustre/llite/rw26.c b/lustre/llite/rw26.c index 6fb6d53..e959e6b 100644 --- a/lustre/llite/rw26.c +++ b/lustre/llite/rw26.c @@ -463,7 +463,7 @@ ll_direct_IO_impl(struct kiocb *iocb, struct iov_iter *iter, int rw) if (ll_iov_iter_alignment(iter) & ~PAGE_MASK) RETURN(-EINVAL); - lcc = ll_cl_find(file); + lcc = ll_cl_find(inode); if (lcc == NULL) RETURN(-EIO); @@ -661,7 +661,7 @@ static int ll_write_begin(struct file *file, struct address_space *mapping, const struct lu_env *env = NULL; struct cl_io *io = NULL; struct cl_page *page = NULL; - + struct inode *inode = file_inode(file); struct cl_object *clob = ll_i2info(mapping->host)->lli_clob; pgoff_t index = pos >> PAGE_SHIFT; struct page *vmpage = NULL; @@ -672,7 +672,7 @@ static int ll_write_begin(struct file *file, struct address_space *mapping, CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len); - lcc = ll_cl_find(file); + lcc = ll_cl_find(inode); if (lcc == NULL) { vmpage = grab_cache_page_nowait(mapping, index); result = ll_tiny_write_begin(vmpage, mapping); diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index 25889f7..a8628f3 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -466,9 +466,9 @@ static int ll_xattr_get_common(const struct xattr_handler *handler, struct ll_inode_info *lli = ll_i2info(inode); struct posix_acl *acl; - spin_lock(&lli->lli_lock); + read_lock(&lli->lli_lock); acl = posix_acl_dup(lli->lli_posix_acl); - spin_unlock(&lli->lli_lock); + read_unlock(&lli->lli_lock); if (!acl) RETURN(-ENODATA);