From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVFsV-0007c4-N7 for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVFsN-0007mH-T2 for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:51:03 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:34635 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVFsM-0007ic-OZ for qemu-devel@nongnu.org; Tue, 10 Mar 2015 04:50:55 -0400 From: "Denis V. Lunev" Date: Tue, 10 Mar 2015 11:51:08 +0300 Message-Id: <1425977481-13317-15-git-send-email-den@openvz.org> In-Reply-To: <1425977481-13317-1-git-send-email-den@openvz.org> References: <1425977481-13317-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 , Roman Kagan deduplicate copy/paste arithmetcs Signed-off-by: Denis V. Lunev CC: 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 3d5f509..95e99cc 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -151,6 +151,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; @@ -161,7 +167,7 @@ static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num) /* not allocated */ 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, @@ -185,7 +191,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; @@ -199,7 +205,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