Skip to content

Commit f39c010

Browse files
neilbrowntrondmypd
authored andcommitted
NFS: remove BUG possibility in nfs4_open_and_get_state
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]>
1 parent 224ecbf commit f39c010

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/nfs/nfs4proc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,9 +2226,13 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
22262226
ret = _nfs4_proc_open(opendata);
22272227
if (ret != 0) {
22282228
if (ret == -ENOENT) {
2229-
d_drop(opendata->dentry);
2230-
d_add(opendata->dentry, NULL);
2231-
nfs_set_verifier(opendata->dentry,
2229+
dentry = opendata->dentry;
2230+
if (dentry->d_inode)
2231+
d_delete(dentry);
2232+
else if (d_unhashed(dentry))
2233+
d_add(dentry, NULL);
2234+
2235+
nfs_set_verifier(dentry,
22322236
nfs_save_change_attribute(opendata->dir->d_inode));
22332237
}
22342238
goto out;

0 commit comments

Comments
 (0)