NFS: Shortcut lookup revalidations if we have a directory delegation

Holding a directory delegation means we know that nobody else has
modified the directory on the server, so we can take a few revalidation
shortcuts.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
Anna Schumaker
2025-11-04 10:06:44 -05:00
committed by Trond Myklebust
parent 2da2116707
commit 669c0580ac
3 changed files with 27 additions and 0 deletions

View File

@@ -130,6 +130,11 @@ static inline void nfs_request_directory_delegation(struct inode *inode)
set_bit(NFS_INO_REQ_DIR_DELEG, &NFS_I(inode)->flags);
}
static inline bool nfs_have_directory_delegation(struct inode *inode)
{
return S_ISDIR(inode->i_mode) && nfs_have_delegated_attributes(inode);
}
int nfs4_delegation_hash_alloc(struct nfs_server *server);
#endif

View File

@@ -1515,6 +1515,15 @@ static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,
return 0;
if (!nfs_dentry_verify_change(dir, dentry))
return 0;
/*
* If we have a directory delegation then we don't need to revalidate
* the directory. The delegation will either get recalled or we will
* receive a notification when it changes.
*/
if (nfs_have_directory_delegation(dir))
return 0;
/* Revalidate nfsi->cache_change_attribute before we declare a match */
if (nfs_mapping_need_revalidate_inode(dir)) {
if (rcu_walk)
@@ -2207,6 +2216,13 @@ no_open:
}
EXPORT_SYMBOL_GPL(nfs_atomic_open);
static int
nfs_lookup_revalidate_delegated_parent(struct inode *dir, struct dentry *dentry,
struct inode *inode)
{
return nfs_lookup_revalidate_done(dir, dentry, inode, 1);
}
static int
nfs4_lookup_revalidate(struct inode *dir, const struct qstr *name,
struct dentry *dentry, unsigned int flags)
@@ -2234,6 +2250,9 @@ nfs4_lookup_revalidate(struct inode *dir, const struct qstr *name,
if (nfs_verifier_is_delegated(dentry))
return nfs_lookup_revalidate_delegated(dir, dentry, inode);
if (nfs_have_directory_delegation(dir))
return nfs_lookup_revalidate_delegated_parent(dir, dentry, inode);
/* NFS only supports OPEN on regular files */
if (!S_ISREG(inode->i_mode))
goto full_reval;

View File

@@ -1389,6 +1389,9 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
status = pnfs_sync_inode(inode, false);
if (status)
goto out;
} else if (nfs_have_directory_delegation(inode)) {
status = 0;
goto out;
}
status = -ENOMEM;