From: Al Viro <viro@ZenIV.linux.org.uk>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: rwheeler@redhat.com, avati@redhat.com, bfoster@redhat.com,
dhowells@redhat.com, eparis@redhat.com, raven@themaw.net,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
mszeredi@suse.cz, Steven Whitehouse <swhiteho@redhat.com>,
Trond Myklebust <Trond.Myklebust@netapp.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 02/10] vfs: check submounts and drop atomically
Date: Wed, 4 Sep 2013 18:58:34 +0100 [thread overview]
Message-ID: <20130904175834.GI13318@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1378303556-7220-3-git-send-email-miklos@szeredi.hu>
On Wed, Sep 04, 2013 at 04:05:48PM +0200, Miklos Szeredi wrote:
> +static void check_and_drop(void *_data, struct dentry *dentry)
> +{
> + struct select_data *data = _data;
> +
> + /* We're only interested in the root of this subtree */
> + if (data->start == dentry) {
> + if (d_mountpoint(dentry))
> + data->found = -EBUSY;
> + if (!data->found)
> + __d_drop(dentry);
> + }
> +}
Wouldn't it be better to do that in caller? Granted, it's not a hot
path, but... why bother calling it for each dentry in a subtree, only
to return immediately on all calls but the last one?
> +static int __check_submounts_and_drop(struct dentry *parent,
> + struct list_head *dispose)
> +{
> + struct select_data data = {
> + .start = parent,
> + .dispose = dispose,
> + .found = 0,
> + };
> +
> + d_walk(parent, &data, check_and_collect, check_and_drop);
> +
> + return data.found;
> +}
Incidentally, I would rather expand that in the only caller...
> +/**
> + * check_submounts_and_drop - prune dcache, check for submounts and drop
> + *
> + * All done as a single atomic operation relative to has_unlinked_ancestor().
> + * Returns 0 if successfully unhashed @parent. If there were submounts then
> + * return -EBUSY.
> + *
> + * @dentry: dentry to prune and drop
> + */
> +int check_submounts_and_drop(struct dentry *dentry)
> +{
> + int ret = 0;
> +
> + /* Negative dentries can be dropped without further checks */
> + if (!dentry->d_inode) {
> + d_drop(dentry);
> + goto out;
> + }
> +
> + spin_lock(&dentry->d_lock);
> + if (d_unhashed(dentry))
> + goto out_unlock;
> + if (list_empty(&dentry->d_subdirs)) {
> + if (d_mountpoint(dentry)) {
> + ret = -EBUSY;
> + goto out_unlock;
> + }
> + __d_drop(dentry);
> + goto out_unlock;
> + }
> + spin_unlock(&dentry->d_lock);
> +
> + for (;;) {
> + LIST_HEAD(dispose);
> + ret = __check_submounts_and_drop(dentry, &dispose);
> + if (!list_empty(&dispose))
> + shrink_dentry_list(&dispose);
> +
> + if (ret <= 0)
> + break;
> +
> + cond_resched();
> + }
> +
> +out:
> + return ret;
> +
> +out_unlock:
> + spin_unlock(&dentry->d_lock);
> + goto out;
> +}
> +EXPORT_SYMBOL(check_submounts_and_drop);
next prev parent reply other threads:[~2013-09-04 17:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-04 14:05 [PATCH 00/10] [v3] safely drop directory dentry on failed revalidate Miklos Szeredi
2013-09-04 14:05 ` [PATCH 01/10] vfs: add d_walk() Miklos Szeredi
2013-09-04 18:12 ` Al Viro
2013-09-04 14:05 ` [PATCH 02/10] vfs: check submounts and drop atomically Miklos Szeredi
2013-09-04 17:58 ` Al Viro [this message]
2013-09-05 9:11 ` Miklos Szeredi
2013-09-04 14:05 ` [PATCH 03/10] vfs: check unlinked ancestors before mount Miklos Szeredi
2013-09-04 14:05 ` [PATCH 04/10] afs: use check_submounts_and_drop() Miklos Szeredi
2013-09-04 14:05 ` [PATCH 05/10] gfs2: " Miklos Szeredi
2013-09-04 14:05 ` [PATCH 06/10] nfs: " Miklos Szeredi
2013-09-04 14:05 ` [PATCH 07/10] sysfs: " Miklos Szeredi
2013-09-04 15:17 ` Greg Kroah-Hartman
2013-09-04 14:05 ` [PATCH 08/10] fuse: use d_materialise_unique() Miklos Szeredi
2013-09-05 21:29 ` J. Bruce Fields
2013-09-04 14:05 ` [PATCH 09/10] fuse: clean up return in fuse_dentry_revalidate() Miklos Szeredi
2013-09-04 14:05 ` [PATCH 10/10] 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=20130904175834.GI13318@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=Trond.Myklebust@netapp.com \
--cc=avati@redhat.com \
--cc=bfoster@redhat.com \
--cc=dhowells@redhat.com \
--cc=eparis@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=raven@themaw.net \
--cc=rwheeler@redhat.com \
--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