From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLg8H-0000my-H3 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 17:51:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLg8D-0000g8-Fe for qemu-devel@nongnu.org; Wed, 11 Feb 2015 17:51:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLg8D-0000g4-85 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 17:51:41 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1BMpdEM000935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 11 Feb 2015 17:51:39 -0500 Message-ID: <54DBDCFA.90000@redhat.com> Date: Wed, 11 Feb 2015 17:51:38 -0500 From: Max Reitz MIME-Version: 1.0 References: <1423671788-31716-1-git-send-email-kwolf@redhat.com> In-Reply-To: <1423671788-31716-1-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] vpc: Implement bdrv_co_get_status() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-devel@nongnu.org Cc: stefanha@redhat.com On 2015-02-11 at 11:23, Kevin Wolf wrote: > This implements bdrv_co_get_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 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 52 insertions(+), 2 deletions(-) > > diff --git a/block/vpc.c b/block/vpc.c > index 46803b1..379ff4a 100644 > --- a/block/vpc.c > +++ b/block/vpc.c > @@ -597,6 +597,55 @@ 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; Double space before the left parenthesis. > + int64_t start, offset; > + 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); > + > + *pnum = 1; > + start = offset; > + allocated = (offset != -1); > + nb_sectors--; > + > + while (nb_sectors > 0) { > + offset = get_sector_offset(bs, sector_num, 0); During the first iteration, this will is exactly the function call as the one before this loop. > + > + if ((offset != -1) != allocated) { > + break; > + } > + > + if (allocated && offset != start + (*pnum * 512)) { Therefore, if allocated is true, this check will always fail because offset == start. > + break; > + } > + > + /* All sectors in a block are contiguous (without using the bitmap) */ > + n = ROUND_UP(sector_num + 1, s->block_size / 512) - sector_num; > + n = MIN(n, nb_sectors); I think you can make use of this assumption even before calling get_sector_offset() in the first iteration. Also, 512 is shorter than BDRV_SECTOR_SIZE and it's nice to get it on a single line, but I think not introducing another literal 512 in the code would be nicer; the same applies above in "*pnum * 512". Max > + > + *pnum += n; > + sector_num += n; > + nb_sectors -= n; > + } > + > + if (allocated) { > + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; > + } else { > + return 0; > + } > +} > + > /* > * Calculates the number of cylinders, heads and sectors per cylinder > * based on a given number of sectors. This is the algorithm described > @@ -907,8 +956,9 @@ static BlockDriver bdrv_vpc = { > .bdrv_reopen_prepare = vpc_reopen_prepare, > .bdrv_create = vpc_create, > > - .bdrv_read = vpc_co_read, > - .bdrv_write = vpc_co_write, > + .bdrv_read = vpc_co_read, > + .bdrv_write = vpc_co_write, > + .bdrv_co_get_block_status = vpc_co_get_block_status, > > .bdrv_get_info = vpc_get_info, >