{"id":1307020,"url":"http://patchwork.ozlabs.org/api/patches/1307020/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/259e53cff2911316e427c40001801004e6b4257d.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":"<259e53cff2911316e427c40001801004e6b4257d.1591801197.git.berto@igalia.com>","list_archive_url":null,"date":"2020-06-10T15:03:08","name":"[v8,30/34] qcow2: Add prealloc field to QCowL2Meta","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e189a6ae965c915b0d56c747b8302ae1bf0a877c","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/259e53cff2911316e427c40001801004e6b4257d.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/1307020/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1307020/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=sNHuUgGq;\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 49hrGv0cnZz9sQx\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 11 Jun 2020 01:18:31 +1000 (AEST)","from localhost ([::1]:37412 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 1jj2Um-0006FH-BX\n\tfor incoming@patchwork.ozlabs.org; Wed, 10 Jun 2020 11:18:28 -0400","from eggs.gnu.org ([2001:470:142:3::10]:36152)\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 1jj2Gx-0002jF-2U; Wed, 10 Jun 2020 11:04:11 -0400","from fanzine.igalia.com ([178.60.130.6]:58252)\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 1jj2Gs-0006wd-K1; Wed, 10 Jun 2020 11:04:10 -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-0007hH-RC; 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-0007No-IK; 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=Lcb8BrUxErhwUJiz8YryM0p81YuZH+KP4HMqL7rpmqU=;\n b=sNHuUgGqh8EWwVg8On0f8+oChtIsDPHe5xVv3Xry9VqeOzsx26on+qq8oM166R/jofAYatc2eYVJb9EwvHehHarZEYI6unDGw1g4h3/RqzIQYttUtLW4UxYLsRlaxwy7+zFF8PhE0aJ2KJW1CYxgSm4mMSACOFHcRImcfzPKg1VwL0+GXH0WYDemTGwEbqrDeMx/HOD4ehrKsBjfvtDR8fC/6m2hLEwYFU7OVON73BJ0HBiN1VBLjAmyzwp+bunZIpMDmmbIOnXMh04zz2gsKEv9XghTbn4IjzS4mX2/zcCkw3SHAXMhIZm+Bvy2Blw/3MoFhlxjFeh6mqZOVYJdyQ==;","From":"Alberto Garcia <berto@igalia.com>","To":"qemu-devel@nongnu.org","Subject":"[PATCH v8 30/34] qcow2: Add prealloc field to QCowL2Meta","Date":"Wed, 10 Jun 2020 17:03:08 +0200","Message-Id":"\n <259e53cff2911316e427c40001801004e6b4257d.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":"This field allows us to indicate that the L2 metadata update does not\ncome from a write request with actual data but from a preallocation\nrequest.\n\nFor traditional images this does not make any difference, but for\nimages with extended L2 entries this means that the clusters are\nallocated normally in the L2 table but individual subclusters are\nmarked as unallocated.\n\nThis will allow preallocating images that have a backing file.\n\nThere is one special case: when we resize an existing image we can\nalso request that the new clusters are preallocated. If the image\nalready had a backing file then we have to hide any possible stale\ndata and zero out the new clusters (see commit 955c7d6687 for more\ndetails).\n\nIn this case the subclusters cannot be left as unallocated so the L2\nbitmap must be updated.\n\nSigned-off-by: Alberto Garcia <berto@igalia.com>\n---\n block/qcow2.h         | 8 ++++++++\n block/qcow2-cluster.c | 2 +-\n block/qcow2.c         | 6 ++++++\n 3 files changed, 15 insertions(+), 1 deletion(-)","diff":"diff --git a/block/qcow2.h b/block/qcow2.h\nindex 4ef4ae4ab0..f3499e53bf 100644\n--- a/block/qcow2.h\n+++ b/block/qcow2.h\n@@ -463,6 +463,14 @@ typedef struct QCowL2Meta\n      */\n     bool skip_cow;\n \n+    /**\n+     * Indicates that this is not a normal write request but a preallocation.\n+     * If the image has extended L2 entries this means that no new individual\n+     * subclusters will be marked as allocated in the L2 bitmap (but any\n+     * existing contents of that bitmap will be kept).\n+     */\n+    bool prealloc;\n+\n     /**\n      * The I/O vector with the data from the actual guest write request.\n      * If non-NULL, this is meant to be merged together with the data\ndiff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c\nindex 1641976028..c8217081f2 100644\n--- a/block/qcow2-cluster.c\n+++ b/block/qcow2-cluster.c\n@@ -1066,7 +1066,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)\n         set_l2_entry(s, l2_slice, l2_index + i, offset | QCOW_OFLAG_COPIED);\n \n         /* Update bitmap with the subclusters that were just written */\n-        if (has_subclusters(s)) {\n+        if (has_subclusters(s) && !m->prealloc) {\n             uint64_t l2_bitmap = get_l2_bitmap(s, l2_slice, l2_index + i);\n             unsigned written_from = m->cow_start.offset;\n             unsigned written_to = m->cow_end.offset + m->cow_end.nb_bytes ?:\ndiff --git a/block/qcow2.c b/block/qcow2.c\nindex 72bd25e774..003f166024 100644\n--- a/block/qcow2.c\n+++ b/block/qcow2.c\n@@ -2086,6 +2086,7 @@ static coroutine_fn int qcow2_handle_l2meta(BlockDriverState *bs,\n         QCowL2Meta *next;\n \n         if (link_l2) {\n+            assert(!l2meta->prealloc);\n             ret = qcow2_alloc_cluster_link_l2(bs, l2meta);\n             if (ret) {\n                 goto out;\n@@ -3131,6 +3132,7 @@ static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset,\n \n         while (meta) {\n             QCowL2Meta *next = meta->next;\n+            meta->prealloc = true;\n \n             ret = qcow2_alloc_cluster_link_l2(bs, meta);\n             if (ret < 0) {\n@@ -4224,6 +4226,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,\n         int64_t clusters_allocated;\n         int64_t old_file_size, last_cluster, new_file_size;\n         uint64_t nb_new_data_clusters, nb_new_l2_tables;\n+        bool subclusters_need_allocation = false;\n \n         /* With a data file, preallocation means just allocating the metadata\n          * and forwarding the truncate request to the data file */\n@@ -4305,6 +4308,8 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,\n                                    BDRV_REQ_ZERO_WRITE, NULL);\n             if (ret >= 0) {\n                 flags &= ~BDRV_REQ_ZERO_WRITE;\n+                /* Ensure that we read zeroes and not backing file data */\n+                subclusters_need_allocation = true;\n             }\n         } else {\n             ret = -1;\n@@ -4343,6 +4348,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,\n                     .offset       = nb_clusters << s->cluster_bits,\n                     .nb_bytes     = 0,\n                 },\n+                .prealloc     = !subclusters_need_allocation,\n             };\n             qemu_co_queue_init(&allocation.dependent_requests);\n \n","prefixes":["v8","30/34"]}