Attribute revalidation updates
Subsystems (2)
[email protected]
maintainerv2 cover Attribute revalidation updates
From: Trond Myklebust <[email protected]>
The following updates try to simplify some of the attribute caching, and further split out the attribute cache tracking. In particular, we want to make use of the fact that NFSv4.x doesn't always need to retrieve all the attributes to optimise the way we use the GETATTR call.
v2:
- A number of changes to try to clean up the cache invalidation flags.
- Fix a bug that was turning off revalidation for most attributes in nfs_getattr().
- Fixes to allow us to reduce the set of attributes we request from the server when holding a delegation. In particular, try to reduce requests for OWNER and GROUP_OWNER, since those may result in expensive upcalls.
Trond Myklebust (26):
NFS: Deal correctly with attribute generation counter overflow
NFS: Fix up inode cache tracing
NFS: Mask out unsupported attributes in nfs_getattr()
NFS: NFS_INO_REVAL_PAGECACHE should mark the change attribute invalid
NFS: Fix up revalidation of space used
NFS: Don't revalidate attributes that are not being asked for
NFS: Fix up statx() results
NFS: nfs_setattr_update_inode() should clear the suid/sgid bits
NFS: Add a cache validity flag argument to nfs_revalidate_inode()
NFS: Replace use of NFS_INO_REVAL_PAGECACHE when checking cache
validity
NFS: Don't set NFS_INO_REVAL_PAGECACHE in the inode cache validity
NFSv4: Fix nfs4_bitmap_copy_adjust()
NFS: Separate tracking of file nlinks cache validity from the
mode/uid/gid
NFS: Separate tracking of file mode cache validity from the uid/gid
NFS: Fix up handling of outstanding layoutcommit in nfs_update_inode()
NFS: Remove a line of code that has no effect in nfs_update_inode()
NFS: Simplify cache consistency in nfs_check_inode_attributes()
NFSv4: Fix value of decode_fsinfo_maxsz
NFSv4: Don't modify the change attribute cached in the inode
NFSv4: Add support for the NFSv4.2 "change_attr_type" attribute
NFS: Use information about the change attribute to optimise updates
NFS: Another inode revalidation improvement
NFSv4: nfs4_inc/dec_nlink_locked should also invalidate ctime
NFSv4: link must update the inode nlink.
NFS: Don't store NFS_INO_REVAL_FORCED
NFS: Split attribute support out from the server capabilities
fs/nfs/client.c | 18 +- fs/nfs/delegation.c | 21 +- fs/nfs/delegation.h | 3 +- fs/nfs/dir.c | 7 +- fs/nfs/export.c | 6 +- fs/nfs/file.c | 2 +- fs/nfs/inode.c | 414 ++++++++++++++++++++++++-------------- fs/nfs/nfs3acl.c | 2 +- fs/nfs/nfs3xdr.c | 1 + fs/nfs/nfs4proc.c | 160 +++++++++------ fs/nfs/nfs4xdr.c | 43 +++- fs/nfs/nfstrace.h | 11 +- fs/nfs/proc.c | 1 + fs/nfs/write.c | 7 +- include/linux/nfs4.h | 9 + include/linux/nfs_fs.h | 6 +- include/linux/nfs_fs_sb.h | 14 +- include/linux/nfs_xdr.h | 2 + 18 files changed, 478 insertions(+), 249 deletions(-)
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 1/26 NFS: Deal correctly with attribute generation counter overflow
From: Trond Myklebust <[email protected]>
We need to use unsigned long subtraction and then convert to signed in order to deal correcly with C overflow rules.
--- fs/nfs/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfs/inode.c +4 -4
@@ -1662,10 +1662,10 @@ EXPORT_SYMBOL_GPL(_nfs_display_fhandle);*/ static int nfs_inode_attrs_need_update (const struct inode *inode,const struct nfs_fattr *fattr) { -const struct nfs_inode *nfsi =NFS_I (inode); +unsigned long attr_gencount =NFS_I (inode)->attr_gencount; -return ((long )fattr->gencount - (long )nfsi->attr_gencount) >0 || - ((long )nfsi->attr_gencount - (long )nfs_read_attr_generation_counter () >0 ); +return (long )(fattr->gencount - attr_gencount) >0 || + (long )(attr_gencount -nfs_read_attr_generation_counter ()) >0 ; }static int nfs_refresh_inode_locked (struct inode *inode,struct nfs_fattr *fattr)
@@ -2094,7 +2094,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) nfsi->attrtimeo_timestamp = now; }/* Set the barrier to be more recent than this fattr */ -if ((long )fattr->gencount - (long )nfsi->attr_gencount >0 ) +if ((long )(fattr->gencount - nfsi->attr_gencount) >0 ) nfsi->attr_gencount = fattr->gencount; }
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 2/26 NFS: Fix up inode cache tracing
From: Trond Myklebust <[email protected]>
Add missing enum definitions and missing entries for nfs_show_cache_validity().
--- fs/nfs/nfstrace.h | 5 +++++ 1 file changed, 5 insertions(+)
fs/nfs/nfstrace.h +5 -0
@@ -45,6 +45,9 @@ TRACE_DEFINE_ENUM(NFS_INO_INVALID_CTIME);TRACE_DEFINE_ENUM (NFS_INO_INVALID_MTIME );TRACE_DEFINE_ENUM (NFS_INO_INVALID_SIZE );TRACE_DEFINE_ENUM (NFS_INO_INVALID_OTHER ); +TRACE_DEFINE_ENUM (NFS_INO_DATA_INVAL_DEFER ); +TRACE_DEFINE_ENUM (NFS_INO_INVALID_BLOCKS ); +TRACE_DEFINE_ENUM (NFS_INO_INVALID_XATTR );#define nfs_show_cache_validity (v) \ __print_flags(v, "|", \
@@ -60,6 +63,8 @@ TRACE_DEFINE_ENUM(NFS_INO_INVALID_OTHER); { NFS_INO_INVALID_MTIME, "INVALID_MTIME" }, \ { NFS_INO_INVALID_SIZE, "INVALID_SIZE" }, \ { NFS_INO_INVALID_OTHER, "INVALID_OTHER" }, \ + { NFS_INO_DATA_INVAL_DEFER, "DATA_INVAL_DEFER" }, \ + { NFS_INO_INVALID_BLOCKS, "INVALID_BLOCKS" }, \ { NFS_INO_INVALID_XATTR, "INVALID_XATTR" })TRACE_DEFINE_ENUM (NFS_INO_ADVISE_RDPLUS );
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 3/26 NFS: Mask out unsupported attributes in nfs_getattr()
From: Trond Myklebust <[email protected]>
We don't currently support STATX_BTIME, so don't advertise it in the return values for nfs_getattr().
--- fs/nfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/nfs/inode.c +4 -0
@@ -815,6 +815,10 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,trace_nfs_getattr_enter (inode); + request_mask &=STATX_TYPE |STATX_MODE |STATX_NLINK |STATX_UID | +STATX_GID |STATX_ATIME |STATX_MTIME |STATX_CTIME | +STATX_INO |STATX_SIZE |STATX_BLOCKS ; +if ((query_flags &AT_STATX_DONT_SYNC ) && !force_sync) {nfs_readdirplus_parent_cache_hit (path->dentry); goto out_no_update;
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 4/26 NFS: NFS_INO_REVAL_PAGECACHE should mark the change attribute invalid
From: Trond Myklebust <[email protected]>
When we're looking to revalidate the page cache, we should just ensure that we mark the change attribute invalid.
--- fs/nfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfs/inode.c +2 -1
@@ -219,7 +219,8 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) | NFS_INO_INVALID_SIZE |NFS_INO_REVAL_PAGECACHE | NFS_INO_INVALID_XATTR); - } + }else if (flags &NFS_INO_REVAL_PAGECACHE ) + flags |=NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ;if (!nfs_has_xattr_cache (nfsi)) flags &= ~NFS_INO_INVALID_XATTR ;
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 5/26 NFS: Fix up revalidation of space used
From: Trond Myklebust <[email protected]>
Ensure that when the change attribute or the size change, we also remember to revalidate the space used.
--- fs/nfs/inode.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/nfs/inode.c +12 -3
@@ -565,12 +565,13 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, stnfs_set_cache_invalid (inode,NFS_INO_INVALID_XATTR );if (fattr->valid &NFS_ATTR_FATTR_BLOCKS_USED ) inode->i_blocks = fattr->du.nfs2.blocks; -if (fattr->valid &NFS_ATTR_FATTR_SPACE_USED ) { +else if (fattr->valid &NFS_ATTR_FATTR_SPACE_USED ) {/* * report the blocks in 512byte units */ inode->i_blocks =nfs_calc_block_size (fattr->du.nfs3.used); - } + }else if (fattr->size !=0 ) +nfs_set_cache_invalid (inode,NFS_INO_INVALID_BLOCKS );if (nfsi->cache_validity !=0 ) nfsi->cache_validity |=NFS_INO_REVAL_FORCED ;
@@ -711,7 +712,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,spin_lock (&inode->i_lock);NFS_I (inode)->attr_gencount = fattr->gencount;if ((attr->ia_valid &ATTR_SIZE ) !=0 ) { -nfs_set_cache_invalid (inode,NFS_INO_INVALID_MTIME ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_MTIME | +NFS_INO_INVALID_BLOCKS );nfs_inc_stats (inode,NFSIOS_SETATTRTRUNC );nfs_vmtruncate (inode, attr->ia_size); }
@@ -1933,6 +1935,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) save_cache_validity |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE + |NFS_INO_INVALID_BLOCKS |NFS_INO_INVALID_OTHER ;if (S_ISDIR (inode->i_mode))nfs_force_lookup_revalidate (inode);
@@ -1990,6 +1993,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) (long long )cur_isize, (long long)new_isize); } +if (new_isize ==0 && + !(fattr->valid & (NFS_ATTR_FATTR_SPACE_USED | +NFS_ATTR_FATTR_BLOCKS_USED ))) { + fattr->du.nfs3.used =0 ; + fattr->valid |=NFS_ATTR_FATTR_SPACE_USED ; + } }else { nfsi->cache_validity |= save_cache_validity & (NFS_INO_INVALID_SIZE
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 6/26 NFS: Don't revalidate attributes that are not being asked for
From: Trond Myklebust <[email protected]>
If the user doesn't set STATX_UID/GID/MODE, then don't care if they are known to be stale. Ditto if we're not being asked for the file size.
--- fs/nfs/inode.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/nfs/inode.c +9 -4
@@ -857,12 +857,17 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,/* Check whether the cached attributes are stale */ do_update |= force_sync ||nfs_attribute_cache_expired (inode); cache_validity =READ_ONCE (NFS_I (inode)->cache_validity); - do_update |= cache_validity & - (NFS_INO_INVALID_ATTR |NFS_INO_INVALID_LABEL ); + do_update |= cache_validity &NFS_INO_INVALID_CHANGE ;if (request_mask &STATX_ATIME ) do_update |= cache_validity &NFS_INO_INVALID_ATIME ; -if (request_mask & (STATX_CTIME |STATX_MTIME )) - do_update |= cache_validity &NFS_INO_REVAL_PAGECACHE ; +if (request_mask &STATX_CTIME ) + do_update |= cache_validity &NFS_INO_INVALID_CTIME ; +if (request_mask &STATX_MTIME ) + do_update |= cache_validity &NFS_INO_INVALID_MTIME ; +if (request_mask &STATX_SIZE ) + do_update |= cache_validity &NFS_INO_INVALID_SIZE ; +if (request_mask & (STATX_UID |STATX_GID |STATX_MODE |STATX_NLINK )) + do_update |= cache_validity &NFS_INO_INVALID_OTHER ;if (request_mask &STATX_BLOCKS ) do_update |= cache_validity &NFS_INO_INVALID_BLOCKS ;if (do_update) {
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 7/26 NFS: Fix up statx() results
From: Trond Myklebust <[email protected]>
If statx has valid attributes available that weren't asked for, then return them and set the result mask appropriately.
--- fs/nfs/inode.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
fs/nfs/inode.c +26 -3
@@ -806,6 +806,28 @@ static bool nfs_need_revalidate_inode(struct inode *inode)return false; } +static u32 nfs_get_valid_attrmask (struct inode *inode) +{ +unsigned long cache_validity =READ_ONCE (NFS_I (inode)->cache_validity); +u32 reply_mask =STATX_INO |STATX_TYPE ; + +if (!(cache_validity &NFS_INO_INVALID_ATIME )) + reply_mask |=STATX_ATIME ; +if (!(cache_validity &NFS_INO_REVAL_PAGECACHE )) { +if (!(cache_validity &NFS_INO_INVALID_CTIME )) + reply_mask |=STATX_CTIME ; +if (!(cache_validity &NFS_INO_INVALID_MTIME )) + reply_mask |=STATX_MTIME ; +if (!(cache_validity &NFS_INO_INVALID_SIZE )) + reply_mask |=STATX_SIZE ; + } +if (!(cache_validity &NFS_INO_INVALID_OTHER )) + reply_mask |=STATX_UID |STATX_GID |STATX_MODE |STATX_NLINK ; +if (!(cache_validity &NFS_INO_INVALID_BLOCKS )) + reply_mask |=STATX_BLOCKS ; +return reply_mask; +} +int nfs_getattr (struct user_namespace *mnt_userns,const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {
@@ -824,7 +846,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,if ((query_flags &AT_STATX_DONT_SYNC ) && !force_sync) {nfs_readdirplus_parent_cache_hit (path->dentry); - goto out_no_update; + goto out_no_revalidate; }/* Flush out writes to the server in order to update c/mtime. */
@@ -870,6 +892,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, do_update |= cache_validity &NFS_INO_INVALID_OTHER ;if (request_mask &STATX_BLOCKS ) do_update |= cache_validity &NFS_INO_INVALID_BLOCKS ; +if (do_update) {/* Update the attribute cache */ if (!(server->flags &NFS_MOUNT_NOAC ))
@@ -883,8 +906,8 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,nfs_readdirplus_parent_cache_hit (path->dentry); out_no_revalidate:/* Only return attributes that were revalidated. */ - stat->result_mask &= request_mask; -out_no_update: + stat->result_mask =nfs_get_valid_attrmask (inode) | request_mask; +generic_fillattr (&init_user_ns, inode, stat); stat->ino =nfs_compat_user_ino64 (NFS_FILEID (inode));if (S_ISDIR (inode->i_mode))
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 8/26 NFS: nfs_setattr_update_inode() should clear the suid/sgid bits
From: Trond Myklebust <[email protected]>
When we do a 'chown' or 'chgrp', the server will clear the suid/sgid bits. Ensure that we mirror that in nfs_setattr_update_inode().
--- fs/nfs/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/nfs/inode.c +8 -2
@@ -636,8 +636,7 @@ nfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, }/* Optimization: if the end result is no change, don't RPC */ - attr->ia_valid &=NFS_VALID_ATTRS ; -if ((attr->ia_valid & ~(ATTR_FILE |ATTR_OPEN )) ==0 ) +if (((attr->ia_valid &NFS_VALID_ATTRS ) & ~(ATTR_FILE |ATTR_OPEN )) ==0 )return 0 ;trace_nfs_setattr_enter (inode);
@@ -719,6 +718,13 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, }if ((attr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID )) !=0 ) {NFS_I (inode)->cache_validity &= ~NFS_INO_INVALID_CTIME ; +if ((attr->ia_valid &ATTR_KILL_SUID ) !=0 && + inode->i_mode &S_ISUID ) + inode->i_mode &= ~S_ISUID ; +if ((attr->ia_valid &ATTR_KILL_SGID ) !=0 && + (inode->i_mode & (S_ISGID |S_IXGRP )) == + (S_ISGID |S_IXGRP )) + inode->i_mode &= ~S_ISGID ;if ((attr->ia_valid &ATTR_MODE ) !=0 ) {int mode = attr->ia_mode &S_IALLUGO ; mode |= inode->i_mode & ~S_IALLUGO ;
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 9/26 NFS: Add a cache validity flag argument to nfs_revalidate_inode()
From: Trond Myklebust <[email protected]>
Add an argument to nfs_revalidate_inode() to allow callers to specify which attributes they need to check for validity.
--- fs/nfs/dir.c | 2 +- fs/nfs/export.c | 6 +----- fs/nfs/inode.c | 25 +++++++------------------ fs/nfs/nfs3acl.c | 2 +- fs/nfs/nfs4proc.c | 6 +++--- include/linux/nfs_fs.h | 2 +- 6 files changed, 14 insertions(+), 29 deletions(-)
fs/nfs/dir.c +1 -1
@@ -3006,7 +3006,7 @@ int nfs_permission(struct user_namespace *mnt_userns,if (mask &MAY_NOT_BLOCK )return -ECHILD ; - res =nfs_revalidate_inode (NFS_SERVER (inode), inode); + res =nfs_revalidate_inode (inode,NFS_INO_INVALID_OTHER );if (res ==0 ) res =generic_permission (&init_user_ns, inode, mask); goto out;
fs/nfs/export.c +1 -5
@@ -169,11 +169,7 @@ nfs_get_parent(struct dentry *dentry)static u64 nfs_fetch_iversion (struct inode *inode) { -struct nfs_server *server =NFS_SERVER (inode); - -if (nfs_check_cache_invalid (inode,NFS_INO_INVALID_CHANGE | -NFS_INO_REVAL_PAGECACHE )) -__nfs_revalidate_inode (server, inode); +nfs_revalidate_inode (inode,NFS_INO_INVALID_CHANGE );return inode_peek_iversion_raw (inode); }
fs/nfs/inode.c +7 -18
@@ -802,16 +802,6 @@ static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)dput (parent); } -static bool nfs_need_revalidate_inode (struct inode *inode) -{ -if (NFS_I (inode)->cache_validity & - (NFS_INO_INVALID_ATTR |NFS_INO_INVALID_LABEL )) -return true; -if (nfs_attribute_cache_expired (inode)) -return true; -return false; -} -static u32 nfs_get_valid_attrmask (struct inode *inode) {unsigned long cache_validity =READ_ONCE (NFS_I (inode)->cache_validity);
@@ -1004,7 +994,6 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync) {struct nfs_inode *nfsi;struct inode *inode; -struct nfs_server *server;if (!(ctx->mode &FMODE_WRITE ))return ;
@@ -1020,10 +1009,10 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)return ;if (!list_empty (&nfsi->open_files))return ; - server =NFS_SERVER (inode); -if (server->flags &NFS_MOUNT_NOCTO ) +if (NFS_SERVER (inode)->flags &NFS_MOUNT_NOCTO )return ; -nfs_revalidate_inode (server, inode); +nfs_revalidate_inode (inode, +NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ); }EXPORT_SYMBOL_GPL (nfs_close_context);
@@ -1278,16 +1267,16 @@ int nfs_attribute_cache_expired(struct inode *inode)/** * nfs_revalidate_inode - Revalidate the inode attributes -* @server: pointer to nfs_server struct * @inode: pointer to inode struct +* @flags: cache flags to check * * Updates inode attribute information by retrieving the data from the server. */ -int nfs_revalidate_inode (struct nfs_server *server,struct inode *inode) +int nfs_revalidate_inode (struct inode *inode,unsigned long flags) { -if (!nfs_need_revalidate_inode (inode)) +if (!nfs_check_cache_invalid (inode, flags))return NFS_STALE (inode) ? -ESTALE :0 ; -return __nfs_revalidate_inode (server, inode); +return __nfs_revalidate_inode (NFS_SERVER (inode), inode); }EXPORT_SYMBOL_GPL (nfs_revalidate_inode);
fs/nfs/nfs3acl.c +1 -1
@@ -65,7 +65,7 @@ struct posix_acl *nfs3_get_acl(struct inode *inode, int type)if (!nfs_server_capable (inode,NFS_CAP_ACLS ))return ERR_PTR (-EOPNOTSUPP ); - status =nfs_revalidate_inode (server, inode); + status =nfs_revalidate_inode (inode,NFS_INO_INVALID_CHANGE );if (status <0 )return ERR_PTR (status);
fs/nfs/nfs4proc.c +3 -3
@@ -5868,7 +5868,7 @@ static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)if (!nfs4_server_supports_acls (server))return -EOPNOTSUPP ; - ret =nfs_revalidate_inode (server, inode); + ret =nfs_revalidate_inode (inode,NFS_INO_INVALID_CHANGE );if (ret <0 )return ret;if (NFS_I (inode)->cache_validity &NFS_INO_INVALID_ACL )
@@ -7619,7 +7619,7 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,return -EACCES ; } - ret =nfs_revalidate_inode (NFS_SERVER (inode), inode); + ret =nfs_revalidate_inode (inode,NFS_INO_INVALID_CHANGE );if (ret)return ret;
@@ -7650,7 +7650,7 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)return 0 ; } - ret =nfs_revalidate_inode (NFS_SERVER (inode), inode); + ret =nfs_revalidate_inode (inode,NFS_INO_INVALID_CHANGE );if (ret)return ret;
include/linux/nfs_fs.h +1 -1
@@ -386,7 +386,7 @@ extern void nfs_access_set_mask(struct nfs_access_entry *, u32);extern int nfs_permission (struct user_namespace *,struct inode *,int );extern int nfs_open (struct inode *,struct file *);extern int nfs_attribute_cache_expired (struct inode *inode); -extern int nfs_revalidate_inode (struct nfs_server *server,struct inode *inode); +extern int nfs_revalidate_inode (struct inode *inode,unsigned long flags);extern int __nfs_revalidate_inode (struct nfs_server *,struct inode *);extern int nfs_clear_invalid_mapping (struct address_space *mapping);extern bool nfs_mapping_need_revalidate_inode (struct inode *inode);
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 10/26 NFS: Replace use of NFS_INO_REVAL_PAGECACHE when checking cache validity
From: Trond Myklebust <[email protected]>
When checking cache validity, be more specific than just 'we want to check the page cache validity'. In almost all cases, we want to check that change attribute, and possibly also the size.
--- fs/nfs/file.c | 2 +- fs/nfs/inode.c | 41 ++++++++++++----------------------------- fs/nfs/nfs4proc.c | 5 ++--- fs/nfs/write.c | 2 +- 4 files changed, 16 insertions(+), 34 deletions(-)
fs/nfs/file.c +1 -1
@@ -105,7 +105,7 @@ static int nfs_revalidate_file_size(struct inode *inode, struct file *filp)if (filp->f_flags &O_DIRECT ) goto force_reval; -if (nfs_check_cache_invalid (inode,NFS_INO_REVAL_PAGECACHE )) +if (nfs_check_cache_invalid (inode,NFS_INO_INVALID_SIZE )) goto force_reval;return 0 ; force_reval:
fs/nfs/inode.c +12 -29
67 lines not on this page · raw message
fs/nfs/nfs4proc.c +2 -3
@@ -5429,7 +5429,7 @@ static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src,memcpy (bitmask, src,sizeof (*bitmask) *NFS4_BITMASK_SZ ); -if (cache_validity & (NFS_INO_INVALID_CHANGE |NFS_INO_REVAL_PAGECACHE )) +if (cache_validity &NFS_INO_INVALID_CHANGE ) bitmask[0 ] |=FATTR4_WORD0_CHANGE ;if (cache_validity &NFS_INO_INVALID_ATIME ) bitmask[1 ] |=FATTR4_WORD1_TIME_ACCESS ;
@@ -5449,8 +5449,7 @@ static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src,if (nfs4_have_delegation (inode,FMODE_READ ) && !(cache_validity &NFS_INO_REVAL_FORCED )) bitmask[0 ] &= ~FATTR4_WORD0_SIZE ; -else if (cache_validity & - (NFS_INO_INVALID_SIZE |NFS_INO_REVAL_PAGECACHE )) +else if (cache_validity &NFS_INO_INVALID_SIZE ) bitmask[0 ] |=FATTR4_WORD0_SIZE ;for (i =0 ; i <NFS4_BITMASK_SZ ; i++)
fs/nfs/write.c +1 -1
@@ -1293,7 +1293,7 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode,if (nfs_have_delegated_attributes (inode)) goto out;if (nfsi->cache_validity & - (NFS_INO_REVAL_PAGECACHE |NFS_INO_INVALID_SIZE )) + (NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ))return false;smp_rmb ();if (test_bit (NFS_INO_INVALIDATING , &nfsi->flags) && pagelen !=0 )
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 11/26 NFS: Don't set NFS_INO_REVAL_PAGECACHE in the inode cache validity
From: Trond Myklebust <[email protected]>
It is no longer necessary to preserve the NFS_INO_REVAL_PAGECACHE flag.
--- fs/nfs/inode.c | 6 ++---- fs/nfs/nfs4proc.c | 1 - 2 files changed, 2 insertions(+), 5 deletions(-)
fs/nfs/inode.c +2 -4
@@ -202,11 +202,12 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) flags &= ~NFS_INO_INVALID_OTHER ; flags &= ~(NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE - |NFS_INO_REVAL_PAGECACHE |NFS_INO_INVALID_XATTR ); }else if (flags &NFS_INO_REVAL_PAGECACHE ) flags |=NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ; + flags &= ~NFS_INO_REVAL_PAGECACHE ; +if (!nfs_has_xattr_cache (nfsi)) flags &= ~NFS_INO_INVALID_XATTR ;if (flags &NFS_INO_INVALID_DATA )
@@ -1917,7 +1918,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR |NFS_INO_INVALID_ATIME |NFS_INO_REVAL_FORCED - |NFS_INO_REVAL_PAGECACHE |NFS_INO_INVALID_BLOCKS );/* Do atomic weak cache consistency updates */
@@ -1956,7 +1956,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) }else { nfsi->cache_validity |= save_cache_validity & (NFS_INO_INVALID_CHANGE - |NFS_INO_REVAL_PAGECACHE |NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
@@ -2008,7 +2007,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) }else { nfsi->cache_validity |= save_cache_validity & (NFS_INO_INVALID_SIZE - |NFS_INO_REVAL_PAGECACHE |NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
fs/nfs/nfs4proc.c +0 -1
@@ -1191,7 +1191,6 @@ nfs4_update_changeattr_locked(struct inode *inode, 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)) {
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 12/26 NFSv4: Fix nfs4_bitmap_copy_adjust()
From: Trond Myklebust <[email protected]>
Don't remove flags from the set retrieved from the cache_validity. We do want to retrieve all attributes that are listed as being invalid, whether or not there is a delegation set.
--- fs/nfs/nfs4proc.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
fs/nfs/nfs4proc.c +16 -17
@@ -284,7 +284,7 @@ const u32 nfs4_fs_locations_bitmap[3] = { };static void nfs4_bitmap_copy_adjust (__u32 *dst,const __u32 *src, -struct inode *inode) +struct inode *inode,unsigned long flags) {unsigned long cache_validity;
@@ -292,22 +292,19 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,if (!inode || !nfs4_have_delegation (inode,FMODE_READ ))return ; - cache_validity =READ_ONCE (NFS_I (inode)->cache_validity); -if (!(cache_validity &NFS_INO_REVAL_FORCED )) - cache_validity &= ~(NFS_INO_INVALID_CHANGE - |NFS_INO_INVALID_SIZE ); + cache_validity =READ_ONCE (NFS_I (inode)->cache_validity) | flags; +/* Remove the attributes over which we have full control */ + dst[1 ] &= ~FATTR4_WORD1_RAWDEV ;if (!(cache_validity &NFS_INO_INVALID_SIZE )) dst[0 ] &= ~FATTR4_WORD0_SIZE ;if (!(cache_validity &NFS_INO_INVALID_CHANGE )) dst[0 ] &= ~FATTR4_WORD0_CHANGE ; -} -static void nfs4_bitmap_copy_adjust_setattr (__u32 *dst, -const __u32 *src,struct inode *inode) -{ -nfs4_bitmap_copy_adjust (dst, src, inode); +if (!(cache_validity &NFS_INO_INVALID_OTHER )) + dst[1 ] &= ~(FATTR4_WORD1_MODE |FATTR4_WORD1_OWNER | +FATTR4_WORD1_OWNER_GROUP ); } static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
@@ -3344,12 +3341,15 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, .inode = inode, .stateid = &arg.stateid, }; +unsigned long adjust_flags =NFS_INO_INVALID_CHANGE ;int err; +if (sattr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID )) + adjust_flags |=NFS_INO_INVALID_OTHER ; + do { - nfs4_bitmap_copy_adjust_setattr(bitmask, - nfs4_bitmask(server, olabel), - inode); + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, olabel), + inode, adjust_flags); err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); switch (err) {
@@ -4157,8 +4157,7 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,if (inode && (server->flags &NFS_MOUNT_SOFTREVAL )) task_flags |=RPC_TASK_TIMEOUT ; -nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, label), inode); - +nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, label), inode,0 );nfs_fattr_init (fattr);nfs4_init_sequence (&args.seq_args, &res.seq_res,0 ,0 ); return nfs4_do_call_sync(server->client, server, &msg,
@@ -4764,8 +4763,8 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, const struct }nfs4_inode_make_writeable (inode); -nfs4_bitmap_copy_adjust_setattr (bitmask,nfs4_bitmask (server, res.label), inode); - +nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, res.label), inode, +NFS_INO_INVALID_CHANGE ); status =nfs4_call_sync (server->client, server, &msg, &arg.seq_args, &res.seq_res,1 );if (!status) { nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start,
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 13/26 NFS: Separate tracking of file nlinks cache validity from the mode/uid/gid
From: Trond Myklebust <[email protected]>
Rename can cause us to revalidate the access cache, so lets track the nlinks separately from the mode/uid/gid.
--- fs/nfs/dir.c | 2 +- fs/nfs/inode.c | 15 ++++++++++----- fs/nfs/nfs4proc.c | 13 +++++++------ fs/nfs/nfstrace.h | 4 +++- include/linux/nfs_fs.h | 2 ++ 5 files changed, 23 insertions(+), 13 deletions(-)
fs/nfs/dir.c +1 -1
@@ -1711,7 +1711,7 @@ static void nfs_drop_nlink(struct inode *inode)NFS_I (inode)->attr_gencount =nfs_inc_attr_generation_counter ();nfs_set_cache_invalid ( inode,NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME | -NFS_INO_INVALID_OTHER |NFS_INO_REVAL_FORCED ); +NFS_INO_INVALID_NLINK |NFS_INO_REVAL_FORCED );spin_unlock (&inode->i_lock); }
fs/nfs/inode.c +10 -5
@@ -538,7 +538,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, stif (fattr->valid &NFS_ATTR_FATTR_NLINK )set_nlink (inode, fattr->nlink);else if (nfs_server_capable (inode,NFS_CAP_NLINK )) -nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_NLINK );if (fattr->valid &NFS_ATTR_FATTR_OWNER ) inode->i_uid = fattr->uid;else if (nfs_server_capable (inode,NFS_CAP_OWNER ))
@@ -801,8 +801,10 @@ static u32 nfs_get_valid_attrmask(struct inode *inode) reply_mask |=STATX_MTIME ;if (!(cache_validity &NFS_INO_INVALID_SIZE )) reply_mask |=STATX_SIZE ; +if (!(cache_validity &NFS_INO_INVALID_NLINK )) + reply_mask |=STATX_NLINK ;if (!(cache_validity &NFS_INO_INVALID_OTHER )) - reply_mask |=STATX_UID |STATX_GID |STATX_MODE |STATX_NLINK ; + reply_mask |=STATX_UID |STATX_GID |STATX_MODE ;if (!(cache_validity &NFS_INO_INVALID_BLOCKS )) reply_mask |=STATX_BLOCKS ;return reply_mask;
@@ -868,7 +870,9 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, do_update |= cache_validity &NFS_INO_INVALID_MTIME ;if (request_mask &STATX_SIZE ) do_update |= cache_validity &NFS_INO_INVALID_SIZE ; -if (request_mask & (STATX_UID |STATX_GID |STATX_MODE |STATX_NLINK )) +if (request_mask &STATX_NLINK ) + do_update |= cache_validity &NFS_INO_INVALID_NLINK ; +if (request_mask & (STATX_UID |STATX_GID |STATX_MODE )) do_update |= cache_validity &NFS_INO_INVALID_OTHER ;if (request_mask &STATX_BLOCKS ) do_update |= cache_validity &NFS_INO_INVALID_BLOCKS ;
@@ -1518,7 +1522,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat/* Has the link count changed? */ if ((fattr->valid &NFS_ATTR_FATTR_NLINK ) && inode->i_nlink != fattr->nlink) - invalid |=NFS_INO_INVALID_OTHER ; + invalid |=NFS_INO_INVALID_NLINK ; ts = inode->i_atime;if ((fattr->valid &NFS_ATTR_FATTR_ATIME ) && !timespec64_equal (&ts, &fattr->atime))
@@ -1942,6 +1946,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE |NFS_INO_INVALID_BLOCKS + |NFS_INO_INVALID_NLINK |NFS_INO_INVALID_OTHER ;if (S_ISDIR (inode->i_mode))nfs_force_lookup_revalidate (inode);
@@ -2074,7 +2079,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) } }else if (server->caps &NFS_CAP_NLINK ) { nfsi->cache_validity |= save_cache_validity & - (NFS_INO_INVALID_OTHER + (NFS_INO_INVALID_NLINK |NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
fs/nfs/nfs4proc.c +7 -6
@@ -1167,14 +1167,14 @@ int nfs4_call_sync(struct rpc_clnt *clnt,static void nfs4_inc_nlink_locked (struct inode *inode) { -nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_NLINK );inc_nlink (inode); }static void nfs4_dec_nlink_locked (struct inode *inode) { -nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_NLINK );drop_nlink (inode); }
@@ -4717,11 +4717,11 @@ static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,/* Note: If we moved a directory, nlink will change */ nfs4_update_changeattr (old_dir, &res->old_cinfo, res->old_fattr->time_start, -NFS_INO_INVALID_OTHER | +NFS_INO_INVALID_NLINK |NFS_INO_INVALID_DATA );nfs4_update_changeattr (new_dir, &res->new_cinfo, res->new_fattr->time_start, -NFS_INO_INVALID_OTHER | +NFS_INO_INVALID_NLINK |NFS_INO_INVALID_DATA ); }else nfs4_update_changeattr(old_dir, &res->old_cinfo,
@@ -5433,8 +5433,9 @@ static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, bitmask[1 ] |=FATTR4_WORD1_TIME_ACCESS ;if (cache_validity &NFS_INO_INVALID_OTHER ) bitmask[1 ] |=FATTR4_WORD1_MODE |FATTR4_WORD1_OWNER | -FATTR4_WORD1_OWNER_GROUP | -FATTR4_WORD1_NUMLINKS ; +FATTR4_WORD1_OWNER_GROUP ; +if (cache_validity &NFS_INO_INVALID_NLINK ) + bitmask[1 ] |=FATTR4_WORD1_NUMLINKS ;if (label && label->len && cache_validity &NFS_INO_INVALID_LABEL ) bitmask[2 ] |=FATTR4_WORD2_SECURITY_LABEL ;if (cache_validity &NFS_INO_INVALID_CTIME )
fs/nfs/nfstrace.h +3 -1
@@ -48,6 +48,7 @@ TRACE_DEFINE_ENUM(NFS_INO_INVALID_OTHER);TRACE_DEFINE_ENUM (NFS_INO_DATA_INVAL_DEFER );TRACE_DEFINE_ENUM (NFS_INO_INVALID_BLOCKS );TRACE_DEFINE_ENUM (NFS_INO_INVALID_XATTR ); +TRACE_DEFINE_ENUM (NFS_INO_INVALID_NLINK );#define nfs_show_cache_validity (v) \ __print_flags(v, "|", \
@@ -65,7 +66,8 @@ TRACE_DEFINE_ENUM(NFS_INO_INVALID_XATTR); { NFS_INO_INVALID_OTHER, "INVALID_OTHER" }, \ { NFS_INO_DATA_INVAL_DEFER, "DATA_INVAL_DEFER" }, \ { NFS_INO_INVALID_BLOCKS, "INVALID_BLOCKS" }, \ - { NFS_INO_INVALID_XATTR, "INVALID_XATTR" }) + { NFS_INO_INVALID_XATTR, "INVALID_XATTR" }, \ + { NFS_INO_INVALID_NLINK, "INVALID_NLINK" })TRACE_DEFINE_ENUM (NFS_INO_ADVISE_RDPLUS );TRACE_DEFINE_ENUM (NFS_INO_STALE );
include/linux/nfs_fs.h +2 -0
@@ -246,11 +246,13 @@ struct nfs4_copy_state { BIT(13) /* Deferred cache invalidation */#define NFS_INO_INVALID_BLOCKS BIT(14)/* cached blocks are invalid */ #define NFS_INO_INVALID_XATTR BIT(15)/* xattrs are invalid */ +#define NFS_INO_INVALID_NLINK BIT(16)/* cached nlinks is invalid */ #define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \ | NFS_INO_INVALID_CTIME \ | NFS_INO_INVALID_MTIME \ | NFS_INO_INVALID_SIZE \ + | NFS_INO_INVALID_NLINK \ | NFS_INO_INVALID_OTHER)/* inode metadata is invalid */ /*
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 14/26 NFS: Separate tracking of file mode cache validity from the uid/gid
From: Trond Myklebust <[email protected]>
chown()/chgrp() and chmod() are separate operations, and in addition, there are mode operations that are performed automatically by the server. So let's track mode validity separately from the file ownership validity.
--- fs/nfs/dir.c | 5 +++-- fs/nfs/inode.c | 18 ++++++++++++------ fs/nfs/nfs4proc.c | 14 +++++++++----- fs/nfs/nfstrace.h | 4 +++- fs/nfs/write.c | 2 +- include/linux/nfs_fs.h | 2 ++ 6 files changed, 30 insertions(+), 15 deletions(-)
fs/nfs/dir.c +3 -2
@@ -2948,7 +2948,7 @@ static int nfs_execute_ok(struct inode *inode, int mask)if (S_ISDIR (inode->i_mode))return 0 ; -if (nfs_check_cache_invalid (inode,NFS_INO_INVALID_OTHER )) { +if (nfs_check_cache_invalid (inode,NFS_INO_INVALID_MODE )) {if (mask &MAY_NOT_BLOCK )return -ECHILD ; ret =__nfs_revalidate_inode (server, inode);
@@ -3006,7 +3006,8 @@ int nfs_permission(struct user_namespace *mnt_userns,if (mask &MAY_NOT_BLOCK )return -ECHILD ; - res =nfs_revalidate_inode (inode,NFS_INO_INVALID_OTHER ); + res =nfs_revalidate_inode (inode,NFS_INO_INVALID_MODE | +NFS_INO_INVALID_OTHER );if (res ==0 ) res =generic_permission (&init_user_ns, inode, mask); goto out;
fs/nfs/inode.c +12 -6
@@ -199,7 +199,8 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)if (have_delegation) {if (!(flags &NFS_INO_REVAL_FORCED )) - flags &= ~NFS_INO_INVALID_OTHER ; + flags &= ~(NFS_INO_INVALID_MODE | +NFS_INO_INVALID_OTHER ); flags &= ~(NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE |NFS_INO_INVALID_XATTR );
@@ -472,7 +473,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st nfsi->cache_validity =0 ;if ((fattr->valid &NFS_ATTR_FATTR_MODE ) ==0 &&nfs_server_capable (inode,NFS_CAP_MODE )) -nfs_set_cache_invalid (inode,NFS_INO_INVALID_OTHER ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_MODE );/* Why so? Because we want revalidate for devices/FIFOs, and * that's precisely what we have in nfs_file_inode_operations. */
@@ -803,8 +804,10 @@ static u32 nfs_get_valid_attrmask(struct inode *inode) reply_mask |=STATX_SIZE ;if (!(cache_validity &NFS_INO_INVALID_NLINK )) reply_mask |=STATX_NLINK ; +if (!(cache_validity &NFS_INO_INVALID_MODE )) + reply_mask |=STATX_MODE ;if (!(cache_validity &NFS_INO_INVALID_OTHER )) - reply_mask |=STATX_UID |STATX_GID |STATX_MODE ; + reply_mask |=STATX_UID |STATX_GID ;if (!(cache_validity &NFS_INO_INVALID_BLOCKS )) reply_mask |=STATX_BLOCKS ;return reply_mask;
@@ -872,7 +875,9 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, do_update |= cache_validity &NFS_INO_INVALID_SIZE ;if (request_mask &STATX_NLINK ) do_update |= cache_validity &NFS_INO_INVALID_NLINK ; -if (request_mask & (STATX_UID |STATX_GID |STATX_MODE )) +if (request_mask &STATX_MODE ) + do_update |= cache_validity &NFS_INO_INVALID_MODE ; +if (request_mask & (STATX_UID |STATX_GID )) do_update |= cache_validity &NFS_INO_INVALID_OTHER ;if (request_mask &STATX_BLOCKS ) do_update |= cache_validity &NFS_INO_INVALID_BLOCKS ;
@@ -1510,7 +1515,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fatif ((fattr->valid &NFS_ATTR_FATTR_MODE ) && (inode->i_mode &S_IALLUGO ) != (fattr->mode &S_IALLUGO )) invalid |=NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL - |NFS_INO_INVALID_OTHER ; + |NFS_INO_INVALID_MODE ;if ((fattr->valid &NFS_ATTR_FATTR_OWNER ) && !uid_eq (inode->i_uid, fattr->uid)) invalid |=NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL
@@ -1947,6 +1952,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | NFS_INO_INVALID_SIZE |NFS_INO_INVALID_BLOCKS |NFS_INO_INVALID_NLINK + |NFS_INO_INVALID_MODE |NFS_INO_INVALID_OTHER ;if (S_ISDIR (inode->i_mode))nfs_force_lookup_revalidate (inode);
@@ -2037,7 +2043,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) } }else if (server->caps &NFS_CAP_MODE ) { nfsi->cache_validity |= save_cache_validity & - (NFS_INO_INVALID_OTHER + (NFS_INO_INVALID_MODE |NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
fs/nfs/nfs4proc.c +9 -5
@@ -302,9 +302,10 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,if (!(cache_validity &NFS_INO_INVALID_CHANGE )) dst[0 ] &= ~FATTR4_WORD0_CHANGE ; +if (!(cache_validity &NFS_INO_INVALID_MODE )) + dst[1 ] &= ~FATTR4_WORD1_MODE ;if (!(cache_validity &NFS_INO_INVALID_OTHER )) - dst[1 ] &= ~(FATTR4_WORD1_MODE |FATTR4_WORD1_OWNER | -FATTR4_WORD1_OWNER_GROUP ); + dst[1 ] &= ~(FATTR4_WORD1_OWNER |FATTR4_WORD1_OWNER_GROUP ); } static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
@@ -3344,7 +3345,9 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,unsigned long adjust_flags =NFS_INO_INVALID_CHANGE ;int err; -if (sattr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID )) +if (sattr->ia_valid & (ATTR_MODE |ATTR_KILL_SUID |ATTR_KILL_SGID )) + adjust_flags |=NFS_INO_INVALID_MODE ; +if (sattr->ia_valid & (ATTR_UID |ATTR_GID )) adjust_flags |=NFS_INO_INVALID_OTHER ; do {
@@ -5431,9 +5434,10 @@ static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, bitmask[0 ] |=FATTR4_WORD0_CHANGE ;if (cache_validity &NFS_INO_INVALID_ATIME ) bitmask[1 ] |=FATTR4_WORD1_TIME_ACCESS ; +if (cache_validity &NFS_INO_INVALID_MODE ) + bitmask[1 ] |=FATTR4_WORD1_MODE ;if (cache_validity &NFS_INO_INVALID_OTHER ) - bitmask[1 ] |=FATTR4_WORD1_MODE |FATTR4_WORD1_OWNER | -FATTR4_WORD1_OWNER_GROUP ; + bitmask[1 ] |=FATTR4_WORD1_OWNER |FATTR4_WORD1_OWNER_GROUP ;if (cache_validity &NFS_INO_INVALID_NLINK ) bitmask[1 ] |=FATTR4_WORD1_NUMLINKS ;if (label && label->len && cache_validity &NFS_INO_INVALID_LABEL )
fs/nfs/nfstrace.h +3 -1
@@ -49,6 +49,7 @@ TRACE_DEFINE_ENUM(NFS_INO_DATA_INVAL_DEFER);TRACE_DEFINE_ENUM (NFS_INO_INVALID_BLOCKS );TRACE_DEFINE_ENUM (NFS_INO_INVALID_XATTR );TRACE_DEFINE_ENUM (NFS_INO_INVALID_NLINK ); +TRACE_DEFINE_ENUM (NFS_INO_INVALID_MODE );#define nfs_show_cache_validity (v) \ __print_flags(v, "|", \
@@ -67,7 +68,8 @@ TRACE_DEFINE_ENUM(NFS_INO_INVALID_NLINK); { NFS_INO_DATA_INVAL_DEFER, "DATA_INVAL_DEFER" }, \ { NFS_INO_INVALID_BLOCKS, "INVALID_BLOCKS" }, \ { NFS_INO_INVALID_XATTR, "INVALID_XATTR" }, \ - { NFS_INO_INVALID_NLINK, "INVALID_NLINK" }) + { NFS_INO_INVALID_NLINK, "INVALID_NLINK" }, \ + { NFS_INO_INVALID_MODE, "INVALID_MODE" })TRACE_DEFINE_ENUM (NFS_INO_ADVISE_RDPLUS );TRACE_DEFINE_ENUM (NFS_INO_STALE );
fs/nfs/write.c +1 -1
@@ -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_set_cache_invalid (inode,NFS_INO_INVALID_OTHER ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_MODE );spin_unlock (&inode->i_lock); }return 0 ;
include/linux/nfs_fs.h +2 -0
@@ -247,12 +247,14 @@ struct nfs4_copy_state {#define NFS_INO_INVALID_BLOCKS BIT(14)/* cached blocks are invalid */ #define NFS_INO_INVALID_XATTR BIT(15)/* xattrs are invalid */ #define NFS_INO_INVALID_NLINK BIT(16)/* cached nlinks is invalid */ +#define NFS_INO_INVALID_MODE BIT(17)/* cached mode is invalid */ #define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \ | NFS_INO_INVALID_CTIME \ | NFS_INO_INVALID_MTIME \ | NFS_INO_INVALID_SIZE \ | NFS_INO_INVALID_NLINK \ + | NFS_INO_INVALID_MODE \ | NFS_INO_INVALID_OTHER)/* inode metadata is invalid */ /*
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 15/26 NFS: Fix up handling of outstanding layoutcommit in nfs_update_inode()
From: Trond Myklebust <[email protected]>
If there is an outstanding layoutcommit, then the list of attributes whose values are expected to change is not the full set. So let's be explicit about the full list.
--- fs/nfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/inode.c +5 -1
@@ -1933,7 +1933,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)nfs_wcc_update_inode (inode, fattr);if (pnfs_layoutcommit_outstanding (inode)) { - nfsi->cache_validity |= save_cache_validity &NFS_INO_INVALID_ATTR ; + nfsi->cache_validity |= + save_cache_validity & + (NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE | +NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 16/26 NFS: Remove a line of code that has no effect in nfs_update_inode()
From: Trond Myklebust <[email protected]>
Commit 0b467264d0db ("NFS: Fix attribute revalidation") changed the way we populate the 'invalid' attribute, and made the line that strips away the NFS_INO_INVALID_ATTR bits redundant.
--- fs/nfs/inode.c | 1 - 1 file changed, 1 deletion(-)
fs/nfs/inode.c +0 -1
@@ -2110,7 +2110,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)/* Update attrtimeo value if we're out of the unstable period */ if (attr_changed) { - invalid &= ~NFS_INO_INVALID_ATTR ;nfs_inc_stats (inode,NFSIOS_ATTRINVALIDATE ); nfsi->attrtimeo =NFS_MINATTRTIMEO (inode); nfsi->attrtimeo_timestamp = now;
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 17/26 NFS: Simplify cache consistency in nfs_check_inode_attributes()
From: Trond Myklebust <[email protected]>
We should not be invalidating the access or acl caches in nfs_check_inode_attributes(), since the point is we're unsure about whether the contents of the struct nfs_fattr are fully up to date.
--- fs/nfs/inode.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
fs/nfs/inode.c +5 -13
@@ -1491,8 +1491,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fatif (!nfs_file_has_buffered_writers (nfsi)) {/* Verify a few of the more important attributes */ if ((fattr->valid &NFS_ATTR_FATTR_CHANGE ) !=0 && !inode_eq_iversion_raw (inode, fattr->change_attr)) - invalid |=NFS_INO_INVALID_CHANGE - |NFS_INO_REVAL_PAGECACHE ; + invalid |=NFS_INO_INVALID_CHANGE ; ts = inode->i_mtime;if ((fattr->valid &NFS_ATTR_FATTR_MTIME ) && !timespec64_equal (&ts, &fattr->mtime))
@@ -1506,24 +1505,17 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat cur_size =i_size_read (inode); new_isize =nfs_size_to_loff_t (fattr->size);if (cur_size != new_isize) - invalid |=NFS_INO_INVALID_SIZE - |NFS_INO_REVAL_PAGECACHE ; + invalid |=NFS_INO_INVALID_SIZE ; } }/* Have any file permissions changed? */ if ((fattr->valid &NFS_ATTR_FATTR_MODE ) && (inode->i_mode &S_IALLUGO ) != (fattr->mode &S_IALLUGO )) - invalid |=NFS_INO_INVALID_ACCESS - |NFS_INO_INVALID_ACL - |NFS_INO_INVALID_MODE ; + invalid |=NFS_INO_INVALID_MODE ;if ((fattr->valid &NFS_ATTR_FATTR_OWNER ) && !uid_eq (inode->i_uid, fattr->uid)) - invalid |=NFS_INO_INVALID_ACCESS - |NFS_INO_INVALID_ACL - |NFS_INO_INVALID_OTHER ; + invalid |=NFS_INO_INVALID_OTHER ;if ((fattr->valid &NFS_ATTR_FATTR_GROUP ) && !gid_eq (inode->i_gid, fattr->gid)) - invalid |=NFS_INO_INVALID_ACCESS - |NFS_INO_INVALID_ACL - |NFS_INO_INVALID_OTHER ; + invalid |=NFS_INO_INVALID_OTHER ;/* Has the link count changed? */ if ((fattr->valid &NFS_ATTR_FATTR_NLINK ) && inode->i_nlink != fattr->nlink)
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 18/26 NFSv4: Fix value of decode_fsinfo_maxsz
From: Trond Myklebust <[email protected]>
At least two extra fields have been added to fsinfo since this was last updated.
--- fs/nfs/nfs4xdr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/nfs/nfs4xdr.c +10 -1
@@ -144,7 +144,16 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,* layout types will be returned. */ #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ - nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) + nfs4_fattr_bitmap_maxsz + 1 + \ + 1 /* lease time */ + \ + 2 /* max filesize */ + \ + 2 /* max read */ + \ + 2 /* max write */ + \ + nfstime4_maxsz /* time delta */ + \ + 5 /* fs layout types */ + \ + 1 /* layout blksize */ + \ + 1 /* clone blksize */ + \ + 1 /* xattr support */)#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)#define decode_renew_maxsz (op_decode_hdr_maxsz)#define encode_setclientid_maxsz \
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 19/26 NFSv4: Don't modify the change attribute cached in the inode
From: Trond Myklebust <[email protected]>
When the client is caching data and a write delegation is held, then the server may send a CB_GETATTR to query the attributes. When this happens, the client is supposed to bump the change attribute value that it returns if it holds cached data.
However that process uses a value that is stored in the delegation. We do not want to bump the change attribute held in the inode.
--- fs/nfs/write.c | 3 --- 1 file changed, 3 deletions(-)
fs/nfs/write.c +0 -3
@@ -764,9 +764,6 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)* with invalidate/truncate. */ spin_lock (&mapping->private_lock); -if (!nfs_have_writebacks (inode) && -NFS_PROTO (inode)->have_delegation (inode,FMODE_WRITE )) -inode_inc_iversion_raw (inode);if (likely (!PageSwapCache (req->wb_page))) {set_bit (PG_MAPPED , &req->wb_flags);SetPagePrivate (req->wb_page);
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 20/26 NFSv4: Add support for the NFSv4.2 "change_attr_type" attribute
From: Trond Myklebust <[email protected]>
The change_attr_type allows the server to provide a description of how the change attribute will behave. This again will allow the client to optimise its behaviour w.r.t. attribute revalidation.
--- fs/nfs/client.c | 3 +++ fs/nfs/nfs3xdr.c | 1 + fs/nfs/nfs4proc.c | 1 + fs/nfs/nfs4xdr.c | 32 ++++++++++++++++++++++++++++++++ fs/nfs/proc.c | 1 + include/linux/nfs4.h | 9 +++++++++ include/linux/nfs_fs_sb.h | 3 +++ include/linux/nfs_xdr.h | 2 ++ 8 files changed, 52 insertions(+)
fs/nfs/client.c +3 -0
@@ -792,6 +792,7 @@ static void nfs_server_set_fsinfo(struct nfs_server *server, server->maxfilesize = fsinfo->maxfilesize; server->time_delta = fsinfo->time_delta; + server->change_attr_type = fsinfo->change_attr_type; server->clone_blksize = fsinfo->clone_blksize;/* We're airborne Set socket buffersize */
@@ -933,6 +934,8 @@ struct nfs_server *nfs_alloc_server(void)return NULL ; } + server->change_attr_type =NFS4_CHANGE_TYPE_IS_UNDEFINED ; +ida_init (&server->openowner_id);ida_init (&server->lockowner_id);pnfs_init_server (server);
fs/nfs/nfs3xdr.c +1 -0
@@ -2227,6 +2227,7 @@ static int decode_fsinfo3resok(struct xdr_stream *xdr,/* ignore properties */ result->lease_time =0 ; + result->change_attr_type =NFS4_CHANGE_TYPE_IS_TIME_METADATA ;return 0 ; }
fs/nfs/nfs4proc.c +1 -0
@@ -264,6 +264,7 @@ const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE | FATTR4_WORD1_FS_LAYOUT_TYPES, FATTR4_WORD2_LAYOUT_BLKSIZE | FATTR4_WORD2_CLONE_BLKSIZE + | FATTR4_WORD2_CHANGE_ATTR_TYPE | FATTR4_WORD2_XATTR_SUPPORT };
fs/nfs/nfs4xdr.c +32 -0
@@ -153,6 +153,7 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5 /* fs layout types */ + \ 1 /* layout blksize */ + \ 1 /* clone blksize */ + \ + 1 /* change attr type */ + \ 1 /* xattr support */)#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)#define decode_renew_maxsz (op_decode_hdr_maxsz)
@@ -4846,6 +4847,32 @@ static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,return 0 ; } +static int decode_attr_change_attr_type (struct xdr_stream *xdr, +uint32_t *bitmap, +enum nfs4_change_attr_type *res) +{ +u32 tmp =NFS4_CHANGE_TYPE_IS_UNDEFINED ; + +dprintk ("%s: bitmap is %x\n" , __func__, bitmap[2 ]); +if (bitmap[2 ] &FATTR4_WORD2_CHANGE_ATTR_TYPE ) { +if (xdr_stream_decode_u32 (xdr, &tmp)) +return -EIO ; + bitmap[2 ] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE ; + } + +switch (tmp) { +case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR : +case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER : +case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS : +case NFS4_CHANGE_TYPE_IS_TIME_METADATA : + *res = tmp; +break ; +default : + *res =NFS4_CHANGE_TYPE_IS_UNDEFINED ; + } +return 0 ; +} +static int decode_fsinfo (struct xdr_stream *xdr,struct nfs_fsinfo *fsinfo) {unsigned int savep;
@@ -4894,6 +4921,11 @@ static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)if (status) goto xdr_error; + status =decode_attr_change_attr_type (xdr, bitmap, + &fsinfo->change_attr_type); +if (status) + goto xdr_error; + status =decode_attr_xattrsupport (xdr, bitmap, &fsinfo->xattr_support);if (status)
fs/nfs/proc.c +1 -0
@@ -91,6 +91,7 @@ nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, info->dtpref = fsinfo.tsize; info->maxfilesize =0x7FFFFFFF ; info->lease_time =0 ; + info->change_attr_type =NFS4_CHANGE_TYPE_IS_TIME_METADATA ;return 0 ; }
include/linux/nfs4.h +9 -0
@@ -452,6 +452,7 @@ enum lock_type4 {#define FATTR4_WORD2_LAYOUT_BLKSIZE (1UL << 1)#define FATTR4_WORD2_MDSTHRESHOLD (1UL << 4)#define FATTR4_WORD2_CLONE_BLKSIZE (1UL << 13) +#define FATTR4_WORD2_CHANGE_ATTR_TYPE (1UL << 15)#define FATTR4_WORD2_SECURITY_LABEL (1UL << 16)#define FATTR4_WORD2_MODE_UMASK (1UL << 17)#define FATTR4_WORD2_XATTR_SUPPORT (1UL << 18)
@@ -709,6 +710,14 @@ struct nl4_server { } u; }; +enum nfs4_change_attr_type { +NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR =0 , +NFS4_CHANGE_TYPE_IS_VERSION_COUNTER =1 , +NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS =2 , +NFS4_CHANGE_TYPE_IS_TIME_METADATA =3 , +NFS4_CHANGE_TYPE_IS_UNDEFINED =4 , +}; +/* * Options for setxattr. These match the flags for setxattr(2). */
include/linux/nfs_fs_sb.h +3 -0
@@ -180,6 +180,9 @@ struct nfs_server {#define NFS_OPTION_FSCACHE 0x00000001/* - local caching enabled */ #define NFS_OPTION_MIGRATION 0x00000002/* - NFSv4 migration enabled */ +enum nfs4_change_attr_type + change_attr_type;/* Description of change attribute */ +struct nfs_fsid fsid;__u64 maxfilesize;/* maximum file size */ struct timespec64 time_delta;/* smallest time granularity */
include/linux/nfs_xdr.h +2 -0
@@ -152,6 +152,8 @@ struct nfs_fsinfo {__u32 layouttype[NFS_MAX_LAYOUT_TYPES ];/* supported pnfs layout driver */ __u32 blksize;/* preferred pnfs io block size */ __u32 clone_blksize;/* granularity of a CLONE operation */ +enum nfs4_change_attr_type + change_attr_type;/* Info about change attr */ __u32 xattr_support;/* User xattrs supported */ };
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 21/26 NFS: Use information about the change attribute to optimise updates
From: Trond Myklebust <[email protected]>
If the NFSv4.2 server supports the 'change_attr_type' attribute, then allow the client to optimise its attribute cache update strategy.
--- fs/nfs/inode.c | 111 ++++++++++++++++++++++++++++++++++++++-------- fs/nfs/nfs4proc.c | 20 +++++++-- 2 files changed, 110 insertions(+), 21 deletions(-)
fs/nfs/inode.c +93 -18
@@ -1657,25 +1657,20 @@ EXPORT_SYMBOL_GPL(_nfs_display_fhandle);#endif /** -* nfs_inode_attrs_need_update - check if the inode attributes need updating -* @inode: pointer to inode +* nfs_inode_attrs_cmp_generic - compare attributes * @fattr: attributes +* @inode: pointer to inode * * Attempt to divine whether or not an RPC call reply carrying stale * attributes got scheduled after another call carrying updated ones. -* -* To do so, the function first assumes that a more recent ctime means -* that the attributes in fattr are newer, however it also attempt to -* catch the case where ctime either didn't change, or went backwards -* (if someone reset the clock on the server) by looking at whether -* or not this RPC call was started after the inode was last updated. * Note also the check for wraparound of 'attr_gencount' * -* The function returns 'true' if it thinks the attributes in 'fattr' are -* more recent than the ones cached in the inode. -* +* The function returns '1' if it thinks the attributes in @fattr are +* more recent than the ones cached in @inode. Otherwise it returns +* the value '0'. */ -static int nfs_inode_attrs_need_update (const struct inode *inode,const struct nfs_fattr *fattr) +static int nfs_inode_attrs_cmp_generic (const struct nfs_fattr *fattr, +const struct inode *inode) {unsigned long attr_gencount =NFS_I (inode)->attr_gencount;
@@ -1683,15 +1678,93 @@ static int nfs_inode_attrs_need_update(const struct inode *inode, const struct n (long )(attr_gencount -nfs_read_attr_generation_counter ()) >0 ; } -static int nfs_refresh_inode_locked (struct inode *inode,struct nfs_fattr *fattr) +/** +* nfs_inode_attrs_cmp_monotonic - compare attributes +* @fattr: attributes +* @inode: pointer to inode +* +* Attempt to divine whether or not an RPC call reply carrying stale +* attributes got scheduled after another call carrying updated ones. +* +* We assume that the server observes monotonic semantics for +* the change attribute, so a larger value means that the attributes in +* @fattr are more recent, in which case the function returns the +* value '1'. +* A return value of '0' indicates no measurable change +* A return value of '-1' means that the attributes in @inode are +* more recent. +*/ +static int nfs_inode_attrs_cmp_monotonic (const struct nfs_fattr *fattr, +const struct inode *inode) { -int ret; +s64 diff = fattr->change_attr -inode_peek_iversion_raw (inode); +if (diff >0 ) +return 1 ; +return diff ==0 ?0 :-1 ; +} + +/** +* nfs_inode_attrs_cmp_strict_monotonic - compare attributes +* @fattr: attributes +* @inode: pointer to inode +* +* Attempt to divine whether or not an RPC call reply carrying stale +* attributes got scheduled after another call carrying updated ones. +* +* We assume that the server observes strictly monotonic semantics for +* the change attribute, so a larger value means that the attributes in +* @fattr are more recent, in which case the function returns the +* value '1'. +* A return value of '-1' means that the attributes in @inode are +* more recent or unchanged. +*/ +static int nfs_inode_attrs_cmp_strict_monotonic (const struct nfs_fattr *fattr, +const struct inode *inode) +{ +return nfs_inode_attrs_cmp_monotonic (fattr, inode) >0 ?1 :-1 ; +} + +/** +* nfs_inode_attrs_cmp - compare attributes +* @fattr: attributes +* @inode: pointer to inode +* +* This function returns '1' if it thinks the attributes in @fattr are +* more recent than the ones cached in @inode. It returns '-1' if +* the attributes in @inode are more recent than the ones in @fattr, +* and it returns 0 if not sure. +*/ +static int nfs_inode_attrs_cmp (const struct nfs_fattr *fattr, +const struct inode *inode) +{ +if (nfs_inode_attrs_cmp_generic (fattr, inode) >0 ) +return 1 ; +switch (NFS_SERVER (inode)->change_attr_type) { +case NFS4_CHANGE_TYPE_IS_UNDEFINED : +break ; +case NFS4_CHANGE_TYPE_IS_TIME_METADATA : +if (!(fattr->valid &NFS_ATTR_FATTR_CHANGE )) +break ; +return nfs_inode_attrs_cmp_monotonic (fattr, inode); +default : +if (!(fattr->valid &NFS_ATTR_FATTR_CHANGE )) +break ; +return nfs_inode_attrs_cmp_strict_monotonic (fattr, inode); + } +return 0 ; +} + +static int nfs_refresh_inode_locked (struct inode *inode, +struct nfs_fattr *fattr) +{ +int attr_cmp =nfs_inode_attrs_cmp (fattr, inode); +int ret =0 ;trace_nfs_refresh_inode_enter (inode); -if (nfs_inode_attrs_need_update (inode, fattr)) +if (attr_cmp >0 ) ret =nfs_update_inode (inode, fattr); -else +else if (attr_cmp ==0 ) ret =nfs_check_inode_attributes (inode, fattr);trace_nfs_refresh_inode_exit (inode, ret);
@@ -1776,11 +1849,13 @@ EXPORT_SYMBOL_GPL(nfs_post_op_update_inode);*/ int nfs_post_op_update_inode_force_wcc_locked (struct inode *inode,struct nfs_fattr *fattr) { +int attr_cmp =nfs_inode_attrs_cmp (fattr, inode);int status;/* Don't do a WCC update if these attributes are already stale */ -if ((fattr->valid &NFS_ATTR_FATTR ) ==0 || - !nfs_inode_attrs_need_update (inode, fattr)) { +if (attr_cmp <0 ) +return 0 ; +if ((fattr->valid &NFS_ATTR_FATTR ) ==0 || !attr_cmp) { fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE |NFS_ATTR_FATTR_PRESIZE | NFS_ATTR_FATTR_PREMTIME
fs/nfs/nfs4proc.c +17 -3
@@ -1186,10 +1186,23 @@ nfs4_update_changeattr_locked(struct inode *inode, unsigned long timestamp, unsigned long cache_validity) { struct nfs_inode *nfsi = NFS_I(inode); +u64 change_attr =inode_peek_iversion_raw (inode); cache_validity |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; -if (cinfo->atomic && cinfo->before ==inode_peek_iversion_raw (inode)) { +switch (NFS_SERVER (inode)->change_attr_type) { +case NFS4_CHANGE_TYPE_IS_UNDEFINED : +break ; +case NFS4_CHANGE_TYPE_IS_TIME_METADATA : +if ((s64)(change_attr - cinfo->after) >0 ) + goto out; +break ; +default : +if ((s64)(change_attr - cinfo->after) >=0 ) + goto out; + } + +if (cinfo->atomic && cinfo->before == change_attr) { nfsi->attrtimeo_timestamp = jiffies; }else {if (S_ISDIR (inode->i_mode)) {
@@ -1201,7 +1214,7 @@ nfs4_update_changeattr_locked(struct inode *inode, cache_validity |=NFS_INO_REVAL_PAGECACHE ; } -if (cinfo->before !=inode_peek_iversion_raw (inode)) +if (cinfo->before != change_attr) cache_validity |=NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL |NFS_INO_INVALID_XATTR ;
@@ -1209,8 +1222,9 @@ nfs4_update_changeattr_locked(struct inode *inode,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 ; +out: +nfs_set_cache_invalid (inode, cache_validity); }void
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 22/26 NFS: Another inode revalidation improvement
From: Trond Myklebust <[email protected]>
If we're trying to update the inode because a previous update left the cache in a partially unrevalidated state, then allow the update if the change attrs match.
--- fs/nfs/inode.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
fs/nfs/inode.c +29 -1
@@ -1754,6 +1754,34 @@ static int nfs_inode_attrs_cmp(const struct nfs_fattr *fattr,return 0 ; } +/** +* nfs_inode_finish_partial_attr_update - complete a previous inode update +* @fattr: attributes +* @inode: pointer to inode +* +* Returns '1' if the last attribute update left the inode cached +* attributes in a partially unrevalidated state, and @fattr +* matches the change attribute of that partial update. +* Otherwise returns '0'. +*/ +static int nfs_inode_finish_partial_attr_update (const struct nfs_fattr *fattr, +const struct inode *inode) +{ +const unsigned long check_valid = +NFS_INO_INVALID_ATIME |NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE | +NFS_INO_INVALID_BLOCKS |NFS_INO_INVALID_OTHER | +NFS_INO_INVALID_NLINK ; +unsigned long cache_validity =NFS_I (inode)->cache_validity; + +if (!(cache_validity &NFS_INO_INVALID_CHANGE ) && + (cache_validity & check_valid) !=0 && + (fattr->valid &NFS_ATTR_FATTR_CHANGE ) !=0 && +nfs_inode_attrs_cmp_monotonic (fattr, inode) ==0 ) +return 1 ; +return 0 ; +} +static int nfs_refresh_inode_locked (struct inode *inode,struct nfs_fattr *fattr) {
@@ -1762,7 +1790,7 @@ static int nfs_refresh_inode_locked(struct inode *inode,trace_nfs_refresh_inode_enter (inode); -if (attr_cmp >0 ) +if (attr_cmp >0 ||nfs_inode_finish_partial_attr_update (fattr, inode)) ret =nfs_update_inode (inode, fattr);else if (attr_cmp ==0 ) ret =nfs_check_inode_attributes (inode, fattr);
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 23/26 NFSv4: nfs4_inc/dec_nlink_locked should also invalidate ctime
From: Trond Myklebust <[email protected]>
If the nlink changes, then so will the ctime.
--- fs/nfs/nfs4proc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
fs/nfs/nfs4proc.c +11 -7
@@ -1169,14 +1169,18 @@ int nfs4_call_sync(struct rpc_clnt *clnt,static void nfs4_inc_nlink_locked (struct inode *inode) { -nfs_set_cache_invalid (inode,NFS_INO_INVALID_NLINK ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_CHANGE | +NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_NLINK );inc_nlink (inode); }static void nfs4_dec_nlink_locked (struct inode *inode) { -nfs_set_cache_invalid (inode,NFS_INO_INVALID_NLINK ); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_CHANGE | +NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_NLINK );drop_nlink (inode); }
@@ -4602,11 +4606,11 @@ _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) status =nfs4_call_sync (server->client, server, &msg, &args.seq_args, &res.seq_res,1 );if (status ==0 ) {spin_lock (&dir->i_lock); -nfs4_update_changeattr_locked (dir, &res.cinfo, timestamp, -NFS_INO_INVALID_DATA );/* Removing a directory decrements nlink in the parent */ if (ftype ==NF4DIR && dir->i_nlink >2 )nfs4_dec_nlink_locked (dir); +nfs4_update_changeattr_locked (dir, &res.cinfo, timestamp, +NFS_INO_INVALID_DATA );spin_unlock (&dir->i_lock); }return status;
@@ -4864,12 +4868,12 @@ static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_ &data->arg.seq_args, &data->res.seq_res, 1);if (status ==0 ) {spin_lock (&dir->i_lock); -nfs4_update_changeattr_locked (dir, &data->res.dir_cinfo, - data->res.fattr->time_start, -NFS_INO_INVALID_DATA );/* Creating a directory bumps nlink in the parent */ if (data->arg.ftype ==NF4DIR )nfs4_inc_nlink_locked (dir); +nfs4_update_changeattr_locked (dir, &data->res.dir_cinfo, + data->res.fattr->time_start, +NFS_INO_INVALID_DATA );spin_unlock (&dir->i_lock); status =nfs_instantiate (dentry, data->res.fh, data->res.fattr, data->res.label); }
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 24/26 NFSv4: link must update the inode nlink.
From: Trond Myklebust <[email protected]>
--- fs/nfs/dir.c | 2 +- fs/nfs/nfs4proc.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
fs/nfs/dir.c +1 -1
@@ -1711,7 +1711,7 @@ static void nfs_drop_nlink(struct inode *inode)NFS_I (inode)->attr_gencount =nfs_inc_attr_generation_counter ();nfs_set_cache_invalid ( inode,NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME | -NFS_INO_INVALID_NLINK |NFS_INO_REVAL_FORCED ); +NFS_INO_INVALID_NLINK );spin_unlock (&inode->i_lock); }
fs/nfs/nfs4proc.c +9 -0
@@ -1175,6 +1175,14 @@ nfs4_inc_nlink_locked(struct inode *inode)inc_nlink (inode); } +static void +nfs4_inc_nlink (struct inode *inode) +{ +spin_lock (&inode->i_lock); +nfs4_inc_nlink_locked (inode); +spin_unlock (&inode->i_lock); +} +static void nfs4_dec_nlink_locked (struct inode *inode) {
@@ -4791,6 +4799,7 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, const structif (!status) {nfs4_update_changeattr (dir, &res.cinfo, res.fattr->time_start,NFS_INO_INVALID_DATA ); +nfs4_inc_nlink (inode); status =nfs_post_op_update_inode (inode, res.fattr);if (!status)nfs_setsecurity (inode, res.fattr, res.label);
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 25/26 NFS: Don't store NFS_INO_REVAL_FORCED
From: Trond Myklebust <[email protected]>
NFS_INO_REVAL_FORCED is intended to tell us that the cache needs revalidation despite the fact that we hold a delegation. We shouldn't need to store it anymore, though.
--- fs/nfs/delegation.c | 21 +++++++++++---- fs/nfs/delegation.h | 3 +-- fs/nfs/inode.c | 66 +++++++++++++++++---------------------------- fs/nfs/nfs4proc.c | 5 +--- 4 files changed, 43 insertions(+), 52 deletions(-)
fs/nfs/delegation.c +16 -5
@@ -481,6 +481,22 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,if (freeme ==NULL ) goto out; add_new: +/* +* If we didn't revalidate the change attribute before setting +* the delegation, then pre-emptively ask for a full attribute +* cache revalidation. +*/ +spin_lock (&inode->i_lock); +if (NFS_I (inode)->cache_validity &NFS_INO_INVALID_CHANGE ) +nfs_set_cache_invalid (inode, +NFS_INO_INVALID_ATIME |NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE | +NFS_INO_INVALID_BLOCKS |NFS_INO_INVALID_NLINK | +NFS_INO_INVALID_OTHER |NFS_INO_INVALID_DATA | +NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL | +NFS_INO_INVALID_XATTR ); +spin_unlock (&inode->i_lock); +list_add_tail_rcu (&delegation->super_list, &server->delegations);rcu_assign_pointer (nfsi->delegation, delegation); delegation =NULL ;
@@ -488,11 +504,6 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,atomic_long_inc (&nfs_active_delegations);trace_nfs4_set_delegation (inode, type); - -spin_lock (&inode->i_lock); -if (NFS_I (inode)->cache_validity & (NFS_INO_INVALID_ATTR |NFS_INO_INVALID_ATIME )) -NFS_I (inode)->cache_validity |=NFS_INO_REVAL_FORCED ; -spin_unlock (&inode->i_lock); out:spin_unlock (&clp->cl_lock);if (delegation !=NULL )
fs/nfs/delegation.h +1 -2
@@ -84,8 +84,7 @@ int nfs4_inode_make_writeable(struct inode *inode);static inline int nfs_have_delegated_attributes (struct inode *inode) { -return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ) && - !(NFS_I (inode)->cache_validity &NFS_INO_REVAL_FORCED ); +return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ); }#endif
fs/nfs/inode.c +25 -41
153 lines not on this page · raw message
fs/nfs/nfs4proc.c +1 -4
@@ -5477,10 +5477,7 @@ static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src,if (cache_validity &NFS_INO_INVALID_BLOCKS ) bitmask[1 ] |=FATTR4_WORD1_SPACE_USED ; -if (nfs4_have_delegation (inode,FMODE_READ ) && - !(cache_validity &NFS_INO_REVAL_FORCED )) - bitmask[0 ] &= ~FATTR4_WORD0_SIZE ; -else if (cache_validity &NFS_INO_INVALID_SIZE ) +if (cache_validity &NFS_INO_INVALID_SIZE ) bitmask[0 ] |=FATTR4_WORD0_SIZE ;for (i =0 ; i <NFS4_BITMASK_SZ ; i++)
Signature · 1 line
2.30.2
[email protected]
maintainerPATCH v2 26/26 NFS: Split attribute support out from the server capabilities
From: Trond Myklebust <[email protected]>
There are lots of attributes, and they are crowding out the bit space.
--- fs/nfs/client.c | 15 +++++++++--- fs/nfs/inode.c | 51 ++++++++++++++++++++++++--------------- fs/nfs/nfs4proc.c | 49 +++++++++++++++++++------------------ include/linux/nfs_fs_sb.h | 11 ++------- 4 files changed, 70 insertions(+), 56 deletions(-)
fs/nfs/client.c +12 -3
@@ -696,9 +696,18 @@ static int nfs_init_server(struct nfs_server *server,/* Initialise the client representation from the mount data */ server->flags = ctx->flags; server->options = ctx->options; - server->caps |=NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS |NFS_CAP_FILEID | -NFS_CAP_MODE |NFS_CAP_NLINK |NFS_CAP_OWNER |NFS_CAP_OWNER_GROUP | -NFS_CAP_ATIME |NFS_CAP_CTIME |NFS_CAP_MTIME ; + server->caps |=NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS ; + +switch (clp->rpc_ops->version) { +case 2 : + server->fattr_valid =NFS_ATTR_FATTR_V2 ; +break ; +case 3 : + server->fattr_valid =NFS_ATTR_FATTR_V3 ; +break ; +default : + server->fattr_valid =NFS_ATTR_FATTR_V4 ; + }if (ctx->rsize) server->rsize =nfs_block_size (ctx->rsize,NULL );
fs/nfs/inode.c +31 -20
159 lines not on this page · raw message
fs/nfs/nfs4proc.c +25 -24
62 lines not on this page · raw message
include/linux/nfs_fs_sb.h +2 -9
@@ -191,6 +191,8 @@ struct nfs_server {dev_t s_dev;/* superblock dev numbers */ struct nfs_auth_info auth_info;/* parsed auth flavors */ +__u64 fattr_valid;/* Valid attributes */ +#ifdef CONFIG_NFS_FSCACHE struct nfs_fscache_key *fscache_key;/* unique key for superblock */ struct fscache_cookie *fscache;/* superblock cookie */
@@ -267,16 +269,7 @@ struct nfs_server {#define NFS_CAP_SYMLINKS (1U << 2)#define NFS_CAP_ACLS (1U << 3)#define NFS_CAP_ATOMIC_OPEN (1U << 4) -/* #define NFS_CAP_CHANGE_ATTR (1U << 5) */ #define NFS_CAP_LGOPEN (1U << 5) -#define NFS_CAP_FILEID (1U << 6) -#define NFS_CAP_MODE (1U << 7) -#define NFS_CAP_NLINK (1U << 8) -#define NFS_CAP_OWNER (1U << 9) -#define NFS_CAP_OWNER_GROUP (1U << 10) -#define NFS_CAP_ATIME (1U << 11) -#define NFS_CAP_CTIME (1U << 12) -#define NFS_CAP_MTIME (1U << 13)#define NFS_CAP_POSIX_LOCK (1U << 14)#define NFS_CAP_UIDGID_NOMAP (1U << 15)#define NFS_CAP_STATEID_NFSV41 (1U << 16)
Signature · 1 line
2.30.2