Skip to content

Commit 0656330

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 601f773 commit 0656330

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
@@ -1869,18 +1869,14 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18691869
if (ret)
18701870
return ret;
18711871

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

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

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

18851881
set_device_specific_options(fs_info);
18861882

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

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

19371927
/*

0 commit comments

Comments
 (0)