From nobody Mon Feb 9 00:01:35 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 1486124127907468.0991755443762; Fri, 3 Feb 2017 04:15:27 -0800 (PST) Received: from localhost ([::1]:33747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZcly-0003rW-0i for importer@patchew.org; Fri, 03 Feb 2017 07:15:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZcbU-00039V-O5 for qemu-devel@nongnu.org; Fri, 03 Feb 2017 07:04:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZcbR-0001nh-IM for qemu-devel@nongnu.org; Fri, 03 Feb 2017 07:04:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZcaC-0000SD-5Y; Fri, 03 Feb 2017 07:03:16 -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 F1EE94D6A5; Fri, 3 Feb 2017 12:03:15 +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 v13C30q9002011; Fri, 3 Feb 2017 07:03:13 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 3 Feb 2017 12:02:52 +0000 Message-Id: <20170203120254.15062-5-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.26]); Fri, 03 Feb 2017 12:03:16 +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 4/6] qemu-img: add support for -o arg to dd 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 -o arg to the convert command allows specification of format/protocol options for the newly created image. This adds a -o arg to the dd command to get feature parity. Signed-off-by: Daniel P. Berrange Reviewed-by: Max Reitz --- qemu-img-cmds.hx | 2 +- qemu-img.c | 32 +++++++++++++++++++++++++++++++- qemu-img.texi | 6 ++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index b2c5424..2488cbe 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -46,7 +46,7 @@ STEXI ETEXI =20 DEF("dd", img_dd, - "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=3Dblock_size] [count= =3Dblocks] [skip=3Dblocks] [conv=3Dnocreat,notrunc] if=3Dinput of=3Doutput") + "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") 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 c9ab9e5..39fcf09 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3949,6 +3949,7 @@ static int img_dd(int argc, char **argv) int c, i; const char *out_fmt =3D "raw"; const char *fmt =3D NULL; + char *optionstr =3D NULL; int64_t size =3D 0, out_size; int64_t block_count =3D 0, out_pos, in_pos; struct DdInfo dd =3D { @@ -3984,7 +3985,7 @@ static int img_dd(int argc, char **argv) { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, "hnf:O:", long_options, NULL))) { + while ((c =3D getopt_long(argc, argv, "hno:f:O:", long_options, NULL))= ) { if (c =3D=3D EOF) { break; } @@ -3995,6 +3996,20 @@ static int img_dd(int argc, char **argv) case 'f': fmt =3D optarg; break; + case 'o': + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + ret =3D -1; + goto out; + } + if (!optionstr) { + optionstr =3D g_strdup(optarg); + } else { + char *old_options =3D optionstr; + optionstr =3D g_strdup_printf("%s,%s", optionstr, optarg); + g_free(old_options); + } + break; case '?': error_report("Try 'qemu-img --help' for more information."); ret =3D -1; @@ -4055,6 +4070,11 @@ static int img_dd(int argc, char **argv) goto out; } =20 + if (optionstr && has_help_option(optionstr)) { + ret =3D print_block_option_help(out.filename, out_fmt); + goto out; + } + if (qemu_opts_foreach(&qemu_object_opts, user_creatable_add_opts_foreach, NULL, NULL)) { @@ -4099,6 +4119,15 @@ static int img_dd(int argc, char **argv) create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); =20 opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); + + if (optionstr) { + qemu_opts_do_parse(opts, optionstr, NULL, &local_err); + if (local_err) { + error_report_err(local_err); + ret =3D -1; + goto out; + } + } } =20 size =3D blk_getlength(blk1); @@ -4224,6 +4253,7 @@ static int img_dd(int argc, char **argv) =20 out: g_free(arg); + g_free(optionstr); qemu_opts_del(opts); qemu_opts_free(create_opts); blk_unref(blk1); diff --git a/qemu-img.texi b/qemu-img.texi index 9f10562..01acfb8 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -326,10 +326,12 @@ skipped. This is useful for formats such as @code{rbd= } if the target volume has already been created with site specific options that cannot be supplied through qemu-img. =20 -@item dd [-f @var{fmt}] [-O @var{output_fmt}] [bs=3D@var{block_size}] [cou= nt=3D@var{blocks}] [skip=3D@var{blocks}] [conv=3Dnocreat,notrunc] if=3D@var= {input} of=3D@var{output} +@item dd [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [bs=3D@va= r{block_size}] [count=3D@var{blocks}] [skip=3D@var{blocks}] [conv=3Dnocreat= ,notrunc] if=3D@var{input} of=3D@var{output} =20 Dd copies from @var{input} file to @var{output} file converting it from -@var{fmt} format to @var{output_fmt} format. +@var{fmt} format to @var{output_fmt} format. Depending on the output file +format, you can add one or more @var{options} that enable additional +features of this format. =20 The data is by default read and written using blocks of 512 bytes but can = be modified by specifying @var{block_size}. If count=3D@var{blocks} is specif= ied --=20 2.9.3