From patchwork Tue Apr 28 07:46:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 465411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3607714012C for ; Tue, 28 Apr 2015 17:56:10 +1000 (AEST) Received: from localhost ([::1]:59381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yn0NE-0005EV-EC for incoming@patchwork.ozlabs.org; Tue, 28 Apr 2015 03:56:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yn0Ek-0005OR-Bx for qemu-devel@nongnu.org; Tue, 28 Apr 2015 03:47:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yn0Ef-0004FI-TW for qemu-devel@nongnu.org; Tue, 28 Apr 2015 03:47:22 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:13843 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yn0Ef-0004Ep-Gq for qemu-devel@nongnu.org; Tue, 28 Apr 2015 03:47:17 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t3S7ktlm031473; Tue, 28 Apr 2015 10:47:15 +0300 (MSK) From: "Denis V. Lunev" To: Date: Tue, 28 Apr 2015 10:46:48 +0300 Message-Id: <1430207220-24458-16-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430207220-24458-1-git-send-email-den@openvz.org> References: <1430207220-24458-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , "Denis V. Lunev" , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 15/27] block/parallels: create bat2sect helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org deduplicate copy/paste arithmetcs Signed-off-by: Denis V. Lunev Reviewed-by: Roman Kagan Reviewed-by: Stefan Hajnoczi CC: Kevin Wolf --- block/parallels.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 16fbdf4..1540c21 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -161,6 +161,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; @@ -172,7 +178,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, @@ -196,7 +202,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; @@ -219,7 +225,7 @@ static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) s->bat_bitmap[idx] = 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,