[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/28] qemu-option: pass QemuOptsList to opts_accepts_any
From: |
Paolo Bonzini |
Subject: |
[PATCH 02/28] qemu-option: pass QemuOptsList to opts_accepts_any |
Date: |
Wed, 2 Dec 2020 04:02:39 -0500 |
A QemuOptsList can be of one of two kinds: either it is pre-validated, or
it accepts any key and validation happens somewhere else (typically in
a Visitor or against a list of QOM properties). opts_accepts_any
returns true if a QemuOpts instance was created from a QemuOptsList of
the latter kind, but there is no function to do the check on a QemuOptsList.
We will need it in the next patch; since almost all callers of
opts_accepts_any use opts->list anyway, simply repurpose it instead
of adding a new function.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/qemu-option.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6bd654a473..c88e159f18 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -460,16 +460,16 @@ static bool qemu_opt_parse(QemuOpt *opt, Error **errp)
}
}
-static bool opts_accepts_any(const QemuOpts *opts)
+static bool opts_accepts_any(const QemuOptsList *list)
{
- return opts->list->desc[0].name == NULL;
+ return list->desc[0].name == NULL;
}
int qemu_opt_unset(QemuOpts *opts, const char *name)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- assert(opts_accepts_any(opts));
+ assert(opts_accepts_any(opts->list));
if (opt == NULL) {
return -1;
@@ -500,9 +500,10 @@ static bool opt_validate(QemuOpt *opt, bool *help_wanted,
Error **errp)
{
const QemuOptDesc *desc;
+ const QemuOptsList *list = opt->opts->list;
- desc = find_desc_by_name(opt->opts->list->desc, opt->name);
- if (!desc && !opts_accepts_any(opt->opts)) {
+ desc = find_desc_by_name(list->desc, opt->name);
+ if (!desc && !opts_accepts_any(list)) {
error_setg(errp, QERR_INVALID_PARAMETER, opt->name);
if (help_wanted && is_help_option(opt->name)) {
*help_wanted = true;
@@ -535,9 +536,10 @@ bool qemu_opt_set_bool(QemuOpts *opts, const char *name,
bool val,
{
QemuOpt *opt;
const QemuOptDesc *desc;
+ const QemuOptsList *list = opts->list;
- desc = find_desc_by_name(opts->list->desc, name);
- if (!desc && !opts_accepts_any(opts)) {
+ desc = find_desc_by_name(list->desc, name);
+ if (!desc && !opts_accepts_any(list)) {
error_setg(errp, QERR_INVALID_PARAMETER, name);
return false;
}
@@ -557,9 +559,10 @@ bool qemu_opt_set_number(QemuOpts *opts, const char *name,
int64_t val,
{
QemuOpt *opt;
const QemuOptDesc *desc;
+ const QemuOptsList *list = opts->list;
- desc = find_desc_by_name(opts->list->desc, name);
- if (!desc && !opts_accepts_any(opts)) {
+ desc = find_desc_by_name(list->desc, name);
+ if (!desc && !opts_accepts_any(list)) {
error_setg(errp, QERR_INVALID_PARAMETER, name);
return false;
}
@@ -1107,7 +1110,7 @@ bool qemu_opts_validate(QemuOpts *opts, const QemuOptDesc
*desc, Error **errp)
{
QemuOpt *opt;
- assert(opts_accepts_any(opts));
+ assert(opts_accepts_any(opts->list));
QTAILQ_FOREACH(opt, &opts->head, next) {
opt->desc = find_desc_by_name(desc, opt->name);
--
2.26.2
- [PATCH 00/28] qemu-option, keyval, vl: switch -object/-M/-accel to keyval parsing, Paolo Bonzini, 2020/12/02
- [PATCH 03/28] qemu-option: clean up id vs. list->merge_lists, Paolo Bonzini, 2020/12/02
- [PATCH 04/28] qemu-option: move help handling to get_opt_name_value, Paolo Bonzini, 2020/12/02
- [PATCH 02/28] qemu-option: pass QemuOptsList to opts_accepts_any,
Paolo Bonzini <=
- [PATCH 01/28] qemu-option: simplify search for end of key, Paolo Bonzini, 2020/12/02
- [PATCH 05/28] qemu-option: warn for short-form boolean options, Paolo Bonzini, 2020/12/02
- [PATCH 06/28] keyval: accept escaped commas in implied option, Paolo Bonzini, 2020/12/02
- [PATCH 11/28] qom: use qemu_printf to print help for user-creatable objects, Paolo Bonzini, 2020/12/02
- [PATCH 07/28] keyval: simplify keyval_parse_one, Paolo Bonzini, 2020/12/02
- [PATCH 08/28] tests: convert check-qom-proplist to keyval, Paolo Bonzini, 2020/12/02
- [PATCH 09/28] keyval: introduce keyval_parse_into, Paolo Bonzini, 2020/12/02
- [PATCH 19/28] qemu-io: use keyval for -object parsing, Paolo Bonzini, 2020/12/02
- [PATCH 25/28] vl: rename local variable in configure_accelerators, Paolo Bonzini, 2020/12/02
- [PATCH 24/28] qom: export more functions for use with non-UserCreatable objects, Paolo Bonzini, 2020/12/02