|
From: | Chunyan Liu |
Subject: | Re: [Qemu-devel] [PATCH v20 01/26] add def_value_str to QemuOptDesc |
Date: | Tue, 18 Feb 2014 15:06:50 +0800 |
On 02/11/2014 11:33 PM, Chunyan Liu wrote:
> Add def_value_str (default value) to QemuOptDesc, to replace function of the
> default value in QEMUOptionParameter. And improved related functions.
>
> Signed-off-by: Dong Xu Wang <address@hidden>
> Signed-off-by: Chunyan Liu <address@hidden>
> ---
> include/qemu/option.h | 3 +-
> util/qemu-option.c | 76 ++++++++++++++++++++++++++++++++++++++++++------
> 2 files changed, 68 insertions(+), 11 deletions(-)
>
> +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,Is this a situation where a topological sort would avoid the need for a
> + const char *name);
> +
forward declaration? But that's not the end of the world.
> const char *qemu_opt_get(QemuOpts *opts, const char *name)If you wanted, you could sink the scope of desc to inside the if block.
> {
> QemuOpt *opt = qemu_opt_find(opts, name);
> + const QemuOptDesc *desc;
> +
> + if (!opt) {
But I'm also fine with it as-is.
Drop this,
> bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> {
> QemuOpt *opt = qemu_opt_find(opts, name);
> + const QemuOptDesc *desc;
> + Error *local_err = NULL;
and change this to use error_abort instead of local_err.
>
> - if (opt == NULL)
> + if (opt == NULL) {
> + desc = find_desc_by_name(opts->list->desc, name);
> + if (desc && desc->def_value_str) {
> + parse_option_bool(name, desc->def_value_str, &defval, &local_err);
> + assert(!local_err);
Likewise to all the other qemu_opt_get_ functions.
Why the swap from stderr to stdout?
> -int qemu_opts_print(QemuOpts *opts, void *dummy)
> +void qemu_opts_print(QemuOpts *opts)
> {
> QemuOpt *opt;
> + QemuOptDesc *desc = opts->list->desc;
>
> - fprintf(stderr, "%s: %s:", opts->list->name,
> - opts->id ? opts->id : "<noid>");
> - QTAILQ_FOREACH(opt, &opts->head, next) {
> - fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
> + if (desc[0].name == NULL) {
> + QTAILQ_FOREACH(opt, &opts->head, next) {
> + printf("%s=\"%s\" ", opt->name, opt->str);
Is this a needless case of O(n^2) complexity?
> + }
> + return;
> + }
> + for (; desc && desc->name; desc++) {
> + const char *value = desc->def_value_str;
> + QemuOpt *opt;
> +
> + opt = qemu_opt_find(opts, desc->name);
Why the lost newline at the end of the loop?
> + if (opt) {
> + value = opt->str;
> + }
> +
> + if (!value) {
> + continue;
> + }
> +
> + if (desc->type == QEMU_OPT_STRING) {
> + printf("%s='%s' ", desc->name, value);
> + } else if (desc->type == QEMU_OPT_SIZE && opt) {
> + printf("%s=%" PRIu64 " ", desc->name, opt->value.uint);
> + } else {
> + printf("%s=%s ", desc->name, value);
> + }
> }
> - fprintf(stderr, "\n");
Eric Blake eblake redhat com +1-919-301-3266
> - return 0;
> }
>
> static int opts_do_parse(QemuOpts *opts, const char *params,
>
--
Libvirt virtualization library http://libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |