From patchwork Fri Jun 12 16:23:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 483685 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 1BE30140348 for ; Sat, 13 Jun 2015 02:28:17 +1000 (AEST) Received: from localhost ([::1]:52485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3RoU-0004QA-VI for incoming@patchwork.ozlabs.org; Fri, 12 Jun 2015 12:28:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3RkH-0004UZ-SI for qemu-devel@nongnu.org; Fri, 12 Jun 2015 12:23:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3RkE-0004ti-Lc for qemu-devel@nongnu.org; Fri, 12 Jun 2015 12:23:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3RkC-0004rz-S5; Fri, 12 Jun 2015 12:23:48 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 8D6C0C6A1B; Fri, 12 Jun 2015 16:23:48 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5CGNcjt006646; Fri, 12 Jun 2015 12:23:47 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 12 Jun 2015 18:23:15 +0200 Message-Id: <1434126214-11681-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1434126214-11681-1-git-send-email-kwolf@redhat.com> References: <1434126214-11681-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 06/25] vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status 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 From: Fam Zheng It has the similar issue with b1649fae49a8. Since the calculation is repeated for a few times already, introduce a function so it can be reused. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vmdk.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index b66745d..3e4d84b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1248,6 +1248,17 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } +static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, + int64_t sector_num) +{ + uint64_t index_in_cluster, extent_begin_sector, extent_relative_sector_num; + + extent_begin_sector = extent->end_sector - extent->sectors; + extent_relative_sector_num = sector_num - extent_begin_sector; + index_in_cluster = extent_relative_sector_num % extent->cluster_sectors; + return index_in_cluster; +} + static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { @@ -1285,7 +1296,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, break; } - index_in_cluster = sector_num % extent->cluster_sectors; + index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num); n = extent->cluster_sectors - index_in_cluster; if (n > nb_sectors) { n = nb_sectors;