Sysfs cleanups
David Sterba
maintainercover Sysfs cleanups
Handful of almost trivial changes that clean up the sysfs structures and helpers so the sysfs-related api is used only inside sysfs.c and that the API facing btrfs is minimized.
David Sterba (13):
btrfs: move sysfs declarations out of ctree.h
btrfs: move btrfs_add_raid_kobjects to sysfs.c
btrfs: factor sysfs code out of link_block_group
btrfs: sysfs: unexport btrfs_raid_ktype
btrfs: factor out sysfs code for creating space infos
btrfs: sysfs: unexport space_info_ktype
btrfs: sysfs: replace direct access to feature set names with a helper
btrfs: factor out sysfs code for sending device uevent
btrfs: factor out sysfs code for deleting block group and space infos
btrfs: factor out sysfs code for updating sprout fsid
btrfs: cleanup kobject.h includes
btrfs: sysfs: move helper macros to sysfs.c
btrfs: sysfs: move type conversion helpers to sysfs.c
fs/btrfs/ctree.h | 15 --- fs/btrfs/extent-tree.c | 59 +---------- fs/btrfs/ioctl.c | 2 +- fs/btrfs/space-info.c | 25 +---- fs/btrfs/super.c | 1 + fs/btrfs/sysfs.c | 217 ++++++++++++++++++++++++++++++++++++++++- fs/btrfs/sysfs.h | 80 +++------------ fs/btrfs/volumes.c | 25 +---- 8 files changed, 238 insertions(+), 186 deletions(-)
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 1/13 btrfs: move sysfs declarations out of ctree.h
As the header for sysfs code already exists, use it to clean up ctree.h.
--- fs/btrfs/ctree.h | 13 ------------- fs/btrfs/super.c | 1 + fs/btrfs/sysfs.h | 12 ++++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-)
fs/btrfs/ctree.h +0 -13
@@ -397,13 +397,6 @@ struct btrfs_dev_replace {wait_queue_head_t replace_wait; }; -/* For raid type sysfs entries */ -struct raid_kobject { -u64 flags; -struct kobject kobj; -struct list_head list; -}; -/* * free clusters are used to claim free space in relatively large chunks, * allowing us to do less seeky writes. They are used for all metadata
@@ -3265,12 +3258,6 @@ loff_t btrfs_remap_file_range(struct file *file_in, loff_t pos_in,int btrfs_defrag_leaves (struct btrfs_trans_handle *trans,struct btrfs_root *root); -/* sysfs.c */ -int __init btrfs_init_sysfs (void ); -void __cold btrfs_exit_sysfs (void ); -int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info); -void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info); -/* super.c */ int btrfs_parse_options (struct btrfs_fs_info *info,char *options,unsigned long new_flags);
fs/btrfs/super.c +1 -0
@@ -43,6 +43,7 @@#include "free-space-cache.h" #include "backref.h" #include "space-info.h" +#include "sysfs.h" #include "tests/btrfs-tests.h" #include "qgroup.h"
fs/btrfs/sysfs.h +12 -0
@@ -40,6 +40,13 @@ struct btrfs_feature_attr {u64 feature_bit; }; +/* For raid type sysfs entries */ +struct raid_kobject { +u64 flags; +struct kobject kobj; +struct list_head list; +}; +#define BTRFS_FEAT_ATTR (_name, _feature_set, _feature_prefix, _feature_bit) \ static struct btrfs_feature_attr btrfs_attr_features_##_name = { \ .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
@@ -91,4 +98,9 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);void btrfs_sysfs_feature_update (struct btrfs_fs_info *fs_info,u64 bit,enum btrfs_feature_set set); +int __init btrfs_init_sysfs (void ); +void __cold btrfs_exit_sysfs (void ); +int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info); +void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info); +#endif
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 2/13 btrfs: move btrfs_add_raid_kobjects to sysfs.c
In reply to David SterbaThe function manipulates sysfs entries so this belongs to sysfs.c.
--- fs/btrfs/ctree.h | 1 - fs/btrfs/extent-tree.c | 27 --------------------------- fs/btrfs/sysfs.c | 27 +++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 1 + 4 files changed, 28 insertions(+), 28 deletions(-)
fs/btrfs/ctree.h +0 -1
@@ -2700,7 +2700,6 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info);int btrfs_make_block_group (struct btrfs_trans_handle *trans,u64 bytes_used,u64 type,u64 chunk_offset,u64 size); -void btrfs_add_raid_kobjects (struct btrfs_fs_info *fs_info);struct btrfs_trans_handle *btrfs_start_trans_remove_block_group (struct btrfs_fs_info *fs_info,const u64 chunk_offset);
fs/btrfs/extent-tree.c +0 -27
@@ -7774,33 +7774,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)return 0 ; } -/* link_block_group will queue up kobjects to add when we're reclaim-safe */ -void btrfs_add_raid_kobjects (struct btrfs_fs_info *fs_info) -{ -struct btrfs_space_info *space_info; -struct raid_kobject *rkobj; -LIST_HEAD (list); -int ret =0 ; - -spin_lock (&fs_info->pending_raid_kobjs_lock); -list_splice_init (&fs_info->pending_raid_kobjs, &list); -spin_unlock (&fs_info->pending_raid_kobjs_lock); - -list_for_each_entry (rkobj, &list, list) { - space_info =btrfs_find_space_info (fs_info, rkobj->flags); - - ret =kobject_add (&rkobj->kobj, &space_info->kobj, -"%s" ,btrfs_bg_type_to_raid_name (rkobj->flags)); -if (ret) { -kobject_put (&rkobj->kobj); -break ; - } - } -if (ret) -btrfs_warn (fs_info, -"failed to add kobject for block cache, ignoring" ); -} -static void link_block_group (struct btrfs_block_group_cache *cache) {struct btrfs_space_info *space_info = cache->space_info;
fs/btrfs/sysfs.c +27 -0
@@ -730,6 +730,33 @@ static void init_feature_attrs(void) } } +/* link_block_group will queue up kobjects to add when we're reclaim-safe */ +void btrfs_add_raid_kobjects (struct btrfs_fs_info *fs_info) +{ +struct btrfs_space_info *space_info; +struct raid_kobject *rkobj; +LIST_HEAD (list); +int ret =0 ; + +spin_lock (&fs_info->pending_raid_kobjs_lock); +list_splice_init (&fs_info->pending_raid_kobjs, &list); +spin_unlock (&fs_info->pending_raid_kobjs_lock); + +list_for_each_entry (rkobj, &list, list) { + space_info =btrfs_find_space_info (fs_info, rkobj->flags); + + ret =kobject_add (&rkobj->kobj, &space_info->kobj, +"%s" ,btrfs_bg_type_to_raid_name (rkobj->flags)); +if (ret) { +kobject_put (&rkobj->kobj); +break ; + } + } +if (ret) +btrfs_warn (fs_info, +"failed to add kobject for block cache, ignoring" ); +} +/* when one_device is NULL, it removes all device links */ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
fs/btrfs/sysfs.h +1 -0
@@ -102,5 +102,6 @@ int __init btrfs_init_sysfs(void);void __cold btrfs_exit_sysfs (void );int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info);void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info); +void btrfs_add_raid_kobjects (struct btrfs_fs_info *fs_info);#endif
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 3/13 btrfs: factor sysfs code out of link_block_group
In reply to David SterbaThe part of link_block_group that just creates the sysfs object is independent and can be factored out to a helper.
--- fs/btrfs/extent-tree.c | 18 ++---------------- fs/btrfs/sysfs.c | 27 +++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 1 + 3 files changed, 30 insertions(+), 16 deletions(-)
fs/btrfs/extent-tree.c +2 -16
@@ -7777,7 +7777,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)static void link_block_group (struct btrfs_block_group_cache *cache) {struct btrfs_space_info *space_info = cache->space_info; -struct btrfs_fs_info *fs_info = cache->fs_info;int index =btrfs_bg_flags_to_raid_index (cache->flags);bool first = false;
@@ -7787,21 +7786,8 @@ static void link_block_group(struct btrfs_block_group_cache *cache)list_add_tail (&cache->list, &space_info->block_groups[index]);up_write (&space_info->groups_sem); -if (first) { -struct raid_kobject *rkobj =kzalloc (sizeof (*rkobj),GFP_NOFS ); -if (!rkobj) { -btrfs_warn (cache->fs_info, -"couldn't alloc memory for raid level kobject" ); -return ; - } - rkobj->flags = cache->flags; -kobject_init (&rkobj->kobj, &btrfs_raid_ktype); - -spin_lock (&fs_info->pending_raid_kobjs_lock); -list_add_tail (&rkobj->list, &fs_info->pending_raid_kobjs); -spin_unlock (&fs_info->pending_raid_kobjs_lock); - space_info->block_group_kobjs[index] = &rkobj->kobj; - } +if (first) +btrfs_sysfs_add_block_group_type (cache); } static struct btrfs_block_group_cache *
fs/btrfs/sysfs.c +27 -0
@@ -757,6 +757,33 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info) "failed to add kobject for block cache, ignoring"); } +/* +* Create a sysfs entry for a given block group type at path +* /sys/fs/btrfs/UUID/allocation/data/TYPE +*/ +void btrfs_sysfs_add_block_group_type (struct btrfs_block_group_cache *cache) +{ +struct btrfs_fs_info *fs_info = cache->fs_info; +struct btrfs_space_info *space_info = cache->space_info; +struct raid_kobject *rkobj; +const int index =btrfs_bg_flags_to_raid_index (cache->flags); + + rkobj =kzalloc (sizeof (*rkobj),GFP_NOFS ); +if (!rkobj) { +btrfs_warn (cache->fs_info, +"couldn't alloc memory for raid level kobject" ); +return ; + } + + rkobj->flags = cache->flags; +kobject_init (&rkobj->kobj, &btrfs_raid_ktype); + +spin_lock (&fs_info->pending_raid_kobjs_lock); +list_add_tail (&rkobj->list, &fs_info->pending_raid_kobjs); +spin_unlock (&fs_info->pending_raid_kobjs_lock); + space_info->block_group_kobjs[index] = &rkobj->kobj; +} +/* when one_device is NULL, it removes all device links */ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
fs/btrfs/sysfs.h +1 -0
@@ -103,5 +103,6 @@ void __cold btrfs_exit_sysfs(void);int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info);void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info);void btrfs_add_raid_kobjects (struct btrfs_fs_info *fs_info); +void btrfs_sysfs_add_block_group_type (struct btrfs_block_group_cache *cache);#endif
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 4/13 btrfs: sysfs: unexport btrfs_raid_ktype
In reply to David SterbaThe last non-sysfs usage of btrfs_raid_ktype has been moved to a private helper in previous patch so the variable can be made static.
--- fs/btrfs/sysfs.c | 2 +- fs/btrfs/sysfs.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/sysfs.c +1 -1
@@ -316,7 +316,7 @@ static void release_raid_kobj(struct kobject *kobj)kfree (to_raid_kobj (kobj)); } -struct kobj_type btrfs_raid_ktype = { +static struct kobj_type btrfs_raid_ktype = { .sysfs_ops = &kobj_sysfs_ops, .release = release_raid_kobj, .default_groups = raid_groups,
fs/btrfs/sysfs.h +0 -1
@@ -86,7 +86,6 @@ attr_to_btrfs_feature_attr(struct attribute *attr)char *btrfs_printable_features (enum btrfs_feature_set set,u64 flags);extern const char *const btrfs_feature_set_names[FEAT_MAX ];extern struct kobj_type space_info_ktype; -extern struct kobj_type btrfs_raid_ktype;int btrfs_sysfs_add_device_link (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 5/13 btrfs: factor out sysfs code for creating space infos
In reply to David SterbaMove creation of data/metadata/system space info directories to sysfs.c.
--- fs/btrfs/space-info.c | 25 ++----------------------- fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 2 ++ 3 files changed, 41 insertions(+), 23 deletions(-)
fs/btrfs/space-info.c +2 -23
@@ -33,23 +33,6 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)rcu_read_unlock (); } -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" ; - }; -} -static int create_space_info (struct btrfs_fs_info *info,u64 flags) {
@@ -79,13 +62,9 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)INIT_LIST_HEAD (&space_info->tickets);INIT_LIST_HEAD (&space_info->priority_tickets); - ret =kobject_init_and_add (&space_info->kobj, &space_info_ktype, - info->space_info_kobj,"%s" , -alloc_name (space_info->flags)); -if (ret) { -kobject_put (&space_info->kobj); + ret =btrfs_sysfs_add_space_info_type (info, space_info); +if (ret)return ret; - }list_add_rcu (&space_info->list, &info->space_info);if (flags &BTRFS_BLOCK_GROUP_DATA )
fs/btrfs/sysfs.c +37 -0
@@ -784,6 +784,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,
fs/btrfs/sysfs.h +2 -0
@@ -103,5 +103,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info);void btrfs_add_raid_kobjects (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);#endif
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 6/13 btrfs: sysfs: unexport space_info_ktype
In reply to David SterbaThe last non-sysfs usage of space_info_ktype has been moved to a private helper in previous patch so the variable can be made static.
--- fs/btrfs/sysfs.c | 2 +- fs/btrfs/sysfs.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/sysfs.c +1 -1
@@ -375,7 +375,7 @@ static void space_info_release(struct kobject *kobj)kfree (sinfo); } -struct kobj_type space_info_ktype = { +static struct kobj_type space_info_ktype = { .sysfs_ops = &kobj_sysfs_ops, .release = space_info_release, .default_groups = space_info_groups,
fs/btrfs/sysfs.h +0 -1
@@ -85,7 +85,6 @@ attr_to_btrfs_feature_attr(struct attribute *attr)char *btrfs_printable_features (enum btrfs_feature_set set,u64 flags);extern const char *const btrfs_feature_set_names[FEAT_MAX ]; -extern struct kobj_type space_info_ktype;int btrfs_sysfs_add_device_link (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 7/13 btrfs: sysfs: replace direct access to feature set names with a helper
In reply to David SterbaIn order to unexport the feature type array, add a helper for the enum-to-string conversion.
--- fs/btrfs/ioctl.c | 2 +- fs/btrfs/sysfs.c | 7 ++++++- fs/btrfs/sysfs.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +1 -1
@@ -5258,7 +5258,7 @@ static int check_feature_bits(struct btrfs_fs_info *fs_info, u64 change_mask, u64 flags, u64 supported_flags, u64 safe_set, u64 safe_clear) { - const char *type = btrfs_feature_set_names[set]; + const char *type = btrfs_feature_set_name(set);char *names;u64 disallowed, unsupported;u64 set_mask = flags & change_mask;
fs/btrfs/sysfs.c +6 -1
@@ -655,12 +655,17 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)btrfs_sysfs_rm_device_link (fs_info->fs_devices,NULL ); } -const char *const btrfs_feature_set_names[FEAT_MAX ] = { +static const char *const btrfs_feature_set_names[FEAT_MAX ] = { [FEAT_COMPAT ] ="compat" , [FEAT_COMPAT_RO ] ="compat_ro" , [FEAT_INCOMPAT ] ="incompat" , }; +const char *const btrfs_feature_set_name (enum btrfs_feature_set set) +{ +return btrfs_feature_set_names[set]; +} +char *btrfs_printable_features (enum btrfs_feature_set set,u64 flags) {size_t bufsize =4096 ;/* safe max, 64 names * 64 bytes */
fs/btrfs/sysfs.h +1 -1
@@ -84,7 +84,7 @@ attr_to_btrfs_feature_attr(struct attribute *attr) }char *btrfs_printable_features (enum btrfs_feature_set set,u64 flags); -extern const char *const btrfs_feature_set_names[FEAT_MAX ]; +const char *const btrfs_feature_set_name (enum btrfs_feature_set set);int btrfs_sysfs_add_device_link (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 8/13 btrfs: factor out sysfs code for sending device uevent
In reply to David SterbaThe device uevent belongs to the sysfs API.
--- fs/btrfs/sysfs.c | 11 +++++++++++ fs/btrfs/sysfs.h | 1 + fs/btrfs/volumes.c | 13 ------------- 3 files changed, 12 insertions(+), 13 deletions(-)
fs/btrfs/sysfs.c +11 -0
@@ -902,6 +902,17 @@ int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,return error; } +void btrfs_kobject_uevent (struct block_device *bdev,enum kobject_action action) +{ +int ret; + + ret =kobject_uevent (&disk_to_dev (bdev->bd_disk)->kobj, action); +if (ret) +pr_warn ("BTRFS: Sending event '%d' to kobject: '%s' (%p): failed\n" , + action,kobject_name (&disk_to_dev (bdev->bd_disk)->kobj), + &disk_to_dev (bdev->bd_disk)->kobj); +} +/* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset;
fs/btrfs/sysfs.h +1 -0
@@ -95,6 +95,7 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);void btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs);void btrfs_sysfs_feature_update (struct btrfs_fs_info *fs_info,u64 bit,enum btrfs_feature_set set); +void btrfs_kobject_uevent (struct block_device *bdev,enum kobject_action action);int __init btrfs_init_sysfs (void );void __cold btrfs_exit_sysfs (void );
fs/btrfs/volumes.c +0 -13
@@ -358,19 +358,6 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices)kfree (fs_devices); } -static void btrfs_kobject_uevent (struct block_device *bdev, -enum kobject_action action) -{ -int ret; - - ret =kobject_uevent (&disk_to_dev (bdev->bd_disk)->kobj, action); -if (ret) -pr_warn ("BTRFS: Sending event '%d' to kobject: '%s' (%p): failed\n" , - action, -kobject_name (&disk_to_dev (bdev->bd_disk)->kobj), - &disk_to_dev (bdev->bd_disk)->kobj); -} - void __exit btrfs_cleanup_fs_uuids(void) {struct btrfs_fs_devices *fs_devices;
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 9/13 btrfs: factor out sysfs code for deleting block group and space infos
In reply to David SterbaThe helpers to create block group and space info directories already live in sysfs.c, move the deletion part there too.
--- fs/btrfs/extent-tree.c | 14 +------------- fs/btrfs/sysfs.c | 22 ++++++++++++++++++++++ fs/btrfs/sysfs.h | 1 + 3 files changed, 24 insertions(+), 13 deletions(-)
fs/btrfs/extent-tree.c +1 -13
@@ -7744,8 +7744,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);
@@ -7759,17 +7757,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 ; }
fs/btrfs/sysfs.c +22 -0
@@ -789,6 +789,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) {
fs/btrfs/sysfs.h +1 -0
@@ -105,5 +105,6 @@ void btrfs_add_raid_kobjects(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
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 10/13 btrfs: factor out sysfs code for updating sprout fsid
In reply to David SterbaWrap the fsid renaming code and move it to sysfs.c.
--- fs/btrfs/sysfs.c | 15 +++++++++++++++ fs/btrfs/sysfs.h | 2 ++ fs/btrfs/volumes.c | 12 ++---------- 3 files changed, 19 insertions(+), 10 deletions(-)
fs/btrfs/sysfs.c +15 -0
@@ -935,6 +935,21 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action) &disk_to_dev(bdev->bd_disk)->kobj); } +void btrfs_sysfs_update_sprout_fsid (struct btrfs_fs_devices *fs_devices, +const u8 *fsid) +{ +char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; + +/* +* Sprouting changes fsid of the mounted filesystem, rename the fsid +* directory +*/ +snprintf (fsid_buf,BTRFS_UUID_UNPARSED_SIZE ,"%pU" , fsid); +if (kobject_rename (&fs_devices->fsid_kobj, fsid_buf)) +btrfs_warn (fs_devices->fs_info, +"sysfs: failed to create fsid for sprout" ); +} +/* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset;
fs/btrfs/sysfs.h +2 -0
@@ -93,6 +93,8 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs, struct kobject *parent);int btrfs_sysfs_add_device (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, +const u8 *fsid);void btrfs_sysfs_feature_update (struct btrfs_fs_info *fs_info,u64 bit,enum btrfs_feature_set set);void btrfs_kobject_uevent (struct block_device *bdev,enum kobject_action action);
fs/btrfs/volumes.c +2 -10
@@ -2680,22 +2680,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path }if (seeding_dev) { -char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; - ret =btrfs_finish_sprout (trans);if (ret) {btrfs_abort_transaction (trans, ret); goto error_sysfs; } -/* Sprouting would change fsid of the mounted root, -* so rename the fsid on the sysfs -*/ -snprintf (fsid_buf,BTRFS_UUID_UNPARSED_SIZE ,"%pU" , - fs_info->fs_devices->fsid); -if (kobject_rename (&fs_devices->fsid_kobj, fsid_buf)) -btrfs_warn (fs_info, -"sysfs: failed to create fsid for sprout" ); +btrfs_sysfs_update_sprout_fsid (fs_devices, + fs_info->fs_devices->fsid); } ret =btrfs_commit_transaction (trans);
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 11/13 btrfs: cleanup kobject.h includes
In reply to David SterbaThe kobject should be pulled in via sysfs.h and that needs to include it because it needs various definitions like kobj_attribute or kobject.
--- fs/btrfs/ctree.h | 1 - fs/btrfs/sysfs.c | 1 - fs/btrfs/sysfs.h | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +0 -1
@@ -16,7 +16,6 @@#include <linux/backing-dev.h> #include <linux/wait.h> #include <linux/slab.h> -#include <linux/kobject.h> #include <trace/events/btrfs.h> #include <asm/kmap_types.h> #include <asm/unaligned.h>
fs/btrfs/sysfs.c +0 -1
@@ -7,7 +7,6 @@#include <linux/slab.h> #include <linux/spinlock.h> #include <linux/completion.h> -#include <linux/kobject.h> #include <linux/bug.h> #include <linux/debugfs.h>
fs/btrfs/sysfs.h +2 -0
@@ -3,6 +3,8 @@#ifndef BTRFS_SYSFS_H #define BTRFS_SYSFS_H +#include <linux/kobject.h> +/* * Data exported through sysfs */
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 12/13 btrfs: sysfs: move helper macros to sysfs.c
In reply to David SterbaNone of the macros is used outside of sysfs.c.
--- fs/btrfs/sysfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/sysfs.h | 50 ------------------------------------------------ 2 files changed, 49 insertions(+), 50 deletions(-)
fs/btrfs/sysfs.c +49 -0
@@ -17,6 +17,55 @@#include "volumes.h" #include "space-info.h" +struct btrfs_feature_attr { +struct kobj_attribute kobj_attr; +enum btrfs_feature_set feature_set; +u64 feature_bit; +}; + +/* For raid type sysfs entries */ +struct raid_kobject { +u64 flags; +struct kobject kobj; +struct list_head list; +}; + +#define __INIT_KOBJ_ATTR (_name, _mode, _show, _store) \ +{ \ + .attr = { .name = __stringify(_name), .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +} + +#define BTRFS_ATTR_RW (_prefix, _name, _show, _store) \ + static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ + __INIT_KOBJ_ATTR(_name, 0644, _show, _store) + +#define BTRFS_ATTR (_prefix, _name, _show) \ + static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ + __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) + +#define BTRFS_ATTR_PTR (_prefix, _name) \ + (&btrfs_attr_##_prefix##_##_name.attr) + +#define BTRFS_FEAT_ATTR (_name, _feature_set, _feature_prefix, _feature_bit) \ +static struct btrfs_feature_attr btrfs_attr_features_##_name = { \ + .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \ + btrfs_feature_attr_show, \ + btrfs_feature_attr_store), \ + .feature_set = _feature_set, \ + .feature_bit = _feature_prefix ##_## _feature_bit, \ +} +#define BTRFS_FEAT_ATTR_PTR (_name) \ + (&btrfs_attr_features_##_name.kobj_attr.attr) + +#define BTRFS_FEAT_ATTR_COMPAT (name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature) +#define BTRFS_FEAT_ATTR_COMPAT_RO (name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature) +#define BTRFS_FEAT_ATTR_INCOMPAT (name, feature) \ + BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) +static inline struct btrfs_fs_info *to_fs_info (struct kobject *kobj);static inline struct btrfs_fs_devices *to_fs_devs (struct kobject *kobj);
fs/btrfs/sysfs.h +0 -50
56 lines not on this page · raw message
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 13/13 btrfs: sysfs: move type conversion helpers to sysfs.c
In reply to David Sterba--- fs/btrfs/sysfs.c | 17 +++++++++++++++++ fs/btrfs/sysfs.h | 18 ------------------ 2 files changed, 17 insertions(+), 18 deletions(-)
fs/btrfs/sysfs.c +17 -0
@@ -69,6 +69,23 @@ static struct btrfs_feature_attr btrfs_attr_features_##_name = { \static inline struct btrfs_fs_info *to_fs_info (struct kobject *kobj);static inline struct btrfs_fs_devices *to_fs_devs (struct kobject *kobj); +/* convert from attribute */ +static struct btrfs_feature_attr *to_btrfs_feature_attr (struct kobj_attribute *a) +{ + return container_of(a, struct btrfs_feature_attr, kobj_attr); +} + +static struct kobj_attribute *attr_to_btrfs_attr (struct attribute *attr) +{ + return container_of(attr, struct kobj_attribute, attr); +} + +static struct btrfs_feature_attr *attr_to_btrfs_feature_attr ( +struct attribute *attr) +{ +return to_btrfs_feature_attr (attr_to_btrfs_attr (attr)); +} +static u64 get_features (struct btrfs_fs_info *fs_info,enum btrfs_feature_set set) {
fs/btrfs/sysfs.h +0 -18
@@ -17,24 +17,6 @@ enum btrfs_feature_set {FEAT_MAX }; -/* convert from attribute */ -static inline struct btrfs_feature_attr * -to_btrfs_feature_attr (struct kobj_attribute *a) -{ - return container_of(a, struct btrfs_feature_attr, kobj_attr); -} - -static inline struct kobj_attribute *attr_to_btrfs_attr (struct attribute *attr) -{ - return container_of(attr, struct kobj_attribute, attr); -} - -static inline struct btrfs_feature_attr * -attr_to_btrfs_feature_attr (struct attribute *attr) -{ -return to_btrfs_feature_attr (attr_to_btrfs_attr (attr)); -} -char *btrfs_printable_features (enum btrfs_feature_set set,u64 flags);const char *const btrfs_feature_set_name (enum btrfs_feature_set set); int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
Signature · 1 line
2.22.0