From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDjNY-0004IY-Ns for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:38:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDjNU-0006CH-AK for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:38:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDjNU-0006CA-1n for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:38:04 -0500 Message-ID: <52FBFCF4.40307@redhat.com> Date: Wed, 12 Feb 2014 16:00:04 -0700 From: Eric Blake MIME-Version: 1.0 References: <1392186806-10418-1-git-send-email-cyliu@suse.com> <1392186806-10418-2-git-send-email-cyliu@suse.com> In-Reply-To: <1392186806-10418-2-git-send-email-cyliu@suse.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AV8XMRKpCW3ctem5dTAhP702aBDe5JQvf" 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: Chunyan Liu , qemu-devel@nongnu.org Cc: kwolf@redhat.com, Dong Xu Wang , stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --AV8XMRKpCW3ctem5dTAhP702aBDe5JQvf Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 02/11/2014 11:33 PM, Chunyan Liu wrote: > Add def_value_str (default value) to QemuOptDesc, to replace function o= f the > default value in QEMUOptionParameter. And improved related functions. >=20 > 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(-) > =20 > +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 =3D 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 =3D qemu_opt_find(opts, name); > + const QemuOptDesc *desc; > + Error *local_err =3D NULL; Drop this, > =20 > - if (opt =3D=3D NULL) > + if (opt =3D=3D NULL) { > + desc =3D find_desc_by_name(opts->list->desc, name); > + if (desc && desc->def_value_str) { > + parse_option_bool(name, desc->def_value_str, &defval, &loc= al_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 =3D opts->list->desc; > =20 > - fprintf(stderr, "%s: %s:", opts->list->name, > - opts->id ? opts->id : ""); > - QTAILQ_FOREACH(opt, &opts->head, next) { > - fprintf(stderr, " %s=3D\"%s\"", opt->name, opt->str); > + if (desc[0].name =3D=3D NULL) { > + QTAILQ_FOREACH(opt, &opts->head, next) { > + printf("%s=3D\"%s\" ", opt->name, opt->str); Why the swap from stderr to stdout? > + } > + return; > + } > + for (; desc && desc->name; desc++) { > + const char *value =3D desc->def_value_str; > + QemuOpt *opt; > + > + opt =3D qemu_opt_find(opts, desc->name); Is this a needless case of O(n^2) complexity? > + if (opt) { > + value =3D opt->str; > + } > + > + if (!value) { > + continue; > + } > + > + if (desc->type =3D=3D QEMU_OPT_STRING) { > + printf("%s=3D'%s' ", desc->name, value); > + } else if (desc->type =3D=3D QEMU_OPT_SIZE && opt) { > + printf("%s=3D%" PRIu64 " ", desc->name, opt->value.uint); > + } else { > + printf("%s=3D%s ", desc->name, value); > + } > } > - fprintf(stderr, "\n"); Why the lost newline at the end of the loop? > - return 0; > } > =20 > static int opts_do_parse(QemuOpts *opts, const char *params, >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --AV8XMRKpCW3ctem5dTAhP702aBDe5JQvf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJS+/z0AAoJEKeha0olJ0NqU5IH/1gw9yOWR3kajrUb14TAqjBs 67fsQiJEUihKxikAxEmVvBHJFYT86TtWEFEcVVAeSE24bQ2Vr/xqXLKbywCNCYxc v9h0AKxX28gLzy/K4z+fRB8gK0sUZsmZ/6gHIIft1qevSP+gqhUVgjns9KcL8w5G DyQtPL13FTPEavFhxbyiAfV9ULtcBpXwBd+MzVqOJyLedvrAGTkf4Yh3OpfZbD+U XFmO0+hNpJ3AVc/LOTEqiiemARdk0mhKDsUi5Ch4J8PZv0UmHQgbggtVK17qI6iW 2K0TrxBLvZxA5qR4+ryOn9um92HWcIQbnuRC45kBMSCUzulWIGod1LilSoiEXw4= =YVKe -----END PGP SIGNATURE----- --AV8XMRKpCW3ctem5dTAhP702aBDe5JQvf--