NFS: Fix open coded versions of nfs_set_cache_invalid()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 8 Mar 2021 19:42:54 +0000 (14:42 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 8 Mar 2021 21:13:55 +0000 (16:13 -0500)
nfs_set_cache_invalid() has code to handle delegations, and other
optimisations, so let's use it when appropriate.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/dir.c
fs/nfs/inode.c
fs/nfs/unlink.c
fs/nfs/write.c

index 02ac982..fc4f490 100644 (file)
@@ -81,8 +81,9 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir
                spin_lock(&dir->i_lock);
                if (list_empty(&nfsi->open_files) &&
                    (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
-                       nfsi->cache_validity |= NFS_INO_INVALID_DATA |
-                               NFS_INO_REVAL_FORCED;
+                       nfs_set_cache_invalid(dir,
+                                             NFS_INO_INVALID_DATA |
+                                                     NFS_INO_REVAL_FORCED);
                list_add(&ctx->list, &nfsi->open_files);
                spin_unlock(&dir->i_lock);
                return ctx;
@@ -1700,10 +1701,9 @@ static void nfs_drop_nlink(struct inode *inode)
        if (inode->i_nlink > 0)
                drop_nlink(inode);
        NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter();
-       NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
-               | NFS_INO_INVALID_CTIME
-               | NFS_INO_INVALID_OTHER
-               | NFS_INO_REVAL_FORCED;
+       nfs_set_cache_invalid(
+               inode, NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME |
+                              NFS_INO_INVALID_OTHER | NFS_INO_REVAL_FORCED);
        spin_unlock(&inode->i_lock);
 }
 
@@ -1715,7 +1715,7 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
 {
        if (S_ISDIR(inode->i_mode))
                /* drop any readdir cache as it could easily be old */
-               NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
+               nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
 
        if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
                nfs_complete_unlink(dentry, inode);
@@ -2481,9 +2481,9 @@ int nfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
        if (error == 0) {
                spin_lock(&old_inode->i_lock);
                NFS_I(old_inode)->attr_gencount = nfs_inc_attr_generation_counter();
-               NFS_I(old_inode)->cache_validity |= NFS_INO_INVALID_CHANGE
-                       | NFS_INO_INVALID_CTIME
-                       | NFS_INO_REVAL_FORCED;
+               nfs_set_cache_invalid(old_inode, NFS_INO_INVALID_CHANGE |
+                                                        NFS_INO_INVALID_CTIME |
+                                                        NFS_INO_REVAL_FORCED);
                spin_unlock(&old_inode->i_lock);
        }
 out:
index d21bfaa..eb1ae77 100644 (file)
@@ -1067,8 +1067,8 @@ void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
        spin_lock(&inode->i_lock);
        if (list_empty(&nfsi->open_files) &&
            (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
-               nfsi->cache_validity |= NFS_INO_INVALID_DATA |
-                       NFS_INO_REVAL_FORCED;
+               nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA |
+                                                    NFS_INO_REVAL_FORCED);
        list_add_tail_rcu(&ctx->list, &nfsi->open_files);
        spin_unlock(&inode->i_lock);
 }
index b27ebdc..5fa11e1 100644 (file)
@@ -500,9 +500,9 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
                nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
                spin_lock(&inode->i_lock);
                NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter();
-               NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
-                       | NFS_INO_INVALID_CTIME
-                       | NFS_INO_REVAL_FORCED;
+               nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE |
+                                                    NFS_INO_INVALID_CTIME |
+                                                    NFS_INO_REVAL_FORCED);
                spin_unlock(&inode->i_lock);
                d_move(dentry, sdentry);
                break;
index 82bdcb9..f05a903 100644 (file)
@@ -303,9 +303,9 @@ static void nfs_set_pageerror(struct address_space *mapping)
        nfs_zap_mapping(mapping->host, mapping);
        /* Force file size revalidation */
        spin_lock(&inode->i_lock);
-       NFS_I(inode)->cache_validity |= NFS_INO_REVAL_FORCED |
-                                       NFS_INO_REVAL_PAGECACHE |
-                                       NFS_INO_INVALID_SIZE;
+       nfs_set_cache_invalid(inode, NFS_INO_REVAL_FORCED |
+                                            NFS_INO_REVAL_PAGECACHE |
+                                            NFS_INO_INVALID_SIZE);
        spin_unlock(&inode->i_lock);
 }
 
@@ -1604,7 +1604,7 @@ static int nfs_writeback_done(struct rpc_task *task,
        /* Deal with the suid/sgid bit corner case */
        if (nfs_should_remove_suid(inode)) {
                spin_lock(&inode->i_lock);
-               NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER;
+               nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
                spin_unlock(&inode->i_lock);
        }
        return 0;