2014-02-13 7:00 GMT+08:00 Eric Blake <ebl...@redhat.com>: > 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 <wdon...@linux.vnet.ibm.com> > > Signed-off-by: Chunyan Liu <cy...@suse.com> > > --- > > 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. > > Just for easier review. Could sort too.
> 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? > It's there since DongXu's v7~v18 :) Will correct that. > > > + } > > + 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? > Sorry, I couldn't see it's needless. In a logic: to list all options, if the opt is set (qemu_opt_find could find it), then use opt->str; otherwise, if there is def_value_str, use default value; it both not, skip it. It seems right. > > > + 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 > >