Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/ZwUkJEtwIpUA4qMz@infradead.org

Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20241009033151.2334888-1-hsiangkao@linux.alibaba.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Gao Xiang and committed by
Christian Brauner
4021e685 42f7652d

+26 -6
+20 -6
fs/super.c
··· 1596 1596 EXPORT_SYMBOL_GPL(setup_bdev_super); 1597 1597 1598 1598 /** 1599 - * get_tree_bdev - Get a superblock based on a single block device 1599 + * get_tree_bdev_flags - Get a superblock based on a single block device 1600 1600 * @fc: The filesystem context holding the parameters 1601 1601 * @fill_super: Helper to initialise a new superblock 1602 + * @flags: GET_TREE_BDEV_* flags 1602 1603 */ 1603 - int get_tree_bdev(struct fs_context *fc, 1604 - int (*fill_super)(struct super_block *, 1605 - struct fs_context *)) 1604 + int get_tree_bdev_flags(struct fs_context *fc, 1605 + int (*fill_super)(struct super_block *sb, 1606 + struct fs_context *fc), unsigned int flags) 1606 1607 { 1607 1608 struct super_block *s; 1608 1609 int error = 0; ··· 1614 1613 1615 1614 error = lookup_bdev(fc->source, &dev); 1616 1615 if (error) { 1617 - errorf(fc, "%s: Can't lookup blockdev", fc->source); 1616 + if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP)) 1617 + errorf(fc, "%s: Can't lookup blockdev", fc->source); 1618 1618 return error; 1619 1619 } 1620 - 1621 1620 fc->sb_flags |= SB_NOSEC; 1622 1621 s = sget_dev(fc, dev); 1623 1622 if (IS_ERR(s)) ··· 1644 1643 BUG_ON(fc->root); 1645 1644 fc->root = dget(s->s_root); 1646 1645 return 0; 1646 + } 1647 + EXPORT_SYMBOL_GPL(get_tree_bdev_flags); 1648 + 1649 + /** 1650 + * get_tree_bdev - Get a superblock based on a single block device 1651 + * @fc: The filesystem context holding the parameters 1652 + * @fill_super: Helper to initialise a new superblock 1653 + */ 1654 + int get_tree_bdev(struct fs_context *fc, 1655 + int (*fill_super)(struct super_block *, 1656 + struct fs_context *)) 1657 + { 1658 + return get_tree_bdev_flags(fc, fill_super, 0); 1647 1659 } 1648 1660 EXPORT_SYMBOL(get_tree_bdev); 1649 1661
+6
include/linux/fs_context.h
··· 160 160 161 161 int setup_bdev_super(struct super_block *sb, int sb_flags, 162 162 struct fs_context *fc); 163 + 164 + #define GET_TREE_BDEV_QUIET_LOOKUP 0x0001 165 + int get_tree_bdev_flags(struct fs_context *fc, 166 + int (*fill_super)(struct super_block *sb, 167 + struct fs_context *fc), unsigned int flags); 168 + 163 169 extern int get_tree_bdev(struct fs_context *fc, 164 170 int (*fill_super)(struct super_block *sb, 165 171 struct fs_context *fc));