[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 19/25] block: Use QemuOpts in bdrv_open_common()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 19/25] block: Use QemuOpts in bdrv_open_common() |
Date: |
Fri, 12 Jun 2015 18:23:28 +0200 |
Instead of manually parsing options and then deleting them from the
options QDict, just use QemuOpts like most other places that deal with
block device options.
More options will be added there and then QemuOpts is a lot more
manageable than open-coding everything.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 38 +++++++++++++++++++++++++++++++++-----
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/block.c b/block.c
index b2e784e..ad8b0c7 100644
--- a/block.c
+++ b/block.c
@@ -767,6 +767,19 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
}
+static QemuOptsList bdrv_runtime_opts = {
+ .name = "bdrv_common",
+ .head = QTAILQ_HEAD_INITIALIZER(bdrv_runtime_opts.head),
+ .desc = {
+ {
+ .name = "node-name",
+ .type = QEMU_OPT_STRING,
+ .help = "Node name of the block device node",
+ },
+ { /* end of list */ }
+ },
+};
+
/*
* Common part for opening disk images and files
*
@@ -778,6 +791,7 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
int ret, open_flags;
const char *filename;
const char *node_name = NULL;
+ QemuOpts *opts;
Error *local_err = NULL;
assert(drv != NULL);
@@ -798,13 +812,21 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
- node_name = qdict_get_try_str(options, "node-name");
+ opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
+ qemu_opts_absorb_qdict(opts, options, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ ret = -EINVAL;
+ goto fail_opts;
+ }
+
+ node_name = qemu_opt_get(opts, "node-name");
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
- return -EINVAL;
+ ret = -EINVAL;
+ goto fail_opts;
}
- qdict_del(options, "node-name");
bs->open_flags = flags;
bs->guest_block_size = 512;
@@ -819,7 +841,8 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
? "Driver '%s' can only be used for read-only devices"
: "Driver '%s' is not whitelisted",
drv->format_name);
- return -ENOTSUP;
+ ret = -ENOTSUP;
+ goto fail_opts;
}
assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
@@ -828,7 +851,8 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
bdrv_enable_copy_on_read(bs);
} else {
error_setg(errp, "Can't use copy-on-read on read-only device");
- return -EINVAL;
+ ret = -EINVAL;
+ goto fail_opts;
}
}
@@ -894,6 +918,8 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
assert(bdrv_opt_mem_align(bs) != 0);
assert(bdrv_min_mem_align(bs) != 0);
assert((bs->request_alignment != 0) || bs->sg);
+
+ qemu_opts_del(opts);
return 0;
free_and_fail:
@@ -901,6 +927,8 @@ free_and_fail:
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
+fail_opts:
+ qemu_opts_del(opts);
return ret;
}
--
1.8.3.1
- [Qemu-devel] [PULL 07/25] vmdk: Use vmdk_find_index_in_cluster everywhere, (continued)
- [Qemu-devel] [PULL 07/25] vmdk: Use vmdk_find_index_in_cluster everywhere, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 09/25] block: record new size in bdrv_dirty_bitmap_truncate, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 10/25] block: Change bitmap truncate conditional to assertion, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 11/25] block: driver should override flags in bdrv_open(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 12/25] iotests: Add tests for overriding BDRV_O_PROTOCOL, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 13/25] qdict: Add qdict_array_entries(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 15/25] check-qdict: Test cases for new functions, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 14/25] qdict: Add qdict_{set,copy}_default(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 16/25] quorum: Use bdrv_open_image(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 18/25] block: Use macro for cache option names, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 19/25] block: Use QemuOpts in bdrv_open_common(),
Kevin Wolf <=
- [Qemu-devel] [PULL 21/25] block: Drain requests before swapping nodes in bdrv_swap(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 22/25] queue.h: Add QLIST_FIX_HEAD_PTR(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 17/25] vmdk: Use bdrv_open_image(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 23/25] block: Add list of children to BlockDriverState, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 20/25] block: Move flag inheritance to bdrv_open_inherit(), Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 24/25] block: Add BlockDriverState.inherits_from, Kevin Wolf, 2015/06/12
- [Qemu-devel] [PULL 25/25] block: Fix reopen flag inheritance, Kevin Wolf, 2015/06/12
- Re: [Qemu-devel] [PULL 00/25] Block layer core and image format patches, Peter Maydell, 2015/06/15