btrfs: sysfs, cleanups
cover btrfs: sysfs, cleanups
Mostly cleanups patches.
Patches 1-7 are renames, code moves patches and there are no functional changes.
Patch 8 drops unused argument in the function btrfs_sysfs_add_fsid(). Patch 9 merges two small functions which is an extension of the other.
Patches 10,11 and 13 removes unnecessary features in the functions, originally it was planned to provide sysfs attributes for the scanned and unmounted devices, as in the un-merged patch in the mailing list [1]
[1] [PATCH] btrfs: Introduce device pool sysfs attributes
Patch 12 merges functions.
Patches 14,15 are code optimize patches.
Anand Jain (15):
btrfs: sysfs, rename device_link add,remove functions
btrfs: sysfs, rename btrfs_sysfs_add_device()
btrfs: sysfs, rename btrfs_device member device_dir_kobj
btrfs: sysfs, move declared struct near its use
btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
btrfs: sysfs, move add remove _mounted function together
btrfs: sysfs, delete code in a comment
btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
btrfs: sysfs, merge btrfs_sysfs_add devices_dir and fsid
btrfs: volume, btrfs_free_stale_devices() cleanup unreachable code
btrfs: sysfs, migrate fs_decvices::fsid_kobject to struct
btrfs_fs_info
btrfs: sysfs, unexport btrfs_sysfs_add_mounted()
btrfs: sysfs, cleanup btrfs_sysfs_remove_fsid()
btrfs: sysfs, merge btrfs_sysfs_remove_fsid() helper function
btrfs: sysfs, unexport btrfs_sysfs_remove_mounted()
fs/btrfs/ctree.h | 2 + fs/btrfs/dev-replace.c | 4 +- fs/btrfs/disk-io.c | 25 +--- fs/btrfs/sysfs.c | 258 ++++++++++++++++++----------------------- fs/btrfs/sysfs.h | 12 +- fs/btrfs/volumes.c | 10 +- fs/btrfs/volumes.h | 3 +- 7 files changed, 134 insertions(+), 180 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/15 btrfs: sysfs, rename device_link add,remove functions
In preparation to add btrfs_device::dev_state attribute in
/sys/fs/btrfs/UUID/devices/
Rename btrfs_sysfs_add_device_link() and btrfs_sysfs_rm_device_link() to btrfs_sysfs_add_device_info() and btrfs_sysfs_remove_device_info() as these functions is going to create more attributes rather than just the link to the disk. No functional changes.
--- fs/btrfs/dev-replace.c | 4 ++-- fs/btrfs/sysfs.c | 10 +++++----- fs/btrfs/sysfs.h | 4 ++-- fs/btrfs/volumes.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-)
fs/btrfs/dev-replace.c +2 -2
@@ -472,7 +472,7 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,atomic64_set (&dev_replace->num_uncorrectable_read_errors,0 );up_write (&dev_replace->rwsem); - ret =btrfs_sysfs_add_device_link (tgt_device->fs_devices, tgt_device); + ret =btrfs_sysfs_add_device_info (tgt_device->fs_devices, tgt_device);if (ret)btrfs_err (fs_info,"kobj add dev failed %d" , ret);
@@ -706,7 +706,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,mutex_unlock (&fs_info->fs_devices->device_list_mutex);/* replace the sysfs entry */ -btrfs_sysfs_rm_device_link (fs_info->fs_devices, src_device); +btrfs_sysfs_remove_device_info (fs_info->fs_devices, src_device);btrfs_rm_dev_replace_free_srcdev (src_device);/* write back the superblocks */
fs/btrfs/sysfs.c +5 -5
@@ -784,7 +784,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)addrm_unknown_feature_attrs (fs_info, false);sysfs_remove_group (&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group);sysfs_remove_files (&fs_info->fs_devices->fsid_kobj, btrfs_attrs); -btrfs_sysfs_rm_device_link (fs_info->fs_devices,NULL ); +btrfs_sysfs_remove_device_info (fs_info->fs_devices,NULL ); }static const char *const btrfs_feature_set_names[FEAT_MAX ] = {
@@ -973,7 +973,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,/* when one_device is NULL, it removes all device links */ -int btrfs_sysfs_rm_device_link (struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_remove_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device) {struct hd_struct *disk;
@@ -1019,7 +1019,7 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)return 0 ; } -int btrfs_sysfs_add_device_link (struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_add_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device) {int error =0 ;
@@ -1105,13 +1105,13 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)btrfs_set_fs_info_ptr (fs_info); - error =btrfs_sysfs_add_device_link (fs_devs,NULL ); + error =btrfs_sysfs_add_device_info (fs_devs,NULL );if (error)return error; error =sysfs_create_files (fsid_kobj, btrfs_attrs);if (error) { -btrfs_sysfs_rm_device_link (fs_devs,NULL ); +btrfs_sysfs_remove_device_info (fs_devs,NULL );return error; }
fs/btrfs/sysfs.h +2 -2
@@ -14,9 +14,9 @@ enum btrfs_feature_set {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, +int btrfs_sysfs_add_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); -int btrfs_sysfs_rm_device_link (struct btrfs_fs_devices *fs_devices, +int btrfs_sysfs_remove_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device);int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs,struct kobject *parent);
fs/btrfs/volumes.c +4 -4
@@ -2012,7 +2012,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_rm_device_link (fs_devices, device); +btrfs_sysfs_remove_device_info (fs_devices, device); } num_devices =btrfs_super_num_devices (fs_info->super_copy) -1 ;
@@ -2133,7 +2133,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)WARN_ON (!tgtdev);mutex_lock (&fs_devices->device_list_mutex); -btrfs_sysfs_rm_device_link (fs_devices, tgtdev); +btrfs_sysfs_remove_device_info (fs_devices, tgtdev);if (tgtdev->bdev) fs_devices->open_devices--;
@@ -2481,7 +2481,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path orig_super_num_devices + 1);/* add sysfs device entry */ -btrfs_sysfs_add_device_link (fs_devices, device); +btrfs_sysfs_add_device_info (fs_devices, device);/* * we've got more storage, clear any full flags on the space
@@ -2549,7 +2549,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathreturn ret; error_sysfs: -btrfs_sysfs_rm_device_link (fs_devices, device); +btrfs_sysfs_remove_device_info (fs_devices, device);mutex_lock (&fs_info->fs_devices->device_list_mutex);mutex_lock (&fs_info->chunk_mutex);list_del_rcu (&device->dev_list);
Signature · 1 line
2.23.0
PATCH 2/15 btrfs: sysfs, rename btrfs_sysfs_add_device()
In reply to Anand Jainbtrfs_sysfs_add_device() creates the directory /sys/fs/btrfs/UUID/devices but its function name is misleading. Rename it to btrfs_sysfs_add_devices_dir() instead. No functional changes.
--- fs/btrfs/disk-io.c | 2 +- fs/btrfs/sysfs.c | 2 +- fs/btrfs/sysfs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/disk-io.c +1 -1
@@ -3089,7 +3089,7 @@ int __cold open_ctree(struct super_block *sb, goto fail_block_groups; } - ret =btrfs_sysfs_add_device (fs_devices); + ret =btrfs_sysfs_add_devices_dir (fs_devices);if (ret) {btrfs_err (fs_info,"failed to init sysfs device interface: %d" , ret);
fs/btrfs/sysfs.c +1 -1
@@ -1007,7 +1007,7 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices,return 0 ; } -int btrfs_sysfs_add_device (struct btrfs_fs_devices *fs_devs) +int btrfs_sysfs_add_devices_dir (struct btrfs_fs_devices *fs_devs) {if (!fs_devs->device_dir_kobj) fs_devs->device_dir_kobj = kobject_create_and_add("devices",
fs/btrfs/sysfs.h +1 -1
@@ -20,7 +20,7 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device);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); +int btrfs_sysfs_add_devices_dir (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);
Signature · 1 line
2.23.0
PATCH 3/15 btrfs: sysfs, rename btrfs_device member device_dir_kobj
In reply to Anand JainThe struct member btrfs_device::device_dir_kobj holds the kobj of the sysfs directory /sys/fs/btrfs/UUID/devices, so rename its holder from device_dir_kobj to devices_dir_kobj. No functional changes.
--- fs/btrfs/sysfs.c | 28 ++++++++++++++-------------- fs/btrfs/volumes.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/btrfs/sysfs.c +14 -14
@@ -744,10 +744,10 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)static void __btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs) { -if (fs_devs->device_dir_kobj) { -kobject_del (fs_devs->device_dir_kobj); -kobject_put (fs_devs->device_dir_kobj); - fs_devs->device_dir_kobj =NULL ; +if (fs_devs->devices_dir_kobj) { +kobject_del (fs_devs->devices_dir_kobj); +kobject_put (fs_devs->devices_dir_kobj); + fs_devs->devices_dir_kobj =NULL ; }if (fs_devs->fsid_kobj.state_initialized) {
@@ -979,15 +979,15 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices,struct hd_struct *disk;struct kobject *disk_kobj; -if (!fs_devices->device_dir_kobj) +if (!fs_devices->devices_dir_kobj)return -EINVAL ;if (one_device && one_device->bdev) { disk = one_device->bdev->bd_part; disk_kobj = &part_to_dev (disk)->kobj; -sysfs_remove_link (fs_devices->device_dir_kobj, - disk_kobj->name); +sysfs_remove_link (fs_devices->devices_dir_kobj, + disk_kobj->name); }if (one_device)
@@ -1000,8 +1000,8 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices, disk = one_device->bdev->bd_part; disk_kobj = &part_to_dev (disk)->kobj; -sysfs_remove_link (fs_devices->device_dir_kobj, - disk_kobj->name); +sysfs_remove_link (fs_devices->devices_dir_kobj, + disk_kobj->name); }return 0 ;
@@ -1009,11 +1009,11 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices,int btrfs_sysfs_add_devices_dir (struct btrfs_fs_devices *fs_devs) { -if (!fs_devs->device_dir_kobj) - fs_devs->device_dir_kobj =kobject_create_and_add ("devices" , - &fs_devs->fsid_kobj); +if (!fs_devs->devices_dir_kobj) + fs_devs->devices_dir_kobj =kobject_create_and_add ("devices" , + &fs_devs->fsid_kobj); -if (!fs_devs->device_dir_kobj) +if (!fs_devs->devices_dir_kobj)return -ENOMEM ;return 0 ;
@@ -1038,7 +1038,7 @@ int btrfs_sysfs_add_device_info(struct btrfs_fs_devices *fs_devices, disk = dev->bdev->bd_part; disk_kobj = &part_to_dev (disk)->kobj; - error =sysfs_create_link (fs_devices->device_dir_kobj, + error =sysfs_create_link (fs_devices->devices_dir_kobj, disk_kobj, disk_kobj->name);if (error)break ;
fs/btrfs/volumes.h +1 -1
@@ -255,7 +255,7 @@ struct btrfs_fs_devices {struct btrfs_fs_info *fs_info;/* sysfs kobjects */ struct kobject fsid_kobj; -struct kobject *device_dir_kobj; +struct kobject *devices_dir_kobj;struct completion kobj_unregister; };
Signature · 1 line
2.23.0
PATCH 4/15 btrfs: sysfs, move declared struct near its use
In reply to Anand JainMove struct btrfs_feature_attr and struct raid_kobject near functions and defines where its used. No functional change.
--- fs/btrfs/sysfs.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fs/btrfs/sysfs.c +12 -12
@@ -19,18 +19,6 @@#include "space-info.h" #include "block-group.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; -}; -#define __INIT_KOBJ_ATTR (_name, _mode, _show, _store) \ { \ .attr = { .name = __stringify(_name), .mode = _mode }, \
@@ -49,6 +37,12 @@ struct raid_kobject {#define BTRFS_ATTR_PTR (_prefix, _name) \ (&btrfs_attr_##_prefix##_##_name.attr) +struct btrfs_feature_attr { +struct kobj_attribute kobj_attr; +enum btrfs_feature_set feature_set; +u64 feature_bit; +}; +#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, \
@@ -394,6 +388,12 @@ static ssize_t global_rsv_reserved_show(struct kobject *kobj, }BTRFS_ATTR (allocation, global_rsv_reserved, global_rsv_reserved_show); +/* For raid type sysfs entries */ +struct raid_kobject { +u64 flags; +struct kobject kobj; +}; +#define to_space_info (_kobj) container_of(_kobj, struct btrfs_space_info, kobj)#define to_raid_kobj (_kobj) container_of(_kobj, struct raid_kobject, kobj)
Signature · 1 line
2.23.0
Re: [PATCH 04/15] btrfs: sysfs, move declared struct near its use
Quoted 2 lines · Anand Jain
Move struct
btrfs_feature_attrand structraid_kobjectnear functions and defines where its used. No functional change.
No, please keep the definitions at the beginning of the file.
PATCH 5/15 btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
In reply to Anand JainNo functional changes. Move functions to bring btrfs_sysfs_remove_fsid() and btrfs_sysfs_add_fsid() and its related functions together.
--- fs/btrfs/sysfs.c | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-)
fs/btrfs/sysfs.c +30 -30
@@ -742,36 +742,6 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)return 0 ; } -static void __btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs) -{ -if (fs_devs->devices_dir_kobj) { -kobject_del (fs_devs->devices_dir_kobj); -kobject_put (fs_devs->devices_dir_kobj); - fs_devs->devices_dir_kobj =NULL ; - } - -if (fs_devs->fsid_kobj.state_initialized) { -kobject_del (&fs_devs->fsid_kobj); -kobject_put (&fs_devs->fsid_kobj); -wait_for_completion (&fs_devs->kobj_unregister); - } -} - -/* when fs_devs is NULL it will remove all fsid kobject */ -void btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs) -{ -struct list_head *fs_uuids =btrfs_get_fs_uuids (); - -if (fs_devs) { -__btrfs_sysfs_remove_fsid (fs_devs); -return ; - } - -list_for_each_entry (fs_devs, fs_uuids, fs_list) { -__btrfs_sysfs_remove_fsid (fs_devs); - } -} -void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) {btrfs_reset_fs_info_ptr (fs_info);
@@ -1076,6 +1046,36 @@ void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,/* /sys/fs/btrfs/ entry */ static struct kset *btrfs_kset; +static void __btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs) +{ +if (fs_devs->devices_dir_kobj) { +kobject_del (fs_devs->devices_dir_kobj); +kobject_put (fs_devs->devices_dir_kobj); + fs_devs->devices_dir_kobj =NULL ; + } + +if (fs_devs->fsid_kobj.state_initialized) { +kobject_del (&fs_devs->fsid_kobj); +kobject_put (&fs_devs->fsid_kobj); +wait_for_completion (&fs_devs->kobj_unregister); + } +} + +/* when fs_devs is NULL it will remove all fsid kobject */ +void btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs) +{ +struct list_head *fs_uuids =btrfs_get_fs_uuids (); + +if (fs_devs) { +__btrfs_sysfs_remove_fsid (fs_devs); +return ; + } + +list_for_each_entry (fs_devs, fs_uuids, fs_list) { +__btrfs_sysfs_remove_fsid (fs_devs); + } +} +/* * Can be called by the device discovery thread. * And parent can be specified for seed device
Signature · 1 line
2.23.0
Re: [PATCH 05/15] btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
Quoted 4 lines · Anand Jain
No functional changes. Move functions to bring
btrfs_sysfs_remove_fsid()andbtrfs_sysfs_add_fsid()and its related functions together.Signed-off-by Anand Jain <[email protected]>
This seems like pointless code motion.
Re: [PATCH 05/15] btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
Quoted 10 lines · Nikolay Borisov
Quoted 4 lines · Anand Jain
No functional changes. Move functions to bring
btrfs_sysfs_remove_fsid()andbtrfs_sysfs_add_fsid()and its related functions together.Signed-off-by Anand Jain <[email protected]>This seems like pointless code motion.
Yeah, unless there's some other reason to move the code, just plain moves are not desired.
Re: [PATCH 05/15] btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
Quoted 7 lines · David Sterba
Quoted 6 lines · Nikolay Borisov
Quoted 3 lines · Anand Jain
No functional changes. Move functions to bring
btrfs_sysfs_remove_fsid()andbtrfs_sysfs_add_fsid()and its related functions together.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Anand Jain <[email protected]>This seems like pointless code motion.
Yeah, unless there's some other reason to move the code, just plain moves are not desired.
The reason was - btrfs_sysfs_add_fsid() and btrfs_sysfs_remove_fsid() are related. Easy to read and verify to have placed them one below other.
Ok not a big deal. I am ok either ways.
Re: [PATCH 05/15] btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
Quoted 7 lines · Anand Jain
Quoted 6 lines · David Sterba
Quoted 5 lines · Nikolay Borisov
Quoted 4 lines · Anand Jain
No functional changes. Move functions to bring
btrfs_sysfs_remove_fsid()andbtrfs_sysfs_add_fsid()and its related functions together.Signed-off-by Anand Jain <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
This seems like pointless code motion.
Yeah, unless there's some other reason to move the code, just plain moves are not desired.
The reason was -
btrfs_sysfs_add_fsid()andbtrfs_sysfs_remove_fsid()are related. Easy to read and verify to have placed them one below other.
I see that add and remove functions are grouped, so this would move someting else away:
btrfs_sysfs_remove_fsid + __btrfs_sysfs_remove_fsid
btrfs_sysfs_add_fsid + btrfs_sysfs_add_mounted
and device related functions are also grouped by the action type, so we can keep it like that.
Re: [PATCH 05/15] btrfs: sysfs, move /sys/fs/btrfs/UUID related functions together
Quoted 17 lines · David Sterba
Quoted 7 lines · Anand Jain
Quoted 6 lines · David Sterba
Quoted 5 lines · Nikolay Borisov
Quoted 4 lines · Anand Jain
No functional changes. Move functions to bring
btrfs_sysfs_remove_fsid()andbtrfs_sysfs_add_fsid()and its related functions together.Signed-off-by Anand Jain <[email protected]>Quoted 8 lines
Quoted 4 lines
Quoted 1 line
This seems like pointless code motion.
Yeah, unless there's some other reason to move the code, just plain moves are not desired.
The reason was -
btrfs_sysfs_add_fsid()andbtrfs_sysfs_remove_fsid()are related. Easy to read and verify to have placed them one below other.
Quoted 6 lines
I see that add and remove functions are grouped, so this would move someting else away:
btrfs_sysfs_remove_fsid+__btrfs_sysfs_remove_fsid
btrfs_sysfs_add_fsid+btrfs_sysfs_add_mounted
Ok.
Quoted 2 lines
and device related functions are also grouped by the action type, so we can keep it like that.
Ok. Grouped by action type.
Thanks, Anand
PATCH 6/15 btrfs: sysfs, move add remove _mounted function together
In reply to Anand JainThe functions btrfs_sysfs_add_mounted() and btrfs_sysfs_remove_mounted() which add and remove files and directory under /sys/fs/btrfs/UUID keep them together to improve readability. No functional changes.
--- fs/btrfs/sysfs.c | 132 +++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 66 deletions(-)
fs/btrfs/sysfs.c +66 -66
@@ -742,21 +742,6 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)return 0 ; } -void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) -{ -btrfs_reset_fs_info_ptr (fs_info); - -if (fs_info->space_info_kobj) { -sysfs_remove_files (fs_info->space_info_kobj, allocation_attrs); -kobject_del (fs_info->space_info_kobj); -kobject_put (fs_info->space_info_kobj); - } -addrm_unknown_feature_attrs (fs_info, false); -sysfs_remove_group (&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); -sysfs_remove_files (&fs_info->fs_devices->fsid_kobj, btrfs_attrs); -btrfs_sysfs_remove_device_info (fs_info->fs_devices,NULL ); -} -static const char *const btrfs_feature_set_names[FEAT_MAX ] = { [FEAT_COMPAT ] ="compat" , [FEAT_COMPAT_RO ] ="compat_ro" ,
@@ -1028,6 +1013,72 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action) &disk_to_dev(bdev->bd_disk)->kobj); } +void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) +{ +btrfs_reset_fs_info_ptr (fs_info); + +if (fs_info->space_info_kobj) { +sysfs_remove_files (fs_info->space_info_kobj, allocation_attrs); +kobject_del (fs_info->space_info_kobj); +kobject_put (fs_info->space_info_kobj); + } +addrm_unknown_feature_attrs (fs_info, false); +sysfs_remove_group (&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); +sysfs_remove_files (&fs_info->fs_devices->fsid_kobj, btrfs_attrs); +btrfs_sysfs_remove_device_info (fs_info->fs_devices,NULL ); +} + +int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info) +{ +int error; +struct btrfs_fs_devices *fs_devs = fs_info->fs_devices; +struct kobject *fsid_kobj = &fs_devs->fsid_kobj; + +btrfs_set_fs_info_ptr (fs_info); + + error =btrfs_sysfs_add_device_info (fs_devs,NULL ); +if (error) +return error; + + error =sysfs_create_files (fsid_kobj, btrfs_attrs); +if (error) { +btrfs_sysfs_remove_device_info (fs_devs,NULL ); +return error; + } + + error =sysfs_create_group (fsid_kobj, + &btrfs_feature_attr_group); +if (error) + goto failure; + +#ifdef CONFIG_BTRFS_DEBUG + error =sysfs_create_group (fsid_kobj, + &btrfs_debug_feature_attr_group); +if (error) + goto failure; +#endif + + error =addrm_unknown_feature_attrs (fs_info, true); +if (error) + goto failure; + + fs_info->space_info_kobj =kobject_create_and_add ("allocation" , + fsid_kobj); +if (!fs_info->space_info_kobj) { + error = -ENOMEM ; + goto failure; + } + + error =sysfs_create_files (fs_info->space_info_kobj, allocation_attrs); +if (error) + goto failure; + +return 0 ; +failure: +btrfs_sysfs_remove_mounted (fs_info); +return error; +} +void btrfs_sysfs_update_sprout_fsid (struct btrfs_fs_devices *fs_devices,const u8 *fsid) {
@@ -1097,57 +1148,6 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,return 0 ; } -int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info) -{ -int error; -struct btrfs_fs_devices *fs_devs = fs_info->fs_devices; -struct kobject *fsid_kobj = &fs_devs->fsid_kobj; - -btrfs_set_fs_info_ptr (fs_info); - - error =btrfs_sysfs_add_device_info (fs_devs,NULL ); -if (error) -return error; - - error =sysfs_create_files (fsid_kobj, btrfs_attrs); -if (error) { -btrfs_sysfs_remove_device_info (fs_devs,NULL ); -return error; - } - - error =sysfs_create_group (fsid_kobj, - &btrfs_feature_attr_group); -if (error) - goto failure; - -#ifdef CONFIG_BTRFS_DEBUG - error =sysfs_create_group (fsid_kobj, - &btrfs_debug_feature_attr_group); -if (error) - goto failure; -#endif - - error =addrm_unknown_feature_attrs (fs_info, true); -if (error) - goto failure; - - fs_info->space_info_kobj =kobject_create_and_add ("allocation" , - fsid_kobj); -if (!fs_info->space_info_kobj) { - error = -ENOMEM ; - goto failure; - } - - error =sysfs_create_files (fs_info->space_info_kobj, allocation_attrs); -if (error) - goto failure; - -return 0 ; -failure: -btrfs_sysfs_remove_mounted (fs_info); -return error; -} -/* * Change per-fs features in /sys/fs/btrfs/UUID/features to match current
Signature · 1 line
2.23.0
PATCH 7/15 btrfs: sysfs, delete code in a comment
In reply to Anand Jaincommit 3ebb2ada (btrfs: sysfs: export supported checksums), added some unwanted commented-code, delete it.
--- fs/btrfs/sysfs.c | 10 ---------- 1 file changed, 10 deletions(-)
fs/btrfs/sysfs.c +0 -10
@@ -255,16 +255,6 @@ BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID);BTRFS_FEAT_ATTR_COMPAT_RO (free_space_tree,FREE_SPACE_TREE );BTRFS_FEAT_ATTR_INCOMPAT (raid1c34,RAID1C34 ); -/* -static struct btrfs_feature_attr btrfs_attr_features_checksums_name = { -.kobj_attr = __INIT_KOBJ_ATTR(supported_checksums, S_IRUGO, -btrfs_supported_checksums_show, -NULL), -.feature_set = FEAT_INCOMPAT, -.feature_bit = 0, -}; -*/ -static struct attribute *btrfs_supported_feature_attrs[] = {BTRFS_FEAT_ATTR_PTR (mixed_backref),BTRFS_FEAT_ATTR_PTR (default_subvol),
Signature · 1 line
2.23.0
Re: [PATCH 07/15] btrfs: sysfs, delete code in a comment
Quoted 15 lines · Anand Jain
commit
3ebb2ada(btrfs: sysfs: export supported checksums), added some unwanted commented-code, delete it.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/sysfs.c | 10 ---------- 1 file changed, 10 deletions(-)fs/btrfs/sysfs.c +0
-0@@ -255,16 +255,6 @@ BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID);BTRFS_FEAT_ATTR_COMPAT_RO (free_space_tree,FREE_SPACE_TREE );BTRFS_FEAT_ATTR_INCOMPAT (raid1c34,RAID1C34 );
fs/btrfs/sysfs.c BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID); · line 266
Quoted 10 lines
fs/btrfs/sysfs.c +0
-9-/* -static struct btrfs_feature_attr btrfs_attr_features_checksums_name = { -.kobj_attr = __INIT_KOBJ_ATTR(supported_checksums, S_IRUGO, -btrfs_supported_checksums_show, -NULL), -.feature_set = FEAT_INCOMPAT, -.feature_bit = 0, -}; -*/
Uh, I'll fold that to the patch that introduced it, thanks for spotting it.
PATCH 8/15 btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
In reply to Anand JainCommit 24bd69cb (Btrfs: sysfs: add support to add parent for fsid) added parent argument in preparation to show the seed fsid under the sprout fsid as in the patch [1] in the mailing list.
[1] Btrfs: sysfs: support seed devices in the sysfs layout
But later this idea was superseded by another idea to rename the fsid as in the commit f93c39970b1d (btrfs: factor out sysfs code for updating sprout fsid).
So we don't need parent argument anymore.
--- fs/btrfs/disk-io.c | 2 +- fs/btrfs/sysfs.c | 11 +++++------ fs/btrfs/sysfs.h | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-)
fs/btrfs/disk-io.c +1 -1
@@ -3082,7 +3082,7 @@ int __cold open_ctree(struct super_block *sb,btrfs_free_extra_devids (fs_devices,1 ); - ret =btrfs_sysfs_add_fsid (fs_devices,NULL ); + ret =btrfs_sysfs_add_fsid (fs_devices);if (ret) {btrfs_err (fs_info,"failed to init sysfs fsid interface: %d" , ret);
fs/btrfs/sysfs.c +5 -6
@@ -1118,18 +1118,17 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) }/* -* Can be called by the device discovery thread. -* And parent can be specified for seed device +* Creates: +* /sys/fs/btrfs/UUID */ -int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs, -struct kobject *parent) +int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs) {int error;init_completion (&fs_devs->kobj_unregister); fs_devs->fsid_kobj.kset = btrfs_kset; - error =kobject_init_and_add (&fs_devs->fsid_kobj, - &btrfs_ktype, parent,"%pU" , fs_devs->fsid); + error =kobject_init_and_add (&fs_devs->fsid_kobj, &btrfs_ktype,NULL , +"%pU" , fs_devs->fsid);if (error) {kobject_put (&fs_devs->fsid_kobj);return error;
fs/btrfs/sysfs.h +1 -2
@@ -18,8 +18,7 @@ int btrfs_sysfs_add_device_info(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device);int btrfs_sysfs_remove_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); -int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs, -struct kobject *parent); +int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs);int btrfs_sysfs_add_devices_dir (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,
Signature · 1 line
2.23.0
PATCH 9/15 btrfs: sysfs, merge btrfs_sysfs_add device_dir and fsid
In reply to Anand JainMerge btrfs_sysfs_add_fsid() and btrfs_sysfs_add_devices_dir() functions these two are small and they are called one after the other.
--- fs/btrfs/disk-io.c | 7 ------- fs/btrfs/sysfs.c | 22 +++++++++------------- fs/btrfs/sysfs.h | 1 - 3 files changed, 9 insertions(+), 21 deletions(-)
fs/btrfs/disk-io.c +0 -7
@@ -3089,13 +3089,6 @@ int __cold open_ctree(struct super_block *sb, goto fail_block_groups; } - ret =btrfs_sysfs_add_devices_dir (fs_devices); -if (ret) { -btrfs_err (fs_info,"failed to init sysfs device interface: %d" , - ret); - goto fail_fsdev_sysfs; - } - ret =btrfs_sysfs_add_mounted (fs_info);if (ret) {btrfs_err (fs_info,"failed to init sysfs interface: %d" , ret);
fs/btrfs/sysfs.c +9 -13
@@ -952,18 +952,6 @@ int btrfs_sysfs_remove_device_info(struct btrfs_fs_devices *fs_devices,return 0 ; } -int btrfs_sysfs_add_devices_dir (struct btrfs_fs_devices *fs_devs) -{ -if (!fs_devs->devices_dir_kobj) - fs_devs->devices_dir_kobj =kobject_create_and_add ("devices" , - &fs_devs->fsid_kobj); - -if (!fs_devs->devices_dir_kobj) -return -ENOMEM ; - -return 0 ; -} -int btrfs_sysfs_add_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device) {
@@ -1134,10 +1122,18 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs)return error; } + fs_devs->devices_dir_kobj =kobject_create_and_add ("devices" , + &fs_devs->fsid_kobj); +if (!fs_devs->devices_dir_kobj) { +btrfs_err (fs_devs->fs_info, +"failed to init sysfs device interface" ); +kobject_put (&fs_devs->fsid_kobj); +return -ENOMEM ; + } +return 0 ; } -/* * Change per-fs features in /sys/fs/btrfs/UUID/features to match current * values in superblock. Call after any changes to incompat/compat_ro flags
fs/btrfs/sysfs.h +0 -1
@@ -19,7 +19,6 @@ int btrfs_sysfs_add_device_info(struct btrfs_fs_devices *fs_devices,int btrfs_sysfs_remove_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device);int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs); -int btrfs_sysfs_add_devices_dir (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);
Signature · 1 line
2.23.0
PATCH 10/15 btrfs: volume, btrfs_free_stale_devices() cleanup unreachable code
In reply to Anand Jainfs_devices::num_devices can be zero only in unmounted context, and we don't have any fsid specific kobjects in the unmoutend context. So no need to call btrfs_sysfs_remove_fsid() in btrfs_free_stale_devices().
---
We implemented this in preparation to provide the fsid/device attributes for the devices in unmoutned context as was proposed here [1].
[1] [PATCH] btrfs: Introduce device pool sysfs attributes
fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/volumes.c +1 -1
@@ -585,7 +585,7 @@ static int btrfs_free_stale_devices(const char *path,mutex_unlock (&fs_devices->device_list_mutex);if (fs_devices->num_devices ==0 ) { -btrfs_sysfs_remove_fsid (fs_devices); +/* If its here fsid is unmounted */ list_del (&fs_devices->fs_list);free_fs_devices (fs_devices); }
Signature · 1 line
2.23.0
PATCH 11/15 btrfs: sysfs, migrate fs_decvices::fsid_kobject to struct btrfs_fs_info
In reply to Anand JainIn an idea that at some point we would have to create sysfs kobjects to show the scanned devices, so we tried to maintain the fsid_kobject in the struct btrfs_fs_devices instead of in the struct btrfs_fs_info. Its been without it for a long time and if it has to be done at some point it can be done using ioctl as well. For now cleanup sysfs and migrate the top most kobject in the mounted context to btrfs_fs_info.
---
PS: There are patches in the ML [1], which shows scanned devices in the sysfs, if at all need there is a choice of doing the same using ioctl as well. So that we dont' have to stress already overloaded sysfs.
[1] [PATCH] btrfs: Introduce device pool sysfs attributes
fs/btrfs/ctree.h | 2 + fs/btrfs/disk-io.c | 8 ++-- fs/btrfs/sysfs.c | 94 ++++++++++++++++++++++------------------------ fs/btrfs/sysfs.h | 4 +- fs/btrfs/volumes.h | 3 +- 5 files changed, 54 insertions(+), 57 deletions(-)
fs/btrfs/ctree.h +2 -0
@@ -739,6 +739,8 @@ struct btrfs_fs_info {struct task_struct *cleaner_kthread;u32 thread_pool_size; +/* sysfs kobjects */ +struct kobject fsid_kobj;struct kobject *space_info_kobj;u64 total_pinned;
fs/btrfs/disk-io.c +4 -4
@@ -3082,10 +3082,10 @@ int __cold open_ctree(struct super_block *sb,btrfs_free_extra_devids (fs_devices,1 ); - ret =btrfs_sysfs_add_fsid (fs_devices); + ret =btrfs_sysfs_add_fsid (fs_info);if (ret) {btrfs_err (fs_info,"failed to init sysfs fsid interface: %d" , - ret); + ret); goto fail_block_groups; }
@@ -3308,7 +3308,7 @@ int __cold open_ctree(struct super_block *sb,btrfs_sysfs_remove_mounted (fs_info); fail_fsdev_sysfs: -btrfs_sysfs_remove_fsid (fs_info->fs_devices); +btrfs_sysfs_remove_fsid (fs_info); fail_block_groups:btrfs_put_block_group_cache (fs_info);
@@ -4006,7 +4006,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) percpu_counter_sum(&fs_info->dio_bytes));btrfs_sysfs_remove_mounted (fs_info); -btrfs_sysfs_remove_fsid (fs_info->fs_devices); +btrfs_sysfs_remove_fsid (fs_info);btrfs_free_fs_roots (fs_info);
fs/btrfs/sysfs.c +45 -49
188 lines not on this page · raw message
fs/btrfs/sysfs.h +2 -2
@@ -18,8 +18,8 @@ int btrfs_sysfs_add_device_info(struct btrfs_fs_devices *fs_devices, struct btrfs_device *one_device);int btrfs_sysfs_remove_device_info (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device); -int btrfs_sysfs_add_fsid (struct btrfs_fs_devices *fs_devs); -void btrfs_sysfs_remove_fsid (struct btrfs_fs_devices *fs_devs); +int btrfs_sysfs_add_fsid (struct btrfs_fs_info *fs_info); +void btrfs_sysfs_remove_fsid (struct btrfs_fs_info *fs_info);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,
fs/btrfs/volumes.h +1 -2
@@ -254,9 +254,8 @@ struct btrfs_fs_devices {struct btrfs_fs_info *fs_info;/* sysfs kobjects */ -struct kobject fsid_kobj; -struct kobject *devices_dir_kobj;struct completion kobj_unregister; +struct kobject *devices_dir_kobj; };#define BTRFS_BIO_INLINE_CSUM_SIZE 64
Signature · 1 line
2.23.0
PATCH 12/15 btrfs: sysfs, unexport btrfs_sysfs_add_mounted()
In reply to Anand JainIn open_ctree() we call btrfs_sysfs_add_fsid() to create /sys/fs/btrfs/UUID kobject, and in the following line of code in open_ctree() we call btrfs_sysfs_add_mounted() to create its attributes. And there is no other users of btrfs_sysfs_add_mounted(). So let btrfs_sysfs_add_fsid() also create its attributes and make btrfs_sysfs_add_mounted() a local static function.
--- fs/btrfs/disk-io.c | 8 -------- fs/btrfs/sysfs.c | 9 ++++++++- fs/btrfs/sysfs.h | 1 - 3 files changed, 8 insertions(+), 10 deletions(-)
fs/btrfs/disk-io.c +0 -8
@@ -3089,12 +3089,6 @@ int __cold open_ctree(struct super_block *sb, goto fail_block_groups; } - ret =btrfs_sysfs_add_mounted (fs_info); -if (ret) { -btrfs_err (fs_info,"failed to init sysfs interface: %d" , ret); - goto fail_fsdev_sysfs; - } - ret =btrfs_init_space_info (fs_info);if (ret) {btrfs_err (fs_info,"failed to initialize space info: %d" , ret);
@@ -3306,8 +3300,6 @@ int __cold open_ctree(struct super_block *sb, fail_sysfs:btrfs_sysfs_remove_mounted (fs_info); - -fail_fsdev_sysfs:btrfs_sysfs_remove_fsid (fs_info); fail_block_groups:
fs/btrfs/sysfs.c +8 -1
@@ -998,7 +998,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)btrfs_sysfs_remove_device_info (fs_info->fs_devices,NULL ); } -int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info) +static int btrfs_sysfs_add_mounted (struct btrfs_fs_info *fs_info) {int error;struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
@@ -1129,6 +1129,13 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_info *fs_info)return -ENOMEM ; } + error =btrfs_sysfs_add_mounted (fs_info); +if (error) { +btrfs_err (fs_info,"failed to init sysfs interface: %d" , error); +btrfs_sysfs_remove_fsid (fs_info); +return error; + } +return 0 ; }
fs/btrfs/sysfs.h +0 -1
@@ -28,7 +28,6 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)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_sysfs_add_block_group_type (struct btrfs_block_group *cache); int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.23.0
PATCH 13/15 btrfs: sysfs, cleanup btrfs_sysfs_remove_fsid()
In reply to Anand Jainbtrfs_sysfs_remove_fsid() when called with NULL argument then it shall cleanup all kobjects belonging to btrfs. However no function is using btrfs_sysfs_remove_fsid() with NULL argument.
This happened in the commit 2e3e1281 (Btrfs: sysfs: provide framework to remove all fsid sysfs kobject) which is a helper commit to the proposed patch [1], which proposed to show /sys/fs/btrfs/UUID in the unmounted but scanned context as well, so that there is a way to know fsid and devices which are scanned. As of now there isn't anyway that the user/script can figure out all the scanned fsids/devices in the system, but its been long time, probably there isn't such a need at all. For developers to debug the struct fs_devices list there is procfs boiler-plate patch in the mailing list which comes handy.
[1] [PATCH] btrfs: Introduce device pool sysfs attributes
--- fs/btrfs/sysfs.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
fs/btrfs/sysfs.c +1 -12
@@ -1087,20 +1087,9 @@ static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info) } } -/* when fs_info is NULL it will remove all fs_info::fsid kobject */ void btrfs_sysfs_remove_fsid (struct btrfs_fs_info *fs_info) { -struct list_head *fs_uuids =btrfs_get_fs_uuids (); -struct btrfs_fs_devices *fs_devices; - -if (fs_info) { -__btrfs_sysfs_remove_fsid (fs_info); -return ; - } - -list_for_each_entry (fs_devices, fs_uuids, fs_list) { -__btrfs_sysfs_remove_fsid (fs_devices->fs_info); - } +__btrfs_sysfs_remove_fsid (fs_info); }/*
Signature · 1 line
2.23.0
PATCH 14/15 btrfs: sysfs, merge btrfs_sysfs_remove_fsid() helper function
In reply to Anand JainMerge __btrfs_sysfs_remove_fsid() into its only caller btrfs_sysfs_remove_fsid().
--- fs/btrfs/sysfs.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
fs/btrfs/sysfs.c +1 -6
@@ -1070,7 +1070,7 @@ static struct kset *btrfs_kset;/* * Remove /sys/fs/btrfs/UUID/devices and /sysfs/btrfs/UUID */ -static void __btrfs_sysfs_remove_fsid (struct btrfs_fs_info *fs_info) +void btrfs_sysfs_remove_fsid (struct btrfs_fs_info *fs_info) {struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
@@ -1087,11 +1087,6 @@ static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info) } } -void btrfs_sysfs_remove_fsid (struct btrfs_fs_info *fs_info) -{ -__btrfs_sysfs_remove_fsid (fs_info); -} -/* * Creates: * /sys/fs/btrfs/UUID
Signature · 1 line
2.23.0
PATCH 15/15 btrfs: sysfs, unexport btrfs_sysfs_remove_mounted()
In reply to Anand Jainbtrfs_sysfs_remove_mounted() is always called along with btrfs_sysfs_remove_fsid(), call btrfs_sysfs_remove_mounted() in btrfs_sysfs_remove_fsid() as well. And unexport btrfs_sysfs_remove_mounted().
--- fs/btrfs/disk-io.c | 2 -- fs/btrfs/sysfs.c | 4 +++- fs/btrfs/sysfs.h | 1 - 3 files changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +0 -2
@@ -3299,7 +3299,6 @@ int __cold open_ctree(struct super_block *sb,filemap_write_and_wait (fs_info->btree_inode->i_mapping); fail_sysfs: -btrfs_sysfs_remove_mounted (fs_info);btrfs_sysfs_remove_fsid (fs_info); fail_block_groups:
@@ -3997,7 +3996,6 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)btrfs_info (fs_info,"at unmount dio bytes count %lld" ,percpu_counter_sum (&fs_info->dio_bytes)); -btrfs_sysfs_remove_mounted (fs_info);btrfs_sysfs_remove_fsid (fs_info);btrfs_free_fs_roots (fs_info);
fs/btrfs/sysfs.c +3 -1
@@ -983,7 +983,7 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action) &disk_to_dev(bdev->bd_disk)->kobj); } -void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) +static void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) {btrfs_reset_fs_info_ptr (fs_info);
@@ -1074,6 +1074,8 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info) {struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; +btrfs_sysfs_remove_mounted (fs_info); +if (fs_devices->devices_dir_kobj) {kobject_del (fs_devices->devices_dir_kobj);kobject_put (fs_devices->devices_dir_kobj);
fs/btrfs/sysfs.h +0 -1
@@ -28,7 +28,6 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)int __init btrfs_init_sysfs (void );void __cold btrfs_exit_sysfs (void ); -void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info);void btrfs_sysfs_add_block_group_type (struct btrfs_block_group *cache);int btrfs_sysfs_add_space_info_type (struct btrfs_fs_info *fs_info,struct btrfs_space_info *space_info);
Signature · 1 line
2.23.0
Quoted 5 lines · Anand Jain
Mostly cleanups patches.
Patches 1-7 are renames, code moves patches and there are no functional changes.
Quoted 7 lines
Patch 8 drops unused argument in the function
btrfs_sysfs_add_fsid(). Patch 9 merges two small functions which is an extension of the other.Patches 10,11 and 13 removes unnecessary features in the functions, originally it was planned to provide sysfs attributes for the scanned and unmounted devices, as in the un-merged patch in the mailing list [1]
[1] [PATCH] btrfs: Introduce device pool sysfs attributes
We want something like that, I don't recall all the past discussions, but a separate directory for all the new sysfs files should be introduced. Extending the existing /devices/ that contains just the sysfs device like should stay as is.
/sys/fs/btrfs/UUID/
devinfo/ 1/ uuid state ... 2/ ...
Quoted 9 lines · David Sterba
Quoted 8 lines · Anand Jain
Mostly cleanups patches.
Patches 1-7 are renames, code moves patches and there are no functional changes.
Patch 8 drops unused argument in the function
btrfs_sysfs_add_fsid(). Patch 9 merges two small functions which is an extension of the other.
Quoted 6 lines
Quoted 4 lines
Patches 10,11 and 13 removes unnecessary features in the functions, originally it was planned to provide sysfs attributes for the scanned and unmounted devices, as in the un-merged patch in the mailing list [1]
[1] [PATCH] btrfs: Introduce device pool sysfs attributesWe want something like that,
Oh.
Ok then I shall relook at these patches with a mind that we might introduce the sysfs for non mounted devices.
Quoted 1 line
I don't recall all the past discussions,
No worries. There wasn't any discussions on this specific topic.
Quoted 4 lines
but a separate directory for all the new sysfs files should be introduced. Extending the existing /devices/ that contains just the sysfs device like should stay as is.
Quoted 9 lines
/sys/fs/btrfs/UUID/devinfo/ 1/ uuid state ... 2/ ...
umm how about..
$ btrfs fi show Label: none uuid: 52ad6beb-524d-4cd8-8979-0890d0b74314 Total devices 4 FS bytes used 384.00KiB devid 1 size 2.93GiB used 368.00MiB path /dev/sdb devid 2 size 2.93GiB used 368.00MiB path /dev/sdc devid 3 size 2.93GiB used 368.00MiB path /dev/sdd devid 4 size 2.93GiB used 368.00MiB path /dev/sde
# ls -l /sys/fs/btrfs/52ad6beb-524d-4cd8-8979-0890d0b74314/devices/ total 0 drwxr-xr-x 2 root root 0 Nov 19 14:39 1_sdb drwxr-xr-x 2 root root 0 Nov 19 14:39 2_sdc drwxr-xr-x 2 root root 0 Nov 19 14:39 3_sdd drwxr-xr-x 2 root root 0 Nov 19 14:39 4_sde lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdb -> ../../../../devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdc -> ../../../../devices/pci0000:00/0000:00:0d.0/ata3/host2/target2:0:0/2:0:0:0/block/sdc lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdd -> ../../../../devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdd lrwxrwxrwx 1 root root 0 Nov 19 14:39 sde -> ../../../../devices/pci0000:00/0000:00:0d.0/ata5/host4/target4:0:0/4:0:0:0/block/sde
# cd /sys/fs/btrfs/52ad6beb-524d-4cd8-8979-0890d0b74314/devices/1_sdb # ls -l dev_state
(Currently its been coded to support only dev_state (patches under tests with me)).
Thanks, Anand
Quoted 19 lines · Anand Jain
Quoted 9 lines · David Sterba
Quoted 8 lines · Anand Jain
Mostly cleanups patches.
Patches 1-7 are renames, code moves patches and there are no functional changes.
Patch 8 drops unused argument in the function
btrfs_sysfs_add_fsid(). Patch 9 merges two small functions which is an extension of the other.Quoted 6 lines
Quoted 4 lines
Patches 10,11 and 13 removes unnecessary features in the functions, originally it was planned to provide sysfs attributes for the scanned and unmounted devices, as in the un-merged patch in the mailing list [1]
[1] [PATCH] btrfs: Introduce device pool sysfs attributesWe want something like that,
Quoted 8 lines
Oh.
Ok then I shall relook at these patches with a mind that we might introduce the sysfs for non mounted devices.
Quoted 1 line
I don't recall all the past discussions,
No worries. There wasn't any discussions on this specific topic.
There were several patchsets sent adding device information exports, and commented, eg.
https://lore.kernel.org/linux-btrfs/[email protected]/t/#u
https://lore.kernel.org/linux-btrfs/[email protected]/t/#u
and maybe followups.
Quoted 26 lines
Quoted 5 lines
but a separate directory for all the new sysfs files should be introduced. Extending the existing /devices/ that contains just the sysfs device like should stay as is.
Quoted 9 lines
/sys/fs/btrfs/UUID/devinfo/ 1/ uuid state ... 2/ ...umm how about..
$ btrfs fi show Label: none uuid: 52ad6beb-524d-4cd8-8979-0890d0b74314 Total devices 4 FS bytes used 384.00KiB devid 1 size 2.93GiB used 368.00MiB path /dev/sdb devid 2 size 2.93GiB used 368.00MiB path /dev/sdc devid 3 size 2.93GiB used 368.00MiB path /dev/sdd devid 4 size 2.93GiB used 368.00MiB path /dev/sde
Quoted 3 lines
# ls -l /sys/fs/btrfs/52ad6beb-524d-4cd8-8979-0890d0b74314/devices/ total 0 drwxr-xr-x 2 root root 0 Nov 19 14:39 1_sdb
Something like that has been suggested in the patchsets, I disagree with the device id and name being glued together. The sysfs files should server scripting, the enumeration should be straightforward and not requiring parsing of the filenames.
Quoted 11 lines
drwxr-xr-x 2 root root 0 Nov 19 14:39 2_sdc
drwxr-xr-x 2 root root 0 Nov 19 14:39 3_sdd
drwxr-xr-x 2 root root 0 Nov 19 14:39 4_sde
lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdb -> ../../../../devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdc -> ../../../../devices/pci0000:00/0000:00:0d.0/ata3/host2/target2:0:0/2:0:0:0/block/sdc lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdd -> ../../../../devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdd lrwxrwxrwx 1 root root 0 Nov 19 14:39 sde -> ../../../../devices/pci0000:00/0000:00:0d.0/ata5/host4/target4:0:0/4:0:0:0/block/sde
If you want to put the directories under /sys/fs/btrfs/UUID/deevices/ then it's probably ok as long as there device node links are plain files and the directories represent the ids. But just the ids, the actual device name depends on the assignment by block layer. This is not persistent.
So two possible layouts:
fs/UUID/devices
sda sdb sdc 1/ ... 2/ ... 3/ ...
Or the one suggested before, where devices by id are in a separate directory. This is modelled after /dev/disk/by-id and the like, but I don't think we need to make it granular like that.
Quoted 29 lines · David Sterba
Quoted 19 lines · Anand Jain
Quoted 9 lines · David Sterba
Quoted 8 lines · Anand Jain
Mostly cleanups patches.
Patches 1-7 are renames, code moves patches and there are no functional changes.
Patch 8 drops unused argument in the function
btrfs_sysfs_add_fsid(). Patch 9 merges two small functions which is an extension of the other.Quoted 6 lines
Quoted 4 lines
Patches 10,11 and 13 removes unnecessary features in the functions, originally it was planned to provide sysfs attributes for the scanned and unmounted devices, as in the un-merged patch in the mailing list [1]
[1] [PATCH] btrfs: Introduce device pool sysfs attributesWe want something like that,
Quoted 8 lines
Oh.
Ok then I shall relook at these patches with a mind that we might introduce the sysfs for non mounted devices.
Quoted 1 line
I don't recall all the past discussions,
No worries. There wasn't any discussions on this specific topic.
Quoted 8 lines
There were several patchsets sent adding device information exports, and commented, eg.
https://lore.kernel.org/linux-btrfs/[email protected]/t/#u
https://lore.kernel.org/linux-btrfs/[email protected]/t/#uand maybe followups.
Ah I missed those reply as I checked the much later patch.
https://lore.kernel.org/linux-btrfs/[email protected]/
Quoted 26 lines
Quoted 26 lines
Quoted 5 lines
but a separate directory for all the new sysfs files should be introduced. Extending the existing /devices/ that contains just the sysfs device like should stay as is.
Quoted 9 lines
/sys/fs/btrfs/UUID/devinfo/ 1/ uuid state ... 2/ ...umm how about..
$ btrfs fi show Label: none uuid: 52ad6beb-524d-4cd8-8979-0890d0b74314 Total devices 4 FS bytes used 384.00KiB devid 1 size 2.93GiB used 368.00MiB path /dev/sdb devid 2 size 2.93GiB used 368.00MiB path /dev/sdc devid 3 size 2.93GiB used 368.00MiB path /dev/sdd devid 4 size 2.93GiB used 368.00MiB path /dev/sde
Quoted 9 lines
Quoted 3 lines
# ls -l /sys/fs/btrfs/52ad6beb-524d-4cd8-8979-0890d0b74314/devices/ total 0 drwxr-xr-x 2 root root 0 Nov 19 14:39 1_sdbSomething like that has been suggested in the patchsets, I disagree with the device id and name being glued together. The sysfs files should server scripting, the enumeration should be straightforward and not requiring parsing of the filenames.
Oh right point.
Quoted 21 lines
Quoted 11 lines
drwxr-xr-x 2 root root 0 Nov 19 14:39 2_sdc
drwxr-xr-x 2 root root 0 Nov 19 14:39 3_sdd
drwxr-xr-x 2 root root 0 Nov 19 14:39 4_sde
lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdb -> ../../../../devices/pci0000:00/0000:00:0d.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdc -> ../../../../devices/pci0000:00/0000:00:0d.0/ata3/host2/target2:0:0/2:0:0:0/block/sdc lrwxrwxrwx 1 root root 0 Nov 19 14:39 sdd -> ../../../../devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdd lrwxrwxrwx 1 root root 0 Nov 19 14:39 sde -> ../../../../devices/pci0000:00/0000:00:0d.0/ata5/host4/target4:0:0/4:0:0:0/block/sdeIf you want to put the directories under
/sys/fs/btrfs/UUID/deevices/then it's probably ok as long as there device node links are plain files and the directories represent the ids. But just the ids, the actual device name depends on the assignment by block layer. This is not persistent.So two possible layouts:
fs/UUID/devices
Quoted 9 lines
sda sdb sdc 1/ ... 2/ ... 3/ ...
Will use this layout.
Thanks, Anand
Quoted 4 lines
Or the one suggested before, where devices by id are in a separate directory. This is modelled after
/dev/disk/by-idand the like, but I don't think we need to make it granular like that.