From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMHxL-0004Bo-UW for qemu-devel@nongnu.org; Thu, 21 Jan 2016 11:19:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMHxK-00077V-Pl for qemu-devel@nongnu.org; Thu, 21 Jan 2016 11:19:31 -0500 Date: Thu, 21 Jan 2016 16:19:19 +0000 From: "Daniel P. Berrange" Message-ID: <20160121161919.GP19835@redhat.com> References: <1453199832-22523-1-git-send-email-berrange@redhat.com> <1453199832-22523-3-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1453199832-22523-3-git-send-email-berrange@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 02/10] qemu-img: add support for --object command line arg Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , Paolo Bonzini , Andreas =?utf-8?Q?F=C3=A4rber?= On Tue, Jan 19, 2016 at 10:37:04AM +0000, Daniel P. Berrange wrote: > Allow creation of user creatable object types with qemu-img > via a new --object command line arg. This will be used to supply > passwords and/or encryption keys to the various block driver > backends via the recently added 'secret' object type. > > # printf letmein > mypasswd.txt > # qemu-img info --object secret,id=sec0,file=mypasswd.txt \ > ...other info args... > > Signed-off-by: Daniel P. Berrange > --- > qemu-img-cmds.hx | 44 ++++----- > qemu-img.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- > qemu-img.texi | 8 ++ > 3 files changed, 288 insertions(+), 30 deletions(-) > +static int object_create(void *opaque, QemuOpts *opts, Error **errp) > +{ > + Error *err = NULL; > + OptsVisitor *ov; > + QDict *pdict; > + > + ov = opts_visitor_new(opts); > + pdict = qemu_opts_to_qdict(opts, NULL); > + > + user_creatable_add(pdict, opts_get_visitor(ov), &err); > + opts_visitor_cleanup(ov); > + QDECREF(pdict); > + if (err) { > + error_propagate(errp, err); > + return -1; > + } > + return 0; > +} > + > static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...) > { > int ret = 0; > @@ -273,9 +309,17 @@ static int img_create(int argc, char **argv) > char *options = NULL; > Error *local_err = NULL; > bool quiet = false; > + QemuOpts *opts; > > for(;;) { > - c = getopt(argc, argv, "F:b:f:he6o:q"); > + int option_index = 0; > + static const struct option long_options[] = { > + {"help", no_argument, 0, 'h'}, > + {"object", required_argument, 0, OPTION_OBJECT}, > + {0, 0, 0, 0} > + }; > + c = getopt_long(argc, argv, "F:b:f:he6o:q", > + long_options, &option_index); > if (c == -1) { > break; > } > @@ -317,6 +361,13 @@ static int img_create(int argc, char **argv) > case 'q': > quiet = true; > break; > + case OPTION_OBJECT: > + opts = qemu_opts_parse_noisily(qemu_find_opts("object"), > + optarg, true); > + if (!opts) { > + exit(1); > + } > + break; > } > } > > @@ -332,6 +383,12 @@ static int img_create(int argc, char **argv) > } > optind++; > > + if (qemu_opts_foreach(qemu_find_opts("object"), > + object_create, > + NULL, NULL)) { > + exit(1); I realize I neeed to pass '&local_err' as the last param and add error_report_err(local_err); before exiting, to get errors shown to the user. Likewise for the qemu-io/qemu-nbd patches. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|