Commit 63519fbc authored by Trond Myklebust's avatar Trond Myklebust

NFS: Be more targeted about readdirplus use when doing lookup/revalidation

There is little point in setting NFS_INO_ADVISE_RDPLUS in nfs_lookup and
nfs_lookup_revalidate() unless a process is actually doing readdir on the
parent directory.
Furthermore, there is little point in using readdirplus if we're trying
to revalidate a negative dentry.
Reviewed-by: default avatarBenjamin Coddington <bcodding@redhat.com>
Tested-by: default avatarBenjamin Coddington <bcodding@redhat.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent 79f687a3
...@@ -455,14 +455,18 @@ bool nfs_use_readdirplus(struct inode *dir, struct dir_context *ctx) ...@@ -455,14 +455,18 @@ bool nfs_use_readdirplus(struct inode *dir, struct dir_context *ctx)
} }
/* /*
* This function is called by the lookup code to request the use of * This function is called by the lookup and getattr code to request the
* readdirplus to accelerate any future lookups in the same * use of readdirplus to accelerate any future lookups in the same
* directory. * directory.
*/ */
static static
void nfs_advise_use_readdirplus(struct inode *dir) void nfs_advise_use_readdirplus(struct inode *dir)
{ {
set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(dir)->flags); struct nfs_inode *nfsi = NFS_I(dir);
if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) &&
!list_empty(&nfsi->open_files))
set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags);
} }
/* /*
...@@ -475,8 +479,11 @@ void nfs_advise_use_readdirplus(struct inode *dir) ...@@ -475,8 +479,11 @@ void nfs_advise_use_readdirplus(struct inode *dir)
*/ */
void nfs_force_use_readdirplus(struct inode *dir) void nfs_force_use_readdirplus(struct inode *dir)
{ {
if (!list_empty(&NFS_I(dir)->open_files)) { struct nfs_inode *nfsi = NFS_I(dir);
nfs_advise_use_readdirplus(dir);
if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) &&
!list_empty(&nfsi->open_files)) {
set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags);
invalidate_mapping_pages(dir->i_mapping, 0, -1); invalidate_mapping_pages(dir->i_mapping, 0, -1);
} }
} }
...@@ -1150,7 +1157,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags) ...@@ -1150,7 +1157,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
return -ECHILD; return -ECHILD;
goto out_bad; goto out_bad;
} }
goto out_valid_noent; goto out_valid;
} }
if (is_bad_inode(inode)) { if (is_bad_inode(inode)) {
...@@ -1173,6 +1180,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags) ...@@ -1173,6 +1180,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
return -ECHILD; return -ECHILD;
goto out_zap_parent; goto out_zap_parent;
} }
nfs_advise_use_readdirplus(dir);
goto out_valid; goto out_valid;
} }
...@@ -1208,12 +1216,12 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags) ...@@ -1208,12 +1216,12 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
nfs_free_fhandle(fhandle); nfs_free_fhandle(fhandle);
nfs4_label_free(label); nfs4_label_free(label);
/* set a readdirplus hint that we had a cache miss */
nfs_force_use_readdirplus(dir);
out_set_verifier: out_set_verifier:
nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
out_valid: out_valid:
/* Success: notify readdir to use READDIRPLUS */
nfs_advise_use_readdirplus(dir);
out_valid_noent:
if (flags & LOOKUP_RCU) { if (flags & LOOKUP_RCU) {
if (parent != ACCESS_ONCE(dentry->d_parent)) if (parent != ACCESS_ONCE(dentry->d_parent))
return -ECHILD; return -ECHILD;
...@@ -1413,8 +1421,8 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in ...@@ -1413,8 +1421,8 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
if (IS_ERR(res)) if (IS_ERR(res))
goto out_label; goto out_label;
/* Success: notify readdir to use READDIRPLUS */ /* Notify readdir to use READDIRPLUS */
nfs_advise_use_readdirplus(dir); nfs_force_use_readdirplus(dir);
no_entry: no_entry:
res = d_splice_alias(inode, dentry); res = d_splice_alias(inode, dentry);
......
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