From nobody Sun Apr 28 15:22:24 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.zoho.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 149872824320251.817384981999794; Thu, 29 Jun 2017 02:24:03 -0700 (PDT) Received: from localhost ([::1]:37929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVg9-0005Gx-U4 for importer@patchew.org; Thu, 29 Jun 2017 05:24:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVep-0004IB-GI for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:22:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVeo-0006fP-Nq for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:22:39 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:36597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVeo-0006f7-IB; Thu, 29 Jun 2017 05:22:38 -0400 Received: by mail-pg0-x243.google.com with SMTP id u36so11233582pgn.3; Thu, 29 Jun 2017 02:22:38 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.22.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:22:37 -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=Frh6VDB0/xAj1TJL449/st2nOhRT2c4sZdDlRf5/ir8=; b=uQT0BINXt+KIhNh58+Su+rBl3znJnpbJiGX8sjqste3tqBBpzBmcZw6Ys0Dm5I2FxR VA5qCtQOBJNt4XoF+qd1HwK3vICcRnva0IwNJ7e71OXFr7HdvdUA87PMck829FqWFg1l lyVuPXxAdH+4gBo/h3+r4RV8SxoD/shfwRK60W3s1BsVet84pL+Gr2TJgx0f2wa1PYF9 tX/jWzVyFas8zhHXAm5Vx8EoIdefINOt+vFG0s7jQm9GcSxSDipsoAkiuzhKzUGAzvfs Bbv6/0+7uUx6RO+LQJuzuRQnIJN7agwm++yZIfQBfcqCrLr7Ct1MSefh+EHmoXMq4gmj tH1A== 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=Frh6VDB0/xAj1TJL449/st2nOhRT2c4sZdDlRf5/ir8=; b=KPIEGW+eZ+TK6ADXSYCaXBoLnXBSLp1q72+Z+8fqHVSF6+lwR+hu5ZPrxFG0mUFOkw sAaWOWeQPxxfUfpc8+rCCX7RhPKpCasYgIioPyL822qqdYy8G6SzjZ0aGql/Azq/Ld6r DNl4nqvNF6bDSbDmdlBBcqMCs0dUDu3p51rYby4XR5w6Yl6WNE3hEhfViDPsEBQN23th Czk/BEAWLI3OM+5vOt25xbt7OG8yV029kd7t1GJYrewCkku3x9MCAc4MTMGc9pUzQfIq ZKrDZAsgs6s7AYv3xyNvpGNn58tvdoKhRwhecXMz+TQpC3FWkwFJKq4Of3+OLV3AhQ7y Tldw== X-Gm-Message-State: AKS2vOwHZ+GV+kiQt6QEPseuv7PdEg6bC4sc/3t+BFtod0oqiKOEmpol gTonLJmPjG5UUA== X-Received: by 10.99.96.204 with SMTP id u195mr14520819pgb.125.1498728157757; Thu, 29 Jun 2017 02:22:37 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:34 +0530 Message-Id: <1498728221-23979-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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 v7 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 a9bd22b..22be887 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; +} + static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) { char *desc; @@ -1266,18 +1278,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.6.2 From nobody Sun Apr 28 15:22:24 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.zoho.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 1498728357210181.84239783866212; Thu, 29 Jun 2017 02:25:57 -0700 (PDT) Received: from localhost ([::1]:37941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVhz-0007Vi-Hd for importer@patchew.org; Thu, 29 Jun 2017 05:25:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVey-0004QP-Ok for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:22:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVey-0006kz-1C for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:22:48 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:36674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVex-0006kn-Rj; Thu, 29 Jun 2017 05:22:47 -0400 Received: by mail-pf0-x241.google.com with SMTP id z6so12378540pfk.3; Thu, 29 Jun 2017 02:22:47 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.22.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:22:46 -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=y0aLdU8eyizcBISOMqtI7Bfk7gF3uIFfg+flRUveKjg=; b=u+KkZbqHzrqSIsjZiG7ohN8R7M8fP0Gc84QQjiNHZFJACiPjEZwFxr5rjyaNo3+OYr hR74r5yL6GuulDmXXrRhwyN42+Xp7E6x89Z5PwM0k9DjAkbMS6wN/Qt07P6ukCOY5tfu s0UtWWOKa0KtUbOwa6d1RDvZIjPdprWQEY2k7iUNvWQZE66f4wZ1reH9s82D/GyyKi1Z 3J1bBjv+/jziwwY874SL0ajQQ3dfDaPecbmx4MCYGOYzodf3tfJwkSnejp1fICajjGF2 8XCdNBRzD5cebSN0dyh8bP/F+P1CfMRFfFjomRTGsoG9OEWhV7btrk8ULzXydAT7xwYd 5vNg== 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=y0aLdU8eyizcBISOMqtI7Bfk7gF3uIFfg+flRUveKjg=; b=pGTi1O29+Qh6JbpgoKTf2zfPJM4JdCvSImyPR8JbCh3E46dS2SElcn93HscvOo+Hl6 VQRCBl/32QhvnH4YKwy5bhs+KVrLwIPmR5MFY3we9Tq7mnT2nAZkWRxQ2SRHeQ1YyKr/ P9sYSy+WLrF0TtK2puwuQGSxDbKFiFNsp0zNhwCU7LMS5CalCLQLNSb24Jk9hqJVT+n2 6QK61qK4gVaMS1/EHuVhAllp3iIrbKCqITAWdtjVdWZeF4Tma4qr8BInqiNV9weJSGeO IG9k+wajfNLN8AL/cRuuwGu6+ZxpYV8SPFcBY/0RQJLuAjaw8//8zNvq+3E6r+yOJJw/ GkwA== X-Gm-Message-State: AKS2vOw+24l1D9TKHHOqPmfqSyT2izs9O4bWHF8N7JD7TLQerF8P/9ka lUSslEe/vSdwKA== X-Received: by 10.84.231.134 with SMTP id g6mr6531911plk.241.1498728166875; Thu, 29 Jun 2017 02:22:46 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:35 +0530 Message-Id: <1498728221-23979-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c00::241 Subject: [Qemu-devel] [PATCH v7 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 22be887..73ae786 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1028,8 +1028,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. @@ -1037,13 +1037,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; @@ -1244,7 +1249,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.6.2 From nobody Sun Apr 28 15:22:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1498728361809566.8618432305785; Thu, 29 Jun 2017 02:26:01 -0700 (PDT) Received: from localhost ([::1]:37942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVi3-0007XB-EG for importer@patchew.org; Thu, 29 Jun 2017 05:25:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfC-0004bX-41 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVf7-0006o7-5F for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:02 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVf6-0006np-Tv; Thu, 29 Jun 2017 05:22:57 -0400 Received: by mail-pf0-x241.google.com with SMTP id d5so12387962pfe.1; Thu, 29 Jun 2017 02:22:56 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.22.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:22:55 -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=wlzoG7oQRHBbI3gL8iwuPmGQOHTo9rMYaIJacXohg3U=; b=pqMa5i35yOpoEdpyFZZ4BP51kpe9pfIbKybXOeUlWftcEJN6IyzhTgg4m0XYPJ+0ko EZRL++s47AJ7txUfWDTpIx9BE49IfO5zyMvN/aRGmDhC2fKIY3xpnmE5LdwDiDvZI+GR CANTpPbDa3K1Fr/58cdkYYq0GtDWEXnaGx8iRWh5PEdiiHUtMqZmWYrjhPTzmcoj8PW0 jQ11BBIaZWlEPlfza0Zu2QggenQiaRHgOhuPCBZFh11sOtDss24jT4t+rkQ3g58dfuSZ 6eF7kAc85k9RLaV3hRcML2NE26Wq6ha33FinAgU0W/O8t8dD+uUmFKT129XBuDkYchGa /nAQ== 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=wlzoG7oQRHBbI3gL8iwuPmGQOHTo9rMYaIJacXohg3U=; b=udUP6adqUE5YNiGE8/7LrU4XUYrtc5tlpklJfZ36S5uhn6oOfwWt1Px7szuZg9OUd6 J2vD6ZW73MSL+x8CEbAElsUyhXYh1UF/Bb+6wk7OMb8w9wfbdu9nbyRJIpipaOzghb5k hTI2WqWbCFXFgMObSGNjFrHZsUNn6ObhbmyPfQm2Za21oyY74RRA4NByI7UlRhRvSRCM F1+F7YKqT72DqVFI8yN1Ksq+skr4UU0+AMWADiTFGnD8X6/DMoOcsOgYoHSQucBG92P4 /zvKHEke8UKi18Edeh6bV0zoUpjc52eLJUZE7Hq1zzUVpBVHOWhYfzPUqPPaOGeqSV0D ERUQ== X-Gm-Message-State: AKS2vOzGHoJmfoOaakExVxwQRfhlT6cbR4vLBZU59ewCNIOzYsapSR4V oXRfATxyiYBMDQ== X-Received: by 10.99.250.69 with SMTP id g5mr14301320pgk.11.1498728175994; Thu, 29 Jun 2017 02:22:55 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:36 +0530 Message-Id: <1498728221-23979-4-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c00::241 Subject: [Qemu-devel] [PATCH v7 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_6 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 73ae786..f403981 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1144,7 +1144,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. @@ -1163,14 +1163,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; @@ -1304,9 +1304,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); @@ -1497,8 +1497,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 @@ -1584,10 +1584,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 */ @@ -1596,8 +1596,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) { @@ -2229,9 +2229,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheck= Result *result, sector_num); 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.6.2 From nobody Sun Apr 28 15:22:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1498728461796611.6614565527228; Thu, 29 Jun 2017 02:27:41 -0700 (PDT) Received: from localhost ([::1]:37950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVjf-0000K4-CR for importer@patchew.org; Thu, 29 Jun 2017 05:27:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfF-0004eY-FN for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfE-0006r2-7F for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:05 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33262) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfD-0006qd-VA; Thu, 29 Jun 2017 05:23:04 -0400 Received: by mail-pf0-x243.google.com with SMTP id e199so12375136pfh.0; Thu, 29 Jun 2017 02:23:03 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.22.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:02 -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=qAEkPGIHiVSIezdBZIr8XdEFG3fHyjwyJ/aTSGOQiII=; b=NOCpPvnZj6tpillK9ehcF5PoiizIsqMaivE5UtEs2047SjsUPqd1euI7XTwhqLYfsl TOFU60KyK7i33ugl+RHgGLmG6ZwVbYeHTUY9NC6TkHNUarOyPqW+GYa8jqgWbtjT7zA9 sLaYO1VSu7eeB+Dk19vy3vytY19+X8a8q+h+eeHYLJ8QBsl0so1tjygJHh2/cwuWsKnj TxRVSWdZc+dvuNS4VjMBxqxXjZciK1EzhUihxrCYhJwbE9KjCvpgoPY+qgWQ48NY9VA+ LCNW3VERDQqKb64FU4WkPWkNhU0tbhF2pQbJXYIoX9EGcrrD9nTj5WlrKTjaEShIpk7N 8jqQ== 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=qAEkPGIHiVSIezdBZIr8XdEFG3fHyjwyJ/aTSGOQiII=; b=mYcoJuJs8kTRBBqg4GZDmqrutD4hgJeeElp8cn3KnegTddvdk0LwnCUA979wt8OFAF bW6TZg4LdCW9negg6BLliHcp4IjOcEXSSn3IapsCXGuPh04QKVnPKG8SCm5168e6m0/m LOn15AFQmR2UjAZB1OVHUBl3z472SqS8hfE47AbHCCAyGSfouNuFrnLL+VZzymqaLzWt PYyTiighJruPZqCDFd+m1kC2jKs9Vy+q3Ar/hNQaofP699UWCiwlvkqq66FzHINp2Hah wJuoXlphuL/0Uzsi7bGa3IlwyIIRj2zfZAGsoKJo/iSqsAbkQVTCunMfoRfOHzGePh+x 3pFg== X-Gm-Message-State: AKS2vOwhtOcwjItaCV6C+UWJwNl83H+d6V4PoWmOuaU/yJkxAYXNeKJB FhXpM+KpmyYpfA== X-Received: by 10.99.2.78 with SMTP id 75mr15123404pgc.120.1498728183023; Thu, 29 Jun 2017 02:23:03 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:37 +0530 Message-Id: <1498728221-23979-5-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c00::243 Subject: [Qemu-devel] [PATCH v7 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_6 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 f403981..5647f53 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1143,6 +1143,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 * @@ -1172,66 +1271,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.6.2 From nobody Sun Apr 28 15:22:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1498728533289490.0951740363578; Thu, 29 Jun 2017 02:28:53 -0700 (PDT) Received: from localhost ([::1]:37952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVkq-0001kF-2h for importer@patchew.org; Thu, 29 Jun 2017 05:28:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfQ-0004oO-4h for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfN-0006xo-6P for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:16 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfN-0006xO-0k; Thu, 29 Jun 2017 05:23:13 -0400 Received: by mail-pf0-x241.google.com with SMTP id d5so12388790pfe.1; Thu, 29 Jun 2017 02:23:12 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23: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=ZHvK2Vys1FDOQRWCQbXjjaMPx12sSGaapnbVk2Pi7bM=; b=tnRtpFVnUs+wwFqp/DWhGRwfbLHlbNouvpsvvrT8hQ2jAy1hEprwkPvxXR0HBGF95M zN41PRA/XSqFNfXM3o3W+qvPMIJ1OrDs4f/1LHSkd+I/RXrEOgX+GaKDwLc2FJOqOU++ rmxlxzWz8dRJilWAAmYHQC653VaqcAP9i1dNNB5tcRRBG0q5Sd6oSZSEDL8NGCJNvGZt jKu8S4IQnTQbDHArOhyocTTwY7WTfpTxU3be9r8wLUcg6D/igPWeRsMMw/z5IKQbAF1I aGkk8FzTcXuGzwOKFjVpO0hWtUhl5Phsmb9EpXfMvRLHfbI6JtqVVCenb8WPHc2jIwsn PFtg== 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=pcq5U7quzLwX2D8hP92heIq1oh9Pskd5aTe1SFcNCqKFLrO/zZP8L4IbF0HiT4T+kX 3P4OU29zuCP8cJYwHVKCdkUc4UHdTGrTQYLDeM4pv2oksYUkb4lOGEA/6IU6kYSiS7eI 5qcfF+F6UrP1Lt7/O6YGTxsJfLsKJFjZ29Mq0eMmrgzeuVyKLaY9b2UzRVkS6Ag+Zka4 iJUXJ31YJpf+umitGH9BIDxc/HUdC8zL6S5segwYkfbvUUI5Fjww/WDe5asusaghcDD0 OP1tdBgQNIQBc9gkQhdI2x11lIJMXJc8pO6MRVETmk0sYg619kPVNa7NZDlCbTf/c9yn dFKg== X-Gm-Message-State: AKS2vOwriHmH/s26nizLSZgTED5WMhxtoqistNj2NkPplydcgfAxhJTq h80LCsMRZyjrSA== X-Received: by 10.99.174.4 with SMTP id q4mr14516132pgf.196.1498728192245; Thu, 29 Jun 2017 02:23:12 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:38 +0530 Message-Id: <1498728221-23979-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c00::241 Subject: [Qemu-devel] [PATCH v7 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_6 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 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 =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 @@ -1637,9 +1638,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.6.2 From nobody Sun Apr 28 15:22:24 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.zoho.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 1498728460184868.5402023967972; Thu, 29 Jun 2017 02:27:40 -0700 (PDT) Received: from localhost ([::1]:37949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVje-0000Iy-Jd for importer@patchew.org; Thu, 29 Jun 2017 05:27:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfU-0004sE-GY for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfS-00070T-Vp for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:20 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfS-000707-O1; Thu, 29 Jun 2017 05:23:18 -0400 Received: by mail-pg0-x243.google.com with SMTP id j186so11236565pge.1; Thu, 29 Jun 2017 02:23:18 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:17 -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=F2xntu2EW174EmdyJVGi3OJgSs8CFfAxPim9BWoBa3Y=; b=doPP8S/YgMBTF437dtIxUqd60UBE9YR4g2pfxAKZmpzyDDAsdbWnWu85oOkUvgFitr xmHNWMmov+lQiABP4jBUALJKrw9+SVR0qdYshW3vXnBN84gNCcWbGZCOwDAnb47fxEHd H2g8yZuzu+L4Z29Mp+ZtqSFbYPrgNAeQMDpYAoJCvfOv+uck63sXqTFB7Dnl0nf9qSeT 4vrPtB3SPSeAh5VzKbj90jeHZVPyfJveT034Wq1vj8UANUOxE1AF2iY1oxgTeoC+BNaM TsFFDTNSK2I3NhiSXGLwMHq61JRGC3Jvh8QrNa7OeLONme1Km70mLEwJKH9zOUdOIoDK ghZg== 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=F2xntu2EW174EmdyJVGi3OJgSs8CFfAxPim9BWoBa3Y=; b=mtgzmiWrqUoOG7p1SblZlpFV2iS7JplevfMXotiyqSs2m1SYoO42GIf20JwHhLXn2Y XnD08IlrkrYTW6lzoppRp3ys0+1bPs3qEoia1euLqZxO59lCIrVzruZ6+pRvL5zyRTZs ri9FsTXSrW7CgdQ0av83/IesPaiABwPV8fMPt62jWDkG4kn+Idacx2PhbzoHucbCKaD5 VuovjQxqu0MzHFdTpjPilw9R3MoSL5UxaAT0lAyfzUZF1CVdxja0N588owtnTJiWJCLQ lJCuKBlKoTx/CMNyYAqX77hi4/99YdeAJK2Cwi6uVKP0XuW4lZUvWEfTHKUJ7FKz0Ob2 Awyw== X-Gm-Message-State: AKS2vOzaIBdzEVfFT250+ZgMbTtQ6Quty6zW+O8Ch17cqgBY//Q1PVZJ BPFBoGnYbIHXWw== X-Received: by 10.84.150.164 with SMTP id h33mr17280135plh.152.1498728197867; Thu, 29 Jun 2017 02:23:17 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:39 +0530 Message-Id: <1498728221-23979-7-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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 v7 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 | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 190 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index fe2046b..277db16 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 { @@ -1242,6 +1243,182 @@ 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 *total_alloc_clusters) +{ + 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; + } + *total_alloc_clusters +=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 *total_alloc_clusters) +{ + 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, total_alloc_clusters); + + if (ret < 0) { + return ret; + + } + } + + return VMDK_OK; +} + /** * vmdk_get_cluster_offset * @@ -1625,6 +1802,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 total_alloc_clusters =3D 0; =20 if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 @@ -1650,10 +1828,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, + &total_alloc_clusters); if (extent->compressed) { if (ret =3D=3D VMDK_OK) { /* Refuse write to allocated cluster for streamOptimized */ @@ -1662,8 +1840,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, + &total_alloc_clusters); } } if (ret =3D=3D VMDK_ERROR) { @@ -1671,10 +1850,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 * + total_alloc_clusters) { + n_bytes =3D extent->cluster_sectors * BDRV_SECTOR_SIZE * + total_alloc_clusters; if (!zero_dry_run) { /* update L2 tables */ if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED) --=20 2.6.2 From nobody Sun Apr 28 15:22:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1498728292319696.4262290379806; Thu, 29 Jun 2017 02:24:52 -0700 (PDT) Received: from localhost ([::1]:37930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVgu-00065l-F4 for importer@patchew.org; Thu, 29 Jun 2017 05:24:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVfb-0004yH-9X for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfZ-00073J-1K for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:27 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:35329) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfY-00072a-Or; Thu, 29 Jun 2017 05:23:24 -0400 Received: by mail-pf0-x244.google.com with SMTP id s66so12366534pfs.2; Thu, 29 Jun 2017 02:23:24 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:23 -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=HM0L7M4aatoqWpIA7MMzf+h8uZggiHVJFAPEzBYpJ4E=; b=LDnLjY23mFGCVPDBC1H0M+qdJxMUijnYIR/T+OktdHcDKE/c1g+n+e7+0kaaYgfqRb b7m7xUrKtQ+obtDes7WhjiSQHlGfrIyHswGuN/vqrhnANPWktFx75QTnS8ovqwOBDMsj JepKQsk9cPCo7mEEnhSxLVG8YGWSOVqGjPN42obE02/rDXO/8MSxeiOZZdt0JY03z6l+ V8Kwlm5HGh01pH/cat/hmieKo/Ev8SGMMxHFFEOSb9NfDTJdRvVGKdcBWmb0dCPwD412 PjXpeNunAlP41g6jR/oLJj+sr3mFB7ejdNZqutgBm7RLrFEgWx/IE/KJKfnOzPgspymN zA3g== 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=HM0L7M4aatoqWpIA7MMzf+h8uZggiHVJFAPEzBYpJ4E=; b=b5hynDPH+DZKrGr2Y91JreZe1L0WCBF84OBoPFdbXADyr7TIuadpYA6o+UW/ZlVj62 8jy/Oc2/1KlFLfFi5KVo2vmCCWyDqKAZeM8K+dovobpKRKKHfE/6damLOFVUFaKmFwAo f7DVC9w5Z0/4o8gIBdIbK7aylLEfAvbeDiOAjMz8Qdm8dkp+QqOi9YV+MRQzYbGehUGC BXpvBs+yPOp/DgphfhjYkqGVbPdE2sDAyRiN8SSjUHLzPCa1UT/IB7rIqzNTlXdMf+wt YRC+3XrZYyj463OIcRg7McHviVq78LK9n43Km4pqrd0qYj/DXXi663cIKpC88hhWyJv3 M74Q== X-Gm-Message-State: AKS2vOyxouAcWPY/MHuobSlurJUXzNYQdsQicENBK7nPGdYDWAW4W+HE XeK87Azwnl35ZA== X-Received: by 10.84.217.137 with SMTP id p9mr17047761pli.80.1498728203770; Thu, 29 Jun 2017 02:23:23 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:40 +0530 Message-Id: <1498728221-23979-8-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c00::244 Subject: [Qemu-devel] [PATCH v7 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_6 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 277db16..60b8adc 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 { @@ -1116,34 +1118,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 * @@ -1260,9 +1315,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 *total_alloc_clusters) { int l1_index, l2_offset, l2_index; @@ -1271,6 +1327,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, @@ -1331,13 +1388,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; @@ -1366,7 +1431,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 *total_alloc_clusters) @@ -1386,8 +1451,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 */ @@ -1800,10 +1865,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 total_alloc_clusters =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, @@ -1812,6 +1879,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; @@ -1857,7 +1925,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, total_alloc_clusters; 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; } @@ -1871,11 +1939,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; } } @@ -1884,6 +1950,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) { @@ -1894,6 +1967,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_= t offset, s->cid_updated =3D true; } } + g_free(m_data); return 0; } =20 --=20 2.6.2 From nobody Sun Apr 28 15:22:24 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.zoho.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 1498728631722360.409747676655; Thu, 29 Jun 2017 02:30:31 -0700 (PDT) Received: from localhost ([::1]:37966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVmO-0002nj-SR for importer@patchew.org; Thu, 29 Jun 2017 05:30:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVff-00052t-Ip for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfe-00077m-GE for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:31 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35129) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfe-00077G-86; Thu, 29 Jun 2017 05:23:30 -0400 Received: by mail-pg0-x244.google.com with SMTP id f127so11229159pgc.2; Thu, 29 Jun 2017 02:23:30 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:28 -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=lrFjJhUO6c1M80+5jJLltXKK/AiSZfH9KtRxLROeXJ0=; b=IfGRtDhi9/Ga2QVPKX11etDyndeHSNUkEuaZA0BJqVfoDAdAb0AjDRIRkPNniOJHv9 jKaKpfWD7witsrldZiJb05vLkCXlui90Fw6D6aR/Y64lX5wlSNSYcZgW7FJZnRIYeH8a TWaeXgntlR4N4QIBRgEk/Fxs30L623h1ye59tcTzMS9qSHSPibTnFlldV8uGMwRK8ALK J3PG2vyvQt+9PjDSkuxxOaFBd/MJdM4bvpNJ7q+DyA8A0e8sy12HuvbcSOuDCO/ERLsO EtE2l9exUbx1PRJCzZZ+BV+zkZdP/SU2LSWp50acPd9qTSYFqExEKLyGli3qU1jdwEvs uT2A== 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=lrFjJhUO6c1M80+5jJLltXKK/AiSZfH9KtRxLROeXJ0=; b=W6fNb4c/Viy/Qsdx5EquskES12UoHM8lt8/t0fD/lx5pp3Cq2ZJNZs+XmMXBxahZr2 +M36BybpAPHH4XcXJdkD9rgfM1RrfcAfic/OpAwyLw9oa0/QprJXb4/WUWkJkz9CRM3G yl09qRvbYWawzj4uVkL9DJqC01j7TIZUbEOBGk6lRqBYG4bog0qZYsRMw0hH9elvl4pC 2gSkeIdUKn8FjAgy8g+7Vc8f0qiTh7yttEa6MjlziqKvijWJyC+PnRVCMnQ+nvdV4h1N TVhYCkyT1D1AjcUI2JmXDmZyAYDoOUXeY/TOodqw3+CqpsiejjGlTEYX169uVusS/9VR 9+vg== X-Gm-Message-State: AKS2vOxfHvZ8tI6lMlPvEol00Yw2pY4Q3/eClmMm8ZEhyDApee1k2fOx qPODwRarjDJxi7gQmWU= X-Received: by 10.84.225.18 with SMTP id t18mr16983148plj.273.1498728209286; Thu, 29 Jun 2017 02:23:29 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:41 +0530 Message-Id: <1498728221-23979-9-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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 v7 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 60b8adc..d41fde9 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1493,25 +1493,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; @@ -1536,31 +1527,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; } @@ -1603,9 +1572,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); @@ -1796,13 +1763,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) { @@ -2549,9 +2517,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheck= Result *result, sector_num); 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.6.2