From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOBmP-0002ez-LJ for qemu-devel@nongnu.org; Wed, 18 Feb 2015 16:03:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOBmL-00040B-0D for qemu-devel@nongnu.org; Wed, 18 Feb 2015 16:03:33 -0500 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:53148 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOBmK-0003zi-LO for qemu-devel@nongnu.org; Wed, 18 Feb 2015 16:03:28 -0500 Message-ID: <54E4FE1B.5090202@kamp.de> Date: Wed, 18 Feb 2015 22:03:23 +0100 From: Peter Lieven MIME-Version: 1.0 References: <7d15cff8d75566a93a52801605d8761c.squirrel@ssl.dlhnet.de> In-Reply-To: <7d15cff8d75566a93a52801605d8761c.squirrel@ssl.dlhnet.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Fwd: [PATCH v2] vpc: Implement bdrv_co_get_block_status()] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com Cc: "qemu-devel@nongnu.org" , "stefanha@redhat.com >> Stefan Hajnoczi" , mreitz@redhat.com Am 18.02.2015 um 21:57 schrieb Peter Lieven: > This implements bdrv_co_get_block_status() for VHD images. This can > significantly speed up qemu-img convert operation because only with this > function implemented sparseness can be considered. (Before, converting a > 1 TB empty image took several minutes for me, now it's instantaneous.) > > Signed-off-by: Kevin Wolf > --- > block/vpc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) > > diff --git a/block/vpc.c b/block/vpc.c > index 7fddbf0..1533b6a 100644 > --- a/block/vpc.c > +++ b/block/vpc.c > @@ -597,6 +597,51 @@ static coroutine_fn int vpc_co_write(BlockDriverState > *bs, int64_t sector_num, > return ret; > } > > +static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs, > + int64_t sector_num, int nb_sectors, int *pnum) > +{ > + BDRVVPCState *s = bs->opaque; > + VHDFooter *footer = (VHDFooter*) s->footer_buf; > + int64_t start, offset, next; > + bool allocated; > + int n; > + > + if (be32_to_cpu(footer->type) == VHD_FIXED) { > + *pnum = nb_sectors; > + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | > + (sector_num << BDRV_SECTOR_BITS); > + } > + > + offset = get_sector_offset(bs, sector_num, 0); > + start = offset; > + allocated = (offset != -1); > + *pnum = 0; > + > + do { > + /* All sectors in a block are contiguous (without using the > bitmap) */ > + n = ROUND_UP(sector_num + 1, s->block_size / BDRV_SECTOR_SIZE) > + - sector_num; > + n = MIN(n, nb_sectors); > + > + *pnum += n; > + sector_num += n; > + nb_sectors -= n; > + next = start + (*pnum * BDRV_SECTOR_SIZE); > + > + if (nb_sectors == 0) { > + break; > + } > + > + offset = get_sector_offset(bs, sector_num, 0); > + } while ((allocated && offset == next) || (!allocated && offset == -1)); > + > + if (allocated) { > + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; > + } else { > + return 0; Shouldn't this be return BDRV_BLOCK_ZERO; ? vpc_read memsets all blocks with offset == -1 to 0x00. Not for this patch, but couldn't we use your new function to signifincantly speed up reading of continous allocated areas in vpc_read? Peter