From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@lst.de>
Cc: Richard Weinberger <richard@nod.at>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/2] fs: export sget_dev()
Date: Wed, 30 Aug 2023 12:02:47 +0200 [thread overview]
Message-ID: <20230830-theater-quizsendung-4ba64e87df36@brauner> (raw)
In-Reply-To: <20230830-ohnedies-umland-fb2b1a45db10@brauner>
> Yeah, good point. Done.
From fe40c7fe1a87814f92f9b1d0b9fb78ac69404c33 Mon Sep 17 00:00:00 2001
From: Christian Brauner <brauner@kernel.org>
Date: Tue, 29 Aug 2023 15:05:28 +0200
Subject: [PATCH 1/2] fs: export sget_dev()
They will be used for mtd devices as well.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/super.c | 64 ++++++++++++++++++++++++++++++++--------------
include/linux/fs.h | 1 +
2 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index ad7ac3a24d38..d27d80bf7c43 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1371,6 +1371,50 @@ int get_tree_keyed(struct fs_context *fc,
}
EXPORT_SYMBOL(get_tree_keyed);
+static int set_bdev_super(struct super_block *s, void *data)
+{
+ s->s_dev = *(dev_t *)data;
+ return 0;
+}
+
+static int super_s_dev_set(struct super_block *s, struct fs_context *fc)
+{
+ return set_bdev_super(s, fc->sget_key);
+}
+
+static int super_s_dev_test(struct super_block *s, struct fs_context *fc)
+{
+ return !(s->s_iflags & SB_I_RETIRED) &&
+ s->s_dev == *(dev_t *)fc->sget_key;
+}
+
+/**
+ * sget_dev - Find or create a superblock by device number
+ * @fc: Filesystem context.
+ * @dev: device number
+ *
+ * Find or create a superblock using the provided device number that
+ * will be stored in fc->sget_key.
+ *
+ * If an extant superblock is matched, then that will be returned with
+ * an elevated reference count that the caller must transfer or discard.
+ *
+ * If no match is made, a new superblock will be allocated and basic
+ * initialisation will be performed (s_type, s_fs_info, s_id, s_dev will
+ * be set). The superblock will be published and it will be returned in
+ * a partially constructed state with SB_BORN and SB_ACTIVE as yet
+ * unset.
+ *
+ * Return: an existing or newly created superblock on success, an error
+ * pointer on failure.
+ */
+struct super_block *sget_dev(struct fs_context *fc, dev_t dev)
+{
+ fc->sget_key = &dev;
+ return sget_fc(fc, super_s_dev_test, super_s_dev_set);
+}
+EXPORT_SYMBOL(sget_dev);
+
#ifdef CONFIG_BLOCK
/*
* Lock a super block that the callers holds a reference to.
@@ -1429,23 +1473,6 @@ const struct blk_holder_ops fs_holder_ops = {
};
EXPORT_SYMBOL_GPL(fs_holder_ops);
-static int set_bdev_super(struct super_block *s, void *data)
-{
- s->s_dev = *(dev_t *)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_iflags & SB_I_RETIRED) &&
- s->s_dev == *(dev_t *)fc->sget_key;
-}
-
int setup_bdev_super(struct super_block *sb, int sb_flags,
struct fs_context *fc)
{
@@ -1523,8 +1550,7 @@ int get_tree_bdev(struct fs_context *fc,
}
fc->sb_flags |= SB_NOSEC;
- fc->sget_key = &dev;
- s = sget_fc(fc, test_bdev_super_fc, set_bdev_super_fc);
+ s = sget_dev(fc, dev);
if (IS_ERR(s))
return PTR_ERR(s);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ca8ceccde3d6..8a8d1cd5b0a9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2274,6 +2274,7 @@ struct super_block *sget(struct file_system_type *type,
int (*test)(struct super_block *,void *),
int (*set)(struct super_block *,void *),
int flags, void *data);
+struct super_block *sget_dev(struct fs_context *fc, dev_t dev);
/* Alas, no aliases. Too much hassle with bringing module.h everywhere */
#define fops_get(fops) \
--
2.34.1
next prev parent reply other threads:[~2023-08-30 18:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 15:23 [PATCH 0/2] mtd: switch to keying by dev_t Christian Brauner
2023-08-29 15:23 ` [PATCH 1/2] fs: export sget_dev() Christian Brauner
2023-08-29 16:29 ` Christian Brauner
2023-08-29 16:55 ` Richard Weinberger
2023-08-30 6:13 ` hch
2023-08-30 7:51 ` Christian Brauner
2023-08-30 6:14 ` Christoph Hellwig
2023-08-30 8:05 ` Christian Brauner
2023-08-30 9:38 ` Jan Kara
2023-08-30 9:43 ` Christian Brauner
2023-08-30 10:02 ` Christian Brauner [this message]
2023-08-30 10:10 ` Jan Kara
2023-08-29 15:23 ` [PATCH 2/2] mtd: key superblock by device number Christian Brauner
2023-08-30 10:13 ` Jan Kara
2023-08-30 9:50 ` [PATCH 0/2] mtd: switch to keying by dev_t Christian Brauner
2023-08-30 10:15 ` Richard Weinberger
2023-08-30 11:52 ` Christoph Hellwig
2023-08-30 12:19 ` Christian Brauner
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=20230830-theater-quizsendung-4ba64e87df36@brauner \
--to=brauner@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/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).