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>
This commit is contained in:
Paolo Bonzini 2020-11-09 03:50:46 -05:00
parent 924e9b0da9
commit 45c53fe64c

View File

@ -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);