Re: [PATCH 1/2] btrfs: initialize sysfs devid and device link for seed device

Anand Jain
2020-08-23T13:05:47Z

>
> So now we're using the main fs_devices->devices_kobj, which is the main
> fs_devices with fs_devices->seed being the seed fs_devices.  This is
> fine, except when we actually mount a seed device, and in that case we
> have fs_devices as the seed devices being used, and then if we add a
> device we'll actually swap in the new fs_devices for the main
> fs_devices, and we have the seed devices with the actual devices_kobj
> that we used set in fs_devices->seed, and thus we'll leak the sysfs
> objects for the seed devices.  Thanks,

Do you mean leaking the devinfo_kobj instead of devices_kobj? If so,
then yes, and this patch fixed it as well (I just found out).

Otherwise, no, there isn't devices_kobj leak. We make sure only mounted
fsid has the devices_kobj initialized. So during sprouting- the
devices_kobj remains with the fs_info->fs_devices, as we move the seed
devices below the seed_devices.

static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
::
list_splice_init_rcu(&fs_devices->devices, &seed_devices->devices,
synchronize_rcu);
list_for_each_entry(device, &seed_devices->devices, dev_list)
device->fs_devices = seed_devices;

And during unmount, we clean up the dev links and devices_kobj.

close_ctree()
btrfs_sysfs_remove_mounted()
btrfs_sysfs_remove_fsid()

Anand

> Josef