btrfs: split and refactor btrfs_sysfs_remove_devices_dir
authorAnand Jain <anand.jain@oracle.com>
Fri, 4 Sep 2020 17:34:27 +0000 (01:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 7 Oct 2020 10:12:21 +0000 (12:12 +0200)
Similar to btrfs_sysfs_add_devices_dir()'s refactoring, split
btrfs_sysfs_remove_devices_dir() so that we don't have to use the device
argument to indicate whether to free all devices or just one device.

Export btrfs_sysfs_remove_device() as device operations outside of
sysfs.c now calls this instead of btrfs_sysfs_remove_devices_dir().

btrfs_sysfs_remove_devices_dir() is renamed to
btrfs_sysfs_remove_fs_devices() to suite its new role.

Now, no one outside of sysfs.c calls btrfs_sysfs_remove_fs_devices()
so it is redeclared s static. And the same function had to be moved
before its first caller.

Reviewed-by: Nikolay Borisov <nborisov@suse.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/dev-replace.c
fs/btrfs/sysfs.c
fs/btrfs/sysfs.h
fs/btrfs/volumes.c

index c176375c2c026121215f8ea7c21b32d19cf3d791..db4d4a53ab73fd3b45516928f454e88b098e8845 100644 (file)
@@ -781,7 +781,7 @@ error:
        mutex_unlock(&fs_info->fs_devices->device_list_mutex);
 
        /* replace the sysfs entry */
-       btrfs_sysfs_remove_devices_dir(fs_info->fs_devices, src_device);
+       btrfs_sysfs_remove_device(src_device);
        btrfs_sysfs_update_devid(tgt_device);
        if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &src_device->dev_state))
                btrfs_scratch_superblocks(fs_info, src_device->bdev,
index bc341560dc69c92a2d969bdaac008b8ddd13a7fb..7aed0712f1834dce4efc02611883d1c4151145e4 100644 (file)
@@ -972,6 +972,14 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
        }
 }
 
+static void btrfs_sysfs_remove_fs_devices(struct btrfs_fs_devices *fs_devices)
+{
+       struct btrfs_device *device;
+
+       list_for_each_entry(device, &fs_devices->devices, dev_list)
+               btrfs_sysfs_remove_device(device);
+}
+
 void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 {
        struct kobject *fsid_kobj = &fs_info->fs_devices->fsid_kobj;
@@ -999,7 +1007,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
        addrm_unknown_feature_attrs(fs_info, false);
        sysfs_remove_group(fsid_kobj, &btrfs_feature_attr_group);
        sysfs_remove_files(fsid_kobj, btrfs_attrs);
-       btrfs_sysfs_remove_devices_dir(fs_info->fs_devices, NULL);
+       btrfs_sysfs_remove_fs_devices(fs_info->fs_devices);
 }
 
 static const char * const btrfs_feature_set_names[FEAT_MAX] = {
@@ -1186,7 +1194,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-static void btrfs_sysfs_remove_device(struct btrfs_device *device)
+void btrfs_sysfs_remove_device(struct btrfs_device *device)
 {
        struct hd_struct *disk;
        struct kobject *disk_kobj;
@@ -1212,19 +1220,6 @@ static void btrfs_sysfs_remove_device(struct btrfs_device *device)
        }
 }
 
-/* When @device is NULL, remove all devices link */
-void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices,
-                                   struct btrfs_device *device)
-{
-       if (device) {
-               btrfs_sysfs_remove_device(device);
-               return;
-       }
-
-       list_for_each_entry(device, &fs_devices->devices, dev_list)
-               btrfs_sysfs_remove_device(device);
-}
-
 static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj,
                                                 struct kobj_attribute *a,
                                                 char *buf)
@@ -1459,7 +1454,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 
        error = sysfs_create_files(fsid_kobj, btrfs_attrs);
        if (error) {
-               btrfs_sysfs_remove_devices_dir(fs_devs, NULL);
+               btrfs_sysfs_remove_fs_devices(fs_devs);
                return error;
        }
 
index 6296c4f6b3303501308231ae93eb125c20a9e9f3..bacef43f72672ba594420dcf65c8fd17d27f563d 100644 (file)
@@ -15,8 +15,7 @@ enum btrfs_feature_set {
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 const char *btrfs_feature_set_name(enum btrfs_feature_set set);
 int btrfs_sysfs_add_device(struct btrfs_device *device);
-void btrfs_sysfs_remove_devices_dir(struct btrfs_fs_devices *fs_devices,
-                                   struct btrfs_device *device);
+void btrfs_sysfs_remove_device(struct btrfs_device *device);
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices);
index 2aa7fd89efbf71605105a508f5a0de504406e907..79fe9822196f11d3f85043aae921d509a1e273d0 100644 (file)
@@ -2041,7 +2041,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
 }
 
 int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
-               u64 devid)
+                   u64 devid)
 {
        struct btrfs_device *device;
        struct btrfs_fs_devices *cur_devices;
@@ -2145,7 +2145,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
        if (device->bdev) {
                cur_devices->open_devices--;
                /* remove sysfs entry */
-               btrfs_sysfs_remove_devices_dir(fs_devices, device);
+               btrfs_sysfs_remove_device(device);
        }
 
        num_devices = btrfs_super_num_devices(fs_info->super_copy) - 1;
@@ -2246,7 +2246,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
 
        mutex_lock(&fs_devices->device_list_mutex);
 
-       btrfs_sysfs_remove_devices_dir(fs_devices, tgtdev);
+       btrfs_sysfs_remove_device(tgtdev);
 
        if (tgtdev->bdev)
                fs_devices->open_devices--;
@@ -2682,7 +2682,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
        return ret;
 
 error_sysfs:
-       btrfs_sysfs_remove_devices_dir(fs_devices, device);
+       btrfs_sysfs_remove_device(device);
        mutex_lock(&fs_info->fs_devices->device_list_mutex);
        mutex_lock(&fs_info->chunk_mutex);
        list_del_rcu(&device->dev_list);