From patchwork Thu Jul 27 14:33:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9867035 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 D84196035E for ; Thu, 27 Jul 2017 14:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7148283C7 for ; Thu, 27 Jul 2017 14:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB94C283AF; Thu, 27 Jul 2017 14:38:51 +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 4D25A283AF for ; Thu, 27 Jul 2017 14:38:50 +0000 (UTC) Received: from localhost ([::1]:43398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dajwA-000591-0p for patchwork-qemu-devel@patchwork.kernel.org; Thu, 27 Jul 2017 10:38:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dajpf-000802-CM for qemu-devel@nongnu.org; Thu, 27 Jul 2017 10:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dajpb-0005wo-H1 for qemu-devel@nongnu.org; Thu, 27 Jul 2017 10:32:07 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:35782) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dajpb-0005wC-Bl; Thu, 27 Jul 2017 10:32:03 -0400 Received: by mail-pg0-x243.google.com with SMTP id d193so20698758pgc.2; Thu, 27 Jul 2017 07:32:03 -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=b5jVC3I6RBHJZkn3RlFeW0BaQcyntNaxoFBvILbjkmHOWp+XuRV3NsGeNjByyWpwSr r4CVSPzckNDEmckB237LjSDnLGa4l5nYIYaK86jdEr3uLaduA7KxqjkPuPJZ4TL3rYOj sd9pIomNCP7WHN0Du6C7SebdWMPIxj+WU3hQXdlDXnEmT6r0/QNK/NWi/UMc7tjcrZfZ k1bHpvwKUpb+sh06TWbg7Q9CpwcLp3FjuxorahhromZGLz5eoVRIQr8FoCGfYVU7tmF0 tYCqlj7fX8vk6rMMqnKAV7R5o0Wi86CS6wVitGs2cv5OKBnki7i6tsJJpUSu8QZBxXVC DqvA== 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=t3QVjMJe5F0p18cZ1tSmAasXPmNlBAB6lAy4NEz0/YTu/6ZSIfnYm+LhEWxATyQrJy 8os3ULd1uI9Sf6bOPWx/hKDUz7yipkrxlZZWbu3LSShMEfiOFocjEX1R3lDWQZ1Gu6Iq /dzZZVacw3DMgp+nOS/47Y+cpRGZoPqptYZ/NhNYCw9+ekgLYz4NfWG9ctApM9TTzJKu zUJMyelimja5m0QeBzFXNo/bbdgCB3+S62UgepKlfS5nDUuXvH9jddWH8WP4egqUKlp+ K9RFFx1TqI5QNqpZGX1Z5AmUvVL60W8eqlvbaKcts/mEuHbv7+Pv2ANk9PCTtHf1og+3 dWIA== X-Gm-Message-State: AIVw111cO/YOMXp0WD5v8wAZIue+utdIwCUUptjBFxo+UN82BDWLixbP 3XltnQrNK1pKGiTXWRk= X-Received: by 10.99.105.70 with SMTP id e67mr4156185pgc.77.1501165922442; Thu, 27 Jul 2017 07:32:02 -0700 (PDT) Received: from linux.local ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id y14sm32579540pfa.52.2017.07.27.07.31.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Jul 2017 07:32:01 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 27 Jul 2017 20:03:07 +0530 Message-Id: <1501165990-28033-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1501165990-28033-1-git-send-email-ashijeetacharya@gmail.com> References: <1501165990-28033-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:c05::243 Subject: [Qemu-devel] [PATCH v8 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),