From nobody Mon Feb 9 04:44:17 2026 Delivered-To: importer@patchew.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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587738501; cv=none; d=zohomail.com; s=zohoarc; b=SMTeAWvnW3KERfwmZAc77MWZQPeF2ILHub0N/49cwsHkydbNrtSyyuTEoZwsY+/glOwKBrusSj02R4U8tzKEyWvbmNJ6zYTwv+zQBfN3JytCbzEFKQq3MHpvZh4n7d91tTIw7msKhm+5fuNmFRCkWDxorfpuKZKhVgdZIawHfLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738501; h=Content-Type: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=C4LnEPGFSo/zjI8jEGxKIjBxusRHCEQBZA/zMU3R2RI=; b=ZZLCqy2r1EOkAwhJV+NwHY6NGL0vhhR9bb0X+wIpvPvOuzEVcfEx0G47i1ug9zHINXmSJq42bE8QP6IM0TlBqkho1U+9jm3dQHY1SSSZxkeCxH252WkakSlZRJLxiZUPrGNjJ1r2S2suk3taiphLoaNkswdF0GG1mq7/J75VlcM= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587738501320909.7553826774091; Fri, 24 Apr 2020 07:28:21 -0700 (PDT) Received: from localhost ([::1]:39628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRzJT-0005JH-U8 for importer@patchew.org; Fri, 24 Apr 2020 10:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58884) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRzIZ-0003ri-Ux for qemu-devel@nongnu.org; Fri, 24 Apr 2020 10:27:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRzIZ-00005I-G3 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 10:27:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:42019 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRzIZ-0007w9-29 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 10:27:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-9TghyhhrNxmFCInFRuczyg-1; Fri, 24 Apr 2020 10:27:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA65019057B7; Fri, 24 Apr 2020 14:27:09 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-114-114.ams2.redhat.com [10.36.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D1EE60C05; Fri, 24 Apr 2020 14:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587738435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C4LnEPGFSo/zjI8jEGxKIjBxusRHCEQBZA/zMU3R2RI=; b=cMVnyDBgodsKW6XcfQY3zYQnCvzKSmt4wzUHKDkWGjGKZ5ZKMg/ksoHd0vGkSh5/MQae+0 2oPnZVfBTGIKJP+4LFNqnlhi1jCE4DgmxvEtkA8s9XAbxTcxn0FcwkpnAiyh4c67K18Liq ebObCljQud6RUCHgBe4vOsdyA2JxDmk= X-MC-Unique: 9TghyhhrNxmFCInFRuczyg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v7 10/10] qcow2: Forward ZERO_WRITE flag for full preallocation Date: Fri, 24 Apr 2020 16:27:01 +0200 Message-Id: <20200424142701.67053-1-kwolf@redhat.com> In-Reply-To: <20200424125448.63318-1-kwolf@redhat.com> References: <20200424125448.63318-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:54:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: kwolf@redhat.com, vsementsov@virtuozzo.com, berto@igalia.com, qemu-devel@nongnu.org, mreitz@redhat.com 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_REQ_ZERO_WRITE is currently implemented in a way that first the image is possibly preallocated and then the zero flag is added to all clusters. This means that a copy-on-write operation may be needed when writing to these clusters, despite having used preallocation, negating one of the major benefits of preallocation. Instead, try to forward the BDRV_REQ_ZERO_WRITE to the protocol driver, and if the protocol driver can ensure that the new area reads as zeros, we can skip setting the zero flag in the qcow2 layer. Unfortunately, the same approach doesn't work for metadata preallocation, so we'll still set the zero flag there. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 22 +++++++++++++++++++--- tests/qemu-iotests/274.out | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 98065d7808..2ba0b17c39 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4170,9 +4170,25 @@ static int coroutine_fn qcow2_co_truncate(BlockDrive= rState *bs, int64_t offset, /* Allocate the data area */ new_file_size =3D allocation_start + nb_new_data_clusters * s->cluster_size; - /* Image file grows, so @exact does not matter */ - ret =3D bdrv_co_truncate(bs->file, new_file_size, false, prealloc,= 0, - errp); + /* + * Image file grows, so @exact does not matter. + * + * If we need to zero out the new area, try first whether the prot= ocol + * driver can already take care of this. + */ + if (flags & BDRV_REQ_ZERO_WRITE) { + ret =3D bdrv_co_truncate(bs->file, new_file_size, false, preal= loc, + BDRV_REQ_ZERO_WRITE, NULL); + if (ret >=3D 0) { + flags &=3D ~BDRV_REQ_ZERO_WRITE; + } + } else { + ret =3D -1; + } + if (ret < 0) { + ret =3D bdrv_co_truncate(bs->file, new_file_size, false, preal= loc, 0, + errp); + } if (ret < 0) { error_prepend(errp, "Failed to resize underlying file: "); qcow2_free_clusters(bs, allocation_start, diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out index 1a796fd07c..9d6fdeb1f7 100644 --- a/tests/qemu-iotests/274.out +++ b/tests/qemu-iotests/274.out @@ -187,7 +187,7 @@ read 65536/65536 bytes at offset 9437184 10 MiB (0xa00000) bytes allocated at offset 5 MiB (0x500000) =20 [{ "start": 0, "length": 5242880, "depth": 1, "zero": true, "data": false}, -{ "start": 5242880, "length": 10485760, "depth": 0, "zero": true, "data": = false, "offset": 327680}] +{ "start": 5242880, "length": 10485760, "depth": 0, "zero": false, "data":= true, "offset": 327680}] =20 =3D=3D=3D preallocation=3Dfull =3D=3D=3D Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D16777216 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 @@ -206,7 +206,7 @@ read 65536/65536 bytes at offset 11534336 4 MiB (0x400000) bytes allocated at offset 8 MiB (0x800000) =20 [{ "start": 0, "length": 8388608, "depth": 1, "zero": true, "data": false}, -{ "start": 8388608, "length": 4194304, "depth": 0, "zero": true, "data": f= alse, "offset": 327680}] +{ "start": 8388608, "length": 4194304, "depth": 0, "zero": false, "data": = true, "offset": 327680}] =20 =3D=3D=3D preallocation=3Doff =3D=3D=3D Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D393216 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 --=20 2.25.3