Re: [PATCH v9] btrfs: consolidate device_list_mutex in prepare_sprout to its parent
From: David Sterba <hidden>
Date: 2021-11-08 19:37:32
On Thu, Oct 21, 2021 at 06:49:57PM +0800, Anand Jain wrote:
quoted hunk ↗ jump to hunk
@@ -2662,18 +2688,25 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path if (seeding_dev) { btrfs_clear_sb_rdonly(sb); - ret = btrfs_prepare_sprout(fs_info); - if (ret) { - btrfs_abort_transaction(trans, ret); + + /* GFP_KERNEL alloc should not be under device_list_mutex */ + seed_devices = btrfs_init_sprout(fs_info); + if (IS_ERR(seed_devices)) { + btrfs_abort_transaction(trans, (int)PTR_ERR(seed_devices));
Shouldn't this do ret = PTR_ERR(seed_devices) btrfs_abort_transaction(trans, ret); goto error_trans; The ret value would otherwise remain unchanged, from some previous use which at this point would be 0.
goto error_trans;
}
+ }
+
+ mutex_lock(&fs_devices->device_list_mutex);
+ if (seeding_dev) {
+ btrfs_setup_sprout(fs_info, seed_devices);
+
btrfs_assign_next_active_device(fs_info->fs_devices->latest_dev,
device);
}
device->fs_devices = fs_devices;
- mutex_lock(&fs_devices->device_list_mutex);
mutex_lock(&fs_info->chunk_mutex);
list_add_rcu(&device->dev_list, &fs_devices->devices);
list_add(&device->dev_alloc_list, &fs_devices->alloc_list);