All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: linux-fsdevel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Miklos Szeredi <mszeredi@redhat.com>,
	Trond Myklebust <trond.myklebust@primarydata.com>
Subject: [PATCH 01/16] nfs_instantiate(): prevent multiple aliases for directory inode
Date: Sun, 29 Jul 2018 23:04:38 +0100	[thread overview]
Message-ID: <20180729220453.13431-1-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20180729220317.GB30522@ZenIV.linux.org.uk>

From: Al Viro <viro@zeniv.linux.org.uk>

Since NFS allows open-by-fhandle, we have to cope with the possibility
of mkdir vs. open-by-guessed-handle races.  A local filesystem could
decide what the inumber of the new object will be and insert a locked
inode with that inumber into icache _before_ the on-disk data structures
begin to look good and unlock it only once it has a dentry alias, so
that open-by-handle coming first would quietly fail and mkdir coming
first would have open-by-handle grab its dentry.

For NFS it's a non-starter - the icache key is server-supplied fhandle
and we do not get that until the object has been fully created on server.
We really have to deal with the possibility that open-by-handle gets
the in-core inode and attaches a dentry to it before mkdir does.

Solution: let nfs_mkdir() use d_splice_alias() to catch those.  We can
	* get an error.  Just return it to our caller.
	* get NULL - no preexisting dentry aliases, we'd just done what
d_add() would've done.  Success.
	* get a reference to preexisting alias.  In that case the alias
had been moved in place of nfs_mkdir() argument (and hashed there), while
nfs_mkdir() argument is left unhashed negative.  Which is just fine for
->mkdir() callers, all we need is to release the reference we'd got from
d_splice_alias() and report success.

Cc: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/nfs/dir.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 7a9c14426855..df6fd4e5b068 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1641,6 +1641,7 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
 	struct dentry *parent = dget_parent(dentry);
 	struct inode *dir = d_inode(parent);
 	struct inode *inode;
+	struct dentry *d;
 	int error = -EACCES;
 
 	d_drop(dentry);
@@ -1662,10 +1663,12 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
 			goto out_error;
 	}
 	inode = nfs_fhget(dentry->d_sb, fhandle, fattr, label);
-	error = PTR_ERR(inode);
-	if (IS_ERR(inode))
+	d = d_splice_alias(inode, dentry);
+	if (IS_ERR(d)) {
+		error = PTR_ERR(d);
 		goto out_error;
-	d_add(dentry, inode);
+	}
+	dput(d);
 out:
 	dput(parent);
 	return 0;
-- 
2.11.0


  reply	other threads:[~2018-07-29 22:06 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-29 22:03 [PATCHES][RFC] icache-related stuff Al Viro
2018-07-29 22:04 ` Al Viro [this message]
2018-07-29 22:04   ` [PATCH 02/16] new primitive: discard_new_inode() Al Viro
2018-07-29 22:04   ` [PATCH 03/16] vfs: don't evict uninitialized inode Al Viro
2018-07-30  5:09     ` Amir Goldstein
2018-07-30  7:41       ` Miklos Szeredi
2018-08-16 16:29         ` Amir Goldstein
2018-08-24  6:47           ` Amir Goldstein
2018-10-08  6:41             ` Miklos Szeredi
2018-10-08 13:23               ` Greg KH
2018-07-29 22:04   ` [PATCH 04/16] btrfs: switch to discard_new_inode() Al Viro
2018-08-01 15:25     ` David Sterba
2018-07-29 22:04   ` [PATCH 05/16] ufs: " Al Viro
2018-07-29 22:04   ` [PATCH 06/16] udf: " Al Viro
2018-07-29 22:04   ` [PATCH 07/16] ext2: make sure that partially set up inodes won't be returned by ext2_iget() Al Viro
2018-07-29 22:04   ` [PATCH 08/16] btrfs: btrfs_iget() never returns an is_bad_inode() inode Al Viro
2018-07-30  8:13     ` Nikolay Borisov
2018-07-29 22:04   ` [PATCH 09/16] btrfs: IS_ERR(p) && PTR_ERR(p) == n is a weird way to spell p == ERR_PTR(n) Al Viro
2018-07-30  8:06     ` Nikolay Borisov
2018-07-29 22:04   ` [PATCH 10/16] kill d_instantiate_no_diralias() Al Viro
2018-07-29 22:04   ` [PATCH 11/16] jfs: switch to discard_new_inode() Al Viro
2018-07-29 22:04   ` [PATCH 12/16] new helper: inode_fake_hash() Al Viro
2018-07-29 22:04   ` [PATCH 13/16] btrfs: lift make_bad_inode() into btrfs_iget() Al Viro
2018-07-30  8:15     ` Nikolay Borisov
2018-07-29 22:04   ` [PATCH 14/16] btrfs: simplify btrfs_iget() Al Viro
2018-07-30  8:17     ` Nikolay Borisov
2018-07-29 22:04   ` [PATCH 15/16] adfs: don't put inodes into icache Al Viro
2018-07-29 22:04   ` [PATCH 16/16] jfs: don't bother with make_bad_inode() in ialloc() Al Viro
2018-07-30 21:35 ` [PATCHES][RFC] icache-related stuff Linus Torvalds
2018-08-01 15:25 ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180729220453.13431-1-viro@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=trond.myklebust@primarydata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.