From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:47180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tlm2R-0005MZ-LX for qemu-devel@nongnu.org; Thu, 20 Dec 2012 14:44:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tlm2N-0001A9-5v for qemu-devel@nongnu.org; Thu, 20 Dec 2012 14:44:15 -0500 Received: from mx3-phx2.redhat.com ([209.132.183.24]:55152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tlm2M-0001A5-VG for qemu-devel@nongnu.org; Thu, 20 Dec 2012 14:44:11 -0500 Date: Thu, 20 Dec 2012 14:44:09 -0500 (EST) From: Miroslav Rezanina Message-ID: <1979190175.18558095.1356032649822.JavaMail.root@redhat.com> In-Reply-To: <50D203A1.70808@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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: Eric Blake Cc: Kevin Wolf , Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi ----- Original Message ----- > From: "Eric Blake" > To: mrezanin@redhat.com > Cc: qemu-devel@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com > Sent: Wednesday, December 19, 2012 7:12:49 PM > Subject: Re: [Qemu-devel] [PATCH v7 3/4] qemu-img: Add compare subcommand > > On 12/17/2012 06:39 AM, mrezanin@redhat.com wrote: > > From: Miroslav Rezanina > > > > This patch adds new qemu-img subcommand that compare content of two > > disk > > s/compare/compares/ > > > images. > > > > Signed-off-by: Miroslav Rezanina > > --- > > @@ -587,7 +587,7 @@ static int img_commit(int argc, char **argv) > > } > > > > /* > > - * Returns true iff the first sector pointed to by 'buf' contains > > at least > > + * Returns true if the first sector pointed to by 'buf' contains > > at least > > Spurious change. 'iff' is correct here, for its mathematical meaning > of > if-and-only-if. You're right. I probably just see iff and change it to if without checking the reason. > > > * a non-NUL byte. > > * > > * 'pnum' is set to the number of sectors (including and > > immediately following > > @@ -688,6 +688,272 @@ static int compare_sectors(const uint8_t > > *buf1, const uint8_t *buf2, int n, > > > > #define IO_BUF_SIZE (2 * 1024 * 1024) > > > > +static int64_t sectors_to_bytes(int64_t sectors) > > +{ > > + return sectors << BDRV_SECTOR_BITS; > > Worth checking for overflow? > I think it's not. This should be save as block driver should not allow sectors to cause 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 = 0; > > + ret = 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(-ret)); > > + return ret; > > + } > > + ret = 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? > This is correct order. Function is_allocated_sector test if sectors contain any non-zero byte. We know that sector is "physically" allocated in the image, we test if it contains any data. > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org > > Miroslav Rezanina