[PATCH] btrfs: update devid after replace

Anand Jain
2020-01-15T08:23:27Z

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.

This patch must be squashed with the patch
[PATCH v4] btrfs: sysfs, add devid/dev_state kobject and attribute
or its variant.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
David,
I couldn't find the patch-series..
[PATCH 0/4] btrfs, sysfs cleanup and add dev_state
in your misc-next. And I believe there were changes like
function rename and attribute list reorder in your workspace. So I am
sending a fix-patch which must be squashed to the patch v4 4/4.

With this patch, the test case btrfs/064 runs fine. And volume group
tests are still running.

fs/btrfs/dev-replace.c | 1 +
fs/btrfs/sysfs.c | 11 +++++++++++
fs/btrfs/sysfs.h | 1 +
3 files changed, 13 insertions(+)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 9a29d6de9017..ccdb486bd4c3 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -707,6 +707,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 */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 0b615d99cedd..22971268e5b6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1189,6 +1189,17 @@ int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices,
return 0;
}

+void btrfs_sysfs_update_devid(struct btrfs_device *device)
+{
+ char tmp[64];
+
+ snprintf(tmp, sizeof(tmp), "%llu", device->devid);
+
+ if (kobject_rename(&device->devid_kobj, tmp))
+ btrfs_warn(device->fs_devices->fs_info,
+ "sysfs: failed to update devid");
+}
+
static ssize_t btrfs_sysfs_writeable_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
{
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 9d97b3c8db4e..ccf33eaf9e59 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -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
--
2.23.0