Received: from eggs.gnu.org ([2001:4830:134:3::10]:48459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSkIJ-00080d-0i for qemu-devel@nongnu.org; Tue, 03 Mar 2015 05:43:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSkI6-0000I8-LO for qemu-devel@nongnu.org; Tue, 03 Mar 2015 05:43:18 -0500 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:42985 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSkI6-0000Hk-Bc for qemu-devel@nongnu.org; Tue, 03 Mar 2015 05:43:06 -0500 From: Peter Lieven Date: Tue, 3 Mar 2015 11:41:52 +0100 Message-Id: <1425379316-19639-2-git-send-email-pl@kamp.de> In-Reply-To: <1425379316-19639-1-git-send-email-pl@kamp.de> References: <1425379316-19639-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH v2 1/5] block/vpc: optimize vpc_co_get_block_status List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, carnold@suse.com, famz@redhat.com, jcody@redhat.com, Peter Lieven , mreitz@redhat.com, stefanha@redhat.com *pnum can't be greater than s->block_size / BDRV_SECTOR_SIZE for allocated sectors since there is always a bitmap in between. Signed-off-by: Peter Lieven Reviewed-by: Max Reitz --- block/vpc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 1533b6a..c8e17cb 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -602,7 +602,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs, { BDRVVPCState *s = bs->opaque; VHDFooter *footer = (VHDFooter*) s->footer_buf; - int64_t start, offset, next; + int64_t start, offset; bool allocated; int n; @@ -626,20 +626,18 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs, *pnum += n; sector_num += n; nb_sectors -= n; - next = start + (*pnum * BDRV_SECTOR_SIZE); - + /* *pnum can't be greater than one block for allocated + * sectors since there is always a bitmap in between. */ + if (allocated) { + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + } if (nb_sectors == 0) { break; } - offset = get_sector_offset(bs, sector_num, 0); - } while ((allocated && offset == next) || (!allocated && offset == -1)); + } while (offset == -1); - if (allocated) { - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; - } else { - return 0; - } + return 0; } /* -- 1.9.1