From patchwork Mon Jun 5 07:52:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9765679 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 C970060364 for ; Mon, 5 Jun 2017 07:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF2327480 for ; Mon, 5 Jun 2017 07:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94DF627968; Mon, 5 Jun 2017 07:56:34 +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 25D0927480 for ; Mon, 5 Jun 2017 07:56:34 +0000 (UTC) Received: from localhost ([::1]:60142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHmsK-0006V0-Fo for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Jun 2017 03:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHmqz-0006Qh-UH for qemu-devel@nongnu.org; Mon, 05 Jun 2017 03:55:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHmqx-0002y0-Jk for qemu-devel@nongnu.org; Mon, 05 Jun 2017 03:55:10 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dHmqx-0002vN-F5; Mon, 05 Jun 2017 03:55:07 -0400 Received: by mail-pg0-x244.google.com with SMTP id f127so8879724pgc.2; Mon, 05 Jun 2017 00:55:07 -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=SIRKxbdu/OUHeLMgWd9K0FRC9WdFF0AUeGwR8A1Jsa7DY5pZKYSbruRe+zjXhMfpXY esISVi+68iCJ/osDltkmqPCFuUxX6FlJMVias/wkA584W+PTN6HpQaLJCe7rOeshJ9N1 bQIxOk9C2pHYfOHwdWxpoYYezWanYT524kzBTBC+ZwKaZ64WzkSMKVIkZ8/E0HJ/or7N y2x2TqqJmr7KVD1iSJMv+hgKvf2R5XTwtIsOq/cayNnYqzGht5C8hldL20YDd/j6pnX0 YLUysIyBrVE9To/LK2Vmd/Q0KRjkwxou8hezblMNYLYxJfPZ4Fg1t8u/hoB69wtPDdSz oZyw== 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=eq7bVGumrvjY2oDvl7hC5wGWI0K832diftfIYY+nAPfwegpNOZQaDfMR0EiijuKicP Kl4UqbT81Etm9DQm1n1sWwJqu1YYpnA4stO5gOleXnyd2pWQp1PmroE6fBxe3nYUzSBU B6AmSYMU8u/VS/JPbWDums2WRM09hGIezACAQjzLo0rJixxuMLRrhokeHuDlyfrCaibO N56HYEZakQPm81V3cMMYkOYDEJ03lNjy/iRXfB/WB3ksswhDcv0fgoSWIpfCyHFsGd5s JREAeUYdWDijALRyiWzjlxhyT2NHDe7+dJJkcxBH18D9pKWU6fXO92U4DwJQx/FNWW+I iHFg== X-Gm-Message-State: AODbwcAGmvv7X7J2u+7oYYcfPgSygUTz+44f1495p/NoIH57LC8wDAKu 8Qwb2sTqWMz5p1QPg4Y= X-Received: by 10.98.65.213 with SMTP id g82mr19222329pfd.187.1496649306622; Mon, 05 Jun 2017 00:55:06 -0700 (PDT) Received: from linux.local ([47.247.14.139]) by smtp.gmail.com with ESMTPSA id j71sm11775537pge.63.2017.06.05.00.55.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Jun 2017 00:55:06 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 5 Jun 2017 13:22:49 +0530 Message-Id: <1496649172-26982-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1496649172-26982-1-git-send-email-ashijeetacharya@gmail.com> References: <1496649172-26982-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::244 Subject: [Qemu-devel] [PATCH v6 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),