From patchwork Thu Jun 29 09:23:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9816291 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 F15466035F for ; Thu, 29 Jun 2017 09:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3F57286DE for ; Thu, 29 Jun 2017 09:28:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5167286E5; Thu, 29 Jun 2017 09:28:40 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 6D827286DE for ; Thu, 29 Jun 2017 09:28:40 +0000 (UTC) Received: from localhost ([::1]:37951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVkd-0000ro-NU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Jun 2017 05:28:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfQ-0004oO-4h for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfN-0006xo-6P for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:16 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfN-0006xO-0k; Thu, 29 Jun 2017 05:23:13 -0400 Received: by mail-pf0-x241.google.com with SMTP id d5so12388790pfe.1; Thu, 29 Jun 2017 02:23:12 -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=ZHvK2Vys1FDOQRWCQbXjjaMPx12sSGaapnbVk2Pi7bM=; b=tnRtpFVnUs+wwFqp/DWhGRwfbLHlbNouvpsvvrT8hQ2jAy1hEprwkPvxXR0HBGF95M zN41PRA/XSqFNfXM3o3W+qvPMIJ1OrDs4f/1LHSkd+I/RXrEOgX+GaKDwLc2FJOqOU++ rmxlxzWz8dRJilWAAmYHQC653VaqcAP9i1dNNB5tcRRBG0q5Sd6oSZSEDL8NGCJNvGZt jKu8S4IQnTQbDHArOhyocTTwY7WTfpTxU3be9r8wLUcg6D/igPWeRsMMw/z5IKQbAF1I aGkk8FzTcXuGzwOKFjVpO0hWtUhl5Phsmb9EpXfMvRLHfbI6JtqVVCenb8WPHc2jIwsn PFtg== 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=ZHvK2Vys1FDOQRWCQbXjjaMPx12sSGaapnbVk2Pi7bM=; b=pcq5U7quzLwX2D8hP92heIq1oh9Pskd5aTe1SFcNCqKFLrO/zZP8L4IbF0HiT4T+kX 3P4OU29zuCP8cJYwHVKCdkUc4UHdTGrTQYLDeM4pv2oksYUkb4lOGEA/6IU6kYSiS7eI 5qcfF+F6UrP1Lt7/O6YGTxsJfLsKJFjZ29Mq0eMmrgzeuVyKLaY9b2UzRVkS6Ag+Zka4 iJUXJ31YJpf+umitGH9BIDxc/HUdC8zL6S5segwYkfbvUUI5Fjww/WDe5asusaghcDD0 OP1tdBgQNIQBc9gkQhdI2x11lIJMXJc8pO6MRVETmk0sYg619kPVNa7NZDlCbTf/c9yn dFKg== X-Gm-Message-State: AKS2vOwriHmH/s26nizLSZgTED5WMhxtoqistNj2NkPplydcgfAxhJTq h80LCsMRZyjrSA== X-Received: by 10.99.174.4 with SMTP id q4mr14516132pgf.196.1498728192245; Thu, 29 Jun 2017 02:23:12 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:11 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:38 +0530 Message-Id: <1498728221-23979-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v7 5/8] vmdk: Set maximum bytes allocated in one cycle 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 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 Reviewed-by: Fam Zheng --- block/vmdk.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 5647f53..fe2046b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1624,6 +1624,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t cluster_offset; uint64_t bytes_done = 0; VmdkMetaData m_data; + uint64_t extent_end; if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=0x%" PRIx64 @@ -1637,9 +1638,17 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, if (!extent) { return -EIO; } + extent_end = 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); + + /* 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_end - offset); + } ret = vmdk_get_cluster_offset(bs, extent, &m_data, offset, !(extent->compressed || zeroed),