diff options
author | David Sterba <dsterba@suse.com> | 2019-08-01 19:50:16 +0300 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2019-09-09 15:59:06 +0300 |
commit | b882327a774041d5710e37da3286e25278a1947f (patch) | |
tree | 59ee6d29373db7b60f471600e40a2ddb7ecdede8 /fs/btrfs/sysfs.c | |
parent | 536ea45cba34618669a2f984fa7dff86480823fb (diff) |
btrfs: factor out sysfs code for creating space infos
Move creation of data/metadata/system space info directories to sysfs.c.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/sysfs.c')
-rw-r--r-- | fs/btrfs/sysfs.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index f581ceedf5a9..d982730265b9 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -795,6 +795,43 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache) space_info->block_group_kobjs[index] = &rkobj->kobj; } +static const char *alloc_name(u64 flags) +{ + switch (flags) { + case BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA: + return "mixed"; + case BTRFS_BLOCK_GROUP_METADATA: + return "metadata"; + case BTRFS_BLOCK_GROUP_DATA: + return "data"; + case BTRFS_BLOCK_GROUP_SYSTEM: + return "system"; + default: + WARN_ON(1); + return "invalid-combination"; + }; +} + +/* + * Create a sysfs entry for a space info type at path + * /sys/fs/btrfs/UUID/allocation/TYPE + */ +int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, + struct btrfs_space_info *space_info) +{ + int ret; + + ret = kobject_init_and_add(&space_info->kobj, &space_info_ktype, + fs_info->space_info_kobj, "%s", + alloc_name(space_info->flags)); + if (ret) { + kobject_put(&space_info->kobj); + return ret; + } + + return 0; +} + /* when one_device is NULL, it removes all device links */ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, |