diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2020-12-15 21:24:31 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2020-12-15 21:24:31 +0000 |
commit | af3f37319cb1e1ca0c42842ecdbd1bcfc64a4b6f (patch) | |
tree | 101575a319b7c2f95e75ef44cf1483a87a564226 /util/qemu-option.c | |
parent | 657ee88ef3ec55c3a6164da88c11a6640ca7507c (diff) | |
parent | bbd2d5a8120771ec59b86a80a1f51884e0a26e53 (diff) |
Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging
* New -action option and set-action QMP command (Alejandro)
* More vl.c cleanup (myself with help from Daniel and Igor)
* Remove deprecated options (Philippe, Thomas)
* Dirty bitmap fix (Zenghui)
* icount caching speedup (Pavel)
* SCSI race fix (Maxim)
* Remove pre-GCC 4.8 code (Marc-André)
# gpg: Signature made Tue 15 Dec 2020 17:53:24 GMT
# gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg: issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" [full]
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1
# Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83
* remotes/bonzini-gitlab/tags/for-upstream: (45 commits)
build: -no-pie is no functional linker flag
scripts/git.orderfile: Keep files with .inc extension sorted
compiler.h: remove QEMU_GNUC_PREREQ
linux-user: remove GNUC check
compiler: remove GNUC check
xen: remove GNUC check
poison: remove GNUC check
compiler.h: explicit case for Clang printf attribute
virtiofsd: replace _Static_assert with QEMU_BUILD_BUG_ON
tests: remove GCC < 4 fallbacks
qemu-plugin.h: remove GCC < 4
compiler.h: remove GCC < 3 __builtin_expect fallback
accel/tcg: Remove special case for GCC < 4.6
qemu/atomic: Drop special case for unsupported compiler
hw/core: Restrict 'fw-path-provider.c' to system mode emulation
docs: set CONFDIR when running sphinx
vl: rename local variable in configure_accelerators
qemu-option: pass QemuOptsList to opts_accepts_any
qemu-option: simplify search for end of key
kvm: Take into account the unaligned section size when preparing bitmap
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
# Conflicts:
# softmmu/vl.c
Diffstat (limited to 'util/qemu-option.c')
-rw-r--r-- | util/qemu-option.c | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/util/qemu-option.c b/util/qemu-option.c index 25792159ba..c88e159f18 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -38,27 +38,19 @@ #include "qemu/help_option.h" /* - * Extracts the name of an option from the parameter string (p points at the + * Extracts the name of an option from the parameter string (@p points at the * first byte of the option name) * - * The option name is delimited by delim (usually , or =) or the string end - * and is copied into option. The caller is responsible for free'ing option - * when no longer required. + * The option name is @len characters long and is copied into @option. The + * caller is responsible for free'ing @option when no longer required. * * The return value is the position of the delimiter/zero byte after the option - * name in p. + * name in @p. */ -static const char *get_opt_name(const char *p, char **option, char delim) +static const char *get_opt_name(const char *p, char **option, size_t len) { - char *offset = strchr(p, delim); - - if (offset) { - *option = g_strndup(p, offset - p); - return offset; - } else { - *option = g_strdup(p); - return p + strlen(p); - } + *option = g_strndup(p, len); + return p + len; } /* @@ -468,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; @@ -508,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; @@ -543,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; } @@ -565,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; } @@ -766,12 +761,11 @@ static const char *get_opt_name_value(const char *params, const char *firstname, char **name, char **value) { - const char *p, *pe, *pc; - - pe = strchr(params, '='); - pc = strchr(params, ','); + const char *p; + size_t len; - if (!pe || (pc && pc < pe)) { + len = strcspn(params, "=,"); + if (params[len] != '=') { /* found "foo,more" */ if (firstname) { /* implicitly named first option */ @@ -779,7 +773,7 @@ static const char *get_opt_name_value(const char *params, p = get_opt_value(params, value); } else { /* option without value, must be a flag */ - p = get_opt_name(params, name, ','); + p = get_opt_name(params, name, len); if (strncmp(*name, "no", 2) == 0) { memmove(*name, *name + 2, strlen(*name + 2) + 1); *value = g_strdup("off"); @@ -789,7 +783,7 @@ static const char *get_opt_name_value(const char *params, } } else { /* found "foo=bar,more" */ - p = get_opt_name(params, name, '='); + p = get_opt_name(params, name, len); assert(*p == '='); p++; p = get_opt_value(p, value); @@ -1116,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); |