From: Jan Kara <jack@suse.cz>
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>,
Eric Sandeen <sandeen@redhat.com>,
Dave Chinner <dchinner@redhat.com>,
Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org,
Konishi Ryusuke <konishi.ryusuke@lab.ntt.co.jp>,
Steven Whitehouse <swhiteho@redhat.com>
Subject: Re: [PATCH 7/9] fsfreeze: freeze_super and thaw_bdev don't play well together
Date: Mon, 8 Oct 2012 16:17:03 +0200 [thread overview]
Message-ID: <20121008141703.GD9243@quack.suse.cz> (raw)
In-Reply-To: <1349415760.7347.14.camel@nexus.lab.ntt.co.jp>
On Fri 05-10-12 14:42:40, Fernando Luis Vázquez Cao wrote:
> thaw_bdev() has re-entrancy guards to allow freezes to nest
> together. That is, it ensures that the filesystem is not thawed
> until the last thaw command is issued. This is needed to prevent the
> filesystem from being unfrozen while an existing freezer is still
> operating on the filesystem in a frozen state (e.g. dm-snapshot).
>
> Currently, freeze_super() and thaw_super() bypasses these guards,
> and as a result manual freezing and unfreezing via the ioctl methods
> do not nest correctly. hence mixing userspace directed freezes with
> block device level freezes result in inconsistency due to premature
> thawing of the filesystem.
>
> Move the re-enterency guards to the superblock and into freeze_super
> and thaw_super() so that userspace directed freezes nest correctly
> again. Caveat: Things work as expected as long as direct calls to
> thaw_super are always in response to a previous sb level freeze. In
> other words an unpaired call to thaw_super can still thaw a
> filesystem frozen using freeze_bdev (this issue could be addressed
> in a follow-up patch if deemed necessary).
>
> This patch retains the bdev level mutex and counter to keep the
> "feature" that we can freeze a block device that does not have a
> filesystem mounted yet.
>
> IMPORTANT CAVEAT: This patch restores the nesting feature of the fsfreeze ioctl
> which got removed by commit 18e9e5104fcd9a973ffe3eed3816c87f2a1b6cd2
> ("Introduce freeze_super and thaw_super for the fsfreeze ioctl"). It could be
> argued that it is too late to fix the userland ABI breakage caused by that
> patch and that the current ABI is the one that should be kept. If this is the
> respective maintainer(s) opinion this could be modified to not allow fsfreeze
> ioctl nesting.
>
> 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>
> Cc: Konishi Ryusuke <konishi.ryusuke@lab.ntt.co.jp>
> Cc: Steven Whitehouse <swhiteho@redhat.com>
> Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
Just some style nits below. So after fixing them you can add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
>
> diff -urNp linux-3.6-orig/fs/block_dev.c linux-3.6/fs/block_dev.c
> --- linux-3.6-orig/fs/block_dev.c 2012-10-04 15:05:42.168084928 +0900
> +++ linux-3.6/fs/block_dev.c 2012-10-04 15:08:40.228086607 +0900
...
> int thaw_bdev(struct block_device *bdev, struct super_block *sb)
> {
> int error = -EINVAL;
>
> mutex_lock(&bdev->bd_fsfreeze_mutex);
> +
> if (!bdev->bd_fsfreeze_count)
> goto out;
>
> - if (--bdev->bd_fsfreeze_count > 0 || !sb) {
> + bdev->bd_fsfreeze_count--;
> +
> + if (!sb) {
> error = 0;
> goto out;
> }
>
> error = thaw_super(sb);
> - if (error)
> + /* If the superblock is already unfrozen, i.e. thaw_super() returned
> + * -EINVAL, we consider the block device level thaw successful. This
> + * behavior is important in a scenario where a filesystem frozen using
> + * freeze_bdev() is thawed through the superblock level API; if we
> + * caused the subsequent thaw_bdev() to fail bdev->bd_fsfreeze_count
> + * would not go back to 0 which means that future calls to freeze_bdev()
> + * would not freeze the superblock, just increase the counter. */
^^ The correct formatting of long comments is:
/*
* Text
* Text
*/
> + if (error && error != -EINVAL)
> bdev->bd_fsfreeze_count++;
> + else
> + error = 0;
> out:
> mutex_unlock(&bdev->bd_fsfreeze_mutex);
> return error;
...
> diff -urNp linux-3.6-orig/fs/super.c linux-3.6/fs/super.c
> --- linux-3.6-orig/fs/super.c 2012-10-04 15:06:00.264085275 +0900
> +++ linux-3.6/fs/super.c 2012-10-04 15:09:21.164086840 +0900
...
> @@ -1356,29 +1363,29 @@ static void sb_wait_write(struct super_b
> * freezing. Then we transition to SB_FREEZE_COMPLETE state. This state is
> * mostly auxiliary for filesystems to verify they do not modify frozen fs.
> *
> - * sb->s_writers.frozen is protected by sb->s_umount.
> + * sb->s_writers.frozen and sb->s_freeze_count are protected by sb->s_umount.
> */
> int freeze_super(struct super_block *sb)
> {
> - int ret;
> + int ret = 0;
>
> atomic_inc(&sb->s_active);
> down_write(&sb->s_umount);
> - if (sb->s_writers.frozen != SB_UNFROZEN) {
> - deactivate_locked_super(sb);
> - return -EBUSY;
> - }
>
> - if (!(sb->s_flags & MS_BORN)) {
> - up_write(&sb->s_umount);
> - return 0; /* sic - it's "nothing to do" */
> - }
> + if (++sb->s_freeze_count > 1)
> + goto out_deactivate;
> +
> + /* If MS_BORN is not set it means we have a failing mount (this is
> + * possible if we got here from freeze_bdev()). Keep an active
> + * reference so that the superblock is not killed until it is thawed
> + * via thaw_bdev(). */
Again, comment formatting is wrong.
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
--
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-10-08 14:17 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-05 5:24 [PATCH 0/9 v5] fsfreeze: miscellaneous fixes and cleanups Fernando Luis Vázquez Cao
2012-10-05 5:31 ` [PATCH 1/9] vfs: add __iterate_supers() and helpers around it Fernando Luis Vázquez Cao
2012-10-08 13:48 ` Jan Kara
2012-10-05 5:33 ` [PATCH 2/9] fsfreeze: add unlocked version of thaw_super Fernando Luis Vázquez Cao
2012-10-05 5:34 ` [PATCH 3/9] fsfreeze: Prevent emergency thaw from looping infinitely Fernando Luis Vázquez Cao
2012-10-05 5:35 ` [PATCH 4/9] fsfreeze: emergency thaw will deadlock on s_umount Fernando Luis Vázquez Cao
2012-10-08 13:57 ` Jan Kara
2012-10-09 5:07 ` Fernando Luis Vazquez Cao
2012-10-09 8:20 ` Jan Kara
2012-10-09 9:52 ` Fernando Luis Vazquez Cao
2012-10-05 5:38 ` [PATCH 5/9] xfs: switch to using super methods for fsfreeze Fernando Luis Vázquez Cao
2012-10-05 5:39 ` [PATCH 6/9] fsfreeze: move emergency thaw code to fs/super.c Fernando Luis Vázquez Cao
2012-10-05 5:42 ` [PATCH 7/9] fsfreeze: freeze_super and thaw_bdev don't play well together Fernando Luis Vázquez Cao
2012-10-08 14:17 ` Jan Kara [this message]
2012-10-05 5:43 ` [PATCH 8/9] fsfreeze: add vfs ioctl to check freeze state Fernando Luis Vázquez Cao
2012-10-08 15:05 ` Jan Kara
2012-10-09 9:46 ` Fernando Luis Vazquez Cao
2012-10-09 14:55 ` Jan Kara
2012-10-10 2:17 ` Fernando Luis Vazquez Cao
2012-10-11 16:26 ` Jan Kara
2012-10-05 5:44 ` [PATCH 9/9] fsfreeze: add block device " Fernando Luis Vázquez Cao
-- strict thread matches above, loose matches on Subject: below --
2012-09-14 6:43 [RFC, PATCH 0/9 v4] fsfreeze: miscellaneous fixes and cleanups Fernando Luis Vázquez Cao
2012-09-14 6:53 ` [PATCH 7/9] fsfreeze: freeze_super and thaw_bdev don't play well together Fernando Luis Vázquez Cao
2012-09-14 19:20 ` Eric Sandeen
2012-09-15 1:15 ` Eric Sandeen
2012-09-25 9:48 ` Jan Kara
2012-09-25 10:51 ` Fernando Luis Vazquez Cao
2012-09-25 16:39 ` Jan Kara
2012-09-26 8:22 ` Fernando Luis Vazquez Cao
2012-09-26 9:09 ` Jan Kara
2012-10-03 7:58 ` Fernando Luis Vazquez Cao
2012-10-04 8:18 ` Jan Kara
2012-10-05 4:22 ` Fernando Luis Vázquez Cao
2012-10-05 4:30 ` Fernando Luis Vázquez Cao
2012-09-13 10:57 [RFC 0/9 v3] fsfreeze: miscellaneous fixes and cleanups Fernando Luis Vázquez 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
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=20121008141703.GD9243@quack.suse.cz \
--to=jack@suse.cz \
--cc=dchinner@redhat.com \
--cc=fernando_b1@lab.ntt.co.jp \
--cc=hch@infradead.org \
--cc=jbacik@fusionio.com \
--cc=konishi.ryusuke@lab.ntt.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=swhiteho@redhat.com \
--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).