From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] block: Image file option amendment
Date: Wed, 28 Aug 2013 12:03:25 +0200 [thread overview]
Message-ID: <20130828100325.GD2743@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <1377677336-15804-2-git-send-email-mreitz@redhat.com>
Am 28.08.2013 um 10:08 hat Max Reitz geschrieben:
> This patch adds the "amend" option to qemu-img which allows changing
> image options on existing image files. It also adds the generic bdrv
> implementation which is basically just a wrapper for the image format
> specific function.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 8 +++++
> include/block/block.h | 2 ++
> include/block/block_int.h | 3 ++
> qemu-img-cmds.hx | 6 ++++
> qemu-img.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
> qemu-img.texi | 5 +++
> 6 files changed, 114 insertions(+)
> +static int img_amend(int argc, char **argv)
> +{
> + int c, ret = 0;
> + char *options = NULL;
> + QEMUOptionParameter *create_options = NULL, *options_param = NULL;
> + const char *fmt = NULL, *filename;
> + bool quiet = false;
> + BlockDriverState *bs = NULL;
> + BlockDriver *bdrv;
> +
> + for (;;) {
> + c = getopt(argc, argv, "h?qf:o:");
> + if (c == -1) {
> + break;
> + }
> +
> + switch (c) {
> + case 'h':
> + case '?':
> + help();
> + break;
> + case 'o':
> + options = optarg;
> + break;
> + case 'f':
> + fmt = optarg;
> + break;
> + case 'q':
> + quiet = true;
> + break;
> + }
> + }
> +
> + if (optind != argc - 1) {
> + help();
> + }
> +
> + if (!options) {
> + help();
> + }
> +
> + filename = argv[argc - 1];
> +
> + bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
> + if (!bs) {
> + error_report("Could not open image.");
> + ret = -1;
> + goto out;
> + }
> +
> + bdrv = bs->drv;
> + if (!bdrv) {
This can't happen. A successful bdrv_open() always results in a
BlockDriverState that has a driver assigned.
> + error_report("No driver found for this image file.");
> + ret = -1;
> + goto out;
> + }
> +
> + fmt = bdrv->format_name;
> +
> + if (is_help_option(options)) {
> + ret = print_block_option_help(filename, fmt);
> + goto out;
> + }
> +
> + create_options = append_option_parameters(create_options,
> + bdrv->create_options);
> + options_param = parse_option_parameters(options, create_options,
> + options_param);
> + if (options_param == NULL) {
> + error_report("Invalid options for file format '%s'.", fmt);
> + ret = -1;
> + goto out;
> + }
> +
> + ret = bdrv_amend_options(bs, options_param);
> + if (ret < 0) {
> + error_report("Error while amending options: %s", strerror(-ret));
> + goto out;
> + }
> +
> +out:
> + if (bs) {
> + bdrv_delete(bs);
> + }
> + if (ret) {
> + return 1;
> + }
> + return 0;
> +}
Some free_option_parameters() calls are missing here.
Kevin
next prev parent reply other threads:[~2013-08-28 10:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-28 8:08 [Qemu-devel] [PATCH 0/3] block/qcow2: Image file option amendment Max Reitz
2013-08-28 8:08 ` [Qemu-devel] [PATCH 1/3] block: " Max Reitz
2013-08-28 10:03 ` Kevin Wolf [this message]
2013-08-28 12:22 ` Eric Blake
2013-08-28 12:26 ` Kevin Wolf
2013-08-28 8:08 ` [Qemu-devel] [PATCH 2/3] qcow2: Implement bdrv_amend_options Max Reitz
2013-08-28 11:06 ` Kevin Wolf
2013-08-28 11:39 ` Max Reitz
2013-08-28 11:48 ` Kevin Wolf
2013-08-28 12:05 ` Max Reitz
2013-08-28 12:12 ` Kevin Wolf
2013-08-28 8:08 ` [Qemu-devel] [PATCH 3/3] qemu-iotest: qcow2 image option amendment Max Reitz
2013-08-28 11:40 ` Kevin Wolf
2013-08-28 11:47 ` Max Reitz
2013-08-28 11:54 ` Kevin Wolf
2013-08-28 12:06 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130828100325.GD2743@dhcp-200-207.str.redhat.com \
--to=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).