Re: [PATCH 3/4] btrfs: preallocate anon_dev for subvolume and snapshot creation

David Sterba
2020-07-02T16:08:41Z

On Thu, Jul 02, 2020 at 07:56:57AM +0800, Qu Wenruo wrote:
> On 2020/7/2 上午1:39, David Sterba wrote:
> > On Wed, Jul 01, 2020 at 11:25:27AM +0800, Qu Wenruo wrote:
> > Adding the anon_dev argument to btrfs_get_fs_root is wrong and I have
> > never suggested that. What I meant is to put the actual id allocation
> > to the callers where the subvolume is created, ie only 2 places.
>
> You mean to extract btrfs_init_fs_root() out of btrfs_get_fs_root()?
>
> That looks a little risky and I can't find any good solution to make it
> more elegant than the current one.

I spent more time reading through the get-fs-root functions and the main
problem is that btrfs_get_fs_root is doing several things, and it makes
a lot of code simple, I certainly want to keep it that way.

The idea was to pre-insert the new root (similar to the root item
insertion, btrfs_insert_root) and not letting btrfs_get_fs_root call to
btrfs_init_fs_info where the anon_bdev allocation happens for all the
other non-ioctl cases.

Which could be done by factoring out btrfs_init_fs_root from
btrfs_get_fs_root. This would allow to extend only btrfs_init_fs_root
arguments with the anon_bdev, and keep btrfs_get_fs_root intact.
So this is splitting the API from the end.

What you originally proposed is a split from the begnning, ie. add a
common implementation for existing and new and provide btrfs_get_fs_root
and btrfs_get_new_fs_root that would hide the additional parameters.

Both ways are IMO valid but I thought it would be easier to pass the
anon bdev inside ioctl callbacks. The problem that makes my proposal
less appealing is that btrfs_read_tree_root gets called earlier than
I'd like so factoring everything after btrfs_init_fs_root would not be
so straightforward.

In conclusion, your proposal is better and I'm going to merge it.

> Although I would definitely remove the "__" prefix as we shouldn't add
> such prefix anymore.

Yeah with the small naming fixups.