Skip to content

Commit 47b4dd4

Browse files
adam900710kdave
authored andcommitted
btrfs: add comments to make super block creation more clear
When calling sget_fc(), there are 3 different situations: a) Critical error No super block created. b) A new super block is created The fc->s_fs_info is transferred to the super block, and fc->s_fs_info is reset to NULL. In this case sb->s_root should still be NULL, and needs to be properly initialized later by btrfs_fill_super(). c) An existing super block is returned The fc->s_fs_info is untouched, and anything related to that fs_info should be properly cleaned up. This is not obvious even with the extra comments at sget_fc(). Enhance the situation by: - Add comments for case b) and c) Especially for case c), the fs_info and fs_devices cleanup happens at different timing, thus needs extra explanation. - Move the comments closer to case b) and case c) Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a07562a commit 47b4dd4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

fs/btrfs/super.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,15 +1877,6 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18771877

18781878
bdev = fs_devices->latest_dev->bdev;
18791879

1880-
/*
1881-
* From now on the error handling is not straightforward.
1882-
*
1883-
* If successful, this will transfer the fs_info into the super block,
1884-
* and fc->s_fs_info will be NULL. However if there's an existing
1885-
* super, we'll still have fc->s_fs_info populated. If we error
1886-
* completely out it'll be cleaned up when we drop the fs_context,
1887-
* otherwise it's tied to the lifetime of the super_block.
1888-
*/
18891880
sb = sget_fc(fc, btrfs_fc_test_super, set_anon_super_fc);
18901881
if (IS_ERR(sb)) {
18911882
ret = PTR_ERR(sb);
@@ -1895,6 +1886,20 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18951886
set_device_specific_options(fs_info);
18961887

18971888
if (sb->s_root) {
1889+
/*
1890+
* Not the first mount of the fs thus got an existing super block.
1891+
*
1892+
* Will reuse the returned super block, fs_info and fs_devices.
1893+
*/
1894+
ASSERT(fc->s_fs_info == fs_info);
1895+
1896+
/*
1897+
* fc->s_fs_info is not touched and will be later freed by
1898+
* put_fs_context() through btrfs_free_fs_context().
1899+
*
1900+
* But we have opened fs_devices at the beginning of the
1901+
* function, thus still need to close them manually.
1902+
*/
18981903
btrfs_close_devices(fs_devices);
18991904
/*
19001905
* At this stage we may have RO flag mismatch between
@@ -1903,6 +1908,13 @@ static int btrfs_get_tree_super(struct fs_context *fc)
19031908
* needed.
19041909
*/
19051910
} else {
1911+
/*
1912+
* The first mount of the fs thus a new superblock, fc->s_fs_info
1913+
* should be NULL, and the owner ship of our fs_info and fs_devices is
1914+
* transferred to the super block.
1915+
*/
1916+
ASSERT(fc->s_fs_info == NULL);
1917+
19061918
snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev);
19071919
shrinker_debugfs_rename(sb->s_shrink, "sb-btrfs:%s", sb->s_id);
19081920
btrfs_sb(sb)->bdev_holder = &btrfs_fs_type;

0 commit comments

Comments
 (0)