Skip to content

Commit 366943b

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: call btrfs_close_devices from ->kill_sb
Although btrfs is not yet implementing blk_holder_ops yet, there is a requirement for a proper blk_holder_ops: - blkdev_put() must not be called under sb->s_umount The blkdev_put()/bdev_fput() must not be called under sb->s_umount to avoid lock order reversal with disk->open_mutex. This is for the proper blk_holder_ops callbacks. Currently we're fine because we call regular fput() which defers the blk holder reclaiming. To prepare for the future of blk_holder_ops, move the btrfs_close_devices() calls into btrfs_free_fs_info(). That will be called from kill_sb() callbacks, which is also called for error handing during mount failures, or there is already an existing super block. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 47b4dd4 commit 366943b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

fs/btrfs/disk-io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
12461246
{
12471247
struct percpu_counter *em_counter = &fs_info->evictable_extent_maps;
12481248

1249+
if (fs_info->fs_devices)
1250+
btrfs_close_devices(fs_info->fs_devices);
12491251
percpu_counter_destroy(&fs_info->stats_read_blocks);
12501252
percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
12511253
percpu_counter_destroy(&fs_info->delalloc_bytes);
@@ -3683,7 +3685,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
36833685

36843686
iput(fs_info->btree_inode);
36853687
fail:
3686-
btrfs_close_devices(fs_info->fs_devices);
36873688
ASSERT(ret < 0);
36883689
return ret;
36893690
}
@@ -4430,7 +4431,6 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
44304431
iput(fs_info->btree_inode);
44314432

44324433
btrfs_mapping_tree_free(fs_info);
4433-
btrfs_close_devices(fs_info->fs_devices);
44344434
}
44354435

44364436
void btrfs_mark_buffer_dirty(struct btrfs_trans_handle *trans,

fs/btrfs/super.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,18 +1870,14 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18701870
if (ret)
18711871
return ret;
18721872

1873-
if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) {
1874-
ret = -EACCES;
1875-
goto error;
1876-
}
1873+
if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0)
1874+
return -EACCES;
18771875

18781876
bdev = fs_devices->latest_dev->bdev;
18791877

18801878
sb = sget_fc(fc, btrfs_fc_test_super, set_anon_super_fc);
1881-
if (IS_ERR(sb)) {
1882-
ret = PTR_ERR(sb);
1883-
goto error;
1884-
}
1879+
if (IS_ERR(sb))
1880+
return PTR_ERR(sb);
18851881

18861882
set_device_specific_options(fs_info);
18871883

@@ -1890,17 +1886,15 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18901886
* Not the first mount of the fs thus got an existing super block.
18911887
*
18921888
* Will reuse the returned super block, fs_info and fs_devices.
1893-
*/
1894-
ASSERT(fc->s_fs_info == fs_info);
1895-
1896-
/*
1889+
*
18971890
* fc->s_fs_info is not touched and will be later freed by
18981891
* put_fs_context() through btrfs_free_fs_context().
18991892
*
1900-
* But we have opened fs_devices at the beginning of the
1901-
* function, thus still need to close them manually.
1893+
* And the fs_info->fs_devices will also be closed by
1894+
* btrfs_free_fs_context().
19021895
*/
1903-
btrfs_close_devices(fs_devices);
1896+
ASSERT(fc->s_fs_info == fs_info);
1897+
19041898
/*
19051899
* At this stage we may have RO flag mismatch between
19061900
* fc->sb_flags and sb->s_flags. Caller should detect such
@@ -1929,10 +1923,6 @@ static int btrfs_get_tree_super(struct fs_context *fc)
19291923

19301924
fc->root = dget(sb->s_root);
19311925
return 0;
1932-
1933-
error:
1934-
btrfs_close_devices(fs_devices);
1935-
return ret;
19361926
}
19371927

19381928
/*

0 commit comments

Comments
 (0)