Creating sprout will change the fsid of the mounted root.
do the same on the sysfs as well.

reproducer:
 mount /dev/sdb /btrfs (seed disk)
 btrfs dev add /dev/sdc /btrfs
 mount -o rw,remount /btrfs
 btrfs dev del /dev/sdb /btrfs
 mount /dev/sdb /btrfs

Error:
kobject_add_internal failed for fe350492-dc28-4051-a601-e017b17e6145 with 
-EEXIST, don't try to register things with the same name in the same directory.

Signed-off-by: Anand Jain <anand.j...@oracle.com>
---
 fs/btrfs/volumes.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5a577ab..e6cf3a7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2084,6 +2084,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char 
*device_path)
        mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
        if (seeding_dev) {
+               char fsid_buf[37];
                ret = init_first_rw_device(trans, root, device);
                if (ret) {
                        btrfs_abort_transaction(trans, root, ret);
@@ -2094,6 +2095,13 @@ int btrfs_init_new_device(struct btrfs_root *root, char 
*device_path)
                        btrfs_abort_transaction(trans, root, ret);
                        goto error_trans;
                }
+
+               /* Sprouting would change fsid of the mounted root,
+                * so rename the fsid on the sysfs
+                */
+               sprintf(fsid_buf, "%pU", root->fs_info->fsid);
+               if (kobject_rename(&root->fs_info->super_kobj, fsid_buf))
+                       goto error_trans;
        } else {
                ret = btrfs_add_device(trans, root, device);
                if (ret) {
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to