Whamcloud - gitweb
LU-14677 llite: move env contexts to ll_inode_info level 98/44198/11
authorSebastien Buisson <sbuisson@ddn.com>
Fri, 9 Jul 2021 13:41:34 +0000 (15:41 +0200)
committerOleg Drokin <green@whamcloud.com>
Wed, 22 Sep 2021 04:43:17 +0000 (04:43 +0000)
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 <sbuisson@ddn.com>
Change-Id: I478d2a8eabfcb09074ba52601f05840d047a6da2
Reviewed-on: https://review.whamcloud.com/44198
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/acl.c
lustre/llite/file.c
lustre/llite/llite_internal.h
lustre/llite/llite_lib.c
lustre/llite/llite_mmap.c
lustre/llite/rw.c
lustre/llite/rw26.c
lustre/llite/xattr.c

index 515ac72..7e5b1f0 100644 (file)
@@ -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);
 }
index 0021c76..98f5de3 100644 (file)
@@ -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",
index f567d16..e2b9174 100644 (file)
@@ -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;
 
index 5c88bb2..2df83df 100644 (file)
@@ -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
index 963aa07..982002c 100644 (file)
@@ -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)
index 3d69fec..1af37f2 100644 (file)
@@ -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;
index 6fb6d53..e959e6b 100644 (file)
@@ -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);
index 25889f7..a8628f3 100644 (file)
@@ -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);