From aca740cecbe57b12bd9c1fc632092af5ebacda0c Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Mon, 24 Jul 2023 10:51:45 -0700 Subject: fs: open block device after superblock creation Currently get_tree_bdev and mount_bdev open the block device before committing to allocating a super block. That creates problems for restricting the number of writers to a device, and also leads to a unusual and not very helpful holder (the fs_type). Reorganize the super block code to first look whether the superblock for a particular device does already exist and open the block device only if it doesn't. [hch: port to before the bdev_handle changes, duplicate the bdev read-only check from blkdev_get_by_path, extend the fsfree_mutex coverage to protect against freezes, fix an open bdev leak when the bdev is frozen, use the bdev local variable more, rename the s variable to sb to be more descriptive] [brauner: remove references to mounts as they're mostly irrelevant] [brauner & hch: fold fixes for romfs and cramfs for syzbot+2faac0423fdc9692822b@syzkaller.appspotmail.com] Signed-off-by: Jan Kara Signed-off-by: Christoph Hellwig Message-Id: <20230724175145.201318-1-hch@lst.de> Signed-off-by: Christian Brauner --- fs/cramfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'fs/cramfs') diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 27c6597aa1be..bc99d0fb8ad4 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -485,12 +485,16 @@ static void cramfs_kill_sb(struct super_block *sb) { struct cramfs_sb_info *sbi = CRAMFS_SB(sb); + generic_shutdown_super(sb); + if (IS_ENABLED(CONFIG_CRAMFS_MTD) && sb->s_mtd) { if (sbi && sbi->mtd_point_size) mtd_unpoint(sb->s_mtd, 0, sbi->mtd_point_size); - kill_mtd_super(sb); + put_mtd_device(sb->s_mtd); + sb->s_mtd = NULL; } else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) { - kill_block_super(sb); + sync_blockdev(sb->s_bdev); + blkdev_put(sb->s_bdev, sb->s_type); } kfree(sbi); } -- cgit v1.2.3