For NFS, we only want to make a decision whether to "use" a inode based fscache cookie one time, not multiple times, and based on whether the inode is open for write by any process. Achieve this by gating the call to fscache_use_cookie / fscache_unuse_cookie by the NFS_INO_FSCACHE flag on the nfs_inode. Signed-off-by: Dave Wysochanski <dwysocha@xxxxxxxxxx> --- fs/nfs/fscache.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c index 1c4ced273fb7..00bb720cccfa 100644 --- a/fs/nfs/fscache.c +++ b/fs/nfs/fscache.c @@ -285,8 +285,10 @@ void nfs_fscache_clear_inode(struct inode *inode) dfprintk(FSCACHE, "NFS: clear cookie (0x%p/0x%p)\n", nfsi, cookie); - nfs_fscache_update_auxdata(&auxdata, nfsi); - fscache_unuse_cookie(cookie, &auxdata, NULL); + if (test_and_clear_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags)) { + nfs_fscache_update_auxdata(&auxdata, nfsi); + fscache_unuse_cookie(cookie, &auxdata, NULL); + } fscache_relinquish_cookie(cookie, false); nfsi->fscache = NULL; } @@ -321,18 +323,23 @@ void nfs_fscache_open_file(struct inode *inode, struct file *filp) { struct nfs_inode *nfsi = NFS_I(inode); struct fscache_cookie *cookie = nfs_i_fscache(inode); + struct nfs_fscache_inode_auxdata auxdata; if (!fscache_cookie_valid(cookie)) return; if (inode_is_open_for_write(inode)) { - dfprintk(FSCACHE, "NFS: nfsi 0x%p disabling cache\n", nfsi); - clear_bit(NFS_INO_FSCACHE, &nfsi->flags); + if (test_and_clear_bit(NFS_INO_FSCACHE, &nfsi->flags)) { + dfprintk(FSCACHE, "NFS: nfsi 0x%p disabling cache\n", nfsi); + nfs_fscache_update_auxdata(&auxdata, nfsi); + fscache_unuse_cookie(cookie, &auxdata, NULL); + } } else { - dfprintk(FSCACHE, "NFS: nfsi 0x%p enabling cache\n", nfsi); - set_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags); + if (!test_and_set_bit(NFS_INO_FSCACHE, &nfsi->flags)) { + dfprintk(FSCACHE, "NFS: nfsi 0x%p enabling cache\n", nfsi); + fscache_use_cookie(cookie, false); + } } - fscache_use_cookie(cookie, false); } EXPORT_SYMBOL_GPL(nfs_fscache_open_file); -- 1.8.3.1