From patchwork Sat Mar 25 11:18:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9644515 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 458F660327 for ; Sat, 25 Mar 2017 11:19:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47739265B9 for ; Sat, 25 Mar 2017 11:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C21526907; Sat, 25 Mar 2017 11:19:31 +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 DD43E265B9 for ; Sat, 25 Mar 2017 11:19:30 +0000 (UTC) Received: from localhost ([::1]:36728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crjjF-00016d-P1 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Mar 2017 07:19:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crji3-000158-Ow for qemu-devel@nongnu.org; Sat, 25 Mar 2017 07:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crji2-0000ny-SZ for qemu-devel@nongnu.org; Sat, 25 Mar 2017 07:18:15 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1crji2-0000nk-OL; Sat, 25 Mar 2017 07:18:14 -0400 Received: by mail-pf0-x243.google.com with SMTP id r137so2246959pfr.3; Sat, 25 Mar 2017 04:18:14 -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=m5yLX96dRycwNS98RwieSaA0rh2xKlghZOtXQhBx/jM=; b=etqOCoF96CJxX/PutMEt47QLcYlzvKQmdUH0OXC4Cxu+o7rRK2ozc18722TvhyOhCb 6+nkL9lqHP+ncgupNB+xgCsi72jqojarE76FZXSd8XyJwP1iyGns1aCiFkuB/NbjQYxg /XNGoczE5/x/OhtNxzJ7rme5EOhLqHNBVKSwCgUIJD5pRiXLrKCQIU08ed3kj5JTjFaJ v1Npz7ybh5FvohpPF/c1XPRAfthajohMmRsZBfD3Aj0kx0EBPzU1w/OK2hm3ZkgTEEnn va+6F1DHjb8NxjOHTZUvR0uGu4N/5nJj4qpge8OYQ7m6mENTqS9MDH5Cg9tHL77xaitr wIUQ== 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=m5yLX96dRycwNS98RwieSaA0rh2xKlghZOtXQhBx/jM=; b=bzc/ncs53w9ZI6Rrf+S9zTtB5GKLjwrLYzLyZvgcb/B8xfuSmU5Xuhi4BIIT5VSlyY hCTNT32OTJ3bftszB/gtE8ynAEc0g79yeKxhLU28bBIs6CvF0loWvimNQeIhtL1dGotM vnCLIjSQCji28y6XVLed2prHrq/eXLaXguOdeGduvdN85qa+ICznkSm7YmhkMVJNfqKn XvtDzEX5r4nt3K+XJzxJjrgfW55tBQwcyWc9NDKHEHcAU2j7Kkh7uqyjb0CZrI7ZKtcF aljllGNoX/Mf5CmB1/Tm93/hNrofLAg0b/CbdwJq2M3RiGw2Sw22KMe/qJJCciSa4Mms D7cA== X-Gm-Message-State: AFeK/H11S8dtxFlMiV6Gb+cYx2x6vz1aLesbow6z618HHWY+oX66AC8/oMmLqLQqOJyZSw== X-Received: by 10.99.8.194 with SMTP id 185mr13930302pgi.37.1490440694023; Sat, 25 Mar 2017 04:18:14 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id p189sm9952620pfb.128.2017.03.25.04.18.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Mar 2017 04:18:13 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 25 Mar 2017 16:48:15 +0530 Message-Id: <1490440701-12037-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1490440701-12037-1-git-send-email-ashijeetacharya@gmail.com> References: <1490440701-12037-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:c00::243 Subject: [Qemu-devel] [PATCH v2 1/7] vmdk: Refactor and introduce new helper functions 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 --- block/vmdk.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index a9bd22b..7795c5f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -242,6 +242,26 @@ 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 inline uint64_t size_to_clusters(VmdkExtent *extent, uint64_t size) +{ + uint64_t cluster_size, round_off_size; + cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE; + round_off_size = cluster_size - (size % cluster_size); + return ((size + round_off_size) >> 16) - 1; +} + static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) { char *desc; @@ -1266,18 +1286,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) {