@@ -1182,10 +1182,12 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device)
sysfs_remove_link(devices_kobj, disk_kobj->name);
}
- kobject_del(&device->devid_kobj);
- kobject_put(&device->devid_kobj);
+ if (device->devid_kobj.state_initialized) {
+ kobject_del(&device->devid_kobj);
+ kobject_put(&device->devid_kobj);
+ wait_for_completion(&device->kobj_unregister);
+ }
- wait_for_completion(&device->kobj_unregister);
}
static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj,
@@ -1325,18 +1327,22 @@ int btrfs_sysfs_add_fs_devices(struct btrfs_fs_devices *fs_devices)
list_for_each_entry(device, &fs_devices->devices, dev_list) {
ret = btrfs_sysfs_add_device(device);
if (ret)
- return ret;
+ goto fail;
}
list_for_each_entry(seed, &fs_devices->seed_list, seed_list) {
list_for_each_entry(device, &seed->devices, dev_list) {
ret = btrfs_sysfs_add_device(device);
if (ret)
- return ret;
+ goto fail;
}
}
return 0;
+
+fail:
+ btrfs_sysfs_remove_fs_devices(fs_devices);
+ return ret;
}
void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)
btrfs_sysfs_add_fs_devices() is called by btrfs_sysfs_add_mounted(). btrfs_sysfs_add_mounted() assumes that btrfs_sysfs_add_fs_devices() will either add sysfs entries for all the devices or none. So this patch keeps up to its caller expecatation and cleans up the created sysfs entries if it has to fail at some device in the list. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- v3: fix the goto fail fs/btrfs/sysfs.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)