Skip to content

Commit 4fa2c54

Browse files
neilbrowntrondmypd
authored andcommitted
NFS: nfs4_do_open should add negative results to the dcache.
If you have an NFSv4 mounted directory which does not container 'foo' and: ls -l foo ssh $server touch foo cat foo then the 'cat' will fail (usually, depending a bit on the various cache ages). This is correct as negative looks are cached by default. However with the same initial conditions: cat foo ssh $server touch foo cat foo will usually succeed. This is because an "open" does not add a negative dentry to the dcache, while a "lookup" does. This can have negative performance effects. When "gcc" searches for an include file, it will try to "open" the file in every director in the search path. Without caching of negative "open" results, this generates much more traffic to the server than it should (or than NFSv3 does). The root of the problem is that _nfs4_open_and_get_state() will call d_add_unique() on a positive result, but not on a negative result. Compare with nfs_lookup() which calls d_materialise_unique on both a positive result and on ENOENT. This patch adds a call d_add() in the ENOENT case for _nfs4_open_and_get_state() and also calls nfs_set_verifier(). With it, many fewer "open" requests for known-non-existent files are sent to the server. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 7a9e75a commit 4fa2c54

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/nfs/nfs4proc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,15 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
22242224
seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
22252225

22262226
ret = _nfs4_proc_open(opendata);
2227-
if (ret != 0)
2227+
if (ret != 0) {
2228+
if (ret == -ENOENT) {
2229+
d_drop(opendata->dentry);
2230+
d_add(opendata->dentry, NULL);
2231+
nfs_set_verifier(opendata->dentry,
2232+
nfs_save_change_attribute(opendata->dir->d_inode));
2233+
}
22282234
goto out;
2235+
}
22292236

22302237
state = nfs4_opendata_to_nfs4_state(opendata);
22312238
ret = PTR_ERR(state);

0 commit comments

Comments
 (0)