Skip to content

Commit

Permalink
btrfs: factor out sysfs code for updating sprout fsid
Browse files Browse the repository at this point in the history
Wrap the fsid renaming code and move it to sysfs.c.

Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Sep 9, 2019
1 parent b5865ba commit f93c399
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
15 changes: 15 additions & 0 deletions fs/btrfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions fs/btrfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 2 additions & 10 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f93c399

Please sign in to comment.