Finer grained attribute checking for NFSv4.x
Subsystems (2)
cover Finer grained attribute checking for NFSv4.x
This patch series allows the NFS client to track attribute information on a more fine grained basis, so that we do not end up worrying about the validity of the mode, owner, group etc information when asked about the timestamps.
Basically, this means that the NFSv4 cache consistency data is tracked separately from the other attribute data, allowing it to be revalidated by the cache consistency GETATTR operations.
Trond Myklebust (6):
NFS: Convert NFS_INO_INVALID flags to unsigned long
NFS: Don't force a revalidation of all attributes if change is missing
NFS: Don't redirty the attribute cache in nfs_wcc_update_inode()
NFS: Don't force unnecessary cache invalidation in nfs_update_inode()
NFS: More fine grained attribute tracking
NFSv4: Ignore change attribute invalidations if we hold a delegation
fs/nfs/dir.c | 4 +- fs/nfs/inode.c | 132 ++++++++++++++++++++++++++++--------------------- fs/nfs/nfs4proc.c | 7 ++- fs/nfs/write.c | 7 ++- include/linux/nfs_fs.h | 35 ++++++++----- 5 files changed, 111 insertions(+), 74 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/6 NFS: Convert NFS_INO_INVALID flags to unsigned long
The cache validity attribute is unsigned long, so make sure that the flags are too.
--- include/linux/nfs_fs.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
include/linux/nfs_fs.h +8 -8
@@ -198,14 +198,14 @@ struct nfs_inode {/* * Cache validity bit flags */ -#define NFS_INO_INVALID_ATTR 0x0001/* cached attrs are invalid */ -#define NFS_INO_INVALID_DATA 0x0002/* cached data is invalid */ -#define NFS_INO_INVALID_ATIME 0x0004/* cached atime is invalid */ -#define NFS_INO_INVALID_ACCESS 0x0008/* cached access cred invalid */ -#define NFS_INO_INVALID_ACL 0x0010/* cached acls are invalid */ -#define NFS_INO_REVAL_PAGECACHE 0x0020/* must revalidate pagecache */ -#define NFS_INO_REVAL_FORCED 0x0040/* force revalidation ignoring a delegation */ -#define NFS_INO_INVALID_LABEL 0x0080/* cached label is invalid */ +#define NFS_INO_INVALID_ATTR BIT(0)/* cached attrs are invalid */ +#define NFS_INO_INVALID_DATA BIT(1)/* cached data is invalid */ +#define NFS_INO_INVALID_ATIME BIT(2)/* cached atime is invalid */ +#define NFS_INO_INVALID_ACCESS BIT(3)/* cached access cred invalid */ +#define NFS_INO_INVALID_ACL BIT(4)/* cached acls are invalid */ +#define NFS_INO_REVAL_PAGECACHE BIT(5)/* must revalidate pagecache */ +#define NFS_INO_REVAL_FORCED BIT(6)/* force revalidation ignoring a delegation */ +#define NFS_INO_INVALID_LABEL BIT(7)/* cached label is invalid */ /* * Bit offsets in flags field
Signature · 1 line
2.14.3
PATCH 2/6 NFS: Don't force a revalidation of all attributes if change is missing
Even if the change attribute is missing, it is still OK to mark the other attributes as being up to date.
--- fs/nfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/nfs/inode.c +4 -1
@@ -1813,7 +1813,10 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)inode_set_iversion_raw (inode, fattr->change_attr); } }else { - nfsi->cache_validity |= save_cache_validity; + nfsi->cache_validity |= save_cache_validity & + (NFS_INO_INVALID_ATTR + |NFS_INO_REVAL_PAGECACHE + |NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
Signature · 1 line
2.14.3
PATCH 3/6 NFS: Don't redirty the attribute cache in nfs_wcc_update_inode()
If we received weak cache consistency data from the server, then those attributes are up to date, and there is no reason to mark them as dirty in the attribute cache.
--- fs/nfs/inode.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
fs/nfs/inode.c +2 -10
@@ -1303,24 +1303,20 @@ static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)return nfs_file_has_writers (nfsi) &&nfs_file_io_is_buffered (nfsi); } -static unsigned long nfs_wcc_update_inode (struct inode *inode,struct nfs_fattr *fattr) +static void nfs_wcc_update_inode (struct inode *inode,struct nfs_fattr *fattr) { -unsigned long ret =0 ; -if ((fattr->valid &NFS_ATTR_FATTR_PRECHANGE ) && (fattr->valid &NFS_ATTR_FATTR_CHANGE ) &&inode_eq_iversion_raw (inode, fattr->pre_change_attr)) {inode_set_iversion_raw (inode, fattr->change_attr);if (S_ISDIR (inode->i_mode))nfs_set_cache_invalid (inode,NFS_INO_INVALID_DATA ); - ret |=NFS_INO_INVALID_ATTR ; }/* If we have atomic WCC data, we may update some attributes */ if ((fattr->valid &NFS_ATTR_FATTR_PRECTIME ) && (fattr->valid &NFS_ATTR_FATTR_CTIME ) &×pec_equal (&inode->i_ctime, &fattr->pre_ctime)) {memcpy (&inode->i_ctime, &fattr->ctime,sizeof (inode->i_ctime)); - ret |=NFS_INO_INVALID_ATTR ; } if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
@@ -1329,17 +1325,13 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattrmemcpy (&inode->i_mtime, &fattr->mtime,sizeof (inode->i_mtime));if (S_ISDIR (inode->i_mode))nfs_set_cache_invalid (inode,NFS_INO_INVALID_DATA ); - ret |=NFS_INO_INVALID_ATTR ; }if ((fattr->valid &NFS_ATTR_FATTR_PRESIZE ) && (fattr->valid &NFS_ATTR_FATTR_SIZE ) &&i_size_read (inode) ==nfs_size_to_loff_t (fattr->pre_size) && !nfs_have_writebacks (inode)) {i_size_write (inode,nfs_size_to_loff_t (fattr->size)); - ret |=NFS_INO_INVALID_ATTR ; } - -return ret; }/**
@@ -1789,7 +1781,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | NFS_INO_REVAL_PAGECACHE);/* Do atomic weak cache consistency updates */ - invalid |=nfs_wcc_update_inode (inode, fattr); +nfs_wcc_update_inode (inode, fattr);if (pnfs_layoutcommit_outstanding (inode)) { nfsi->cache_validity |= save_cache_validity &NFS_INO_INVALID_ATTR ;
Signature · 1 line
2.14.3
PATCH 4/6 NFS: Don't force unnecessary cache invalidation in nfs_update_inode()
If we managed to revalidate all the attributes, then there is no reason to mark them as invalid again. We do, however want to ensure that we set nfsi->attrtimeo correctly.
--- fs/nfs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfs/inode.c +3 -4
@@ -1799,6 +1799,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | NFS_INO_INVALID_DATA |NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL ; +/* Force revalidate of all attributes */ + save_cache_validity |=NFS_INO_INVALID_ATTR ;if (S_ISDIR (inode->i_mode))nfs_force_lookup_revalidate (inode); }
@@ -1937,6 +1939,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)/* Update attrtimeo value if we're out of the unstable period */ if (invalid &NFS_INO_INVALID_ATTR ) { + invalid &= ~NFS_INO_INVALID_ATTR ;nfs_inc_stats (inode,NFSIOS_ATTRINVALIDATE ); nfsi->attrtimeo =NFS_MINATTRTIMEO (inode); nfsi->attrtimeo_timestamp = now;
@@ -1957,10 +1960,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) nfsi->attr_gencount = fattr->gencount; } -/* Don't declare attrcache up to date if there were no attrs! */ -if (cache_revalidated) - invalid &= ~NFS_INO_INVALID_ATTR ; -/* Don't invalidate the data if we were to blame */ if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode)))
Signature · 1 line
2.14.3
PATCH 5/6 NFS: More fine grained attribute tracking
Currently, if the NFS_INO_INVALID_ATTR flag is set, for instance by a call to nfs_post_op_update_inode_locked(), then it will not be cleared until all the attributes have been revalidated. This means, for instance, that NFSv4 writes will always force a full attribute revalidation.
Track the ctime, mtime, size and change attribute separately from the other attributes so that we can have nfs_post_op_update_inode_locked() set them correctly, and later have the cache consistency bitmask be able to clear them.
--- fs/nfs/dir.c | 4 +- fs/nfs/inode.c | 109 +++++++++++++++++++++++++++++-------------------- fs/nfs/nfs4proc.c | 7 +++- fs/nfs/write.c | 7 +++- include/linux/nfs_fs.h | 21 +++++++--- 5 files changed, 94 insertions(+), 54 deletions(-)
fs/nfs/dir.c +3 -1
@@ -1272,7 +1272,9 @@ static void nfs_drop_nlink(struct inode *inode)/* drop the inode if we're reasonably sure this is the last link */ if (inode->i_nlink ==1 )clear_nlink (inode); -NFS_I (inode)->cache_validity |=NFS_INO_INVALID_ATTR ; +NFS_I (inode)->cache_validity |=NFS_INO_INVALID_CHANGE + |NFS_INO_INVALID_CTIME + |NFS_INO_INVALID_OTHER ;spin_unlock (&inode->i_lock); }
fs/nfs/inode.c +65 -44
293 lines not on this page · raw message
fs/nfs/nfs4proc.c +5 -2
@@ -1045,7 +1045,9 @@ static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo,struct nfs_inode *nfsi =NFS_I (dir);spin_lock (&dir->i_lock); - nfsi->cache_validity |=NFS_INO_INVALID_ATTR |NFS_INO_INVALID_DATA ; + nfsi->cache_validity |=NFS_INO_INVALID_CTIME + |NFS_INO_INVALID_MTIME + |NFS_INO_INVALID_DATA ;if (cinfo->atomic && cinfo->before ==inode_peek_iversion_raw (dir)) { nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE ; nfsi->attrtimeo_timestamp = jiffies;
@@ -5364,7 +5366,8 @@ 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_ATTR ; +NFS_I (inode)->cache_validity |=NFS_INO_INVALID_CHANGE + |NFS_INO_INVALID_CTIME ;spin_unlock (&inode->i_lock);nfs_access_zap_cache (inode);nfs_zap_acl_cache (inode);
fs/nfs/write.c +5 -2
@@ -1562,8 +1562,11 @@ static int nfs_writeback_done(struct rpc_task *task, }/* Deal with the suid/sgid bit corner case */ -if (nfs_should_remove_suid (inode)) -nfs_mark_for_revalidate (inode); +if (nfs_should_remove_suid (inode)) { +spin_lock (&inode->i_lock); +NFS_I (inode)->cache_validity |=NFS_INO_INVALID_OTHER ; +spin_unlock (&inode->i_lock); + }return 0 ; }
include/linux/nfs_fs.h +16 -5
@@ -198,7 +198,6 @@ struct nfs_inode {/* * Cache validity bit flags */ -#define NFS_INO_INVALID_ATTR BIT(0)/* cached attrs are invalid */ #define NFS_INO_INVALID_DATA BIT(1)/* cached data is invalid */ #define NFS_INO_INVALID_ATIME BIT(2)/* cached atime is invalid */ #define NFS_INO_INVALID_ACCESS BIT(3)/* cached access cred invalid */
@@ -206,6 +205,17 @@ struct nfs_inode {#define NFS_INO_REVAL_PAGECACHE BIT(5)/* must revalidate pagecache */ #define NFS_INO_REVAL_FORCED BIT(6)/* force revalidation ignoring a delegation */ #define NFS_INO_INVALID_LABEL BIT(7)/* cached label is invalid */ +#define NFS_INO_INVALID_CHANGE BIT(8)/* cached change is invalid */ +#define NFS_INO_INVALID_CTIME BIT(9)/* cached ctime is invalid */ +#define NFS_INO_INVALID_MTIME BIT(10)/* cached mtime is invalid */ +#define NFS_INO_INVALID_SIZE BIT(11)/* cached size is invalid */ +#define NFS_INO_INVALID_OTHER BIT(12)/* other attrs are 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_OTHER)/* inode metadata is invalid */ /* * Bit offsets in flags field
@@ -292,10 +302,11 @@ static inline void nfs_mark_for_revalidate(struct inode *inode)struct nfs_inode *nfsi =NFS_I (inode);spin_lock (&inode->i_lock); - nfsi->cache_validity |=NFS_INO_INVALID_ATTR | -NFS_INO_REVAL_PAGECACHE | -NFS_INO_INVALID_ACCESS | -NFS_INO_INVALID_ACL ; + nfsi->cache_validity |=NFS_INO_REVAL_PAGECACHE + |NFS_INO_INVALID_ACCESS + |NFS_INO_INVALID_ACL + |NFS_INO_INVALID_CHANGE + |NFS_INO_INVALID_CTIME ;if (S_ISDIR (inode->i_mode)) nfsi->cache_validity |=NFS_INO_INVALID_DATA ;spin_unlock (&inode->i_lock);
Signature · 1 line
2.14.3
PATCH 6/6 NFSv4: Ignore change attribute invalidations if we hold a delegation
Don't bother even recording an invalid change attribute if we hold a delegation since we already know the state of our attribute cache. We can rely on the fact that we will pick up a copy from the server when we return the delegation.
--- fs/nfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)
fs/nfs/inode.c +3 -0
@@ -200,7 +200,10 @@ bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)static void nfs_set_cache_invalid (struct inode *inode,unsigned long flags) {struct nfs_inode *nfsi =NFS_I (inode); +bool have_delegation =nfs_have_delegated_attributes (inode); +if (have_delegation) + flags &= ~(NFS_INO_INVALID_CHANGE |NFS_INO_REVAL_PAGECACHE );if (inode->i_mapping->nrpages ==0 ) flags &= ~NFS_INO_INVALID_DATA ; nfsi->cache_validity |= flags;
Signature · 1 line
2.14.3