btrfs, sysfs cleanup and add dev_state
PATCH RESEND v5 4/4 btrfs, sysfs cleanup and add dev_state
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory patches (1,2,3)/4. So I am resending those 3 patches. And the changes in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch 4/4 has the details of the changes.
Patch 1/4 is a cleanup patch.
Patch 2/4 adds the kobject devinfo which is a preparatory to patch 4/4. Patch 3/4 was sent before, no functional changes, change log is updated. Patch 4/4 creates the attribute dev_state.
Anand Jain (4):
btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
btrfs: sysfs, add UUID/devinfo kobject
btrfs: sysfs, rename device_link add,remove functions
btrfs: sysfs, add devid/dev_state kobject and device attribute
fs/btrfs/dev-replace.c | 4 +- fs/btrfs/sysfs.c | 156 +++++++++++++++++++++++++++++++++++++++---------- fs/btrfs/sysfs.h | 4 +- fs/btrfs/volumes.c | 8 +-- fs/btrfs/volumes.h | 3 + 5 files changed, 137 insertions(+), 38 deletions(-)
Signature · 1 line
1.8.3.1
PATCH RESEND 1/4 btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
We have one simple function btrfs_sysfs_remove_fsid() to cleanup kobjects added by btrfs_sysfs_add_fsid() and calls kobject_put() and kobject_delete() only if the kobject is initialized or not null. So use this function while retreating in the function btrfs_sysfs_add_fsid().
One difference though, earlier we did not call kobject_del() during retreat in btrfs_sysfs_add_fsid() and I did experiment to figureout if that's an error or warning, however I didn't notice any such issues with or without kobject_del() not being called.
So this patch is just for cleanup.
--- fs/btrfs/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/sysfs.c +1 -1
@@ -1256,7 +1256,7 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs)if (!fs_devs->devices_kobj) {btrfs_err (fs_devs->fs_info,"failed to init sysfs device interface" ); -kobject_put (&fs_devs->fsid_kobj); +btrfs_sysfs_remove_fsid (fs_devs);return -ENOMEM ; }
Signature · 1 line
2.23.0
PATCH RESEND 2/4 btrfs: sysfs, add UUID/devinfo kobject
In reply to Anand JainPreparatory patch creates kobject /sys/fs/btrfs/UUID/devinfo to hold btrfs_fs_devices::dev_state attribute.
This is being added in the mount context, that means we don't see UUID/devinfo before the mount (yet).
--- fs/btrfs/sysfs.c | 15 +++++++++++++++ fs/btrfs/volumes.h | 1 + 2 files changed, 16 insertions(+)
fs/btrfs/sysfs.c +15 -0
@@ -901,6 +901,12 @@ 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->devinfo_kobj) { +kobject_del (fs_devs->devinfo_kobj); +kobject_put (fs_devs->devinfo_kobj); + fs_devs->devinfo_kobj =NULL ; + } +if (fs_devs->devices_kobj) {kobject_del (fs_devs->devices_kobj);kobject_put (fs_devs->devices_kobj);
@@ -1260,6 +1266,15 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs)return -ENOMEM ; } + fs_devs->devinfo_kobj =kobject_create_and_add ("devinfo" , + &fs_devs->fsid_kobj); +if (!fs_devs->devinfo_kobj) { +btrfs_err (fs_devs->fs_info, +"failed to init sysfs devinfo kobject" ); +btrfs_sysfs_remove_fsid (fs_devs); +return -ENOMEM ; + } +return 0 ; }
fs/btrfs/volumes.h +1 -0
@@ -254,6 +254,7 @@ struct btrfs_fs_devices {/* sysfs kobjects */ struct kobject fsid_kobj;struct kobject *devices_kobj; +struct kobject *devinfo_kobj;struct completion kobj_unregister; };
Signature · 1 line
2.23.0
PATCH RESEND v2 3/4 btrfs: sysfs, rename device_link add,remove functions
In reply to Anand JainIn preparation to add btrfs_device::dev_state attribute in
/sys/fs/btrfs/UUID/devinfo
Rename btrfs_sysfs_add_device_link() and btrfs_sysfs_rm_device_link() to btrfs_sysfs_add_devices_attr() and btrfs_sysfs_remove_devices_attr() as these functions is going to create device attribute rather than just the link to the disk. No functional changes.
---
v2: Update change log. Change ..UUID/devices to ..UUID/devinfo
fs/btrfs/dev-replace.c | 4 ++-- fs/btrfs/sysfs.c | 12 ++++++------ fs/btrfs/sysfs.h | 4 ++-- fs/btrfs/volumes.c | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-)
fs/btrfs/dev-replace.c +2 -2
@@ -512,7 +512,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_devices_attr (tgt_device->fs_devices, tgt_device);if (ret)btrfs_err (fs_info,"kobj add dev failed %d" , ret);
@@ -743,7 +743,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_devices_attr (fs_info->fs_devices, src_device);btrfs_rm_dev_replace_free_srcdev (src_device);/* write back the superblocks */
fs/btrfs/sysfs.c +6 -6
@@ -960,7 +960,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_devices_attr (fs_info->fs_devices,NULL ); }static const char *const btrfs_feature_set_names[FEAT_MAX ] = {
@@ -1149,7 +1149,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_devices_attr (struct btrfs_fs_devices *fs_devices,struct btrfs_device *one_device) {struct hd_struct *disk;
@@ -1181,8 +1181,8 @@ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,return 0 ; } -int btrfs_sysfs_add_device_link (struct btrfs_fs_devices *fs_devices, -struct btrfs_device *one_device) +int btrfs_sysfs_add_devices_attr (struct btrfs_fs_devices *fs_devices, +struct btrfs_device *one_device) {int error =0 ;struct btrfs_device *dev;
@@ -1286,13 +1286,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_devices_attr (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_devices_attr (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_devices_attr (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_devices_attr (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);
fs/btrfs/volumes.c +4 -4
@@ -2054,7 +2054,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_devices_attr (fs_devices, device); } num_devices =btrfs_super_num_devices (fs_info->super_copy) -1 ;
@@ -2174,7 +2174,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)mutex_lock (&fs_devices->device_list_mutex); -btrfs_sysfs_rm_device_link (fs_devices, tgtdev); +btrfs_sysfs_remove_devices_attr (fs_devices, tgtdev);if (tgtdev->bdev) fs_devices->open_devices--;
@@ -2522,7 +2522,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_devices_attr (fs_devices, device);/* * we've got more storage, clear any full flags on the space
@@ -2590,7 +2590,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_devices_attr (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 v5 4/4 btrfs: sysfs, add devid/dev_state kobject and device attribute
In reply to Anand JainNew sysfs attributes that track the filesystem status of devices, stored in the per-filesystem directory in /sys/fs/btrfs/FSID/devinfo . There's a directory for each device, with name corresponding to the numerical device id.
in_fs_metadata - device is in the list of fs metadata missing - device is missing (no device node or block device) replace_target - device is target of replace writeable - writes from fs are allowed
These attributes reflect the state of the device::dev_state and created at mount time.
Sample output:
$ pwd
/sys/fs/btrfs/6e1961f1-5918-4ecc-a22f-948897b409f7/devinfo/1/
$ ls
in_fs_metadata missing replace_target writeable
$ cat missing
0The output from these attributes are 0 or 1. 0 indicates unset and 1 indicates set. These attributes are readonly.
It is observed that the device delete thread and sysfs read thread will not race because the delete thread calls sysfs kobject_put() which in turn waits for existing sysfs read to complete.
Note for device replace devid swap:
During the replace the target device temporarily assumes devid 0 before assigning the devid of the soruce device.
In btrfs_dev_replace_finishing() we remove source sysfs devid using the function btrfs_sysfs_remove_devices_attr(), so after that call kobject_rename() to update the devid in the sysfs. This adds and calls btrfs_sysfs_update_devid() helper function to update the device id.
---
v5: squash [PATCH] btrfs: update devid after replace
import changes as in misc-next
changelog
rename btrfs_sysfs_xx to btrfs_devinfo_xx
reorder devinfo attributes
relocate btrfs_sysfs_update_devid with in sysfs.c add device in the title
rename btrfs_sysfs_missing_show to btrfs_devinfo_missing_show
v4:
after patch
[PATCH v5 2/2] btrfs: reset device back to allocation state when removing in misc-next, the device::devid_kobj remains stale, fix it by using release.
v3:
Use optional groupid devid in BTRFS_ATTR(), it was blank in v2.
V2:
Make the devinfo attribute to carry one parameter, so now instead of dev_state attribute, we create in_fs_metadata, writeable, missing and replace_target attributes.
--- fs/btrfs/dev-replace.c | 1 + fs/btrfs/sysfs.c | 155 +++++++++++++++++++++++++++++++++++------ fs/btrfs/sysfs.h | 1 + fs/btrfs/volumes.h | 4 ++ 4 files changed, 138 insertions(+), 23 deletions(-)
fs/btrfs/dev-replace.c +1 -0
@@ -744,6 +744,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,/* replace the sysfs entry */ btrfs_sysfs_remove_devices_attr (fs_info->fs_devices, src_device); +btrfs_sysfs_update_devid (tgt_device);btrfs_rm_dev_replace_free_srcdev (src_device);/* write back the superblocks */
fs/btrfs/sysfs.c +132 -23
189 lines not on this page · raw message
fs/btrfs/sysfs.h +1 -0
@@ -34,5 +34,6 @@ 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);void btrfs_sysfs_remove_space_info (struct btrfs_space_info *space_info); +void btrfs_sysfs_update_devid (struct btrfs_device *device);#endif
fs/btrfs/volumes.h +4 -0
@@ -136,6 +136,10 @@ struct btrfs_device {atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX ];struct extent_io_tree alloc_state; + +struct completion kobj_unregister; +/* For sysfs/FSID/devinfo/devid/ */ +struct kobject devid_kobj; };/*
Signature · 1 line
2.23.0
Quoted 5 lines · Anand Jain
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory patches (1,2,3)/4. So I am resending those 3 patches. And the changes in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch 4/4 has the details of the changes.
All the patches have been merged and now are in linus/master branch. I haven't reordered the patches so they're not in a group and the preparatory patches are about 10 commits above v5.5-rc7 which is the beginning of the branch.
Quoted 8 lines · David Sterba
Quoted 5 lines · Anand Jain
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory patches (1,2,3)/4. So I am resending those 3 patches. And the changes in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch 4/4 has the details of the changes.All the patches have been merged and now are in linus/master branch.
David,
Quoted 3 lines
I haven't reordered the patches so they're not in a group and the preparatory patches are about 10 commits above v5.5-rc7 which is the beginning of the branch.
It will cause problem during bisect, without the preparatory patches the devid kobject lands under devices instead of under devinfo, that's how I noticed that preparatory patches are missing.
Thanks, Anand
Quoted 15 lines · Anand Jain
Quoted 8 lines · David Sterba
Quoted 5 lines · Anand Jain
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory patches (1,2,3)/4. So I am resending those 3 patches. And the changes in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch 4/4 has the details of the changes.All the patches have been merged and now are in linus/master branch.
David,
Quoted 8 lines
Quoted 3 lines
I haven't reordered the patches so they're not in a group and the preparatory patches are about 10 commits above v5.5-rc7 which is the beginning of the branch.
It will cause problem during bisect, without the preparatory patches the devid kobject lands under devices instead of under devinfo, that's how I noticed that preparatory patches are missing.
I've tested current master and the device ids are indeed placed under device/ and there is no devinfo/, so this needs to be fixed.
Preparatory patches I was referring to are:
bc036bb33524 btrfs: sysfs, merge btrfs_sysfs_add devices_kobj and fsid be2cf92e0a2f btrfs: sysfs, rename btrfs_sysfs_add_device() c6761a9ed329 btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent b5501504cb6a btrfs: sysfs, rename devices kobject holder to devices_kobj
so I'll have another look at what you sent.
Quoted 28 lines · David Sterba
Quoted 15 lines · Anand Jain
Quoted 8 lines · David Sterba
Quoted 5 lines · Anand Jain
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory patches (1,2,3)/4. So I am resending those 3 patches. And the changes in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch 4/4 has the details of the changes.All the patches have been merged and now are in linus/master branch.
David,
Quoted 8 lines
Quoted 3 lines
I haven't reordered the patches so they're not in a group and the preparatory patches are about 10 commits above v5.5-rc7 which is the beginning of the branch.
It will cause problem during bisect, without the preparatory patches the devid kobject lands under devices instead of under devinfo, that's how I noticed that preparatory patches are missing.
I've tested current master and the device ids are indeed placed under device/ and there is no devinfo/, so this needs to be fixed.
Quoted 9 lines
Preparatory patches I was referring to are:
bc036bb33524btrfs: sysfs, mergebtrfs_sysfs_adddevices_kobjand fsidbe2cf92e0a2fbtrfs: sysfs, renamebtrfs_sysfs_add_device()c6761a9ed329btrfs: sysfs,btrfs_sysfs_add_fsid()drop unused argument parentb5501504cb6abtrfs: sysfs, rename devices kobject holder todevices_kobjso I'll have another look at what you sent.
David,
Busy? Can I ping on this?
Those aren't the preparatory patches. The patches sent here applies nicely on misc-next with git revert 668e48af7a94
Thanks, Anand
Quoted 10 lines · Anand Jain
Quoted 10 lines
I've tested current master and the device ids are indeed placed under device/ and there is no devinfo/, so this needs to be fixed.
Preparatory patches I was referring to are:
bc036bb33524btrfs: sysfs, mergebtrfs_sysfs_adddevices_kobjand fsidbe2cf92e0a2fbtrfs: sysfs, renamebtrfs_sysfs_add_device()c6761a9ed329btrfs: sysfs,btrfs_sysfs_add_fsid()drop unused argument parentb5501504cb6abtrfs: sysfs, rename devices kobject holder todevices_kobj
Quoted 8 lines
Quoted 2 lines
so I'll have another look at what you sent.
David,
Busy? Can I ping on this?
Those aren't the preparatory patches. The patches sent here applies nicely on misc-next with git revert
668e48af7a94
Do you realize that patch 668e48af7a94 had been merged to linus/master at the time you sent the patchset a week ago? How can I do git revert? That was in the middle of merge window, 2 weeks after code freeze. If I don't merge a patch intentionally or by mistake, then you send me an incremental change.
Please send update with this patch order:
* "btrfs: sysfs, add UUID/devinfo kobject"
* fixup of the device id files created under devices
* the other cleanups
Quoted 5 lines
* "btrfs: sysfs, add UUID/devinfo kobject"
* fixup of the device id files created under devices
* the other cleanups
Done. Its here: