]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
btrfs: add btrfs_sysfs_remove_device helper
authorAnand Jain <anand.jain@oracle.com>
Fri, 4 Sep 2020 17:34:24 +0000 (01:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 7 Oct 2020 10:12:21 +0000 (12:12 +0200)
btrfs_sysfs_remove_devices_dir() removes device link and devid kobject
(sysfs entries) for a device or all the devices in the btrfs_fs_devices.
In preparation to remove these sysfs entries for the seed as well, add
a btrfs_sysfs_remove_device() helper function and avoid code
duplication.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/sysfs.c

index 8ffe5df99b3c83922309d840275155a96d1a3c26..a3bd4ba906cf3b7d85a0042587bcdf2cba366167 100644 (file)
@@ -1186,50 +1186,43 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-/* when one_device is NULL, it removes all device links */
-
-int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices,
-               struct btrfs_device *one_device)
+static void btrfs_sysfs_remove_device(struct btrfs_device *device)
 {
        struct hd_struct *disk;
        struct kobject *disk_kobj;
+       struct kobject *devices_kobj;
 
-       if (!fs_devices->devices_kobj)
-               return -EINVAL;
-
-       if (one_device) {
-               if (one_device->bdev) {
-                       disk = one_device->bdev->bd_part;
-                       disk_kobj = &part_to_dev(disk)->kobj;
-                       sysfs_remove_link(fs_devices->devices_kobj,
-                                         disk_kobj->name);
-               }
+       /*
+        * Seed fs_devices devices_kobj aren't used, fetch kobject from the
+        * fs_info::fs_devices.
+        */
+       devices_kobj = device->fs_info->fs_devices->devices_kobj;
+       ASSERT(devices_kobj);
 
-               if (one_device->devid_kobj.state_initialized) {
-                       kobject_del(&one_device->devid_kobj);
-                       kobject_put(&one_device->devid_kobj);
+       if (device->bdev) {
+               disk = device->bdev->bd_part;
+               disk_kobj = &part_to_dev(disk)->kobj;
+               sysfs_remove_link(devices_kobj, disk_kobj->name);
+       }
 
-                       wait_for_completion(&one_device->kobj_unregister);
-               }
+       if (device->devid_kobj.state_initialized) {
+               kobject_del(&device->devid_kobj);
+               kobject_put(&device->devid_kobj);
+               wait_for_completion(&device->kobj_unregister);
+       }
+}
 
+/* When @device is NULL, remove all devices link */
+int btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices,
+                                  struct btrfs_device *device)
+{
+       if (device) {
+               btrfs_sysfs_remove_device(device);
                return 0;
        }
 
-       list_for_each_entry(one_device, &fs_devices->devices, dev_list) {
-
-               if (one_device->bdev) {
-                       disk = one_device->bdev->bd_part;
-                       disk_kobj = &part_to_dev(disk)->kobj;
-                       sysfs_remove_link(fs_devices->devices_kobj,
-                                         disk_kobj->name);
-               }
-               if (one_device->devid_kobj.state_initialized) {
-                       kobject_del(&one_device->devid_kobj);
-                       kobject_put(&one_device->devid_kobj);
-
-                       wait_for_completion(&one_device->kobj_unregister);
-               }
-       }
+       list_for_each_entry(device, &fs_devices->devices, dev_list)
+               btrfs_sysfs_remove_device(device);
 
        return 0;
 }