From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M643r-0004EC-T6 for qemu-devel@nongnu.org; Mon, 18 May 2009 10:43:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M643m-0004Cv-8R for qemu-devel@nongnu.org; Mon, 18 May 2009 10:43:27 -0400 Received: from [199.232.76.173] (port=38091 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M643l-0004CQ-Di for qemu-devel@nongnu.org; Mon, 18 May 2009 10:43:21 -0400 Received: from mx2.redhat.com ([66.187.237.31]:46491) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M643k-00081I-PS for qemu-devel@nongnu.org; Mon, 18 May 2009 10:43:21 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4IEhKku031609 for ; Mon, 18 May 2009 10:43:20 -0400 From: Kevin Wolf Date: Mon, 18 May 2009 16:42:12 +0200 Message-Id: <1242657732-29043-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1242657732-29043-1-git-send-email-kwolf@redhat.com> References: <1242657732-29043-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 4/4] Convert qemu-img convert to new bdrv_create List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf This is part two of the qemu-img conversion. This really works the same as the previous conversion of qemu-img create: It introduces a new -o option for the generic approach and adds the old-style options to this option set. Signed-off-by: Kevin Wolf --- qemu-img.c | 97 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 65 insertions(+), 32 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 0032979..3edf25a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -215,6 +215,32 @@ static BlockDriverState *bdrv_new_open(const char *filename, return bs; } +static void add_old_style_options(const char *fmt, QEMUOptionParameter *list, + int flags, const char *base_filename, const char *base_fmt) +{ + if (flags & BLOCK_FLAG_ENCRYPT) { + if (set_option_parameter(list, BLOCK_OPT_ENCRYPT, "on")) { + error("Encryption not supported for file format '%s'", fmt); + } + } + if (flags & BLOCK_FLAG_COMPAT6) { + if (set_option_parameter(list, BLOCK_OPT_COMPAT6, "on")) { + error("VMDK version 6 not supported for file format '%s'", fmt); + } + } + + if (base_filename) { + if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) { + error("Backing file not supported for file format '%s'", fmt); + } + } + if (base_fmt) { + if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) { + error("Backing file format not supported for file format '%s'", fmt); + } + } +} + static int img_create(int argc, char **argv) { int c, ret, flags; @@ -279,27 +305,7 @@ static int img_create(int argc, char **argv) } /* Add old-style options to parameters */ - if (flags & BLOCK_FLAG_ENCRYPT) { - if (set_option_parameter(param, BLOCK_OPT_ENCRYPT, "on")) { - error("Encryption not supported for file format '%s'", fmt); - } - } - if (flags & BLOCK_FLAG_COMPAT6) { - if (set_option_parameter(param, BLOCK_OPT_COMPAT6, "on")) { - error("VMDK version 6 not supported for file format '%s'", fmt); - } - } - - if (base_filename) { - if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE, base_filename)) { - error("Backing file not supported for file format '%s'", fmt); - } - } - if (base_fmt) { - if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) { - error("Backing file format not supported for file format '%s'", fmt); - } - } + add_old_style_options(fmt, param, flags, base_filename, base_fmt); // The size for the image must always be specified, with one exception: // If we are using a backing file, we can obtain the size from there @@ -525,13 +531,15 @@ static int img_convert(int argc, char **argv) uint8_t buf[IO_BUF_SIZE]; const uint8_t *buf1; BlockDriverInfo bdi; + QEMUOptionParameter *param = NULL; + char *options = NULL; fmt = NULL; out_fmt = "raw"; out_baseimg = NULL; flags = 0; for(;;) { - c = getopt(argc, argv, "f:O:B:hce6"); + c = getopt(argc, argv, "f:O:B:hce6o:"); if (c == -1) break; switch(c) { @@ -556,6 +564,9 @@ static int img_convert(int argc, char **argv) case '6': flags |= BLOCK_FLAG_COMPAT6; break; + case 'o': + options = optarg; + break; } } @@ -580,19 +591,41 @@ static int img_convert(int argc, char **argv) total_sectors += bs_sectors; } + /* Find driver and parse its options */ drv = bdrv_find_format(out_fmt); if (!drv) error("Unknown file format '%s'", out_fmt); - if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) - error("Compression not supported for this file format"); - if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) - error("Encryption not supported for this file format"); - if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk")) - error("Alternative compatibility level not supported for this file format"); - if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) - error("Compression and encryption not supported at the same time"); - - ret = bdrv_create2(drv, out_filename, total_sectors, out_baseimg, NULL, flags); + + if (options) { + param = parse_option_parameters(options, drv->create_options, param); + if (param == NULL) { + error("Invalid options for file format '%s'.", out_fmt); + } + } else { + param = parse_option_parameters("", drv->create_options, param); + } + + set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512); + add_old_style_options(out_fmt, param, flags, out_baseimg, NULL); + + /* Check if compression is supported */ + if (flags & BLOCK_FLAG_COMPRESS) { + QEMUOptionParameter *encryption = + get_option_parameter(param, BLOCK_OPT_ENCRYPT); + + if (!drv->bdrv_write_compressed) { + error("Compression not supported for this file format"); + } + + if (encryption && encryption->value.n) { + error("Compression and encryption not supported at the same time"); + } + } + + /* Create the new image */ + ret = bdrv_create(drv, out_filename, param); + free_option_parameters(param); + if (ret < 0) { if (ret == -ENOTSUP) { error("Formatting not supported for file format '%s'", out_fmt); -- 1.6.0.6