Skip to content

Commit e2f7c8a

Browse files
committed
btrfs: do device clone using the btrfs_scan_one_device
When we add a device to the RO mounted seed device, it becomes a RW sprout FS. The following steps are used to hold the seed and sprout fs_devices. (first two steps are not mandatory for the sprouting, they are there to ensure the seed device remains in the scanned state) . Clone the (mounted) fs_devices, lets call it as old_devices . Now add old_devices to fs_uuids (yeah, there is duplicate fsid in the list, as we are under uuid_mutex so its fine). . Alloc a new fs_devices, lets call it as seed_devices . Copy fs_devices into the seed_devices . Move fs_devices::devices into seed_devices::devices . Bring seed_devices to under fs_devices::seed (fs_devices->seed = seed_devices) . Assign a new FSID to the fs_devices and add the new writable device to the fs_devices. This patch makes the following changes.. As we clone fs_devices to make sure the device remains scanned after the sprouting. So use the btrfs_scan_one_device() code instead. And do it at the end of the sprouting. Signed-off-by: Anand Jain <[email protected]>
1 parent 89325c8 commit e2f7c8a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

fs/btrfs/volumes.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
21812181
static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
21822182
{
21832183
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
2184-
struct btrfs_fs_devices *old_devices;
2184+
struct btrfs_fs_devices *old_fs_devices;
21852185
struct btrfs_fs_devices *seed_devices;
21862186
struct btrfs_super_block *disk_super = fs_info->super_copy;
21872187
struct btrfs_device *device;
@@ -2195,14 +2195,6 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
21952195
if (IS_ERR(seed_devices))
21962196
return PTR_ERR(seed_devices);
21972197

2198-
old_devices = clone_fs_devices(fs_devices);
2199-
if (IS_ERR(old_devices)) {
2200-
kfree(seed_devices);
2201-
return PTR_ERR(old_devices);
2202-
}
2203-
2204-
list_add(&old_devices->fs_list, &fs_uuids);
2205-
22062198
memcpy(seed_devices, fs_devices, sizeof(*seed_devices));
22072199
seed_devices->opened = 1;
22082200
INIT_LIST_HEAD(&seed_devices->devices);
@@ -2235,6 +2227,17 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
22352227
~BTRFS_SUPER_FLAG_SEEDING;
22362228
btrfs_set_super_flags(disk_super, super_flags);
22372229

2230+
/*
2231+
* As the above code hijacked the original seed fs_devices, now
2232+
* create a new one for the original seed FSID.
2233+
*/
2234+
list_for_each_entry(device, &fs_devices->seed->devices, dev_list) {
2235+
if (!device->name)
2236+
continue;
2237+
btrfs_scan_one_device(device->name->str, FMODE_READ,
2238+
fs_info->bdev_holder, &old_fs_devices);
2239+
}
2240+
22382241
return 0;
22392242
}
22402243

0 commit comments

Comments
 (0)