NFS: Don't revalidate the directory permissions on a lookup failure
Subsystems (2)
[email protected]
maintainerPATCH v2 1/5 NFS: Don't revalidate the directory permissions on a lookup failure
From: Trond Myklebust <[email protected]>
There should be no reason to expect the directory permissions to change just because the directory contents changed or a negative lookup timed out. So let's avoid doing a full call to nfs_mark_for_revalidate() in that case.
Furthermore, if this is a negative dentry, and we haven't actually done a new lookup, then we have no reason yet to believe the directory has changed at all. So let's remove the gratuitous directory inode invalidation altogether when called from nfs_lookup_revalidate_negative().
--- fs/nfs/dir.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
fs/nfs/dir.c +17 -3
@@ -1401,6 +1401,15 @@ int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags) goto out; } +static void nfs_mark_dir_for_revalidate (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +spin_lock (&inode->i_lock); + nfsi->cache_validity |=NFS_INO_REVAL_PAGECACHE ; +spin_unlock (&inode->i_lock); +} +/* * We judge how long we want to trust negative * dentries by looking at the parent inode mtime.
@@ -1435,7 +1444,6 @@ nfs_lookup_revalidate_done(struct inode *dir, struct dentry *dentry, __func__, dentry);return 1 ;case 0 : -nfs_mark_for_revalidate (dir);if (inode &&S_ISDIR (inode->i_mode)) {/* Purge readdir caches. */ nfs_zap_caches (inode);
@@ -1525,6 +1533,13 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,nfs_free_fattr (fattr);nfs_free_fhandle (fhandle);nfs4_label_free (label); + +/* +* If the lookup failed despite the dentry change attribute being +* a match, then we should revalidate the directory cache. +*/ +if (!ret &&nfs_verify_change_attribute (dir, dentry->d_time)) +nfs_mark_dir_for_revalidate (dir);return nfs_lookup_revalidate_done (dir, dentry, inode, ret); }
@@ -1567,7 +1582,7 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, error =nfs_lookup_verify_inode (inode, flags);if (error) {if (error == -ESTALE ) -nfs_zap_caches (dir); +nfs_mark_dir_for_revalidate (dir); goto out_bad; }nfs_advise_use_readdirplus (dir);
@@ -2064,7 +2079,6 @@ nfs_add_or_obtain(struct dentry *dentry, struct nfs_fh *fhandle,dput (parent);return d; out_error: -nfs_mark_for_revalidate (dir); d =ERR_PTR (error); goto out; }
Signature · 1 line
2.29.2
[email protected]
maintainerPATCH v2 2/5 NFS: Don't gratuitously clear the inode cache when lookup failed
From: Trond Myklebust <[email protected]>
The fact that the lookup revalidation failed, does not mean that the inode contents have changed.
--- fs/nfs/dir.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
fs/nfs/dir.c +8 -12
@@ -1444,18 +1444,14 @@ nfs_lookup_revalidate_done(struct inode *dir, struct dentry *dentry, __func__, dentry);return 1 ;case 0 : -if (inode &&S_ISDIR (inode->i_mode)) { -/* Purge readdir caches. */ -nfs_zap_caches (inode); -/* -* We can't d_drop the root of a disconnected tree: -* its d_hash is on the s_anon list and d_drop() would hide -* it from shrink_dcache_for_unmount(), leading to busy -* inodes on unmount and further oopses. -*/ -if (IS_ROOT (dentry)) -return 1 ; - } +/* +* We can't d_drop the root of a disconnected tree: +* its d_hash is on the s_anon list and d_drop() would hide +* it from shrink_dcache_for_unmount(), leading to busy +* inodes on unmount and further oopses. +*/ +if (inode &&IS_ROOT (dentry)) +return 1 ;dfprintk (LOOKUPCACHE ,"NFS: %s(%pd2) is invalid\n" , __func__, dentry);return 0 ;
Signature · 1 line
2.29.2
[email protected]
maintainerPATCH v2 3/5 NFS: Clean up function nfs_mark_dir_for_revalidate()
From: Trond Myklebust <[email protected]>
--- fs/nfs/dir.c | 4 +--- fs/nfs/inode.c | 2 +- fs/nfs/internal.h | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-)
fs/nfs/dir.c +1 -3
@@ -1403,10 +1403,8 @@ int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags)static void nfs_mark_dir_for_revalidate (struct inode *inode) { -struct nfs_inode *nfsi =NFS_I (inode); -spin_lock (&inode->i_lock); - nfsi->cache_validity |=NFS_INO_REVAL_PAGECACHE ; +nfs_set_cache_invalid (inode,NFS_INO_REVAL_PAGECACHE );spin_unlock (&inode->i_lock); }
fs/nfs/inode.c +1 -1
@@ -207,7 +207,7 @@ static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi) }#endif -static void nfs_set_cache_invalid (struct inode *inode,unsigned long flags) +void nfs_set_cache_invalid (struct inode *inode,unsigned long flags) {struct nfs_inode *nfsi =NFS_I (inode);bool have_delegation =NFS_PROTO (inode)->have_delegation (inode,FMODE_READ );
fs/nfs/internal.h +2 -1
@@ -411,7 +411,8 @@ extern int nfs_write_inode(struct inode *, struct writeback_control *);extern int nfs_drop_inode (struct inode *);extern void nfs_clear_inode (struct inode *);extern void nfs_evict_inode (struct inode *); -void nfs_zap_acl_cache (struct inode *inode); +extern void nfs_zap_acl_cache (struct inode *inode); +extern void nfs_set_cache_invalid (struct inode *inode,unsigned long flags);extern bool nfs_check_cache_invalid (struct inode *,unsigned long );extern int nfs_wait_bit_killable (struct wait_bit_key *key,int mode);extern int nfs_wait_atomic_killable (atomic_t *p,unsigned int mode);
Signature · 1 line
2.29.2
[email protected]
maintainerPATCH v2 4/5 NFS: Fix open coded versions of nfs_set_cache_invalid()
From: Trond Myklebust <[email protected]>
nfs_set_cache_invalid() has code to handle delegations, and other optimisations, so let's use it when appropriate.
--- fs/nfs/dir.c | 20 ++++++++++---------- fs/nfs/inode.c | 4 ++-- fs/nfs/unlink.c | 6 +++--- fs/nfs/write.c | 8 ++++---- 4 files changed, 19 insertions(+), 19 deletions(-)
fs/nfs/dir.c +10 -10
@@ -81,8 +81,9 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dirspin_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:
fs/nfs/inode.c +2 -2
@@ -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); }
fs/nfs/unlink.c +3 -3
@@ -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 ;
fs/nfs/write.c +4 -4
@@ -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 ;
Signature · 1 line
2.29.2
[email protected]
maintainerPATCH v2 5/5 NFS: Fix open coded versions of nfs_set_cache_invalid() in NFSv4
From: Trond Myklebust <[email protected]>
nfs_set_cache_invalid() has code to handle delegations, and other optimisations, so let's use it when appropriate.
--- fs/nfs/inode.c | 1 + fs/nfs/nfs42proc.c | 12 +++++++----- fs/nfs/nfs4proc.c | 28 ++++++++++++---------------- 3 files changed, 20 insertions(+), 21 deletions(-)
fs/nfs/inode.c +1 -0
@@ -229,6 +229,7 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)if (flags &NFS_INO_INVALID_DATA )nfs_fscache_invalidate (inode); } +EXPORT_SYMBOL_GPL (nfs_set_cache_invalid);/* * Invalidate the local caches
fs/nfs/nfs42proc.c +7 -5
@@ -357,13 +357,15 @@ static ssize_t _nfs42_proc_copy(struct file *src,truncate_pagecache_range (dst_inode, pos_dst, pos_dst + res->write_res.count);spin_lock (&dst_inode->i_lock); -NFS_I (dst_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE | -NFS_INO_REVAL_FORCED |NFS_INO_INVALID_SIZE | -NFS_INO_INVALID_ATTR |NFS_INO_INVALID_DATA ); +nfs_set_cache_invalid ( + dst_inode,NFS_INO_REVAL_PAGECACHE |NFS_INO_REVAL_FORCED | +NFS_INO_INVALID_SIZE |NFS_INO_INVALID_ATTR | +NFS_INO_INVALID_DATA );spin_unlock (&dst_inode->i_lock);spin_lock (&src_inode->i_lock); -NFS_I (src_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE | -NFS_INO_REVAL_FORCED |NFS_INO_INVALID_ATIME ); +nfs_set_cache_invalid (src_inode,NFS_INO_REVAL_PAGECACHE | +NFS_INO_REVAL_FORCED | +NFS_INO_INVALID_ATIME );spin_unlock (&src_inode->i_lock); status = res->write_res.count; out:
fs/nfs/nfs4proc.c +12 -16
@@ -1169,14 +1169,14 @@ int nfs4_call_sync(struct rpc_clnt *clnt,static void nfs4_inc_nlink_locked (struct inode *inode) { -NFS_I (inode)->cache_validity |=NFS_INO_INVALID_OTHER ; +nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER );inc_nlink (inode); }static void nfs4_dec_nlink_locked (struct inode *inode) { -NFS_I (inode)->cache_validity |=NFS_INO_INVALID_OTHER ; +nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER );drop_nlink (inode); }
@@ -1187,35 +1187,31 @@ nfs4_update_changeattr_locked(struct inode *inode, {struct nfs_inode *nfsi =NFS_I (inode); - nfsi->cache_validity |=NFS_INO_INVALID_CTIME - |NFS_INO_INVALID_MTIME - | cache_validity; + cache_validity |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ;if (cinfo->atomic && cinfo->before ==inode_peek_iversion_raw (inode)) { nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE ; nfsi->attrtimeo_timestamp = jiffies; }else {if (S_ISDIR (inode->i_mode)) { - nfsi->cache_validity |=NFS_INO_INVALID_DATA ; + cache_validity |=NFS_INO_INVALID_DATA ;nfs_force_lookup_revalidate (inode); }else {if (!NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) - nfsi->cache_validity |=NFS_INO_REVAL_PAGECACHE ; + cache_validity |=NFS_INO_REVAL_PAGECACHE ; }if (cinfo->before !=inode_peek_iversion_raw (inode)) - nfsi->cache_validity |=NFS_INO_INVALID_ACCESS | -NFS_INO_INVALID_ACL | -NFS_INO_INVALID_XATTR ; + cache_validity |=NFS_INO_INVALID_ACCESS | +NFS_INO_INVALID_ACL | +NFS_INO_INVALID_XATTR ; }inode_set_iversion_raw (inode, cinfo->after); nfsi->read_cache_jiffies = timestamp; nfsi->attr_gencount =nfs_inc_attr_generation_counter (); +nfs_set_cache_invalid (inode, cache_validity); nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE ; - -if (nfsi->cache_validity &NFS_INO_INVALID_DATA ) -nfs_fscache_invalidate (inode); }void
@@ -5915,9 +5911,9 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl* so mark the attribute cache invalid. */ spin_lock (&inode->i_lock); -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);nfs_access_zap_cache (inode);nfs_zap_acl_cache (inode);
Signature · 1 line
2.29.2