From patchwork Sat Apr 1 14:44:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9658065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CE1E2602BC for ; Sat, 1 Apr 2017 14:47:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2C76285E7 for ; Sat, 1 Apr 2017 14:47:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B432B285ED; Sat, 1 Apr 2017 14:47:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 64CED285E7 for ; Sat, 1 Apr 2017 14:47:55 +0000 (UTC) Received: from localhost ([::1]:51695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuKJm-0007uq-En for patchwork-qemu-devel@patchwork.kernel.org; Sat, 01 Apr 2017 10:47:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuKGM-0005s0-Aa for qemu-devel@nongnu.org; Sat, 01 Apr 2017 10:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuKGL-0003vZ-IQ for qemu-devel@nongnu.org; Sat, 01 Apr 2017 10:44:22 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34398) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuKGL-0003v5-Ca; Sat, 01 Apr 2017 10:44:21 -0400 Received: by mail-pg0-x243.google.com with SMTP id o123so22356113pga.1; Sat, 01 Apr 2017 07:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1faKV22GHrDVBYD9PXGcSxdK5iwLqbnfKNfj8zAbbxE=; b=SaCH6AczEDQIqJ+BUkEyl4qMTXryMEYukIjUguuP4iXwDOinOW/+59rj3nlzt7qk2e z/52cGINVqc04HVjidO9fhrSmOe9ayZz7Kt+FOQKEBkO49a8vuPSYxswCMmfVNsWcFzC s2iVXB0QPNXIH0fN7YUiamPm5fHDjQPpSMSa6HtvhRSQLM6ju7k7FMNynFpBf+Uk8wid +jg298gMd3yvQdyZbn44Zcw7fwUnhVffSxKyUGrpqQb+AUV4097jJ7t4lw6IsYE+lsfj QUvDonLlALEgVLcEbl9pFi4Bu25mUWhw91Wj4tAyoxS0/dLLfowm32RMyuHdk6gDXB/h ZaAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1faKV22GHrDVBYD9PXGcSxdK5iwLqbnfKNfj8zAbbxE=; b=EZyVTBReK3wQ126TnqW05lyY9LBs+nxBAUrn+2xdatxqEDfKtSMCu4/eh1/VCnpIjU lHXpKtXsBBrlt2WossM2s1NjD51vbpq2vfyph+sZQxiNW08F8C5d3V58F2j7+4lYL/Hm gFD6hhOK2+Qs73y4++ng9xXabsPwnLvc4kSruZ16Zqv7q6G8x5ULtthXb+cPHJZqTlz7 kNRy/whhWZBkpDvGphirS5bmbHlqlzSEOGwG2tCZTrtHFPtQnM1BUAf5XU9Hr6/5Z29s L1baoIpIOSONGluirEZGWrypYCLF2Bq1hfl761NMRoN1piIIc0zdjbJ7GsaevSvbfJaC UQcA== X-Gm-Message-State: AFeK/H3B40rGFoSmUtEgIB+gqLL8rpoIXCUkdjKG7hO/dymnvByIa+AwsA4MPvLSpjNmHg== X-Received: by 10.99.151.10 with SMTP id n10mr8462945pge.199.1491057860429; Sat, 01 Apr 2017 07:44:20 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id h14sm9618461pgn.64.2017.04.01.07.44.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 01 Apr 2017 07:44:19 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 1 Apr 2017 20:14:33 +0530 Message-Id: <1491057878-27868-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1491057878-27868-1-git-send-email-ashijeetacharya@gmail.com> References: <1491057878-27868-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v3 1/6] vmdk: Move vmdk_find_offset_in_cluster() to the top X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, stefanha@gmail.com, qemu-devel@nongnu.org, mreitz@redhat.com, Ashijeet Acharya , jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Move the existing vmdk_find_offset_in_cluster() function to the top of the driver. Also, introduce a new helper function size_to_clusters() which returns the number of clusters for a given size in bytes. Here, we leave the last cluster as we need to perform COW for that one. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index a9bd22b..22be887 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -242,6 +242,18 @@ static void vmdk_free_last_extent(BlockDriverState *bs) s->extents = g_renew(VmdkExtent, s->extents, s->num_extents); } +static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, + int64_t offset) +{ + uint64_t extent_begin_offset, extent_relative_offset; + uint64_t cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE; + + extent_begin_offset = + (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; + extent_relative_offset = offset - extent_begin_offset; + return extent_relative_offset % cluster_size; +} + static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) { char *desc; @@ -1266,18 +1278,6 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } -static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, - int64_t offset) -{ - uint64_t extent_begin_offset, extent_relative_offset; - uint64_t cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE; - - extent_begin_offset = - (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; - extent_relative_offset = offset - extent_begin_offset; - return extent_relative_offset % cluster_size; -} - static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, int64_t sector_num) {