summaryrefslogtreecommitdiffstats
path: root/block.c
diff options
context:
space:
mode:
authorMaxim Levitsky2020-03-26 02:12:18 +0100
committerMax Reitz2020-03-26 14:44:33 +0100
commit5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9 (patch)
tree8b31bc0a2fc9cd2b25032ef51546035d8b38e78f /block.c
parentblock: pass BlockDriver reference to the .bdrv_co_create (diff)
downloadqemu-5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9.tar.gz
qemu-5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9.tar.xz
qemu-5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9.zip
block: trickle down the fallback image creation function use to the block drivers
Instead of checking the .bdrv_co_create_opts to see if we need the fallback, just implement the .bdrv_co_create_opts in the drivers that need it. This way we don't break various places that need to know if the underlying protocol/format really supports image creation, and this way we still allow some drivers to not support image creation. Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1816007 Note that technically this driver reverts the image creation fallback for the vxhs driver since I don't have a means to test it, and IMHO it is better to leave it not supported as it was prior to generic image creation patches. Also drop iscsi_create_opts which was left accidentally. Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20200326011218.29230-3-mlevitsk@redhat.com> Reviewed-by: Denis V. Lunev <den@openvz.org> [mreitz: Fixed alignment, and moved bdrv_co_create_opts_simple() and bdrv_create_opts_simple from block.h into block_int.h] Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/block.c b/block.c
index ff23e20443..af3faf664e 100644
--- a/block.c
+++ b/block.c
@@ -598,8 +598,15 @@ static int create_file_fallback_zero_first_sector(BlockBackend *blk,
return 0;
}
-static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
- QemuOpts *opts, Error **errp)
+/**
+ * Simple implementation of bdrv_co_create_opts for protocol drivers
+ * which only support creation via opening a file
+ * (usually existing raw storage device)
+ */
+int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
+ const char *filename,
+ QemuOpts *opts,
+ Error **errp)
{
BlockBackend *blk;
QDict *options;
@@ -663,11 +670,7 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
return -ENOENT;
}
- if (drv->bdrv_co_create_opts) {
- return bdrv_create(drv, filename, opts, errp);
- } else {
- return bdrv_create_file_fallback(filename, drv, opts, errp);
- }
+ return bdrv_create(drv, filename, opts, errp);
}
int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
@@ -1592,9 +1595,9 @@ QemuOptsList bdrv_runtime_opts = {
},
};
-static QemuOptsList fallback_create_opts = {
- .name = "fallback-create-opts",
- .head = QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head),
+QemuOptsList bdrv_create_opts_simple = {
+ .name = "simple-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(bdrv_create_opts_simple.head),
.desc = {
{
.name = BLOCK_OPT_SIZE,
@@ -5963,13 +5966,15 @@ void bdrv_img_create(const char *filename, const char *fmt,
return;
}
+ if (!proto_drv->create_opts) {
+ error_setg(errp, "Protocol driver '%s' does not support image creation",
+ proto_drv->format_name);
+ return;
+ }
+
/* Create parameter list */
create_opts = qemu_opts_append(create_opts, drv->create_opts);
- if (proto_drv->create_opts) {
- create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
- } else {
- create_opts = qemu_opts_append(create_opts, &fallback_create_opts);
- }
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);