From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014958; cv=none; d=zohomail.com; s=zohoarc; b=CyOFLPPDQPFyJHc8hDAX99VV/9d/emvnNZgDeDLC+EM/QeSfrNu0u+r1RwbTT9Q5kBEfMFyfM6GGNi6sut9o9LEYO+Ww78F4iSI/U6AgYF8VpSNTsIl+0XTeFbEh1Oxfw0/aHi2P3sJoDQXqdFlJ1o+kBxsX+E3Vbzlbq6sBWDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014958; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mgKJgIU5zdpoNf8COv2Q/Z566sYNJX9g2NTWfKTqyjc=; b=ec69oqslYe3BpKp/+yb8WJtLiWEjf9ZKjhKNqzYiCp65HfxFI36903K6ATmu/yVBEA5XO3ZfqxjEeFa3swFZZMbks6nOs8Iz0pdSoj+q6mpcGYqOqHK+GjOEQSDa7F9On+I7OQapMuey1+HeP7xBSTGQXs9C/M22SNr/dLn1G9k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014958920485.58236711728205; Sun, 22 Dec 2019 03:42:38 -0800 (PST) Received: from localhost ([::1]:46668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizd7-0008Dk-Gv for importer@patchew.org; Sun, 22 Dec 2019 06:42:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41509) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nx-Ea for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005bD-Py for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34953) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Om-0f; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d4-DM; Sun, 22 Dec 2019 12:37:50 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001VU-83; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=mgKJgIU5zdpoNf8COv2Q/Z566sYNJX9g2NTWfKTqyjc=; b=kzfYZ1f2bQxMpPZ5FxAoj0XKe0fIsVzDcLLdw1vktTQmQJ0cPPUWsszp+z+y/biLizWLTyUY8uYx8k7ocq761KIFa9oQKIEkyYz8whsvrviQT10i09eROoPytqTYC3Glr7AjIkz6gZu16ak6pGBfKb5PQh3yQG2GX/PD5yTclxbHBAAcJFP+YOjehK65pol0utvuMryK16IreTNSOdsuNkwAcOjvHYIdyTVymQLAfuXZn2qyScl+7kwAyhRwjtpuoT969fTWVqNUIPNR9VE6EL7CF5oghwZdUdJ7oSbgSyDckoQuKfWf/rTY/ljrex3pidSMt4sGIwFA6PpHpdIDvw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 01/27] qcow2: Add calculate_l2_meta() Date: Sun, 22 Dec 2019 12:36:42 +0100 Message-Id: <2d53eae8fe9b9ab262daee45b662f631c3ba3899.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" handle_alloc() creates a QCowL2Meta structure in order to update the image metadata and perform the necessary copy-on-write operations. This patch moves that code to a separate function so it can be used from other places. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 77 +++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8982b7b762..617618dc54 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1019,6 +1019,56 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs,= QCowL2Meta *m) QCOW2_DISCARD_NEVER); } =20 +/* + * For a given write request, create a new QCowL2Meta structure, add + * it to @m and the BDRVQcow2State.cluster_allocs list. + * + * @host_cluster_offset points to the beginning of the first cluster. + * + * @guest_offset and @bytes indicate the offset and length of the + * request. + * + * If @keep_old is true it means that the clusters were already + * allocated and will be overwritten. If false then the clusters are + * new and we have to decrease the reference count of the old ones. + */ +static void calculate_l2_meta(BlockDriverState *bs, + uint64_t host_cluster_offset, + uint64_t guest_offset, unsigned bytes, + QCowL2Meta **m, bool keep_old) +{ + BDRVQcow2State *s =3D bs->opaque; + unsigned cow_start_from =3D 0; + unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); + unsigned cow_end_from =3D cow_start_to + bytes; + unsigned cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); + QCowL2Meta *old_m =3D *m; + + *m =3D g_malloc0(sizeof(**m)); + **m =3D (QCowL2Meta) { + .next =3D old_m, + + .alloc_offset =3D host_cluster_offset, + .offset =3D start_of_cluster(s, guest_offset), + .nb_clusters =3D nb_clusters, + + .keep_old_clusters =3D keep_old, + + .cow_start =3D { + .offset =3D cow_start_from, + .nb_bytes =3D cow_start_to - cow_start_from, + }, + .cow_end =3D { + .offset =3D cow_end_from, + .nb_bytes =3D cow_end_to - cow_end_from, + }, + }; + + qemu_co_queue_init(&(*m)->dependent_requests); + QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); +} + /* * Returns the number of contiguous clusters that can be used for an alloc= ating * write, but require COW to be performed (this includes yet unallocated s= pace, @@ -1417,35 +1467,14 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, uint64_t requested_bytes =3D *bytes + offset_into_cluster(s, guest_off= set); int avail_bytes =3D nb_clusters << s->cluster_bits; int nb_bytes =3D MIN(requested_bytes, avail_bytes); - QCowL2Meta *old_m =3D *m; - - *m =3D g_malloc0(sizeof(**m)); - - **m =3D (QCowL2Meta) { - .next =3D old_m, - - .alloc_offset =3D alloc_cluster_offset, - .offset =3D start_of_cluster(s, guest_offset), - .nb_clusters =3D nb_clusters, - - .keep_old_clusters =3D keep_old_clusters, - - .cow_start =3D { - .offset =3D 0, - .nb_bytes =3D offset_into_cluster(s, guest_offset), - }, - .cow_end =3D { - .offset =3D nb_bytes, - .nb_bytes =3D avail_bytes - nb_bytes, - }, - }; - qemu_co_queue_init(&(*m)->dependent_requests); - QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); =20 *host_offset =3D alloc_cluster_offset + offset_into_cluster(s, guest_o= ffset); *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 + calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, + m, keep_old_clusters); + return 1; =20 fail: --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016061; cv=none; d=zohomail.com; s=zohoarc; b=iRnoFGmfQcoDgNdYZga8vGN2tazmu5TJnZVTRF2yayljCxxfcyM3PbkvSkwaEpAZJ15nA3P4Sg2pi0NtxRV/XEL2FTRn3vRCMM2KkRhaeD3IfRWui7SkGUNlmZtUKypQnAtZSob1+aJBVuzpZJ0PLIxcxj2RfzHe8UxVmNmn7g0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016061; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G5UHWiqSgBi5RZLPT5B93DOloDP71FGfaNpqmuSGnG0=; b=jnHisS85GbyNy6MtDWBD2Wiy4Kgyp/fbSXA18ia+qjJ/gQ/spcR8uow7WcSvWVdV+9ryz5T00VaTBdTV1gnP2suVh6gaxGJvBVVAVE3kh6xpP8RC+xW2PmdI3IJhd+2B2FDCi5qPoV9fU+IJPjJZXOC2XT/u6/USneVLbuwOyLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577016061914711.5151115611039; Sun, 22 Dec 2019 04:01:01 -0800 (PST) Received: from localhost ([::1]:47052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizuu-0001hp-IZ for importer@patchew.org; Sun, 22 Dec 2019 07:01:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43809) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ9-0003NG-Th for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ8-0006q8-BP for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:31 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34946) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Oo-TB; Sun, 22 Dec 2019 06:38:30 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d3-Co; Sun, 22 Dec 2019 12:37:50 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001VW-93; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=G5UHWiqSgBi5RZLPT5B93DOloDP71FGfaNpqmuSGnG0=; b=H42spux6danfMP+XOXoVaoaqRZ6pRSPVMBoK4906zLYGXJI3IGg9VYtRNiFyT6T2ellNEpj1Ya7hLfydZBXz+tCDAtsBqSnya/gOIRMKMhN9sOiZgZz3aq87vTHreFhzR+D2GnMQuJPT2/us2FPzX/CiyahHJYv1DPBSZnZZRqTKKjQ3JIuBZeVgWErqSjG8VOvusmnUkD7cwNNSr2USZSbaVrXxmw4qm8gtgx2qUvsWrflPRS4M5l4vei89fLZry3vDfeYK6J1Mf4+yHHUYGDBF3zOO8EyHxv/COnZ7roL0ULwz5z35RjbV/kkLdOL0s1XlS5ZWpOqT9URvp/sNng==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 02/27] qcow2: Split cluster_needs_cow() out of count_cow_clusters() Date: Sun, 22 Dec 2019 12:36:43 +0100 Message-Id: <7c18e5c5faed0fd0a630bcaeeac7b175fe4918a7.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We are going to need it in other places. Signed-off-by: Alberto Garcia Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 617618dc54..e078bddcc2 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1069,6 +1069,24 @@ static void calculate_l2_meta(BlockDriverState *bs, QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); } =20 +/* Returns true if writing to a cluster requires COW */ +static bool cluster_needs_cow(BlockDriverState *bs, uint64_t l2_entry) +{ + switch (qcow2_get_cluster_type(bs, l2_entry)) { + case QCOW2_CLUSTER_NORMAL: + if (l2_entry & QCOW_OFLAG_COPIED) { + return false; + } + case QCOW2_CLUSTER_UNALLOCATED: + case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_ZERO_ALLOC: + return true; + default: + abort(); + } +} + /* * Returns the number of contiguous clusters that can be used for an alloc= ating * write, but require COW to be performed (this includes yet unallocated s= pace, @@ -1081,25 +1099,11 @@ static int count_cow_clusters(BlockDriverState *bs,= int nb_clusters, =20 for (i =3D 0; i < nb_clusters; i++) { uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); - QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l2_en= try); - - switch(cluster_type) { - case QCOW2_CLUSTER_NORMAL: - if (l2_entry & QCOW_OFLAG_COPIED) { - goto out; - } + if (!cluster_needs_cow(bs, l2_entry)) { break; - case QCOW2_CLUSTER_UNALLOCATED: - case QCOW2_CLUSTER_COMPRESSED: - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: - break; - default: - abort(); } } =20 -out: assert(i <=3D nb_clusters); return i; } --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014827; cv=none; d=zohomail.com; s=zohoarc; b=GJ8HfzbWCnbXYatJe6AnDS0Kna5H9ymqbbHxjMS3+hb6gIB6wu5+ncEm+cOZ1WGnuPbpCSdw/1hwlK3PDRIQ9IDCPTPcbSzI08+3c9R2N6xHx4ST8mSOxkpuUARt82E8UMRMZZH9DGy82W469hpERtoOhJdgMuGP1XqmufPGC+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014827; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vI/6WKUx24nI08Xe5mGI0CFOmQYhsxMite6QbkZCRK4=; b=HQbM3qsnIMqXHwccbKbu7yU3K9jgdDNHwk2Pqoll6PEwmfZgDWZoAHBe96dEhioZYJxGmDkNuRX8geilW08ih3VnRFZRicwyV+m9TyoUb72D3fNRbvzOBzyiq4T1gCent9gGIKI+lgUKLJfszMbj5HqVqiBM1/2i7xD/zj7kKsE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014827895948.6791909486556; Sun, 22 Dec 2019 03:40:27 -0800 (PST) Received: from localhost ([::1]:46606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizb0-0005NL-Nk for importer@patchew.org; Sun, 22 Dec 2019 06:40:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41653) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYq-0002oC-K6 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005bC-Qw for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Or-0h; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d5-Ek; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001VY-A3; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vI/6WKUx24nI08Xe5mGI0CFOmQYhsxMite6QbkZCRK4=; b=EnVwwCCbaMMnUzpiwFMkh88wwP8F6ydgwUIQxnw1V/kf/BkjG67PE9EM6c5FkhdZTxv5c8wrRNaKhEE7m63xlkDO6lkxg9RpRkOoowUbk2fyjF7ua1poN2ZIYyTitET4RfZFyMQ+4MEsghrWvkG1jJQpC0T3yFQxyfNaqOvrNem9J9Mmk82DVod8gVlMQI0bCUGweImuIH1tbLXLHkFxD6219lZ7rkKc8p1NqblOKMMUCkUMWaYCCIe6hxP9Zx70kZavLQi1IQvXHVq3LnpwgHuCBMgVWKyBWsz5n8ntaE3m2r4WfN/vipGH2048mgp6oUMR9VT+3gzwp/ACXYBiEQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 03/27] qcow2: Process QCOW2_CLUSTER_ZERO_ALLOC clusters in handle_copied() Date: Sun, 22 Dec 2019 12:36:44 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When writing to a qcow2 file there are two functions that take a virtual offset and return a host offset, possibly allocating new clusters if necessary: - handle_copied() looks for normal data clusters that are already allocated and have a reference count of 1. In those clusters we can simply write the data and there is no need to perform any copy-on-write. - handle_alloc() looks for clusters that do need copy-on-write, either because they haven't been allocated yet, because their reference count is !=3D 1 or because they are ZERO_ALLOC clusters. The ZERO_ALLOC case is a bit special because those are clusters that are already allocated and they could perfectly be dealt with in handle_copied() (as long as copy-on-write is performed when required). In fact, there is extra code specifically for them in handle_alloc() that tries to reuse the existing allocation if possible and frees them otherwise. This patch changes the handling of ZERO_ALLOC clusters so the semantics of these two functions are now like this: - handle_copied() looks for clusters that are already allocated and which we can overwrite (NORMAL and ZERO_ALLOC clusters with a reference count of 1). - handle_alloc() looks for clusters for which we need a new allocation (all other cases). One importante difference after this change is that clusters found in handle_copied() may now require copy-on-write, but this will be anyway necessary once we add support for subclusters. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 226 +++++++++++++++++++++++------------------- 1 file changed, 126 insertions(+), 100 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e078bddcc2..9387f15866 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1021,13 +1021,18 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs= , QCowL2Meta *m) =20 /* * For a given write request, create a new QCowL2Meta structure, add - * it to @m and the BDRVQcow2State.cluster_allocs list. + * it to @m and the BDRVQcow2State.cluster_allocs list. If the write + * request does not need copy-on-write or changes to the L2 metadata + * then this function does nothing. * * @host_cluster_offset points to the beginning of the first cluster. * * @guest_offset and @bytes indicate the offset and length of the * request. * + * @l2_slice contains the L2 entries of all clusters involved in this + * write request. + * * If @keep_old is true it means that the clusters were already * allocated and will be overwritten. If false then the clusters are * new and we have to decrease the reference count of the old ones. @@ -1035,15 +1040,53 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs= , QCowL2Meta *m) static void calculate_l2_meta(BlockDriverState *bs, uint64_t host_cluster_offset, uint64_t guest_offset, unsigned bytes, - QCowL2Meta **m, bool keep_old) + uint64_t *l2_slice, QCowL2Meta **m, bool kee= p_old) { BDRVQcow2State *s =3D bs->opaque; - unsigned cow_start_from =3D 0; + int l2_index =3D offset_to_l2_slice_index(s, guest_offset); + uint64_t l2_entry; + unsigned cow_start_from, cow_end_to; unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); unsigned cow_end_from =3D cow_start_to + bytes; - unsigned cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); QCowL2Meta *old_m =3D *m; + QCow2ClusterType type; + + assert(nb_clusters <=3D s->l2_slice_size - l2_index); + + /* Return if there's no COW (all clusters are normal and we keep them)= */ + if (keep_old) { + int i; + for (i =3D 0; i < nb_clusters; i++) { + l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { + break; + } + } + if (i =3D=3D nb_clusters) { + return; + } + } + + /* Get the L2 entry from the first cluster */ + l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + type =3D qcow2_get_cluster_type(bs, l2_entry); + + if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { + cow_start_from =3D cow_start_to; + } else { + cow_start_from =3D 0; + } + + /* Get the L2 entry from the last cluster */ + l2_entry =3D be64_to_cpu(l2_slice[l2_index + nb_clusters - 1]); + type =3D qcow2_get_cluster_type(bs, l2_entry); + + if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { + cow_end_to =3D cow_end_from; + } else { + cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + } =20 *m =3D g_malloc0(sizeof(**m)); **m =3D (QCowL2Meta) { @@ -1069,18 +1112,20 @@ static void calculate_l2_meta(BlockDriverState *bs, QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); } =20 -/* Returns true if writing to a cluster requires COW */ -static bool cluster_needs_cow(BlockDriverState *bs, uint64_t l2_entry) +/* Returns true if writing to the cluster pointed to by @l2_entry + * requires a new allocation (that is, if the cluster is unallocated + * or has refcount > 1 and therefore cannot be written in-place). */ +static bool cluster_needs_new_alloc(BlockDriverState *bs, uint64_t l2_entr= y) { switch (qcow2_get_cluster_type(bs, l2_entry)) { case QCOW2_CLUSTER_NORMAL: + case QCOW2_CLUSTER_ZERO_ALLOC: if (l2_entry & QCOW_OFLAG_COPIED) { return false; } case QCOW2_CLUSTER_UNALLOCATED: case QCOW2_CLUSTER_COMPRESSED: case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: return true; default: abort(); @@ -1088,20 +1133,36 @@ static bool cluster_needs_cow(BlockDriverState *bs,= uint64_t l2_entry) } =20 /* - * Returns the number of contiguous clusters that can be used for an alloc= ating - * write, but require COW to be performed (this includes yet unallocated s= pace, - * which must copy from the backing file) + * Returns the number of contiguous clusters that can be written to + * using one single write request, starting from @l2_index. + * At most @nb_clusters are checked. + * + * If @new_alloc is true this counts clusters that are either + * unallocated, or allocated but with refcount > 1 (so they need to be + * newly allocated and COWed). + * + * If @new_alloc is false this counts clusters that are already + * allocated and can be overwritten in-place (this includes clusters + * of type QCOW2_CLUSTER_ZERO_ALLOC). */ -static int count_cow_clusters(BlockDriverState *bs, int nb_clusters, - uint64_t *l2_slice, int l2_index) +static int count_single_write_clusters(BlockDriverState *bs, int nb_cluste= rs, + uint64_t *l2_slice, int l2_index, + bool new_alloc) { + BDRVQcow2State *s =3D bs->opaque; + uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; int i; =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); - if (!cluster_needs_cow(bs, l2_entry)) { + l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + if (cluster_needs_new_alloc(bs, l2_entry) !=3D new_alloc) { break; } + if (!new_alloc && expected_offset !=3D (l2_entry & L2E_OFFSET_MASK= )) { + break; + } + expected_offset +=3D s->cluster_size; } =20 assert(i <=3D nb_clusters); @@ -1172,10 +1233,10 @@ static int handle_dependencies(BlockDriverState *bs= , uint64_t guest_offset, } =20 /* - * Checks how many already allocated clusters that don't require a copy on - * write there are at the given guest_offset (up to *bytes). If *host_offs= et is - * not INV_OFFSET, only physically contiguous clusters beginning at this h= ost - * offset are counted. + * Checks how many already allocated clusters that don't require a new + * allocation there are at the given guest_offset (up to *bytes). + * If *host_offset is not INV_OFFSET, only physically contiguous clusters + * beginning at this host offset are counted. * * Note that guest_offset may not be cluster aligned. In this case, the * returned *host_offset points to exact byte referenced by guest_offset a= nd @@ -1184,12 +1245,12 @@ static int handle_dependencies(BlockDriverState *bs= , uint64_t guest_offset, * Returns: * 0: if no allocated clusters are available at the given offset. * *bytes is normally unchanged. It is set to 0 if the cluster - * is allocated and doesn't need COW, but doesn't have the right - * physical offset. + * is allocated and can be overwritten in-place but doesn't have + * the right physical offset. * - * 1: if allocated clusters that don't require a COW are available at - * the requested offset. *bytes may have decreased and describes - * the length of the area that can be written to. + * 1: if allocated clusters that can be overwritten in place are + * available at the requested offset. *bytes may have decreased + * and describes the length of the area that can be written to. * * -errno: in error cases */ @@ -1219,7 +1280,8 @@ static int handle_copied(BlockDriverState *bs, uint64= _t guest_offset, =20 l2_index =3D offset_to_l2_slice_index(s, guest_offset); nb_clusters =3D MIN(nb_clusters, s->l2_slice_size - l2_index); - assert(nb_clusters <=3D INT_MAX); + /* Limit total byte count to BDRV_REQUEST_MAX_BYTES */ + nb_clusters =3D MIN(nb_clusters, BDRV_REQUEST_MAX_BYTES >> s->cluster_= bits); =20 /* Find L2 entry for the first involved cluster */ ret =3D get_cluster_table(bs, guest_offset, &l2_slice, &l2_index); @@ -1229,18 +1291,17 @@ static int handle_copied(BlockDriverState *bs, uint= 64_t guest_offset, =20 cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); =20 - /* Check how many clusters are already allocated and don't need COW */ - if (qcow2_get_cluster_type(bs, cluster_offset) =3D=3D QCOW2_CLUSTER_NO= RMAL - && (cluster_offset & QCOW_OFLAG_COPIED)) - { + if (!cluster_needs_new_alloc(bs, cluster_offset)) { /* If a specific host_offset is required, check it */ bool offset_matches =3D (cluster_offset & L2E_OFFSET_MASK) =3D=3D *host_offset; =20 if (offset_into_cluster(s, cluster_offset & L2E_OFFSET_MASK)) { - qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset= " + qcow2_signal_corruption(bs, true, -1, -1, "%s cluster offset " "%#llx unaligned (guest offset: %#" PR= Ix64 - ")", cluster_offset & L2E_OFFSET_MASK, + ")", cluster_offset & QCOW_OFLAG_ZERO ? + "Preallocated zero" : "Data", + cluster_offset & L2E_OFFSET_MASK, guest_offset); ret =3D -EIO; goto out; @@ -1253,15 +1314,17 @@ static int handle_copied(BlockDriverState *bs, uint= 64_t guest_offset, } =20 /* We keep all QCOW_OFLAG_COPIED clusters */ - keep_clusters =3D - count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], - QCOW_OFLAG_COPIED | QCOW_OFLAG_ZERO); + keep_clusters =3D count_single_write_clusters(bs, nb_clusters, l2_= slice, + l2_index, false); assert(keep_clusters <=3D nb_clusters); =20 *bytes =3D MIN(*bytes, keep_clusters * s->cluster_size - offset_into_cluster(s, guest_offset)); + assert(*bytes !=3D 0); + + calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, guest_offs= et, + *bytes, l2_slice, m, true); =20 ret =3D 1; } else { @@ -1337,9 +1400,10 @@ static int do_alloc_cluster_offset(BlockDriverState = *bs, uint64_t guest_offset, } =20 /* - * Allocates new clusters for an area that either is yet unallocated or ne= eds a - * copy on write. If *host_offset is not INV_OFFSET, clusters are only - * allocated if the new allocation can match the specified host offset. + * Allocates new clusters for an area that either is yet unallocated or + * cannot be overwritten in-place. If *host_offset is not INV_OFFSET, + * clusters are only allocated if the new allocation can match the specifi= ed + * host offset. * * Note that guest_offset may not be cluster aligned. In this case, the * returned *host_offset points to exact byte referenced by guest_offset a= nd @@ -1362,12 +1426,10 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, BDRVQcow2State *s =3D bs->opaque; int l2_index; uint64_t *l2_slice; - uint64_t entry; uint64_t nb_clusters; int ret; - bool keep_old_clusters =3D false; =20 - uint64_t alloc_cluster_offset =3D INV_OFFSET; + uint64_t alloc_cluster_offset; =20 trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_of= fset, *bytes); @@ -1382,10 +1444,8 @@ static int handle_alloc(BlockDriverState *bs, uint64= _t guest_offset, =20 l2_index =3D offset_to_l2_slice_index(s, guest_offset); nb_clusters =3D MIN(nb_clusters, s->l2_slice_size - l2_index); - assert(nb_clusters <=3D INT_MAX); - - /* Limit total allocation byte count to INT_MAX */ - nb_clusters =3D MIN(nb_clusters, INT_MAX >> s->cluster_bits); + /* Limit total allocation byte count to BDRV_REQUEST_MAX_BYTES */ + nb_clusters =3D MIN(nb_clusters, BDRV_REQUEST_MAX_BYTES >> s->cluster_= bits); =20 /* Find L2 entry for the first involved cluster */ ret =3D get_cluster_table(bs, guest_offset, &l2_slice, &l2_index); @@ -1393,67 +1453,32 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, return ret; } =20 - entry =3D be64_to_cpu(l2_slice[l2_index]); - nb_clusters =3D count_cow_clusters(bs, nb_clusters, l2_slice, l2_index= ); + nb_clusters =3D count_single_write_clusters(bs, nb_clusters, + l2_slice, l2_index, true); =20 /* This function is only called when there were no non-COW clusters, s= o if * we can't find any unallocated or COW clusters either, something is * wrong with our code. */ assert(nb_clusters > 0); =20 - if (qcow2_get_cluster_type(bs, entry) =3D=3D QCOW2_CLUSTER_ZERO_ALLOC = && - (entry & QCOW_OFLAG_COPIED) && - (*host_offset =3D=3D INV_OFFSET || - start_of_cluster(s, *host_offset) =3D=3D (entry & L2E_OFFSET_MASK= ))) - { - int preallocated_nb_clusters; - - if (offset_into_cluster(s, entry & L2E_OFFSET_MASK)) { - qcow2_signal_corruption(bs, true, -1, -1, "Preallocated zero " - "cluster offset %#llx unaligned (guest= " - "offset: %#" PRIx64 ")", - entry & L2E_OFFSET_MASK, guest_offset); - ret =3D -EIO; - goto fail; - } - - /* Try to reuse preallocated zero clusters; contiguous normal clus= ters - * would be fine, too, but count_cow_clusters() above has limited - * nb_clusters already to a range of COW clusters */ - preallocated_nb_clusters =3D - count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], QCOW_OFLAG_COPI= ED); - assert(preallocated_nb_clusters > 0); - - nb_clusters =3D preallocated_nb_clusters; - alloc_cluster_offset =3D entry & L2E_OFFSET_MASK; - - /* We want to reuse these clusters, so qcow2_alloc_cluster_link_l2= () - * should not free them. */ - keep_old_clusters =3D true; + /* Allocate at a given offset in the image file */ + alloc_cluster_offset =3D *host_offset =3D=3D INV_OFFSET ? INV_OFFSET : + start_of_cluster(s, *host_offset); + ret =3D do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offse= t, + &nb_clusters); + if (ret < 0) { + goto out; } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); - - if (alloc_cluster_offset =3D=3D INV_OFFSET) { - /* Allocate, if necessary at a given offset in the image file */ - alloc_cluster_offset =3D *host_offset =3D=3D INV_OFFSET ? INV_OFFS= ET : - start_of_cluster(s, *host_offset); - ret =3D do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_o= ffset, - &nb_clusters); - if (ret < 0) { - goto fail; - } - - /* Can't extend contiguous allocation */ - if (nb_clusters =3D=3D 0) { - *bytes =3D 0; - return 0; - } - - assert(alloc_cluster_offset !=3D INV_OFFSET); + /* Can't extend contiguous allocation */ + if (nb_clusters =3D=3D 0) { + *bytes =3D 0; + ret =3D 0; + goto out; } =20 + assert(alloc_cluster_offset !=3D INV_OFFSET); + /* * Save info needed for meta data update. * @@ -1476,13 +1501,14 @@ static int handle_alloc(BlockDriverState *bs, uint6= 4_t guest_offset, *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, - m, keep_old_clusters); + calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, l2_s= lice, + m, false); =20 - return 1; + ret =3D 1; =20 -fail: - if (*m && (*m)->nb_clusters > 0) { +out: + qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); + if (ret < 0 && *m && (*m)->nb_clusters > 0) { QLIST_REMOVE(*m, next_in_flight); } return ret; --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015668; cv=none; d=zohomail.com; s=zohoarc; b=HCPtovYox1aVktCVDCXaIpvZ0sYYy0HhFh071ilDLC6JLGEghP9/11jutm25HDlyc5TbxW+uZr2eDIILsNavUxyXQDJ59wijgvJ0xia82h7hVYw6F+94K5HuacHnA5BJw2VSBqGvKMz4v57RvepxTlCufh+ohs8OuDNtaLHvj+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015668; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QRXi6MJ1Q6YuXaj80jS4cUlvS90lVmbKyazl1lEuJc0=; b=MJtckCjXhw+a/qa5wgZ3bElKnmaFx4ZRjF3i6/EWz/I70gD65n+IvFyyP9S5yLVjoxS67ZjEqTAmHLQjE/qZ7ORi5u0FvstMxcTwvoWIeTVQL3Z0NUkLcevdn5PquLtSCpEWp8J1oZuIj38ortXslGHphljdauhbqQvfL3sv9nE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015668141751.4247979458444; Sun, 22 Dec 2019 03:54:28 -0800 (PST) Received: from localhost ([::1]:46904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizoY-0002rN-T1 for importer@patchew.org; Sun, 22 Dec 2019 06:54:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44469) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZF-0003YM-Vo for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00077I-VJ for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:37 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35055) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004oi-JR; Sun, 22 Dec 2019 06:38:34 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d6-GM; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Va-Aw; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=QRXi6MJ1Q6YuXaj80jS4cUlvS90lVmbKyazl1lEuJc0=; b=gzdAXrK5+bPE+pMGoesXXgaOFyTcxlskCXQ9yD/y757VC7sevp/moZXw2wgHcSLw7731brfPMawqUzS3unNEFRPIq4Tiqjo2gEQZ5olLF2VYTrDv7Q7P29jMqjzkH/ygpmqBaNG5il0qfzJ5+TQxnCdrG4EGixtuns2N6ElDZxx0GOSeHTo7EYOCW6tBKkSxqWpHGGsEC6C8wEbpb2kfsLpDRB25HV2XhYx3tmA0sNSSsZWob2d0sMh5dV15kKgWKHkpQ0+iLVgvZ/44/TQ23PjHiRhJbDrtoV084Eps941HPFm6Vs7q7+lNXu36UIQe74T+dXKQF3g7+jz4bukv9g==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 04/27] qcow2: Add get_l2_entry() and set_l2_entry() Date: Sun, 22 Dec 2019 12:36:45 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The size of an L2 entry is 64 bits, but if we want to have subclusters we need extended L2 entries. This means that we have to access L2 tables and slices differently depending on whether an image has extended L2 entries or not. This patch replaces all l2_slice[] accesses with calls to get_l2_entry() and set_l2_entry(). Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 65 ++++++++++++++++++++++-------------------- block/qcow2-refcount.c | 17 +++++------ block/qcow2.h | 12 ++++++++ 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 9387f15866..683c9569ad 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -379,12 +379,13 @@ fail: * cluster which may require a different handling) */ static int count_contiguous_clusters(BlockDriverState *bs, int nb_clusters, - int cluster_size, uint64_t *l2_slice, uint64_t stop_flags) + int cluster_size, uint64_t *l2_slice, int l2_index, uint64_t stop_= flags) { + BDRVQcow2State *s =3D bs->opaque; int i; QCow2ClusterType first_cluster_type; uint64_t mask =3D stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; - uint64_t first_entry =3D be64_to_cpu(l2_slice[0]); + uint64_t first_entry =3D get_l2_entry(s, l2_slice, l2_index); uint64_t offset =3D first_entry & mask; =20 first_cluster_type =3D qcow2_get_cluster_type(bs, first_entry); @@ -397,7 +398,7 @@ static int count_contiguous_clusters(BlockDriverState *= bs, int nb_clusters, first_cluster_type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC); =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[i]) & mask; + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i) & ma= sk; if (offset + (uint64_t) i * cluster_size !=3D l2_entry) { break; } @@ -413,14 +414,16 @@ static int count_contiguous_clusters(BlockDriverState= *bs, int nb_clusters, static int count_contiguous_clusters_unallocated(BlockDriverState *bs, int nb_clusters, uint64_t *l2_slice, + int l2_index, QCow2ClusterType wanted_t= ype) { + BDRVQcow2State *s =3D bs->opaque; int i; =20 assert(wanted_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || wanted_type =3D=3D QCOW2_CLUSTER_UNALLOCATED); for (i =3D 0; i < nb_clusters; i++) { - uint64_t entry =3D be64_to_cpu(l2_slice[i]); + uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); QCow2ClusterType type =3D qcow2_get_cluster_type(bs, entry); =20 if (type !=3D wanted_type) { @@ -566,7 +569,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, /* find the cluster offset for the given disk offset */ =20 l2_index =3D offset_to_l2_slice_index(s, offset); - *cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + *cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -601,14 +604,14 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, case QCOW2_CLUSTER_UNALLOCATED: /* how many empty clusters ? */ c =3D count_contiguous_clusters_unallocated(bs, nb_clusters, - &l2_slice[l2_index], typ= e); + l2_slice, l2_index, type= ); *cluster_offset =3D 0; break; case QCOW2_CLUSTER_ZERO_ALLOC: case QCOW2_CLUSTER_NORMAL: /* how many allocated clusters ? */ c =3D count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - &l2_slice[l2_index], QCOW_OFLAG_ZERO= ); + l2_slice, l2_index, QCOW_OFLAG_ZERO); *cluster_offset &=3D L2E_OFFSET_MASK; if (offset_into_cluster(s, *cluster_offset)) { qcow2_signal_corruption(bs, true, -1, -1, @@ -761,7 +764,7 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, =20 /* Compression can't overwrite anything. Fail if the cluster was alrea= dy * allocated. */ - cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); if (cluster_offset & L2E_OFFSET_MASK) { qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); return -EIO; @@ -786,7 +789,7 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, =20 BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); - l2_slice[l2_index] =3D cpu_to_be64(cluster_offset); + set_l2_entry(s, l2_slice, l2_index, cluster_offset); qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 *host_offset =3D cluster_offset & s->cluster_offset_mask; @@ -978,12 +981,12 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,= QCowL2Meta *m) * cluster the second one has to do RMW (which is done above by * perform_cow()), update l2 table with its cluster pointer and fr= ee * old cluster. This is what this loop does */ - if (l2_slice[l2_index + i] !=3D 0) { - old_cluster[j++] =3D l2_slice[l2_index + i]; + if (get_l2_entry(s, l2_slice, l2_index + i) !=3D 0) { + old_cluster[j++] =3D get_l2_entry(s, l2_slice, l2_index + i); } =20 - l2_slice[l2_index + i] =3D cpu_to_be64((cluster_offset + - (i << s->cluster_bits)) | QCOW_OFLAG_COPIED); + set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_COPIED | + (cluster_offset + (i << s->cluster_bits))); } =20 =20 @@ -997,8 +1000,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, = QCowL2Meta *m) */ if (!m->keep_old_clusters && j !=3D 0) { for (i =3D 0; i < j; i++) { - qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1, - QCOW2_DISCARD_NEVER); + qcow2_free_any_clusters(bs, old_cluster[i], 1, QCOW2_DISCARD_N= EVER); } } =20 @@ -1058,7 +1060,7 @@ static void calculate_l2_meta(BlockDriverState *bs, if (keep_old) { int i; for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { break; } @@ -1069,7 +1071,7 @@ static void calculate_l2_meta(BlockDriverState *bs, } =20 /* Get the L2 entry from the first cluster */ - l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index); type =3D qcow2_get_cluster_type(bs, l2_entry); =20 if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { @@ -1079,7 +1081,7 @@ static void calculate_l2_meta(BlockDriverState *bs, } =20 /* Get the L2 entry from the last cluster */ - l2_entry =3D be64_to_cpu(l2_slice[l2_index + nb_clusters - 1]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + nb_clusters - 1); type =3D qcow2_get_cluster_type(bs, l2_entry); =20 if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { @@ -1150,12 +1152,12 @@ static int count_single_write_clusters(BlockDriverS= tate *bs, int nb_clusters, bool new_alloc) { BDRVQcow2State *s =3D bs->opaque; - uint64_t l2_entry =3D be64_to_cpu(l2_slice[l2_index]); + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index); uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; int i; =20 for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); if (cluster_needs_new_alloc(bs, l2_entry) !=3D new_alloc) { break; } @@ -1289,7 +1291,7 @@ static int handle_copied(BlockDriverState *bs, uint64= _t guest_offset, return ret; } =20 - cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); + cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); =20 if (!cluster_needs_new_alloc(bs, cluster_offset)) { /* If a specific host_offset is required, check it */ @@ -1670,7 +1672,7 @@ static int discard_in_l2_slice(BlockDriverState *bs, = uint64_t offset, for (i =3D 0; i < nb_clusters; i++) { uint64_t old_l2_entry; =20 - old_l2_entry =3D be64_to_cpu(l2_slice[l2_index + i]); + old_l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); =20 /* * If full_discard is false, make sure that a discarded area reads= back @@ -1710,9 +1712,9 @@ static int discard_in_l2_slice(BlockDriverState *bs, = uint64_t offset, /* First remove L2 entries */ qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (!full_discard && s->qcow_version >=3D 3) { - l2_slice[l2_index + i] =3D cpu_to_be64(QCOW_OFLAG_ZERO); + set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); } else { - l2_slice[l2_index + i] =3D cpu_to_be64(0); + set_l2_entry(s, l2_slice, l2_index + i, 0); } =20 /* Then decrease the refcount */ @@ -1792,7 +1794,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uin= t64_t offset, uint64_t old_offset; QCow2ClusterType cluster_type; =20 - old_offset =3D be64_to_cpu(l2_slice[l2_index + i]); + old_offset =3D get_l2_entry(s, l2_slice, l2_index + i); =20 /* * Minimize L2 changes if the cluster already reads back as @@ -1806,10 +1808,11 @@ static int zero_in_l2_slice(BlockDriverState *bs, u= int64_t offset, =20 qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (cluster_type =3D=3D QCOW2_CLUSTER_COMPRESSED || unmap) { - l2_slice[l2_index + i] =3D cpu_to_be64(QCOW_OFLAG_ZERO); + set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUE= ST); } else { - l2_slice[l2_index + i] |=3D cpu_to_be64(QCOW_OFLAG_ZERO); + uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); + set_l2_entry(s, l2_slice, l2_index + i, entry | QCOW_OFLAG_ZER= O); } } =20 @@ -1947,7 +1950,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } =20 for (j =3D 0; j < s->l2_slice_size; j++) { - uint64_t l2_entry =3D be64_to_cpu(l2_slice[j]); + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, j); int64_t offset =3D l2_entry & L2E_OFFSET_MASK; QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l2_entry); @@ -1961,7 +1964,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, if (!bs->backing) { /* not backed; therefore we can simply deallocate = the * cluster */ - l2_slice[j] =3D 0; + set_l2_entry(s, l2_slice, j, 0); l2_dirty =3D true; continue; } @@ -2024,9 +2027,9 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } =20 if (l2_refcount =3D=3D 1) { - l2_slice[j] =3D cpu_to_be64(offset | QCOW_OFLAG_COPIED= ); + set_l2_entry(s, l2_slice, j, offset | QCOW_OFLAG_COPIE= D); } else { - l2_slice[j] =3D cpu_to_be64(offset); + set_l2_entry(s, l2_slice, j, offset); } l2_dirty =3D true; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f67ac6b2d8..223048569e 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1309,7 +1309,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, uint64_t cluster_index; uint64_t offset; =20 - entry =3D be64_to_cpu(l2_slice[j]); + entry =3D get_l2_entry(s, l2_slice, j); old_entry =3D entry; entry &=3D ~QCOW_OFLAG_COPIED; offset =3D entry & L2E_OFFSET_MASK; @@ -1383,7 +1383,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, qcow2_cache_set_dependency(bs, s->l2_table_cac= he, s->refcount_block_c= ache); } - l2_slice[j] =3D cpu_to_be64(entry); + set_l2_entry(s, l2_slice, j, entry); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); } @@ -1616,7 +1616,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, =20 /* Do the actual checks */ for(i =3D 0; i < s->l2_size; i++) { - l2_entry =3D be64_to_cpu(l2_table[i]); + l2_entry =3D get_l2_entry(s, l2_table, i); =20 switch (qcow2_get_cluster_type(bs, l2_entry)) { case QCOW2_CLUSTER_COMPRESSED: @@ -1685,7 +1685,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, QCOW2_OL_INACTIVE_L2; =20 l2_entry =3D QCOW_OFLAG_ZERO; - l2_table[i] =3D cpu_to_be64(l2_entry); + set_l2_entry(s, l2_table, i, l2_entry); ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, sizeof(uint64_t), false); if (ret < 0) { @@ -1913,7 +1913,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, } =20 for (j =3D 0; j < s->l2_size; j++) { - uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); + uint64_t l2_entry =3D get_l2_entry(s, l2_table, j); uint64_t data_offset =3D l2_entry & L2E_OFFSET_MASK; QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(bs, l= 2_entry); =20 @@ -1936,9 +1936,10 @@ static int check_oflag_copied(BlockDriverState *bs, = BdrvCheckResult *res, "l2_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "= \n", repair ? "Repairing" : "ERROR", l2_entry, refc= ount); if (repair) { - l2_table[j] =3D cpu_to_be64(refcount =3D=3D 1 - ? l2_entry | QCOW_OFLAG_COPIED - : l2_entry & ~QCOW_OFLAG_COPIED); + set_l2_entry(s, l2_table, j, + refcount =3D=3D 1 ? + l2_entry | QCOW_OFLAG_COPIED : + l2_entry & ~QCOW_OFLAG_COPIED); l2_dirty++; } } diff --git a/block/qcow2.h b/block/qcow2.h index 0942126232..6823d3f68f 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -495,6 +495,18 @@ typedef enum QCow2MetadataOverlap { =20 #define INV_OFFSET (-1ULL) =20 +static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, + int idx) +{ + return be64_to_cpu(l2_slice[idx]); +} + +static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, + int idx, uint64_t entry) +{ + l2_slice[idx] =3D cpu_to_be64(entry); +} + static inline bool has_data_file(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016134; cv=none; d=zohomail.com; s=zohoarc; b=AzKIk7XRt2QuG1npCgJg7+dY8S5sMudQeMxiA9BoYX26zv7Q0SmhPbTO0EivN+M2XbDZwt95B8KPYZtaSP5d7Z4EU0W8+Sai5tf8q5/eRfLEQn4wIVAUnv7lkfwEAlAMezYfTO9EYLd5w0FvMhy/5lyjOg1O7gPmEXhpLXrzvC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016134; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HiUDYygHbreOJ4VpTqnZuGeG1uwk96nU2SwXCxyXjEw=; b=hWL7jRM3/5WczA4ZnAFEfdUzBL6QjFb9PFswVIdVhLJ2qLu5gqcHokiEf7sMp7wOp0IFjsAbWd+DRKD5qoBvJmBwHglaYQLk8mNxQfB7SoqvNEoEU7P3+QvE0wxgrGU/WjsfcdlIifFry/CWD9JKcrwYX8jP7FS6Er7fDoqEiyk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157701613467442.77618265505453; Sun, 22 Dec 2019 04:02:14 -0800 (PST) Received: from localhost ([::1]:47074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizw5-0002rq-Ky for importer@patchew.org; Sun, 22 Dec 2019 07:02:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44283) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZE-0003VR-FT for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00074S-3B for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004no-JC; Sun, 22 Dec 2019 06:38:33 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d7-FQ; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vc-Bw; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=HiUDYygHbreOJ4VpTqnZuGeG1uwk96nU2SwXCxyXjEw=; b=gCUQRQQmE6sV3CANOS4KIIp1mvmOGau7BqrarvBzkfKuqBZJNQz+9YRCp7ijiPlykD9NM80skRoqgrmRIe67zLVkQCPlanZFve9E4ysV+IdfA+DoGSbNcL4n8WNcWuL81327ml79yWgYMz3Nw0fJoFpKc47bagkp9Wd4ZHLjdPBxf/0ykzn/w8orBmd+1ARDW8sMlWcr7M0ipWYzil4l4yooDGrduMNdCz7FNWpnkGEVV1AAxCWhoZLupytXgqu0O8IGrLlvFb92cqmIP8Sb72mNAH63L6EFJfmURoRwJxOGqzsfW0ubbQlcfKE5P/SiuqZafs0AjNbYg6VaQa9AUg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 05/27] qcow2: Document the Extended L2 Entries feature Date: Sun, 22 Dec 2019 12:36:46 +0100 Message-Id: <0b884ddcd0ac3a3c0b8cdd9d09c74566ac107c9a.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Subcluster allocation in qcow2 is implemented by extending the existing L2 table entries and adding additional information to indicate the allocation status of each subcluster. This patch documents the changes to the qcow2 format and how they affect the calculation of the L2 cache size. Signed-off-by: Alberto Garcia --- docs/interop/qcow2.txt | 68 ++++++++++++++++++++++++++++++++++++++++-- docs/qcow2-cache.txt | 19 +++++++++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index af5711e533..d34261f955 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -39,6 +39,9 @@ The first cluster of a qcow2 image contains the file head= er: as the maximum cluster size and won't be able to open = images with larger cluster sizes. =20 + Note: if the image has Extended L2 Entries then cluste= r_bits + must be at least 14 (i.e. 16384 byte clusters). + 24 - 31: size Virtual disk size in bytes. =20 @@ -109,7 +112,12 @@ in the description of a field. An External Data File Name header extensio= n may be present if this bit is set. =20 - Bits 3-63: Reserved (set to 0) + Bit 3: Extended L2 Entries. If this bit is set t= hen + L2 table entries use an extended format th= at + allows subcluster-based allocation. See the + Extended L2 Entries section for more detai= ls. + + Bits 4-63: Reserved (set to 0) =20 80 - 87: compatible_features Bitmask of compatible features. An implementation can @@ -437,7 +445,7 @@ cannot be relaxed without an incompatible layout change= ). Given an offset into the virtual disk, the offset into the image file can = be obtained as follows: =20 - l2_entries =3D (cluster_size / sizeof(uint64_t)) + l2_entries =3D (cluster_size / sizeof(uint64_t)) [*] =20 l2_index =3D (offset / cluster_size) % l2_entries l1_index =3D (offset / cluster_size) / l2_entries @@ -447,6 +455,8 @@ obtained as follows: =20 return cluster_offset + (offset % cluster_size) =20 + [*] this changes if Extended L2 Entries are enabled, see next section + L1 table entry: =20 Bit 0 - 8: Reserved (set to 0) @@ -487,7 +497,8 @@ Standard Cluster Descriptor: nor is data read from the backing file if the cluster = is unallocated. =20 - With version 2, this is always 0. + With version 2 or with extended L2 entries (see the ne= xt + section), this is always 0. =20 1 - 8: Reserved (set to 0) =20 @@ -524,6 +535,57 @@ file (except if bit 0 in the Standard Cluster Descript= or is set). If there is no backing file or the backing file is smaller than the image, they shall = read zeros for all parts that are not covered by the backing file. =20 +=3D=3D Extended L2 Entries =3D=3D + +An image uses Extended L2 Entries if bit 3 is set on the incompatible_feat= ures +field of the header. + +In these images standard data clusters are divided into 32 subclusters of = the +same size. They are contiguous and start from the beginning of the cluster. +Subclusters can be allocated independently and the L2 entry contains infor= mation +indicating the status of each one of them. Compressed data clusters don't = have +subclusters so they are treated like in images without this feature. + +The size of an extended L2 entry is 128 bits so the number of entries per = table +is calculated using this formula: + + l2_entries =3D (cluster_size / (2 * sizeof(uint64_t))) + +The first 64 bits have the same format as the standard L2 table entry desc= ribed +in the previous section, with the exception of bit 0 of the standard clust= er +descriptor. + +The last 64 bits contain a subcluster allocation bitmap with this format: + +Subcluster Allocation Bitmap (for standard clusters): + + Bit 0 - 31: Allocation status (one bit per subcluster) + + 1: the subcluster is allocated. In this case the + host cluster offset field must contain a valid + offset. + 0: the subcluster is not allocated. In this case + read requests shall go to the backing file or + return zeros if there is no backing file data. + + Bits are assigned starting from the most significant o= ne. + (i.e. bit x is used for subcluster 31 - x) + + 32 - 63 Subcluster reads as zeros (one bit per subcluster) + + 1: the subcluster reads as zeros. In this case the + allocation status bit must be unset. The host + cluster offset field may or may not be set. + 0: no effect. + + Bits are assigned starting from the most significant o= ne. + (i.e. bit x is used for subcluster 63 - x) + +Subcluster Allocation Bitmap (for compressed clusters): + + Bit 0 - 63: Reserved (set to 0) + Compressed clusters don't have subclusters, + so this field is not used. =20 =3D=3D Snapshots =3D=3D =20 diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index d57f409861..04eb4ce2f1 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -1,6 +1,6 @@ qcow2 L2/refcount cache configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Copyright (C) 2015, 2018 Igalia, S.L. +Copyright (C) 2015, 2018-2019 Igalia, S.L. Author: Alberto Garcia =20 This work is licensed under the terms of the GNU GPL, version 2 or @@ -222,3 +222,20 @@ support this functionality, and is 0 (disabled) on oth= er platforms. This functionality currently relies on the MADV_DONTNEED argument for madvise() to actually free the memory. This is a Linux-specific feature, so cache-clean-interval is not supported on other systems. + + +Extended L2 Entries +------------------- +All numbers shown in this document are valid for qcow2 images with normal +64-bit L2 entries. + +Images with extended L2 entries need twice as much L2 metadata, so the L2 +cache size must be twice as large for the same disk space. + + disk_size =3D l2_cache_size * cluster_size / 16 + +i.e. + + l2_cache_size =3D disk_size * 16 / cluster_size + +Refcount blocks are not affected by this. --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015922; cv=none; d=zohomail.com; s=zohoarc; b=j9POnVeH2yiew/tJELkkiJ7naLC5ICbZh/98RL4Wcz4W2gFDAp6inw6y4JuJhAAf9DMMjUBfVWkcVmYZh0x4EhnlR1d6Bpb4aLo5WsUaqpEJyaJQHjsmrnHAyj5ChxsDUB306L9b8VwfINCNj0+9q1/t6wBwxOwLJFZqqgIJqNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015922; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IVBAlyVPifyO1dOQL27WASmPqtIuzSy/kdIJ89D+GVQ=; b=Kt5Jk6wvcCB+Bi7D1SkzYe9KmEZghyj5k5Nfo6HcJjjdxZTIhO+JeJNzKwDGZdImqx8C2uN/G8gQK3H1ZBsWomebrunSz9cvV8V08WIDVPdJSVQ0qpifWuuh6ZU8zDElnlgwrBhWprR/+xHqgsQchOdC/jpKy5czpWp3TiyJkS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015922544830.8853266227615; Sun, 22 Dec 2019 03:58:42 -0800 (PST) Received: from localhost ([::1]:47006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizsf-0007Tg-DB for importer@patchew.org; Sun, 22 Dec 2019 06:58:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43773) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ9-0003Mn-J0 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ8-0006qx-FG for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:31 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34943) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ8-0004Oj-27; Sun, 22 Dec 2019 06:38:30 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d8-IW; Sun, 22 Dec 2019 12:37:50 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Ve-D2; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=IVBAlyVPifyO1dOQL27WASmPqtIuzSy/kdIJ89D+GVQ=; b=YHzGwartUlNd0tmyum2aO+cTZ7w6vxWrPAc9bkHEo1ugWPgSNUlDADgcIx+Q48lX3PxM7PlwLyRTq2r66ooJSFJFBTHL8ALfQIuAhSWljbgGKOqUSw9Q3ZDJNGPd15EmHyGCJAaqj/mtyHwuma8pk3fJjj/9ebuV9462U3o+F4Smvk2a55oESVdtMpzlK56cC/YdChN5jJDke2D1Y2t0qh2IJuxrtW0Dm9tVMl8n4wktdRmen6GoKPiZJS1oXLVUO5YxBHJVXGWBUWlT5ZalmAM+TEKkjaLo/O6MS93eZyD4s8Nibw3ZXF97Fa3ebYG+MlpZ8jNWnNv/eRPZdfo+Ig==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 06/27] qcow2: Add dummy has_subclusters() function Date: Sun, 22 Dec 2019 12:36:47 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function will be used by the qcow2 code to check if an image has subclusters or not. At the moment this simply returns false. Once all patches needed for subcluster support are ready then QEMU will be able to create and read images with subclusters and this function will return the actual value. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 6823d3f68f..1db3fc5dbc 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -495,6 +495,12 @@ typedef enum QCow2MetadataOverlap { =20 #define INV_OFFSET (-1ULL) =20 +static inline bool has_subclusters(BDRVQcow2State *s) +{ + /* FIXME: Return false until this feature is complete */ + return false; +} + static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015151; cv=none; d=zohomail.com; s=zohoarc; b=APeXZ9BCwd8z9SSsBxeLD1G2DBnx3CB7kmf5HlcOqEJGb6qTsHHIdVeVHu9YAND7IGAbcAOerk3NUXqkF4BF/ddvXo9novGKTjp+LYg3ipUi6X8gM3FK6QAzbBK48ZPQgFfL9E1xXpq7DEkoLVXRV2Mc+MKjJGLgDjUxkIy8Ics= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015151; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=flXGfZhQJSs04qAtnGSSBaswVOGe2VgIccmH2UkpbYk=; b=ObAxvi9clAGaJPHsj1LxLMCN+NcMqtnTgRK4KLb90dCSzvC3OfSSHnaYLYeF/DY4QhJZxN9N5zkKZAz/eAfx6ESfsMnlfhZC7XvfhmuLDaS4XJknRgpX1hDZ0CPjQGzQk6hmhAvBkEQdSxWF6MgyKCF6mLs+t1eAZfMxvd4MS1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015151429400.61033516839063; Sun, 22 Dec 2019 03:45:51 -0800 (PST) Received: from localhost ([::1]:46738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizgD-0003J4-Dx for importer@patchew.org; Sun, 22 Dec 2019 06:45:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nu-5t for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005b8-QI for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:10 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Ol-24; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005d9-I6; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vg-Dy; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=flXGfZhQJSs04qAtnGSSBaswVOGe2VgIccmH2UkpbYk=; b=je/j4XVdtVvdzmKBrFcgE4znmE0Z65JNYPayialAGpHAURG2h6iebYZsyMzAOjSUkuP+rl4R0GLRmMLJTrgbZcTsnhTuYUw+xbtcRKhTUJ4IhzjnrqQkZpqzsK1vfDylJ3NCnMqvZCt9zlHl1S7ppnZHTr/M0KESvQ+d+Iks/BQz2cZwvKQ3phg+5i++5PH3kAerR0HT3jHkwTsB+fMAs4JC9OTOVwDoiFOR60vgXnAvd+9vSD7Ph1LRdQ0odM0hlewQkwm9er/+EzI6CcQHV8NWYbG6+Gu4zzuDvV/lhpFsf++JiLl5RC/LxtMwJy+yhzNIneyz5ZxD0os272eOSA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 07/27] qcow2: Add subcluster-related fields to BDRVQcow2State Date: Sun, 22 Dec 2019 12:36:48 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds the following new fields to BDRVQcow2State: - subclusters_per_cluster: Number of subclusters in a cluster - subcluster_size: The size of each subcluster, in bytes - subcluster_bits: No. of bits so 1 << subcluster_bits =3D subcluster_size Images without subclusters are treated as if they had exactly one, with subcluster_size =3D cluster_size. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 5 +++++ block/qcow2.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 3866b47946..cbd857e9c7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1378,6 +1378,11 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, } } =20 + s->subclusters_per_cluster =3D + has_subclusters(s) ? QCOW_MAX_SUBCLUSTERS_PER_CLUSTER : 1; + s->subcluster_size =3D s->cluster_size / s->subclusters_per_cluster; + s->subcluster_bits =3D ctz32(s->subcluster_size); + /* Check support for various header values */ if (header.refcount_order > 6) { error_setg(errp, "Reference count entry width too large; may not " diff --git a/block/qcow2.h b/block/qcow2.h index 1db3fc5dbc..941330cfc9 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -78,6 +78,8 @@ /* The cluster reads as all zeros */ #define QCOW_OFLAG_ZERO (1ULL << 0) =20 +#define QCOW_MAX_SUBCLUSTERS_PER_CLUSTER 32 + #define MIN_CLUSTER_BITS 9 #define MAX_CLUSTER_BITS 21 =20 @@ -284,6 +286,9 @@ typedef struct BDRVQcow2State { int cluster_bits; int cluster_size; int l2_slice_size; + int subcluster_bits; + int subcluster_size; + int subclusters_per_cluster; int l2_bits; int l2_size; int l1_size; --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015021; cv=none; d=zohomail.com; s=zohoarc; b=aGfqxx8ft/DuaugVRR26RXH1cSM2C8NCjsc/23rUJgWIMya+y3Leoe2OWrQEleKuAQFpQNvmr9CZBZ7lC+83LCrG+tJmeeiBc/sjuVLlNGAoTmlaPVSFfNkmmHf+TJeHtzKhLKMzwVmck1OxMQt+pmSgUSHeaxVxmYIG87KinDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015021; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v7Z/v/trFlU1y5ia2m4/ef6xOxYRQRjvg+MxQ8Ut/g0=; b=KuPrfgPZ2jwHCyDATSIU2VlD6k9SCYrz68r0ZqyLq+X00dWDZb7o3HK+hFi7jKinvtFPIPiyO1cKVctHXcH1LhiTMNEU2+JpWD1kxPAJJAcvTdv7Rfbq6qVjHogGFOTqfgi189rABRoQpnNpbPkAFgBj8M9LiDkkPCKXh+lnSS4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015021318118.3108666596961; Sun, 22 Dec 2019 03:43:41 -0800 (PST) Received: from localhost ([::1]:46677 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iize8-0000jy-6j for importer@patchew.org; Sun, 22 Dec 2019 06:43:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43680) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ9-0003Le-0t for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006nW-JO for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:30 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34944) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Oq-73; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dA-IL; Sun, 22 Dec 2019 12:37:50 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vi-Et; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=v7Z/v/trFlU1y5ia2m4/ef6xOxYRQRjvg+MxQ8Ut/g0=; b=H2f527j8iAryF6Yn3y3JAtt4IRw5+koAqlY7i59Z0b7Qu9fDrGplAgI9MSCQSgnJp1jzlarCbu53nOnZPqKJRv7rmYHnbtR9sL0ZFo+yhU5KegLLe6IgVTnnG2Xe9MHjPbrYxahcOnjow9ZPzqOgEo16hATlM15sD855mBn8GJk4zlms+1YPFdhKvv0iIoZf7r5wuY171tVkKHM5nyjYfKK7rOYniU8I8n29wjd1EZaNt25eMyE4p2UFsheh4OfqTty0t5qZxi6Trlv6UddmndEc3BbybISPL4g/TtgJ2vjWrtqql33xkVu0SgdluwD+PE98eI7tlZ5mCglio9zLZA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 08/27] qcow2: Add offset_to_sc_index() Date: Sun, 22 Dec 2019 12:36:49 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For a given offset, return the subcluster number within its cluster (i.e. with 32 subclusters per cluster it returns a number between 0 and 31). Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 941330cfc9..523bc489a5 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -566,6 +566,11 @@ static inline int offset_to_l2_slice_index(BDRVQcow2St= ate *s, int64_t offset) return (offset >> s->cluster_bits) & (s->l2_slice_size - 1); } =20 +static inline int offset_to_sc_index(BDRVQcow2State *s, int64_t offset) +{ + return (offset >> s->subcluster_bits) & (s->subclusters_per_cluster - = 1); +} + static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s) { return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits); --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016349; cv=none; d=zohomail.com; s=zohoarc; b=fPac3tcnvzUZGeg+djgWd7+XYUgLsCPQ3/5/MnnCrERdr9MtejjUs/vpFq2Mh7eOXFwohdjeEpDx94HsxV0H8UIkHTQam/DHJKK49PfcTwqJQoE3UudDNAav0aZHsCdaa/LHRiSwcMu4Mnl32wprRVkodCC9/3K2jE/1EJQ6/BQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016349; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eQZtVYMrBqGStkJoVsWjaQexcWMluHZ+2ryhOj/2jmY=; b=HRcxCncU0YsGwTrPVDpSUO9tGCVhjPztzX1pZUB3kMvmiL6TncN1cBDzaEWQOF7jGVSQCFK7Nhyvlc0yhUU26qh/KxhAizAo+KFnMEalkE6DKBjQ9Q9PsU2kXMcg6Jmc9cg7hxlrqyfS6Oe1KjwoZmUstOrasD1MS9UjszAn/GQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577016349950992.1540984793415; Sun, 22 Dec 2019 04:05:49 -0800 (PST) Received: from localhost ([::1]:47160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizzZ-0006Do-5J for importer@patchew.org; Sun, 22 Dec 2019 07:05:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44332) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZE-0003Vr-P4 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00074o-4s for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35052) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004o8-JM; Sun, 22 Dec 2019 06:38:34 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dB-Jn; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vk-Ft; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=eQZtVYMrBqGStkJoVsWjaQexcWMluHZ+2ryhOj/2jmY=; b=KRpjVLHC4B+2Jbs1/r6Cq3E6pMnMvRygvKbRoSweB531rA8uHU3uMjAKHIAZq0aVkV/Qxliw40gqCtMk3MVPGQp7StpTCb1n8NAcGPcGWKnV0u3HlzBlvHi1V/FJ5X6HW+6mJ5CpXLS9jd8iNdFn8gpAWJqLlCO7blTms0JK168ZI91U0gTs8u3qVlV5oluogsSIbyqY7SdWF2msHIo+EXRSGq6tOKMxxDiIngC6p1yEOb11/FaQoJIDFnKe4/ILlb/3HN1SnXs2pPJbbhV9OOjtfr98g3FKDYpSLACUvwc01a1mA4bo/2XzBdWePQldPgSMdm0Iuz2wp6joV/47GQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 09/27] qcow2: Add l2_entry_size() Date: Sun, 22 Dec 2019 12:36:50 +0100 Message-Id: <7927a81fc619c3e842fdf91f1909dc3ca444ba3c.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qcow2 images with subclusters have 128-bit L2 entries. The first 64 bits contain the same information as traditional images and the last 64 bits form a bitmap with the status of each individual subcluster. Because of that we cannot assume that L2 entries are sizeof(uint64_t) anymore. This function returns the proper value for the image. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 12 ++++++------ block/qcow2-refcount.c | 14 ++++++++------ block/qcow2.c | 8 ++++---- block/qcow2.h | 9 +++++++++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 683c9569ad..851c7e6165 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -209,7 +209,7 @@ static int l2_load(BlockDriverState *bs, uint64_t offse= t, uint64_t l2_offset, uint64_t **l2_slice) { BDRVQcow2State *s =3D bs->opaque; - int start_of_slice =3D sizeof(uint64_t) * + int start_of_slice =3D l2_entry_size(s) * (offset_to_l2_index(s, offset) - offset_to_l2_slice_index(s, offse= t)); =20 return qcow2_cache_get(bs, s->l2_table_cache, l2_offset + start_of_sli= ce, @@ -277,7 +277,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_ind= ex) =20 /* allocate a new l2 entry */ =20 - l2_offset =3D qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t)); + l2_offset =3D qcow2_alloc_clusters(bs, s->l2_size * l2_entry_size(s)); if (l2_offset < 0) { ret =3D l2_offset; goto fail; @@ -301,7 +301,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_ind= ex) =20 /* allocate a new entry in the l2 cache */ =20 - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 trace_qcow2_l2_allocate_get_empty(bs, l1_index); @@ -365,7 +365,7 @@ fail: } s->l1_table[l1_index] =3D old_l2_offset; if (l2_offset > 0) { - qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t), + qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s), QCOW2_DISCARD_ALWAYS); } return ret; @@ -708,7 +708,7 @@ static int get_cluster_table(BlockDriverState *bs, uint= 64_t offset, =20 /* Then decrease the refcount of the old table */ if (l2_offset) { - qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_= t), + qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(= s), QCOW2_DISCARD_OTHER); } =20 @@ -1895,7 +1895,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, int ret; int i, j; =20 - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 if (!is_active_l1) { diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 223048569e..de85ed29a4 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1253,7 +1253,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, l2_slice =3D NULL; l1_table =3D NULL; l1_size2 =3D l1_size * sizeof(uint64_t); - slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * l2_entry_size(s); n_slices =3D s->cluster_size / slice_size2; =20 s->cache_discards =3D true; @@ -1604,7 +1604,7 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, int i, l2_size, nb_csectors, ret; =20 /* Read L2 table from disk */ - l2_size =3D s->l2_size * sizeof(uint64_t); + l2_size =3D s->l2_size * l2_entry_size(s); l2_table =3D g_malloc(l2_size); =20 ret =3D bdrv_pread(bs->file, l2_offset, l2_table, l2_size); @@ -1679,15 +1679,16 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", offset); if (fix & BDRV_FIX_ERRORS) { + int idx =3D i * (l2_entry_size(s) / sizeof(uint64_= t)); uint64_t l2e_offset =3D - l2_offset + (uint64_t)i * sizeof(uint64_t); + l2_offset + (uint64_t)i * l2_entry_size(s); int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; =20 l2_entry =3D QCOW_OFLAG_ZERO; set_l2_entry(s, l2_table, i, l2_entry); ret =3D qcow2_pre_write_overlap_check(bs, ign, - l2e_offset, sizeof(uint64_t), false); + l2e_offset, l2_entry_size(s), false); if (ret < 0) { fprintf(stderr, "ERROR: Overlap check failed\n= "); res->check_errors++; @@ -1697,7 +1698,8 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, } =20 ret =3D bdrv_pwrite_sync(bs->file, l2e_offset, - &l2_table[i], sizeof(uint64= _t)); + &l2_table[idx], + l2_entry_size(s)); if (ret < 0) { fprintf(stderr, "ERROR: Failed to overwrite L2= " "table entry: %s\n", strerror(-ret)); @@ -1904,7 +1906,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, } =20 ret =3D bdrv_pread(bs->file, l2_offset, l2_table, - s->l2_size * sizeof(uint64_t)); + s->l2_size * l2_entry_size(s)); if (ret < 0) { fprintf(stderr, "ERROR: Could not read L2 table: %s\n", strerror(-ret)); diff --git a/block/qcow2.c b/block/qcow2.c index cbd857e9c7..e7607d90d4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -868,7 +868,7 @@ static void read_cache_sizes(BlockDriverState *bs, Qemu= Opts *opts, uint64_t max_l2_entries =3D DIV_ROUND_UP(virtual_disk_size, s->cluster= _size); /* An L2 table is always one cluster in size so the max cache size * should be a multiple of the cluster size. */ - uint64_t max_l2_cache =3D ROUND_UP(max_l2_entries * sizeof(uint64_t), + uint64_t max_l2_cache =3D ROUND_UP(max_l2_entries * l2_entry_size(s), s->cluster_size); =20 combined_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE); @@ -1029,7 +1029,7 @@ static int qcow2_update_options_prepare(BlockDriverSt= ate *bs, } } =20 - r->l2_slice_size =3D l2_cache_entry_size / sizeof(uint64_t); + r->l2_slice_size =3D l2_cache_entry_size / l2_entry_size(s); r->l2_table_cache =3D qcow2_cache_create(bs, l2_cache_size, l2_cache_entry_size); r->refcount_block_cache =3D qcow2_cache_create(bs, refcount_cache_size, @@ -1423,7 +1423,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, bs->encrypted =3D true; } =20 - s->l2_bits =3D s->cluster_bits - 3; /* L2 is always one cluster */ + s->l2_bits =3D s->cluster_bits - ctz32(l2_entry_size(s)); s->l2_size =3D 1 << s->l2_bits; /* 2^(s->refcount_order - 3) is the refcount width in bytes */ s->refcount_block_bits =3D s->cluster_bits - (s->refcount_order - 3); @@ -4115,7 +4115,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, * preallocation. All that matters is that we will not have to al= locate * new refcount structures for them.) */ nb_new_l2_tables =3D DIV_ROUND_UP(nb_new_data_clusters, - s->cluster_size / sizeof(uint64_t)= ); + s->cluster_size / l2_entry_size(s)= ); /* The cluster range may not be aligned to L2 boundaries, so add o= ne L2 * table for a potential head/tail */ nb_new_l2_tables++; diff --git a/block/qcow2.h b/block/qcow2.h index 523bc489a5..8be020bb76 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -80,6 +80,10 @@ =20 #define QCOW_MAX_SUBCLUSTERS_PER_CLUSTER 32 =20 +/* Size of normal and extended L2 entries */ +#define L2E_SIZE_NORMAL (sizeof(uint64_t)) +#define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2) + #define MIN_CLUSTER_BITS 9 #define MAX_CLUSTER_BITS 21 =20 @@ -506,6 +510,11 @@ static inline bool has_subclusters(BDRVQcow2State *s) return false; } =20 +static inline size_t l2_entry_size(BDRVQcow2State *s) +{ + return has_subclusters(s) ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; +} + static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014957; cv=none; d=zohomail.com; s=zohoarc; b=UKq3M763Ze7PE7SmX+5/5ZQBvy+1vYiYJe474VeDaHFGEJRpGNqM9xAT3YmOlWgU2Bsnz+oafhV+PNWZjoYjDlxDcDd/0GJyuyXwqHWopPFyUENRR1Qyj/fkGw3eQKVgvsaqsPVAF8ZoWEOZqxYnD1lfjirS1PRTb2Bq5kGuekU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014957; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ju9m1bHZwrBhmoBOR8wUG6o2CitZFGgTqc+m8uLXTAo=; b=RFgipbpCSlv8ZvdVA0rt/ij1oAkOEt5+mAr84+TBtCtRZf4Uu4DSIou5PrhEFufLxCzmFpip+LHYgEP0bMx9xtc/jPGqmv/CZg05CH6TyM38LrxJhGIRNy40mBdaw9AiWtotIl38NDSAI6lpSi2NISTtOAOjJVvsCok8WNO0PHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014957039753.7574466434914; Sun, 22 Dec 2019 03:42:37 -0800 (PST) Received: from localhost ([::1]:46664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizd5-0008Bt-R7 for importer@patchew.org; Sun, 22 Dec 2019 06:42:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41551) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002o0-P1 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYo-0005cI-4s for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34979) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004V0-Df; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dC-M2; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vm-H3; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ju9m1bHZwrBhmoBOR8wUG6o2CitZFGgTqc+m8uLXTAo=; b=bOmmmXNk7vR4LVuGDGs7+YyG3PZbYplNpBKwodCDMSpht5NqnR5TxziEZp+6uz82R0dBDHuGUMqVAjyrg1fLxyj8K5xbMq/B1+qHZE1ddvzjL0Ea4zoilUwmfgtVlR3Qz40f+bUA1jH5nbfNj91b22ivD/m25JiNlHwAKaUnod9Bb8VEEb3RwfD/CdzaGXXmL/ar4WaITiajdETIgNK82ttcdmcx4HNGKo6UctX0Zqk/7PzwC1qc8sKdP3T9JlOTHQZeu+Fea6QSUGHnN5okJ7pY7p+qLPCqx2wXlKVOB9fNsF9fbO9reYL82rtYqztBCqW2BR+6eKCXBoHahiW8Aw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 10/27] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap() Date: Sun, 22 Dec 2019 12:36:51 +0100 Message-Id: <0229eca3c5199c5383b640f9a041a83ddfcf5b0c.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extended L2 entries are 128-bit wide: 64 bits for the entry itself and 64 bits for the subcluster allocation bitmap. In order to support them correctly get/set_l2_entry() need to be updated so they take the entry width into account in order to calculate the correct offset. This patch also adds the get/set_l2_bitmap() functions that are used to access the bitmaps. For convenience we allow calling get_l2_bitmap() on images without subclusters, although the caller does not need and should ignore the returned value. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 8be020bb76..64b0a814f4 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -518,15 +518,37 @@ static inline size_t l2_entry_size(BDRVQcow2State *s) static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); return be64_to_cpu(l2_slice[idx]); } =20 +static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, + int idx) +{ + if (has_subclusters(s)) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); + return be64_to_cpu(l2_slice[idx + 1]); + } else { + /* For convenience only; the caller should ignore this value. */ + return 0; + } +} + static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, int idx, uint64_t entry) { + idx *=3D l2_entry_size(s) / sizeof(uint64_t); l2_slice[idx] =3D cpu_to_be64(entry); } =20 +static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, + int idx, uint64_t bitmap) +{ + assert(has_subclusters(s)); + idx *=3D l2_entry_size(s) / sizeof(uint64_t); + l2_slice[idx + 1] =3D cpu_to_be64(bitmap); +} + static inline bool has_data_file(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014802; cv=none; d=zohomail.com; s=zohoarc; b=BcBlI4qjcS/xrp+p/InQ5Bb9oAyw/SgRyC9bnHovW2sq2TkTd4CjFoAHHQi4Nj0k6Q3S5KBDwdHFCl9bOtJdy2BngKhP+vjRhDonJjlAzcT6dbK9qcKE0BUj0MzSUuVjFrRHbd/KOg/+Z5hh7/5QHWyQpmPWtKBFBlVK++pVOIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014802; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sKZ/LI8kUszYPtNMyvsyF4RnStAXro4R3DTVZkwSSf4=; b=XCEgViu62RpTm8sNe/3ZLYZsyCsKW4oo6Hjx58205Rh+PpJktGmrFuCqR9MWuiXktLb78e6IDM4ALLgyglH3eVidmC23NUsjRJKZQyMylIEF7HpmhVcddrnpAN5OySRZGdG5CaTszvXtHGQgGg5d5VMsbQaqxNWDEv7RzSMC3sU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014802953928.4202306923319; Sun, 22 Dec 2019 03:40:02 -0800 (PST) Received: from localhost ([::1]:46602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizab-0004mi-Jg for importer@patchew.org; Sun, 22 Dec 2019 06:40:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41523) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002ny-H6 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005bO-RZ for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Uu-Cm; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dD-MH; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vo-I0; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=sKZ/LI8kUszYPtNMyvsyF4RnStAXro4R3DTVZkwSSf4=; b=cyWlLEdfBFr+4u6ipZKz7vU6+IMGHm/vwzdw+PFF0EGZA7jgijvi7TIsUahhATyp/0aRlj16hQW9RT50vKe3ub3aboC0ZFckOxIyaGGLlvnQejcfXv40nlB9bficQEBxjb7aMSFHsms2w8eUD0j+UoILyrAT4UweHT3dMUVex0r8cPpkopi4slcKUZJDeac5C1pdSzuk20w0/PMFyaT0dd0Gb/3of2D0DrSZXWjjfEBgf4zlZw/kn/qk1fPQ1HU37h7wqsaSCHIo9eqTByI3zdkXIVsoHeKUpNFVLpgyCqwZnA6cEQj14rCFcDgoWCwpsjsO6IdDZQNrZQwwbJOZ7w==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 11/27] qcow2: Add QCow2SubclusterType and qcow2_get_subcluster_type() Date: Sun, 22 Dec 2019 12:36:52 +0100 Message-Id: <124dca3e5be368048346209754fec38dff404990.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds QCow2SubclusterType, which is the subcluster-level version of QCow2ClusterType. All QCOW2_SUBCLUSTER_* values have the the same meaning as their QCOW2_CLUSTER_* equivalents (when they exist). See below for details and caveats. In images without extended L2 entries clusters are treated as having exactly one subcluster so it is possible to replace one data type with the other while keeping the exact same semantics. With extended L2 entries there are new possible values, and every subcluster in the same cluster can obviously have a different QCow2SubclusterType so functions need to be adapted to work on the subcluster level. There are several things that have to be taken into account: a) QCOW2_SUBCLUSTER_COMPRESSED means that the whole cluster is compressed. We do not support compression at the subcluster level. b) There are two different values for unallocated subclusters: QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN which means that the whole cluster is unallocated, and QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC which means that the cluster is allocated but the subcluster is not. The latter can only happen in images with extended L2 entries. c) QCOW2_SUBCLUSTER_INVALID is used to detect the cases where an L2 entry has a value that violates the specification. The caller is responsible for handling these situations. To prevent compatibility problems with images that have invalid values but are currently being read by QEMU without causing side effects, QCOW2_SUBCLUSTER_INVALID is only returned for images with extended L2 entries. qcow2_cluster_to_subcluster_type() is added as a separate function from qcow2_get_subcluster_type(), but this is only temporary and both will be merged in a subsequent patch. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 64b0a814f4..321ba9550f 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -80,6 +80,15 @@ =20 #define QCOW_MAX_SUBCLUSTERS_PER_CLUSTER 32 =20 +/* The subcluster X [0..31] reads as zeroes */ +#define QCOW_OFLAG_SUB_ZERO(X) ((1ULL << 63) >> (X)) +/* The subcluster X [0..31] is allocated */ +#define QCOW_OFLAG_SUB_ALLOC(X) ((1ULL << 31) >> (X)) +/* L2 entry bitmap with all "read as zeroes" bits set */ +#define QCOW_L2_BITMAP_ALL_ZEROES 0xFFFFFFFF00000000ULL +/* L2 entry bitmap with all allocation bits set */ +#define QCOW_L2_BITMAP_ALL_ALLOC 0x00000000FFFFFFFFULL + /* Size of normal and extended L2 entries */ #define L2E_SIZE_NORMAL (sizeof(uint64_t)) #define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2) @@ -455,6 +464,16 @@ typedef enum QCow2ClusterType { QCOW2_CLUSTER_COMPRESSED, } QCow2ClusterType; =20 +typedef enum QCow2SubclusterType { + QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN, + QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC, + QCOW2_SUBCLUSTER_ZERO_PLAIN, + QCOW2_SUBCLUSTER_ZERO_ALLOC, + QCOW2_SUBCLUSTER_NORMAL, + QCOW2_SUBCLUSTER_COMPRESSED, + QCOW2_SUBCLUSTER_INVALID, +} QCow2SubclusterType; + typedef enum QCow2MetadataOverlap { QCOW2_OL_MAIN_HEADER_BITNR =3D 0, QCOW2_OL_ACTIVE_L1_BITNR =3D 1, @@ -632,6 +651,79 @@ static inline QCow2ClusterType qcow2_get_cluster_type(= BlockDriverState *bs, } } =20 +/* For an image without extended L2 entries, return the + * QCow2SubclusterType equivalent of a given QCow2ClusterType */ +static inline +QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type) +{ + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + case QCOW2_CLUSTER_NORMAL: + return QCOW2_SUBCLUSTER_NORMAL; + case QCOW2_CLUSTER_UNALLOCATED: + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + default: + g_assert_not_reached(); + } +} + +/* In an image without subsclusters @l2_bitmap is ignored and + * @sc_index must be 0. */ +static inline +QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs, + uint64_t l2_entry, + uint64_t l2_bitmap, + unsigned sc_index) +{ + BDRVQcow2State *s =3D bs->opaque; + QCow2ClusterType type =3D qcow2_get_cluster_type(bs, l2_entry); + assert(sc_index < s->subclusters_per_cluster); + + if (has_subclusters(s)) { + bool sc_zero =3D l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index); + bool sc_alloc =3D l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index); + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + if (l2_bitmap !=3D 0) { + return QCOW2_SUBCLUSTER_INVALID; + } + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_INVALID; + case QCOW2_CLUSTER_NORMAL: + if (!sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC; + } else if (!sc_zero && sc_alloc) { + return QCOW2_SUBCLUSTER_NORMAL; + } else if (sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + } else { /* sc_zero && sc_alloc */ + return QCOW2_SUBCLUSTER_INVALID; + } + case QCOW2_CLUSTER_UNALLOCATED: + if (!sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + } else if (!sc_zero && sc_alloc) { + return QCOW2_SUBCLUSTER_INVALID; + } else if (sc_zero && !sc_alloc) { + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + } else { /* sc_zero && sc_alloc */ + return QCOW2_SUBCLUSTER_INVALID; + } + default: + g_assert_not_reached(); + } + } else { + return qcow2_cluster_to_subcluster_type(type); + } +} + /* Check whether refcounts are eager or lazy */ static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016411; cv=none; d=zohomail.com; s=zohoarc; b=ArqQi+CpYzoBmrrTkpgRlJ4nyqdWhqeArkiZcvsj16Cicqd4/v/VNzxNaLqOuURtDcFf/g30jdDpL+hbtRyyFlC4IcP1i1/jHA1BBWhYyS3a1AERP3IPhfdwf+5AcmPRGvt6+v74hYebsWO18Him58TSbCyuFpGUCWKU+Uf0Roc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016411; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2WhpOWC666BhwTTPbASHMuPGmY1UVgCMvKZYd0QtBRI=; b=R7L6NOv1UCxEqcwVKlLiyfaS1UTuogmLGookuE49kwGdeaCdrbqkhFUuXB8ZIisghRmjKWaHzstOez5X0TwQksHYTlkTKKwEQ/OjUYwHJAV+fY3ouXJeHUxVibBrxF6eoSWHOXkjIgjisWTb0lTzQZNuBwR6g20GW308LqhGkZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15770164113161008.9012503895675; Sun, 22 Dec 2019 04:06:51 -0800 (PST) Received: from localhost ([::1]:47172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ij00Y-00079P-9l for importer@patchew.org; Sun, 22 Dec 2019 07:06:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44395) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZF-0003X7-F2 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00075W-Cz for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:37 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35034) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004l0-JQ; Sun, 22 Dec 2019 06:38:34 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dE-MR; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vq-J0; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=2WhpOWC666BhwTTPbASHMuPGmY1UVgCMvKZYd0QtBRI=; b=WFDsGi6bW7d2kWE5O/tP6uNpCR0Amo0F4I8r43INFzd0iZLa366BYJEv4LF4H8ai+69s7C5bPLiEl85g5BUS3dW3Jm0bGjQXlwE6EaEqLQ/dYi7VBXgxuCWTY35bP3+OiKlEf55+dkE+kmW/1fAqT+Bs2eJn4wPZZiWky1R1SygiAsZi7G0SY+d+JSgcK79KgYuCd2sZr5ip/xYxagHXCwxGfFhLEgHlYPOXbx3itTmpU9qhCiJ4phU58U8FR0MBcTkW1pFY/C4lsNXN0hL/bDRFee09cAU/Isf3obgy0q44OtC8aIXTTUiuKJAVV5g7++DUYAn7R0EL6Z1CWJWnBA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 12/27] qcow2: Replace QCOW2_CLUSTER_* with QCOW2_SUBCLUSTER_* Date: Sun, 22 Dec 2019 12:36:53 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In order to support extended L2 entries some functions of the qcow2 driver need to start dealing with subclusters instead of clusters. qcow2_get_cluster_offset() is modified to return the subcluster type instead of the cluster type, and all callers are updated to replace all values of QCow2ClusterType with their QCow2SubclusterType equivalents (as returned by qcow2_cluster_to_subcluster_type()). This patch only changes the data types, there are no semantic changes. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 19 +++++----- block/qcow2.c | 82 +++++++++++++++++++++++++------------------ block/qcow2.h | 3 +- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 851c7e6165..40c2e34a2a 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -497,21 +497,22 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, /* * get_cluster_offset * - * For a given offset of the virtual disk, find the cluster type and offse= t in - * the qcow2 file. The offset is stored in *cluster_offset. + * For a given offset of the virtual disk, find the cluster offset in + * the qcow2 file and store it in *cluster_offset. * * On entry, *bytes is the maximum number of contiguous bytes starting at * offset that we are interested in. * * On exit, *bytes is the number of bytes starting at offset that have the= same - * cluster type and (if applicable) are stored contiguously in the image f= ile. - * Compressed clusters are always returned one by one. + * subcluster type and (if applicable) are stored contiguously in the image + * file. The subcluster type is stored in *subcluster_type. Compressed clu= sters + * are always processed one by one. * - * Returns the cluster type (QCOW2_CLUSTER_*) on success, -errno in error - * cases. + * Returns 0 on success, -errno in error cases. */ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *cluster_offset) + unsigned int *bytes, uint64_t *cluster_offset, + QCow2SubclusterType *subcluster_type) { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; @@ -653,7 +654,9 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - return type; + *subcluster_type =3D qcow2_cluster_to_subcluster_type(type); + + return 0; =20 fail: qcow2_cache_put(s->l2_table_cache, (void **)&l2_slice); diff --git a/block/qcow2.c b/block/qcow2.c index e7607d90d4..9277d680ef 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1964,6 +1964,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_offset; unsigned int bytes; + QCow2SubclusterType type; int ret, status =3D 0; =20 qemu_co_mutex_lock(&s->lock); @@ -1975,7 +1976,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, } =20 bytes =3D MIN(INT_MAX, count); - ret =3D qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset); + ret =3D qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset, = &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; @@ -1983,15 +1984,16 @@ static int coroutine_fn qcow2_co_block_status(Block= DriverState *bs, =20 *pnum =3D bytes; =20 - if ((ret =3D=3D QCOW2_CLUSTER_NORMAL || ret =3D=3D QCOW2_CLUSTER_ZERO_= ALLOC) && - !s->crypto) { + if ((type =3D=3D QCOW2_SUBCLUSTER_NORMAL || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) && !s->crypto) { *map =3D cluster_offset | offset_into_cluster(s, offset); *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || ret =3D=3D QCOW2_CLUSTER_ZE= RO_ALLOC) { + if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (ret !=3D QCOW2_CLUSTER_UNALLOCATED) { + } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2094,7 +2096,7 @@ typedef struct Qcow2AioTask { AioTask task; =20 BlockDriverState *bs; - QCow2ClusterType cluster_type; /* only for read */ + QCow2SubclusterType subcluster_type; /* only for read */ uint64_t file_cluster_offset; uint64_t offset; uint64_t bytes; @@ -2107,7 +2109,7 @@ static coroutine_fn int qcow2_co_preadv_task_entry(Ai= oTask *task); static coroutine_fn int qcow2_add_task(BlockDriverState *bs, AioTaskPool *pool, AioTaskFunc func, - QCow2ClusterType cluster_type, + QCow2SubclusterType subcluster_type, uint64_t file_cluster_offset, uint64_t offset, uint64_t bytes, @@ -2121,7 +2123,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, *task =3D (Qcow2AioTask) { .task.func =3D func, .bs =3D bs, - .cluster_type =3D cluster_type, + .subcluster_type =3D subcluster_type, .qiov =3D qiov, .file_cluster_offset =3D file_cluster_offset, .offset =3D offset, @@ -2132,7 +2134,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, =20 trace_qcow2_add_task(qemu_coroutine_self(), bs, pool, func =3D=3D qcow2_co_preadv_task_entry ? "read" := "write", - cluster_type, file_cluster_offset, offset, bytes, + subcluster_type, file_cluster_offset, offset, byt= es, qiov, qiov_offset); =20 if (!pool) { @@ -2145,7 +2147,7 @@ static coroutine_fn int qcow2_add_task(BlockDriverSta= te *bs, } =20 static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, - QCow2ClusterType cluster_type, + QCow2SubclusterType subc_type, uint64_t file_cluster_offset, uint64_t offset, uint64_t byt= es, QEMUIOVector *qiov, @@ -2154,24 +2156,24 @@ static coroutine_fn int qcow2_co_preadv_task(BlockD= riverState *bs, BDRVQcow2State *s =3D bs->opaque; int offset_in_cluster =3D offset_into_cluster(s, offset); =20 - switch (cluster_type) { - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: + switch (subc_type) { + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: /* Both zero types are handled in qcow2_co_preadv_part */ g_assert_not_reached(); =20 - case QCOW2_CLUSTER_UNALLOCATED: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part = */ =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); return bdrv_co_preadv_part(bs->backing, offset, bytes, qiov, qiov_offset, 0); =20 - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_COMPRESSED: return qcow2_co_preadv_compressed(bs, file_cluster_offset, offset, bytes, qiov, qiov_offset= ); =20 - case QCOW2_CLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_NORMAL: if ((file_cluster_offset & 511) !=3D 0) { return -EIO; } @@ -2199,8 +2201,9 @@ static coroutine_fn int qcow2_co_preadv_task_entry(Ai= oTask *task) =20 assert(!t->l2meta); =20 - return qcow2_co_preadv_task(t->bs, t->cluster_type, t->file_cluster_of= fset, - t->offset, t->bytes, t->qiov, t->qiov_offs= et); + return qcow2_co_preadv_task(t->bs, t->subcluster_type, + t->file_cluster_offset, t->offset, t->byte= s, + t->qiov, t->qiov_offset); } =20 static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, @@ -2212,6 +2215,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, int ret =3D 0; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t cluster_offset =3D 0; + QCow2SubclusterType type; AioTaskPool *aio =3D NULL; =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -2223,22 +2227,23 @@ static coroutine_fn int qcow2_co_preadv_part(BlockD= riverState *bs, } =20 qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_= offset); + ret =3D qcow2_get_cluster_offset(bs, offset, &cur_bytes, + &cluster_offset, &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { goto out; } =20 - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - ret =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || - (ret =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) + if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { if (!aio && cur_bytes !=3D bytes) { aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } - ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, re= t, + ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, ty= pe, cluster_offset, offset, cur_bytes, qiov, qiov_offset, NULL); if (ret < 0) { @@ -2469,7 +2474,7 @@ static coroutine_fn int qcow2_co_pwritev_task_entry(A= ioTask *task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 - assert(!t->cluster_type); + assert(!t->subcluster_type); =20 return qcow2_co_pwritev_task(t->bs, t->file_cluster_offset, t->offset, t->bytes, t->qiov, t->qiov_off= set, @@ -3723,6 +3728,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, if (head || tail) { uint64_t off; unsigned int nr; + QCow2SubclusterType type; =20 assert(head + bytes <=3D s->cluster_size); =20 @@ -3738,10 +3744,14 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Bloc= kDriverState *bs, offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); bytes =3D s->cluster_size; nr =3D s->cluster_size; - ret =3D qcow2_get_cluster_offset(bs, offset, &nr, &off); - if (ret !=3D QCOW2_CLUSTER_UNALLOCATED && - ret !=3D QCOW2_CLUSTER_ZERO_PLAIN && - ret !=3D QCOW2_CLUSTER_ZERO_ALLOC) { + ret =3D qcow2_get_cluster_offset(bs, offset, &nr, &off, &type); + if (ret < 0) { + qemu_co_mutex_unlock(&s->lock); + return -ENOTSUP; + } + if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && + type !=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } @@ -3799,17 +3809,19 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 while (bytes !=3D 0) { uint64_t copy_offset =3D 0; + QCow2SubclusterType type; /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); cur_write_flags =3D write_flags; =20 - ret =3D qcow2_get_cluster_offset(bs, src_offset, &cur_bytes, ©= _offset); + ret =3D qcow2_get_cluster_offset(bs, src_offset, &cur_bytes, + ©_offset, &type); if (ret < 0) { goto out; } =20 - switch (ret) { - case QCOW2_CLUSTER_UNALLOCATED: + switch (type) { + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); if (src_offset >=3D backing_length) { @@ -3824,16 +3836,16 @@ qcow2_co_copy_range_from(BlockDriverState *bs, } break; =20 - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; break; =20 - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_COMPRESSED: ret =3D -ENOTSUP; goto out; =20 - case QCOW2_CLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_NORMAL: child =3D s->data_file; copy_offset +=3D offset_into_cluster(s, src_offset); if ((copy_offset & 511) !=3D 0) { diff --git a/block/qcow2.h b/block/qcow2.h index 321ba9550f..37b7e25989 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -831,7 +831,8 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t se= ctor_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *cluster_offset= ); + unsigned int *bytes, uint64_t *cluster_offset, + QCow2SubclusterType *subcluster_type); int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015606; cv=none; d=zohomail.com; s=zohoarc; b=eAF1ETE1gqFuMdX6XyRxcres2hHDMUAaV5GIwthVbi1VFbap5mmiCfqwxGEJ/zvYhDSXipKc/abeRAvqSo4KMP/By0ueKsBF7uDgKsfPwDycUXCr3rWcPhoGGA7oEu+Qj6xzO4AeyANpttYd/TMUTOP8xazdad173ODkcYMBAus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015606; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i05ULFbw66+cnut3ZhVJxSLNIOEckOUgveo/uLuVGKE=; b=jpzt3c5y0wThZFlEmBioEEl4TQ06gPuYV1A3YW3yv7ODijmjMIqEtoT8BAdJBNiA/Udn0oVlwCFvVVQkyXbFwqKfR+sn05WBhpvjZnimjPuv7Sg3JWWAHydy4hQzyA5NQ1pj/zfQjZQe1xoqsl8611YWCJiWrqXgO+vW6bF3WVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015606481161.46064156544105; Sun, 22 Dec 2019 03:53:26 -0800 (PST) Received: from localhost ([::1]:46892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiznZ-0001zt-D6 for importer@patchew.org; Sun, 22 Dec 2019 06:53:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43692) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ8-0003Ls-Vm for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006o0-Me for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:30 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34967) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Un-9Q; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dF-OV; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vs-K3; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=i05ULFbw66+cnut3ZhVJxSLNIOEckOUgveo/uLuVGKE=; b=dVnN2wMQWmCdO0Aok2hl/6IF2q27sfq7aRm48rqtg6Cjp1jmEcg2MSX+3aX2gPpJidbfbRI3XOq2sVa+hRWCY/qVGavottWpy9x9y3djcsnYcUnFa4/H1hJ/kBnHevLy6QY4X0bVneYnP9w7qHXaBiFdzcTBtVsH16aJrvBk6ZjsYB5Yidkaslb8axlXFl8bvFwU5xer4U9sS3s1dbtgasb70Pohl8qjASJnOB58zbw1pVntvIROUjCMJczOgQV9Wz+WV4Tmqnzjbn6R1gM8rETJQRUkmRTyYYP2ib+BZ7gRpNbCzFo6/yqHd6llIgKmYlxUzMqmGocQgomQ+js23Q==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 13/27] qcow2: Handle QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC Date: Sun, 22 Dec 2019 12:36:54 +0100 Message-Id: <6b6c430112937f628d91fe085121c09d23dece24.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When dealing with subcluster types there is a new value called QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC that has no equivalent in QCow2ClusterType. This patch handles that value in all places where subcluster types are processed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 9277d680ef..1d3da0ccf6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1985,7 +1985,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, *pnum =3D bytes; =20 if ((type =3D=3D QCOW2_SUBCLUSTER_NORMAL || - type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) && !s->crypto) { + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || + type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC) && !s->crypto) { *map =3D cluster_offset | offset_into_cluster(s, offset); *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; @@ -1993,7 +1994,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN) { + } else if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2163,6 +2165,7 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDri= verState *bs, g_assert_not_reached(); =20 case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part = */ =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); @@ -2236,7 +2239,8 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, =20 if (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC || - (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g)) + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && !bs->backin= g) || + (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && !bs->backin= g)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { @@ -3750,6 +3754,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, return -ENOTSUP; } if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && + type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && type !=3D QCOW2_SUBCLUSTER_ZERO_ALLOC) { qemu_co_mutex_unlock(&s->lock); @@ -3822,6 +3827,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 switch (type) { case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); if (src_offset >=3D backing_length) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015465; cv=none; d=zohomail.com; s=zohoarc; b=Knx2h/imHZ+BaAZFJP4M9eQtPOlL3PA2qJS5nivVmj9J5EE74qXZDRsmFiNvsyQEJ1pKmqqAbcfxpt/nt77V4k3tI7NdB/BL25ckHPZ4t6pSNXP2OOcH+EQLmZRf1s0FVLjLK2Tz7uDA62Lrssm72BzY/g9IOYpVQozBpxLS3Zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015465; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MK6gAIIseage27+p2TUYo7rv6F6KMjsSarL7qVc5wk0=; b=XdGOjqM6OKa32NDaoA7SnYaiGOG3UN6m0MK1ox9LxeW80sVSno1EzfgTVfw79gDkxRfX37Aiz6nExzBVLElrCpbkAKeCA/nJkVL5NZASiGmFU070e+DXFxjFSZgHid+GUfkuqFeqPNWFkSq/pKjyjbWjwROYC927fQ98hKaoXl8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015465855718.3372129478346; Sun, 22 Dec 2019 03:51:05 -0800 (PST) Received: from localhost ([::1]:46842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizlI-0008Cn-BF for importer@patchew.org; Sun, 22 Dec 2019 06:51:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44327) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZE-0003Vo-Oe for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00074t-GK for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004nn-Hp; Sun, 22 Dec 2019 06:38:34 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dG-Ox; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vu-LG; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MK6gAIIseage27+p2TUYo7rv6F6KMjsSarL7qVc5wk0=; b=UEVpw+MRViUwmvRe0T+mgxCPvAbo4G8TZJk42Qt7ll7EQ9/pvuJO6wzoHjmUx+uvvP/FlZPqoUbTWPqFtJTyWr8MXykqQKFPt81I0lVzAdvTqtXyCccSTmWAb6HH9TYuiDbGtuXrYQQuw/F2U5tbIfXulGHzciooYqLYYhaaNKJmIlvilz/qxJ8opIVqxwqxnPa1DyNkMUdHUANq2mZw9fWSqJICHJNNlr/saAUy2COeWVc1eyPsL3ffrS55zkF9oHUAhk/q+AJbxLQ2gWA9O/pbo8pu5OfHWp8TbAdBtvah2xWLGr3TjARKZVbVe1WGEl77z/eBBU681sTnhCq50A==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 14/27] qcow2: Add subcluster support to calculate_l2_meta() Date: Sun, 22 Dec 2019 12:36:55 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If an image has subclusters then there are more copy-on-write scenarios that we need to consider. Let's say we have a write request from the middle of subcluster #3 until the end of the cluster: - If the cluster is new, then subclusters #0 to #3 from the old cluster must be copied into the new one. - If the cluster is new but the old cluster was unallocated, then only subcluster #3 needs copy-on-write. #0 to #2 are marked as unallocated in the bitmap of the new L2 entry. - If we are overwriting an old cluster and subcluster #3 is unallocated or has the all-zeroes bit set then we need copy-on-write on subcluster #3. - If we are overwriting an old cluster and subcluster #3 was allocated then there is no need to copy-on-write. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 140 +++++++++++++++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 30 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 40c2e34a2a..c6eb480ee8 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1041,56 +1041,128 @@ void qcow2_alloc_cluster_abort(BlockDriverState *b= s, QCowL2Meta *m) * If @keep_old is true it means that the clusters were already * allocated and will be overwritten. If false then the clusters are * new and we have to decrease the reference count of the old ones. + * + * Returns 1 on success, -errno on failure (in order to match the + * return value of handle_copied() and handle_alloc()). */ -static void calculate_l2_meta(BlockDriverState *bs, - uint64_t host_cluster_offset, - uint64_t guest_offset, unsigned bytes, - uint64_t *l2_slice, QCowL2Meta **m, bool kee= p_old) +static int calculate_l2_meta(BlockDriverState *bs, uint64_t host_cluster_o= ffset, + uint64_t guest_offset, unsigned bytes, + uint64_t *l2_slice, QCowL2Meta **m, bool keep= _old) { BDRVQcow2State *s =3D bs->opaque; - int l2_index =3D offset_to_l2_slice_index(s, guest_offset); - uint64_t l2_entry; + int sc_index, l2_index =3D offset_to_l2_slice_index(s, guest_offset); + uint64_t l2_entry, l2_bitmap; unsigned cow_start_from, cow_end_to; unsigned cow_start_to =3D offset_into_cluster(s, guest_offset); unsigned cow_end_from =3D cow_start_to + bytes; unsigned nb_clusters =3D size_to_clusters(s, cow_end_from); QCowL2Meta *old_m =3D *m; - QCow2ClusterType type; + QCow2SubclusterType type; =20 assert(nb_clusters <=3D s->l2_slice_size - l2_index); =20 - /* Return if there's no COW (all clusters are normal and we keep them)= */ + /* Return if there's no COW (all subclusters are normal and we are + * keeping the clusters) */ if (keep_old) { + unsigned first_sc =3D cow_start_to / s->subcluster_size; + unsigned last_sc =3D (cow_end_from - 1) / s->subcluster_size; int i; - for (i =3D 0; i < nb_clusters; i++) { - l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); - if (qcow2_get_cluster_type(bs, l2_entry) !=3D QCOW2_CLUSTER_NO= RMAL) { + for (i =3D first_sc; i <=3D last_sc; i++) { + unsigned c =3D i / s->subclusters_per_cluster; + unsigned sc =3D i % s->subclusters_per_cluster; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + c); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + c); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc= ); + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + l2_index +=3D c; /* Point to the invalid entry */ + goto fail; + } + if (type !=3D QCOW2_SUBCLUSTER_NORMAL) { break; } } - if (i =3D=3D nb_clusters) { - return; + if (i =3D=3D last_sc + 1) { + return 1; } } =20 /* Get the L2 entry from the first cluster */ l2_entry =3D get_l2_entry(s, l2_slice, l2_index); - type =3D qcow2_get_cluster_type(bs, l2_entry); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + sc_index =3D offset_to_sc_index(s, guest_offset); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); =20 - if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { - cow_start_from =3D cow_start_to; + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + goto fail; + } + + if (!keep_old) { + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_start_from =3D 0; + break; + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + cow_start_from =3D sc_index << s->subcluster_bits; + break; + default: + g_assert_not_reached(); + } } else { - cow_start_from =3D 0; + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + cow_start_from =3D cow_start_to; + break; + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_start_from =3D sc_index << s->subcluster_bits; + break; + default: + g_assert_not_reached(); + } } =20 /* Get the L2 entry from the last cluster */ - l2_entry =3D get_l2_entry(s, l2_slice, l2_index + nb_clusters - 1); - type =3D qcow2_get_cluster_type(bs, l2_entry); + l2_index +=3D nb_clusters - 1; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + sc_index =3D offset_to_sc_index(s, guest_offset + bytes - 1); + type =3D qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); =20 - if (type =3D=3D QCOW2_CLUSTER_NORMAL && keep_old) { - cow_end_to =3D cow_end_from; + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + goto fail; + } + + if (!keep_old) { + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + break; + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + cow_end_to =3D ROUND_UP(cow_end_from, s->subcluster_size); + break; + default: + g_assert_not_reached(); + } } else { - cow_end_to =3D ROUND_UP(cow_end_from, s->cluster_size); + switch (type) { + case QCOW2_SUBCLUSTER_NORMAL: + cow_end_to =3D cow_end_from; + break; + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + cow_end_to =3D ROUND_UP(cow_end_from, s->subcluster_size); + break; + default: + g_assert_not_reached(); + } } =20 *m =3D g_malloc0(sizeof(**m)); @@ -1115,6 +1187,18 @@ static void calculate_l2_meta(BlockDriverState *bs, =20 qemu_co_queue_init(&(*m)->dependent_requests); QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); + +fail: + if (type =3D=3D QCOW2_SUBCLUSTER_INVALID) { + uint64_t l1_index =3D offset_to_l1_index(s, guest_offset); + uint64_t l2_offset =3D s->l1_table[l1_index] & L1E_OFFSET_MASK; + qcow2_signal_corruption(bs, true, -1, -1, "Invalid cluster entry f= ound " + " (L2 offset: %#" PRIx64 ", L2 index: %#x)= ", + l2_offset, l2_index); + return -EIO; + } + + return 1; } =20 /* Returns true if writing to the cluster pointed to by @l2_entry @@ -1328,10 +1412,8 @@ static int handle_copied(BlockDriverState *bs, uint6= 4_t guest_offset, - offset_into_cluster(s, guest_offset)); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, guest_offs= et, - *bytes, l2_slice, m, true); - - ret =3D 1; + ret =3D calculate_l2_meta(bs, cluster_offset & L2E_OFFSET_MASK, + guest_offset, *bytes, l2_slice, m, true); } else { ret =3D 0; } @@ -1506,10 +1588,8 @@ static int handle_alloc(BlockDriverState *bs, uint64= _t guest_offset, *bytes =3D MIN(*bytes, nb_bytes - offset_into_cluster(s, guest_offset)= ); assert(*bytes !=3D 0); =20 - calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *bytes, l2_s= lice, - m, false); - - ret =3D 1; + ret =3D calculate_l2_meta(bs, alloc_cluster_offset, guest_offset, *byt= es, + l2_slice, m, false); =20 out: qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015960; cv=none; d=zohomail.com; s=zohoarc; b=GrvKZ379/k6yTowdA40HLAPS3FFzV9k5dWdsDRZeJXbjQpn7zFO2/KSwaPcT6UiF8j9zAHEvUl6KcjLK9iEUINYo6fVJiBhEtCTecCdO7jgO+9lq0QRqU4yM2LFz+hem0UgL0Ac+vyrZOa5NBLHpjjGVWyFR1DMrl1lc6H5cwq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015960; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9iMosx7u4f6rdZZvmG+CDPsOCgSu+D4AascyNAkVXR8=; b=MLVDAyqNJauSHqobUktuwpEkb3qn6wWC7aHywcXp/Fmzk4YhdwWs2FIJY0n94ll2yATUKqQC3b6HWqea9kboxonmaCblfJFw25Uvo0h4MHFynH4aF/d3o7y9sDfCExyH7gAo3CfNNeY1m33bNygkdWtXnkAWGvQTTyrV34IRGy8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015960752794.0663850774681; Sun, 22 Dec 2019 03:59:20 -0800 (PST) Received: from localhost ([::1]:47014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiztH-0008N0-MR for importer@patchew.org; Sun, 22 Dec 2019 06:59:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43842) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZA-0003Nn-81 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006od-V6 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:31 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004V2-9M; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dH-SN; Sun, 22 Dec 2019 12:37:53 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vw-MG; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=9iMosx7u4f6rdZZvmG+CDPsOCgSu+D4AascyNAkVXR8=; b=PCO91fBulDti5ftVodihVg7DWKeHtTbQvkE1W6jFmcrX1NLJsTdIhwqP+CPCdGSDtMgpRyoVrFMBfjArnhC6NffV4PptLkMN+H0onpijscPKsTVS1pIPQvGvZU5gG71+hCwCebLNYP6kNtlDQD7EeWAmB889WUb3GaCZ0QN5WDnN2Kt+HdUiJmyiNQ0NM8yq3xaUlL1rWxsbpva7fMr4o7cl1hbYL3fziuuVhdu5KXbWFuI81WNQmzEuFnO4LCOMIXO75M6bgjZTFNBzBrduHY4ZeP9mUMR4lt8BkAGhlPiixO3hA5e6nODoS7P8qHtqs07sDBNv//p59dTedXSGhA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 15/27] qcow2: Add subcluster support to qcow2_get_cluster_offset() Date: Sun, 22 Dec 2019 12:36:56 +0100 Message-Id: <020909580d10ee5b9681961b52b8372ee892d35d.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The logic of this function remains pretty much the same, except that it uses count_contiguous_subclusters(), which combines the logic of count_contiguous_clusters() / count_contiguous_clusters_unallocated() and checks individual subclusters. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 136 ++++++++++++++++++++---------------------- block/qcow2.h | 36 +++++------ 2 files changed, 80 insertions(+), 92 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c6eb480ee8..c10601a828 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -372,66 +372,55 @@ fail: } =20 /* - * Checks how many clusters in a given L2 slice are contiguous in the image - * file. As soon as one of the flags in the bitmask stop_flags changes com= pared - * to the first cluster, the search is stopped and the cluster is not coun= ted - * as contiguous. (This allows it, for example, to stop at the first compr= essed - * cluster which may require a different handling) + * Return the number of contiguous subclusters of the exact same type + * in a given L2 slice, starting from cluster @l2_index, subcluster + * @sc_index. Allocated subclusters are required to be contiguous in + * the image file. + * At most @nb_clusters are checked (note that this means clusters, + * not subclusters). */ -static int count_contiguous_clusters(BlockDriverState *bs, int nb_clusters, - int cluster_size, uint64_t *l2_slice, int l2_index, uint64_t stop_= flags) +static int count_contiguous_subclusters(BlockDriverState *bs, int nb_clust= ers, + unsigned sc_index, uint64_t *l2_sl= ice, + int l2_index) { BDRVQcow2State *s =3D bs->opaque; - int i; - QCow2ClusterType first_cluster_type; - uint64_t mask =3D stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; - uint64_t first_entry =3D get_l2_entry(s, l2_slice, l2_index); - uint64_t offset =3D first_entry & mask; - - first_cluster_type =3D qcow2_get_cluster_type(bs, first_entry); - if (first_cluster_type =3D=3D QCOW2_CLUSTER_UNALLOCATED) { - return 0; + int i, j, count =3D 0; + uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index); + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); + uint64_t expected_offset =3D l2_entry & L2E_OFFSET_MASK; + bool check_offset =3D true; + QCow2SubclusterType type =3D + qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, sc_index); + + assert(type !=3D QCOW2_SUBCLUSTER_INVALID); /* The caller should check= this */ + + if (type =3D=3D QCOW2_SUBCLUSTER_COMPRESSED) { + /* Compressed clusters are always processed one by one */ + return s->subclusters_per_cluster - sc_index; } =20 - /* must be allocated */ - assert(first_cluster_type =3D=3D QCOW2_CLUSTER_NORMAL || - first_cluster_type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC); - - for (i =3D 0; i < nb_clusters; i++) { - uint64_t l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i) & ma= sk; - if (offset + (uint64_t) i * cluster_size !=3D l2_entry) { - break; - } + if (type =3D=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN) { + check_offset =3D false; } =20 - return i; -} - -/* - * Checks how many consecutive unallocated clusters in a given L2 - * slice have the same cluster type. - */ -static int count_contiguous_clusters_unallocated(BlockDriverState *bs, - int nb_clusters, - uint64_t *l2_slice, - int l2_index, - QCow2ClusterType wanted_t= ype) -{ - BDRVQcow2State *s =3D bs->opaque; - int i; - - assert(wanted_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - wanted_type =3D=3D QCOW2_CLUSTER_UNALLOCATED); for (i =3D 0; i < nb_clusters; i++) { - uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); - QCow2ClusterType type =3D qcow2_get_cluster_type(bs, entry); - - if (type !=3D wanted_type) { - break; + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + i); + if (check_offset && expected_offset !=3D (l2_entry & L2E_OFFSET_MA= SK)) { + goto out; + } + for (j =3D (i =3D=3D 0) ? sc_index : 0; j < s->subclusters_per_clu= ster; j++) { + if (qcow2_get_subcluster_type(bs, l2_entry, l2_bitmap, j) !=3D= type) { + goto out; + } + count++; } + expected_offset +=3D s->cluster_size; } =20 - return i; +out: + return count; } =20 static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, @@ -515,12 +504,12 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, QCow2SubclusterType *subcluster_type) { BDRVQcow2State *s =3D bs->opaque; - unsigned int l2_index; - uint64_t l1_index, l2_offset, *l2_slice; - int c; + unsigned int l2_index, sc_index; + uint64_t l1_index, l2_offset, *l2_slice, l2_bitmap; + int sc; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; - QCow2ClusterType type; + QCow2SubclusterType type; int ret; =20 offset_in_cluster =3D offset_into_cluster(s, offset); @@ -570,7 +559,9 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, /* find the cluster offset for the given disk offset */ =20 l2_index =3D offset_to_l2_slice_index(s, offset); + sc_index =3D offset_to_sc_index(s, offset); *cluster_offset =3D get_l2_entry(s, l2_slice, l2_index); + l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -578,9 +569,9 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, * true */ assert(nb_clusters <=3D INT_MAX); =20 - type =3D qcow2_get_cluster_type(bs, *cluster_offset); - if (s->qcow_version < 3 && (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC)) { + type =3D qcow2_get_subcluster_type(bs, *cluster_offset, l2_bitmap, sc_= index); + if (s->qcow_version < 3 && (type =3D=3D QCOW2_SUBCLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_SUBCLUSTER_ZERO_ALLOC)) { qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry foun= d" " in pre-v3 image (L2 offset: %#" PRIx64 ", L2 index: %#x)", l2_offset, l2_index); @@ -588,7 +579,13 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uin= t64_t offset, goto fail; } switch (type) { - case QCOW2_CLUSTER_COMPRESSED: + case QCOW2_SUBCLUSTER_INVALID: + qcow2_signal_corruption(bs, true, -1, -1, "Invalid cluster entry f= ound " + " (L2 offset: %#" PRIx64 ", L2 index: %#x)= ", + l2_offset, l2_index); + ret =3D -EIO; + goto fail; + case QCOW2_SUBCLUSTER_COMPRESSED: if (has_data_file(bs)) { qcow2_signal_corruption(bs, true, -1, -1, "Compressed cluster " "entry found in image with external da= ta " @@ -598,21 +595,20 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, goto fail; } /* Compressed clusters can only be processed one by one */ - c =3D 1; + sc =3D s->subclusters_per_cluster - sc_index; *cluster_offset &=3D L2E_COMPRESSED_OFFSET_SIZE_MASK; break; - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_UNALLOCATED: - /* how many empty clusters ? */ - c =3D count_contiguous_clusters_unallocated(bs, nb_clusters, - l2_slice, l2_index, type= ); + case QCOW2_SUBCLUSTER_ZERO_PLAIN: + case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: + sc =3D count_contiguous_subclusters(bs, nb_clusters, sc_index, + l2_slice, l2_index); *cluster_offset =3D 0; break; - case QCOW2_CLUSTER_ZERO_ALLOC: - case QCOW2_CLUSTER_NORMAL: - /* how many allocated clusters ? */ - c =3D count_contiguous_clusters(bs, nb_clusters, s->cluster_size, - l2_slice, l2_index, QCOW_OFLAG_ZERO); + case QCOW2_SUBCLUSTER_ZERO_ALLOC: + case QCOW2_SUBCLUSTER_NORMAL: + case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: + sc =3D count_contiguous_subclusters(bs, nb_clusters, sc_index, + l2_slice, l2_index); *cluster_offset &=3D L2E_OFFSET_MASK; if (offset_into_cluster(s, *cluster_offset)) { qcow2_signal_corruption(bs, true, -1, -1, @@ -641,7 +637,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, =20 qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 - bytes_available =3D (int64_t)c * s->cluster_size; + bytes_available =3D ((int64_t)sc + sc_index) << s->subcluster_bits; =20 out: if (bytes_available > bytes_needed) { @@ -654,7 +650,7 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - *subcluster_type =3D qcow2_cluster_to_subcluster_type(type); + *subcluster_type =3D type; =20 return 0; =20 diff --git a/block/qcow2.h b/block/qcow2.h index 37b7e25989..ae7973a2c2 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -651,27 +651,6 @@ static inline QCow2ClusterType qcow2_get_cluster_type(= BlockDriverState *bs, } } =20 -/* For an image without extended L2 entries, return the - * QCow2SubclusterType equivalent of a given QCow2ClusterType */ -static inline -QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type) -{ - switch (type) { - case QCOW2_CLUSTER_COMPRESSED: - return QCOW2_SUBCLUSTER_COMPRESSED; - case QCOW2_CLUSTER_ZERO_PLAIN: - return QCOW2_SUBCLUSTER_ZERO_PLAIN; - case QCOW2_CLUSTER_ZERO_ALLOC: - return QCOW2_SUBCLUSTER_ZERO_ALLOC; - case QCOW2_CLUSTER_NORMAL: - return QCOW2_SUBCLUSTER_NORMAL; - case QCOW2_CLUSTER_UNALLOCATED: - return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; - default: - g_assert_not_reached(); - } -} - /* In an image without subsclusters @l2_bitmap is ignored and * @sc_index must be 0. */ static inline @@ -720,7 +699,20 @@ QCow2SubclusterType qcow2_get_subcluster_type(BlockDri= verState *bs, g_assert_not_reached(); } } else { - return qcow2_cluster_to_subcluster_type(type); + switch (type) { + case QCOW2_CLUSTER_COMPRESSED: + return QCOW2_SUBCLUSTER_COMPRESSED; + case QCOW2_CLUSTER_ZERO_PLAIN: + return QCOW2_SUBCLUSTER_ZERO_PLAIN; + case QCOW2_CLUSTER_ZERO_ALLOC: + return QCOW2_SUBCLUSTER_ZERO_ALLOC; + case QCOW2_CLUSTER_NORMAL: + return QCOW2_SUBCLUSTER_NORMAL; + case QCOW2_CLUSTER_UNALLOCATED: + return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; + default: + g_assert_not_reached(); + } } } =20 --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014798; cv=none; d=zohomail.com; s=zohoarc; b=A7yuYJzLiTh6PK0Y9l5RRGdCdjs/C80arTjjdMcCAUrNHkt0RVAb0bWvCm/Mwk7N+UcxEk83r/svPMPwyuL3ddu8OW1vrXAxb1749tp7TrGbn6dTMI/TOhdZ5+70NnfL2kKjzbtxGe1B0LEbKMuJhl5DD5RqCK6hi4Z57hqXAgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014798; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3YI9V2tDlLRPz3CdTbTokSYxL9dcWurq4MZPIj1h9PU=; b=HgwC9avsRYhyU9miq6LctKoExRHGa47C788EZr74EDbR3Qi8XPOCFL0mDn6PQ65V/yAD60HeXaG9WSyJlbfJDeYbJQgF0zJmnhSk2jNgDZsS3MyD8wWjgToZGGj5h1Ri4fn1uLwPU2nvPLov737anqbnKz/b3DuoUs2VU4alZUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014797405847.379754963897; Sun, 22 Dec 2019 03:39:57 -0800 (PST) Received: from localhost ([::1]:46594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizaV-0004gz-5q for importer@patchew.org; Sun, 22 Dec 2019 06:39:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41461) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nt-22 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005as-Py for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:10 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34961) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Uh-0l; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dI-Sk; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001Vy-NS; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=3YI9V2tDlLRPz3CdTbTokSYxL9dcWurq4MZPIj1h9PU=; b=a0nK9UqkTJEEolEtXiguVNDxZOEij7ax0tGwF7S3aj2fVvjc1QJ1Q/gVr25d/MdH8FgygvfBAFudPr9Kk8pZQvlnk4sdj9p2dKdnf7tHVNiClubhgCDN5e6lrCrKacJ3qxXEwTb8DVNVjfH7UKM9MCwodK4E6jJV5kkMTZCD2zJ0oyC+LrEkF8rr2Gvzk/qgmRyipoSUY9FCZ5W+fkyrboik3qaRr5Bq9adoNyzXBchlD5e4epwBd4u/VWQU4bfdKC+v9Z/EwTjsm7Y2NXn4SbZmZ8MxHpTeOU7aQ+axBn+1l8KSorMfjAdD6A0V/71TYOphQeibkn10lQ1EVesvmA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 16/27] qcow2: Add subcluster support to zero_in_l2_slice() Date: Sun, 22 Dec 2019 12:36:57 +0100 Message-Id: <4ab32f6dfcfeb5a22e119b03e223ea198988538e.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has subclusters. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c10601a828..70b0aaa00a 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1870,7 +1870,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uin= t64_t offset, assert(nb_clusters <=3D INT_MAX); =20 for (i =3D 0; i < nb_clusters; i++) { - uint64_t old_offset; + uint64_t old_offset, l2_entry =3D 0; QCow2ClusterType cluster_type; =20 old_offset =3D get_l2_entry(s, l2_slice, l2_index + i); @@ -1887,12 +1887,18 @@ static int zero_in_l2_slice(BlockDriverState *bs, u= int64_t offset, =20 qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); if (cluster_type =3D=3D QCOW2_CLUSTER_COMPRESSED || unmap) { - set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUE= ST); } else { - uint64_t entry =3D get_l2_entry(s, l2_slice, l2_index + i); - set_l2_entry(s, l2_slice, l2_index + i, entry | QCOW_OFLAG_ZER= O); + l2_entry =3D get_l2_entry(s, l2_slice, l2_index + i); } + + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, l2_index + i, QCOW_L2_BITMAP_ALL_ZE= ROES); + } else { + l2_entry |=3D QCOW_OFLAG_ZERO; + } + + set_l2_entry(s, l2_slice, l2_index + i, l2_entry); } =20 qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015375; cv=none; d=zohomail.com; s=zohoarc; b=Di0tfII2ED851MQzqoi38pImR9CJr5wU7j1ppebGbHronoi65fmqoUSW6gHPcW8aQGhNnjQWcXAaZXN95ksilTrnlZGowcKAIkcbXZ8iSIrHkfAWbFNbF5e3oWg1zCg5KQXqzvBT1qfc6RXwXz22IDlZjXWuPzDmNJJl/pZFbXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015375; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1HJa94babNCY+tS0ic1Tyr09nP5Ql5uC87OGgfrBtTg=; b=LkuVT6Q5bwL0uEDWCZYL/3MxkUCPumPwHtPVIK/tCG6StAn+/gyIBpRk2gzyc89W3GLM0VxUA7qLZO5g4iSnXzvnelxawA+WnQIRjkDm0X+J/nauFs+Jua3OlX6zfACzC/D4sxP+hjq8VbIgiQFlmKhmsSBIiif2xwR52AF+R+s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015375337386.37247774265984; Sun, 22 Dec 2019 03:49:35 -0800 (PST) Received: from localhost ([::1]:46828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizjq-0006uH-AC for importer@patchew.org; Sun, 22 Dec 2019 06:49:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41524) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nz-HD for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYo-0005cp-8I for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34980) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Up-Db; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dJ-SX; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001W0-OU; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=1HJa94babNCY+tS0ic1Tyr09nP5Ql5uC87OGgfrBtTg=; b=jWvVW+tMqs6gvQhMvGhtbeXe1MullaeJSVOxjMbrKzbOUkQDH4HR31NTw29P7+rxtp0efcJAaZ9/lt+NflvsZBJsOxEDubhQSnvHmu6aA7gwJHif8e3fxr/rkHJotIPMPmcRkPiEGwy5iXDMZVIXfHs20tQtoTB+AVDE2wq91dizFymGAvZIH/EzfCwRc9KNfFlOGRfWzwDCYovVP+zFmlJn7WDMHdul//5JNALtr6ypLPHOXvio43VX6I1o57flA+i3Zi+CUFohGeJqZ42+c7l0BluT2KYnVHb5iYZFfZBGLYVBpAcv0v3I/KyrxM4CgTPej4WfO9iMUhqg46JtzQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 17/27] qcow2: Add subcluster support to discard_in_l2_slice() Date: Sun, 22 Dec 2019 12:36:58 +0100 Message-Id: <69a823b113145f6b2187ed6cfd4291e55c92c5f6.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has subclusters. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 70b0aaa00a..207f670c94 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1790,7 +1790,11 @@ static int discard_in_l2_slice(BlockDriverState *bs,= uint64_t offset, =20 /* First remove L2 entries */ qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); - if (!full_discard && s->qcow_version >=3D 3) { + if (has_subclusters(s)) { + set_l2_entry(s, l2_slice, l2_index + i, 0); + set_l2_bitmap(s, l2_slice, l2_index + i, + full_discard ? 0 : QCOW_L2_BITMAP_ALL_ZEROES); + } else if (!full_discard && s->qcow_version >=3D 3) { set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO); } else { set_l2_entry(s, l2_slice, l2_index + i, 0); --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015570; cv=none; d=zohomail.com; s=zohoarc; b=f+FpZiaYnfocZTb8kifWM9S/AFyhBwHETt07mkPYSibvlId2BXyDejOFcCy8bbm0efZfeAx8VLbP1V4s8Gfrr8pdcuJmuj8lF0jozJmbA8XBOeipT1XO5rCp1WRPisruzhWgwSkd1HhFr4QO1RkomY9T5FQgSN6IN9bRhyBism0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015570; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vrl3GLQfcFIv5bcPqB/dgOQOJJKXmkDxlI4dGSew4sk=; b=gfYcU5IhjYAV3L6izseDkEMbQiAWfVgt75inzrs7a138SoOorLG0B+wUGXt/OKbu2wBRN0qtZVAr9RaJ7pSiR5v3cNknV85LF3fkfBlwO8atr4kCDOcmGKyZie7HBD4kMCfX5ABFSv8BJLsXlDSk/zj/goFKLHiPK9rcIbPOcZ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015570246700.4835473576562; Sun, 22 Dec 2019 03:52:50 -0800 (PST) Received: from localhost ([::1]:46880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizmz-0001HC-2D for importer@patchew.org; Sun, 22 Dec 2019 06:52:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41504) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nv-Dh for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYn-0005cC-Vr for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004Uw-Dg; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dK-Ub; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001W2-PP; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Vrl3GLQfcFIv5bcPqB/dgOQOJJKXmkDxlI4dGSew4sk=; b=WFQdP98koBD8QUEBF/zd6IXqKqDA0kQe7zq29Mew7zyA7dKSDJrf9sKLU7hsBlBoV2cSjkGKKP5SkqvPkp73VshzcFXUg6hHUOwY0QzzCs9ti9Cx5JFc4pvmJULQwbZt59ai9qTIUFmfbUvNgkLlAgqPwNO2UpFLuIjssescEKzor4y8HHWTBZmucQkCkT5k075wZAt7+ZXkh3V3N4vZZD6gfgglDf62ISnb8c7HmUvGZpu3LXYa5FjrKgUXN+V7xHaF8mflg5Fe/q+aU40qt747IbCfnfuNJaG/1CYVzBXYynbn85yRIEskl6Z38szD1B6jj+/dfWmGyH5PJuB/eQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 18/27] qcow2: Add subcluster support to check_refcounts_l2() Date: Sun, 22 Dec 2019 12:36:59 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Setting the QCOW_OFLAG_ZERO bit of the L2 entry is forbidden if an image has subclusters. Instead, the individual 'all zeroes' bits must be used. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index de85ed29a4..65f4fc27c3 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1685,8 +1685,13 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, int ign =3D active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2; =20 - l2_entry =3D QCOW_OFLAG_ZERO; - set_l2_entry(s, l2_table, i, l2_entry); + if (has_subclusters(s)) { + set_l2_entry(s, l2_table, i, 0); + set_l2_bitmap(s, l2_table, i, + QCOW_L2_BITMAP_ALL_ZEROES); + } else { + set_l2_entry(s, l2_table, i, QCOW_OFLAG_ZERO); + } ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s), false); if (ret < 0) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015786; cv=none; d=zohomail.com; s=zohoarc; b=ZGxT7yPBGNc/KrkmbVsf71hwN0aMFhVz0/9jeQe9ex2oeEV5ohKloTJ4yV/pSMAcBbJBG00CwstoaOYQnXtGYIr7JCljSyQqecMwEin6QF/64/2pw4Lc7LxAXWWYl7auyRTpicy5k/Ty8vxJWp5DCFLpoH5qFGgMR3LR9YG64ZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015786; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AkPLgWeXD8Sp8Vv4WDnQhlr8ICgxnf9zj64xPn9SawY=; b=dQiKCjlKwqmCWXwmehy7SBd7bVxRjzm8OBV04fGLsiHQCvLbGaIxCuzytRIkmxUQuncpe44shuApiv25i/7S6DQZZbdNfvNVt5hkqg4kzRY6ecNj933WZRZLTBleLX0Uqb2Ng9OVgyxMiGEKTF2XVrq9al2ZUS/j4JbQ2MJ7VYo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157701578626598.87997597768253; Sun, 22 Dec 2019 03:56:26 -0800 (PST) Received: from localhost ([::1]:46946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizqT-0004iI-9V for importer@patchew.org; Sun, 22 Dec 2019 06:56:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ9-0003Lm-0J for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006o6-Mp for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:30 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004V1-A0; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dL-VE; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001W4-QE; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=AkPLgWeXD8Sp8Vv4WDnQhlr8ICgxnf9zj64xPn9SawY=; b=ozO1RPtFOyCCHRRi7ZUwrFjmlZZtZb5mDupZh0aPyv5ufp0csfCFDkoPHRnnfpXzXKNDuxctw6UTKMaD25gVv9uF50YmqjHg9tDooSUQpOYoXOLohrzjpWstJDDsL0ttLQVksdP4aFaIDuUyfLntG4GFDyMZ+hj2DgN0p0xSSMjRkhtC2Tqk6cKPmE4Nw3hpKVx39i5iB7Km7tnoT/HmEIyXIyjl6v6DoTDQZoab5Nn/wWX9bqoAEqeqti1UU54fgr/nNIJ2FN83GdA6YVbP4avnrV3X3lxlR9myVN5hwLELUaYKWEYCjSSY7i9K7iOny+8JN81zOoUrXgRLBFoTug==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 19/27] qcow2: Add subcluster support to expand_zero_clusters_in_l1() Date: Sun, 22 Dec 2019 12:37:00 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Two changes are needed in order to add subcluster support to this function: deallocated clusters must have their bitmaps cleared, and expanded clusters must have all the "subcluster allocated" bits set. Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 207f670c94..ede75138d2 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2054,6 +2054,9 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, /* not backed; therefore we can simply deallocate = the * cluster */ set_l2_entry(s, l2_slice, j, 0); + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, j, 0); + } l2_dirty =3D true; continue; } @@ -2120,6 +2123,9 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, } else { set_l2_entry(s, l2_slice, j, offset); } + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, j, QCOW_L2_BITMAP_ALL_ALLOC= ); + } l2_dirty =3D true; } =20 --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015185; cv=none; d=zohomail.com; s=zohoarc; b=fC30ItqxGggLPMf76RfSL0bgQLHHiHWbVxbmnkgxp+w18b2Kf2EWXVtqsDOWC+RDJurU3AJgp0ZIJ96IUgNT/Q8rnhSGIISyggSGGBohmYpVx4YUq3Y9Os0RUxxLo4A5rgCPG85QNwUEKpkNJE9Ayc8eKKhwNLb8SlznqDdU1GI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015185; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FfRwlFoUXwcSP1PUYtt1ApuHt/UcQFWHMXoKMvFasHA=; b=K/r4m8miwpz/X8X/sDHlsB9FBRO2ZuSzuBx8Smmlk3vFd5O0UUOtZxzvsIo7KWsKHVThgIYR8o+eMisPR/zpfnlZBa1j9Axj531+bL6/5o0+66ty2jdM8gIEQJpk5QnxHB2QP4o5m3CDbW1lGkOVFXNxk+AOb1QBV8UV6YtcwHI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015185592578.8296578784111; Sun, 22 Dec 2019 03:46:25 -0800 (PST) Received: from localhost ([::1]:46766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizgm-0004BU-5S for importer@patchew.org; Sun, 22 Dec 2019 06:46:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44203) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZD-0003UD-Si for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-000759-6c for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:35 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004nS-JD; Sun, 22 Dec 2019 06:38:33 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dM-01; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001W7-RE; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=FfRwlFoUXwcSP1PUYtt1ApuHt/UcQFWHMXoKMvFasHA=; b=Vd9T794WPeEoNkJP48CItIAD0AP/Shc/0+3bItdcHMbbG/LgbN+D4XYmOf1PFbxWnoyRpvu1mdacu992dQHJf2+Iq7u9bqK+EQnaKC23ANyd7HNgOxvP3D3mtW6OuJDTfPpaMf7mwG2gT3oMosIK3sy/mtQuojIV1dTFMp/0j3Kr5w99oc2kpg2IHidGHwGZcPtReQEvEuU74Uhe8tQvI5hWAZJUfy2hUxpl44UyclFOR61IhHqHPN7w1fbfOMX8R9RgdaHffBdvZcN8cxPHCdvWu56DdqVov0cJW+fiVJn/MuHeM20thlYYP3jmG9Vl3xGcs+2t6+pL8VfLl/1iXA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 20/27] qcow2: Fix offset calculation in handle_dependencies() Date: Sun, 22 Dec 2019 12:37:01 +0100 Message-Id: <655e0ce198903682430272f6cfecb08afee6667c.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" l2meta_cow_start() and l2meta_cow_end() are not necessarily cluster-aligned if the image has subclusters, so update the calculation of old_start and old_end to guarantee that no two requests try to write on the same cluster. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ede75138d2..0a40944667 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1279,8 +1279,8 @@ static int handle_dependencies(BlockDriverState *bs, = uint64_t guest_offset, =20 uint64_t start =3D guest_offset; uint64_t end =3D start + bytes; - uint64_t old_start =3D l2meta_cow_start(old_alloc); - uint64_t old_end =3D l2meta_cow_end(old_alloc); + uint64_t old_start =3D start_of_cluster(s, l2meta_cow_start(old_al= loc)); + uint64_t old_end =3D ROUND_UP(l2meta_cow_end(old_alloc), s->cluste= r_size); =20 if (end <=3D old_start || start >=3D old_end) { /* No intersection */ --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014975; cv=none; d=zohomail.com; s=zohoarc; b=d9s3fIOd6ozSWzknfet0+Z3rGl+5Nq6qKnTNAkGkQP3Kp2oBwjp8f3MYG+Znrra2n7qt+UZ7qTm2Ev5e7aDNYSnKs8Z057mPmtrHbb64/tSSTxu+xsOo3mK4O2WNUaHbsHMkypZeT9c2DFxqvqz6AWZeotmkzqmq1U+MEJaMeAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014975; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7yEjOZlUVJ7jHicAcELr1+Yiz+TxR8WDeHeO6wbNjdo=; b=biz1YGLvluf/RLOYFyG+6kmUJmDQWS28935Lb2i73xe8I5ZXsECD9Rx8nxB1BjwyuGkbXe4pvcamoI9qaCZ7ETujwIAJGQIiQ1zgI7zWwPJ5xFe+CGfP6/O6teM52woM8Z3AUw9JMVXjsMPWfcvTFDizIYl8p62aw97SIJniH90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014975728387.424811042775; Sun, 22 Dec 2019 03:42:55 -0800 (PST) Received: from localhost ([::1]:46672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizdO-00004w-NU for importer@patchew.org; Sun, 22 Dec 2019 06:42:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43676) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ8-0003La-SU for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006nn-K8 for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:30 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34965) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Uk-6K; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYU-0005dN-W8; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001W9-S6; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=7yEjOZlUVJ7jHicAcELr1+Yiz+TxR8WDeHeO6wbNjdo=; b=RqYFzZt3wyGDyp0iwR5FojAIGOn7SVGmqCQMuTEA8nJqMMLJSn2vNOhi/BRGumWeW0+zej3axuYRQYSdUu70V5ubGCUuQ7m4KRB9eWayLZNpdHyDwwwotWvfNgcb32yeHNRFKAAvx3Jc+O0iG28FylgcOUvfOy3JDHUgrGNybAgbGpiStOSnRhxaJciB1UDe5E4JRcATx3ikZP9i/+Ziay18NWvzgQhL28eLgKFaRksp1HjmWO2m2+5e3KJnsgqYZRjZb8gAjbZIGEY00boZ5LdGhpjXZEI012paytWWllu+Q4eEGNsixpZTOwXPV/WSZk247/Ia3x/XxK+ZPlI5nA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 21/27] qcow2: Update L2 bitmap in qcow2_alloc_cluster_link_l2() Date: Sun, 22 Dec 2019 12:37:02 +0100 Message-Id: <4e1c4c2994470119889e8f602b9c98f4d3457e8b.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The L2 bitmap needs to be updated after each write to indicate what new subclusters are now allocated. This needs to happen even if the cluster was already allocated and the L2 entry was otherwise valid. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 0a40944667..ed291a4042 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -986,6 +986,23 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, = QCowL2Meta *m) =20 set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_COPIED | (cluster_offset + (i << s->cluster_bits))); + + /* Update bitmap with the subclusters that were just written */ + if (has_subclusters(s)) { + unsigned written_from =3D m->cow_start.offset; + unsigned written_to =3D m->cow_end.offset + m->cow_end.nb_byte= s ?: + m->nb_clusters << s->cluster_bits; + uint64_t l2_bitmap =3D get_l2_bitmap(s, l2_slice, l2_index + i= ); + int sc; + for (sc =3D 0; sc < s->subclusters_per_cluster; sc++) { + int sc_off =3D i * s->cluster_size + sc * s->subcluster_si= ze; + if (sc_off >=3D written_from && sc_off < written_to) { + l2_bitmap |=3D QCOW_OFLAG_SUB_ALLOC(sc); + l2_bitmap &=3D ~QCOW_OFLAG_SUB_ZERO(sc); + } + } + set_l2_bitmap(s, l2_slice, l2_index + i, l2_bitmap); + } } =20 =20 --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015416; cv=none; d=zohomail.com; s=zohoarc; b=UuhERiRnyzqtF3GWEZK55kFhViK5ICD4v/XPosnIrQ/Sq5INCx0EYSOzvYxhyk3pXjXInIj9g+jHi81R3KHhbBL72uVNxtecvbjuFpjl2UdIFHCHGvugEW0/lZRF5FNgvspM/yzK+4xcK4o3QptFz5YBT6sEN6VC17vEq6htndA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015416; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8ovRW+9TPD4268Z3Rpebx38DdbkpGyk/zhXsYbm5FYM=; b=jqn957swfTxF1dw16UnLnneUMGP7VCtQVfiOnI1ahLqP5YqqwsFugkz4GPhEtC4v4T2ucMji1oaMtwdWTXVj8Xbxvex3e7LTAKdDIzvLjVkllsAlsVJo0f7+HbkeLnlkrjApIJG+OcQ9aqI7CsD8SIcG1n9XP/H9NrPg6W1DLJE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015416578737.0473140183063; Sun, 22 Dec 2019 03:50:16 -0800 (PST) Received: from localhost ([::1]:46834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizkV-0007bU-AD for importer@patchew.org; Sun, 22 Dec 2019 06:50:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43682) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZ8-0003Lj-UX for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ7-0006ng-KF for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:30 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Ur-8u; Sun, 22 Dec 2019 06:38:29 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dO-0L; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001WE-Sx; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=8ovRW+9TPD4268Z3Rpebx38DdbkpGyk/zhXsYbm5FYM=; b=c4pph57QMDwzk4sUF1xgi1WOw5cM9BvGF3klLFzCWHu+S3fw7JOwiOTaiz5+2OlN+Rz2oaRz1DNYlBaRs4Y0KumlHr0Zh2md7Peby1FwpDy8UUjP6zf6IqJhHNtSVMEQbcYimTwCqifEuCuxNSMWVc7oLdMHQO/rwQvoKdX7S44UulruorsP+vPBtgA+8uyjkf89vrtjxzPGATcHEYOrFmy5VtUVIUxeY5y3J2msTy846uokFZdZYmdmPMPikpwbSnWU239wE8aquH4Be76MvRKTBr8uiurZcZIOV7LPe8Rrar6m4kKnuG7ZgTFSlvnI3KWJwNWlxcqod7+snZLOQA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 22/27] qcow2: Clear the L2 bitmap when allocating a compressed cluster Date: Sun, 22 Dec 2019 12:37:03 +0100 Message-Id: <410dd2fcfc6d0a177e3aea669cbc8f665f0df20a.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Compressed clusters always have the bitmap part of the extended L2 entry set to 0. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ed291a4042..af0f01621c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -789,6 +789,9 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverSt= ate *bs, BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice); set_l2_entry(s, l2_slice, l2_index, cluster_offset); + if (has_subclusters(s)) { + set_l2_bitmap(s, l2_slice, l2_index, 0); + } qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 *host_offset =3D cluster_offset & s->cluster_offset_mask; --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015269; cv=none; d=zohomail.com; s=zohoarc; b=DGtccyySsCyX/CQNqC4cokqikg8KXfIUOQbIkzOJCh9MQk3ZYJDMKsD+TY+0seziszHqWlYo4FY9XciQ/TVAY4qIXwez2BxDQecgOlN38zJWR8l0bG1U1JJn9U/ovmcaEYpB9//U1sEt8WCbsShrgcqEhl4lEsCySYOivWcaXnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015269; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/cY/IXpXQHwL/+wBuvEvO5IwS2Zd6P6ebh+NCvUlByc=; b=nXhshn9iuU52K341QmeJj2I6lPeEHytW9XJn+ufRngg5Etd6Eu4GnL88FC2JbiFfK45fhYbZYyUAnmt+rKQYAhMIfvEtAwBBS264FK8GEVOUSHzpeN+6fM/H/f4lPNWSeo9Sjgwbb64i/zXXB39kgG8A5MDUEpOsuNKjsPgxDc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015269048360.29152171605733; Sun, 22 Dec 2019 03:47:49 -0800 (PST) Received: from localhost ([::1]:46770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizi7-000537-De for importer@patchew.org; Sun, 22 Dec 2019 06:47:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44178) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZD-0003U3-Pl for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZB-00073x-TJ for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:35 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35040) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004nX-IB; Sun, 22 Dec 2019 06:38:33 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dP-0q; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001WG-Tq; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/cY/IXpXQHwL/+wBuvEvO5IwS2Zd6P6ebh+NCvUlByc=; b=nInR2eav65cccb7txeHu+JY1E2y6se1NWXkiWJmi8+SkeNPe2SU0pKW3eFw0a9dOkE6bRaBwDZL6LyizczeiC6Fqi5304RpITHxR2SCcFH/a2rarKfTWi/nK5ugAzlDyPPyK6RKxpbQmwUcUwDh+kkl2KLUWZOuZBPw9aEmlI7azOVgl+ugSJZ8GPJg5l4dLlAMYm9nFe+5N/lz0i49wV3+gw7gwWxcLHyiuSYLB32kmhihxeyFG/mVX2syyB4qG/QHhsmjP4P0Hpil1vKBAX/lMxBuHGpQ1u0/+FEG0OPIIoutFnKbNrlpANv+WgCJZsiHMCOm3L69WCJBxVU18MQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 23/27] qcow2: Add subcluster support to handle_alloc_space() Date: Sun, 22 Dec 2019 12:37:04 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The bdrv_co_pwrite_zeroes() call here fills complete clusters with zeroes, but it can happen that some subclusters are not part of the write request or the copy-on-write. This patch makes sure that only the affected subclusters are overwritten. A potential improvement would be to also fill with zeroes the other subclusters if we can guarantee that we are not overwriting existing data. However this would waste more disk space, so we should first evaluate if it's really worth doing. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1d3da0ccf6..242001afa2 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2354,6 +2354,9 @@ static int handle_alloc_space(BlockDriverState *bs, Q= CowL2Meta *l2meta) =20 for (m =3D l2meta; m !=3D NULL; m =3D m->next) { int ret; + uint64_t start_offset =3D m->alloc_offset + m->cow_start.offset; + unsigned nb_bytes =3D m->cow_end.offset + m->cow_end.nb_bytes - + m->cow_start.offset; =20 if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) { continue; @@ -2368,16 +2371,14 @@ static int handle_alloc_space(BlockDriverState *bs,= QCowL2Meta *l2meta) * efficiently zero out the whole clusters */ =20 - ret =3D qcow2_pre_write_overlap_check(bs, 0, m->alloc_offset, - m->nb_clusters * s->cluster_si= ze, + ret =3D qcow2_pre_write_overlap_check(bs, 0, start_offset, nb_byte= s, true); if (ret < 0) { return ret; } =20 BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE); - ret =3D bdrv_co_pwrite_zeroes(s->data_file, m->alloc_offset, - m->nb_clusters * s->cluster_size, + ret =3D bdrv_co_pwrite_zeroes(s->data_file, start_offset, nb_bytes, BDRV_REQ_NO_FALLBACK); if (ret < 0) { if (ret !=3D -ENOTSUP && ret !=3D -EAGAIN) { --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577014800; cv=none; d=zohomail.com; s=zohoarc; b=eTKB6mb9Aw7p15CnP7b1sEJ3f+QjMUUfQPVsVZnAy25CvWPn2nBBAqhNmsH9Ylv2hmU+vZmvSu9DLRJeW2XTK73ks19FvjbjwW8kpwQRLDRHSbDD2Kh0+ubmabnd987CRPCCd4JXG6PPoTC/OI6/AS5iXIf7qW0kyXuYOIyYQbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577014800; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ieXDi5ioqJCItbaztNvJyCyrJUb3lZG7EmUXCdrCtsM=; b=ANdyDSWLcBSB/5kYu1Uua8nIQx+zARaEzMsQfEtDVX0BaRvBUfXBxro0tx57T3AJ1eb+YEhzV4RSQgFm9Xju7MaNMMjYFFv4B1/FJlxiPVSmTzMCOQyJk9v8WNvBNAo4v7aELO8X66jd/+6subjJTmulQ3C/1dcbIrriTWRiONc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577014799061158.40545839559502; Sun, 22 Dec 2019 03:39:59 -0800 (PST) Received: from localhost ([::1]:46598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizaX-0004hU-UD for importer@patchew.org; Sun, 22 Dec 2019 06:39:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41507) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYp-0002nw-EN for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYo-0005c7-5y for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:11 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34983) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004V6-DZ; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dQ-25; Sun, 22 Dec 2019 12:37:51 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001WK-Ui; Sun, 22 Dec 2019 12:37:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ieXDi5ioqJCItbaztNvJyCyrJUb3lZG7EmUXCdrCtsM=; b=XYDaHwDagAxK83krAbTO2HObdLEydAnPk+UtYRJLLHBtKDCr3p1sFbN/ngqARcgQkyxlZiquEl1bSG42+37xxBpxHBHa2owHMW/EVlwnMW0Sb4sLnKFkD8/0pqemqKEVctVwiBw2CUCHdqAifH3uRmA1yGqp3dRWDbIKgDduBeSeEhJ0Qf/FuOGp4k17S6COJXlbRVmwAVHFw6Z4Kq/6SVlw7T2tI1UNHvuzuimzdVeluY69wru5rcvsxv2PWxIY7WZweoyYe7QTRlRK360xHCetzM7YSfM2VbZxGubzw02xVvk3TLrARZ1Ru5zsSadz9ydGqGzCTHHmWj4PpHhv5w==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 24/27] qcow2: Restrict qcow2_co_pwrite_zeroes() to full clusters only Date: Sun, 22 Dec 2019 12:37:05 +0100 Message-Id: <7a68ff6b42f3d0c7e5118099d17934e08a6bb49f.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Ideally it should be possible to zero individual subclusters using this function, but this is currently not implemented. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 242001afa2..0267722065 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3754,6 +3754,12 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Block= DriverState *bs, qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } + /* TODO: allow zeroing separate subclusters, we only allow + * zeroing full clusters at the moment. */ + if (nr !=3D bytes) { + qemu_co_mutex_unlock(&s->lock); + return -ENOTSUP; + } if (type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN && type !=3D QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC && type !=3D QCOW2_SUBCLUSTER_ZERO_PLAIN && --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016508; cv=none; d=zohomail.com; s=zohoarc; b=mwmRi1kqvH8/49uPZQwC4yoy69JVblw9GjDtwCOa7UwB42RyAyJcH5lo1GpFSc4xy75fK0eTbwIB46gTzmo8R4db7+mRUgek8qA9Tpzq2hf3yvGIRgqz+bUukksTxOQii2bQVhZIGiUnYAB4sEM5PgJ5Rra9nfEDPfISiTYN24Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016508; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cDS+6jbmN4KFm09m4go3p7uEI44mBbxqjpNLa+4Jqek=; b=n/so7mOjIjfADW8lwT72Srci23b601K9f+wJuNoUyMYUGP5iI28chD4zi5gueVwr8ChsGyd/8T0afuSLqJ/88K3I+b6S9Z0tNmBqKGCcNeqUt2ueU14c2LU77kczlTUDY9HzAMfJc20pSgxDMUfrkZ/1ajB5+kilazhRXByPAOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577016508965560.6367370970725; Sun, 22 Dec 2019 04:08:28 -0800 (PST) Received: from localhost ([::1]:47198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ij027-0008Em-VE for importer@patchew.org; Sun, 22 Dec 2019 07:08:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZI-0003cA-3i for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZ8-0006rF-HX for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:39 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34995) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZ7-0004Y6-Rm; Sun, 22 Dec 2019 06:38:30 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dR-2u; Sun, 22 Dec 2019 12:37:53 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXu-0001WN-WF; Sun, 22 Dec 2019 12:37:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cDS+6jbmN4KFm09m4go3p7uEI44mBbxqjpNLa+4Jqek=; b=dRQ2bp3RAKQbIla2jYtSgkrO0S9KWj/1yzoKuS2FRfaqWc4ly/rCDlv9D+LYYjBESclHneZ+3YoTYfjXKb5mE0rIN7YErHr/OnkFyRCaLLsvX90JW5vwZRmuXexANM0OMRNAps/7RE36/jNqHTrBRtUH1zx3rWPpXc4qmsuqHyho0B0YgQzYWk8bJt0sXvx4XnONOgdci3kYoVcrfeiOqoedXEyxkNiBvaHjZ20b98lRX3IxUt2ASYvMYlmZRvL8lZOez+K/4Mv5dxDMsqEBE9cOSE/B3DJkf/jqId99wW88HyIkh+XwL7Uaneh+7RmRWTE0QpLnoOgp6gtSy4mwLA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 25/27] qcow2: Add the 'extended_l2' option and the QCOW2_INCOMPAT_EXTL2 bit Date: Sun, 22 Dec 2019 12:37:06 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that the implementation of subclusters is complete we can finally add the necessary options to create and read images with this feature, which we call "extended L2 entries". Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 65 ++++++++++++++++++-- block/qcow2.h | 8 ++- include/block/block_int.h | 1 + qapi/block-core.json | 7 +++ tests/qemu-iotests/031.out | 8 +-- tests/qemu-iotests/036.out | 4 +- tests/qemu-iotests/049.out | 102 +++++++++++++++---------------- tests/qemu-iotests/060.out | 1 + tests/qemu-iotests/061.out | 20 +++--- tests/qemu-iotests/065 | 18 ++++-- tests/qemu-iotests/082.out | 48 ++++++++++++--- tests/qemu-iotests/085.out | 38 ++++++------ tests/qemu-iotests/144.out | 4 +- tests/qemu-iotests/182.out | 2 +- tests/qemu-iotests/185.out | 8 +-- tests/qemu-iotests/198.out | 2 + tests/qemu-iotests/206.out | 4 ++ tests/qemu-iotests/242.out | 5 ++ tests/qemu-iotests/255.out | 8 +-- tests/qemu-iotests/273.out | 9 ++- tests/qemu-iotests/common.filter | 1 + 21 files changed, 245 insertions(+), 118 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0267722065..4f26953b1e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1383,6 +1383,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, s->subcluster_size =3D s->cluster_size / s->subclusters_per_cluster; s->subcluster_bits =3D ctz32(s->subcluster_size); =20 + if (s->subcluster_size < (1 << MIN_CLUSTER_BITS)) { + error_setg(errp, "Unsupported subcluster size: %d", s->subcluster_= size); + ret =3D -EINVAL; + goto fail; + } + /* Check support for various header values */ if (header.refcount_order > 6) { error_setg(errp, "Reference count entry width too large; may not " @@ -2856,6 +2862,11 @@ int qcow2_update_header(BlockDriverState *bs) .bit =3D QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR, .name =3D "lazy refcounts", }, + { + .type =3D QCOW2_FEAT_TYPE_INCOMPATIBLE, + .bit =3D QCOW2_INCOMPAT_EXTL2_BITNR, + .name =3D "extended L2 entries", + }, }; =20 ret =3D header_ext_add(buf, QCOW2_EXT_MAGIC_FEATURE_TABLE, @@ -3184,7 +3195,8 @@ static int64_t qcow2_calc_prealloc_size(int64_t total= _size, return meta_size + aligned_total_size; } =20 -static bool validate_cluster_size(size_t cluster_size, Error **errp) +static bool validate_cluster_size(size_t cluster_size, bool extended_l2, + Error **errp) { int cluster_bits =3D ctz32(cluster_size); if (cluster_bits < MIN_CLUSTER_BITS || cluster_bits > MAX_CLUSTER_BITS= || @@ -3194,16 +3206,28 @@ static bool validate_cluster_size(size_t cluster_si= ze, Error **errp) "%dk", 1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - = 10)); return false; } + + if (extended_l2) { + unsigned min_cluster_size =3D + (1 << MIN_CLUSTER_BITS) * QCOW_MAX_SUBCLUSTERS_PER_CLUSTER; + if (cluster_size < min_cluster_size) { + error_setg(errp, "Extended L2 entries are only supported with " + "cluster sizes of at least %u bytes", min_cluster_s= ize); + return false; + } + } + return true; } =20 -static size_t qcow2_opt_get_cluster_size_del(QemuOpts *opts, Error **errp) +static size_t qcow2_opt_get_cluster_size_del(QemuOpts *opts, bool extended= _l2, + Error **errp) { size_t cluster_size; =20 cluster_size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, DEFAULT_CLUSTER_SIZE); - if (!validate_cluster_size(cluster_size, errp)) { + if (!validate_cluster_size(cluster_size, extended_l2, errp)) { return 0; } return cluster_size; @@ -3316,7 +3340,20 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) cluster_size =3D DEFAULT_CLUSTER_SIZE; } =20 - if (!validate_cluster_size(cluster_size, errp)) { + if (!qcow2_opts->has_extended_l2) { + qcow2_opts->extended_l2 =3D false; + } + if (qcow2_opts->extended_l2) { + if (version < 3) { + error_setg(errp, "Extended L2 entries are only supported with " + "compatibility level 1.1 and above (use version=3Dv= 3 or " + "greater)"); + ret =3D -EINVAL; + goto out; + } + } + + if (!validate_cluster_size(cluster_size, qcow2_opts->extended_l2, errp= )) { ret =3D -EINVAL; goto out; } @@ -3436,6 +3473,11 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) cpu_to_be64(QCOW2_AUTOCLEAR_DATA_FILE_RAW); } =20 + if (qcow2_opts->extended_l2) { + header->incompatible_features |=3D + cpu_to_be64(QCOW2_INCOMPAT_EXTL2); + } + ret =3D blk_pwrite(blk, 0, header, cluster_size, 0); g_free(header); if (ret < 0) { @@ -3614,6 +3656,7 @@ static int coroutine_fn qcow2_co_create_opts(const ch= ar *filename, QemuOpts *opt { BLOCK_OPT_BACKING_FMT, "backing-fmt" }, { BLOCK_OPT_CLUSTER_SIZE, "cluster-size" }, { BLOCK_OPT_LAZY_REFCOUNTS, "lazy-refcounts" }, + { BLOCK_OPT_EXTL2, "extended-l2" }, { BLOCK_OPT_REFCOUNT_BITS, "refcount-bits" }, { BLOCK_OPT_ENCRYPT, BLOCK_OPT_ENCRYPT_FORMAT }, { BLOCK_OPT_COMPAT_LEVEL, "version" }, @@ -4660,9 +4703,13 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opt= s, BlockDriverState *in_bs, PreallocMode prealloc; bool has_backing_file; bool has_luks; + bool extended_l2; =20 /* Parse image creation options */ - cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); + extended_l2 =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_EXTL2, false); + + cluster_size =3D qcow2_opt_get_cluster_size_del(opts, extended_l2, + &local_err); if (local_err) { goto err; } @@ -4838,6 +4885,8 @@ static ImageInfoSpecific *qcow2_get_specific_info(Blo= ckDriverState *bs, .corrupt =3D s->incompatible_features & QCOW2_INCOMPAT_CORRUPT, .has_corrupt =3D true, + .has_extended_l2 =3D true, + .extended_l2 =3D has_subclusters(s), .refcount_bits =3D s->refcount_bits, .has_bitmaps =3D !!bitmaps, .bitmaps =3D bitmaps, @@ -5496,6 +5545,12 @@ static QemuOptsList qcow2_create_opts =3D { .help =3D "Postpone refcount updates", .def_value_str =3D "off" }, + { + .name =3D BLOCK_OPT_EXTL2, + .type =3D QEMU_OPT_BOOL, + .help =3D "Extended L2 tables", + .def_value_str =3D "off" + }, { .name =3D BLOCK_OPT_REFCOUNT_BITS, .type =3D QEMU_OPT_NUMBER, diff --git a/block/qcow2.h b/block/qcow2.h index ae7973a2c2..e879d54b05 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -231,13 +231,16 @@ enum { QCOW2_INCOMPAT_DIRTY_BITNR =3D 0, QCOW2_INCOMPAT_CORRUPT_BITNR =3D 1, QCOW2_INCOMPAT_DATA_FILE_BITNR =3D 2, + QCOW2_INCOMPAT_EXTL2_BITNR =3D 3, QCOW2_INCOMPAT_DIRTY =3D 1 << QCOW2_INCOMPAT_DIRTY_BITNR, QCOW2_INCOMPAT_CORRUPT =3D 1 << QCOW2_INCOMPAT_CORRUPT_BITNR, QCOW2_INCOMPAT_DATA_FILE =3D 1 << QCOW2_INCOMPAT_DATA_FILE_BITN= R, + QCOW2_INCOMPAT_EXTL2 =3D 1 << QCOW2_INCOMPAT_EXTL2_BITNR, =20 QCOW2_INCOMPAT_MASK =3D QCOW2_INCOMPAT_DIRTY | QCOW2_INCOMPAT_CORRUPT - | QCOW2_INCOMPAT_DATA_FILE, + | QCOW2_INCOMPAT_DATA_FILE + | QCOW2_INCOMPAT_EXTL2, }; =20 /* Compatible feature bits */ @@ -525,8 +528,7 @@ typedef enum QCow2MetadataOverlap { =20 static inline bool has_subclusters(BDRVQcow2State *s) { - /* FIXME: Return false until this feature is complete */ - return false; + return s->incompatible_features & QCOW2_INCOMPAT_EXTL2; } =20 static inline size_t l2_entry_size(BDRVQcow2State *s) diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0b37..e8fbfa6dc8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -57,6 +57,7 @@ #define BLOCK_OPT_REFCOUNT_BITS "refcount_bits" #define BLOCK_OPT_DATA_FILE "data_file" #define BLOCK_OPT_DATA_FILE_RAW "data_file_raw" +#define BLOCK_OPT_EXTL2 "extended_l2" =20 #define BLOCK_PROBE_BUF_SIZE 512 =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index 0cf68fea14..e366eba2f2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -66,6 +66,9 @@ # standalone (read-only) raw image without looking at qcow2 # metadata (since: 4.0) # +# @extended-l2: true if the image has extended L2 entries; only valid for +# compat >=3D 1.1 (since 4.2) +# # @lazy-refcounts: on or off; only valid for compat >=3D 1.1 # # @corrupt: true if the image has been marked corrupt; only valid for @@ -85,6 +88,7 @@ 'compat': 'str', '*data-file': 'str', '*data-file-raw': 'bool', + '*extended-l2': 'bool', '*lazy-refcounts': 'bool', '*corrupt': 'bool', 'refcount-bits': 'int', @@ -4372,6 +4376,8 @@ # @data-file-raw True if the external data file must stay valid as a # standalone (read-only) raw image without looking at qc= ow2 # metadata (default: false; since: 4.0) +# @extended-l2 True to make the image have extended L2 entries +# (default: false; since 4.2) # @size Size of the virtual disk in bytes # @version Compatibility level (default: v3) # @backing-file File name of the backing file if a backing file @@ -4390,6 +4396,7 @@ 'data': { 'file': 'BlockdevRef', '*data-file': 'BlockdevRef', '*data-file-raw': 'bool', + '*extended-l2': 'bool', 'size': 'size', '*version': 'BlockdevQcow2Version', '*backing-file': 'str', diff --git a/tests/qemu-iotests/031.out b/tests/qemu-iotests/031.out index 68a74d03b9..614950be56 100644 --- a/tests/qemu-iotests/031.out +++ b/tests/qemu-iotests/031.out @@ -117,7 +117,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: @@ -150,7 +150,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: @@ -164,7 +164,7 @@ No errors were found on the image. =20 magic 0x514649fb version 3 -backing_file_offset 0x178 +backing_file_offset 0x1a8 backing_file_size 0x17 cluster_bits 16 size 67108864 @@ -188,7 +188,7 @@ data 'host_device' =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 Header extension: diff --git a/tests/qemu-iotests/036.out b/tests/qemu-iotests/036.out index e489b44386..c7e6512b43 100644 --- a/tests/qemu-iotests/036.out +++ b/tests/qemu-iotests/036.out @@ -58,7 +58,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 =20 @@ -86,7 +86,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 *** done diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index 6b505408dd..ba4b42fd58 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -4,90 +4,90 @@ QA output created by 049 =3D=3D 1. Traditional size parameter =3D=3D =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D 2. Specifying size via -o =3D=3D =20 qemu-img create -f qcow2 -o size=3D1024 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D 3. Invalid sizes =3D=3D =20 @@ -124,84 +124,84 @@ and exabytes, respectively. =3D=3D Check correct interpretation of suffixes for cluster size =3D=3D =20 qemu-img create -f qcow2 -o cluster_size=3D1024 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1048576 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1048576 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 524288 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 524288 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D Check compat level option =3D=3D =20 qemu-img create -f qcow2 -o compat=3D0.10 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3D1.1 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.42 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter '0.42' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3Dfoobar TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter 'foobar' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= cluster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits= =3D16 =20 =3D=3D Check preallocation option =3D=3D =20 qemu-img create -f qcow2 -o preallocation=3Doff TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Doff lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Doff lazy_refcounts=3Doff extended_l2=3Doff refcount_b= its=3D16 =20 qemu-img create -f qcow2 -o preallocation=3Dmetadata TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Dmetadata lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Dmetadata lazy_refcounts=3Doff extended_l2=3Doff refco= unt_bits=3D16 =20 qemu-img create -f qcow2 -o preallocation=3D1234 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid parameter '1234' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3D1234 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3D1234 lazy_refcounts=3Doff extended_l2=3Doff refcount_= bits=3D16 =20 =3D=3D Check encryption option =3D=3D =20 qemu-img create -f qcow2 -o encryption=3Doff TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits= =3D16 =20 qemu-img create -f qcow2 --object secret,id=3Dsec0,data=3D123456 -o encryp= tion=3Don,encrypt.key-secret=3Dsec0 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= encrypt.key-secret=3Dsec0 cluster_size=3D65536 lazy_refcounts=3Doff refcou= nt_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= encrypt.key-secret=3Dsec0 cluster_size=3D65536 lazy_refcounts=3Doff extend= ed_l2=3Doff refcount_bits=3D16 =20 =3D=3D Check lazy_refcounts option (only with v3) =3D=3D =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Doff TEST_DIR/t.q= cow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Don TEST_DIR/t.qc= ow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Doff TEST_DIR/t.= qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D= 16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Don TEST_DIR/t.q= cow2 64M qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibili= ty level 1.1 and above (use version=3Dv3 or greater) -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 =20 *** done diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 0f6b0658a1..1f6ae50027 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -20,6 +20,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: true + extended l2: false qemu-io: can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; ca= nnot be opened read/write no file open, try 'help open' read 512/512 bytes at offset 0 diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index d6a7c2af95..96a6933554 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -26,7 +26,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -84,7 +84,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -140,7 +140,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 ERROR cluster 5 refcount=3D0 reference=3D1 @@ -195,7 +195,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 magic 0x514649fb @@ -264,7 +264,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 read 65536/65536 bytes at offset 44040192 @@ -298,7 +298,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 ERROR cluster 5 refcount=3D0 reference=3D1 @@ -327,7 +327,7 @@ header_length 104 =20 Header extension: magic 0x6803f857 -length 192 +length 240 data =20 read 131072/131072 bytes at offset 0 @@ -496,6 +496,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. =20 =3D=3D=3D Try changing the external data file =3D=3D=3D @@ -516,6 +517,7 @@ Format specific information: data file: foo data file raw: false corrupt: false + extended l2: false =20 qemu-img: Could not open 'TEST_DIR/t.IMGFMT': 'data-file' is required for = this image image: TEST_DIR/t.IMGFMT @@ -528,6 +530,7 @@ Format specific information: refcount bits: 16 data file raw: false corrupt: false + extended l2: false =20 =3D=3D=3D Clearing and setting data-file-raw =3D=3D=3D =20 @@ -543,6 +546,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: true corrupt: false + extended l2: false No errors were found on the image. image: TEST_DIR/t.IMGFMT file format: IMGFMT @@ -555,6 +559,7 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. qemu-img: data-file-raw cannot be set on existing images image: TEST_DIR/t.IMGFMT @@ -568,5 +573,6 @@ Format specific information: data file: TEST_DIR/t.IMGFMT.data data file raw: false corrupt: false + extended l2: false No errors were found on the image. *** done diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065 index 5b21eb96bd..7d3a137434 100755 --- a/tests/qemu-iotests/065 +++ b/tests/qemu-iotests/065 @@ -95,17 +95,21 @@ class TestQCow3NotLazy(TestQemuImgInfo): '''Testing a qcow2 version 3 image with lazy refcounts disabled''' img_options =3D 'compat=3D1.1,lazy_refcounts=3Doff' json_compare =3D { 'compat': '1.1', 'lazy-refcounts': False, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } human_compare =3D [ 'compat: 1.1', 'lazy refcounts: false', - 'refcount bits: 16', 'corrupt: false' ] + 'refcount bits: 16', 'corrupt: false', + 'extended l2: false' ] =20 class TestQCow3Lazy(TestQemuImgInfo): '''Testing a qcow2 version 3 image with lazy refcounts enabled''' img_options =3D 'compat=3D1.1,lazy_refcounts=3Don' json_compare =3D { 'compat': '1.1', 'lazy-refcounts': True, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } human_compare =3D [ 'compat: 1.1', 'lazy refcounts: true', - 'refcount bits: 16', 'corrupt: false' ] + 'refcount bits: 16', 'corrupt: false', + 'extended l2: false' ] =20 class TestQCow3NotLazyQMP(TestQMP): '''Testing a qcow2 version 3 image with lazy refcounts disabled, openi= ng @@ -113,7 +117,8 @@ class TestQCow3NotLazyQMP(TestQMP): img_options =3D 'compat=3D1.1,lazy_refcounts=3Doff' qemu_options =3D 'lazy-refcounts=3Don' compare =3D { 'compat': '1.1', 'lazy-refcounts': False, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } =20 =20 class TestQCow3LazyQMP(TestQMP): @@ -122,7 +127,8 @@ class TestQCow3LazyQMP(TestQMP): img_options =3D 'compat=3D1.1,lazy_refcounts=3Don' qemu_options =3D 'lazy-refcounts=3Doff' compare =3D { 'compat': '1.1', 'lazy-refcounts': True, - 'refcount-bits': 16, 'corrupt': False } + 'refcount-bits': 16, 'corrupt': False, + 'extended-l2': False } =20 TestImageInfoSpecific =3D None TestQemuImgInfo =3D None diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 9d4ed4dc9d..2a01e8bac2 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -3,14 +3,14 @@ QA output created by 082 =3D=3D=3D create: Options specified more than once =3D=3D=3D =20 Testing: create -f foo -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) cluster_size: 65536 =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don TEST_= DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D4096 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D4096 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -20,9 +20,10 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don -o cl= uster_size=3D8k TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Don extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -32,9 +33,10 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: create -f qcow2 -o cluster_size=3D4k,cluster_size=3D8k TEST_DIR/t= .qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) @@ -59,6 +61,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -82,6 +85,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -105,6 +109,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -128,6 +133,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -151,6 +157,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -174,6 +181,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -197,6 +205,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -220,6 +229,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -227,10 +237,10 @@ Supported options: size=3D - Virtual disk size =20 Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_= DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff refcoun= t_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff extende= d_l2=3Doff refcount_bits=3D16 =20 Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR= /t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff refcount_b= its=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff extended_l= 2=3Doff refcount_bits=3D16 =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2, -o help TEST_= DIR/t.qcow2 128M qemu-img: Invalid option list: backing_file=3DTEST_DIR/t.qcow2, @@ -258,6 +268,7 @@ Supported qcow2 options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -279,7 +290,7 @@ qemu-img: Format driver 'bochs' does not support image = creation =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 Testing: create -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 Testing: convert -f foo -f qcow2 TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -302,6 +313,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: convert -O qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don -o c= luster_size=3D8k TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -313,6 +325,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: convert -O qcow2 -o cluster_size=3D4k,cluster_size=3D8k TEST_DIR/= t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -339,6 +352,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -362,6 +376,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -385,6 +400,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -408,6 +424,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -431,6 +448,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -454,6 +472,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -477,6 +496,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -500,6 +520,7 @@ Supported options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates nocow=3D - Turn off copy-on-write (valid only on btrfs) preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) @@ -538,6 +559,7 @@ Supported qcow2 options: encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -582,6 +604,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D130M -o lazy_refcounts=3Doff TEST_DIR/t.= qcow2 image: TEST_DIR/t.IMGFMT @@ -593,6 +616,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D8M -o lazy_refcounts=3Don -o size=3D132M= TEST_DIR/t.qcow2 image: TEST_DIR/t.IMGFMT @@ -604,6 +628,7 @@ Format specific information: lazy refcounts: true refcount bits: 16 corrupt: false + extended l2: false =20 Testing: amend -f qcow2 -o size=3D4M,size=3D148M TEST_DIR/t.qcow2 image: TEST_DIR/t.IMGFMT @@ -630,6 +655,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -654,6 +680,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -678,6 +705,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -702,6 +730,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -726,6 +755,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -750,6 +780,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -774,6 +805,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -798,6 +830,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits @@ -839,6 +872,7 @@ Creation options for 'qcow2': encrypt.ivgen-hash-alg=3D - Name of IV generator hash algorithm encrypt.key-secret=3D - ID of secret providing qcow AES key or LUKS= passphrase encryption=3D - Encrypt the image with format 'aes'. (Dep= recated in favor of encrypt.format=3Daes) + extended_l2=3D - Extended L2 tables lazy_refcounts=3D - Postpone refcount updates preallocation=3D - Preallocation mode (allowed values: off, meta= data, falloc, full) refcount_bits=3D - Width of a reference count entry in bits diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out index bb50227b82..8a41314690 100644 --- a/tests/qemu-iotests/085.out +++ b/tests/qemu-iotests/085.out @@ -13,7 +13,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D13421= 7728 =3D=3D=3D Create a single snapshot on virtio0 =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/1-snapshot-v0.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Invalid command - missing device and nodename =3D=3D=3D @@ -30,40 +30,40 @@ Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 = size=3D134217728 backing_file =3D=3D=3D Create several transactional group snapshots =3D=3D=3D =20 { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /2-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/2-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /3-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/3-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /4-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/4-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /5-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/5-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /6-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/6-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /7-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/7-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /8-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/8-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /9-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : { = 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/9-snapshot-v1.IMGFMT' } } ]= } } -Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'transaction', 'arguments': {'actions': [ { 'type': 'blockdev= -snapshot-sync', 'data' : { 'device': 'virtio0', 'snapshot-file': 'TEST_DIR= /10-snapshot-v0.IMGFMT' } }, { 'type': 'blockdev-snapshot-sync', 'data' : {= 'device': 'virtio1', 'snapshot-file': 'TEST_DIR/10-snapshot-v1.IMGFMT' } }= ] } } -Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Create a couple of snapshots using blockdev-snapshot =3D=3D=3D diff --git a/tests/qemu-iotests/144.out b/tests/qemu-iotests/144.out index c7aa2e4820..5d9aceaf13 100644 --- a/tests/qemu-iotests/144.out +++ b/tests/qemu-iotests/144.out @@ -9,7 +9,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D5368709= 12 { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/tmp.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcounts= =3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcounts= =3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Performing block-commit on active layer =3D=3D=3D @@ -31,6 +31,6 @@ Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D53687= 0912 backing_file=3DTEST_DIR/ =3D=3D=3D Performing Live Snapshot 2 =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'virtio0',= 'snapshot-file':'TEST_DIR/tmp2.IMGFMT', 'format': 'IMGFMT' } } -Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} *** done diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out index a8eea166c3..84dc7a2360 100644 --- a/tests/qemu-iotests/182.out +++ b/tests/qemu-iotests/182.out @@ -13,7 +13,7 @@ Is another process using the image [TEST_DIR/t.qcow2]? {'execute': 'blockdev-add', 'arguments': { 'node-name': 'node0', 'driver':= 'file', 'filename': 'TEST_DIR/t.IMGFMT', 'locking': 'on' } } {"return": {}} {'execute': 'blockdev-snapshot-sync', 'arguments': { 'node-name': 'node0',= 'snapshot-file': 'TEST_DIR/t.IMGFMT.overlay', 'snapshot-node-name': 'node1= ' } } -Formatting 'TEST_DIR/t.qcow2.overlay', fmt=3Dqcow2 size=3D197120 backing_f= ile=3DTEST_DIR/t.qcow2 backing_fmt=3Dfile cluster_size=3D65536 lazy_refcoun= ts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.overlay', fmt=3Dqcow2 size=3D197120 backing_f= ile=3DTEST_DIR/t.qcow2 backing_fmt=3Dfile cluster_size=3D65536 lazy_refcoun= ts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} {'execute': 'blockdev-add', 'arguments': { 'node-name': 'node1', 'driver':= 'file', 'filename': 'TEST_DIR/t.IMGFMT', 'locking': 'on' } } {"return": {}} diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out index 8379ac5854..46b4268b30 100644 --- a/tests/qemu-iotests/185.out +++ b/tests/qemu-iotests/185.out @@ -9,14 +9,14 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 =3D=3D=3D Creating backing chain =3D=3D=3D =20 { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'disk', 's= napshot-file': 'TEST_DIR/t.IMGFMT.mid', 'format': 'IMGFMT', 'mode': 'absolu= te-paths' } } -Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_ref= counts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_ref= counts=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} { 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'qemu= -io disk "write 0 4M"' } } wrote 4194304/4194304 bytes at offset 0 4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) {"return": ""} { 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'disk', 's= napshot-file': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'absolute-p= aths' } } -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff extended_l2=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Start commit job and exit qemu =3D=3D=3D @@ -48,7 +48,7 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D6710886= 4 backing_file=3DTEST_DIR/t.q { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'drive-mirror', 'arguments': { 'device': 'disk', 'target': 'T= EST_DIR/t.IMGFMT.copy', 'format': 'IMGFMT', 'sync': 'full', 'speed': 65536 = } } -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} {"return": {}} @@ -62,7 +62,7 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67= 108864 cluster_size=3D65536 l { 'execute': 'qmp_capabilities' } {"return": {}} { 'execute': 'drive-backup', 'arguments': { 'device': 'disk', 'target': 'T= EST_DIR/t.IMGFMT.copy', 'format': 'IMGFMT', 'sync': 'full', 'speed': 65536 = } } -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} {"return": {}} diff --git a/tests/qemu-iotests/198.out b/tests/qemu-iotests/198.out index e86b175e39..e46dccdb08 100644 --- a/tests/qemu-iotests/198.out +++ b/tests/qemu-iotests/198.out @@ -72,6 +72,7 @@ Format specific information: key offset: 1810432 payload offset: 2068480 master key iters: 1024 + extended l2: false =20 =3D=3D checking image layer =3D=3D image: json:{"encrypt.key-secret": "sec1", "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/t.IMGFMT"}} @@ -115,4 +116,5 @@ Format specific information: key offset: 1810432 payload offset: 2068480 master key iters: 1024 + extended l2: false *** done diff --git a/tests/qemu-iotests/206.out b/tests/qemu-iotests/206.out index 61e7241e0b..d2efc0394a 100644 --- a/tests/qemu-iotests/206.out +++ b/tests/qemu-iotests/206.out @@ -21,6 +21,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (inline blockdev-add, explicit default= s) =3D=3D=3D =20 @@ -43,6 +44,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (v3 non-default options) =3D=3D=3D =20 @@ -65,6 +67,7 @@ Format specific information: lazy refcounts: true refcount bits: 1 corrupt: false + extended l2: false =20 =3D=3D=3D Successful image creation (v2 non-default options) =3D=3D=3D =20 @@ -141,6 +144,7 @@ Format specific information: payload offset: 528384 master key iters: XXX corrupt: false + extended l2: false =20 =3D=3D=3D Invalid BlockdevRef =3D=3D=3D =20 diff --git a/tests/qemu-iotests/242.out b/tests/qemu-iotests/242.out index 7ac8404d11..0d32dd9148 100644 --- a/tests/qemu-iotests/242.out +++ b/tests/qemu-iotests/242.out @@ -15,6 +15,7 @@ Format specific information: lazy refcounts: false refcount bits: 16 corrupt: false + extended l2: false =20 No bitmap in JSON format output =20 @@ -40,6 +41,7 @@ Format specific information: granularity: 32768 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -77,6 +79,7 @@ Format specific information: granularity: 65536 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -119,6 +122,7 @@ Format specific information: granularity: 65536 refcount bits: 16 corrupt: false + extended l2: false =20 The same bitmaps in JSON format: [ @@ -162,5 +166,6 @@ Format specific information: granularity: 16384 refcount bits: 16 corrupt: false + extended l2: false =20 Test complete diff --git a/tests/qemu-iotests/255.out b/tests/qemu-iotests/255.out index 348909fdef..4e1b917a0f 100644 --- a/tests/qemu-iotests/255.out +++ b/tests/qemu-iotests/255.out @@ -3,9 +3,9 @@ Finishing a commit job with background reads =20 =3D=3D=3D Create backing chain and start VM =3D=3D=3D =20 -Formatting 'TEST_DIR/PID-t.qcow2.mid', fmt=3Dqcow2 size=3D134217728 cluste= r_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-t.qcow2.mid', fmt=3Dqcow2 size=3D134217728 cluste= r_size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 -Formatting 'TEST_DIR/PID-t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_si= ze=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 =3D=3D=3D Start background read requests =3D=3D=3D =20 @@ -23,9 +23,9 @@ Closing the VM while a job is being cancelled =20 =3D=3D=3D Create images and start VM =3D=3D=3D =20 -Formatting 'TEST_DIR/PID-src.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-src.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 -Formatting 'TEST_DIR/PID-dst.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/PID-dst.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_= size=3D65536 lazy_refcounts=3Doff extended_l2=3Doff refcount_bits=3D16 =20 wrote 1048576/1048576 bytes at offset 0 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) diff --git a/tests/qemu-iotests/273.out b/tests/qemu-iotests/273.out index c410fee5c4..b9ffe4dcd7 100644 --- a/tests/qemu-iotests/273.out +++ b/tests/qemu-iotests/273.out @@ -44,7 +44,8 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTEST_= DIR/t.IMGFMT.base -blockdev "compat": "1.1", "lazy-refcounts": false, "refcount-bits": 16, - "corrupt": false + "corrupt": false, + "extended-l2": false } }, "full-backing-filename": "TEST_DIR/t.IMGFMT.base", @@ -63,7 +64,8 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTEST_= DIR/t.IMGFMT.base -blockdev "compat": "1.1", "lazy-refcounts": false, "refcount-bits": 16, - "corrupt": false + "corrupt": false, + "extended-l2": false } }, "full-backing-filename": "TEST_DIR/t.IMGFMT.mid", @@ -142,7 +144,8 @@ Testing: -blockdev file,node-name=3Dbase,filename=3DTES= T_DIR/t.IMGFMT.base -blockdev "compat": "1.1", "lazy-refcounts": false, "refcount-bits": 16, - "corrupt": false + "corrupt": false, + "extended-l2": false } }, "full-backing-filename": "TEST_DIR/t.IMGFMT.base", diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 5367deea39..ec42b9a62b 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -140,6 +140,7 @@ _filter_img_create() -e "s# adapter_type=3D[^ ]*##g" \ -e "s# hwversion=3D[^ ]*##g" \ -e "s# lazy_refcounts=3D\\(on\\|off\\)##g" \ + -e "s# extended_l2=3D\\(on\\|off\\)##g" \ -e "s# block_size=3D[0-9]\\+##g" \ -e "s# block_state_zero=3D\\(on\\|off\\)##g" \ -e "s# log_size=3D[0-9]\\+##g" \ --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577016221; cv=none; d=zohomail.com; s=zohoarc; b=mB7YgHw3fw6dytUG81J+MIagTa7JCjBSdGXJzFySSg3cdNLDfpCAXiRUfl1x7bGCks5DdvquJgn+ehMrY/CSOcPiuHRHoDcvxr9qKQLf8Bfuj0I2gQl6tdD8QkwNzMB1dSQIX7sGYnSY07V1hClf0Rxe4MeuJdicqkAFwHGRQ8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577016221; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E+SoyxPLvlWargalWgxEbk+TBsEEMcY7UkhPnTR5WLU=; b=glNKIRh+vYIPnmNn+CTQJ89Ps2i0sN8nmWf522iuCirhdjO2J610R0hp1HREnJDBbd9pnk1R1A3UhMHoll8TlQIrQuZXmFtsEu7W/7OlRL29WB5jBn9rqNifKVVLmBEL0KAXsSwzB3GoxtSBUphLtyHVVsyfr5/meFNA8TmKJCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577016221318498.3889609377411; Sun, 22 Dec 2019 04:03:41 -0800 (PST) Received: from localhost ([::1]:47114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizxU-0004JD-8u for importer@patchew.org; Sun, 22 Dec 2019 07:03:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44317) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizZE-0003Vj-Li for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizZC-00075A-6v for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:36 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:35048) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizZB-0004nz-JE; Sun, 22 Dec 2019 06:38:33 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dS-41; Sun, 22 Dec 2019 12:37:52 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXv-0001WQ-0s; Sun, 22 Dec 2019 12:37:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=E+SoyxPLvlWargalWgxEbk+TBsEEMcY7UkhPnTR5WLU=; b=IdeYm4BNIW3A/RXjsU5kpk/IYwbTICe1ijNea21/YLu9lsWcs23+QjU1q7CsF675y1GIXUfB7C8FKFrwDpPqDyHjU+tsPemiAI1sLOcfDMTbI3NGdrnEU88h9z0yKqYRV3OpVWYGMMJE+yeNPVM+RIYgMw4zOk/pftbNHPmVxHu++9tNEkd/08O+Rv4xPm7I518cRdJMfU0PxzGxP9oUauhABWT+Ondr9k7eaFrUEGCV0EuQPMYua7iVNBIBUODr7QrRAiUh8AG/IFuxEaluKC7pviNSRJFl4kFRjJLGhe1K+NM4/6/y63q4CuCfdzIgpTaL3AQbDmA7JbKXpZhMxQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 26/27] qcow2: Add subcluster support to qcow2_measure() Date: Sun, 22 Dec 2019 12:37:07 +0100 Message-Id: <9fadbca0b9fc6d7a5c8b1dc4cda53d45a4d37c25.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extended L2 entries are bigger than normal L2 entries so this has an impact on the amount of metadata needed for a qcow2 file. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 4f26953b1e..62093de1c6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3162,28 +3162,31 @@ int64_t qcow2_refcount_metadata_size(int64_t cluste= rs, size_t cluster_size, * @total_size: virtual disk size in bytes * @cluster_size: cluster size in bytes * @refcount_order: refcount bits power-of-2 exponent + * @extended_l2: true if the image has extended L2 entries * * Returns: Total number of bytes required for the fully allocated image * (including metadata). */ static int64_t qcow2_calc_prealloc_size(int64_t total_size, size_t cluster_size, - int refcount_order) + int refcount_order, + bool extended_l2) { int64_t meta_size =3D 0; uint64_t nl1e, nl2e; int64_t aligned_total_size =3D ROUND_UP(total_size, cluster_size); + size_t l2e_size =3D extended_l2 ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; =20 /* header: 1 cluster */ meta_size +=3D cluster_size; =20 /* total size of L2 tables */ nl2e =3D aligned_total_size / cluster_size; - nl2e =3D ROUND_UP(nl2e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl2e * sizeof(uint64_t); + nl2e =3D ROUND_UP(nl2e, cluster_size / l2e_size); + meta_size +=3D nl2e * l2e_size; =20 /* total size of L1 tables */ - nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; + nl1e =3D nl2e * l2e_size / cluster_size; nl1e =3D ROUND_UP(nl1e, cluster_size / sizeof(uint64_t)); meta_size +=3D nl1e * sizeof(uint64_t); =20 @@ -4704,6 +4707,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, bool has_backing_file; bool has_luks; bool extended_l2; + size_t l2e_size; =20 /* Parse image creation options */ extended_l2 =3D qemu_opt_get_bool_del(opts, BLOCK_OPT_EXTL2, false); @@ -4754,8 +4758,9 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, virtual_size =3D ROUND_UP(virtual_size, cluster_size); =20 /* Check that virtual disk size is valid */ + l2e_size =3D extended_l2 ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; l2_tables =3D DIV_ROUND_UP(virtual_size / cluster_size, - cluster_size / sizeof(uint64_t)); + cluster_size / l2e_size); if (l2_tables * sizeof(uint64_t) > QCOW_MAX_L1_SIZE) { error_setg(&local_err, "The image size is too large " "(try using a larger cluster size)"); @@ -4818,9 +4823,9 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, } =20 info =3D g_new(BlockMeasureInfo, 1); - info->fully_allocated =3D + info->fully_allocated =3D luks_payload_size + qcow2_calc_prealloc_size(virtual_size, cluster_size, - ctz32(refcount_bits)) + luks_payload_size; + ctz32(refcount_bits), extended_l2); =20 /* Remove data clusters that are not required. This overestimates the * required size because metadata needed for the fully allocated file = is --=20 2.20.1 From nobody Thu May 2 03:50:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1577015162; cv=none; d=zohomail.com; s=zohoarc; b=X/Iof6j3gNRdsrPS0bjJRaElyAugd85sQ5VGJFvAWIh1PlVwWUXnmIQWBJ+JMw4VXdh3p4c2IgaEInJcjLrv5S13NrNrI4p/0V5pRAqjZwDKwYiIxzlOiRomA2iGItCIIpO6+B13mSdCRAlnseMMjTfRLftak4Rp/7FIQWQpQas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577015162; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aluSIzE6GH+yHAKmqELbdLf3r0L5i/N+TmqncvlhsVw=; b=c6FG+uTuIMipbiAlm0L/Ju9wnlOGm9eo0YdyQSb0EWbmwg8m84XBIotw3Mr4iZSbkGq6COkEQgBzxKdlU+5PSD79SBbZZ4iGWT24Gdt/hfZfd19Co/icNcs7DeJK6cYsMXDmtYoA2+6p4/MDgvS9LBsh/k1ya7TTCEe/97pZf74= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577015162032674.281440308104; Sun, 22 Dec 2019 03:46:02 -0800 (PST) Received: from localhost ([::1]:46750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizgO-0003W2-9H for importer@patchew.org; Sun, 22 Dec 2019 06:46:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41837) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iizYs-0002qU-Lc for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iizYo-0005cf-6z for qemu-devel@nongnu.org; Sun, 22 Dec 2019 06:38:14 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:34984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iizYn-0004V9-Dn; Sun, 22 Dec 2019 06:38:09 -0500 Received: from [80.30.182.172] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iizYV-0005dT-5d; Sun, 22 Dec 2019 12:37:53 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1iizXv-0001WT-1y; Sun, 22 Dec 2019 12:37:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aluSIzE6GH+yHAKmqELbdLf3r0L5i/N+TmqncvlhsVw=; b=Pjq+dtPIiMh0/Q4DTUvGwBJwyRgJbbJkimAZM+BeIOtUaQTL0xMsn9O5sbsSTtaPTTFg28wzhlZG/5SwrO3m0i5TFWxGcEqGYmT3AIQ2dE2DdpJtYtmfyryJfwL6PgWhOhrRLBn4j3B1JgbEpxg1se920TtcKEYMx8ilGMGbbnUav6XYMFBiRyrDYuR85fAzKaMgJ299A8KFi8J8HR/43mbNojnK597mJNJMHB5ao+Z+W4wSMyDsZPOuUZrNdn8oJlljAW03lW6ThyyBGTyNOEUJcs8yJqlCo/FebOI4jThyi0PsAMJIxSj0vtb+N7tfsf64nqiqD3WhhNTKF1qxlA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 27/27] iotests: Add tests for qcow2 images with extended L2 entries Date: Sun, 22 Dec 2019 12:37:08 +0100 Message-Id: <9ece987f62e5f05f817c76339bf22ec4810e3205.1577014346.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- tests/qemu-iotests/271 | 256 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/271.out | 208 ++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 465 insertions(+) create mode 100755 tests/qemu-iotests/271 create mode 100644 tests/qemu-iotests/271.out diff --git a/tests/qemu-iotests/271 b/tests/qemu-iotests/271 new file mode 100755 index 0000000000..73cdc37bf0 --- /dev/null +++ b/tests/qemu-iotests/271 @@ -0,0 +1,256 @@ +#!/bin/bash +# +# Test qcow2 images with extended L2 entries +# +# Copyright (C) 2019 Igalia, S.L. +# Author: Alberto Garcia +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dberto@igalia.com + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +here=3D"$PWD" +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.raw" + rm -f "$TEST_IMG.backing" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file nfs +_supported_os Linux + +IMGOPTS=3D"extended_l2=3Don" +l2_offset=3D262144 # 0x40000 + +_verify_img() +{ + $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.raw" | grep -v 'Images are id= entical' + $QEMU_IMG check "$TEST_IMG" | _filter_qemu_img_check | \ + grep -v 'No errors were found on the image' +} + +_read_l2_entry() +{ + entry_no=3D$1 + nentries=3D$2 + offset=3D$(($l2_offset + $entry_no * 16)) + length=3D$((nentries * 16)) + $QEMU_IO -f raw -c "read -v $offset $length" "$TEST_IMG" | _filter_qem= u_io | head -n -2 +} + +_test_write() +{ + cmd=3D"$1" + l2_entry_idx=3D"$2" + l2_entry_num=3D"$3" + raw_cmd=3D`echo $1 | sed s/-c//` # Raw images don't support -c + echo "$cmd" + $QEMU_IO -c "$cmd" "$TEST_IMG" | _filter_qemu_io + $QEMU_IO -c "$raw_cmd" -f raw "$TEST_IMG.raw" | _filter_qemu_io + _verify_img + if [ -n "$l2_entry_idx" ]; then + _read_l2_entry "$l2_entry_idx" "$l2_entry_num" + fi +} + +_reset_img() +{ + $QEMU_IMG create -f raw "$TEST_IMG.raw" 1M | _filter_img_create + if [ "$use_backing_file" =3D "yes" ]; then + $QEMU_IMG create -f raw "$TEST_IMG.backing" 1M | _filter_img_create + $QEMU_IO -c 'write -q -P 0xFF 0 1M' -f raw "$TEST_IMG.backing" | _= filter_qemu_io + $QEMU_IO -c 'write -q -P 0xFF 0 1M' -f raw "$TEST_IMG.raw" | _filt= er_qemu_io + _make_test_img -b "$TEST_IMG.backing" 1M + else + _make_test_img 1M + fi +} + +# Test that writing to an image with subclusters produces the expected +# results, in images with and without backing files +for use_backing_file in yes no; do + echo + echo "### Standard write tests (backing file: $use_backing_file) ###" + echo + _reset_img + ### Write subcluster #0 (beginning of subcluster) ### + _test_write 'write -q -P 1 0 1k' 0 1 + + ### Write subcluster #1 (middle of subcluster) ### + _test_write 'write -q -P 2 3k 512' 0 1 + + ### Write subcluster #2 (end of subcluster) ### + _test_write 'write -q -P 3 5k 1k' 0 1 + + ### Write subcluster #3 (full subcluster) ### + _test_write 'write -q -P 4 6k 2k' 0 1 + + ### Write subclusters #4-6 (full subclusters) ### + _test_write 'write -q -P 5 8k 6k' 0 1 + + ### Write subclusters #7-9 (partial subclusters) ### + _test_write 'write -q -P 6 15k 4k' 0 1 + + ### Write subcluster #16 (partial subcluster) ### + _test_write 'write -q -P 7 32k 1k' 0 2 + + ### Write subcluster #31-#34 (cluster overlap) ### + _test_write 'write -q -P 8 63k 4k' 0 2 + + ### Zero subcluster #1 (TODO: use the "all zeros" bit) + _test_write 'write -q -z 2k 2k' 0 1 + + ### Zero cluster #0 + _test_write 'write -q -z 0 64k' 0 1 + + ### Fill cluster #0 with data + _test_write 'write -q -P 9 0 64k' 0 1 + + ### Zero and unmap half of cluster #0 (this won't unmap it) + _test_write 'write -q -z -u 0 32k' 0 1 + + ### Zero and unmap cluster #0 + _test_write 'write -q -z -u 0 64k' 0 1 + + ### Write subcluster #2 (middle of subcluster) + _test_write 'write -q -P 10 3k 512' 0 1 + + ### Fill cluster #0 with data + _test_write 'write -q -P 11 0 64k' 0 1 + + ### Discard cluster #0 + _test_write 'discard -q 0 64k' 0 1 + + ### Write compressed data to cluster #0 + _test_write 'write -q -c -P 12 0 64k' 0 1 + + ### Write subcluster #2 (middle of subcluster) + _test_write 'write -q -P 13 3k 512' 0 1 +done + +# Test that corrupted L2 entries are detected in both read and write +# operations +for corruption_test_cmd in read write; do + echo + echo "### Corrupted L2 entries - $corruption_test_cmd test (allocated)= ###" + echo + echo "# 'cluster is zero' bit set on the standard cluster descriptor" + echo + _make_test_img 1M + $QEMU_IO -c 'write -q 0 2k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+7)) "\x01" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# Both 'subcluster is zero' and 'subcluster is allocated' bits s= et" + echo + _make_test_img 1M + $QEMU_IO -c 'write -q 0 2k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+8)) "\x80" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "### Corrupted L2 entries - $corruption_test_cmd test (unallocate= d) ###" + echo + echo "# 'cluster is zero' bit set on the standard cluster descriptor" + echo + _make_test_img 1M + # Write to cluster #4 in order to initialize the L2 table + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+7)) "\x01" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# 'subcluster is allocated' bit set" + echo + _make_test_img 1M + # Write to cluster #4 in order to initialize the L2 table + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+12)) "\x80" + _read_l2_entry 0 1 + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "# Both 'subcluster is zero' and 'subcluster is allocated' bits s= et" + echo + _make_test_img 1M + # Write to cluster #4 in order to initialize the L2 table + $QEMU_IO -c 'write -q 256k 1k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+8)) "\x80\x00\x00\x00\x80" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" + + echo + echo "### Compressed cluster with subcluster bitmap !=3D 0 - $corrupti= on_test_cmd test ###" + echo + _make_test_img 1M + $QEMU_IO -c 'write -q -c 0 64k' "$TEST_IMG" + poke_file "$TEST_IMG" $(($l2_offset+8)) "\x01" + $QEMU_IO -c "$corruption_test_cmd 0 1k" "$TEST_IMG" +done + +echo +echo "### Image creation options ###" +echo +echo "# cluster_size < 16k" +IMGOPTS=3D"extended_l2=3Don,cluster_size=3D8k" _make_test_img 1M + +echo "# backing file and preallocation=3Dmetadata" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dmetadata" _make_test_img -b "$= TEST_IMG.backing" 1M + +echo "# backing file and preallocation=3Dfalloc" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dfalloc" _make_test_img -b "$TE= ST_IMG.backing" 1M + +echo "# backing file and preallocation=3Dfull" +IMGOPTS=3D"extended_l2=3Don,preallocation=3Dfull" _make_test_img -b "$TEST= _IMG.backing" 1M + +echo +echo "### qemu-img measure ###" +echo +echo "# 512MB, extended_l2=3Doff" # This needs one L2 table +$QEMU_IMG measure --size 512M -O qcow2 -o extended_l2=3Doff +echo "# 512MB, extended_l2=3Don" # This needs two L2 tables +$QEMU_IMG measure --size 512M -O qcow2 -o extended_l2=3Don + +echo "# 16K clusters, 64GB, extended_l2=3Doff" # This needs one L1 table +$QEMU_IMG measure --size 64G -O qcow2 -o cluster_size=3D16k,extended_l2=3D= off +echo "# 16K clusters, 64GB, extended_l2=3Don" # This needs two L2 tables +$QEMU_IMG measure --size 64G -O qcow2 -o cluster_size=3D16k,extended_l2=3D= on + +echo "# 8k clusters" # This should fail +$QEMU_IMG measure --size 1M -O qcow2 -o cluster_size=3D8k,extended_l2=3Don + +echo "# 1024 TB" # Maximum allowed size with extended_l2=3Don and 64K clus= ters +$QEMU_IMG measure --size 1024T -O qcow2 -o extended_l2=3Don +echo "# 1025 TB" # This should fail +$QEMU_IMG measure --size 1025T -O qcow2 -o extended_l2=3Don + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 + diff --git a/tests/qemu-iotests/271.out b/tests/qemu-iotests/271.out new file mode 100644 index 0000000000..7e8cff5e14 --- /dev/null +++ b/tests/qemu-iotests/271.out @@ -0,0 +1,208 @@ +QA output created by 271 + +### Standard write tests (backing file: yes) ### + +Formatting 'TEST_DIR/t.IMGFMT.raw', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT.backing', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing +write -q -P 1 0 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 80 00 00 00 ..............= .. +write -q -P 2 3k 512 +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 c0 00 00 00 ..............= .. +write -q -P 3 5k 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 e0 00 00 00 ..............= .. +write -q -P 4 6k 2k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 f0 00 00 00 ..............= .. +write -q -P 5 8k 6k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 fe 00 00 00 ..............= .. +write -q -P 6 15k 4k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 00 00 ..............= .. +write -q -P 7 32k 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 00 ..............= .. +00040010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..............= .. +write -q -P 8 63k 4k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 01 ..............= .. +00040010: 80 00 00 00 00 06 00 00 00 00 00 00 c0 00 00 00 ..............= .. +write -q -z 2k 2k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 01 ..............= .. +write -q -z 0 64k +00040000: 80 00 00 00 00 05 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -P 9 0 64k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +write -q -z -u 0 32k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +write -q -z -u 0 64k +00040000: 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -P 10 3k 512 +00040000: 80 00 00 00 00 05 00 00 bf ff ff ff 40 00 00 00 ..............= .. +write -q -P 11 0 64k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +discard -q 0 64k +00040000: 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -c -P 12 0 64k +00040000: 40 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 ..............= .. +write -q -P 13 3k 512 +00040000: 80 00 00 00 00 07 00 00 00 00 00 00 ff ff ff ff ..............= .. + +### Standard write tests (backing file: no) ### + +Formatting 'TEST_DIR/t.IMGFMT.raw', fmt=3Draw size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +write -q -P 1 0 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 80 00 00 00 ..............= .. +write -q -P 2 3k 512 +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 c0 00 00 00 ..............= .. +write -q -P 3 5k 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 e0 00 00 00 ..............= .. +write -q -P 4 6k 2k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 f0 00 00 00 ..............= .. +write -q -P 5 8k 6k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 fe 00 00 00 ..............= .. +write -q -P 6 15k 4k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 00 00 ..............= .. +write -q -P 7 32k 1k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 00 ..............= .. +00040010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..............= .. +write -q -P 8 63k 4k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 01 ..............= .. +00040010: 80 00 00 00 00 06 00 00 00 00 00 00 c0 00 00 00 ..............= .. +write -q -z 2k 2k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff c0 80 01 ..............= .. +write -q -z 0 64k +00040000: 80 00 00 00 00 05 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -P 9 0 64k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +write -q -z -u 0 32k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +write -q -z -u 0 64k +00040000: 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -P 10 3k 512 +00040000: 80 00 00 00 00 05 00 00 bf ff ff ff 40 00 00 00 ..............= .. +write -q -P 11 0 64k +00040000: 80 00 00 00 00 05 00 00 00 00 00 00 ff ff ff ff ..............= .. +discard -q 0 64k +00040000: 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 ..............= .. +write -q -c -P 12 0 64k +00040000: 40 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 ..............= .. +write -q -P 13 3k 512 +00040000: 80 00 00 00 00 07 00 00 00 00 00 00 ff ff ff ff ..............= .. + +### Corrupted L2 entries - read test (allocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +### Corrupted L2 entries - read test (unallocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# 'subcluster is allocated' bit set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +00040000: 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 ..............= .. +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +### Compressed cluster with subcluster bitmap !=3D 0 - read test ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +read failed: Input/output error + +### Corrupted L2 entries - write test (allocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +### Corrupted L2 entries - write test (unallocated) ### + +# 'cluster is zero' bit set on the standard cluster descriptor + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# 'subcluster is allocated' bit set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +00040000: 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 ..............= .. +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +# Both 'subcluster is zero' and 'subcluster is allocated' bits set + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +### Compressed cluster with subcluster bitmap !=3D 0 - write test ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qcow2: Marking image as corrupt: Invalid cluster entry found (L2 offset: = 0x40000, L2 index: 0); further corruption events will be suppressed +write failed: Input/output error + +### Image creation options ### + +# cluster_size < 16k +qemu-img: TEST_DIR/t.IMGFMT: Extended L2 entries are only supported with c= luster sizes of at least 16384 bytes +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +# backing file and preallocation=3Dmetadata +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dmetadata +# backing file and preallocation=3Dfalloc +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dfalloc +# backing file and preallocation=3Dfull +qemu-img: TEST_DIR/t.IMGFMT: Backing file and preallocation cannot be used= at the same time +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT.backing preallocation=3Dfull + +### qemu-img measure ### + +# 512MB, extended_l2=3Doff +required size: 327680 +fully allocated size: 537198592 +# 512MB, extended_l2=3Don +required size: 393216 +fully allocated size: 537264128 +# 16K clusters, 64GB, extended_l2=3Doff +required size: 42008576 +fully allocated size: 68761485312 +# 16K clusters, 64GB, extended_l2=3Don +required size: 75579392 +fully allocated size: 68795056128 +# 8k clusters +qemu-img: Extended L2 entries are only supported with cluster sizes of at = least 16384 bytes +# 1024 TB +required size: 309285027840 +fully allocated size: 1126209191870464 +# 1025 TB +qemu-img: The image size is too large (try using a larger cluster size) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 6b10a6a762..3012f171a6 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -283,6 +283,7 @@ 267 rw auto quick snapshot 268 rw auto quick 270 rw backing quick +271 rw auto 272 rw 273 backing quick 277 rw quick --=20 2.20.1