From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFelY-0007Ol-Vt for qemu-devel@nongnu.org; Tue, 18 Feb 2014 02:06:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFelX-0003u3-FL for qemu-devel@nongnu.org; Tue, 18 Feb 2014 02:06:52 -0500 Received: from mail-ve0-x233.google.com ([2607:f8b0:400c:c01::233]:43939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFelX-0003tz-8y for qemu-devel@nongnu.org; Tue, 18 Feb 2014 02:06:51 -0500 Received: by mail-ve0-f179.google.com with SMTP id jx11so12865324veb.24 for ; Mon, 17 Feb 2014 23:06:50 -0800 (PST) MIME-Version: 1.0 Sender: kgrace.liu@gmail.com In-Reply-To: <52FBFCF4.40307@redhat.com> References: <1392186806-10418-1-git-send-email-cyliu@suse.com> <1392186806-10418-2-git-send-email-cyliu@suse.com> <52FBFCF4.40307@redhat.com> Date: Tue, 18 Feb 2014 15:06:50 +0800 Message-ID: From: Chunyan Liu Content-Type: multipart/alternative; boundary=001a11c2c102921ee404f2a8ea25 Subject: Re: [Qemu-devel] [PATCH v20 01/26] add def_value_str to QemuOptDesc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , Dong Xu Wang , qemu-devel@nongnu.org, stefanha@redhat.com --001a11c2c102921ee404f2a8ea25 Content-Type: text/plain; charset=UTF-8 2014-02-13 7:00 GMT+08:00 Eric Blake : > 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 > > Signed-off-by: Chunyan Liu > > --- > > 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 : ""); > > - 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 > > --001a11c2c102921ee404f2a8ea25 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



2014-02-13 7:00 GMT+08:00 Eric Blake <eblake@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.<= br> >
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu= @suse.com>
> ---
> =C2=A0include/qemu/option.h | =C2=A0 =C2=A03 +-
> =C2=A0util/qemu-option.c =C2=A0 =C2=A0| =C2=A0 76 ++++++++++++++++++++= ++++++++++++++++++++++------
> =C2=A02 files changed, 68 insertions(+), 11 deletions(-)

>
> +static const QemuOptDesc *find_desc_by_name(con= st QemuOptDesc *desc,
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0const char *name);
> +

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

=C2=A0Just for easier review. C= ould sort too.

> =C2=A0const char *qemu_opt_get(QemuOpts *opts, const char *name)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, name);
> + =C2=A0 =C2=A0const QemuOptDesc *desc;
> +
> + =C2=A0 =C2=A0if (!opt) {

If you wanted, you could sink the scope of desc to inside the if bloc= k.
=C2=A0But I'm also fine with it as-is.

> =C2=A0bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool de= fval)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, name);
> + =C2=A0 =C2=A0const QemuOptDesc *desc;
> + =C2=A0 =C2=A0Error *local_err =3D NULL;

Drop this,

>
> - =C2=A0 =C2=A0if (opt =3D=3D NULL)
> + =C2=A0 =C2=A0if (opt =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0desc =3D find_desc_by_name(opts->list-= >desc, name);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (desc && desc->def_value_st= r) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0parse_option_bool(name, des= c->def_value_str, &defval, &local_err);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assert(!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)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt;
> + =C2=A0 =C2=A0QemuOptDesc *desc =3D opts->list->desc;
>
> - =C2=A0 =C2=A0fprintf(stderr, "%s: %s:", opts->list->= name,
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0opts->id ? opts->id := "<noid>");
> - =C2=A0 =C2=A0QTAILQ_FOREACH(opt, &opts->head, next) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, " %s=3D\"%s\&qu= ot;", opt->name, opt->str);
> + =C2=A0 =C2=A0if (desc[0].name =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0QTAILQ_FOREACH(opt, &opts->head, n= ext) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("%s=3D\"%s= \" ", opt->name, opt->str);

Why the swap from stderr to stdout?

It's there since DongXu's v7~v18 :) Will correct that.
=
=C2=A0

> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> + =C2=A0 =C2=A0}
> + =C2=A0 =C2=A0for (; desc && desc->name; desc++) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0const char *value =3D desc->def_value_= str;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0QemuOpt *opt;
> +
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0opt =3D 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 li= st all options, if the opt
is set (qemu_opt_find could find it), then us= e opt->str; otherwise, if there
is def_value_str, use default value; it both not, skip it. It seems right.<= br>
=C2=A0

> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (opt) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0value =3D opt->str;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!value) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (desc->type =3D=3D QEMU_OPT_STRING)= {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("%s=3D'%s&#= 39; ", desc->name, value);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else if (desc->type =3D=3D QEMU_OPT_= SIZE && opt) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("%s=3D%" P= RIu64 " ", desc->name, opt->value.uint);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("%s=3D%s "= , desc->name, value);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0}
> - =C2=A0 =C2=A0fprintf(stderr, "\n");

Why the lost newline at the end of the loop?

> - =C2=A0 =C2=A0return 0;
> =C2=A0}
>
> =C2=A0static int opts_do_parse(QemuOpts *opts, const char *params,
>

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


--001a11c2c102921ee404f2a8ea25--