From nobody Sun Feb 8 20:52:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486124127124997.4746062442065; Fri, 3 Feb 2017 04:15:27 -0800 (PST) Received: from localhost ([::1]:33746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZclv-0003pV-K7 for importer@patchew.org; Fri, 03 Feb 2017 07:15:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZcbX-0003Bv-3e for qemu-devel@nongnu.org; Fri, 03 Feb 2017 07:04:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZcbU-0001sZ-R1 for qemu-devel@nongnu.org; Fri, 03 Feb 2017 07:04:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZcaF-0000V3-3A; Fri, 03 Feb 2017 07:03:19 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEDD161BB0; Fri, 3 Feb 2017 12:03:18 +0000 (UTC) Received: from t460.redhat.com (ovpn-117-145.ams2.redhat.com [10.36.117.145]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v13C30qA002011; Fri, 3 Feb 2017 07:03:16 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 3 Feb 2017 12:02:53 +0000 Message-Id: <20170203120254.15062-6-berrange@redhat.com> In-Reply-To: <20170203120254.15062-1-berrange@redhat.com> References: <20170203120254.15062-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 03 Feb 2017 12:03:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/6] qemu-img: introduce --target-image-opts for 'convert' command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The '--image-opts' flags indicates whether the source filename includes options. The target filename has to remain in the plain filename format though, since it needs to be passed to bdrv_create(). When using --skip-create though, it would be possible to use image-opts syntax. This adds --target-image-opts to indicate that the target filename includes options. Currently this mandates use of the --skip-create flag too. Signed-off-by: Daniel P. Berrange --- qemu-img-cmds.hx | 6 +-- qemu-img.c | 131 ++++++++++++++++++++++++++++++++++++---------------= ---- qemu-img.texi | 12 ++++- 3 files changed, 98 insertions(+), 51 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 2488cbe..13fded9 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -40,13 +40,13 @@ STEXI ETEXI =20 DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f f= mt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_= or_name] [-l snapshot_param] [-S sparse_size] filename [filename2 [...]] ou= tput_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [-c= ] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o opt= ions] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] filenam= e [filename2 [...]] output_filename") STEXI -@item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n= ] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}= ] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param= }] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{outpu= t_filename} +@item convert [--object @var{objectdef}] [--image-opts] [--target-image-op= ts] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}= ] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [= -l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filena= me2} [...]] @var{output_filename} ETEXI =20 DEF("dd", img_dd, - "dd [--image-opts] [-f fmt] [-O output_fmt] [-o options] [bs=3Dblock_s= ize] [count=3Dblocks] [skip=3Dblocks] [conv=3Dnocreat,notrunc] if=3Dinput o= f=3Doutput") + "dd [--image-opts] [--target-image-opts] [-f fmt] [-O output_fmt] [-o = options] [bs=3Dblock_size] [count=3Dblocks] [skip=3Dblocks] [conv=3Dnocreat= ,notrunc] if=3Dinput of=3Doutput") STEXI @item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=3D@var{bl= ock_size}] [count=3D@var{blocks}] [skip=3D@var{blocks}] [conv=3Dnocreat,not= runc] if=3D@var{input} of=3D@var{output} ETEXI diff --git a/qemu-img.c b/qemu-img.c index 39fcf09..dc4c6eb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -59,6 +59,7 @@ enum { OPTION_PATTERN =3D 260, OPTION_FLUSH_INTERVAL =3D 261, OPTION_NO_DRAIN =3D 262, + OPTION_TARGET_IMAGE_OPTS =3D 263, }; =20 typedef enum OutputFormat { @@ -1765,7 +1766,7 @@ static int img_convert(int argc, char **argv) int progress =3D 0, flags, src_flags; bool writethrough, src_writethrough; const char *fmt, *out_fmt, *cache, *src_cache, *out_baseimg, *out_file= name; - BlockDriver *drv, *proto_drv; + BlockDriver *drv =3D NULL, *proto_drv =3D NULL; BlockBackend **blk =3D NULL, *out_blk =3D NULL; BlockDriverState **bs =3D NULL, *out_bs =3D NULL; int64_t total_sectors; @@ -1783,9 +1784,10 @@ static int img_convert(int argc, char **argv) QemuOpts *sn_opts =3D NULL; ImgConvertState state; bool image_opts =3D false; + bool tgt_image_opts =3D false; =20 + out_fmt =3D NULL; fmt =3D NULL; - out_fmt =3D "raw"; cache =3D "unsafe"; src_cache =3D BDRV_DEFAULT_CACHE; out_baseimg =3D NULL; @@ -1796,6 +1798,7 @@ static int img_convert(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, {0, 0, 0, 0} }; c =3D getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qn", @@ -1900,15 +1903,27 @@ static int img_convert(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + case OPTION_TARGET_IMAGE_OPTS: + tgt_image_opts =3D true; + break; } } =20 + if (!out_fmt && !tgt_image_opts) { + out_fmt =3D "raw"; + } + if (qemu_opts_foreach(&qemu_object_opts, user_creatable_add_opts_foreach, NULL, NULL)) { goto fail_getopt; } =20 + if (tgt_image_opts && !skip_create) { + error_report("--target-image-opts requires use of -n flag"); + goto fail_getopt; + } + /* Initialize before goto out */ if (quiet) { progress =3D 0; @@ -1918,7 +1933,7 @@ static int img_convert(int argc, char **argv) bs_n =3D argc - optind - 1; out_filename =3D bs_n >=3D 1 ? argv[argc - 1] : NULL; =20 - if (options && has_help_option(options)) { + if (out_fmt && options && has_help_option(options)) { ret =3D print_block_option_help(out_filename, out_fmt); goto out; } @@ -1987,22 +2002,22 @@ static int img_convert(int argc, char **argv) goto out; } =20 - /* Find driver and parse its options */ - drv =3D bdrv_find_format(out_fmt); - if (!drv) { - error_report("Unknown file format '%s'", out_fmt); - ret =3D -1; - goto out; - } + if (!skip_create) { + /* Find driver and parse its options */ + drv =3D bdrv_find_format(out_fmt); + if (!drv) { + error_report("Unknown file format '%s'", out_fmt); + ret =3D -1; + goto out; + } =20 - proto_drv =3D bdrv_find_protocol(out_filename, true, &local_err); - if (!proto_drv) { - error_report_err(local_err); - ret =3D -1; - goto out; - } + proto_drv =3D bdrv_find_protocol(out_filename, true, &local_err); + if (!proto_drv) { + error_report_err(local_err); + ret =3D -1; + goto out; + } =20 - if (!skip_create) { if (!drv->create_opts) { error_report("Format driver '%s' does not support image creati= on", drv->format_name); @@ -2091,12 +2106,18 @@ static int img_convert(int argc, char **argv) goto out; } =20 - /* XXX we should allow --image-opts to trigger use of - * img_open() here, but then we have trouble with - * the bdrv_create() call which takes different params. - * Not critical right now, so fix can wait... - */ - out_blk =3D img_open_file(out_filename, out_fmt, flags, writethrough, = quiet); + if (skip_create) { + out_blk =3D img_open(tgt_image_opts, out_filename, out_fmt, + flags, writethrough, quiet); + } else { + /* TODO ultimately we should allow --target-image-opts + * to be used even when -n is not given. + * That has to wait for bdrv_create to be improved + * to allow filenames in option syntax + */ + out_blk =3D img_open_file(out_filename, out_fmt, + flags, writethrough, quiet); + } if (!out_blk) { ret =3D -1; goto out; @@ -3946,8 +3967,9 @@ static int img_dd(int argc, char **argv) QemuOptsList *create_opts =3D NULL; Error *local_err =3D NULL; bool image_opts =3D false; + bool tgt_image_opts =3D false; int c, i; - const char *out_fmt =3D "raw"; + const char *out_fmt =3D NULL; const char *fmt =3D NULL; char *optionstr =3D NULL; int64_t size =3D 0, out_size; @@ -3982,6 +4004,7 @@ static int img_dd(int argc, char **argv) { "help", no_argument, 0, 'h'}, { "object", required_argument, 0, OPTION_OBJECT}, { "image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, { 0, 0, 0, 0 } }; =20 @@ -4028,6 +4051,9 @@ static int img_dd(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + case OPTION_TARGET_IMAGE_OPTS: + tgt_image_opts =3D true; + break; } } =20 @@ -4064,13 +4090,22 @@ static int img_dd(int argc, char **argv) arg =3D NULL; } =20 + if (tgt_image_opts && !(dd.flags & C_NOCREAT)) { + error_report("--target-image-opts requires use of -n flag"); + goto out; + } + + if (!out_fmt && !tgt_image_opts) { + out_fmt =3D "raw"; + } + if (!(dd.flags & C_IF && dd.flags & C_OF)) { error_report("Must specify both input and output files"); ret =3D -1; goto out; } =20 - if (optionstr && has_help_option(optionstr)) { + if (out_fmt && optionstr && has_help_option(optionstr)) { ret =3D print_block_option_help(out.filename, out_fmt); goto out; } @@ -4088,21 +4123,21 @@ static int img_dd(int argc, char **argv) goto out; } =20 - drv =3D bdrv_find_format(out_fmt); - if (!drv) { - error_report("Unknown file format"); - ret =3D -1; - goto out; - } - proto_drv =3D bdrv_find_protocol(out.filename, true, &local_err); + if (!(dd.flags & C_NOCREAT)) { + drv =3D bdrv_find_format(out_fmt); + if (!drv) { + error_report("Unknown file format"); + ret =3D -1; + goto out; + } + proto_drv =3D bdrv_find_protocol(out.filename, true, &local_err); =20 - if (!proto_drv) { - error_report_err(local_err); - ret =3D -1; - goto out; - } + if (!proto_drv) { + error_report_err(local_err); + ret =3D -1; + goto out; + } =20 - if (!(dd.flags & C_NOCREAT)) { if (!drv->create_opts) { error_report("Format driver '%s' does not support image creati= on", drv->format_name); @@ -4152,7 +4187,6 @@ static int img_dd(int argc, char **argv) =20 if (!(dd.flags & C_NOCREAT)) { qemu_opt_set_number(opts, BLOCK_OPT_SIZE, out_size, &error_abort); - ret =3D bdrv_create(drv, out.filename, opts, &local_err); if (ret < 0) { error_reportf_err(local_err, @@ -4163,13 +4197,18 @@ static int img_dd(int argc, char **argv) } } =20 - /* TODO, we can't honour --image-opts for the target, - * since it needs to be given in a format compatible - * with the bdrv_create() call above which does not - * support image-opts style. - */ - blk2 =3D img_open_file(out.filename, out_fmt, BDRV_O_RDWR, - false, false); + if (dd.flags & C_NOCREAT) { + blk2 =3D img_open(tgt_image_opts, out.filename, out_fmt, + BDRV_O_RDWR, false, false); + } else { + /* TODO ultimately we should allow --target-image-opts + * to be used even when -n is not given. + * That has to wait for bdrv_create to be improved + * to allow filenames in option syntax + */ + blk2 =3D img_open_file(out.filename, out_fmt, + BDRV_O_RDWR, false, false); + } =20 if (!blk2) { ret =3D -1; diff --git a/qemu-img.texi b/qemu-img.texi index 01acfb8..bda3cc3 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -45,9 +45,17 @@ keys. =20 @item --image-opts =20 -Indicates that the @var{filename} parameter is to be interpreted as a +Indicates that the source @var{filename} parameter is to be interpreted as= a full option string, not a plain filename. This parameter is mutually -exclusive with the @var{-f} and @var{-F} parameters. +exclusive with the @var{-f} parameter. + +@item --target-image-opts + +Indicates that the target @var{filename} parameter(s) are to be interprete= d a +a full option string, not a plain filename. This parameter is mutually +exclusive with the @var{-F} or @var{-O} parameters. It is currently requir= ed +to also use the @var{-n} parameter to skip image creation. This restriction +will be relaxed in a future release. =20 @item fmt is the disk image format. It is guessed automatically in most cases. See b= elow --=20 2.9.3