qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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>

authored by

Maxim Levitsky and committed by
Max Reitz
5a5e7f8c b92902df

+51 -28
+20 -15
block.c
··· 598 598 return 0; 599 599 } 600 600 601 - static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv, 602 - QemuOpts *opts, Error **errp) 601 + /** 602 + * Simple implementation of bdrv_co_create_opts for protocol drivers 603 + * which only support creation via opening a file 604 + * (usually existing raw storage device) 605 + */ 606 + int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, 607 + const char *filename, 608 + QemuOpts *opts, 609 + Error **errp) 603 610 { 604 611 BlockBackend *blk; 605 612 QDict *options; ··· 663 670 return -ENOENT; 664 671 } 665 672 666 - if (drv->bdrv_co_create_opts) { 667 - return bdrv_create(drv, filename, opts, errp); 668 - } else { 669 - return bdrv_create_file_fallback(filename, drv, opts, errp); 670 - } 673 + return bdrv_create(drv, filename, opts, errp); 671 674 } 672 675 673 676 int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp) ··· 1592 1595 }, 1593 1596 }; 1594 1597 1595 - static QemuOptsList fallback_create_opts = { 1596 - .name = "fallback-create-opts", 1597 - .head = QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head), 1598 + QemuOptsList bdrv_create_opts_simple = { 1599 + .name = "simple-create-opts", 1600 + .head = QTAILQ_HEAD_INITIALIZER(bdrv_create_opts_simple.head), 1598 1601 .desc = { 1599 1602 { 1600 1603 .name = BLOCK_OPT_SIZE, ··· 5963 5966 return; 5964 5967 } 5965 5968 5969 + if (!proto_drv->create_opts) { 5970 + error_setg(errp, "Protocol driver '%s' does not support image creation", 5971 + proto_drv->format_name); 5972 + return; 5973 + } 5974 + 5966 5975 /* Create parameter list */ 5967 5976 create_opts = qemu_opts_append(create_opts, drv->create_opts); 5968 - if (proto_drv->create_opts) { 5969 - create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); 5970 - } else { 5971 - create_opts = qemu_opts_append(create_opts, &fallback_create_opts); 5972 - } 5977 + create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); 5973 5978 5974 5979 opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); 5975 5980
+6 -1
block/file-posix.c
··· 3513 3513 .bdrv_reopen_prepare = raw_reopen_prepare, 3514 3514 .bdrv_reopen_commit = raw_reopen_commit, 3515 3515 .bdrv_reopen_abort = raw_reopen_abort, 3516 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 3517 + .create_opts = &bdrv_create_opts_simple, 3516 3518 .mutable_opts = mutable_opts, 3517 3519 .bdrv_co_invalidate_cache = raw_co_invalidate_cache, 3518 3520 .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, ··· 3639 3641 .bdrv_reopen_prepare = raw_reopen_prepare, 3640 3642 .bdrv_reopen_commit = raw_reopen_commit, 3641 3643 .bdrv_reopen_abort = raw_reopen_abort, 3644 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 3645 + .create_opts = &bdrv_create_opts_simple, 3642 3646 .mutable_opts = mutable_opts, 3643 3647 .bdrv_co_invalidate_cache = raw_co_invalidate_cache, 3644 3648 3645 - 3646 3649 .bdrv_co_preadv = raw_co_preadv, 3647 3650 .bdrv_co_pwritev = raw_co_pwritev, 3648 3651 .bdrv_co_flush_to_disk = raw_co_flush_to_disk, ··· 3771 3774 .bdrv_reopen_prepare = raw_reopen_prepare, 3772 3775 .bdrv_reopen_commit = raw_reopen_commit, 3773 3776 .bdrv_reopen_abort = raw_reopen_abort, 3777 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 3778 + .create_opts = &bdrv_create_opts_simple, 3774 3779 .mutable_opts = mutable_opts, 3775 3780 3776 3781 .bdrv_co_preadv = raw_co_preadv,
+4 -12
block/iscsi.c
··· 2399 2399 return r; 2400 2400 } 2401 2401 2402 - static QemuOptsList iscsi_create_opts = { 2403 - .name = "iscsi-create-opts", 2404 - .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), 2405 - .desc = { 2406 - { 2407 - .name = BLOCK_OPT_SIZE, 2408 - .type = QEMU_OPT_SIZE, 2409 - .help = "Virtual disk size" 2410 - }, 2411 - { /* end of list */ } 2412 - } 2413 - }; 2414 2402 2415 2403 static const char *const iscsi_strong_runtime_opts[] = { 2416 2404 "transport", ··· 2434 2422 .bdrv_parse_filename = iscsi_parse_filename, 2435 2423 .bdrv_file_open = iscsi_open, 2436 2424 .bdrv_close = iscsi_close, 2425 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 2426 + .create_opts = &bdrv_create_opts_simple, 2437 2427 .bdrv_reopen_prepare = iscsi_reopen_prepare, 2438 2428 .bdrv_reopen_commit = iscsi_reopen_commit, 2439 2429 .bdrv_co_invalidate_cache = iscsi_co_invalidate_cache, ··· 2471 2461 .bdrv_parse_filename = iscsi_parse_filename, 2472 2462 .bdrv_file_open = iscsi_open, 2473 2463 .bdrv_close = iscsi_close, 2464 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 2465 + .create_opts = &bdrv_create_opts_simple, 2474 2466 .bdrv_reopen_prepare = iscsi_reopen_prepare, 2475 2467 .bdrv_reopen_commit = iscsi_reopen_commit, 2476 2468 .bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,
+6
block/nbd.c
··· 2038 2038 .protocol_name = "nbd", 2039 2039 .instance_size = sizeof(BDRVNBDState), 2040 2040 .bdrv_parse_filename = nbd_parse_filename, 2041 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 2042 + .create_opts = &bdrv_create_opts_simple, 2041 2043 .bdrv_file_open = nbd_open, 2042 2044 .bdrv_reopen_prepare = nbd_client_reopen_prepare, 2043 2045 .bdrv_co_preadv = nbd_client_co_preadv, ··· 2063 2065 .protocol_name = "nbd+tcp", 2064 2066 .instance_size = sizeof(BDRVNBDState), 2065 2067 .bdrv_parse_filename = nbd_parse_filename, 2068 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 2069 + .create_opts = &bdrv_create_opts_simple, 2066 2070 .bdrv_file_open = nbd_open, 2067 2071 .bdrv_reopen_prepare = nbd_client_reopen_prepare, 2068 2072 .bdrv_co_preadv = nbd_client_co_preadv, ··· 2088 2092 .protocol_name = "nbd+unix", 2089 2093 .instance_size = sizeof(BDRVNBDState), 2090 2094 .bdrv_parse_filename = nbd_parse_filename, 2095 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 2096 + .create_opts = &bdrv_create_opts_simple, 2091 2097 .bdrv_file_open = nbd_open, 2092 2098 .bdrv_reopen_prepare = nbd_client_reopen_prepare, 2093 2099 .bdrv_co_preadv = nbd_client_co_preadv,
+3
block/nvme.c
··· 1333 1333 .protocol_name = "nvme", 1334 1334 .instance_size = sizeof(BDRVNVMeState), 1335 1335 1336 + .bdrv_co_create_opts = bdrv_co_create_opts_simple, 1337 + .create_opts = &bdrv_create_opts_simple, 1338 + 1336 1339 .bdrv_parse_filename = nvme_parse_filename, 1337 1340 .bdrv_file_open = nvme_file_open, 1338 1341 .bdrv_close = nvme_close,
+1
include/block/block.h
··· 283 283 int bdrv_create(BlockDriver *drv, const char* filename, 284 284 QemuOpts *opts, Error **errp); 285 285 int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp); 286 + 286 287 BlockDriverState *bdrv_new(void); 287 288 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, 288 289 Error **errp);
+11
include/block/block_int.h
··· 1331 1331 void bdrv_set_monitor_owned(BlockDriverState *bs); 1332 1332 BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp); 1333 1333 1334 + /** 1335 + * Simple implementation of bdrv_co_create_opts for protocol drivers 1336 + * which only support creation via opening a file 1337 + * (usually existing raw storage device) 1338 + */ 1339 + int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, 1340 + const char *filename, 1341 + QemuOpts *opts, 1342 + Error **errp); 1343 + extern QemuOptsList bdrv_create_opts_simple; 1344 + 1334 1345 #endif /* BLOCK_INT_H */