From: "Fernando Luis Vázquez Cao" <fernando_b1@lab.ntt.co.jp>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: 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,
Chris Mason <chris.mason@fusionio.com>
Subject: [PATCH 14/17] vfs: leverage bd_super in get_super and get_active_super
Date: Mon, 07 Jan 2013 20:41:04 +0900 [thread overview]
Message-ID: <1357558864.8183.22.camel@nexus.lab.ntt.co.jp> (raw)
In-Reply-To: <1357557492.8183.1.camel@nexus.lab.ntt.co.jp>
Using get_active_super will not work properly if the fs (like btrfs) does not
save its s_bdev with the device it is on. Also it does not provide the entire
picture, since an filesystem can be contained on multiple disks (again like
btrfs).
Fortunately we now have a bd_super field in struct block_device were a pointer
to the superblock sitting on top of the block device can be stored.
Filesystems using the vfs helper mount_bdev (the ext filesystems, xfs, etc) and
gfs2 already do this (for the former it is a freebie), so for these there is
no need to iterate through the list of superblocks; we can get the superblock
directly from ->bd_super which is more efficient and what this patch
implements.
A multi-device filesystem (once again lile btrfs) can use that field to store
a pointer to the superblock for each block device in its storage pool. By
doing so it would get_active_super and, by extension, thaw_bdev initiated
freezes working.
Thanks go to Josef Bacik and Christoph Hellwig for initiating this effort
to fix btrfs and for suggesting the solution implemented here, respectively.
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org
Cc: Josef Bacik <jbacik@fusionio.com>
Cc: Eric Sandeen <sandeen@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Chris Mason <chris.mason@fusionio.com>
Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
---
diff -urNp linux-3.8-rc1-orig/fs/super.c linux-3.8-rc1/fs/super.c
--- linux-3.8-rc1-orig/fs/super.c 2012-12-25 16:35:43.100018000 +0900
+++ linux-3.8-rc1/fs/super.c 2012-12-25 16:36:22.312018000 +0900
@@ -632,26 +632,29 @@ struct super_block *get_super(struct blo
return NULL;
spin_lock(&sb_lock);
+ if ((sb = bdev->bd_super) != NULL)
+ goto out_found;
rescan:
list_for_each_entry(sb, &super_blocks, s_list) {
if (hlist_unhashed(&sb->s_instances))
continue;
- if (sb->s_bdev == bdev) {
- sb->s_count++;
- 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);
- /* nope, got unmounted */
- spin_lock(&sb_lock);
- __put_super(sb);
- goto rescan;
- }
+ if (sb->s_bdev == bdev)
+ goto out_found;
}
spin_unlock(&sb_lock);
return NULL;
+out_found:
+ sb->s_count++;
+ 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);
+ /* nope, got unmounted */
+ spin_lock(&sb_lock);
+ __put_super(sb);
+ goto rescan;
}
EXPORT_SYMBOL(get_super);
@@ -696,18 +699,22 @@ struct super_block *get_active_super(str
restart:
spin_lock(&sb_lock);
+ if ((sb = bdev->bd_super) != NULL)
+ goto out_grabsuper;
list_for_each_entry(sb, &super_blocks, s_list) {
if (hlist_unhashed(&sb->s_instances))
continue;
- if (sb->s_bdev == bdev) {
- if (grab_super(sb)) /* drops sb_lock */
- return sb;
- else
- goto restart;
- }
+ if (sb->s_bdev == bdev)
+ goto out_grabsuper;
}
spin_unlock(&sb_lock);
return NULL;
+
+out_grabsuper:
+ if (grab_super(sb)) /* drops sb_lock */
+ return sb;
+ else
+ goto restart;
}
struct super_block *user_get_super(dev_t dev)
next prev parent reply other threads:[~2013-01-07 11:41 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
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 ` Fernando Luis Vázquez Cao [this message]
2013-01-09 16:44 ` [PATCH 14/17] vfs: leverage bd_super in get_super and get_active_super 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=1357558864.8183.22.camel@nexus.lab.ntt.co.jp \
--to=fernando_b1@lab.ntt.co.jp \
--cc=chris.mason@fusionio.com \
--cc=dchinner@redhat.com \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--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).