btrfs: factor out sysfs code for deleting block group and space infos
authorDavid Sterba <dsterba@suse.com>
Thu, 1 Aug 2019 16:50:16 +0000 (18:50 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:07 +0000 (14:59 +0200)
The helpers to create block group and space info directories already
live in sysfs.c, move the deletion part there too.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/sysfs.c
fs/btrfs/sysfs.h

index 37e56b0c04843f43f57c915ecc5fcc4cc3b3dc9a..05f6464b31236f1e77c3d8fe0371566db960b6ac 100644 (file)
@@ -7539,8 +7539,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
        btrfs_release_global_block_rsv(info);
 
        while (!list_empty(&info->space_info)) {
-               int i;
-
                space_info = list_entry(info->space_info.next,
                                        struct btrfs_space_info,
                                        list);
@@ -7554,17 +7552,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
                            space_info->bytes_may_use > 0))
                        btrfs_dump_space_info(info, space_info, 0, 0);
                list_del(&space_info->list);
-               for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
-                       struct kobject *kobj;
-                       kobj = space_info->block_group_kobjs[i];
-                       space_info->block_group_kobjs[i] = NULL;
-                       if (kobj) {
-                               kobject_del(kobj);
-                               kobject_put(kobj);
-                       }
-               }
-               kobject_del(&space_info->kobj);
-               kobject_put(&space_info->kobj);
+               btrfs_sysfs_remove_space_info(space_info);
        }
        return 0;
 }
index 5562ce1f70907c0baad718f6192d7adac2b57b80..4de9bae3e18689397612e6927dcfb9d38f0a397b 100644 (file)
@@ -800,6 +800,28 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
        space_info->block_group_kobjs[index] = &rkobj->kobj;
 }
 
+/*
+ * Remove sysfs directories for all block group types of a given space info and
+ * the space info as well
+ */
+void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info)
+{
+       int i;
+
+       for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
+               struct kobject *kobj;
+
+               kobj = space_info->block_group_kobjs[i];
+               space_info->block_group_kobjs[i] = NULL;
+               if (kobj) {
+                       kobject_del(kobj);
+                       kobject_put(kobj);
+               }
+       }
+       kobject_del(&space_info->kobj);
+       kobject_put(&space_info->kobj);
+}
+
 static const char *alloc_name(u64 flags)
 {
        switch (flags) {
index 6807d105c0276f7bd4e9f1ebfae57ec2f132df91..031697358b6e63a0c0626559cd88ef37598dc57b 100644 (file)
@@ -98,5 +98,6 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache);
 int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
                                    struct btrfs_space_info *space_info);
+void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info);
 
 #endif