From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WY5mb-0002QV-FU for qemu-devel@nongnu.org; Wed, 09 Apr 2014 23:36:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WY5mZ-0003nx-Fb for qemu-devel@nongnu.org; Wed, 09 Apr 2014 23:36:09 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:53010) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WY5mY-0003ni-WC for qemu-devel@nongnu.org; Wed, 09 Apr 2014 23:36:07 -0400 Received: by mail-we0-f180.google.com with SMTP id p61so3293963wes.25 for ; Wed, 09 Apr 2014 20:36:06 -0700 (PDT) MIME-Version: 1.0 Sender: kgrace.liu@gmail.com In-Reply-To: <20140408013149.GA11200@dorilex-lnv.MultilaserAP> References: <1396518889-21681-1-git-send-email-cyliu@suse.com> <1396518889-21681-3-git-send-email-cyliu@suse.com> <20140408013149.GA11200@dorilex-lnv.MultilaserAP> Date: Thu, 10 Apr 2014 11:36:05 +0800 Message-ID: From: Chunyan Liu Content-Type: multipart/alternative; boundary=f46d043891ffca605704f6a7ea0c Subject: Re: [Qemu-devel] [PATCH v24 02/31] QemuOpts: add def_value_str to QemuOptDesc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Leandro Dorileo Cc: qemu-devel@nongnu.org, Stefan Hajnoczi --f46d043891ffca605704f6a7ea0c Content-Type: text/plain; charset=UTF-8 2014-04-08 9:31 GMT+08:00 Leandro Dorileo : > On Thu, Apr 03, 2014 at 05:54:20PM +0800, Chunyan Liu wrote: > > Add def_value_str (default value) to QemuOptDesc, to replace function of > the > > default value in QEMUOptionParameter. > > > > Improve qemu_opts_get_* functions: if find opt, return opt->str; > otherwise, > > if desc->def_value_str is set, return desc->def_value_str; otherwise, > return > > input defval. > > > > Improve qemu_opts_print: if option is set, print opt->str; otherwise, if > > desc->def_value_str is set, also print it. > > > > Reviewed-by: Eric Blake > > Signed-off-by: Dong Xu Wang > > Signed-off-by: Chunyan Liu > > --- > > include/qemu/option.h | 3 ++- > > util/qemu-option.c | 56 > ++++++++++++++++++++++++++++++++++++++++++--------- > > 2 files changed, 49 insertions(+), 10 deletions(-) > > > > diff --git a/include/qemu/option.h b/include/qemu/option.h > > index 8c0ac34..c3b0a91 100644 > > --- a/include/qemu/option.h > > +++ b/include/qemu/option.h > > @@ -99,6 +99,7 @@ typedef struct QemuOptDesc { > > const char *name; > > enum QemuOptType type; > > const char *help; > > + const char *def_value_str; > > } QemuOptDesc; > > > I still think you don't need to define the default value as a string to > later > parse it, see what I mean > https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg04273.html > > But I think we can live with it. See bellow, if you fix the issue you can > add my Reviewed-by. > > > > > > struct QemuOptsList { > > @@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict > *qdict); > > void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); > > > > typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); > > -int qemu_opts_print(QemuOpts *opts, void *dummy); > > +void qemu_opts_print(QemuOpts *opts); > > int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void > *opaque, > > int abort_on_failure); > > > > diff --git a/util/qemu-option.c b/util/qemu-option.c > > index e6d10bc..d5e80da 100644 > > --- a/util/qemu-option.c > > +++ b/util/qemu-option.c > > @@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const > char *name) > > const char *qemu_opt_get(QemuOpts *opts, const char *name) > > { > > QemuOpt *opt = qemu_opt_find(opts, name); > > + > > + if (!opt) { > > + const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, > name); > > + if (desc && desc->def_value_str) { > > + return desc->def_value_str; > > + } > > + } > > return opt ? opt->str : NULL; > > } > > > > @@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char > *name, bool defval) > > { > > QemuOpt *opt = qemu_opt_find(opts, name); > > > > - if (opt == NULL) > > + if (opt == NULL) { > > + const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, > name); > > + if (desc && desc->def_value_str) { > > + parse_option_bool(name, desc->def_value_str, &defval, > &error_abort); > > + } > > return defval; > > + } > > assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL); > > return opt->value.boolean; > > } > > @@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const > char *name, uint64_t defval) > > { > > QemuOpt *opt = qemu_opt_find(opts, name); > > > > - if (opt == NULL) > > + if (opt == NULL) { > > + const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, > name); > > + if (desc && desc->def_value_str) { > > + parse_option_number(name, desc->def_value_str, &defval, > > + &error_abort); > > + } > > return defval; > > + } > > assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER); > > return opt->value.uint; > > } > > @@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const > char *name, uint64_t defval) > > { > > QemuOpt *opt = qemu_opt_find(opts, name); > > > > - if (opt == NULL) > > + if (opt == NULL) { > > + const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, > name); > > + if (desc && desc->def_value_str) { > > + parse_option_size(name, desc->def_value_str, &defval, > &error_abort); > > + } > > return defval; > > + } > > assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE); > > return opt->value.uint; > > } > > @@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts) > > g_free(opts); > > } > > > > -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) { > > + fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str); > > + } > > + return; > > + } > > + for (; desc && desc->name; desc++) { > > + const char *value; > > + QemuOpt *opt = qemu_opt_find(opts, desc->name); > > + > > + value = opt ? opt->str : desc->def_value_str; > > + if (!value) { > > + continue; > > + } > > + if (desc->type == QEMU_OPT_STRING) { > > + fprintf(stderr, "%s='%s' ", desc->name, value); > > + } else { > > + fprintf(stderr, "%s=%s ", desc->name, value); > > + } > > } > > fprintf(stderr, "\n"); > > > > I see you removed this fprintf() in the commit > afe65f5c92694d551aaebc128233b623e8665d5e > Please do this change in this commit and avoid breaking the block tests in > further commits. > > This function won't be used until 0012-change-block-layer-to-support-both-QemuOpts-and-QEMU.patch. It won't break block tests. The commit afe65f5c92694d551aaebc128233b623e8665d5e could be squashed with this commit directly. I split it into two steps just to make each patch easy to review, since in previous version, switching fprintf to printf in this patch was complained. But sure I can merge these two patches if you still think it's better. Chunyan > -- > Leandro Dorileo > > > - return 0; > > } > > > > static int opts_do_parse(QemuOpts *opts, const char *params, > > -- > > 1.7.12.4 > > > > --f46d043891ffca605704f6a7ea0c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



2014-04-08 9:31 GMT+08:00 Leandro Dorileo <l@dorileo.org>:
On Thu, Apr 03, 2014 at 05:54:20PM +0800, Chunyan Liu wrote:
> Add def_value_str (default value) to QemuOptDesc, to replace function = of the
> default value in QEMUOptionParameter.
>
> Improve qemu_opts_get_* functions: if find opt, return opt->str; ot= herwise,
> if desc->def_value_str is set, return desc->def_value_str; other= wise, return
> input defval.
>
> Improve qemu_opts_print: if option is set, print opt->str; otherwis= e, if
> desc->def_value_str is set, also print it.
>
> Reviewed-by: Eric Blake <eblak= e@redhat.com>
> 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=A03 ++-
> =C2=A0util/qemu-option.c =C2=A0 =C2=A0| 56 +++++++++++++++++++++++++++= +++++++++++++++---------
> =C2=A02 files changed, 49 insertions(+), 10 deletions(-)
>
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 8c0ac34..c3b0a91 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
> =C2=A0 =C2=A0 =C2=A0const char *name;
> =C2=A0 =C2=A0 =C2=A0enum QemuOptType type;
> =C2=A0 =C2=A0 =C2=A0const char *help;
> + =C2=A0 =C2=A0const char *def_value_str;
> =C2=A0} QemuOptDesc;


I still think you don't need to define the default value as a string to= later
parse it, see what I mean https://lists.gnu.org/arch= ive/html/qemu-devel/2014-03/msg04273.html

But I think we can live with it. See bellow, if you fix the issue you can a= dd my Reviewed-by.


>
> =C2=A0struct QemuOptsList {
> @@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *q= dict);
> =C2=A0void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error = **errp);
>
> =C2=A0typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);=
> -int qemu_opts_print(QemuOpts *opts, void *dummy);
> +void qemu_opts_print(QemuOpts *opts);
> =C2=A0int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc fun= c, void *opaque,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0int abort_on_failure);
>
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index e6d10bc..d5e80da 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, con= st char *name)
> =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=A0if (!opt) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0const QemuOptDesc *desc =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=A0return desc->def_value_s= tr;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> + =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0return opt ? opt->str : NULL;
> =C2=A0}
>
> @@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char= *name, bool defval)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, name);
>
> - =C2=A0 =C2=A0if (opt =3D=3D NULL)
> + =C2=A0 =C2=A0if (opt =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0const QemuOptDesc *desc =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, &error_abort);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return defval;
> + =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0assert(opt->desc && opt->desc->ty= pe =3D=3D QEMU_OPT_BOOL);
> =C2=A0 =C2=A0 =C2=A0return opt->value.boolean;
> =C2=A0}
> @@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, cons= t char *name, uint64_t defval)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, name);
>
> - =C2=A0 =C2=A0if (opt =3D=3D NULL)
> + =C2=A0 =C2=A0if (opt =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0const QemuOptDesc *desc =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_number(name, d= esc->def_value_str, &defval,
> + =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&error_abort);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return defval;
> + =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0assert(opt->desc && opt->desc->ty= pe =3D=3D QEMU_OPT_NUMBER);
> =C2=A0 =C2=A0 =C2=A0return opt->value.uint;
> =C2=A0}
> @@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const = char *name, uint64_t defval)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, name);
>
> - =C2=A0 =C2=A0if (opt =3D=3D NULL)
> + =C2=A0 =C2=A0if (opt =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0const QemuOptDesc *desc =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_size(name, des= c->def_value_str, &defval, &error_abort);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return defval;
> + =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0assert(opt->desc && opt->desc->ty= pe =3D=3D QEMU_OPT_SIZE);
> =C2=A0 =C2=A0 =C2=A0return opt->value.uint;
> =C2=A0}
> @@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts)
> =C2=A0 =C2=A0 =C2=A0g_free(opts);
> =C2=A0}
>
> -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=A0fprintf(stderr, "%s=3D= \"%s\" ", opt->name, opt->str);
> + =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;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0QemuOpt *opt =3D qemu_opt_find(opts, desc= ->name);
> +
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0value =3D opt ? opt->str : desc->de= f_value_str;
> + =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=A0fprintf(stderr, "%s=3D= '%s' ", desc->name, value);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "%s=3D= %s ", desc->name, value);
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "\n");



I see you removed this fprintf() in the commit afe65f5c92694d551aaebc128233= b623e8665d5e
Please do this change in this commit and avoid breaking the block tests in<= br> further commits.


This function won't be used until 0012-change-block-la= yer-to-support-both-QemuOpts-and-QEMU.patch.
It won't bre= ak block tests. The commit afe65f5c92694d551aaebc128233b623e8665d5e
could be squashed with this commit directly. I split it into two steps just= to make
each patch easy to review, since in previous version, switching= fprintf to printf
in this patch was complained. But sure I can merge th= ese two patches=C2=A0 if you
still think it's better.

Chunyan
=
=C2=A0
--
Leandro Dorileo

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


--f46d043891ffca605704f6a7ea0c--