From: Ian Kent <raven@themaw.net>
To: linux-xfs <linux-xfs@vger.kernel.org>
Cc: Brian Foster <bfoster@redhat.com>,
Eric Sandeen <sandeen@sandeen.net>,
David Howells <dhowells@redhat.com>,
Dave Chinner <dchinner@redhat.com>,
Al Viro <viro@ZenIV.linux.org.uk>
Subject: [PATCH v5 01/17] vfs: Create fs_context-aware mount_bdev() replacement
Date: Wed, 09 Oct 2019 19:30:16 +0800 [thread overview]
Message-ID: <157062061592.32346.16071223118598694422.stgit@fedora-28> (raw)
In-Reply-To: <157062043952.32346.977737248061083292.stgit@fedora-28>
From: David Howells <dhowells@redhat.com>
Create a function, get_tree_bdev(), that is fs_context-aware and a
->get_tree() counterpart of mount_bdev().
It caches the block device pointer in the fs_context struct so that this
information can be passed into sget_fc()'s test and set functions.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: linux-block@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/super.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/fs_context.h | 5 ++
2 files changed, 99 insertions(+)
diff --git a/fs/super.c b/fs/super.c
index 113c58f19425..a7f62c964e58 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1215,6 +1215,7 @@ int get_tree_single(struct fs_context *fc,
EXPORT_SYMBOL(get_tree_single);
#ifdef CONFIG_BLOCK
+
static int set_bdev_super(struct super_block *s, void *data)
{
s->s_bdev = data;
@@ -1224,6 +1225,99 @@ static int set_bdev_super(struct super_block *s, void *data)
return 0;
}
+static int set_bdev_super_fc(struct super_block *s, struct fs_context *fc)
+{
+ return set_bdev_super(s, fc->sget_key);
+}
+
+static int test_bdev_super_fc(struct super_block *s, struct fs_context *fc)
+{
+ return s->s_bdev == fc->sget_key;
+}
+
+/**
+ * get_tree_bdev - Get a superblock based on a single block device
+ * @fc: The filesystem context holding the parameters
+ * @fill_super: Helper to initialise a new superblock
+ */
+int get_tree_bdev(struct fs_context *fc,
+ int (*fill_super)(struct super_block *,
+ struct fs_context *))
+{
+ struct block_device *bdev;
+ struct super_block *s;
+ fmode_t mode = FMODE_READ | FMODE_EXCL;
+ int error = 0;
+
+ if (!(fc->sb_flags & SB_RDONLY))
+ mode |= FMODE_WRITE;
+
+ if (!fc->source)
+ return invalf(fc, "No source specified");
+
+ bdev = blkdev_get_by_path(fc->source, mode, fc->fs_type);
+ if (IS_ERR(bdev)) {
+ errorf(fc, "%s: Can't open blockdev", fc->source);
+ return PTR_ERR(bdev);
+ }
+
+ /* Once the superblock is inserted into the list by sget_fc(), s_umount
+ * will protect the lockfs code from trying to start a snapshot while
+ * we are mounting
+ */
+ mutex_lock(&bdev->bd_fsfreeze_mutex);
+ if (bdev->bd_fsfreeze_count > 0) {
+ mutex_unlock(&bdev->bd_fsfreeze_mutex);
+ warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
+ return -EBUSY;
+ }
+
+ fc->sb_flags |= SB_NOSEC;
+ fc->sget_key = bdev;
+ s = sget_fc(fc, test_bdev_super_fc, set_bdev_super_fc);
+ mutex_unlock(&bdev->bd_fsfreeze_mutex);
+ if (IS_ERR(s))
+ return PTR_ERR(s);
+
+ if (s->s_root) {
+ /* Don't summarily change the RO/RW state. */
+ if ((fc->sb_flags ^ s->s_flags) & SB_RDONLY) {
+ warnf(fc, "%pg: Can't mount, would change RO state", bdev);
+ deactivate_locked_super(s);
+ blkdev_put(bdev, mode);
+ return -EBUSY;
+ }
+
+ /*
+ * s_umount nests inside bd_mutex during
+ * __invalidate_device(). blkdev_put() acquires
+ * bd_mutex and can't be called under s_umount. Drop
+ * s_umount temporarily. This is safe as we're
+ * holding an active reference.
+ */
+ up_write(&s->s_umount);
+ blkdev_put(bdev, mode);
+ down_write(&s->s_umount);
+ } else {
+ s->s_mode = mode;
+ snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev);
+ sb_set_blocksize(s, block_size(bdev));
+ error = fill_super(s, fc);
+ if (error) {
+ deactivate_locked_super(s);
+ return error;
+ }
+
+ s->s_flags |= SB_ACTIVE;
+ bdev->bd_super = s;
+ }
+
+ BUG_ON(fc->root);
+ fc->root = dget(s->s_root);
+ return 0;
+}
+EXPORT_SYMBOL(get_tree_bdev);
+
static int test_bdev_super(struct super_block *s, void *data)
{
return (void *)s->s_bdev == data;
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index 7c6fe3d47fa6..7bf6179a83fd 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -88,6 +88,7 @@ struct fs_context {
struct mutex uapi_mutex; /* Userspace access mutex */
struct file_system_type *fs_type;
void *fs_private; /* The filesystem's context */
+ void *sget_key;
struct dentry *root; /* The root and superblock */
struct user_namespace *user_ns; /* The user namespace for this mount */
struct net *net_ns; /* The network namespace for this mount */
@@ -154,6 +155,10 @@ extern int get_tree_single(struct fs_context *fc,
int (*fill_super)(struct super_block *sb,
struct fs_context *fc));
+extern int get_tree_bdev(struct fs_context *fc,
+ int (*fill_super)(struct super_block *sb,
+ struct fs_context *fc));
+
extern const struct file_operations fscontext_fops;
/*
next prev parent reply other threads:[~2019-10-09 11:30 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 11:30 [PATCH v5 00/17] xfs: mount API patch series Ian Kent
2019-10-09 11:30 ` Ian Kent [this message]
2019-10-09 11:30 ` [PATCH v5 02/17] vfs: add missing blkdev_put() in get_tree_bdev() Ian Kent
2019-10-09 11:30 ` [PATCH v5 03/17] xfs: remove very old mount option Ian Kent
2019-10-09 11:30 ` [PATCH v5 04/17] xfs: mount-api - add fs parameter description Ian Kent
2019-10-09 14:48 ` Christoph Hellwig
2019-10-10 0:56 ` Ian Kent
2019-10-10 6:39 ` Christoph Hellwig
2019-10-10 8:31 ` Ian Kent
2019-10-09 14:53 ` Christoph Hellwig
2019-10-09 11:30 ` [PATCH v5 05/17] xfs: mount-api - refactor suffix_kstrtoint() Ian Kent
2019-10-09 14:48 ` Christoph Hellwig
2019-10-09 15:21 ` Al Viro
2019-10-09 15:29 ` Christoph Hellwig
2019-10-09 16:03 ` Al Viro
2019-10-09 18:01 ` Christoph Hellwig
2019-10-09 18:22 ` Al Viro
2019-12-06 8:27 ` Christoph Hellwig
2019-10-10 0:59 ` Ian Kent
2019-10-09 11:30 ` [PATCH v5 06/17] xfs: mount-api - refactor xfs_parseags() Ian Kent
2019-10-09 14:56 ` Christoph Hellwig
2019-10-10 1:08 ` Ian Kent
2019-10-09 11:30 ` [PATCH v5 07/17] xfs: mount-api - make xfs_parse_param() take context .parse_param() args Ian Kent
2019-10-09 11:30 ` [PATCH v5 08/17] xfs: mount-api - move xfs_parseargs() validation to a helper Ian Kent
2019-10-09 15:02 ` Christoph Hellwig
2019-10-09 19:47 ` Darrick J. Wong
2019-10-10 6:38 ` Christoph Hellwig
2019-10-10 7:57 ` Christoph Hellwig
2019-10-09 11:30 ` [PATCH v5 09/17] xfs: mount-api - refactor xfs_fs_fill_super() Ian Kent
2019-10-09 15:03 ` Christoph Hellwig
2019-10-10 1:10 ` Ian Kent
2019-10-09 11:31 ` [PATCH v5 10/17] xfs: mount-api - add xfs_get_tree() Ian Kent
2019-10-09 15:04 ` Christoph Hellwig
2019-10-10 1:11 ` Ian Kent
2019-10-09 11:31 ` [PATCH v5 11/17] xfs: mount-api - add xfs_remount_rw() helper Ian Kent
2019-10-09 11:31 ` [PATCH v5 12/17] xfs: mount-api - add xfs_remount_ro() helper Ian Kent
2019-10-09 11:31 ` [PATCH v5 13/17] xfs: mount api - add xfs_reconfigure() Ian Kent
2019-10-09 12:51 ` Brian Foster
2019-10-09 15:05 ` Christoph Hellwig
2019-10-10 1:12 ` Ian Kent
2019-10-09 11:31 ` [PATCH v5 14/17] xfs: mount-api - add xfs_fc_free() Ian Kent
2019-10-09 12:51 ` Brian Foster
2019-10-09 11:31 ` [PATCH v5 15/17] xfs: mount-api - dont set sb in xfs_mount_alloc() Ian Kent
2019-10-09 11:31 ` [PATCH v5 16/17] xfs: mount-api - switch to new mount-api Ian Kent
2019-10-09 15:10 ` Christoph Hellwig
2019-10-10 1:15 ` Ian Kent
2019-10-09 11:31 ` [PATCH v5 17/17] xfs: mount-api - remove remaining legacy mount code Ian Kent
2019-10-09 15:10 ` Christoph Hellwig
2019-10-10 1:17 ` Ian Kent
2019-10-09 14:52 ` [PATCH v5 00/17] xfs: mount API patch series Christoph Hellwig
2019-10-14 1:28 ` Ian Kent
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=157062061592.32346.16071223118598694422.stgit@fedora-28 \
--to=raven@themaw.net \
--cc=bfoster@redhat.com \
--cc=dchinner@redhat.com \
--cc=dhowells@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--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).