Commit ad1e109a authored by Trond Myklebust's avatar Trond Myklebust

NFS: Don't ask for readdirplus unless it can help nfs_getattr()

If attribute caching is turned off, then use of readdirplus is not going
to help stat() performance.
Readdirplus also doesn't help if a file is being written to, since we
will have to flush those writes in order to sync the mtime/ctime.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent 230bc98f
......@@ -780,26 +780,32 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
}
EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
/*
* Don't request help from readdirplus if the file is being written to,
* or if attribute caching is turned off
*/
static bool nfs_getattr_readdirplus_enable(const struct inode *inode)
{
struct dentry *parent;
return nfs_server_capable(inode, NFS_CAP_READDIRPLUS) &&
!nfs_have_writebacks(inode) && NFS_MAXATTRTIMEO(inode) > 5 * HZ;
}
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
return;
parent = dget_parent(dentry);
nfs_readdir_record_entry_cache_miss(d_inode(parent));
dput(parent);
static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
{
if (!IS_ROOT(dentry)) {
struct dentry *parent = dget_parent(dentry);
nfs_readdir_record_entry_cache_miss(d_inode(parent));
dput(parent);
}
}
static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
{
struct dentry *parent;
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
return;
parent = dget_parent(dentry);
nfs_readdir_record_entry_cache_hit(d_inode(parent));
dput(parent);
if (!IS_ROOT(dentry)) {
struct dentry *parent = dget_parent(dentry);
nfs_readdir_record_entry_cache_hit(d_inode(parent));
dput(parent);
}
}
static u32 nfs_get_valid_attrmask(struct inode *inode)
......@@ -835,6 +841,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
int err = 0;
bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
bool do_update = false;
bool readdirplus_enabled = nfs_getattr_readdirplus_enable(inode);
trace_nfs_getattr_enter(inode);
......@@ -843,7 +850,8 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
STATX_INO | STATX_SIZE | STATX_BLOCKS;
if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
nfs_readdirplus_parent_cache_hit(path->dentry);
if (readdirplus_enabled)
nfs_readdirplus_parent_cache_hit(path->dentry);
goto out_no_revalidate;
}
......@@ -893,15 +901,12 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
if (do_update) {
/* Update the attribute cache */
if (!(server->flags & NFS_MOUNT_NOAC))
if (readdirplus_enabled)
nfs_readdirplus_parent_cache_miss(path->dentry);
else
nfs_readdirplus_parent_cache_hit(path->dentry);
err = __nfs_revalidate_inode(server, inode);
if (err)
goto out;
} else
} else if (readdirplus_enabled)
nfs_readdirplus_parent_cache_hit(path->dentry);
out_no_revalidate:
/* Only return attributes that were revalidated. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment