Skip to contentSkip to conversation

fs/super.c: introduce get_tree_bdev_flags()

PATCH Applied Gao Xiang 4 participants 12 messages Oct 9, 2024 – Oct 21, 2024

Subsystems (2)
lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v2 1/2 fs/super.c: introduce get_tree_bdev_flags()

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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[1] https://lore.kernel.org/r/CAOYeF9VQ8jKVmpy5Zy9DNhO6xmWSKMB-DO8yvBB0XvBE7=3Ugg@mail.gmail.com
[2] https://lore.kernel.org/r/[email protected]

---
v1: https://lore.kernel.org/r/[email protected]
change since v1:
- add get_tree_bdev_flags() suggested by Christoph.

 fs/super.c                 | 26 ++++++++++++++++++++------
 include/linux/fs_context.h |  6 ++++++
 2 files changed, 26 insertions(+), 6 deletions(-)
fs/super.c +20 -6
index 1db230432960..c9c7223bc2a2 100644
@@ -1596,13 +1596,14 @@ 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_flags - Get a superblock based on a single block device
  * @fc: The filesystem context holding the parameters
  * @fill_super: Helper to initialise a new superblock
+ * @flags: GET_TREE_BDEV_* flags
  */
-int get_tree_bdev(struct fs_context *fc,
-		int (*fill_super)(struct super_block *,
-				  struct fs_context *))
+int get_tree_bdev_flags(struct fs_context *fc,
+		int (*fill_super)(struct super_block *sb,
+				  struct fs_context *fc), unsigned int flags)
 {
 	struct super_block *s;
 	int error = 0;
@@ -1613,10 +1614,10 @@ int get_tree_bdev(struct fs_context *fc,
 
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
-		errorf(fc, "%s: Can't lookup blockdev", fc->source);
+		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
+			errorf(fc, "%s: Can't lookup blockdev", fc->source);
 		return error;
 	}
-
 	fc->sb_flags |= SB_NOSEC;
 	s = sget_dev(fc, dev);
 	if (IS_ERR(s))
@@ -1644,6 +1645,19 @@ int get_tree_bdev(struct fs_context *fc,
 	fc->root = dget(s->s_root);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(get_tree_bdev_flags);
+
+/**
+ * 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 *))
+{
+	return get_tree_bdev_flags(fc, fill_super, 0);
+}
 EXPORT_SYMBOL(get_tree_bdev);
 
 static int test_bdev_super(struct super_block *s, void *data)
include/linux/fs_context.h +6 -0
index c13e99cbbf81..4b4bfef6f053 100644
@@ -160,6 +160,12 @@ extern int get_tree_keyed(struct fs_context *fc,
 
 int setup_bdev_super(struct super_block *sb, int sb_flags,
 		struct fs_context *fc);
+
+#define GET_TREE_BDEV_QUIET_LOOKUP		0x0001
+int get_tree_bdev_flags(struct fs_context *fc,
+		int (*fill_super)(struct super_block *sb,
+				  struct fs_context *fc), unsigned int flags);
+
 extern int get_tree_bdev(struct fs_context *fc,
 			       int (*fill_super)(struct super_block *sb,
 						 struct fs_context *fc));
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH v2 2/2 erofs: use get_tree_bdev_flags() to avoid misleading messages

Users can pass in an arbitrary source path for the proper type of a mount then without "Can't lookup blockdev" error message.

---
changes since v1:
- use new get_tree_bdev_flags().

 fs/erofs/super.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/erofs/super.c +3 -1
index 666873f745da..b89836a8760d 100644
@@ -705,7 +705,9 @@ static int erofs_fc_get_tree(struct fs_context *fc)
 	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);
+	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
+		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
+			GET_TREE_BDEV_QUIET_LOOKUP : 0);
 #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
 	if (ret == -ENOTBLK) {
 		if (!fc->source)
Signature · 1 line
2.43.5
#2 lore raw

Re: [PATCH v2 2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages

Quoted 18 lines · 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.

---
changes since v1:
- use new get_tree_bdev_flags().

 fs/erofs/super.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/erofs/super.c +0 -0
index 666873f745da..b89836a8760d 100644

fs/erofs/super.c static int erofs_fc_get_tree(struct fs_context *fc) · line 710

Quoted 7 lines
fs/erofs/super.c +3 -1
@@ -705,7 +705,9 @@ static int erofs_fc_get_tree(struct fs_context *fc)
 	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);
+	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
+		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
+			GET_TREE_BDEV_QUIET_LOOKUP : 0);

Why not pass it unconditionally and provide your own more useful error message at the end of the function if you could not find any source?

author
#3 lore raw

Re: [PATCH v2 2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages

Hi Christoph,

Quoted 22 lines · Christoph Hellwig
Quoted 21 lines · 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.

---
changes since v1:
- use new get_tree_bdev_flags().

  fs/erofs/super.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/erofs/super.c +0 -0
index 666873f745da..b89836a8760d 100644
@@ -705,7 +705,9 @@ static int erofs_fc_get_tree(struct fs_context *fc)
  	if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid)
  		return get_tree_nodev(fc, erofs_fc_fill_super);
 
Quoted 8 lines

fs/erofs/super.c static int erofs_fc_get_tree(struct fs_context *fc) · line 710

Quoted 4 lines
fs/erofs/super.c +3 -1
-	ret = get_tree_bdev(fc, erofs_fc_fill_super);
+	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
+		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
+			GET_TREE_BDEV_QUIET_LOOKUP : 0);

Why not pass it unconditionally and provide your own more useful error message at the end of the function if you could not find any source?

My own (potential) concern is that if CONFIG_EROFS_FS_BACKED_BY_FILE is off, EROFS should just behave as other pure bdev fses since I'm not sure if some userspace program really relies on "Can't lookup blockdev" behavior.

.. Yet that is just my own potential worry anyway.

Thanks,
Gao Xiang

author
#4 lore raw

Re: [PATCH v2 2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages

Quoted 2 lines · Gao Xiang

Hi Christoph,

...

Quoted 17 lines
Quoted 16 lines

fs/erofs/super.c static int erofs_fc_get_tree(struct fs_context *fc) · line 709

Quoted 12 lines
fs/erofs/super.c +3 -1
index 666873f745da..b89836a8760d 100644
@@ -705,7 +705,9 @@ static int erofs_fc_get_tree(struct fs_context *fc)
       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);
+    ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
+        IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
+            GET_TREE_BDEV_QUIET_LOOKUP : 0);

Why not pass it unconditionally and provide your own more useful error message at the end of the function if you could not find any source?

Quoted 6 lines

My own (potential) concern is that if CONFIG_EROFS_FS_BACKED_BY_FILE is off, EROFS should just behave as other pure bdev fses since I'm not sure if some userspace program really relies on "Can't lookup blockdev" behavior.

.. Yet that is just my own potential worry anyway.

Many thanks all for the review... So I guess it sounds fine?

Hi Christian,

If they also look good to you, since it's a VFS change, if possible, could you apply these two patches through the VFS tree for this cycle? There is a redundant blank line removal in the first patch, I guess you could help adjust or I need to submit another version?

I also have another related fix in erofs tree to address a syzbot issue
https://lore.kernel.org/r/[email protected]

but it shouldn't cause any conflict with the second patch though..

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Gao Xiang

reviewer Reviewed-by on v2 1/2
#6 lore raw
In reply to Gao Xiang
Quoted 6 lines · 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.

Quoted 8 lines

Add get_tree_bdev_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[1] https://lore.kernel.org/r/CAOYeF9VQ8jKVmpy5Zy9DNhO6xmWSKMB-DO8yvBB0XvBE7=3Ugg@mail.gmail.com
[2] https://lore.kernel.org/r/[email protected]

Looks good. Feel free to add:

Honza

Quoted 85 lines

---
v1: https://lore.kernel.org/r/[email protected]
change since v1:
- add get_tree_bdev_flags() suggested by Christoph.

 fs/super.c                 | 26 ++++++++++++++++++++------
 include/linux/fs_context.h |  6 ++++++
 2 files changed, 26 insertions(+), 6 deletions(-)
fs/super.c +20 -6
index 1db230432960..c9c7223bc2a2 100644
@@ -1596,13 +1596,14 @@ 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_flags - Get a superblock based on a single block device
  * @fc: The filesystem context holding the parameters
  * @fill_super: Helper to initialise a new superblock
+ * @flags: GET_TREE_BDEV_* flags
  */
-int get_tree_bdev(struct fs_context *fc,
-		int (*fill_super)(struct super_block *,
-				  struct fs_context *))
+int get_tree_bdev_flags(struct fs_context *fc,
+		int (*fill_super)(struct super_block *sb,
+				  struct fs_context *fc), unsigned int flags)
 {
 	struct super_block *s;
 	int error = 0;
@@ -1613,10 +1614,10 @@ int get_tree_bdev(struct fs_context *fc,
 
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
-		errorf(fc, "%s: Can't lookup blockdev", fc->source);
+		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
+			errorf(fc, "%s: Can't lookup blockdev", fc->source);
 		return error;
 	}
-
 	fc->sb_flags |= SB_NOSEC;
 	s = sget_dev(fc, dev);
 	if (IS_ERR(s))
@@ -1644,6 +1645,19 @@ int get_tree_bdev(struct fs_context *fc,
 	fc->root = dget(s->s_root);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(get_tree_bdev_flags);
+
+/**
+ * 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 *))
+{
+	return get_tree_bdev_flags(fc, fill_super, 0);
+}
 EXPORT_SYMBOL(get_tree_bdev);
 
 static int test_bdev_super(struct super_block *s, void *data)
include/linux/fs_context.h +6 -0
index c13e99cbbf81..4b4bfef6f053 100644
@@ -160,6 +160,12 @@ extern int get_tree_keyed(struct fs_context *fc,
 
 int setup_bdev_super(struct super_block *sb, int sb_flags,
 		struct fs_context *fc);
+
+#define GET_TREE_BDEV_QUIET_LOOKUP		0x0001
+int get_tree_bdev_flags(struct fs_context *fc,
+		int (*fill_super)(struct super_block *sb,
+				  struct fs_context *fc), unsigned int flags);
+
 extern int get_tree_bdev(struct fs_context *fc,
 			       int (*fill_super)(struct super_block *sb,
 						 struct fs_context *fc));
Signature · 1 line
2.43.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#7 lore raw
In reply to Gao Xiang
Quoted 11 lines · 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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[...]

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/2] fs/super.c: introduce get_tree_bdev_flags()

      https://git.kernel.org/vfs/vfs/c/f54acb32dff2
[2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages
      https://git.kernel.org/vfs/vfs/c/83e6e973d9c9
author
#8 lore raw

Hi Christian,

Quoted 25 lines · Christian Brauner
Quoted 11 lines · 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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[...]

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

Quoted 7 lines
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/2] fs/super.c: introduce get_tree_bdev_flags()

       https://git.kernel.org/vfs/vfs/c/f54acb32dff2
[2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages
       https://git.kernel.org/vfs/vfs/c/83e6e973d9c9

Anyway, I'm not sure what's your thoughts about this, so I try to write an email again.

As Allison suggested in the email [1], "..so probably it should get fixed before the final release.". Although I'm pretty fine to leave it in "vfs.misc" for the next merge window (6.13) instead, it could cause an unnecessary backport to the stable kernel.

Or if there is some other potential concern about these two patches? Also I hope my previous reply about a redundant blank line removal in the first patch might be useful too [2].

[1] https://lore.kernel.org/r/CAOYeF9VQ8jKVmpy5Zy9DNhO6xmWSKMB-DO8yvBB0XvBE7=3Ugg@mail.gmail.com
[2] https://lore.kernel.org/r/[email protected]

Thanks,
Gao Xiang

#9 lore raw
Quoted 36 lines · Gao Xiang

Hi Christian,

Quoted 25 lines · Christian Brauner
Quoted 11 lines · 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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[...]

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

Quoted 7 lines
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/2] fs/super.c: introduce get_tree_bdev_flags()

       https://git.kernel.org/vfs/vfs/c/f54acb32dff2
[2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages
       https://git.kernel.org/vfs/vfs/c/83e6e973d9c9
Quoted 7 lines

Anyway, I'm not sure what's your thoughts about this, so I try to write an email again.

As Allison suggested in the email [1], "..so probably it should get fixed before the final release.". Although I'm pretty fine to leave it in "vfs.misc" for the next merge window (6.13) instead, it could cause an unnecessary backport to the stable kernel.

Oh, the file changes have been merged during the v6.12 merge window? Sorry, that wasn't clear.

Well, this is a bit annoying but yes, we can get that fixed upstream then. I'll move it to vfs.fixes...

author
#10 lore raw
Quoted 45 lines · Christian Brauner
Quoted 36 lines · Gao Xiang

Hi Christian,

Quoted 25 lines · Christian Brauner
Quoted 11 lines · 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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[...]

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

Quoted 7 lines
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/2] fs/super.c: introduce get_tree_bdev_flags()

        https://git.kernel.org/vfs/vfs/c/f54acb32dff2
[2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages
        https://git.kernel.org/vfs/vfs/c/83e6e973d9c9
Quoted 7 lines

Anyway, I'm not sure what's your thoughts about this, so I try to write an email again.

As Allison suggested in the email [1], "..so probably it should get fixed before the final release.". Although I'm pretty fine to leave it in "vfs.misc" for the next merge window (6.13) instead, it could cause an unnecessary backport to the stable kernel.

Quoted 5 lines

Oh, the file changes have been merged during the v6.12 merge window? Sorry, that wasn't clear.

Well, this is a bit annoying but yes, we can get that fixed upstream then. I'll move it to vfs.fixes...

Many thanks for the reply!

Yeah, the feature is already usable [1] and it will be used for several use cases, yet the unexpected message might be confusing. Anyway, both options are fine to me, but "vfs.fixes" may be better to avoid unnecesary backporting.

[1] https://lwn.net/Articles/990750

Thanks,
Gao Xiang

maintainer Applied
#11 lore raw
In reply to Gao Xiang
Quoted 11 lines · 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_flags() to specify extensible flags [2] and GET_TREE_BDEV_QUIET_LOOKUP to silence "Can't lookup blockdev" message since it's misleading to EROFS file-backed mounts now.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/2] fs/super.c: introduce get_tree_bdev_flags()

      https://git.kernel.org/vfs/vfs/c/4021e685139d
[2/2] erofs: use get_tree_bdev_flags() to avoid misleading messages
      https://git.kernel.org/vfs/vfs/c/14c2d97265ea