btrfs: handle add/remove of sysfs links when devices are added/removed
PATCH 1/1 btrfs: handle add/remove of sysfs links when devices are added/removed
btrfs currently publishes device membership via sysfs based on the devices present when the file system is mounted. That publishing is not updated when devices are added or removed while mounted.
This patch handles those events.
--- fs/btrfs/volumes.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/volumes.c +11 -0
@@ -1704,6 +1704,9 @@ int btrfs_rm_device(struct btrfs_root *r ret =0 ; +sysfs_remove_link (root->fs_info->device_dir_kobj, +part_to_dev (bdev->bd_part)->kobj.name); +/* Notify udev that device has changed */ if (bdev)btrfs_kobject_uevent (bdev,KOBJ_CHANGE );
@@ -2038,6 +2041,12 @@ int btrfs_init_new_device(struct btrfs_r goto error; } + ret =sysfs_create_link (root->fs_info->device_dir_kobj, + &part_to_dev (bdev->bd_part)->kobj, +part_to_dev (bdev->bd_part)->kobj.name); +if (ret) + goto error; +lock_chunks (root); q =bdev_get_queue (bdev);
@@ -2152,6 +2161,8 @@ error_trans:unlock_chunks (root);btrfs_end_transaction (trans, root);rcu_string_free (device->name); +sysfs_remove_link (root->fs_info->device_dir_kobj, +part_to_dev (bdev->bd_part)->kobj.name);kfree (device); error:blkdev_put (bdev,FMODE_EXCL );
Signature · 2 lines
Jeff Mahoney SUSE Labs
Jeff,
We were working on the same bugs. I have sent out my patches as well.
Further I will be working on to revamp /sys/fs/btrfs/<fsid>/devices so that instead of links to block device we will have dir based on devices of the FS.
[PATCH RFC] btrfs: revamp /sys/fs/btrfs/<fsid>/devices
Comments appreciated.
Thanks, Anand
Quoted 47 lines · Jeff Mahoney
btrfs currently publishes device membership via sysfs based on the devices present when the file system is mounted. That publishing is not updated when devices are added or removed while mounted.
This patch handles those events.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/btrfs/volumes.c | 11 +++++++++++ 1 file changed, 11 insertions(+)fs/btrfs/volumes.c +11
-0@@ -1704,6 +1704,9 @@ int btrfs_rm_device(struct btrfs_root *r ret =0 ; +sysfs_remove_link (root->fs_info->device_dir_kobj, +part_to_dev (bdev->bd_part)->kobj.name); +/* Notify udev that device has changed */ if (bdev)btrfs_kobject_uevent (bdev,KOBJ_CHANGE );@@ -2038,6 +2041,12 @@ int btrfs_init_new_device(struct btrfs_r goto error; } + ret =sysfs_create_link (root->fs_info->device_dir_kobj, + &part_to_dev (bdev->bd_part)->kobj, +part_to_dev (bdev->bd_part)->kobj.name); +if (ret) + goto error; +lock_chunks (root); q =bdev_get_queue (bdev);@@ -2152,6 +2161,8 @@ error_trans:unlock_chunks (root);btrfs_end_transaction (trans, root);rcu_string_free (device->name); +sysfs_remove_link (root->fs_info->device_dir_kobj, +part_to_dev (bdev->bd_part)->kobj.name);kfree (device); error:blkdev_put (bdev,FMODE_EXCL );