From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlO8S-0002HZ-Pj for qemu-devel@nongnu.org; Wed, 19 Dec 2012 13:12:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlO8R-0000sM-9N for qemu-devel@nongnu.org; Wed, 19 Dec 2012 13:12:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlO8R-0000sH-2A for qemu-devel@nongnu.org; Wed, 19 Dec 2012 13:12:51 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBJICoVI004709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Dec 2012 13:12:50 -0500 Message-ID: <50D203A1.70808@redhat.com> Date: Wed, 19 Dec 2012 11:12:49 -0700 From: Eric Blake MIME-Version: 1.0 References: <1355751593-31535-1-git-send-email-mrezanin@redhat.com> <1355751593-31535-2-git-send-email-mrezanin@redhat.com> <1355751593-31535-3-git-send-email-mrezanin@redhat.com> <1355751593-31535-4-git-send-email-mrezanin@redhat.com> In-Reply-To: <1355751593-31535-4-git-send-email-mrezanin@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig55DB0EC15921FAB8D1AAE31D" Subject: Re: [Qemu-devel] [PATCH v7 3/4] qemu-img: Add compare subcommand List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mrezanin@redhat.com Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig55DB0EC15921FAB8D1AAE31D Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 12/17/2012 06:39 AM, mrezanin@redhat.com wrote: > From: Miroslav Rezanina >=20 > This patch adds new qemu-img subcommand that compare content of two dis= k s/compare/compares/ > images. >=20 > Signed-off-by: Miroslav Rezanina > --- > @@ -587,7 +587,7 @@ static int img_commit(int argc, char **argv) > } > =20 > /* > - * Returns true iff the first sector pointed to by 'buf' contains at l= east > + * Returns true if the first sector pointed to by 'buf' contains at le= ast Spurious change. 'iff' is correct here, for its mathematical meaning of if-and-only-if. > * a non-NUL byte. > * > * 'pnum' is set to the number of sectors (including and immediately f= ollowing > @@ -688,6 +688,272 @@ static int compare_sectors(const uint8_t *buf1, c= onst uint8_t *buf2, int n, > =20 > #define IO_BUF_SIZE (2 * 1024 * 1024) > =20 > +static int64_t sectors_to_bytes(int64_t sectors) > +{ > + return sectors << BDRV_SECTOR_BITS; Worth checking for overflow? > +static int check_empty_sectors(BlockDriverState *bs, int64_t sect_num,= > + int sect_count, const char *filename, > + uint8_t *buffer, bool quiet) > +{ > + int pnum, ret =3D 0; > + ret =3D bdrv_read(bs, sect_num, buffer, sect_count); > + if (ret < 0) { > + error_report("Error while reading offset %" PRId64 " of %s: %s= ", > + sectors_to_bytes(sect_num), filename, strerror(-r= et)); > + return ret; > + } > + ret =3D is_allocated_sectors(buffer, sect_count, &pnum); Is this logic backwards? Isn't it wasteful to read a sector prior to seeing if it was actually allocated? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig55DB0EC15921FAB8D1AAE31D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQEcBAEBCAAGBQJQ0gOhAAoJEKeha0olJ0NqR6YH/jxP70qqnf376mvcOviRYlEk +BWNCdZaVEZfPmUxtlymyKC0nIb19MV5okOeGUBK/wRIUaTJ5hmboxe3AL36rfFU /6LhIGpVnQGaR9m+GteMcvcTyQtPtqhJyN8hos/qVJan90ek1rT2BGj9PaAu8ksD IwQACxoL3+B5JFDFo5Upt+/8hatELqilL/EmcRHgbRZIHs5rdit/KxvPbxLwEONV kmaqI0VaxOM4RlGU8s3c8Mrihx69cU2yYBheYInpEIUXTfGvR3XscOc+lexS/ndl TwkjSldd78NMFqXt7fTWWIzE7zRoV+rDPz8PvpotLQMCLlCwemPwucn/419pzEA= =lGZP -----END PGP SIGNATURE----- --------------enig55DB0EC15921FAB8D1AAE31D--