From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507553988361602.6742409574456; Mon, 9 Oct 2017 05:59:48 -0700 (PDT) Received: from localhost ([::1]:57752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xei-00020h-FJ for importer@patchew.org; Mon, 09 Oct 2017 08:59:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xcs-0000pr-IH for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1Xcr-0001ra-NB for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:42 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1Xcr-0001rP-H2; Mon, 09 Oct 2017 08:57:41 -0400 Received: by mail-pf0-x243.google.com with SMTP id z11so10193717pfk.3; Mon, 09 Oct 2017 05:57:41 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.57.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:57:40 -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=SOsS1a9gfdzvuQvETR7oR1HQw20Ak/ij2sOH5vkYgAw=; b=KQwrIs6b/Sy9MWdZUHdJAY/is3LB/KsaSNjIOHGOSLGIeUfMW0Bvxm9DxM7uTp2Rxs sM698GcWcZB/wUDPyKkoSChzNOmsxcgmb9n6c3F9ukpsfcDkY6n9W2BpViJ6FDZNfvo7 SwbhNgquoGtawCu+7uwSeVzfPcMKvBothglM5pVUpyv5G8aPtBTsUqymsQO+05Q6wVHx bBill3eYamd9ICGDfPr0mwkzn1kTbIjTarzk9l4CatqYyFlJjJFbETrx5ddEPGho45M7 DF5Qe8vO7vMNjqpJF5SbjCZDVAkZzYeFGd9NukEBAnrPrnajdajRLZ+p31qkIIaaipj2 1RUw== 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=SOsS1a9gfdzvuQvETR7oR1HQw20Ak/ij2sOH5vkYgAw=; b=mVoQ+hZPk6347keUTR/huq3PYy2gyHrXn6udCcb+1LwfunRmREe8Zt51a6sJVnFpur AEsVn09inEG6IZslQNA/dmpXlk0yP/kbh4ICqMVrRfbMm5ou1fjSBaBjORV9m23DasXP ZfiPRB4QVRUvOATlJ/bM54o4Aa9z6K/ebPX+lee+V/i3LZvton03zeoULSQ+cFwbvlid aO7bD/grIkxUvJme+sRNG2+aTrW+x37ZwCM9gvVKZuzyq/lNV/HYeFqT3UKVxsQDLXM3 R7xLWYVsg1qT4kxY4silz7VpA01jag3fnM+W+f2RzzRSrLjXeK/XH9gzrgqqXK3oNFHw QKAw== X-Gm-Message-State: AMCzsaXfqUCjSGcnYO8YYcg2syTkqzaRlhjn6J3Ff1l8PTBE0SCTIr4j hLoGVwAlJsqkfD6UyB435cA= X-Google-Smtp-Source: AOwi7QDu5Lktsg58gYhz3hJjeNzAGAiRlr7b7gghqoi465eTfY+hRQmZibPHyK7ZW3gXQ5RIwnnlfg== X-Received: by 10.84.232.195 with SMTP id x3mr8989058plm.347.1507553860503; Mon, 09 Oct 2017 05:57:40 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:33 +0530 Message-Id: <20171009125940.24220-2-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 1/8] vmdk: Move vmdk_find_offset_in_cluster() to the top 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the existing vmdk_find_offset_in_cluster() function to the top of the driver. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index c665bcc977..e86ca39ff2 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -242,6 +242,18 @@ static void vmdk_free_last_extent(BlockDriverState *bs) s->extents =3D g_renew(VmdkExtent, s->extents, s->num_extents); } =20 +static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, + int64_t offset) +{ + uint64_t extent_begin_offset, extent_relative_offset; + uint64_t cluster_size =3D extent->cluster_sectors * BDRV_SECTOR_SIZE; + + extent_begin_offset =3D + (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; + extent_relative_offset =3D offset - extent_begin_offset; + return extent_relative_offset % cluster_size; +} + /* Return -ve errno, or 0 on success and write CID into *pcid. */ static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid) { @@ -1283,18 +1295,6 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } =20 -static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, - int64_t offset) -{ - uint64_t extent_begin_offset, extent_relative_offset; - uint64_t cluster_size =3D extent->cluster_sectors * BDRV_SECTOR_SIZE; - - extent_begin_offset =3D - (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; - extent_relative_offset =3D offset - extent_begin_offset; - return extent_relative_offset % cluster_size; -} - static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, int64_t sector_num) { --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150755400336053.956979694322854; Mon, 9 Oct 2017 06:00:03 -0700 (PDT) Received: from localhost ([::1]:57754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xf6-0002Kf-Kc for importer@patchew.org; Mon, 09 Oct 2017 09:00:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xcz-0000vu-E1 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1Xcw-0001uB-Bt for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:49 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:38443) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1Xcw-0001tl-6I; Mon, 09 Oct 2017 08:57:46 -0400 Received: by mail-pf0-x241.google.com with SMTP id a7so27578465pfj.5; Mon, 09 Oct 2017 05:57:45 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.57.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:57:44 -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=1L9xKHQYG5gN46lYSOyf0FOOeRTfMpCyylacb0myeII=; b=qyv7sgxWG1QOauI0daBr0qFd2MKqih2UE1Ng8ha8B+fsndBwRBkeSCF7EW9cfRvESU KUOk215/5BC7gnWzYxOptD+Dbl7JwNAQAIHyO2xirmf0v1/UrbOMMDDBEjGDC+DxoZMV HIL3+4F+K3N8zwN6R0T3Kz1FJ9xaV2ZCACV34hOkNyOY8yF7XAR5dP7EuHEOtReBqtXi ES5rzGhApzR17/Q1cpW3iXfxfFD+1Bx6ODmu4f9oZIJO7+dCO29MrRSowcMpuumih4Lh WKQtJJofZeV49H8P9Xe8ADYvHqrTJsRifQkX1Jvg46w84DzeF7hDrW5Gr72vA2B11fqN PqZw== 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=1L9xKHQYG5gN46lYSOyf0FOOeRTfMpCyylacb0myeII=; b=QtRVkuyfo6sZk3uTgOoVlCzmQjIyVyFv2WcMI84Fg0opmyBnqHEbttMajH9nfjP+dm 4/mgUNsyopw7YhB3ne0TyZL/ujCIBpGmRAWkwZahB2NbWfM5vA1L00jrCYzz0FKZHdSG FrafnZtBs+JWRNr6gLruMRC5L2ov+cII043SUkrrEbfciUYTX4FVnfYZrLQRm45zJQ1E fLO4Er+mYsunVKL7is9LhEqwgSFUW6qsN38QIF6kNBQ73r/09S1dgtDc9pLb6XcCO7BI tDVzrm3Cb1I+DiD+ZLbh4cNhRMRXREVQH6GBvyKuxLzGznkPVSCOBkMZT5cGbgNLJdBY k2IA== X-Gm-Message-State: AMCzsaXKk2/Bq4qFwL2TjkvJlP/oIxvYVlZkOBcisNNyG3SmCr9nxwuB togp4sHOg9A9lzzJvdxzr7OrLA== X-Google-Smtp-Source: AOwi7QBLRs2FYBT1e8wOKCR690iL3RiU1i3wVfdAOnbvrBJv5x4nz3LoOiOcxfCgW6Bkn/T9yC+WAQ== X-Received: by 10.101.85.4 with SMTP id f4mr9059719pgr.10.1507553865180; Mon, 09 Oct 2017 05:57:45 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:34 +0530 Message-Id: <20171009125940.24220-3-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::241 Subject: [Qemu-devel] [PATCH v9 2/8] vmdk: Rename get_whole_cluster() to vmdk_perform_cow() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename the existing function get_whole_cluster() to vmdk_perform_cow() as its sole purpose is to perform COW for the first and the last allocated clusters if needed. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index e86ca39ff2..109c589b43 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1045,8 +1045,8 @@ static void vmdk_refresh_limits(BlockDriverState *bs,= Error **errp) } } =20 -/** - * get_whole_cluster +/* + * vmdk_perform_cow * * Copy backing file's cluster that covers @sector_num, otherwise write ze= ro, * to the cluster at @cluster_sector_num. @@ -1054,13 +1054,18 @@ static void vmdk_refresh_limits(BlockDriverState *b= s, Error **errp) * If @skip_start_sector < @skip_end_sector, the relative range * [@skip_start_sector, @skip_end_sector) is not copied or written, and le= ave * it for call to write user data in the request. + * + * Returns: + * VMDK_OK: on success + * + * VMDK_ERROR: in error cases */ -static int get_whole_cluster(BlockDriverState *bs, - VmdkExtent *extent, - uint64_t cluster_offset, - uint64_t offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) +static int vmdk_perform_cow(BlockDriverState *bs, + VmdkExtent *extent, + uint64_t cluster_offset, + uint64_t offset, + uint64_t skip_start_bytes, + uint64_t skip_end_bytes) { int ret =3D VMDK_OK; int64_t cluster_bytes; @@ -1261,7 +1266,7 @@ static int get_cluster_offset(BlockDriverState *bs, * This problem may occur because of insufficient space on host di= sk * or inappropriate VM shutdown. */ - ret =3D get_whole_cluster(bs, extent, cluster_sector * BDRV_SECTOR= _SIZE, + ret =3D vmdk_perform_cow(bs, extent, cluster_sector * BDRV_SECTOR_= SIZE, offset, skip_start_bytes, skip_end_bytes); if (ret) { return ret; --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507554007252780.1950874047867; Mon, 9 Oct 2017 06:00:07 -0700 (PDT) Received: from localhost ([::1]:57753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xey-0002E7-CK for importer@patchew.org; Mon, 09 Oct 2017 08:59:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xd1-0000xd-Gf for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1Xd0-0001wQ-GO for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:51 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1Xd0-0001vr-8t; Mon, 09 Oct 2017 08:57:50 -0400 Received: by mail-pf0-x242.google.com with SMTP id z11so10194689pfk.3; Mon, 09 Oct 2017 05:57:50 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.57.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:57:48 -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=rDgzsycOLvOFBDTIcjAlbOL166d1VnW+OrwxLBVnFuM=; b=PRenKElUmzMfr2ZXI+D9qMZnOjuHvYPj9Fz4QGLmtSy4BIgahv1ssyx3V3EG/la2Oo 7bnvdAwR5/oB5wPO3BPKfAdU1txs9scRemkxqSamrAEeGxXdXUIVGP+he3qOMrH1mTyt Zuv3Xs1WUjeKVniJnopR5yO/eDN0csFz25CCoUdjJgQZsqkq5FqmICTjptpth1hMmWdh 8aP0YHAvzw0zyBPBWaRwOyDE2D8JkQlM8IquTWdp8a1UOjyy1Nekvsys6EqQqSa+lN0+ +pRiubk0JszuyuFMxOkORjggYZxzDij7JbWPj0tpPWB1x5ZJmohZ0lO9zGxXgPNA8ZJm 9yRQ== 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=rDgzsycOLvOFBDTIcjAlbOL166d1VnW+OrwxLBVnFuM=; b=RcBrfWlLtXCDB1clMmA3R+XX9JQhdpEywRyzJjd5gc8GXTB/FxdK2aPuTc0Oe7jQcH k+1PLRUAKBz7QKKmEZN9hAMkKGSK3Pn2L5bCJ+ad8iSIVilCFPWPYPbaLwzHvci/yaS5 kt5l0n+eJpJFwak1Cl49cariPUzeH/HGd+OKMhZgAmpEhl0biERDmgS8p25pm1T/e3Xc Nj91bxaggoC4VQENF4Wvk+y1JoiA27KVrFEyjtm8WeG03mckJnjfL5Nc+j8yEABAHDoI ia/hXhGgimSaOJMnlDSYgqM7S0ZsmmmA3TuULX9MViE+dlcs5fwU0e3oentvPpdc8dec qMig== X-Gm-Message-State: AMCzsaXSYnUVke1HG1PaPxpTsuiXBLRKAXUsaPSBfKibZnzpr8n5c7al YFUsmrkco820EEpcUEWCqqpP2w== X-Google-Smtp-Source: AOwi7QB60/v0qrSpPSFw7IHjjJxet+HTGEFEjtXaFOXovPzytFaYXlU79Z6MoF57/UFtU5YwvloBMA== X-Received: by 10.101.93.65 with SMTP id e1mr9284104pgt.150.1507553869177; Mon, 09 Oct 2017 05:57:49 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:35 +0530 Message-Id: <20171009125940.24220-4-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::242 Subject: [Qemu-devel] [PATCH v9 3/8] vmdk: Rename get_cluster_offset() to vmdk_get_cluster_offset() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename the existing get_cluster_offset() to vmdk_get_cluster_offset() and update name in all the callers accordingly. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 109c589b43..d4ea92bdcf 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1161,7 +1161,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMeta= Data *m_data, } =20 /** - * get_cluster_offset + * vmdk_get_cluster_offset * * Look up cluster offset in extent file by sector number, and store in * @cluster_offset. @@ -1180,14 +1180,14 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMe= taData *m_data, * VMDK_UNALLOC if cluster is not mapped and @allocate is false. * VMDK_ERROR if failed. */ -static int get_cluster_offset(BlockDriverState *bs, - VmdkExtent *extent, - VmdkMetaData *m_data, - uint64_t offset, - bool allocate, - uint64_t *cluster_offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) +static int vmdk_get_cluster_offset(BlockDriverState *bs, + VmdkExtent *extent, + VmdkMetaData *m_data, + uint64_t offset, + bool allocate, + uint64_t *cluster_offset, + uint64_t skip_start_bytes, + uint64_t skip_end_bytes) { unsigned int l1_index, l2_offset, l2_index; int min_index, i, j; @@ -1321,9 +1321,9 @@ static int64_t coroutine_fn vmdk_co_get_block_status(= BlockDriverState *bs, return 0; } qemu_co_mutex_lock(&s->lock); - ret =3D get_cluster_offset(bs, extent, NULL, - sector_num * 512, false, &offset, - 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, NULL, + sector_num * 512, false, &offset, + 0, 0); qemu_co_mutex_unlock(&s->lock); =20 index_in_cluster =3D vmdk_find_index_in_cluster(extent, sector_num); @@ -1514,8 +1514,8 @@ vmdk_co_preadv(BlockDriverState *bs, uint64_t offset,= uint64_t bytes, ret =3D -EIO; goto fail; } - ret =3D get_cluster_offset(bs, extent, NULL, - offset, false, &cluster_offset, 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, NULL, + offset, false, &cluster_offset, 0, 0= ); offset_in_cluster =3D vmdk_find_offset_in_cluster(extent, offset); =20 n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE @@ -1601,10 +1601,10 @@ static int vmdk_pwritev(BlockDriverState *bs, uint6= 4_t offset, n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - offset_in_cluster); =20 - ret =3D get_cluster_offset(bs, extent, &m_data, offset, - !(extent->compressed || zeroed), - &cluster_offset, offset_in_cluster, - offset_in_cluster + n_bytes); + ret =3D vmdk_get_cluster_offset(bs, extent, &m_data, offset, + !(extent->compressed || zeroed), + &cluster_offset, offset_in_cluster, + offset_in_cluster + n_bytes); if (extent->compressed) { if (ret =3D=3D VMDK_OK) { /* Refuse write to allocated cluster for streamOptimized */ @@ -1613,8 +1613,8 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, return -EIO; } else { /* allocate */ - ret =3D get_cluster_offset(bs, extent, &m_data, offset, - true, &cluster_offset, 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, &m_data, offse= t, + true, &cluster_offset, 0, 0); } } if (ret =3D=3D VMDK_ERROR) { @@ -2244,9 +2244,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheck= Result *result, ret =3D -EINVAL; break; } - ret =3D get_cluster_offset(bs, extent, NULL, - sector_num << BDRV_SECTOR_BITS, - false, &cluster_offset, 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, NULL, + sector_num << BDRV_SECTOR_BITS, + false, &cluster_offset, 0, 0); if (ret =3D=3D VMDK_ERROR) { fprintf(stderr, "ERROR: could not get cluster_offset for sector %" --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507554135454894.6504690751148; Mon, 9 Oct 2017 06:02:15 -0700 (PDT) Received: from localhost ([::1]:57780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XhG-00049u-Oo for importer@patchew.org; Mon, 09 Oct 2017 09:02:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xd8-00013f-Sq for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1Xd5-0001zC-QQ for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:57:58 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1Xd5-0001ys-ID; Mon, 09 Oct 2017 08:57:55 -0400 Received: by mail-pf0-x242.google.com with SMTP id b85so7216019pfj.1; Mon, 09 Oct 2017 05:57:55 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:57:54 -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=77Ftzxb9xf8mVe3AO01KfI/usXg3/u5zQO1fq1cJmrE=; b=aiqdKAjeJRM8vmOFHmpaM4KsO4AFjou6VQA0f/eviHOwdXBAxyZ/wmYCtQAGM8CnTq 5IxM59Ac8UtHMB6JUyObVQNiapKYnylaK3ybQOHwS0wnLYtWu8ASN1OgLnnzrQ1nfADH /TGNiDQSFlDzGYJqCcOB2xc4mKQOH4cdoYCAdOJ/5iiFK+ntZcKKPzgAKczkHr9NXFB0 eClq4NVxpQI5cafveHQErVkdKm+tqlW19blWOq+X75w/8FKzHDi434yjb3T/FlnYezK2 xNFvQUjGhLtyM18CXsCBk3jnObupHzIA4vkHLIw0OkG16yac1Kk9/2E3IjIBPfXKvFOa 9NAQ== 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=77Ftzxb9xf8mVe3AO01KfI/usXg3/u5zQO1fq1cJmrE=; b=hvF1NBxHVSjMUM6+IpRpBZIVHvLym9YvIOhJZJeTUu/pqO96AJHGaK5aW0MDr+xxhw DN0o1mobMsmXq+y0resAoCgz3L1JCTYPXXxgjhio2aV7m0C62hw4lOCDPY8zEjNWlzwn CkeOvYHaVYuRh7drWS34hJP5Zy5FzouFAHOjJ7/IHCQTFpgp+kiYT9CD1LLmhGfl3zlT aryhZhqpkCOmqioDHONBNxc8OXCBjVL8NzqoWWiK2t7OW1FdkcDxU2YzyxD0ABNCLpuk OBf8LD+mi3XEEWk5GfGFCQCaZXJdqjy7Hvf8JdhhZnO8goFjt8BWbZUwrcN/6TWnAojx WKMA== X-Gm-Message-State: AMCzsaVXux046sl46dPHciaYPfZB+hEAzWcZ9g5J/zWL/wSl7TS5kPXr NL8goKaqB5Xtela9srkBAi3Csg== X-Google-Smtp-Source: AOwi7QBhq1TJuaTIDu31tvCvSJBZlfNmHQtFRjnD7/Zl821AVrNOAwSw4Sm/a2J6C3CiyuuAMaAnsg== X-Received: by 10.99.147.69 with SMTP id w5mr6149765pgm.401.1507553874558; Mon, 09 Oct 2017 05:57:54 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:36 +0530 Message-Id: <20171009125940.24220-5-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::242 Subject: [Qemu-devel] [PATCH v9 4/8] vmdk: Factor out metadata loading code out of vmdk_get_cluster_offset() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the cluster tables loading code out of the existing vmdk_get_cluster_offset() function and implement it in separate get_cluster_table() and vmdk_l2load() functions. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 153 ++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 105 insertions(+), 48 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index d4ea92bdcf..07707779a0 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1160,6 +1160,105 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMe= taData *m_data, return VMDK_OK; } =20 +/* + * vmdk_l2load + * + * Load a new L2 table into memory. If the table is in the cache, the cache + * is used; otherwise the L2 table is loaded from the image file. + * + * Returns: + * VMDK_OK: on success + * VMDK_ERROR: in error cases + */ +static int vmdk_l2load(VmdkExtent *extent, uint64_t offset, int l2_offset, + uint32_t **new_l2_table, int *new_l2_index) +{ + int min_index, i, j; + uint32_t *l2_table; + uint32_t min_count; + + for (i =3D 0; i < L2_CACHE_SIZE; i++) { + if (l2_offset =3D=3D extent->l2_cache_offsets[i]) { + /* increment the hit count */ + if (++extent->l2_cache_counts[i] =3D=3D UINT32_MAX) { + for (j =3D 0; j < L2_CACHE_SIZE; j++) { + extent->l2_cache_counts[j] >>=3D 1; + } + } + l2_table =3D extent->l2_cache + (i * extent->l2_size); + goto found; + } + } + /* not found: load a new entry in the least used one */ + min_index =3D 0; + min_count =3D UINT32_MAX; + for (i =3D 0; i < L2_CACHE_SIZE; i++) { + if (extent->l2_cache_counts[i] < min_count) { + min_count =3D extent->l2_cache_counts[i]; + min_index =3D i; + } + } + l2_table =3D extent->l2_cache + (min_index * extent->l2_size); + if (bdrv_pread(extent->file, + (int64_t)l2_offset * 512, + l2_table, + extent->l2_size * sizeof(uint32_t) + ) !=3D extent->l2_size * sizeof(uint32_t)) { + return VMDK_ERROR; + } + + extent->l2_cache_offsets[min_index] =3D l2_offset; + extent->l2_cache_counts[min_index] =3D 1; +found: + *new_l2_index =3D ((offset >> 9) / extent->cluster_sectors) % extent->= l2_size; + *new_l2_table =3D l2_table; + + return VMDK_OK; +} + +/* + * get_cluster_table + * + * For a given offset, load (and allocate if needed) the l2 table. + * + * Returns: + * VMDK_OK: on success + * + * VMDK_UNALLOC: if cluster is not mapped + * + * VMDK_ERROR: in error cases + */ +static int get_cluster_table(VmdkExtent *extent, uint64_t offset, + int *new_l1_index, int *new_l2_offset, + int *new_l2_index, uint32_t **new_l2_table) +{ + int l1_index, l2_offset, l2_index; + uint32_t *l2_table; + int ret; + + offset -=3D (extent->end_sector - extent->sectors) * SECTOR_SIZE; + l1_index =3D (offset >> 9) / extent->l1_entry_sectors; + if (l1_index >=3D extent->l1_size) { + return VMDK_ERROR; + } + l2_offset =3D extent->l1_table[l1_index]; + if (!l2_offset) { + return VMDK_UNALLOC; + } + + ret =3D vmdk_l2load(extent, offset, l2_offset, &l2_table, &l2_index); + if (ret < 0) { + return ret; + } + + *new_l1_index =3D l1_index; + *new_l2_offset =3D l2_offset; + *new_l2_index =3D l2_index; + *new_l2_table =3D l2_table; + + return VMDK_OK; +} + /** * vmdk_get_cluster_offset * @@ -1189,66 +1288,24 @@ static int vmdk_get_cluster_offset(BlockDriverState= *bs, uint64_t skip_start_bytes, uint64_t skip_end_bytes) { - unsigned int l1_index, l2_offset, l2_index; - int min_index, i, j; - uint32_t min_count, *l2_table; + int l1_index, l2_offset, l2_index; + uint32_t *l2_table; bool zeroed =3D false; int64_t ret; int64_t cluster_sector; =20 - if (m_data) { - m_data->valid =3D 0; - } if (extent->flat) { *cluster_offset =3D extent->flat_start_offset; return VMDK_OK; } =20 - offset -=3D (extent->end_sector - extent->sectors) * SECTOR_SIZE; - l1_index =3D (offset >> 9) / extent->l1_entry_sectors; - if (l1_index >=3D extent->l1_size) { - return VMDK_ERROR; - } - l2_offset =3D extent->l1_table[l1_index]; - if (!l2_offset) { - return VMDK_UNALLOC; - } - for (i =3D 0; i < L2_CACHE_SIZE; i++) { - if (l2_offset =3D=3D extent->l2_cache_offsets[i]) { - /* increment the hit count */ - if (++extent->l2_cache_counts[i] =3D=3D 0xffffffff) { - for (j =3D 0; j < L2_CACHE_SIZE; j++) { - extent->l2_cache_counts[j] >>=3D 1; - } - } - l2_table =3D extent->l2_cache + (i * extent->l2_size); - goto found; - } - } - /* not found: load a new entry in the least used one */ - min_index =3D 0; - min_count =3D 0xffffffff; - for (i =3D 0; i < L2_CACHE_SIZE; i++) { - if (extent->l2_cache_counts[i] < min_count) { - min_count =3D extent->l2_cache_counts[i]; - min_index =3D i; - } - } - l2_table =3D extent->l2_cache + (min_index * extent->l2_size); - if (bdrv_pread(extent->file, - (int64_t)l2_offset * 512, - l2_table, - extent->l2_size * sizeof(uint32_t) - ) !=3D extent->l2_size * sizeof(uint32_t)) { - return VMDK_ERROR; + ret =3D get_cluster_table(extent, offset, &l1_index, &l2_offset, + &l2_index, &l2_table); + if (ret < 0) { + return ret; } =20 - extent->l2_cache_offsets[min_index] =3D l2_offset; - extent->l2_cache_counts[min_index] =3D 1; - found: - l2_index =3D ((offset >> 9) / extent->cluster_sectors) % extent->l2_si= ze; cluster_sector =3D le32_to_cpu(l2_table[l2_index]); - if (extent->has_zero_grain && cluster_sector =3D=3D VMDK_GTE_ZEROED) { zeroed =3D true; } --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150755412254627.2994386959989; Mon, 9 Oct 2017 06:02:02 -0700 (PDT) Received: from localhost ([::1]:57779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xgy-0003xB-SJ for importer@patchew.org; Mon, 09 Oct 2017 09:01:56 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D 0; VmdkMetaData m_data; + uint64_t extent_end; =20 if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 @@ -1654,9 +1655,17 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64= _t offset, if (!extent) { return -EIO; } + extent_end =3D extent->end_sector * BDRV_SECTOR_SIZE; + offset_in_cluster =3D vmdk_find_offset_in_cluster(extent, offset); - n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - - offset_in_cluster); + + /* truncate n_bytes to first cluster because we need to perform CO= W */ + if (offset_in_cluster > 0) { + n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_S= IZE + - offset_in_cluster); + } else { + n_bytes =3D MIN(bytes, extent_end - offset); + } =20 ret =3D vmdk_get_cluster_offset(bs, extent, &m_data, offset, !(extent->compressed || zeroed), --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507554264272831.312813339719; Mon, 9 Oct 2017 06:04:24 -0700 (PDT) Received: from localhost ([::1]:57786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XjB-0005K7-FD for importer@patchew.org; Mon, 09 Oct 2017 09:04:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XdJ-0001DJ-Np for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1XdI-00026A-AF for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:09 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1XdI-00025j-2L; Mon, 09 Oct 2017 08:58:08 -0400 Received: by mail-pf0-x242.google.com with SMTP id m28so27449786pfi.0; Mon, 09 Oct 2017 05:58:07 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:58:06 -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=wMmHzSBYCqTOfYe3z26qaCx1tO8lVkM/lLXaudnhrtE=; b=ITPeeXpcPXkq8/nOsHBtL0VV1MbdZqcdJOGO0hv5TjFyAHCbT3dfjQ7UOjV67COJg1 LeR2i/S9W8AvKYujYLrvCvIWy9KThe1Ji1hVWjil694IU5N21QdI6wGuAysp+nfBIVbD 4C+RkoGbBNeQi/x2IhAauH/v2R9PNyAirDxPljGZgds0H0I3Oc8IuL4UEvG/8LBByuE8 ompCTxaWzOWG8lUkvqKRIPlbLi1pSDn8YrFMjADJB4ufA87vAL3g3/6ik8mZ4p7EZ2NX xgCJGipPt30YN7FgVppb8JV283KgnAxp68tqgR68RssZCNN/zRUtOrhKdXkmBB8nHDor C4yA== 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=wMmHzSBYCqTOfYe3z26qaCx1tO8lVkM/lLXaudnhrtE=; b=MsND3tjEH/kCeKW60cyaDSpESHVPsINEMxELdq28PK8mwbFWvYnDSNeY3r78sPzSbc d0LX9LRnS5zIXmeyiUPEOPPcVyx8c/njrvC5Yxgks/hJCq7a3CuYggQTFJ1LQjG2t2D9 OzxK2gw0ZV/R4rnMIcgYFwKsQHeaFSsbMe3ngeQg2CEzqFy/vDVsDyJhEN0mNZCDsiQ2 TuJLGDI/ATQopPEsm7ZfA+KbFtpAUfEWINJyRnrW1kLd1yAszwMoTbyITzqdGJ/Bc5hg +8C3ntVqK1eIkiOdRvyLRL0XViQIxzyXGRyr9Qaufb6bnriqYX6jdm6YxApXtm47ej/H jO3w== X-Gm-Message-State: AMCzsaVMQT8ZSRGkXzN9vvxFaMGTM8mrHjhWCdiQydI1BKViDh7FulD8 MJTXyrICtoBwNvaBcj1ZP8g= X-Google-Smtp-Source: AOwi7QDVbCxRs/YdL6a+UWjgpbJZfnxqZwgLI5mdIHZwm7fe7IcqLWhIRQyRX2jIOH66a2FjMIUZtA== X-Received: by 10.99.174.78 with SMTP id e14mr8987189pgp.155.1507553887014; Mon, 09 Oct 2017 05:58:07 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:38 +0530 Message-Id: <20171009125940.24220-7-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::242 Subject: [Qemu-devel] [PATCH v9 6/8] vmdk: New functions to assist allocating multiple clusters 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce two new helper functions handle_alloc() and vmdk_alloc_cluster_offset(). handle_alloc() helps to allocate multiple clusters at once starting from a given offset on disk and performs COW if necessary for first and last allocated clusters. vmdk_alloc_cluster_offset() helps to return the offset of the first of the many newly allocated clusters. Also, provide proper documentation for both. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 191 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 11bc0f09c7..d5dfd21abe 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -136,6 +136,7 @@ typedef struct VmdkMetaData { unsigned int l2_offset; int valid; uint32_t *l2_cache_entry; + uint32_t nb_clusters; } VmdkMetaData; =20 typedef struct VmdkGrainMarker { @@ -1259,6 +1260,183 @@ static int get_cluster_table(VmdkExtent *extent, ui= nt64_t offset, return VMDK_OK; } =20 +/* + * vmdk_handle_alloc + * + * Allocate new clusters for an area that either is yet unallocated or nee= ds a + * copy on write. + * + * Returns: + * VMDK_OK: if new clusters were allocated, *bytes may be decrease= d if + * the new allocation doesn't cover all of the requested = area. + * *cluster_offset is updated to contain the offset of the + * first newly allocated cluster. + * + * VMDK_UNALLOC: if no clusters could be allocated. *cluster_offset is = left + * unchanged. + * + * VMDK_ERROR: in error cases + */ +static int vmdk_handle_alloc(BlockDriverState *bs, VmdkExtent *extent, + uint64_t offset, uint64_t *cluster_offset, + int64_t *bytes, VmdkMetaData *m_data, + bool allocate, uint32_t *alloc_clusters_count= er) +{ + int l1_index, l2_offset, l2_index; + uint32_t *l2_table; + uint32_t cluster_sector; + uint32_t nb_clusters; + bool zeroed =3D false; + uint64_t skip_start_bytes, skip_end_bytes; + int ret; + + ret =3D get_cluster_table(extent, offset, &l1_index, &l2_offset, + &l2_index, &l2_table); + if (ret < 0) { + return ret; + } + + cluster_sector =3D le32_to_cpu(l2_table[l2_index]); + + skip_start_bytes =3D vmdk_find_offset_in_cluster(extent, offset); + /* Calculate the number of clusters to look for. Here we truncate the = last + * cluster, i.e. 1 less than the actual value calculated as we may nee= d to + * perform COW for the last one. */ + nb_clusters =3D DIV_ROUND_UP(skip_start_bytes + *bytes, + extent->cluster_sectors << BDRV_SECTOR_BITS= ) - 1; + + nb_clusters =3D MIN(nb_clusters, extent->l2_size - l2_index); + assert(nb_clusters <=3D INT_MAX); + + /* update bytes according to final nb_clusters value */ + if (nb_clusters !=3D 0) { + *bytes =3D ((nb_clusters * extent->cluster_sectors) << BDRV_SECTOR= _BITS) + - skip_start_bytes; + } else { + nb_clusters =3D 1; + } + *alloc_clusters_counter +=3D nb_clusters; + + /* we need to use MIN() for basically 3 cases that arise : + * 1. alloc very first cluster : here skip_start_bytes >=3D 0 and + * *bytes <=3D cluster_size. + * 2. alloc middle clusters : here *bytes is a perfect multiple of + * cluster_size and skip_start_bytes is 0. + * 3. alloc very last cluster : here *bytes <=3D cluster_size and + * skip_start_bytes is 0 + */ + skip_end_bytes =3D skip_start_bytes + MIN(*bytes, + extent->cluster_sectors * BDRV_SECTOR_SIZE + - skip_start_bytes); + + if (extent->has_zero_grain && cluster_sector =3D=3D VMDK_GTE_ZEROED) { + zeroed =3D true; + } + + if (!cluster_sector || zeroed) { + if (!allocate) { + return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; + } + + cluster_sector =3D extent->next_cluster_sector; + extent->next_cluster_sector +=3D extent->cluster_sectors + * nb_clusters; + + ret =3D vmdk_perform_cow(bs, extent, cluster_sector * BDRV_SECTOR_= SIZE, + offset, skip_start_bytes, + skip_end_bytes); + if (ret < 0) { + return ret; + } + if (m_data) { + m_data->valid =3D 1; + m_data->l1_index =3D l1_index; + m_data->l2_index =3D l2_index; + m_data->l2_offset =3D l2_offset; + m_data->l2_cache_entry =3D &l2_table[l2_index]; + m_data->nb_clusters =3D nb_clusters; + } + } + *cluster_offset =3D cluster_sector << BDRV_SECTOR_BITS; + return VMDK_OK; +} + +/* + * vmdk_alloc_clusters + * + * For a given offset on the virtual disk, find the cluster offset in vmdk + * file. If the offset is not found, allocate a new cluster. + * + * If the cluster is newly allocated, m_data->nb_clusters is set to the nu= mber + * of contiguous clusters that have been allocated. In this case, the other + * fields of m_data are valid and contain information about the first allo= cated + * cluster. + * + * Returns: + * + * VMDK_OK: on success and @cluster_offset was set + * + * VMDK_UNALLOC: if no clusters were allocated and @cluster_offset = is + * set to zero + * + * VMDK_ERROR: in error cases + */ +static int vmdk_alloc_clusters(BlockDriverState *bs, + VmdkExtent *extent, + VmdkMetaData *m_data, uint64_t offset, + bool allocate, uint64_t *cluster_offset, + int64_t bytes, + uint32_t *alloc_clusters_counter) +{ + uint64_t start, remaining; + uint64_t new_cluster_offset; + int64_t n_bytes; + int ret; + + if (extent->flat) { + *cluster_offset =3D extent->flat_start_offset; + return VMDK_OK; + } + + start =3D offset; + remaining =3D bytes; + new_cluster_offset =3D 0; + *cluster_offset =3D 0; + n_bytes =3D 0; + if (m_data) { + m_data->valid =3D 0; + } + + /* due to L2 table margins all bytes may not get allocated at once */ + while (true) { + + if (!*cluster_offset) { + *cluster_offset =3D new_cluster_offset; + } + + start +=3D n_bytes; + remaining -=3D n_bytes; + new_cluster_offset +=3D n_bytes; + + if (remaining =3D=3D 0) { + break; + } + + n_bytes =3D remaining; + + ret =3D vmdk_handle_alloc(bs, extent, start, &new_cluster_offset, + &n_bytes, m_data, allocate, + alloc_clusters_counter); + + if (ret < 0) { + return ret; + + } + } + + return VMDK_OK; +} + /** * vmdk_get_cluster_offset * @@ -1642,6 +1820,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, uint64_t bytes_done =3D 0; VmdkMetaData m_data; uint64_t extent_end; + uint32_t alloc_clusters_counter =3D 0; =20 if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 @@ -1667,10 +1846,10 @@ static int vmdk_pwritev(BlockDriverState *bs, uint6= 4_t offset, n_bytes =3D MIN(bytes, extent_end - offset); } =20 - ret =3D vmdk_get_cluster_offset(bs, extent, &m_data, offset, - !(extent->compressed || zeroed), - &cluster_offset, offset_in_cluster, - offset_in_cluster + n_bytes); + ret =3D vmdk_alloc_clusters(bs, extent, &m_data, offset, + !(extent->compressed || zeroed), + &cluster_offset, n_bytes, + &alloc_clusters_counter); if (extent->compressed) { if (ret =3D=3D VMDK_OK) { /* Refuse write to allocated cluster for streamOptimized */ @@ -1679,8 +1858,9 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, return -EIO; } else { /* allocate */ - ret =3D vmdk_get_cluster_offset(bs, extent, &m_data, offse= t, - true, &cluster_offset, 0, 0); + ret =3D vmdk_alloc_clusters(bs, extent, &m_data, offset, + true, &cluster_offset, n_bytes, + &alloc_clusters_counter); } } if (ret =3D=3D VMDK_ERROR) { @@ -1688,10 +1868,11 @@ static int vmdk_pwritev(BlockDriverState *bs, uint6= 4_t offset, } if (zeroed) { /* Do zeroed write, buf is ignored */ - if (extent->has_zero_grain && - offset_in_cluster =3D=3D 0 && - n_bytes >=3D extent->cluster_sectors * BDRV_SECTOR_SIZ= E) { - n_bytes =3D extent->cluster_sectors * BDRV_SECTOR_SIZE; + if (extent->has_zero_grain && offset_in_cluster =3D=3D 0 && + n_bytes >=3D extent->cluster_sectors * BDRV_SECTOR_SIZ= E * + alloc_clusters_counter) { + n_bytes =3D extent->cluster_sectors * BDRV_SECTOR_SIZE * + alloc_clusters_counter; if (!zero_dry_run) { /* update L2 tables */ if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED) --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507554254225500.54084077339735; Mon, 9 Oct 2017 06:04:14 -0700 (PDT) Received: from localhost ([::1]:57785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xiv-0005Bw-Le for importer@patchew.org; Mon, 09 Oct 2017 09:03:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XdQ-0001JW-5T for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1XdM-0002AM-UO for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:16 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:33686) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1XdM-00029t-LE; Mon, 09 Oct 2017 08:58:12 -0400 Received: by mail-pf0-x244.google.com with SMTP id m28so27450245pfi.0; Mon, 09 Oct 2017 05:58:12 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.58.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:58:11 -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=iguFLwDlrza/4tJYngdmzGLEOpBl+xtRjuB8Ti2e7Rg=; b=Rllbj0t7rHxTUchvOFsFuaYI0u72egc6vNLqFKvlJJgGFQOOdCemi7uzhfAaJvWe9R lH60Nr11pncAWo1GGvE72iJa/FLc3Tndswxa6pZb+Nzot7vnvW/iP4AxaEuKFX+8G/57 cCl741HaccNrZLmYaNuzphN9FnK/TmA6rUFfvvyGycAx10ILl/b7T/JngRKHYk7Qw1Me PLIC0YOQR5uf4/TBoj+q2Hh42fIyiP1leYBIJcMrZKon7FKepL25pDGQrfp5r5ZbqOjT Dfu0ZiYQb4AMVlTPVRXutvdOp+o/4c4ZqOVc1Tweo67OBJmes7RW7Ip3KYzqk/hgIWyd /zFg== 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=iguFLwDlrza/4tJYngdmzGLEOpBl+xtRjuB8Ti2e7Rg=; b=FMuTF6ANVQdo5kGLKfJP4y1o1wiZWMQj9JHCywGICBOgIgzCcYJw7YOm6Zr+BrCMpc +G30oqtxHLIAXeN9Lq0sUofUV/oN2R/55gKtZBqVfbOTeuw3NFmFpziXmnR4erjSa5Pd wAPuUx9a6lxvjQmn2XUVGYxfixMjTZsLUNs7Nj6bu0a7WIDN3DWGmoukNpGuh/cQIcS1 WMRPzZujBzAaFWzjPn1A2dmoZpWQ9wT/0yTts/tEDfyExHWzpt4vQhlDYNstYfU1m/5A 4gajvBSYZ4gOBoWJ4DGbpkXBwN5AyzY7NO6qVSyQMWa+ki0BplMGpLHL8r+A+glaGn/u r4zg== X-Gm-Message-State: AMCzsaVsl7yXegBw/jFsNMzOgIJIOF5MBjbt3RhAs1wdClgX1DvW3Q6r viR+J5+nLmf4HkHn8jQgxrE= X-Google-Smtp-Source: AOwi7QAGKWgLp4Bsj59rkAXVzWcnYEtDX/JuF5V3CWwkhbA/RgwsDILzFGv/z0Hn2Gza+y4XNnnN5g== X-Received: by 10.159.245.147 with SMTP id a19mr8848037pls.256.1507553891555; Mon, 09 Oct 2017 05:58:11 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:39 +0530 Message-Id: <20171009125940.24220-8-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::244 Subject: [Qemu-devel] [PATCH v9 7/8] vmdk: Update metadata for multiple clusters 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Include a next pointer in VmdkMetaData struct to point to the previous allocated L2 table. Modify vmdk_L2update to start updating metadata for allocation of multiple clusters at once. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 101 insertions(+), 27 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index d5dfd21abe..cbeffb1552 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -137,6 +137,8 @@ typedef struct VmdkMetaData { int valid; uint32_t *l2_cache_entry; uint32_t nb_clusters; + uint32_t offset; + struct VmdkMetaData *next; } VmdkMetaData; =20 typedef struct VmdkGrainMarker { @@ -1133,34 +1135,87 @@ exit: return ret; } =20 -static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, - uint32_t offset) +static int vmdk_alloc_cluster_link_l2(VmdkExtent *extent, + VmdkMetaData *m_data, bool zeroed) { - offset =3D cpu_to_le32(offset); + int i; + uint32_t offset, temp_offset; + int *l2_table_array; + int l2_array_size; + + if (zeroed) { + temp_offset =3D VMDK_GTE_ZEROED; + } else { + temp_offset =3D m_data->offset; + } + + l2_array_size =3D sizeof(uint32_t) * m_data->nb_clusters; + l2_table_array =3D qemu_try_blockalign(extent->file->bs, + QEMU_ALIGN_UP(l2_array_size, + BDRV_SECTOR_SIZE)); + if (l2_table_array =3D=3D NULL) { + return VMDK_ERROR; + } + memset(l2_table_array, 0, QEMU_ALIGN_UP(l2_array_size, BDRV_SECTOR_SIZ= E)); /* update L2 table */ + offset =3D temp_offset; + for (i =3D 0; i < m_data->nb_clusters; i++) { + l2_table_array[i] =3D cpu_to_le32(offset); + if (!zeroed) { + offset +=3D extent->cluster_sectors; + } + } if (bdrv_pwrite_sync(extent->file, - ((int64_t)m_data->l2_offset * 512) - + (m_data->l2_index * sizeof(offset)), - &offset, sizeof(offset)) < 0) { + ((int64_t)m_data->l2_offset * 512) + + ((m_data->l2_index) * sizeof(offset)), + l2_table_array, l2_array_size) < 0) { return VMDK_ERROR; } /* update backup L2 table */ if (extent->l1_backup_table_offset !=3D 0) { m_data->l2_offset =3D extent->l1_backup_table[m_data->l1_index]; if (bdrv_pwrite_sync(extent->file, - ((int64_t)m_data->l2_offset * 512) - + (m_data->l2_index * sizeof(offset)), - &offset, sizeof(offset)) < 0) { + ((int64_t)m_data->l2_offset * 512) + + ((m_data->l2_index) * sizeof(offset)), + l2_table_array, l2_array_size) < 0) { return VMDK_ERROR; } } + + offset =3D temp_offset; if (m_data->l2_cache_entry) { - *m_data->l2_cache_entry =3D offset; + for (i =3D 0; i < m_data->nb_clusters; i++) { + *m_data->l2_cache_entry =3D cpu_to_le32(offset); + m_data->l2_cache_entry++; + + if (!zeroed) { + offset +=3D extent->cluster_sectors; + } + } } =20 + qemu_vfree(l2_table_array); return VMDK_OK; } =20 +static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, + bool zeroed) +{ + int ret; + + while (m_data->next !=3D NULL) { + + ret =3D vmdk_alloc_cluster_link_l2(extent, m_data, zeroed); + if (ret < 0) { + return ret; + } + + m_data =3D m_data->next; + } + + return VMDK_OK; +} + /* * vmdk_l2load * @@ -1277,9 +1332,10 @@ static int get_cluster_table(VmdkExtent *extent, uin= t64_t offset, * * VMDK_ERROR: in error cases */ + static int vmdk_handle_alloc(BlockDriverState *bs, VmdkExtent *extent, uint64_t offset, uint64_t *cluster_offset, - int64_t *bytes, VmdkMetaData *m_data, + int64_t *bytes, VmdkMetaData **m_data, bool allocate, uint32_t *alloc_clusters_count= er) { int l1_index, l2_offset, l2_index; @@ -1288,6 +1344,7 @@ static int vmdk_handle_alloc(BlockDriverState *bs, Vm= dkExtent *extent, uint32_t nb_clusters; bool zeroed =3D false; uint64_t skip_start_bytes, skip_end_bytes; + VmdkMetaData *old_m_data; int ret; =20 ret =3D get_cluster_table(extent, offset, &l1_index, &l2_offset, @@ -1348,13 +1405,21 @@ static int vmdk_handle_alloc(BlockDriverState *bs, = VmdkExtent *extent, if (ret < 0) { return ret; } - if (m_data) { - m_data->valid =3D 1; - m_data->l1_index =3D l1_index; - m_data->l2_index =3D l2_index; - m_data->l2_offset =3D l2_offset; - m_data->l2_cache_entry =3D &l2_table[l2_index]; - m_data->nb_clusters =3D nb_clusters; + + if (m_data !=3D NULL) { + old_m_data =3D *m_data; + *m_data =3D g_malloc0(sizeof(**m_data)); + + **m_data =3D (VmdkMetaData) { + .valid =3D 1, + .l1_index =3D l1_index, + .l2_index =3D l2_index, + .l2_offset =3D l2_offset, + .l2_cache_entry =3D &l2_table[l2_index], + .nb_clusters =3D nb_clusters, + .offset =3D cluster_sector, + .next =3D old_m_data, + }; } } *cluster_offset =3D cluster_sector << BDRV_SECTOR_BITS; @@ -1383,7 +1448,7 @@ static int vmdk_handle_alloc(BlockDriverState *bs, Vm= dkExtent *extent, */ static int vmdk_alloc_clusters(BlockDriverState *bs, VmdkExtent *extent, - VmdkMetaData *m_data, uint64_t offset, + VmdkMetaData **m_data, uint64_t offset, bool allocate, uint64_t *cluster_offset, int64_t bytes, uint32_t *alloc_clusters_counter) @@ -1403,8 +1468,8 @@ static int vmdk_alloc_clusters(BlockDriverState *bs, new_cluster_offset =3D 0; *cluster_offset =3D 0; n_bytes =3D 0; - if (m_data) { - m_data->valid =3D 0; + if (*m_data) { + (*m_data)->valid =3D 0; } =20 /* due to L2 table margins all bytes may not get allocated at once */ @@ -1818,10 +1883,12 @@ static int vmdk_pwritev(BlockDriverState *bs, uint6= 4_t offset, int64_t offset_in_cluster, n_bytes; uint64_t cluster_offset; uint64_t bytes_done =3D 0; - VmdkMetaData m_data; uint64_t extent_end; + VmdkMetaData *m_data; uint32_t alloc_clusters_counter =3D 0; =20 + m_data =3D g_new0(VmdkMetaData, 1); + if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 " total_sectors=3D0x%" PRIx64, @@ -1830,6 +1897,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, } =20 while (bytes > 0) { + m_data->next =3D NULL; extent =3D find_extent(s, offset >> BDRV_SECTOR_BITS, extent); if (!extent) { return -EIO; @@ -1875,7 +1943,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, alloc_clusters_counter; if (!zero_dry_run) { /* update L2 tables */ - if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED) + if (vmdk_L2update(extent, m_data, zeroed) !=3D VMDK_OK) { return -EIO; } @@ -1889,11 +1957,9 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64= _t offset, if (ret) { return ret; } - if (m_data.valid) { + if (m_data->valid) { /* update L2 tables */ - if (vmdk_L2update(extent, &m_data, - cluster_offset >> BDRV_SECTOR_BITS) - !=3D VMDK_OK) { + if (vmdk_L2update(extent, m_data, zeroed) !=3D VMDK_OK) { return -EIO; } } @@ -1902,6 +1968,13 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64= _t offset, offset +=3D n_bytes; bytes_done +=3D n_bytes; =20 + while (m_data->next !=3D NULL) { + VmdkMetaData *next; + next =3D m_data->next; + g_free(m_data); + m_data =3D next; + } + /* update CID on the first write every time the virtual disk is * opened */ if (!s->cid_updated) { @@ -1912,6 +1985,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, s->cid_updated =3D true; } } + g_free(m_data); return 0; } =20 --=20 2.13.5 From nobody Mon Apr 29 23:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150755437305347.14145470824508; Mon, 9 Oct 2017 06:06:13 -0700 (PDT) Received: from localhost ([::1]:57801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1Xl6-0006sT-8K for importer@patchew.org; Mon, 09 Oct 2017 09:06:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XdT-0001N2-O0 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1XdS-0002Dx-KT for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:58:19 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:38503) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1XdS-0002Da-Bf; Mon, 09 Oct 2017 08:58:18 -0400 Received: by mail-pf0-x243.google.com with SMTP id a7so27581945pfj.5; Mon, 09 Oct 2017 05:58:18 -0700 (PDT) Received: from localhost.localdomain ([27.251.197.195]) by smtp.gmail.com with ESMTPSA id d190sm14781283pgc.11.2017.10.09.05.58.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 05:58:16 -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=JV70LmVWv57R6jWJ5/+1X3dmJLF1JVav5+wRwguopgI=; b=tiZbw9gNlUTH4/I9lgujpFznxv7HSd08+ps/fEeePrJ4MN8BABJN1T5gj+YdyrXhZH UapmGqGKT7RttexOiqW92R2a8AD82sqiKsvLZxBIgYhj2NL8Zc1BSBwaOj9fVWAkERo7 xeUKLOkHrIvTPqJGe82d2fnAga6jZf5Yq1LYBzzu61yngYA2eDG1pks+ltyeS9EphVUD wjRk2a7zqp/YckrhRh5v9L8N81haArqqF6HI01jexZrCEIpbiIrseL49oUhA40+lBXNV YV9R/VdcZZ58RZPxqBxV4dr4IQ0dNadfbQORS2ADGTq1eY9l81tVsxkIxjZpNtWApnXt XMzg== 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=JV70LmVWv57R6jWJ5/+1X3dmJLF1JVav5+wRwguopgI=; b=UtrChntkO3kvylQN/DXvZkISe8c6BY9VpKQkJHYNOwimfRBZo3e64qaUGxE7xo008I vg44X0GrK9HsIyTCjgUc/NZrIp1SyjxL4eb0yUZyt9kj+jle4W3mSMOdzQy4DPzfvJa+ 2fXfKQV/x6GguOliBvHMG76/N1mDJna2Q6i/fWepKtz9xvAC7DCO1DlYxds1mBsOJCoW Euxom1QjuFOqFMoD5hb4iu4oWr5YCB6A/8/42vo+xQyzMxQyqMaLhTrT1bqGJ19ByQ0F ac0zqV7XtxfVE+NN/Z4vuHx9J8qsyF7DgtXRy7dmAVZCtCq+6OpLdgId+65s3V53GaXt 4GSA== X-Gm-Message-State: AMCzsaUxb3hiweAUIuBEmeq1afREZ5wITHZpM0mxfClng1GRWOgyZfVD fErp9bSI1e4qAHWPmvYOrUA= X-Google-Smtp-Source: AOwi7QDaYVqFPIq2nqixZqUkZGOLEfVSDXCneXFB9MGSUTBZZhe4ymdB47b+HobBc2y1oJDVOccHZw== X-Received: by 10.159.253.148 with SMTP id q20mr8977951pls.308.1507553897352; Mon, 09 Oct 2017 05:58:17 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 9 Oct 2017 18:29:40 +0530 Message-Id: <20171009125940.24220-9-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 8/8] vmdk: Make vmdk_get_cluster_offset() return cluster offset only 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vmdk_alloc_clusters() introduced earlier now handles the task of allocating clusters and performing COW when needed. Thus we can change vmdk_get_cluster_offset() to stick to the sole purpose of returning cluster offset using sector number. Update the changes at all call sites. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 56 ++++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index cbeffb1552..497e30f6df 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1511,25 +1511,16 @@ static int vmdk_alloc_clusters(BlockDriverState *bs, * For flat extents, the start offset as parsed from the description file = is * returned. * - * For sparse extents, look up in L1, L2 table. If allocate is true, retur= n an - * offset for a new cluster and update L2 cache. If there is a backing fil= e, - * COW is done before returning; otherwise, zeroes are written to the allo= cated - * cluster. Both COW and zero writing skips the sector range - * [@skip_start_sector, @skip_end_sector) passed in by caller, because cal= ler - * has new data to write there. + * For sparse extents, look up the L1, L2 table. * * Returns: VMDK_OK if cluster exists and mapped in the image. - * VMDK_UNALLOC if cluster is not mapped and @allocate is false. - * VMDK_ERROR if failed. + * VMDK_UNALLOC if cluster is not mapped. + * VMDK_ERROR if failed */ static int vmdk_get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, - VmdkMetaData *m_data, uint64_t offset, - bool allocate, - uint64_t *cluster_offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) + uint64_t *cluster_offset) { int l1_index, l2_offset, l2_index; uint32_t *l2_table; @@ -1554,31 +1545,9 @@ static int vmdk_get_cluster_offset(BlockDriverState = *bs, } =20 if (!cluster_sector || zeroed) { - if (!allocate) { - return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; - } - - cluster_sector =3D extent->next_cluster_sector; - extent->next_cluster_sector +=3D extent->cluster_sectors; - - /* First of all we write grain itself, to avoid race condition - * that may to corrupt the image. - * This problem may occur because of insufficient space on host di= sk - * or inappropriate VM shutdown. - */ - ret =3D vmdk_perform_cow(bs, extent, cluster_sector * BDRV_SECTOR_= SIZE, - offset, skip_start_bytes, skip_end_bytes); - if (ret) { - return ret; - } - if (m_data) { - m_data->valid =3D 1; - m_data->l1_index =3D l1_index; - m_data->l2_index =3D l2_index; - m_data->l2_offset =3D l2_offset; - m_data->l2_cache_entry =3D &l2_table[l2_index]; - } + return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; } + *cluster_offset =3D cluster_sector << BDRV_SECTOR_BITS; return VMDK_OK; } @@ -1621,9 +1590,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(= BlockDriverState *bs, return 0; } qemu_co_mutex_lock(&s->lock); - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, - sector_num * 512, false, &offset, - 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, sector_num * 512, &offset); qemu_co_mutex_unlock(&s->lock); =20 index_in_cluster =3D vmdk_find_index_in_cluster(extent, sector_num); @@ -1814,13 +1781,14 @@ vmdk_co_preadv(BlockDriverState *bs, uint64_t offse= t, uint64_t bytes, ret =3D -EIO; goto fail; } - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, - offset, false, &cluster_offset, 0, 0= ); + offset_in_cluster =3D vmdk_find_offset_in_cluster(extent, offset); =20 n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - offset_in_cluster); =20 + ret =3D vmdk_get_cluster_offset(bs, extent, offset, &cluster_offse= t); + if (ret !=3D VMDK_OK) { /* if not allocated, try to read from parent image, if exist */ if (bs->backing && ret !=3D VMDK_ZEROED) { @@ -2565,9 +2533,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheck= Result *result, ret =3D -EINVAL; break; } - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, + ret =3D vmdk_get_cluster_offset(bs, extent, sector_num << BDRV_SECTOR_BITS, - false, &cluster_offset, 0, 0); + &cluster_offset); if (ret =3D=3D VMDK_ERROR) { fprintf(stderr, "ERROR: could not get cluster_offset for sector %" --=20 2.13.5