From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXVH7-0001DT-IO for qemu-devel@nongnu.org; Wed, 10 Aug 2016 11:18:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXVH1-0005LK-Ny for qemu-devel@nongnu.org; Wed, 10 Aug 2016 11:18:32 -0400 References: <20160810024312.14544-1-fullmanet@gmail.com> From: Max Reitz Message-ID: Date: Wed, 10 Aug 2016 17:18:10 +0200 MIME-Version: 1.0 In-Reply-To: <20160810024312.14544-1-fullmanet@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Kqu2xIcXrBS4ktnRrqcUcLhIJqEfagA8G" Subject: Re: [Qemu-devel] [PATCH v9] qemu-img: add the 'dd' subcommand List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Reda Sallahi , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Fam Zheng , Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Kqu2xIcXrBS4ktnRrqcUcLhIJqEfagA8G From: Max Reitz To: Reda Sallahi , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Fam Zheng , Stefan Hajnoczi Message-ID: Subject: Re: [PATCH v9] qemu-img: add the 'dd' subcommand References: <20160810024312.14544-1-fullmanet@gmail.com> In-Reply-To: <20160810024312.14544-1-fullmanet@gmail.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 10.08.2016 04:43, Reda Sallahi wrote: > This patch adds a basic dd subcommand analogous to dd(1) to qemu-img. >=20 > For the start, this implements the bs, if, of and count options and req= uires > both if and of to be specified (no stdin/stdout if not specified) and d= oesn't > support tty, pipes, etc. >=20 > The image format must be specified with -O for the output if the raw fo= rmat > is not the intended one. >=20 > Two tests are added to test qemu-img dd. >=20 > Signed-off-by: Reda Sallahi > --- > Changes from v8: > * Add an overflow check. > Changes from v7: > * Remove a C99-style for loop. > Changes from v6: > * Remove get_size() to use qemu_strtosz_suffix() instead. > * Type changes for some fields in DdIo and DdInfo. > Changes from v5: > * Add dd sections on qemu-img.texi. > Changes from v4: > * Fix the exit status. > Changes from v3: > * Delete an unused (so far) field in DdIo. > Changes from v2: > * Add copyright headers to new files. > Changes from v1: > * Removal of dead code. > * Fix a memory leak. > * Complete the cleanup function in the test cases. >=20 > qemu-img-cmds.hx | 6 + > qemu-img.c | 303 +++++++++++++++++++++++++++++++= +++++++- > qemu-img.texi | 25 ++++ > tests/qemu-iotests/158 | 67 +++++++++ > tests/qemu-iotests/158.out | 15 ++ > tests/qemu-iotests/159 | 70 +++++++++ > tests/qemu-iotests/159.out | 87 +++++++++++ > tests/qemu-iotests/common.filter | 9 ++ > tests/qemu-iotests/common.rc | 5 +- > tests/qemu-iotests/group | 2 + > 10 files changed, 584 insertions(+), 5 deletions(-) > create mode 100755 tests/qemu-iotests/158 > create mode 100644 tests/qemu-iotests/158.out > create mode 100755 tests/qemu-iotests/159 > create mode 100644 tests/qemu-iotests/159.out [...] > diff --git a/qemu-img.c b/qemu-img.c > index d2865a5..034baf7 100644 > --- a/qemu-img.c > +++ b/qemu-img.c [...] > @@ -3794,6 +3801,300 @@ out: [...] > + size =3D blk_getlength(blk1); > + if (size < 0) { > + error_report("Failed to get size for '%s'", in.filename); > + ret =3D -1; > + goto out; > + } > + > + if (dd.flags & C_COUNT && dd.count <=3D INT64_MAX / in.bsz && > + dd.count * in.bsz < size) { > + size =3D dd.count * in.bsz; At first I wanted to object and say that we should throw an error if dd.count * in.bsz overflows. But you're right, since all bs and count do is limit the length of the data to copy, we can just consider them "infinite" (i.e. no limit) if there product overflows. Clever. Thanks, Reda, I've applied this patch to my block-next branch for the qemu 2.8 development window: https://github.com/XanClic/qemu/commits/block-next Max --Kqu2xIcXrBS4ktnRrqcUcLhIJqEfagA8G Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEvBAEBCAAZBQJXq0WyEhxtcmVpdHpAcmVkaGF0LmNvbQAKCRA7sUIC6DisrT9D CAClGVx2CpWzULyRBOYaQA7+DNYy3i75hakjPvLu2x+6duoWeivZIXd5xbx/u9NR oj3YPENAPHz2xKocVGwsw3QjfY8NBNNVBCx1y8wtSKbhHEOSdJ/oYBIyLELtiXYz S0wiBfLlSmykEKeTSSXVKZ2NEIVwbNabQtOuWIBAYywTc4yjVHs2lmeAORYc1Jyt cnZtMypxG1zhRKfB/SaECZ2W5OvbunxWgwJYN2e6+QIitzS7+grifDIQxNP/0E54 oak3gG3ouF7w0Jyo00YFBIXnWF7n0Ssjrq7W2rad3QW9Zq4HFLQl+cV9Wo589JWm CF06a9uLHw8EdwdI406IaYHb =rDUQ -----END PGP SIGNATURE----- --Kqu2xIcXrBS4ktnRrqcUcLhIJqEfagA8G--