Skip to content

Commit

Permalink
NFS: remove BUG possibility in nfs4_open_and_get_state
Browse files Browse the repository at this point in the history
commit 4fa2c54
    NFS: nfs4_do_open should add negative results to the dcache.

used "d_drop(); d_add();" to ensure that a dentry was hashed
as a negative cached entry.
This is not safe if the dentry has an non-NULL ->d_inode.
It will trigger a BUG_ON in d_instantiate().
In that case, d_delete() is needed.

Also, only d_add if the dentry is currently unhashed, it seems
pointless removed and re-adding it unchanged.

Reported-by: Christoph Hellwig <[email protected]>
Fixes: 4fa2c54
Cc: Jeff Layton <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: NeilBrown <[email protected]>
Acked-by: Jeff Layton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
  • Loading branch information
neilbrown authored and trondmypd committed Sep 12, 2014
1 parent 224ecbf commit f39c010
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2226,9 +2226,13 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
ret = _nfs4_proc_open(opendata);
if (ret != 0) {
if (ret == -ENOENT) {
d_drop(opendata->dentry);
d_add(opendata->dentry, NULL);
nfs_set_verifier(opendata->dentry,
dentry = opendata->dentry;
if (dentry->d_inode)
d_delete(dentry);
else if (d_unhashed(dentry))
d_add(dentry, NULL);

nfs_set_verifier(dentry,
nfs_save_change_attribute(opendata->dir->d_inode));
}
goto out;
Expand Down

0 comments on commit f39c010

Please sign in to comment.