Received: from eggs.gnu.org ([2001:4830:134:3::10]:52157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXGA2-0001K0-1L for qemu-devel@nongnu.org; Tue, 09 Aug 2016 19:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXGA0-0005ol-N5 for qemu-devel@nongnu.org; Tue, 09 Aug 2016 19:10:13 -0400 References: <20160809212007.4868-1-fullmanet@gmail.com> From: Max Reitz Message-ID: Date: Wed, 10 Aug 2016 01:10:03 +0200 MIME-Version: 1.0 In-Reply-To: <20160809212007.4868-1-fullmanet@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="faPt1i2nFHFe8FQQb2cVmIWxVEivco0Aq" Subject: Re: [Qemu-devel] [PATCH v8] 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) --faPt1i2nFHFe8FQQb2cVmIWxVEivco0Aq 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 v8] qemu-img: add the 'dd' subcommand References: <20160809212007.4868-1-fullmanet@gmail.com> In-Reply-To: <20160809212007.4868-1-fullmanet@gmail.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 09.08.2016 23:20, 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 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 | 302 +++++++++++++++++++++++++++++++= +++++++- > qemu-img.texi | 25 ++++ > tests/qemu-iotests/158 | 68 +++++++++ > 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/group | 2 + > 9 files changed, 583 insertions(+), 1 deletion(-) > 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 Looks good overall, just some minor comments below (and maybe you still want to replace {in,out}count by {in,out}_position anyway). [...] > diff --git a/qemu-img.c b/qemu-img.c > index d2865a5..10aaf0e 100644 > --- a/qemu-img.c > +++ b/qemu-img.c [...] > @@ -3794,6 +3801,299 @@ 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 * in.bsz < size) { dd.count * in.bsz can overflow, there should probably be a check for that before this point. > + size =3D dd.count * in.bsz; > + } [...] > diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 > new file mode 100755 > index 0000000..48972c8 > --- /dev/null > +++ b/tests/qemu-iotests/158 > @@ -0,0 +1,68 @@ [...] > +echo > +echo "=3D=3D Converting the image with dd =3D=3D" > + > +$QEMU_IMG dd if=3D"$TEST_IMG" of=3D"$TEST_IMG.out" -O "$IMGFMT" > +$QEMU_IMG check "$TEST_IMG.out" -f "$IMGFMT" 2>&1 | _filter_testdir |= \ > + _filter_qemu_img_check A simpler way of doing this would be: TEST_IMG=3D"$TEST_IMG.out" _check_test_img [...] > diff --git a/tests/qemu-iotests/159 b/tests/qemu-iotests/159 > new file mode 100755 > index 0000000..e55d942 > --- /dev/null > +++ b/tests/qemu-iotests/159 > @@ -0,0 +1,70 @@ [...] > +for bs in $TEST_SIZES; do > + echo > + echo "=3D=3D Creating image =3D=3D" > + > + size=3D1M > + _make_test_img $size > + _check_test_img > + $QEMU_IO -c "write -P 0xa 0 $size" "$TEST_IMG" | _filter_qemu_io > + > + echo > + echo "=3D=3D Converting the image with dd with a block size of $bs= =3D=3D" > + > + $QEMU_IMG dd if=3D"$TEST_IMG" of=3D"$TEST_IMG.out" bs=3D$bs -O "$I= MGFMT" > + $QEMU_IMG check "$TEST_IMG.out" -f "$IMGFMT" 2>&1 | _filter_testd= ir | \ > + _filter_qemu_img_check Again, TEST_IMG=3D"$TEST_IMG.out" _check_test_img would be simpler. > + echo > + echo "=3D=3D Compare the images with qemu-img compare =3D=3D" > + > + $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.out" > +done > + > +echo > +echo "*** done" > +rm -f "$seq.full" > +status=3D0 [...] > diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/comm= on.filter > index 3ab6e4d..cef5222 100644 > --- a/tests/qemu-iotests/common.filter > +++ b/tests/qemu-iotests/common.filter > @@ -44,6 +44,15 @@ _filter_imgfmt() > sed -e "s#$IMGFMT#IMGFMT#g" > } > =20 > +# replace error message when the format is not supported and delete > +# the output lines after the first one > +_filter_qemu_img_check() > +{ > + sed -e '/allocated.*fragmented.*compressed clusters/d' \ > + -e 's/qemu-img: This image format does not support checks/No e= rrors were found on the image./' \ > + -e '/Image end offset: [0-9]\+/d' > +} > + If you use the TEST_IMG=3D"$TEST_IMG.out" _check_test_img shorthand I've proposed above, then this function will no longer be necessary. If you don't, then please make use of this function in _check_test_img. That function contains exactly the same code (probably not by chance), so you should replace that code by a call to this function. Max --faPt1i2nFHFe8FQQb2cVmIWxVEivco0Aq 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 iQEvBAEBCAAZBQJXqmLLEhxtcmVpdHpAcmVkaGF0LmNvbQAKCRA7sUIC6DisrYvG B/9DpALhMAibM9ONdVCzAU8WKLbwYOeKdn62HS/Ti5KBu1CLjWicDRusoEHcQN/m iCZoQf3xFPUTY1uh1ovRwuuTPxz6RtfB4YdV0UPQmmFiO13VYxTd4VG/3VIqTGDM /Pvui+hIhidPoFds8UWQ6S5cmqAaOkMor2sCDirTfZQxLL1tfIt6NM63HyWga5PS /kcCHBgCULAl8d5Oy0GASQvJngW4hF6yCLjq6WW8mSy1VCUtOI1x9TbzOMgfFVf3 CSxVLHmWv4p1zXK8FlDNnXvOYCNiVXAZDL1ifbicGVqd99drwCgxDUKCrWFvtX6U KDFspfJ3bh735HxzJ1zuCXsW =a2u6 -----END PGP SIGNATURE----- --faPt1i2nFHFe8FQQb2cVmIWxVEivco0Aq--