linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Dave Chinner <david@fromorbit.com>
Cc: Jan Kara <jack@suse.cz>, Al Viro <viro@ZenIV.linux.org.uk>,
	linux-fsdevel@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	mpatocka@redhat.com, sandeen@sandeen.net
Subject: Re: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw
Date: Thu, 9 Feb 2012 00:47:03 +0100	[thread overview]
Message-ID: <20120208234703.GG1696@quack.suse.cz> (raw)
In-Reply-To: <20120208232705.GF1696@quack.suse.cz>

[-- Attachment #1: Type: text/plain, Size: 2473 bytes --]

On Thu 09-02-12 00:27:05, Jan Kara wrote:
> On Thu 09-02-12 10:20:49, Dave Chinner wrote:
> > On Tue, Feb 07, 2012 at 11:37:46PM +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.
> > > 
> > > Signed-off-by: Jan Kara <jack@suse.cz>
> > > ---
> > >  fs/super.c         |   47 +++++++++++++++++++++++++++++++++++------------
> > >  include/linux/fs.h |    1 +
> > >  2 files changed, 36 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/fs/super.c b/fs/super.c
> > > index 6015c02..e320239 100644
> > > --- a/fs/super.c
> > > +++ b/fs/super.c
> > > @@ -593,15 +593,7 @@ 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 thawed)
> > >  {
> > >  	struct super_block *sb;
> > >  
> > > @@ -618,9 +610,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 (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 +627,36 @@ rescan:
> > >  	return NULL;
> > >  }
> > 
> > The thawed parameter appears to be unused and the waiting for frozen
> > filesystems appears to happen for all callers. Is this intentional?
>   Ah, sorry. Obviously that's a bug. Thanks for spotting it. I'll fix it
> up.
  Attached is a fixed version.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

[-- Attachment #2: 0001-vfs-Provide-function-to-get-superblock-and-wait-for-.patch --]
[-- Type: text/x-patch, Size: 3554 bytes --]

>From 5dce7adb0c281612a14fa3dd8c8d5ef3f5eb3666 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Tue, 7 Feb 2012 22:59:06 +0100
Subject: [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw

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         |   47 +++++++++++++++++++++++++++++++++++------------
 include/linux/fs.h |    1 +
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index 6015c02..e15aaa9 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -593,15 +593,7 @@ 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 thawed)
 {
 	struct super_block *sb;
 
@@ -618,9 +610,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 (!thawed || 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 +627,36 @@ 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.
+ */
+
+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 given once the superblock is thawed. %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


  reply	other threads:[~2012-02-08 23:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-07 22:37 [PATCH 0/2] Fix deadlock with suspend & quotas Jan Kara
2012-02-07 22:37 ` [PATCH 1/2] vfs: Provide function to get superblock and wait for it to thaw Jan Kara
2012-02-08 23:20   ` Dave Chinner
2012-02-08 23:27     ` Jan Kara
2012-02-08 23:47       ` Jan Kara [this message]
2012-02-09 16:37         ` Eric Sandeen
2012-02-09 23:14           ` Mikulas Patocka
2012-02-10  9:48           ` Jan Kara
2012-02-10 23:16             ` Dave Chinner
2012-02-07 22:37 ` [PATCH 2/2] quota: Fix deadlock with suspend and quotas Jan Kara
2012-02-09 16:46   ` Eric Sandeen
  -- strict thread matches above, loose matches on Subject: below --
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

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=20120208234703.GG1696@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=david@fromorbit.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=sandeen@sandeen.net \
    --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).