From patchwork Sat Apr 22 05:13: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: 9694145 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 9B9556038D for ; Sat, 22 Apr 2017 05:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E3FF28409 for ; Sat, 22 Apr 2017 05:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EFD32846F; Sat, 22 Apr 2017 05:16:35 +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 2A2A428409 for ; Sat, 22 Apr 2017 05:16:35 +0000 (UTC) Received: from localhost ([::1]:34218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1nPO-0002aI-C3 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 22 Apr 2017 01:16:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1nMR-0008Ny-CZ for qemu-devel@nongnu.org; Sat, 22 Apr 2017 01:13:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1nMQ-0000V0-GI for qemu-devel@nongnu.org; Sat, 22 Apr 2017 01:13:31 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:35275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1nMQ-0000Uo-Ba; Sat, 22 Apr 2017 01:13:30 -0400 Received: by mail-it0-x244.google.com with SMTP id e132so2405088ite.2; Fri, 21 Apr 2017 22:13:30 -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=lkZ43kOpzh7EC0OqxbYQGZSsMAxJVqJ3UbrDPcf30js=; b=HaA229IDI9a1fQCeBxXTMAiPOuOi4a684yMiLFRJfQbCsj6KheWbihi/AtPimQoG0e /4Cjbg6ZFBwQDP7RD/6BQwwoSv75Ry5CC7rftAEt1XtH4FTcxULJhKf4iCM1cuuZBOeq JdcGQREgQQUXo4x+6tN25iU7XVAikF/6RFRDLbeU/vVo4BhoZ8oWazfBnjlFYD3tCJA3 0HJiW+lfVn5hbkFPPrWsMrBHcufu05t3DBT078hKHxck5VflkfnzkpfxO6ChM8v4sPIi PWUWerr6K12EYpIpB8Etz5TMpXLG2iZW+z4YoI9Q4IPWpDtA8ZK7sIa/C11+E2F+qqQ5 NQmA== 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=lkZ43kOpzh7EC0OqxbYQGZSsMAxJVqJ3UbrDPcf30js=; b=Xiya/KZfQbGFa0UuE5eY8/ir/PA2zwLunuHG77uYZtaQyrN/nt1upZqQf3P9Vay1tC XrmBdtT1rCxNX35eXPM7NvAh2bYY/Dk7+4NpI2o3zdxiLe+sm6nGBThUUa2CxtTkvvj+ vWEPQequuz0RbyCEP9vuab2viGTQn1hgePxi2FPHdkXZlfXldDv9w3g+8nfcLHBCeEss m0b5p+BmSHW20uU+VTpNGaJJTiwirXBkilv/RjSAs1eXAimKUiMudet12SJUGPhoNU3m 4YOfvxsNlr2Xx5FSsqSqJN/g/xTmkXgSJ1Z1Ed1KMir7sRFALfc3YmaI090czlSedFNg mAVA== X-Gm-Message-State: AN3rC/52JY56Yc4r2X6sdNt+m6If/wRd4mO1Wy5q9dXhb6nt3d6xEwZJ p7Qvh2KiSrYbyDjC X-Received: by 10.99.121.133 with SMTP id u127mr15403300pgc.96.1492838009877; Fri, 21 Apr 2017 22:13:29 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id d82sm18780120pfl.124.2017.04.21.22.13.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Apr 2017 22:13:29 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 22 Apr 2017 10:43:38 +0530 Message-Id: <1492838021-10538-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1492838021-10538-1-git-send-email-ashijeetacharya@gmail.com> References: <1492838021-10538-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:4001:c0b::244 Subject: [Qemu-devel] [PATCH v4 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 4cee868..7862791 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),