From: Al Viro <viro@ZenIV.linux.org.uk>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
mszeredi@suse.cz, David Howells <dhowells@redhat.com>,
Steven Whitehouse <swhiteho@redhat.com>,
Trond Myklebust <Trond.Myklebust@netapp.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 04/11] vfs: check unlinked ancestors before mount
Date: Thu, 5 Sep 2013 12:18:52 +0100 [thread overview]
Message-ID: <20130905111852.GP13318@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1378374284-1484-5-git-send-email-miklos@szeredi.hu>
On Thu, Sep 05, 2013 at 11:44:37AM +0200, Miklos Szeredi wrote:
> +static bool __has_unlinked_ancestor(struct dentry *dentry)
> +{
> + struct dentry *this;
> +
> + for (this = dentry; !IS_ROOT(this); this = this->d_parent) {
> + int is_unhashed;
> +
> + /* Need exclusion wrt. check_submounts_and_drop() */
> + spin_lock(&this->d_lock);
> + is_unhashed = d_unhashed(this);
> + spin_unlock(&this->d_lock);
> +
> + if (is_unhashed)
> + return true;
> + }
> + return false;
> +}
> +
> +/*
> + * Called by mount code to check if the mountpoint is reachable (e.g. NFS can
> + * unhash a directory dentry and then the complete subtree can become
> + * unreachable).
> + */
> +bool has_unlinked_ancestor(struct dentry *dentry)
> +{
> + bool found;
> +
> + /* Need exclusion wrt. check_submounts_and_drop() */
> + write_seqlock(&rename_lock);
> + found = __has_unlinked_ancestor(dentry);
> + write_sequnlock(&rename_lock);
> +
> + return found;
> +}
> +
> /*
> * Search the dentry child list of the specified parent,
> * and move any unused dentries to the end of the unused
> diff --git a/fs/internal.h b/fs/internal.h
> index 7c5f01c..d232355 100644
> --- a/fs/internal.h
> +++ b/fs/internal.h
> @@ -126,6 +126,7 @@ extern int invalidate_inodes(struct super_block *, bool);
> * dcache.c
> */
> extern struct dentry *__d_alloc(struct super_block *, const struct qstr *);
> +extern bool has_unlinked_ancestor(struct dentry *dentry);
>
> /*
> * read_write.c
> diff --git a/fs/namespace.c b/fs/namespace.c
> index a45ba4f..91b1c39 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -634,6 +634,15 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
> }
> dentry->d_flags |= DCACHE_MOUNTED;
> spin_unlock(&dentry->d_lock);
> +
> + if (has_unlinked_ancestor(dentry)) {
> + spin_lock(&dentry->d_lock);
> + dentry->d_flags &= ~DCACHE_MOUNTED;
> + spin_unlock(&dentry->d_lock);
> + kfree(mp);
> + return ERR_PTR(-ENOENT);
> + }
Something's really odd with locking here. You are take d_lock, do one
check, set flag, drop d_lock, grab rename_lock, do another check (taking
and dropping d_lock in process), and, in case that check fails, grab
d_lock again to clear the flag.
At the very least it's a massive overkill. Just grab rename_lock, then
d_lock, then do the damn check and set the flag only on success. Moreover,
with rename_lock held, do you need d_lock on ancestors to mess with in
has_unlinked_ancestor()?
next prev parent reply other threads:[~2013-09-05 11:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-05 9:44 [PATCH 00/11] [v4] safely drop directory dentry on failed revalidate Miklos Szeredi
2013-09-05 9:44 ` [PATCH 01/11] vfs: restructure d_genocide() Miklos Szeredi
2013-09-05 9:44 ` [PATCH 02/11] vfs: add d_walk() Miklos Szeredi
2013-09-05 9:44 ` [PATCH 03/11] vfs: check submounts and drop atomically Miklos Szeredi
2013-09-05 9:44 ` [PATCH 04/11] vfs: check unlinked ancestors before mount Miklos Szeredi
2013-09-05 11:18 ` Al Viro [this message]
2013-09-05 11:32 ` Miklos Szeredi
2013-09-05 12:02 ` Miklos Szeredi
2013-09-05 12:03 ` Miklos Szeredi
2013-09-05 12:39 ` Miklos Szeredi
2013-09-05 13:23 ` Al Viro
2013-09-05 14:26 ` Miklos Szeredi
2013-09-05 14:56 ` Al Viro
2013-09-05 15:52 ` Miklos Szeredi
2013-09-05 16:07 ` Al Viro
2013-09-05 9:44 ` [PATCH 05/11] afs: use check_submounts_and_drop() Miklos Szeredi
2013-09-05 9:44 ` [PATCH 06/11] gfs2: " Miklos Szeredi
2013-09-05 9:44 ` [PATCH 07/11] nfs: " Miklos Szeredi
2013-09-05 9:44 ` [PATCH 08/11] sysfs: " Miklos Szeredi
2013-09-05 9:44 ` [PATCH 09/11] fuse: use d_materialise_unique() Miklos Szeredi
2013-09-05 9:44 ` [PATCH 10/11] fuse: clean up return in fuse_dentry_revalidate() Miklos Szeredi
2013-09-05 9:44 ` [PATCH 11/11] fuse: drop dentry on failed revalidate Miklos Szeredi
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=20130905111852.GP13318@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=Trond.Myklebust@netapp.com \
--cc=dhowells@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mszeredi@suse.cz \
--cc=swhiteho@redhat.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 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).