[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC PATCH 08/10] util: Add qemu_opts_to_qdict_filtered()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [RFC PATCH 08/10] util: Add qemu_opts_to_qdict_filtered() |
Date: |
Thu, 11 Jan 2018 20:52:23 +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>
---
include/qemu/option.h | 2 ++
util/qemu-option.c | 28 +++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index a88c5f02b1..197f80e79d 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -125,6 +125,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 553d3dc552..76dc5bedf8 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1009,9 +1009,10 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict
*qdict, Error **errp)
* 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();
@@ -1019,12 +1020,33 @@ 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_all(opts, opt->name);
+ }
}
return qdict;
}
+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
- Re: [Qemu-block] [RFC PATCH 04/10] qcow2: Pass BlockdevCreateOptions to qcow2_create2(), (continued)
[Qemu-block] [RFC PATCH 05/10] qcow2: Use BlockdevRef in qcow2_create2(), Kevin Wolf, 2018/01/11
[Qemu-block] [RFC PATCH 06/10] qcow2: Use QCryptoBlockCreateOptions in qcow2_create2(), Kevin Wolf, 2018/01/11
[Qemu-block] [RFC PATCH 07/10] qcow2: Handle full/falloc preallocation in qcow2_create2(), Kevin Wolf, 2018/01/11
[Qemu-block] [RFC PATCH 08/10] util: Add qemu_opts_to_qdict_filtered(),
Kevin Wolf <=
[Qemu-block] [RFC PATCH 09/10] qcow2: Use visitor for options in qcow2_create(), Kevin Wolf, 2018/01/11
[Qemu-block] [RFC PATCH 10/10] block: x-blockdev-create QMP command, Kevin Wolf, 2018/01/11
Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/10] x-blockdev-create for qcow2, no-reply, 2018/01/11
Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/10] x-blockdev-create for qcow2, no-reply, 2018/01/11
Re: [Qemu-block] [RFC PATCH 00/10] x-blockdev-create for qcow2, Kevin Wolf, 2018/01/16
Re: [Qemu-block] [RFC PATCH 00/10] x-blockdev-create for qcow2, Max Reitz, 2018/01/29