From: Eric Sandeen <sandeen@redhat.com>
To: "Fernando Luis Vázquez Cao" <fernando_b1@lab.ntt.co.jp>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Josef Bacik <jbacik@fusionio.com>,
Dave Chinner <dchinner@redhat.com>,
Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/9] vfs: add __iterate_supers() helper
Date: Thu, 13 Sep 2012 21:36:39 -0500 [thread overview]
Message-ID: <50529837.5060307@redhat.com> (raw)
In-Reply-To: <1347534020.5646.4.camel@nexus.lab.ntt.co.jp>
On 9/13/12 6:00 AM, Fernando Luis Vázquez Cao wrote:
> iterate_supers() calls a function provided by the caller with the s_umount
> semaphore taken in read mode. However, there may be cases where write mode
> is preferable, so we add a new helper, __iterate_supers(), which lets one
> specify the mode of the lock.
>
> This will be used to fix the emergency thaw (filesystem unfreeze) code, which
> iterates over the list of superblocks but needs to hold the s_umount semaphore
> in _write_ mode bebore carrying out the actual thaw operation.
I'll go ahead & comment on this even though all of this is to support the
emergency thaw misfeature which I'm liking less and less this evening.
I think this split is a little odd, usually __foo() provides some fundamental
action, and foo_*() functions call it after possibly defining or altering aspects of
that action, or preparing for that action.
So having iterate_supers() do read locks, and __iterate_supers do either read
or write, seems asymmetric, and isn't very well self-documenting.
Why not have i.e. iterate_supers_read() and iterate_supers_write(), each
of which can call __iterate_supers(blah, blah, locktype).
Anyway, it'd mean changing 5 callers but it's a little clearer and more symmetric
to me. What do you think?
The logic seems fine, just a question about the style.
Thanks,
-Eric
> Cc: Josef Bacik <jbacik@fusionio.com>
> Cc: Eric Sandeen <sandeen@redhat.com>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Dave Chinner <dchinner@redhat.com>
> Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
> ---
>
> diff -urNp linux-3.6-rc5-orig/fs/super.c linux-3.6-rc5/fs/super.c
> --- linux-3.6-rc5-orig/fs/super.c 2012-09-12 18:45:13.818046999 +0900
> +++ linux-3.6-rc5/fs/super.c 2012-09-12 19:08:58.214034467 +0900
> @@ -537,14 +537,22 @@ void drop_super(struct super_block *sb)
> EXPORT_SYMBOL(drop_super);
>
> /**
> - * iterate_supers - call function for all active superblocks
> + * __iterate_supers - call function for all active superblocks
> * @f: function to call
> * @arg: argument to pass to it
> + * @wlock: mode of superblock lock (false->read lock, true->write lock)
> *
> * Scans the superblock list and calls given function, passing it
> * locked superblock and given argument.
> + *
> + * When the caller asks for the superblock lock (s_umount semaphore) to be
> + * taken in write mode, the lock is taken but not released because the
> + * function provided by the caller may deactivate the superblock itself.
> + * It is that function's job to unlock the superblock as needed in such a
> + * case.
> */
> -void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
> +void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
> + bool wlock)
> {
> struct super_block *sb, *p = NULL;
>
> @@ -555,10 +563,19 @@ void iterate_supers(void (*f)(struct sup
> sb->s_count++;
> spin_unlock(&sb_lock);
>
> - down_read(&sb->s_umount);
> + if (wlock)
> + down_write(&sb->s_umount);
> + else
> + down_read(&sb->s_umount);
> +
> if (sb->s_root && (sb->s_flags & MS_BORN))
> f(sb, arg);
> - up_read(&sb->s_umount);
> +
> + /* When the semaphore was taken in write mode the function
> + * provided by the caller takes care of unlocking it as
> + * needed. See explanation above for details. */
> + if (!wlock)
> + up_read(&sb->s_umount);
>
> spin_lock(&sb_lock);
> if (p)
> @@ -571,6 +588,19 @@ void iterate_supers(void (*f)(struct sup
> }
>
> /**
> + * iterate_supers - call function for all active superblocks
> + * @f: function to call
> + * @arg: argument to pass to it
> + *
> + * Scans the superblock list and calls given function, passing it
> + * a superblock locked in _read_ mode and given argument.
> + */
> +void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
> +{
> + __iterate_supers(f, arg , false);
> +}
> +
> +/**
> * iterate_supers_type - call function for superblocks of given type
> * @type: fs type
> * @f: function to call
> diff -urNp linux-3.6-rc5-orig/include/linux/fs.h linux-3.6-rc5/include/linux/fs.h
> --- linux-3.6-rc5-orig/include/linux/fs.h 2012-09-12 18:45:14.002047001 +0900
> +++ linux-3.6-rc5/include/linux/fs.h 2012-09-12 18:46:39.466082276 +0900
> @@ -2684,6 +2684,8 @@ extern struct super_block *get_super(str
> extern struct super_block *get_super_thawed(struct block_device *);
> extern struct super_block *get_active_super(struct block_device *bdev);
> extern void drop_super(struct super_block *sb);
> +extern void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
> + bool wlock);
> extern void iterate_supers(void (*)(struct super_block *, void *), void *);
> extern void iterate_supers_type(struct file_system_type *,
> void (*)(struct super_block *, void *), void *);
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-09-14 2:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-13 10:57 [RFC 0/9 v3] fsfreeze: miscellaneous fixes and cleanups Fernando Luis Vázquez Cao
2012-09-13 11:00 ` [PATCH 1/9] vfs: add __iterate_supers() helper Fernando Luis Vázquez Cao
2012-09-14 2:36 ` Eric Sandeen [this message]
2012-09-14 2:40 ` Fernando Luis Vazquez Cao
2012-09-13 11:01 ` [RFC 2/9] fsfreeze: add unlocked version of thaw_super Fernando Luis Vázquez Cao
2012-09-13 18:13 ` Eric Sandeen
2012-09-13 11:03 ` [RFC 3/9] fsfreeze: Prevent emergency thaw from looping infinitely Fernando Luis Vázquez Cao
2012-09-13 16:40 ` Eric Sandeen
2012-09-13 11:04 ` [RFC 4/9] fsfreeze: emergency thaw will deadlock on s_umount Fernando Luis Vázquez Cao
2012-09-13 11:07 ` [RFC 5/9] xfs: switch to using super methods for fsfreeze Fernando Luis Vázquez Cao
2012-09-13 11:08 ` [RFC 6/9] fsfreeze: move emergency thaw code to fs/super.c Fernando Luis Vázquez Cao
2012-09-13 19:00 ` Josef Bacik
2012-09-13 21:10 ` Eric Sandeen
2012-09-14 2:11 ` Fernando Luis Vazquez Cao
2012-09-14 1:59 ` Fernando Luis Vazquez Cao
2012-09-13 11:10 ` [PATCH 7/9] fsfreeze: freeze_super and thaw_bdev don't play well together Fernando Luis Vázquez Cao
2012-09-13 11:11 ` [PATCH 8/9] fsfreeze: add vfs ioctl to check freeze state Fernando Luis Vázquez Cao
2012-09-13 11:13 ` [PATCH 9/9] fsfreeze: add block device " Fernando Luis Vázquez Cao
2012-09-14 0:57 ` [RFC 0/9 v3] fsfreeze: miscellaneous fixes and cleanups Dave Chinner
2012-09-14 2:20 ` Fernando Luis Vazquez Cao
2012-09-14 2:33 ` Eric Sandeen
2012-09-14 2:48 ` Fernando Luis Vazquez Cao
2012-09-14 6:22 ` Fernando Luis Vazquez Cao
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=50529837.5060307@redhat.com \
--to=sandeen@redhat.com \
--cc=dchinner@redhat.com \
--cc=fernando_b1@lab.ntt.co.jp \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=jbacik@fusionio.com \
--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).