From nobody Mon Feb 9 03:13:03 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=1587654571; cv=none; d=zohomail.com; s=zohoarc; b=CCKLZe6/2dy5DH+/9tEK9t/rbQAPXHw0k7xh/8qukBp6l+0Rm7OBXS0VYGvJrYe+DlGL1qBwyuN45hzRtyrPjZj2WwDyuQL6TJtu74JmdGvE9/HVUGolXes1WeKyJJSuY0cR4G0yh8mkt/47Rg7v4EQ43jNrCWCEvCXzDRFbj6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587654571; 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=Y2cqhM0E1bEKC/9lcpTQwkAhtbzAs7FyjA2Zy3RAW3s=; b=NSDy4sekqXAuiiQMDH3lhR5vYFaiuxOTzoN5nhHGljI4feDEcifuc7bv8Nu1ivUfpuu0nz+r0sokPLckUzwOX+wC2ZeNd27jmyuMoYkMJxUjFDU+UUe1Z481ccbigTY/L1vvwYFLe5lZRriJ4CmsN/Z1tCj9/sTmoQsorXyo+L8= 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 1587654571116100.07033751433414; Thu, 23 Apr 2020 08:09:31 -0700 (PDT) Received: from localhost ([::1]:45224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRdTl-00080t-FX for importer@patchew.org; Thu, 23 Apr 2020 11:09:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41174) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRdMp-0005YO-M8 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 11:02:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRdMo-0006E6-V8 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 11:02:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52143 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 1jRdMo-0006DG-FY for qemu-devel@nongnu.org; Thu, 23 Apr 2020 11:02:18 -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-479-BDRbcyOIPE2N1XXN94C_Mg-1; Thu, 23 Apr 2020 11:02:15 -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 11F1A107ACF2; Thu, 23 Apr 2020 15:02:14 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-114-28.ams2.redhat.com [10.36.114.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C24B610AB; Thu, 23 Apr 2020 15:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587654137; 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=Y2cqhM0E1bEKC/9lcpTQwkAhtbzAs7FyjA2Zy3RAW3s=; b=KWVPZDlvwAWSizvEcHxjpGd0XodkezYsg1KStB5hEFHq1woaiuhjkrqBezt2fNnX+Aomu0 7zwl6Z9tk9rkVfV2i/N3KDwlNDCnCfsbdinynCsxsUHF3RiYpkgx+Q042J8ws4TBFcNSpf tRkrWvg15+8Tm5qQ81km1mn7yPAJQ6s= X-MC-Unique: BDRbcyOIPE2N1XXN94C_Mg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v6 10/10] qcow2: Forward ZERO_WRITE flag for full preallocation Date: Thu, 23 Apr 2020 17:01:27 +0200 Message-Id: <20200423150127.142609-11-kwolf@redhat.com> In-Reply-To: <20200423150127.142609-1-kwolf@redhat.com> References: <20200423150127.142609-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=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/23 06:43:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.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 --- 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 ad621fe404..b28e588942 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, errp); + 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 179bd7ccaf..c355b52689 100644 --- a/tests/qemu-iotests/274.out +++ b/tests/qemu-iotests/274.out @@ -179,7 +179,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 @@ -198,7 +198,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