From patchwork Mon Oct 9 12:59:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9992963 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 013BB60244 for ; Mon, 9 Oct 2017 13:01:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E77F2287BB for ; Mon, 9 Oct 2017 13:01:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC78B287CA; Mon, 9 Oct 2017 13:01: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 83D78287BB for ; Mon, 9 Oct 2017 13:01:34 +0000 (UTC) Received: from localhost ([::1]:57762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xgb-00038P-Pf for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Oct 2017 09:01:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XdC-000181-Uc for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1XdC-00022E-6H for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:03 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:38467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1XdC-00021u-0b; Mon, 09 Oct 2017 08:58:02 -0400 Received: by mail-pf0-x243.google.com with SMTP id a7so27580203pfj.5; Mon, 09 Oct 2017 05:58:01 -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=zjJKNRIS4rIign5XgXZaDxHP/boQZypOU9hYXkMiejg=; b=OJ+xhuqMYNU8Oge/vn0MlCV9OpOqiLeGsHzTQLro6eF87CzuDW4fgARESEddKrg2mv zSBQXAc6hrCPI/LF2iMmiCj8tjIEE5gl5Bq1tB0xvfnvKxHOxo0WAv0SJQ4r4oVDgtNp GlMk0LER+TPlc2dcxnh6uVZMKWglPeOZ6f0RHp6ZWZKEltwa9JIncWSdbScY1ea/fSB+ XSwWuhfJHTJJIV4B2LTWz/L7eJwfaGJZQOuv6HflZSZ0og9TTfg2O6NTfprtpvcTdksn YBZ1TGluDkVSLtoNaEY2rfZgiUDoDngjAHFlIkYd+NgsiTgnfNEdE0kfrBpoWDxOkveS 6KTQ== 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=zjJKNRIS4rIign5XgXZaDxHP/boQZypOU9hYXkMiejg=; b=EnDwGyq4Mds59IW9IIk4wGvFymJFzfGWUZGLQxlLGc067z5Ha8szao/8jixVCllDYS liBMbPBrYtTmsCtKLiD6PpuhijKZbdUvQOHu616kTRsfFt8u3S8ADlhnMz/Zl+kdVMb4 883VgrOLXLBthTeFeEh61kOBcHL/WVZjUb6h7pQmfdQE4XaWn/CEyN/NWmLJJfszSpaM 6BdlURqgDTc1C0MBE1UQZPmSdyWQlYmpW2DbrHFX4AALZI58/q3j30WVMwHsF9AVTtLD is6+I9jqHuJOn5V0mMqJVVwJPzv7VtH9CwvsXD5Y+56kpwE6CHbMB3AurrK0NIyUvx6s e9Eg== X-Gm-Message-State: AMCzsaWO9Tcbl3fbKltuE+oyqhAGUyIkgAD4qjg0lfDnKk2M0AXKAJgk Vy/UbFllKBt92J2jQ6J6d3dr/Q== X-Google-Smtp-Source: AOwi7QAK5OoKTEz+Rm5CYJDFJYsYw7MceCfTYZPT5KUtE8vyEP5Pm19DFlh/cufCunOsoLlhs3JSdw== X-Received: by 10.159.218.75 with SMTP id x11mr8846892plv.92.1507553881023; Mon, 09 Oct 2017 05:58:01 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.57.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:58:00 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:37 +0530 Message-Id: <20171009125940.24220-6-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171009125940.24220-1-ashijeetacharya@gmail.com> References: <20171009125940.24220-1-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v9 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 07707779a0..11bc0f09c7 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1641,6 +1641,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 @@ -1654,9 +1655,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),