{"id":1307006,"url":"http://patchwork.ozlabs.org/api/patches/1307006/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/b39f0ae0871a31382b6338612523cb12f776ae3b.1591801197.git.berto@igalia.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<b39f0ae0871a31382b6338612523cb12f776ae3b.1591801197.git.berto@igalia.com>","list_archive_url":null,"date":"2020-06-10T15:03:00","name":"[v8,22/34] qcow2: Add subcluster support to zero_in_l2_slice()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"230a096f4b0c4d0ac97229a8faaab253943d7674","submitter":{"id":65704,"url":"http://patchwork.ozlabs.org/api/people/65704/?format=json","name":"Alberto Garcia","email":"berto@igalia.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/b39f0ae0871a31382b6338612523cb12f776ae3b.1591801197.git.berto@igalia.com/mbox/","series":[{"id":182563,"url":"http://patchwork.ozlabs.org/api/series/182563/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=182563","date":"2020-06-10T15:02:49","name":"Add subcluster allocation to qcow2","version":8,"mbox":"http://patchwork.ozlabs.org/series/182563/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1307006/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1307006/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=<UNKNOWN>)","ozlabs.org;\n dmarc=none (p=none dis=none) header.from=igalia.com","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256\n header.s=20170329 header.b=r1AdAkTu;\n\tdkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 49hr2p3Fb8z9sRh\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 11 Jun 2020 01:08:02 +1000 (AEST)","from localhost ([::1]:57898 helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1jj2Ke-0006xO-5l\n\tfor incoming@patchwork.ozlabs.org; Wed, 10 Jun 2020 11:08:00 -0400","from eggs.gnu.org ([2001:470:142:3::10]:35958)\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <berto@igalia.com>)\n id 1jj2Gb-0002Hg-65; Wed, 10 Jun 2020 11:03:49 -0400","from fanzine.igalia.com ([178.60.130.6]:58154)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <berto@igalia.com>)\n id 1jj2GX-0006wQ-UR; Wed, 10 Jun 2020 11:03:48 -0400","from [81.0.38.199] (helo=perseus.local)\n by fanzine.igalia.com with esmtpsa\n (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim)\n id 1jj2GR-0007h2-Nc; Wed, 10 Jun 2020 17:03:39 +0200","from berto by perseus.local with local (Exim 4.92)\n (envelope-from <berto@igalia.com>)\n id 1jj2GC-0007NQ-AV; Wed, 10 Jun 2020 17:03:24 +0200"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n s=20170329;\n h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From;\n bh=9sinAT98PUzgL4pBz7R1BbWSmbQmOO5Lnaa9e5wFELw=;\n b=r1AdAkTu34mMrO/oLdQUe/lyzZjbwIw8VujTxMDlsPl/djoMWOqiIYhzr4JfkMwkFtffIjKtKyCvJsS5VigpJM/LJnmyHotCDdSMJ/aDUU4d+jnC8liCZHLwYdLEMufo9G0X7M9nirACvugto9Ji9yRGz1g8Y6+RL66YTWLJzlSKnqVFSfKfOL1A+Fzj0GUrdt3Qvu0YSQBaYQk41eLNzLigrWChUEwiX2x9geBCGaPZLEo6QvEvJOMDKtpo1aC22xXMarg63+y98uWU9TFWhm1kFN06RlfKsUSKEzVRQvzXNZCUBSpfYNr0ei8cVLpL9izc2ijf1wzKPNZfninqVw==;","From":"Alberto Garcia <berto@igalia.com>","To":"qemu-devel@nongnu.org","Subject":"[PATCH v8 22/34] qcow2: Add subcluster support to zero_in_l2_slice()","Date":"Wed, 10 Jun 2020 17:03:00 +0200","Message-Id":"\n <b39f0ae0871a31382b6338612523cb12f776ae3b.1591801197.git.berto@igalia.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<cover.1591801197.git.berto@igalia.com>","References":"<cover.1591801197.git.berto@igalia.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=178.60.130.6; envelope-from=berto@igalia.com;\n helo=fanzine.igalia.com","X-detected-operating-system":"by eggs.gnu.org: First seen = 2020/06/10 11:03:39","X-ACL-Warn":"Detected OS   = Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy]","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=_AUTOLEARN","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Kevin Wolf <kwolf@redhat.com>,\n Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,\n Alberto Garcia <berto@igalia.com>, qemu-block@nongnu.org,\n Derek Su <dereksu@qnap.com>, Max Reitz <mreitz@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"The QCOW_OFLAG_ZERO bit that indicates that a cluster reads as\nzeroes is only used in standard L2 entries. Extended L2 entries use\nindividual 'all zeroes' bits for each subcluster.\n\nThis must be taken into account when updating the L2 entry and also\nwhen deciding that an existing entry does not need to be updated.\n\nSigned-off-by: Alberto Garcia <berto@igalia.com>\nReviewed-by: Eric Blake <eblake@redhat.com>\n---\n block/qcow2-cluster.c | 36 +++++++++++++++++++-----------------\n 1 file changed, 19 insertions(+), 17 deletions(-)","diff":"diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c\nindex 2f3bd3a882..4e59bbd545 100644\n--- a/block/qcow2-cluster.c\n+++ b/block/qcow2-cluster.c\n@@ -1956,7 +1956,6 @@ static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,\n     int l2_index;\n     int ret;\n     int i;\n-    bool unmap = !!(flags & BDRV_REQ_MAY_UNMAP);\n \n     ret = get_cluster_table(bs, offset, &l2_slice, &l2_index);\n     if (ret < 0) {\n@@ -1968,28 +1967,31 @@ static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,\n     assert(nb_clusters <= INT_MAX);\n \n     for (i = 0; i < nb_clusters; i++) {\n-        uint64_t old_offset;\n-        QCow2ClusterType cluster_type;\n+        uint64_t old_l2_entry = get_l2_entry(s, l2_slice, l2_index + i);\n+        uint64_t old_l2_bitmap = get_l2_bitmap(s, l2_slice, l2_index + i);\n+        QCow2ClusterType type = qcow2_get_cluster_type(bs, old_l2_entry);\n+        bool unmap = (type == QCOW2_CLUSTER_COMPRESSED) ||\n+            ((flags & BDRV_REQ_MAY_UNMAP) && qcow2_cluster_is_allocated(type));\n+        uint64_t new_l2_entry = unmap ? 0 : old_l2_entry;\n+        uint64_t new_l2_bitmap = old_l2_bitmap;\n \n-        old_offset = get_l2_entry(s, l2_slice, l2_index + i);\n+        if (has_subclusters(s)) {\n+            new_l2_bitmap = QCOW_L2_BITMAP_ALL_ZEROES;\n+        } else {\n+            new_l2_entry |= QCOW_OFLAG_ZERO;\n+        }\n \n-        /*\n-         * Minimize L2 changes if the cluster already reads back as\n-         * zeroes with correct allocation.\n-         */\n-        cluster_type = qcow2_get_cluster_type(bs, old_offset);\n-        if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN ||\n-            (cluster_type == QCOW2_CLUSTER_ZERO_ALLOC && !unmap)) {\n+        if (old_l2_entry == new_l2_entry && old_l2_bitmap == new_l2_bitmap) {\n             continue;\n         }\n \n         qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice);\n-        if (cluster_type == QCOW2_CLUSTER_COMPRESSED || unmap) {\n-            set_l2_entry(s, l2_slice, l2_index + i, QCOW_OFLAG_ZERO);\n-            qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);\n-        } else {\n-            uint64_t entry = get_l2_entry(s, l2_slice, l2_index + i);\n-            set_l2_entry(s, l2_slice, l2_index + i, entry | QCOW_OFLAG_ZERO);\n+        if (unmap) {\n+            qcow2_free_any_clusters(bs, old_l2_entry, 1, QCOW2_DISCARD_REQUEST);\n+        }\n+        set_l2_entry(s, l2_slice, l2_index + i, new_l2_entry);\n+        if (has_subclusters(s)) {\n+            set_l2_bitmap(s, l2_slice, l2_index + i, new_l2_bitmap);\n         }\n     }\n \n","prefixes":["v8","22/34"]}