Skip to contentSkip to conversation

NFS: remove BUG possibility in nfs4_open_and_get_state

PATCH In review NeilBrown 2 participants 2 messages Sep 11, 2014

Subsystems (2)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 NFS: remove BUG possibility in nfs4_open_and_get_state

commit 4fa2c54b5198d09607a534e2fd436581064587ed
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.

Fixes 4fa2c54b5198d09607a534e2fd436581064587ed
Cc Jeff Layton <[email protected]>
fs/nfs/nfs4proc.c +7 -3
index 7dd8aca31c29..ac2dd953fc18 100644
@@ -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;
Acked-by on v1 1/1
#1 lore raw
Quoted 31 lines · On Thu, 11 Sep 2014 16:19:37 +1000 NeilBrown <[email protected]> wrote:

commit 4fa2c54b5198d09607a534e2fd436581064587ed
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.

Fixes 4fa2c54b5198d09607a534e2fd436581064587ed
Cc Jeff Layton <[email protected]>
fs/nfs/nfs4proc.c +0 -3
index 7dd8aca31c29..ac2dd953fc18 100644
@@ -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,

fs/nfs/nfs4proc.c static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, · line 2238

Quoted 10 lines
fs/nfs/nfs4proc.c +7 -0
+			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;