qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v20 01/26] add def_value_str to QemuOptDesc


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v20 01/26] add def_value_str to QemuOptDesc
Date: Wed, 12 Feb 2014 16:00:04 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

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,
> +                                            const char *name);
> +

Is this a situation where a topological sort would avoid the need for a
forward declaration?  But that's not the end of the world.

>  const char *qemu_opt_get(QemuOpts *opts, const char *name)
>  {
>      QemuOpt *opt = qemu_opt_find(opts, name);
> +    const QemuOptDesc *desc;
> +
> +    if (!opt) {

If you wanted, you could sink the scope of desc to inside the if block.
 But I'm also fine with it as-is.

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

Drop this,

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

and change this to use error_abort instead of local_err.

Likewise to all the other qemu_opt_get_ functions.

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

Why the swap from stderr to stdout?

> +        }
> +        return;
> +    }
> +    for (; desc && desc->name; desc++) {
> +        const char *value = desc->def_value_str;
> +        QemuOpt *opt;
> +
> +        opt = qemu_opt_find(opts, desc->name);

Is this a needless case of O(n^2) complexity?

> +        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");

Why the lost newline at the end of the loop?

> -    return 0;
>  }
>  
>  static int opts_do_parse(QemuOpts *opts, const char *params,
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]