btrfs: factor out sysfs code for updating sprout fsid
authorDavid Sterba <dsterba@suse.com>
Thu, 1 Aug 2019 16:50:16 +0000 (18:50 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:07 +0000 (14:59 +0200)
Wrap the fsid renaming code and move it to sysfs.c.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/sysfs.c
fs/btrfs/sysfs.h
fs/btrfs/volumes.c

index 4de9bae3e18689397612e6927dcfb9d38f0a397b..9078e377ba7baf014f232710df04e0a131e0ce65 100644 (file)
@@ -946,6 +946,21 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)
                        &disk_to_dev(bdev->bd_disk)->kobj);
 }
 
+void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
+                                   const u8 *fsid)
+{
+       char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
+
+       /*
+        * Sprouting changes fsid of the mounted filesystem, rename the fsid
+        * directory
+        */
+       snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU", fsid);
+       if (kobject_rename(&fs_devices->fsid_kobj, fsid_buf))
+               btrfs_warn(fs_devices->fs_info,
+                               "sysfs: failed to create fsid for sprout");
+}
+
 /* /sys/fs/btrfs/ entry */
 static struct kset *btrfs_kset;
 
index 031697358b6e63a0c0626559cd88ef37598dc57b..4243fcf607b01d259e6ee2c0422ffcc49f801bca 100644 (file)
@@ -87,6 +87,8 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
                                struct kobject *parent);
 int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
+void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
+                                   const u8 *fsid);
 void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
                u64 bit, enum btrfs_feature_set set);
 void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action);
index 830e4b0b5957712bffbe291b6875503355c05b5b..fa6eb9e0ba89710514a8365b85d7add25c7f7f8b 100644 (file)
@@ -2680,22 +2680,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
        }
 
        if (seeding_dev) {
-               char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
-
                ret = btrfs_finish_sprout(trans);
                if (ret) {
                        btrfs_abort_transaction(trans, ret);
                        goto error_sysfs;
                }
 
-               /* Sprouting would change fsid of the mounted root,
-                * so rename the fsid on the sysfs
-                */
-               snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
-                                               fs_info->fs_devices->fsid);
-               if (kobject_rename(&fs_devices->fsid_kobj, fsid_buf))
-                       btrfs_warn(fs_info,
-                                  "sysfs: failed to create fsid for sprout");
+               btrfs_sysfs_update_sprout_fsid(fs_devices,
+                               fs_info->fs_devices->fsid);
        }
 
        ret = btrfs_commit_transaction(trans);