linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-fsdevel@vger.kernel.org,
	"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 04/11] dcache: d_splice_alias mustn't create directory aliases
Date: Wed,  4 Jun 2014 17:20:56 -0400	[thread overview]
Message-ID: <1401916863-7916-5-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <1401916863-7916-1-git-send-email-bfields@redhat.com>

From: "J. Bruce Fields" <bfields@redhat.com>

Currently if d_splice_alias finds a directory with an alias that is not
IS_ROOT or not DCACHE_DISCONNECTED, it creates a duplicate directory.

Duplicate directory dentries are unacceptable; it is better just to
error out.

(In the case of a local filesystem the most likely case is filesystem
corruption: for example, perhaps two directories point to the same child
directory, and the other parent has already been found and cached.)

Note that distributed filesystems may encounter this case in normal
operation if a remote host moves a directory to a location different
from the one we last cached in the dcache.  For that reason, such
filesystems should instead use d_materialise_unique, which tries to move
the old directory alias to the right place instead of erroring out.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/dcache.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index a833e97..54b602e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2590,6 +2590,9 @@ static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon)
  * DCACHE_DISCONNECTED), then d_move that in place of the given dentry
  * and return it, else simply d_add the inode to the dentry and return NULL.
  *
+ * If a non-IS_ROOT directory is found, the filesystem is corrupt, and
+ * we should error out: directories can't have multiple aliases.
+ *
  * This is needed in the lookup routine of any filesystem that is exportable
  * (via knfsd) so that we can build dcache paths to directories effectively.
  *
@@ -2610,9 +2613,13 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
 
 	if (inode && S_ISDIR(inode->i_mode)) {
 		spin_lock(&inode->i_lock);
-		new = __d_find_alias(inode, 1);
+		new = __d_find_any_alias(inode);
 		if (new) {
-			BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED));
+			if (!IS_ROOT(new) || !(new->d_flags & DCACHE_DISCONNECTED)) {
+				spin_unlock(&inode->i_lock);
+				dput(new);
+				return ERR_PTR(-EIO);
+			}
 			write_seqlock(&rename_lock);
 			__d_materialise_dentry(dentry, new);
 			write_sequnlock(&rename_lock);
-- 
1.7.9.5


  parent reply	other threads:[~2014-06-04 21:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 21:20 [PATCH 00/11] mainly d_splice_alias fixes J. Bruce Fields
2014-06-04 21:20 ` [PATCH 01/11] namei: trivial fix to vfs_rename_dir comment J. Bruce Fields
2014-06-04 21:20 ` [PATCH 02/11] dcache: move d_splice_alias J. Bruce Fields
2014-06-04 21:20 ` [PATCH 03/11] dcache: close d_move race in d_splice_alias J. Bruce Fields
2014-06-04 21:20 ` J. Bruce Fields [this message]
2014-06-04 21:20 ` [PATCH 05/11] dcache: d_splice_alias should ignore DCACHE_DISCONNECTED J. Bruce Fields
2014-06-04 21:20 ` [PATCH 06/11] dcache: d_obtain_alias callers don't all want DISCONNECTED J. Bruce Fields
2014-06-04 21:20 ` [PATCH 07/11] dcache: remove unused d_find_alias parameter J. Bruce Fields
2014-06-04 21:21 ` [PATCH 08/11] dcache: d_find_alias needn't recheck IS_ROOT && DCACHE_DISCONNECTED J. Bruce Fields
2014-06-04 21:21 ` [PATCH 09/11] exportfs: update Exporting documentation J. Bruce Fields
2014-06-04 21:54   ` Bernd Schubert
2014-06-06 21:23     ` J. Bruce Fields
2014-06-05 12:51   ` Marc Dionne
2014-06-06 21:20     ` J. Bruce Fields
2014-06-04 21:21 ` [PATCH 10/11] dcache: d_materialise_unique isn't GPL-only J. Bruce Fields
2014-06-04 21:21 ` [PATCH 11/11] dcache: d_splice_alias should detect loops J. Bruce Fields

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=1401916863-7916-5-git-send-email-bfields@redhat.com \
    --to=bfields@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).