Skip to content

Commit

Permalink
btrfs: factor out sysfs code for deleting block group and space infos
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kdave committed Sep 9, 2019
1 parent 5b28692 commit b5865ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
14 changes: 1 addition & 13 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions fs/btrfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b5865ba

Please sign in to comment.