* [PATCH 0/2 v2] Fix deadlock with suspend & quotas
@ 2012-02-10 10:02 Jan Kara
2012-02-10 10:03 ` [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw Jan Kara
2012-02-10 10:03 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
0 siblings, 2 replies; 7+ messages in thread
From: Jan Kara @ 2012-02-10 10:02 UTC (permalink / raw)
To: Al Viro; +Cc: LKML, linux-fsdevel, Dave Chinner, mpatocka, Eric Sandeen
Hello Al,
This is my attempt to fix deadlock in quota code when filesystem is
suspended and someone tries to modify quota e.g. via Q_SETQUOTA command. I
added a VFS function to get a superblock reference and return only after
the filesystem is thawed.
Changes since v1:
* wait for frozen fs really only when requested
* updated some comments & names
Honza
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw
2012-02-10 10:02 [PATCH 0/2 v2] Fix deadlock with suspend & quotas Jan Kara
@ 2012-02-10 10:03 ` Jan Kara
2012-02-12 21:13 ` Al Viro
2012-02-10 10:03 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
1 sibling, 1 reply; 7+ messages in thread
From: Jan Kara @ 2012-02-10 10:03 UTC (permalink / raw)
To: Al Viro
Cc: LKML, linux-fsdevel, Dave Chinner, mpatocka, Eric Sandeen, Jan Kara
In quota code we need to find a superblock corresponding to a device and wait
for superblock to be unfrozen. However this waiting has to happen without
s_umount semaphore because that is required for superblock to thaw. So provide
a function in VFS for this to keep dances with s_umount where they belong.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/super.c | 50 ++++++++++++++++++++++++++++++++++++++------------
include/linux/fs.h | 1 +
2 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index 6015c02..1f657d6 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -593,15 +593,8 @@ void iterate_supers_type(struct file_system_type *type,
EXPORT_SYMBOL(iterate_supers_type);
-/**
- * get_super - get the superblock of a device
- * @bdev: device to get the superblock for
- *
- * Scans the superblock list and finds the superblock of the file system
- * mounted on the device given. %NULL is returned if no match is found.
- */
-
-struct super_block *get_super(struct block_device *bdev)
+static struct super_block *__get_super(struct block_device *bdev,
+ bool wait_thaw)
{
struct super_block *sb;
@@ -618,9 +611,13 @@ rescan:
spin_unlock(&sb_lock);
down_read(&sb->s_umount);
/* still alive? */
- if (sb->s_root && (sb->s_flags & MS_BORN))
- return sb;
- up_read(&sb->s_umount);
+ if (sb->s_root && (sb->s_flags & MS_BORN)) {
+ if (!wait_thaw || sb->s_frozen == SB_UNFROZEN)
+ return sb;
+ up_read(&sb->s_umount);
+ vfs_check_frozen(sb, SB_FREEZE_WRITE);
+ } else
+ up_read(&sb->s_umount);
/* nope, got unmounted */
spin_lock(&sb_lock);
__put_super(sb);
@@ -631,9 +628,38 @@ rescan:
return NULL;
}
+/**
+ * get_super - get the superblock of a device
+ * @bdev: device to get the superblock for
+ *
+ * Scans the superblock list and finds the superblock of the file system
+ * mounted on the device given. %NULL is returned if no match is found.
+ * Note that the returned superblock may be frozen.
+ */
+
+struct super_block *get_super(struct block_device *bdev)
+{
+ return __get_super(bdev, false);
+}
EXPORT_SYMBOL(get_super);
/**
+ * get_super_thawed - get thawed superblock of a device
+ * @bdev: device to get the superblock for
+ *
+ * Scans the superblock list and finds the superblock of the file system
+ * mounted on the device. The superblock is returned once it is thawed
+ * (or immediately if it was not frozen). %NULL is returned if no match
+ * is found.
+ */
+
+struct super_block *get_super_thawed(struct block_device *bdev)
+{
+ return __get_super(bdev, true);
+}
+EXPORT_SYMBOL(get_super_thawed);
+
+/**
* get_active_super - get an active reference to the superblock of a device
* @bdev: device to get the superblock for
*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 386da09..69cd5bb 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2496,6 +2496,7 @@ extern void get_filesystem(struct file_system_type *fs);
extern void put_filesystem(struct file_system_type *fs);
extern struct file_system_type *get_fs_type(const char *name);
extern struct super_block *get_super(struct block_device *);
+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 (*)(struct super_block *, void *), void *);
--
1.7.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] quota: Fix deadlock with suspend and quotas
2012-02-10 10:02 [PATCH 0/2 v2] Fix deadlock with suspend & quotas Jan Kara
2012-02-10 10:03 ` [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw Jan Kara
@ 2012-02-10 10:03 ` Jan Kara
1 sibling, 0 replies; 7+ messages in thread
From: Jan Kara @ 2012-02-10 10:03 UTC (permalink / raw)
To: Al Viro
Cc: LKML, linux-fsdevel, Dave Chinner, mpatocka, Eric Sandeen, Jan Kara
This script causes a kernel deadlock:
set -e
DEVICE=/dev/vg1/linear
lvchange -ay $DEVICE
mkfs.ext3 $DEVICE
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
quotacheck -gu /mnt/test
umount /mnt/test
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
quotaon /mnt/test
dmsetup suspend $DEVICE
setquota -u root 1 2 3 4 /mnt/test &
sleep 1
dmsetup resume $DEVICE
setquota acquired semaphore s_umount for read and then tried to perform a
transaction (and waits because the device is suspended). dmsetup resume tries
to acquire s_umount for write before resuming the device (and waits for
setquota).
Fix the deadlock by grabbing a thawed superblock for quota commands which need
it.
Reported-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/quota/quota.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 7898cd6..fc2c438 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -292,11 +292,26 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
}
}
+/* Return 1 if 'cmd' will block on frozen filesystem */
+static int quotactl_cmd_write(int cmd)
+{
+ switch (cmd) {
+ case Q_GETFMT:
+ case Q_GETINFO:
+ case Q_SYNC:
+ case Q_XGETQSTAT:
+ case Q_XGETQUOTA:
+ case Q_XQUOTASYNC:
+ return 0;
+ }
+ return 1;
+}
+
/*
* look up a superblock on which quota ops will be performed
* - use the name of a block device to find the superblock thereon
*/
-static struct super_block *quotactl_block(const char __user *special)
+static struct super_block *quotactl_block(const char __user *special, int cmd)
{
#ifdef CONFIG_BLOCK
struct block_device *bdev;
@@ -309,7 +324,10 @@ static struct super_block *quotactl_block(const char __user *special)
putname(tmp);
if (IS_ERR(bdev))
return ERR_CAST(bdev);
- sb = get_super(bdev);
+ if (quotactl_cmd_write(cmd))
+ sb = get_super_thawed(bdev);
+ else
+ sb = get_super(bdev);
bdput(bdev);
if (!sb)
return ERR_PTR(-ENODEV);
@@ -361,7 +379,7 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
pathp = &path;
}
- sb = quotactl_block(special);
+ sb = quotactl_block(special, cmds);
if (IS_ERR(sb)) {
ret = PTR_ERR(sb);
goto out;
--
1.7.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw
2012-02-10 10:03 ` [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw Jan Kara
@ 2012-02-12 21:13 ` Al Viro
2012-02-13 14:24 ` Jan Kara
0 siblings, 1 reply; 7+ messages in thread
From: Al Viro @ 2012-02-12 21:13 UTC (permalink / raw)
To: Jan Kara; +Cc: LKML, linux-fsdevel, Dave Chinner, mpatocka, Eric Sandeen
On Fri, Feb 10, 2012 at 11:03:00AM +0100, Jan Kara wrote:
> In quota code we need to find a superblock corresponding to a device and wait
> for superblock to be unfrozen. However this waiting has to happen without
> s_umount semaphore because that is required for superblock to thaw. So provide
> a function in VFS for this to keep dances with s_umount where they belong.
Eww... All it takes is
struct super_block *get_super_thawed(struct block_device *bdev)
{
while (1) {
struct super_block *s = get_super(bdev);
if (!s || s->s_frozen == SB_UNFROZEN)
return s;
up_read(&s->s_umount);
vfs_check_frozen(s, SB_FREEZE_WRITE);
put_super(s);
}
}
and there's no need of extra arguments, etc. whatsoever. Both patches
applied, with implementation of get_super_thawed() done as above.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw
2012-02-12 21:13 ` Al Viro
@ 2012-02-13 14:24 ` Jan Kara
0 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2012-02-13 14:24 UTC (permalink / raw)
To: Al Viro
Cc: Jan Kara, LKML, linux-fsdevel, Dave Chinner, mpatocka, Eric Sandeen
On Sun 12-02-12 21:13:25, Al Viro wrote:
> On Fri, Feb 10, 2012 at 11:03:00AM +0100, Jan Kara wrote:
> > In quota code we need to find a superblock corresponding to a device and wait
> > for superblock to be unfrozen. However this waiting has to happen without
> > s_umount semaphore because that is required for superblock to thaw. So provide
> > a function in VFS for this to keep dances with s_umount where they belong.
>
> Eww... All it takes is
> struct super_block *get_super_thawed(struct block_device *bdev)
> {
> while (1) {
> struct super_block *s = get_super(bdev);
> if (!s || s->s_frozen == SB_UNFROZEN)
> return s;
> up_read(&s->s_umount);
> vfs_check_frozen(s, SB_FREEZE_WRITE);
> put_super(s);
> }
> }
> and there's no need of extra arguments, etc. whatsoever. Both patches
> applied, with implementation of get_super_thawed() done as above.
Yeah, this looks better. Thanks!
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] quota: Fix deadlock with suspend and quotas
2012-02-07 22:37 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
@ 2012-02-09 16:46 ` Eric Sandeen
0 siblings, 0 replies; 7+ messages in thread
From: Eric Sandeen @ 2012-02-09 16:46 UTC (permalink / raw)
To: Jan Kara; +Cc: Al Viro, linux-fsdevel, LKML, mpatocka
On 2/7/12 4:37 PM, Jan Kara wrote:
> This script causes a kernel deadlock:
> set -e
> DEVICE=/dev/vg1/linear
> lvchange -ay $DEVICE
> mkfs.ext3 $DEVICE
> mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
> quotacheck -gu /mnt/test
> umount /mnt/test
> mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
> quotaon /mnt/test
> dmsetup suspend $DEVICE
> setquota -u root 1 2 3 4 /mnt/test &
> sleep 1
> dmsetup resume $DEVICE
>
> setquota acquired semaphore s_umount for read and then tried to perform a
> transaction (and waits because the device is suspended). dmsetup resume tries
> to acquire s_umount for write before resuming the device (and waits for
> setquota).
>
> Fix the deadlock by grabbing a thawed superblock for quota commands which need
> it.
>
> Reported-by: Mikulas Patocka <mpatocka@redhat.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
Makes sense to me, thanks.
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> fs/quota/quota.c | 24 +++++++++++++++++++++---
> 1 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/fs/quota/quota.c b/fs/quota/quota.c
> index 7898cd6..fc2c438 100644
> --- a/fs/quota/quota.c
> +++ b/fs/quota/quota.c
> @@ -292,11 +292,26 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
> }
> }
>
> +/* Return 1 if 'cmd' will block on frozen filesystem */
> +static int quotactl_cmd_write(int cmd)
> +{
> + switch (cmd) {
> + case Q_GETFMT:
> + case Q_GETINFO:
> + case Q_SYNC:
> + case Q_XGETQSTAT:
> + case Q_XGETQUOTA:
> + case Q_XQUOTASYNC:
> + return 0;
> + }
> + return 1;
> +}
> +
> /*
> * look up a superblock on which quota ops will be performed
> * - use the name of a block device to find the superblock thereon
> */
> -static struct super_block *quotactl_block(const char __user *special)
> +static struct super_block *quotactl_block(const char __user *special, int cmd)
> {
> #ifdef CONFIG_BLOCK
> struct block_device *bdev;
> @@ -309,7 +324,10 @@ static struct super_block *quotactl_block(const char __user *special)
> putname(tmp);
> if (IS_ERR(bdev))
> return ERR_CAST(bdev);
> - sb = get_super(bdev);
> + if (quotactl_cmd_write(cmd))
> + sb = get_super_thawed(bdev);
> + else
> + sb = get_super(bdev);
> bdput(bdev);
> if (!sb)
> return ERR_PTR(-ENODEV);
> @@ -361,7 +379,7 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
> pathp = &path;
> }
>
> - sb = quotactl_block(special);
> + sb = quotactl_block(special, cmds);
> if (IS_ERR(sb)) {
> ret = PTR_ERR(sb);
> goto out;
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] quota: Fix deadlock with suspend and quotas
2012-02-07 22:37 [PATCH 0/2] Fix deadlock with suspend & quotas Jan Kara
@ 2012-02-07 22:37 ` Jan Kara
2012-02-09 16:46 ` Eric Sandeen
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kara @ 2012-02-07 22:37 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, LKML, mpatocka, sandeen, Jan Kara
This script causes a kernel deadlock:
set -e
DEVICE=/dev/vg1/linear
lvchange -ay $DEVICE
mkfs.ext3 $DEVICE
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
quotacheck -gu /mnt/test
umount /mnt/test
mount -t ext3 -o usrquota,grpquota $DEVICE /mnt/test
quotaon /mnt/test
dmsetup suspend $DEVICE
setquota -u root 1 2 3 4 /mnt/test &
sleep 1
dmsetup resume $DEVICE
setquota acquired semaphore s_umount for read and then tried to perform a
transaction (and waits because the device is suspended). dmsetup resume tries
to acquire s_umount for write before resuming the device (and waits for
setquota).
Fix the deadlock by grabbing a thawed superblock for quota commands which need
it.
Reported-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/quota/quota.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 7898cd6..fc2c438 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -292,11 +292,26 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
}
}
+/* Return 1 if 'cmd' will block on frozen filesystem */
+static int quotactl_cmd_write(int cmd)
+{
+ switch (cmd) {
+ case Q_GETFMT:
+ case Q_GETINFO:
+ case Q_SYNC:
+ case Q_XGETQSTAT:
+ case Q_XGETQUOTA:
+ case Q_XQUOTASYNC:
+ return 0;
+ }
+ return 1;
+}
+
/*
* look up a superblock on which quota ops will be performed
* - use the name of a block device to find the superblock thereon
*/
-static struct super_block *quotactl_block(const char __user *special)
+static struct super_block *quotactl_block(const char __user *special, int cmd)
{
#ifdef CONFIG_BLOCK
struct block_device *bdev;
@@ -309,7 +324,10 @@ static struct super_block *quotactl_block(const char __user *special)
putname(tmp);
if (IS_ERR(bdev))
return ERR_CAST(bdev);
- sb = get_super(bdev);
+ if (quotactl_cmd_write(cmd))
+ sb = get_super_thawed(bdev);
+ else
+ sb = get_super(bdev);
bdput(bdev);
if (!sb)
return ERR_PTR(-ENODEV);
@@ -361,7 +379,7 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
pathp = &path;
}
- sb = quotactl_block(special);
+ sb = quotactl_block(special, cmds);
if (IS_ERR(sb)) {
ret = PTR_ERR(sb);
goto out;
--
1.7.1
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-02-13 14:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10 10:02 [PATCH 0/2 v2] Fix deadlock with suspend & quotas Jan Kara
2012-02-10 10:03 ` [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw Jan Kara
2012-02-12 21:13 ` Al Viro
2012-02-13 14:24 ` Jan Kara
2012-02-10 10:03 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2012-02-07 22:37 [PATCH 0/2] Fix deadlock with suspend & quotas Jan Kara
2012-02-07 22:37 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
2012-02-09 16:46 ` Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®