From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2hjo-0000NB-54 for qemu-devel@nongnu.org; Mon, 13 Jan 2014 08:39:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W2hjj-0003mW-19 for qemu-devel@nongnu.org; Mon, 13 Jan 2014 08:39:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2hji-0003mL-Pc for qemu-devel@nongnu.org; Mon, 13 Jan 2014 08:39:26 -0500 Date: Mon, 13 Jan 2014 21:39:21 +0800 From: Fam Zheng Message-ID: <20140113133921.GB7503@T430.nay.redhat.com> References: <1389612246-9545-1-git-send-email-pl@kamp.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1389612246-9545-1-git-send-email-pl@kamp.de> Subject: Re: [Qemu-devel] [PATCH] block/vmdk: add basic .bdrv_check support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Mon, 01/13 12:24, Peter Lieven wrote: > this adds a basic vmdk corruption check. it should detect severe > table corruptions and file truncation. > > Signed-off-by: Peter Lieven > --- > block/vmdk.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/block/vmdk.c b/block/vmdk.c > index c6b60b4..1d66858 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -1918,6 +1918,51 @@ static ImageInfo *vmdk_get_extent_info(VmdkExtent *extent) > return info; > } > > +static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result, > + BdrvCheckMode fix) > +{ > + BDRVVmdkState *s = bs->opaque; > + VmdkExtent *extent = NULL; > + int64_t sector_num = 0; > + int64_t total_sectors = bdrv_getlength(bs) / BDRV_SECTOR_SIZE; > + int ret; > + uint64_t cluster_offset; > + > + if (fix) { > + return -ENOTSUP; > + } > + > + for (;;) { > + if (sector_num >= total_sectors) { > + return 0; > + } > + extent = find_extent(s, sector_num, extent); > + if (!extent) { > + fprintf(stderr, "ERROR: could not find extend for sector %ld\n", > + sector_num); > + break; > + } > + ret = get_cluster_offset(bs, extent, NULL, sector_num << BDRV_SECTOR_BITS, > + 0, &cluster_offset); > + if (ret == VMDK_ERROR) { > + fprintf(stderr, > + "ERROR: could not get cluster_offset for sector %ld\n", > + sector_num); > + break; > + } > + if (ret == VMDK_OK && cluster_offset >= bdrv_getlength(extent->file)) { > + fprintf(stderr, > + "ERROR: cluster offset for sector %ld points after EOF\n", > + sector_num); > + break; > + } > + sector_num += extent->cluster_sectors; > + } > + > + result->corruptions++; > + return 0; > +} > + > static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs) > { > int i; > @@ -1991,6 +2036,7 @@ static BlockDriver bdrv_vmdk = { > .instance_size = sizeof(BDRVVmdkState), > .bdrv_probe = vmdk_probe, > .bdrv_open = vmdk_open, > + .bdrv_check = vmdk_check, > .bdrv_reopen_prepare = vmdk_reopen_prepare, > .bdrv_read = vmdk_co_read, > .bdrv_write = vmdk_co_write, Works for me. Thank. And BTW, is it worth comparing with the "grain_offset" header field? This should be the first data cluster's offset. When you have a fresh image with no data cluster allocated, and it's truncated, this patch doesn't catch it. Anyway, Reviewed-by: Fam Zheng