>From 1b8d700007f1f8709a6ef1960111ea022cfb6d74 Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Fri, 17 Jan 2020 12:05:09 +0000 Subject: [PATCH] xen-block: Fix parsing of legacy options Even though the xen-disk PV backend can be instantiated via QMP, we still need to handle the case where the backend is created via xenstore. This means that we need to be able to parse legacy disk options such as "aio:nbd://host:1234/disk". Signed-off-by: Anthony PERARD --- block.c | 6 ++++++ hw/block/xen-block.c | 25 +++++++++++++++++++++---- include/sysemu/block-backend.h | 3 +++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index ecd09dbbfd89..13b8690e5006 100644 --- a/block.c +++ b/block.c @@ -1705,6 +1705,12 @@ static int bdrv_fill_options(QDict **options, const char *filename, return 0; } +int bdrv_fill_options_legacy(QDict **options, const char *filename, + int *flags, Error **errp) +{ + return bdrv_fill_options(options, filename, flags, errp); +} + static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, uint64_t perm, uint64_t shared, diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 879fc310a4c5..1cc97a001e1f 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -28,6 +28,7 @@ #include "sysemu/iothread.h" #include "dataplane/xen-block.h" #include "trace.h" +#include "include/block/qdict.h" static char *xen_block_get_name(XenDevice *xendev, Error **errp) { @@ -687,7 +688,12 @@ static char *xen_block_blockdev_add(const char *id, QDict *qdict, trace_xen_block_blockdev_add(node_name); - v = qobject_input_visitor_new(QOBJECT(qdict)); + qdict_flatten(qdict); + v = qobject_input_visitor_new_flat_confused(qdict, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; + } visit_type_BlockdevOptions(v, NULL, &options, &local_err); visit_free(v); @@ -782,8 +788,14 @@ static XenBlockDrive *xen_block_drive_create(const char *id, file_layer = qdict_new(); driver_layer = qdict_new(); - qdict_put_str(file_layer, "driver", "file"); - qdict_put_str(file_layer, "filename", filename); + int flags = BDRV_O_PROTOCOL | BDRV_O_RDWR; + if (mode && *mode != 'w') { + flags &= ~BDRV_O_RDWR; + } + bdrv_fill_options_legacy(&file_layer, filename, &flags, &local_err); + if (local_err) + goto done; + g_free(filename); if (mode && *mode != 'w') { @@ -816,7 +828,12 @@ static XenBlockDrive *xen_block_drive_create(const char *id, * It is necessary to turn file locking off as an emulated device * may have already opened the same image file. */ - qdict_put_str(file_layer, "locking", "off"); + const char *file_driver = qdict_get_str(file_layer, "driver"); + if (!strcmp("file", file_driver) || + !strcmp("host_device", file_driver) || + !strcmp("host_cdrom", file_driver) + ) + qdict_put_str(file_layer, "locking", "off"); qdict_put_str(driver_layer, "driver", driver); g_free(driver); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index b198deca0b24..93efded0ab61 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -98,6 +98,9 @@ void blk_remove_bs(BlockBackend *blk); int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp); bool bdrv_has_blk(BlockDriverState *bs); bool bdrv_is_root_node(BlockDriverState *bs); +/* deprecated, not to be used for new backends */ +int bdrv_fill_options_legacy(QDict **options, const char *filename, + int *flags, Error **errp); int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, Error **errp); void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm); -- Anthony PERARD