* [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
@ 2024-10-08 9:56 Gao Xiang
2024-10-08 9:56 ` [PATCH 2/2] erofs: use get_tree_bdev_by_dev() to avoid misleading messages Gao Xiang
2024-10-08 11:49 ` [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Christoph Hellwig
0 siblings, 2 replies; 8+ messages in thread
From: Gao Xiang @ 2024-10-08 9:56 UTC (permalink / raw)
To: Christian Brauner, Alexander Viro, Jan Kara
Cc: Allison Karlitskaya, Chao Yu, LKML, linux-fsdevel, linux-erofs,
Gao Xiang
As Allison reported [1], currently get_tree_bdev() will store
"Can't lookup blockdev" error message. Although it makes sense for
pure bdev-based fses, this message may mislead users who try to use
EROFS file-backed mounts since get_tree_nodev() is used as a fallback
then.
Add get_tree_bdev_by_dev() to specify a device number explicitly
instead of the hardcoded fc->source as mentioned in [2], there are
other benefits like:
- Filesystems can have other ways to get a bdev-based sb
in addition to the current hard-coded source path;
- Pseudo-filesystems can utilize this method to generate a
filesystem from given device numbers too.
- Like get_tree_nodev(), it doesn't strictly tie to fc->source
either.
[1] https://lore.kernel.org/r/CAOYeF9VQ8jKVmpy5Zy9DNhO6xmWSKMB-DO8yvBB0XvBE7=3Ugg@mail.gmail.com
[2] https://lore.kernel.org/r/b9565874-7018-46ef-b123-b524a1dffb21@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
fs/super.c | 41 ++++++++++++++++++++++++++------------
include/linux/fs_context.h | 3 +++
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index 1db230432960..8cc8350b9ba6 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1596,26 +1596,17 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
EXPORT_SYMBOL_GPL(setup_bdev_super);
/**
- * get_tree_bdev - Get a superblock based on a single block device
+ * get_tree_bdev_by_dev - Get a bdev-based superblock with a given device number
* @fc: The filesystem context holding the parameters
* @fill_super: Helper to initialise a new superblock
+ * @dev: The device number indicating the target block device
*/
-int get_tree_bdev(struct fs_context *fc,
+int get_tree_bdev_by_dev(struct fs_context *fc,
int (*fill_super)(struct super_block *,
- struct fs_context *))
+ struct fs_context *), dev_t dev)
{
struct super_block *s;
int error = 0;
- dev_t dev;
-
- if (!fc->source)
- return invalf(fc, "No source specified");
-
- error = lookup_bdev(fc->source, &dev);
- if (error) {
- errorf(fc, "%s: Can't lookup blockdev", fc->source);
- return error;
- }
fc->sb_flags |= SB_NOSEC;
s = sget_dev(fc, dev);
@@ -1644,6 +1635,30 @@ int get_tree_bdev(struct fs_context *fc,
fc->root = dget(s->s_root);
return 0;
}
+EXPORT_SYMBOL_GPL(get_tree_bdev_by_dev);
+
+/**
+ * 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 *))
+{
+ int error;
+ dev_t dev;
+
+ if (!fc->source)
+ return invalf(fc, "No source specified");
+
+ error = lookup_bdev(fc->source, &dev);
+ if (error) {
+ errorf(fc, "%s: Can't lookup blockdev", fc->source);
+ return error;
+ }
+ return get_tree_bdev_by_dev(fc, fill_super, dev);
+}
EXPORT_SYMBOL(get_tree_bdev);
static int test_bdev_super(struct super_block *s, void *data)
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index c13e99cbbf81..54f23589ad5b 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -160,6 +160,9 @@ extern int get_tree_keyed(struct fs_context *fc,
int setup_bdev_super(struct super_block *sb, int sb_flags,
struct fs_context *fc);
+int get_tree_bdev_by_dev(struct fs_context *fc,
+ int (*fill_super)(struct super_block *sb,
+ struct fs_context *fc), dev_t dev);
extern int get_tree_bdev(struct fs_context *fc,
int (*fill_super)(struct super_block *sb,
struct fs_context *fc));
--
2.43.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] erofs: use get_tree_bdev_by_dev() to avoid misleading messages
2024-10-08 9:56 [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Gao Xiang
@ 2024-10-08 9:56 ` Gao Xiang
2024-10-08 11:49 ` [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Christoph Hellwig
1 sibling, 0 replies; 8+ messages in thread
From: Gao Xiang @ 2024-10-08 9:56 UTC (permalink / raw)
To: Christian Brauner, Alexander Viro, Jan Kara
Cc: Allison Karlitskaya, Chao Yu, LKML, linux-fsdevel, linux-erofs,
Gao Xiang
Users can pass in an arbitrary source path for the proper type of
a mount then without "Can't lookup blockdev" error message.
Reported-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
Closes: https://lore.kernel.org/r/CAOYeF9VQ8jKVmpy5Zy9DNhO6xmWSKMB-DO8yvBB0XvBE7=3Ugg@mail.gmail.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
fs/erofs/super.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 666873f745da..04a5873c1594 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -700,16 +700,19 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
static int erofs_fc_get_tree(struct fs_context *fc)
{
struct erofs_sb_info *sbi = fc->s_fs_info;
+ dev_t dev;
int ret;
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid)
return get_tree_nodev(fc, erofs_fc_fill_super);
- ret = get_tree_bdev(fc, erofs_fc_fill_super);
+ if (!fc->source)
+ return invalf(fc, "No source specified");
+ ret = lookup_bdev(fc->source, &dev);
+ if (!ret)
+ return get_tree_bdev_by_dev(fc, erofs_fc_fill_super, dev);
#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
if (ret == -ENOTBLK) {
- if (!fc->source)
- return invalf(fc, "No source specified");
sbi->fdev = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(sbi->fdev))
return PTR_ERR(sbi->fdev);
--
2.43.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 9:56 [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Gao Xiang
2024-10-08 9:56 ` [PATCH 2/2] erofs: use get_tree_bdev_by_dev() to avoid misleading messages Gao Xiang
@ 2024-10-08 11:49 ` Christoph Hellwig
2024-10-08 12:10 ` Gao Xiang
1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2024-10-08 11:49 UTC (permalink / raw)
To: Gao Xiang
Cc: Christian Brauner, Alexander Viro, Jan Kara, Allison Karlitskaya,
Chao Yu, LKML, linux-fsdevel, linux-erofs
On Tue, Oct 08, 2024 at 05:56:05PM +0800, Gao Xiang wrote:
> As Allison reported [1], currently get_tree_bdev() will store
> "Can't lookup blockdev" error message. Although it makes sense for
> pure bdev-based fses, this message may mislead users who try to use
> EROFS file-backed mounts since get_tree_nodev() is used as a fallback
> then.
>
> Add get_tree_bdev_by_dev() to specify a device number explicitly
> instead of the hardcoded fc->source as mentioned in [2], there are
> other benefits like:
> - Filesystems can have other ways to get a bdev-based sb
> in addition to the current hard-coded source path;
>
> - Pseudo-filesystems can utilize this method to generate a
> filesystem from given device numbers too.
>
> - Like get_tree_nodev(), it doesn't strictly tie to fc->source
> either.
Do you have concrete plans for any of those? If so send pointers.
Otherwise just passing a quiet flag of some form feels like a much
saner interface.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 11:49 ` [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Christoph Hellwig
@ 2024-10-08 12:10 ` Gao Xiang
2024-10-08 12:23 ` Christoph Hellwig
0 siblings, 1 reply; 8+ messages in thread
From: Gao Xiang @ 2024-10-08 12:10 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Christian Brauner, Alexander Viro, Jan Kara, Allison Karlitskaya,
Chao Yu, LKML, linux-fsdevel, linux-erofs
Hi Christoph,
On 2024/10/8 19:49, Christoph Hellwig wrote:
> On Tue, Oct 08, 2024 at 05:56:05PM +0800, Gao Xiang wrote:
>> As Allison reported [1], currently get_tree_bdev() will store
>> "Can't lookup blockdev" error message. Although it makes sense for
>> pure bdev-based fses, this message may mislead users who try to use
>> EROFS file-backed mounts since get_tree_nodev() is used as a fallback
>> then.
>>
>> Add get_tree_bdev_by_dev() to specify a device number explicitly
>> instead of the hardcoded fc->source as mentioned in [2], there are
>> other benefits like:
>> - Filesystems can have other ways to get a bdev-based sb
>> in addition to the current hard-coded source path;
>>
>> - Pseudo-filesystems can utilize this method to generate a
>> filesystem from given device numbers too.
>>
>> - Like get_tree_nodev(), it doesn't strictly tie to fc->source
>> either.
>
> Do you have concrete plans for any of those? If so send pointers.
Thanks for your comment.
I don't have any pointer for now, just listing the potential use
cases for reference.
But the error message out of get_tree_bdev() is inflexible and
IMHO it's too coupled to `fc->source`.
> Otherwise just passing a quiet flag of some form feels like a much
> saner interface.
I'm fine with this way, but that will be a treewide change, I
will send out a version with a flag later.
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 12:10 ` Gao Xiang
@ 2024-10-08 12:23 ` Christoph Hellwig
2024-10-08 12:33 ` Gao Xiang
0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2024-10-08 12:23 UTC (permalink / raw)
To: Gao Xiang
Cc: Christoph Hellwig, Christian Brauner, Alexander Viro, Jan Kara,
Allison Karlitskaya, Chao Yu, LKML, linux-fsdevel, linux-erofs
On Tue, Oct 08, 2024 at 08:10:45PM +0800, Gao Xiang wrote:
> But the error message out of get_tree_bdev() is inflexible and
> IMHO it's too coupled to `fc->source`.
>
> > Otherwise just passing a quiet flag of some form feels like a much
> > saner interface.
>
> I'm fine with this way, but that will be a treewide change, I
> will send out a version with a flag later.
I'd probably just add a get_tree_bdev_flags and pass 0 flags from
get_tree_bdev.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 12:23 ` Christoph Hellwig
@ 2024-10-08 12:33 ` Gao Xiang
2024-10-08 12:55 ` Christoph Hellwig
0 siblings, 1 reply; 8+ messages in thread
From: Gao Xiang @ 2024-10-08 12:33 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Christian Brauner, Alexander Viro, Jan Kara, Allison Karlitskaya,
Chao Yu, LKML, linux-fsdevel, linux-erofs
On 2024/10/8 20:23, Christoph Hellwig wrote:
> On Tue, Oct 08, 2024 at 08:10:45PM +0800, Gao Xiang wrote:
>> But the error message out of get_tree_bdev() is inflexible and
>> IMHO it's too coupled to `fc->source`.
>>
>>> Otherwise just passing a quiet flag of some form feels like a much
>>> saner interface.
>>
>> I'm fine with this way, but that will be a treewide change, I
>> will send out a version with a flag later.
>
> I'd probably just add a get_tree_bdev_flags and pass 0 flags from
> get_tree_bdev.
how about
int get_tree_bdev_flags(struct fs_context *fc,
int (*fill_super)(struct super_block *,
struct fs_context *), bool quiet)
for now? it can be turned into `int flags` if other needs
are shown later (and I don't need to define an enum.)
Does it look good to you? if okay, I will follow this way.
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 12:33 ` Gao Xiang
@ 2024-10-08 12:55 ` Christoph Hellwig
2024-10-08 13:12 ` Gao Xiang
0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2024-10-08 12:55 UTC (permalink / raw)
To: Gao Xiang
Cc: Christoph Hellwig, Christian Brauner, Alexander Viro, Jan Kara,
Allison Karlitskaya, Chao Yu, LKML, linux-fsdevel, linux-erofs
On Tue, Oct 08, 2024 at 08:33:27PM +0800, Gao Xiang wrote:
> how about
> int get_tree_bdev_flags(struct fs_context *fc,
> int (*fill_super)(struct super_block *,
> struct fs_context *), bool quiet)
>
> for now? it can be turned into `int flags` if other needs
> are shown later (and I don't need to define an enum.)
I'd pass an unsigned int flags with a clearly spellt out (and
extensible) flags namespae.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev()
2024-10-08 12:55 ` Christoph Hellwig
@ 2024-10-08 13:12 ` Gao Xiang
0 siblings, 0 replies; 8+ messages in thread
From: Gao Xiang @ 2024-10-08 13:12 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Christian Brauner, Alexander Viro, Jan Kara, Allison Karlitskaya,
Chao Yu, LKML, linux-fsdevel, linux-erofs
On 2024/10/8 20:55, Christoph Hellwig wrote:
> On Tue, Oct 08, 2024 at 08:33:27PM +0800, Gao Xiang wrote:
>> how about
>> int get_tree_bdev_flags(struct fs_context *fc,
>> int (*fill_super)(struct super_block *,
>> struct fs_context *), bool quiet)
>>
>> for now? it can be turned into `int flags` if other needs
>> are shown later (and I don't need to define an enum.)
>
> I'd pass an unsigned int flags with a clearly spellt out (and
> extensible) flags namespae.
okay, got it.
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-10-08 13:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08 9:56 [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Gao Xiang
2024-10-08 9:56 ` [PATCH 2/2] erofs: use get_tree_bdev_by_dev() to avoid misleading messages Gao Xiang
2024-10-08 11:49 ` [PATCH 1/2] fs/super.c: introduce get_tree_bdev_by_dev() Christoph Hellwig
2024-10-08 12:10 ` Gao Xiang
2024-10-08 12:23 ` Christoph Hellwig
2024-10-08 12:33 ` Gao Xiang
2024-10-08 12:55 ` Christoph Hellwig
2024-10-08 13:12 ` Gao Xiang
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).