aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-11-09 03:50:46 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2020-12-15 12:52:06 -0500
commit45c53fe64c28239b7504d00d76fe37ef31c0eefa (patch)
tree01135eec11ca852db636b056141b80c94fb6611a /util
parent924e9b0da90ca1fa0de7c5076768a8a9f3795f8d (diff)
downloadqemu-45c53fe64c28239b7504d00d76fe37ef31c0eefa.zip
qemu-45c53fe64c28239b7504d00d76fe37ef31c0eefa.tar.gz
qemu-45c53fe64c28239b7504d00d76fe37ef31c0eefa.tar.bz2
qemu-option: pass QemuOptsList to opts_accepts_any
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. Since this property comes from the QemuOptsList and almost all callers of opts_accepts_any use opts->list anyway, modify the function to accept QemuOptsList. Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-option.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6bd654a..c88e159 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);