From patchwork Sat Mar 25 11:18:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9644523 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 790A360327 for ; Sat, 25 Mar 2017 11:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7987720144 for ; Sat, 25 Mar 2017 11:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DF682026B; Sat, 25 Mar 2017 11:22:17 +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 0F0DD20144 for ; Sat, 25 Mar 2017 11:22:17 +0000 (UTC) Received: from localhost ([::1]:36744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crjlv-0003D2-Ut for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Mar 2017 07:22:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crjiS-0001Rl-V9 for qemu-devel@nongnu.org; Sat, 25 Mar 2017 07:18:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crjiR-0000tw-A8 for qemu-devel@nongnu.org; Sat, 25 Mar 2017 07:18:40 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35724) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1crjiR-0000to-4O; Sat, 25 Mar 2017 07:18:39 -0400 Received: by mail-pf0-x242.google.com with SMTP id n11so2250880pfg.2; Sat, 25 Mar 2017 04:18:39 -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=2GL0B5OQlyf0zt7bwRYKfjjxPQBABmDg3Ytvdkm3J9c=; b=ieGLYeu+ZqDFvzLNnhxrnk5rA5CHJTyXknnfjzPT7SmMsMys0TPCb6LtKDaBTPsytO YGYaSGHSkRdg9y/qDBuw3gHOfVsU1OrP08WN/VCiQ6sOLQaQuGcDtF7DCE2hgXUBitEN MRxAFwEMRg3o8jNOrJvj9+N/n1/G8ORt3CMq3ikW4gUj70M3UTR4mxTHspiMt1KW6IB/ TyFJ0x62o10DKnQLfJCrgKwERVAUnPcC5C+rp4GQRVMrDikQNG/5WKQQ/aohHdfhfVFs 81BbXbJ4TI59e0ZXjUHMP1xq9hToctatbP1n7rLCVwwFHUyBcWo6b2kPtmFHUMfsUX8a lVVA== 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=2GL0B5OQlyf0zt7bwRYKfjjxPQBABmDg3Ytvdkm3J9c=; b=oAHQKJPC+447V8ngSQMs42vDXZf/VZ8Lmporg1YBwWJ2F5Pp555hvm175D2wFIW49x Pn3UHj8KEOOJzr6Fq0WB/H7b6yOUWL4yvEKAGlVHzg9HjrBdn8E42Jz40nfSB9QAkOVN 6ZhIL6226uXYYPwnBhKoXdWl9V6ehKyZHf7oZvPn4KFziYznxB+giQMZ3I1+zH7L37Sf GBFKokMIVBv+dSAqh+amNOAGeEdS4ulVx+gWwkRynZ4UfzklV2b5mQA4vvJJ7nBk8lQc 5OWo3c4dOkA14UepNo8fCIzysVXjL0Ct/LKRz95UemwMpP+J3l9Ik/syc+CEF2m2Zqev uFjw== X-Gm-Message-State: AFeK/H2XOlpeNboeCiHj1rMN3dtt3l1oYP0KQL/6vx4PTN1rYgbIHJZLdBXi010MTN3YUA== X-Received: by 10.99.132.73 with SMTP id k70mr14208164pgd.28.1490440718243; Sat, 25 Mar 2017 04:18:38 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id p189sm9952620pfb.128.2017.03.25.04.18.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Mar 2017 04:18:37 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 25 Mar 2017 16:48:20 +0530 Message-Id: <1490440701-12037-7-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::242 Subject: [Qemu-devel] [PATCH v2 6/7] vmdk: Allocate multiple clusters at once 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 Get vmdk_pwritev() to make use of the new multiple cluster allocation helper functions to allocate multiple clusters at once. Set the maximum bytes allowed to get allocated at once to be not more than the extent size boundary to handle writes at two separate extents appropriately. Signed-off-by: Ashijeet Acharya --- block/vmdk.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 387e45b..3de8b8f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1767,7 +1767,9 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, int64_t offset_in_cluster, n_bytes; uint64_t cluster_offset; uint64_t bytes_done = 0; + uint64_t extent_size; VmdkMetaData m_data; + uint32_t total_alloc_clusters = 0; if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=0x%" PRIx64 @@ -1781,14 +1783,22 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, if (!extent) { return -EIO; } + extent_size = extent->end_sector * BDRV_SECTOR_SIZE; + offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset); - n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - - offset_in_cluster); - ret = get_cluster_offset(bs, extent, &m_data, offset, - !(extent->compressed || zeroed), - &cluster_offset, offset_in_cluster, - offset_in_cluster + n_bytes); + /* truncate n_bytes to first cluster because we need to perform COW */ + if (offset_in_cluster > 0) { + n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE + - offset_in_cluster); + } else { + n_bytes = MIN(bytes, extent_size - offset); + } + + ret = vmdk_alloc_cluster_offset(bs, extent, &m_data, offset, + !(extent->compressed || zeroed), + &cluster_offset, n_bytes, + &total_alloc_clusters); if (extent->compressed) { if (ret == VMDK_OK) { /* Refuse write to allocated cluster for streamOptimized */ @@ -1797,19 +1807,22 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, return -EIO; } else { /* allocate */ - ret = get_cluster_offset(bs, extent, &m_data, offset, - true, &cluster_offset, 0, 0); + ret = vmdk_alloc_cluster_offset(bs, extent, &m_data, offset, + true, &cluster_offset, n_bytes, + &total_alloc_clusters); } } if (ret == VMDK_ERROR) { return -EINVAL; } + if (zeroed) { /* Do zeroed write, buf is ignored */ - if (extent->has_zero_grain && - offset_in_cluster == 0 && - n_bytes >= extent->cluster_sectors * BDRV_SECTOR_SIZE) { - n_bytes = extent->cluster_sectors * BDRV_SECTOR_SIZE; + if (extent->has_zero_grain && offset_in_cluster == 0 && + n_bytes >= extent->cluster_sectors * BDRV_SECTOR_SIZE * + total_alloc_clusters) { + n_bytes = extent->cluster_sectors * BDRV_SECTOR_SIZE * + total_alloc_clusters; if (!zero_dry_run) { /* update L2 tables */ if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED)