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>,
Luiz Capitulino <lcapitulino@redhat.com>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 4/17] fsfreeze: emergency thaw will deadlock on s_umount
Date: Wed, 9 Jan 2013 17:12:21 +0100 [thread overview]
Message-ID: <20130109161221.GB17353@quack.suse.cz> (raw)
In-Reply-To: <1357557972.8183.7.camel@nexus.lab.ntt.co.jp>
On Mon 07-01-13 20:26:12, Fernando Luis Vázquez Cao wrote:
> The emergency thaw process uses iterate_super() which holds the
> sb->s_umount lock in read mode. The current thaw_super() code takes
> the sb->s_umount lock in write mode, hence leading to an instant
> deadlock.
>
> Use the unlocked version of thaw_super() to do the thawing and replace
> iterate_supers() with iterate_supers_write() so that the unfreeze operation can
> be performed with s_umount held as the locking rules for fsfreeze indicate.
>
> As a bonus, by using thaw_super(), which does not nest, instead of thaw_bdev()
> when can get rid of the ugly while loop.
>
> Jan Kara pointed out that with this approach we will leave the block devices
> frozen, but this is a problem we have had since the introduction of the
> superblock level API: if we thaw the filesystem using the superblock level API
> (be it through the thaw ioctl or emergency thaw) the bdev level freeze
> reference counter (bd_fsfreeze_count) will not be updated and even though
> subsequent calls to thaw_bdev() will decrease it it will never get back to 0
> (if thaw_super() returns an error, and it will when the superblock is unfrozen,
> thaw_bdev() will return without decreasing the counter). The solution I propose
> (and will be implementing in the followup patch "fsfreeze: freeze_super and
> thaw_bdev don't play well together") is letting bd_fsfreeze_count
> become zero when the superblock sitting on top of it is unfrozen, so that
> future calls to freeze_bdev() actually try to freeze the superblock.
The patch looks good. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
>
> Cc: linux-fsdevel@vger.kernel.org
> 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: Luiz Capitulino <lcapitulino@redhat.com>
> Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
> ---
>
> diff -urNp linux-3.8-rc1-orig/drivers/tty/sysrq.c linux-3.8-rc1/drivers/tty/sysrq.c
> --- linux-3.8-rc1-orig/drivers/tty/sysrq.c 2012-12-25 10:27:40.614737000 +0900
> +++ linux-3.8-rc1/drivers/tty/sysrq.c 2012-12-25 11:40:06.128018000 +0900
> @@ -363,7 +363,6 @@ static struct sysrq_key_op sysrq_moom_op
> .enable_mask = SYSRQ_ENABLE_SIGNAL,
> };
>
> -#ifdef CONFIG_BLOCK
> static void sysrq_handle_thaw(int key)
> {
> emergency_thaw_all();
> @@ -374,7 +373,6 @@ static struct sysrq_key_op sysrq_thaw_op
> .action_msg = "Emergency Thaw of all frozen filesystems",
> .enable_mask = SYSRQ_ENABLE_SIGNAL,
> };
> -#endif
>
> static void sysrq_handle_kill(int key)
> {
> diff -urNp linux-3.8-rc1-orig/fs/buffer.c linux-3.8-rc1/fs/buffer.c
> --- linux-3.8-rc1-orig/fs/buffer.c 2012-12-25 11:30:38.208018000 +0900
> +++ linux-3.8-rc1/fs/buffer.c 2012-12-25 11:40:06.128018000 +0900
> @@ -512,15 +512,33 @@ repeat:
>
> static void do_thaw_one(struct super_block *sb, void *unused)
> {
> - char b[BDEVNAME_SIZE];
> - while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
> - printk(KERN_WARNING "Emergency Thaw on %s\n",
> + int res;
> +
> + if (sb->s_bdev) {
> + char b[BDEVNAME_SIZE];
> + printk(KERN_WARNING "Emergency Thaw on %s.\n",
> bdevname(sb->s_bdev, b));
> + }
> +
> + /*
> + * We got here from __iterate_supers with the superblock lock taken
> + * so we can call the lockless version of thaw_super() safely.
> + */
> + res = __thaw_super(sb);
> + if (!res) {
> + deactivate_locked_super(sb);
> + /*
> + * We have to re-acquire s_umount because
> + * iterate_supers_write() will unlock it. It still holds
> + * passive reference so sb cannot be freed under us.
> + */
> + down_write(&sb->s_umount);
> + }
> }
>
> static void do_thaw_all(struct work_struct *work)
> {
> - iterate_supers_read(do_thaw_one, NULL);
> + iterate_supers_write(do_thaw_one, NULL);
> kfree(work);
> printk(KERN_WARNING "Emergency Thaw complete\n");
> }
> diff -urNp linux-3.8-rc1-orig/include/linux/fs.h linux-3.8-rc1/include/linux/fs.h
> --- linux-3.8-rc1-orig/include/linux/fs.h 2012-12-25 11:35:55.488018000 +0900
> +++ linux-3.8-rc1/include/linux/fs.h 2012-12-25 11:40:06.132018000 +0900
> @@ -1881,6 +1881,7 @@ extern int vfs_ustat(dev_t, struct kstat
> extern int freeze_super(struct super_block *super);
> extern int __thaw_super(struct super_block *super);
> extern int thaw_super(struct super_block *super);
> +extern void emergency_thaw_all(void);
> extern bool our_mnt(struct vfsmount *mnt);
>
> extern int current_umask(void);
> @@ -2053,7 +2054,6 @@ extern void iterate_bdevs(void (*)(struc
> extern int sync_blockdev(struct block_device *bdev);
> extern void kill_bdev(struct block_device *);
> extern struct super_block *freeze_bdev(struct block_device *);
> -extern void emergency_thaw_all(void);
> extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
> extern int fsync_bdev(struct block_device *);
> #else
>
>
--
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:[~2013-01-09 16:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 11:18 [PATCH v6 0/17] fsfreeze: miscellaneous fixes and cleanups Fernando Luis Vázquez Cao
2013-01-07 11:21 ` [PATCH 1/17] vfs: add __iterate_supers() and helpers around it Fernando Luis Vázquez Cao
2013-01-07 11:22 ` [PATCH 2/17] fsfreeze: add unlocked version of thaw_super Fernando Luis Vázquez Cao
2013-01-07 11:23 ` [PATCH 3/17] fsfreeze: fix emergency thaw infinite loop Fernando Luis Vázquez Cao
2013-01-07 11:26 ` [PATCH 4/17] fsfreeze: emergency thaw will deadlock on s_umount Fernando Luis Vázquez Cao
2013-01-09 16:12 ` Jan Kara [this message]
2013-01-07 11:27 ` [PATCH 5/17] xfs: switch to using super methods for fsfreeze Fernando Luis Vázquez Cao
2013-01-07 11:29 ` [PATCH 6/17] fsfreeze: move emergency thaw code to fs/super.c Fernando Luis Vázquez Cao
2013-01-07 11:30 ` [PATCH 7/17] fsfreeze: fix nested freezing of sb-less bdevs Fernando Luis Vázquez Cao
2013-01-09 16:24 ` Jan Kara
2013-01-07 11:32 ` [PATCH 8/17] fsfreeze: allow bdev level thaws when the sb is unfrozen Fernando Luis Vázquez Cao
2013-01-09 16:26 ` Jan Kara
2013-01-07 11:34 ` [PATCH 9/17] fsfreeze: freeze_super and thaw_bdev don't play well together Fernando Luis Vázquez Cao
2013-01-07 11:35 ` [PATCH 10/17] fsfreeze: automatically thaw on umount Fernando Luis Vázquez Cao
2013-01-09 17:20 ` Jan Kara
2013-01-10 9:14 ` Fernando Luis Vazquez Cao
2013-01-07 11:36 ` [PATCH 11/17] fsfreeze: add thaw_super_force Fernando Luis Vázquez Cao
2013-01-07 11:38 ` [PATCH 12/17] fsfreeze: sb-level/bdev-level fsfreeze integration Fernando Luis Vázquez Cao
2013-01-09 16:37 ` Jan Kara
2013-01-10 9:57 ` Fernando Luis Vazquez Cao
2013-01-07 11:39 ` [PATCH 13/17] fsfreeze: unfreeze bdevs in addition to filesystems during emergency thaw Fernando Luis Vázquez Cao
2013-01-09 16:41 ` Jan Kara
2013-01-07 11:41 ` [PATCH 14/17] vfs: leverage bd_super in get_super and get_active_super Fernando Luis Vázquez Cao
2013-01-09 16:44 ` Jan Kara
2013-01-07 11:42 ` [PATCH 15/17] btrfs: store pointer to superblock in bd_super Fernando Luis Vázquez Cao
2013-01-07 11:43 ` [PATCH 16/17] fsfreeze: allow freeze counter lock nesting Fernando Luis Vázquez Cao
2013-01-07 11:44 ` [PATCH 17/17] fsfreeze: export freeze_count through mountinfo 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=20130109161221.GB17353@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=lcapitulino@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sandeen@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).