[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists
From: |
Paolo Bonzini |
Subject: |
[PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists |
Date: |
Mon, 9 Nov 2020 08:39:29 -0500 |
Forbid ids if the option is intended to be a singleton, as indicated by
list->merge_lists. This avoids that "./qemu-system-x86_64 -M q35,id=ff"
uses a "pc" machine type. Instead it errors out. The affected options
are "qemu-img reopen -o", "qemu-io open -o", -rtc, -M, -boot, -name,
-m, -icount, -smp, -spice.
qemu_opts_create's fail_if_exists parameter is now unnecessary:
- it is unused if id is NULL
- opts_parse only passes false if reached from qemu_opts_set_defaults,
in which case this patch enforces that id must be NULL
- other callers that can pass a non-NULL id always set it to true
Assert that it is true in the only case where "fail_if_exists" matters,
i.e. "id && !lists->merge_lists". This means that if an id is present,
duplicates are always forbidden, which was already the status quo.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/qemu-option.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index c88e159f18..91f4120ce1 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -619,7 +619,17 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char
*id,
{
QemuOpts *opts = NULL;
- if (id) {
+ if (list->merge_lists) {
+ if (id) {
+ error_setg(errp, QERR_INVALID_PARAMETER, "id");
+ return NULL;
+ }
+ opts = qemu_opts_find(list, NULL);
+ if (opts) {
+ return opts;
+ }
+ } else if (id) {
+ assert(fail_if_exists);
if (!id_wellformed(id)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id",
"an identifier");
@@ -629,17 +639,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char
*id,
}
opts = qemu_opts_find(list, id);
if (opts != NULL) {
- if (fail_if_exists && !list->merge_lists) {
- error_setg(errp, "Duplicate ID '%s' for %s", id, list->name);
- return NULL;
- } else {
- return opts;
- }
- }
- } else if (list->merge_lists) {
- opts = qemu_opts_find(list, NULL);
- if (opts) {
- return opts;
+ error_setg(errp, "Duplicate ID '%s' for %s", id, list->name);
+ return NULL;
}
}
opts = g_malloc0(sizeof(*opts));
@@ -893,7 +894,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char
*params,
* (if unlikely) future misuse:
*/
assert(!defaults || list->merge_lists);
- opts = qemu_opts_create(list, id, !defaults, errp);
+ opts = qemu_opts_create(list, id, !list->merge_lists, errp);
g_free(id);
if (opts == NULL) {
return NULL;
--
2.26.2
[PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists,
Paolo Bonzini <=
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Markus Armbruster, 2020/11/09
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Paolo Bonzini, 2020/11/09
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Markus Armbruster, 2020/11/09
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Paolo Bonzini, 2020/11/09
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Markus Armbruster, 2020/11/10
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Paolo Bonzini, 2020/11/10
- Re: [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists, Markus Armbruster, 2020/11/10
[PATCH v2 5/6] qemu-option: move help handling to get_opt_name_value, Paolo Bonzini, 2020/11/09