From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVdrm-0008ST-4U for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:27:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVdrf-0003xI-7h for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:27:54 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:12682 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVdre-0003u9-K0 for qemu-devel@nongnu.org; Wed, 11 Mar 2015 06:27:46 -0400 From: "Denis V. Lunev" Date: Wed, 11 Mar 2015 13:28:08 +0300 Message-Id: <1426069701-1405-15-git-send-email-den@openvz.org> In-Reply-To: <1426069701-1405-1-git-send-email-den@openvz.org> References: <1426069701-1405-1-git-send-email-den@openvz.org> Subject: [Qemu-devel] [PATCH 14/27] block/parallels: create bat2sect helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "Denis V. Lunev" , qemu-devel@nongnu.org, Stefan Hajnoczi deduplicate copy/paste arithmetcs Signed-off-by: Denis V. Lunev Reviewed-by: Roman Kagan CC: Kevin Wolf CC: Stefan Hajnoczi --- block/parallels.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index a7c66dc..6bc5e62 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -152,6 +152,12 @@ fail: return ret; } + +static int64_t bat2sect(BDRVParallelsState *s, uint32_t idx) +{ + return (uint64_t)s->bat_bitmap[idx] * s->off_multiplier; +} + static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num) { uint32_t index, offset; @@ -163,7 +169,7 @@ static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num) if ((index >= s->bat_size) || (s->bat_bitmap[index] == 0)) { return -1; } - return (uint64_t)s->bat_bitmap[index] * s->off_multiplier + offset; + return bat2sect(s, index) + offset; } static int cluster_remainder(BDRVParallelsState *s, int64_t sector_num, @@ -187,7 +193,7 @@ static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) return -EINVAL; } if (s->bat_bitmap[idx] != 0) { - return (uint64_t)s->bat_bitmap[idx] * s->off_multiplier + offset; + return bat2sect(s, idx) + offset; } pos = bdrv_getlength(bs->file) >> BDRV_SECTOR_BITS; @@ -201,7 +207,7 @@ static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) if (ret < 0) { return ret; } - return (uint64_t)s->bat_bitmap[idx] * s->off_multiplier + offset; + return bat2sect(s, idx) + offset; } static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs, -- 1.9.1