[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 08/36] util: Add qemu_opts_to_qdict_filtered()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v3 08/36] util: Add qemu_opts_to_qdict_filtered() |
Date: |
Fri, 23 Feb 2018 20:25:21 +0100 |
This allows, given a QemuOpts for a QemuOptsList that was merged from
multiple QemuOptsList, to only consider those options that exist in one
specific list. Block drivers need this to separate format-layer create
options from protocol-level options.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
include/qemu/option.h | 2 ++
util/qemu-option.c | 42 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index b127fb6db6..306fdb5f7a 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -124,6 +124,8 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char
*params,
int permit_abbrev);
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
Error **errp);
+QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict,
+ QemuOptsList *list, bool del);
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index a401e936da..2b412eff5e 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1007,14 +1007,23 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict
*qdict, Error **errp)
}
/*
- * Convert from QemuOpts to QDict.
- * The QDict values are of type QString.
+ * Convert from QemuOpts to QDict. The QDict values are of type QString.
+ *
+ * If @list is given, only add those options to the QDict that are contained in
+ * the list. If @del is true, any options added to the QDict are removed from
+ * the QemuOpts, otherwise they remain there.
+ *
+ * If two options in @opts have the same name, they are processed in order
+ * so that the last one wins (consistent with the reverse iteration in
+ * qemu_opt_find()), but all of them are deleted if @del is true.
+ *
* TODO We'll want to use types appropriate for opt->desc->type, but
* this is enough for now.
*/
-QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
+QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict,
+ QemuOptsList *list, bool del)
{
- QemuOpt *opt;
+ QemuOpt *opt, *next;
if (!qdict) {
qdict = qdict_new();
@@ -1022,12 +1031,35 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
if (opts->id) {
qdict_put_str(qdict, "id", opts->id);
}
- QTAILQ_FOREACH(opt, &opts->head, next) {
+ QTAILQ_FOREACH_SAFE(opt, &opts->head, next, next) {
+ if (list) {
+ QemuOptDesc *desc;
+ bool found = false;
+ for (desc = list->desc; desc->name; desc++) {
+ if (!strcmp(desc->name, opt->name)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ continue;
+ }
+ }
qdict_put_str(qdict, opt->name, opt->str);
+ if (del) {
+ qemu_opt_del(opt);
+ }
}
return qdict;
}
+/* Copy all options in a QemuOpts to the given QDict. See
+ * qemu_opts_to_qdict_filtered() for details. */
+QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
+{
+ return qemu_opts_to_qdict_filtered(opts, qdict, NULL, false);
+}
+
/* Validate parsed opts against descriptions where no
* descriptions were provided in the QemuOptsList.
*/
--
2.13.6
- [Qemu-block] [PATCH v3 00/36] x-blockdev-create for protocols and qcow2, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 02/36] block/qapi: Add qcow2 create options to schema, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 01/36] block/qapi: Introduce BlockdevCreateOptions, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 05/36] qcow2: Use BlockdevRef in qcow2_create2(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 03/36] qcow2: Let qcow2_create() handle protocol layer, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 04/36] qcow2: Pass BlockdevCreateOptions to qcow2_create2(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 06/36] qcow2: Use QCryptoBlockCreateOptions in qcow2_create2(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 07/36] qcow2: Handle full/falloc preallocation in qcow2_create2(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 08/36] util: Add qemu_opts_to_qdict_filtered(),
Kevin Wolf <=
- [Qemu-block] [PATCH v3 09/36] test-qemu-opts: Test qemu_opts_append(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 11/36] qdict: Introduce qdict_rename_keys(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 10/36] test-qemu-opts: Test qemu_opts_to_qdict_filtered(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 13/36] block: Make bdrv_is_whitelisted() public, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 12/36] qcow2: Use visitor for options in qcow2_create(), Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 16/36] file-win32: Support .bdrv_co_create, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 14/36] block: x-blockdev-create QMP command, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 15/36] file-posix: Support .bdrv_co_create, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 17/36] gluster: Support .bdrv_co_create, Kevin Wolf, 2018/02/23
- [Qemu-block] [PATCH v3 18/36] rbd: Fix use after free in qemu_rbd_set_keypairs() error path, Kevin Wolf, 2018/02/23