From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aBQS5-0001RA-ER for qemu-devel@nongnu.org; Tue, 22 Dec 2015 12:10:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aBQS4-0005QB-79 for qemu-devel@nongnu.org; Tue, 22 Dec 2015 12:10:21 -0500 References: <1450782389-17326-1-git-send-email-berrange@redhat.com> <1450782389-17326-7-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <567983F5.10400@redhat.com> Date: Tue, 22 Dec 2015 10:10:13 -0700 MIME-Version: 1.0 In-Reply-To: <1450782389-17326-7-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k2f2Lm9E9EWq4gKem4BrFnihRJfb3Ne6U" Subject: Re: [Qemu-devel] [PATCH 6/7] qemu-nbd: allow specifying image as a set of options args List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Markus Armbruster , qemu-block@nongnu.org, =?UTF-8?Q?Andreas_F=c3=a4rber?= This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --k2f2Lm9E9EWq4gKem4BrFnihRJfb3Ne6U Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/22/2015 04:06 AM, Daniel P. Berrange wrote: > Currently qemu-nbd allows an image filename to be passed on the > command line, but does not have a way to set any options except > the format eg >=20 > qemu-nbd https://127.0.0.1/images/centos7.iso > qemu-nbd /home/berrange/demo.qcow2 Well, technically we have: qemu-nbd json:{...} but I'm fine with adding the nicer syntax. >=20 > This adds a --source arg (that is mutually exclusive with a > positional filename arg and -f arg) that accepts a full option > string, as well as the original syntax eg >=20 > qemu-nbd --source driver=3Dhttp,url=3Dhttps://127.0.0.1/images,sslve= rify=3Doff > qemu-nbd --source https://127.0.0.1/images/centos7.iso > qemu-nbd --source file=3D/home/berrange/demo.qcow2 > qemu-nbd --source /home/berrange/demo.qcow2 >=20 > Signed-off-by: Daniel P. Berrange > --- > qemu-nbd.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++----= --- > 1 file changed, 50 insertions(+), 7 deletions(-) >=20 > diff --git a/qemu-nbd.c b/qemu-nbd.c > index b4b6681..0b9f99e 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -49,6 +49,7 @@ > #define QEMU_NBD_OPT_DISCARD 3 > #define QEMU_NBD_OPT_DETECT_ZEROES 4 > #define QEMU_NBD_OPT_OBJECT 5 > +#define QEMU_NBD_OPT_SOURCE 6 Same comment as earlier about this being safer if it is > 255. > @@ -486,6 +497,7 @@ int main(int argc, char **argv) > { "persistent", 0, NULL, 't' }, > { "verbose", 0, NULL, 'v' }, > { "object", 1, NULL, QEMU_NBD_OPT_OBJECT }, > + { "source", 1, NULL, QEMU_NBD_OPT_SOURCE }, Same comment as earlier on spelling this as required_argument. > { NULL, 0, NULL, 0 } > }; > int ch; > @@ -657,13 +669,23 @@ int main(int argc, char **argv) > exit(1); > } > break; > + case QEMU_NBD_OPT_SOURCE: > + if (srcpath) { > + errx(EXIT_FAILURE, "--source can only be used once"); Markus has a series getting rid of errx() usage; you'll want to follow su= it: https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg03492.html > + } > + if (!qemu_opts_parse_noisily(&file_opts, optarg, true)) { > + qemu_opts_reset(&file_opts); > + exit(EXIT_FAILURE); > + } > + srcpath =3D optarg; > + break; > case '?': > errx(EXIT_FAILURE, "Try `%s --help' for more information."= , > argv[0]); > } > } > =20 > - if ((argc - optind) !=3D 1) { > + if ((argc - optind) > 1) { Inner () are redundant. > errx(EXIT_FAILURE, "Invalid number of argument.\n" > "Try `%s --help' for more information.", > argv[0]); > @@ -757,15 +779,36 @@ int main(int argc, char **argv) > bdrv_init(); > atexit(bdrv_close_all); > =20 > - if (fmt) { > - options =3D qdict_new(); > - qdict_put(options, "driver", qstring_from_str(fmt)); > + if (srcpath) { > + char *file =3D NULL; > + opts =3D qemu_opts_find(&file_opts, NULL); > + if (fmt) { > + errx(EXIT_FAILURE, "--source and -f are mutually exclusive= "); > + } > + if ((argc - optind) > 1) { and again. > + errx(EXIT_FAILURE, "--source and filename are mutually exc= lusive"); More errx() to avoid. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --k2f2Lm9E9EWq4gKem4BrFnihRJfb3Ne6U Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWeYP1AAoJEKeha0olJ0NqkF0IAKfbhz74JKck8GZv61cr155x YgiFmoH82GSbm+HF/S/W+ugILORFQTaFxiHUR4ILEzhSu5hUpT2gitJGkIZNJqxZ bGyjwl1sVmtWVO9cUbOJnnv6acDMcaHU+aqo0RlL+eCTD9bO/5pi5OX4cF5AgGdk DwDqEp5bWNm1VYmbK3lKS78pjryn7P/SkUvaCCDDZYeVoO3NlYSYaMm7tONBUMFi 1QevwMq/xAL24XXOf9w3t8dhC+mVPhUBiR/rptfPh2XeVCs8Hz9M60I7E1vHUv1w TwXFt4cinWpj7vsyPR3vdRCHTxiwIDmMzjmqZuB1Gi07UOADdIGR2fxSq7PDamk= =rEWK -----END PGP SIGNATURE----- --k2f2Lm9E9EWq4gKem4BrFnihRJfb3Ne6U--