btrfs: update devid after replace
diff mbox series

Message ID 20200115082250.3064-1-anand.jain@oracle.com
State New
Headers show
Series
  • btrfs: update devid after replace
Related show

Commit Message

Anand Jain Jan. 15, 2020, 8:22 a.m. UTC
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(+)

Comments

David Sterba Jan. 15, 2020, 4:17 p.m. UTC | #1
On Wed, Jan 15, 2020 at 04:22:50PM +0800, Anand Jain wrote:
> 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.

I had to remove the patch from misc-next as it prevented further
testing. The whole patchset can be found in branch
ext/anand/sysfs-devinfo on github repo. Once I test this patch I'll add
it back.
David Sterba Jan. 20, 2020, 7:10 p.m. UTC | #2
On Wed, Jan 15, 2020 at 04:22:50PM +0800, Anand Jain wrote:
> --- 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];

24 is enough

> +
> +	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");

And printing for which devid the rename failed should be here

> +}
> +

Once the tests finish I'll add it to misc-next so the patchset is
complete.

Patch
diff mbox series

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