Skip to content

Commit f6d92b9

Browse files
adam900710kdave
authored andcommitted
btrfs: get rid of the re-entry of btrfs_get_tree()
[EXISTING PROBLEM] Currently btrfs mount is split into two parts: - btrfs_get_tree_subvol() Which setups the very basic fs_info, and eventually call mount_subvol() to mount the target subvolume. - btrfs_get_tree_super() This is the part doing super block allocation and if there is no existing super block, do the real open_ctree() to open the fs. However currently we're doing this in a complex re-entry fashion: vfs_get_tree() |- btrfs_get_tree() |- btrfs_get_tree_subvol() |- vfs_get_tree() | |- btrfs_get_tree() | |- btrfs_get_tree_super() |- mount_subvol() This is definitely not that easy to grasp. [ENHANCEMENT] The function vfs_get_tree() is only doing the following works: - Call get_tree() call back - Call super_wake() - Call security_sb_set_mnt_opts() In our case, super_wake() can be skipped, as after btrfs_get_tree_subvol() finished, vfs_get_tree() will call super_wake() on the super block we got anyway. The same applies to security_sb_set_mnt_opts(), as long as we do not free the security from our original fc in btrfs_get_tree_subvol(), the first vfs_get_tree() call will handle the security correctly. So here we only need to: - Replace vfs_get_tree() call with btrfs_get_tree_super() - Keep the existing fc->security for vfs_get_tree() to handle the security This will remove the re-entry behavior and make thing much easier to follow. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 25eec19 commit f6d92b9

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

fs/btrfs/super.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,15 +2046,7 @@ static int btrfs_get_tree_subvol(struct fs_context *fc)
20462046
*/
20472047
dup_fc->s_fs_info = fs_info;
20482048

2049-
/*
2050-
* We'll do the security settings in our btrfs_get_tree_super() mount
2051-
* loop, they were duplicated into dup_fc, we can drop the originals
2052-
* here.
2053-
*/
2054-
security_free_mnt_opts(&fc->security);
2055-
fc->security = NULL;
2056-
2057-
ret = vfs_get_tree(dup_fc);
2049+
ret = btrfs_get_tree_super(dup_fc);
20582050
if (ret)
20592051
goto error;
20602052

@@ -2086,21 +2078,8 @@ static int btrfs_get_tree_subvol(struct fs_context *fc)
20862078

20872079
static int btrfs_get_tree(struct fs_context *fc)
20882080
{
2089-
/*
2090-
* Since we use mount_subtree to mount the default/specified subvol, we
2091-
* have to do mounts in two steps.
2092-
*
2093-
* First pass through we call btrfs_get_tree_subvol(), this is just a
2094-
* wrapper around fc_mount() to call back into here again, and this time
2095-
* we'll call btrfs_get_tree_super(). This will do the open_ctree() and
2096-
* everything to open the devices and file system. Then we return back
2097-
* with a fully constructed vfsmount in btrfs_get_tree_subvol(), and
2098-
* from there we can do our mount_subvol() call, which will lookup
2099-
* whichever subvol we're mounting and setup this fc with the
2100-
* appropriate dentry for the subvol.
2101-
*/
2102-
if (fc->s_fs_info)
2103-
return btrfs_get_tree_super(fc);
2081+
ASSERT(fc->s_fs_info == NULL);
2082+
21042083
return btrfs_get_tree_subvol(fc);
21052084
}
21062085

0 commit comments

Comments
 (0)