btrfs: fix BUG_ON in btrfs_init_new_device()
Instead of BUG_ON return error to the caller. And handle the fail condition by calling the abort transaction and going through the error path. Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
0af2c4bf5a
commit
d31c32f674
|
@ -2394,7 +2394,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
|
||||||
if (seeding_dev) {
|
if (seeding_dev) {
|
||||||
sb->s_flags &= ~MS_RDONLY;
|
sb->s_flags &= ~MS_RDONLY;
|
||||||
ret = btrfs_prepare_sprout(fs_info);
|
ret = btrfs_prepare_sprout(fs_info);
|
||||||
BUG_ON(ret); /* -ENOMEM */
|
if (ret) {
|
||||||
|
btrfs_abort_transaction(trans, ret);
|
||||||
|
goto error_trans;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
device->fs_devices = fs_info->fs_devices;
|
device->fs_devices = fs_info->fs_devices;
|
||||||
|
@ -2440,14 +2443,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
|
||||||
mutex_unlock(&fs_info->chunk_mutex);
|
mutex_unlock(&fs_info->chunk_mutex);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
btrfs_abort_transaction(trans, ret);
|
btrfs_abort_transaction(trans, ret);
|
||||||
goto error_trans;
|
goto error_sysfs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = btrfs_add_device(trans, fs_info, device);
|
ret = btrfs_add_device(trans, fs_info, device);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
btrfs_abort_transaction(trans, ret);
|
btrfs_abort_transaction(trans, ret);
|
||||||
goto error_trans;
|
goto error_sysfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seeding_dev) {
|
if (seeding_dev) {
|
||||||
|
@ -2456,7 +2459,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
|
||||||
ret = btrfs_finish_sprout(trans, fs_info);
|
ret = btrfs_finish_sprout(trans, fs_info);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
btrfs_abort_transaction(trans, ret);
|
btrfs_abort_transaction(trans, ret);
|
||||||
goto error_trans;
|
goto error_sysfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sprouting would change fsid of the mounted root,
|
/* Sprouting would change fsid of the mounted root,
|
||||||
|
@ -2495,12 +2498,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
|
||||||
update_dev_time(device_path);
|
update_dev_time(device_path);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
error_sysfs:
|
||||||
|
btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
|
||||||
error_trans:
|
error_trans:
|
||||||
if (seeding_dev)
|
if (seeding_dev)
|
||||||
sb->s_flags |= MS_RDONLY;
|
sb->s_flags |= MS_RDONLY;
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
rcu_string_free(device->name);
|
rcu_string_free(device->name);
|
||||||
btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
|
|
||||||
kfree(device);
|
kfree(device);
|
||||||
error:
|
error:
|
||||||
blkdev_put(bdev, FMODE_EXCL);
|
blkdev_put(bdev, FMODE_EXCL);
|
||||||
|
|
Loading…
Reference in New Issue