From nobody Sun Feb 8 05:12:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687523979; cv=none; d=zohomail.com; s=zohoarc; b=iAHl4SBigY34ogAEBYPYf0b8LSUcwQE0Hkt4hX4Zmy9Pt/I+2QBxmyT0pvlbBOiYqOpsHhHztqPfcd6dQl3SB8T08bs5VUNleYaX4cRMJhfOmci83CqeEnqyir/UCsseT5DL5QV9mfU7SPDNf3WuliU/riiY89ycXv4NocHLcZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687523979; 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=4YA06G2J9Wf0jW2bWUBfPCd93kdS3Hbie5NgXZ1voK4=; b=bUgA97M/eAYUBYkn6G34r/JhRy3R1UvHeFKdLk4SU/ChZU0ODu7UmNSM87TqcSkm9/HQyUjp8OkS/Wjn4TZYt7JOWj6KMWhbOTquyadFSOu+90MZKrbA7rOmWK7iAUNA0fKaxeacUWcbuB1Xu035TvxRoWB5i4eLcIMqOCBHGdA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1687523979851856.8049361989598; Fri, 23 Jun 2023 05:39:39 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-48-aoHTtDAVNDOSWM8IiBT-Zw-1; Fri, 23 Jun 2023 08:39:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38E6229DD989; Fri, 23 Jun 2023 12:39:34 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17CECF5AE3; Fri, 23 Jun 2023 12:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9F7041946588; Fri, 23 Jun 2023 12:39:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 52C3E1946587 for ; Fri, 23 Jun 2023 12:39:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 323BC40C2070; Fri, 23 Jun 2023 12:39:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86BBF40C2063; Fri, 23 Jun 2023 12:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687523978; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4YA06G2J9Wf0jW2bWUBfPCd93kdS3Hbie5NgXZ1voK4=; b=DW0n3Xv+YKRBVoj+fwhpFAUlBOu7MKug9Wfy0VfYYi+JHTnk3lvDpgszrkc00LXCIwgRHs s8XbrV3ccgQRBEcqeqvMw2g+1cjQK48lpFjTD3hWF0f66knxYtGVBClk7r+07BJvAvaXkW ndk6zpfqKuJHDC94hxBqEzhcg4MI7PM= X-MC-Unique: aoHTtDAVNDOSWM8IiBT-Zw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v3 1/3] qemu: capabilities: Introduce QEMU_CAPS_QCOW2_DISCARD_NO_UNREF Date: Fri, 23 Jun 2023 14:39:22 +0200 Message-Id: <8ad5dbfc0f18d6854296ff13a1cf884bef152a9c.1687523851.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687523980860100001 Content-Type: text/plain; charset="utf-8" The qcow2 driver allows passing discards to the storage while keeping the reference of the block, and just marking it as zeroed. This can decrease the levels of fragmentation of the qcow2 metadata when discards are enabled. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml | 1 + 3 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 0552486805..7dad7231ee 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -693,6 +693,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "virtio-gpu.blob", /* QEMU_CAPS_VIRTIO_GPU_BLOB */ "rbd-encryption-layering", /* QEMU_CAPS_RBD_ENCRYPTION_LAYER= ING */ "rbd-encryption-luks-any", /* QEMU_CAPS_RBD_ENCRYPTION_LUKS_= ANY */ + "qcow2-discard-no-unref", /* QEMU_CAPS_QCOW2_DISCARD_NO_UNRE= F */ ); @@ -1536,6 +1537,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "blockdev-add/arg-type/+rbd/encrypt/parent", QEMU_CAPS_RBD_ENCRYPTIO= N_LAYERING }, { "blockdev-add/arg-type/+rbd/encrypt/format/^luks-any", QEMU_CAPS_RBD= _ENCRYPTION_LUKS_ANY }, { "blockdev-add/arg-type/+nbd/tls-hostname", QEMU_CAPS_BLOCKDEV_NBD_TL= S_HOSTNAME }, + { "blockdev-add/arg-type/+qcow2/discard-no-unref", QEMU_CAPS_QCOW2_DIS= CARD_NO_UNREF }, { "blockdev-snapshot/$allow-write-only-overlay", QEMU_CAPS_BLOCKDEV_SN= APSHOT_ALLOW_WRITE_ONLY }, { "chardev-add/arg-type/backend/+socket/data/reconnect", QEMU_CAPS_CHA= RDEV_RECONNECT }, { "device_add/$json-cli-hotplug", QEMU_CAPS_DEVICE_JSON }, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 3b55aed07a..ce545cb2cc 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -672,6 +672,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_VIRTIO_GPU_BLOB, /* -device virtio-gpu-*.blob=3D */ QEMU_CAPS_RBD_ENCRYPTION_LAYERING, /* layered encryption support for C= eph RBD */ QEMU_CAPS_RBD_ENCRYPTION_LUKS_ANY, /* luks-any (LUKS and LUKS2) encryp= tion format for Ceph RBD */ + QEMU_CAPS_QCOW2_DISCARD_NO_UNREF, /* qcow2 block driver allows discard= s without unrefing the sector */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml b/tests/qemuc= apabilitiesdata/caps_8.1.0_x86_64.xml index 50ed122fa4..58bb206f79 100644 --- a/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_8.1.0_x86_64.xml @@ -206,6 +206,7 @@ + 8000050 43100245 v8.0.0-1619-g369081c455 --=20 2.40.1 From nobody Sun Feb 8 05:12:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687523981; cv=none; d=zohomail.com; s=zohoarc; b=g6dEhNp7DD3JpXTKCW5IgpsXI8yJnhG1TndzIfphQ9pd5tjgslC6st3y0N8v9ow/lD0ZHXNUC+VK4VDmPXCA3XaauuP0SONsCfPwX7gn/8EuF26LbxMgWZVjY8Ef+Q+Z32KG8Vos4btt0tGzSUZMMOS5qyG4/HOQk55pHOHP7ng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687523981; 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=4069/wOUDLcMSmuFMEV0LZIxA7UxXNc42NQOao00rsY=; b=CMvrpAjp+r/hDvp5trbpRBvQAh0uKnE6IfWo1IxmHkm8F2EnHC4fDxr7kHAKAQlxoQVPUjuTW5xHakR/O7ayE2V36hu7LXTbTmsRoTyTh/LKydBRKpKaYQPAjuaXCOBOOeoyYNBf7ToyWekxCvhRmiZ7Rpnq3xZpQiSuT0LiVQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1687523981780667.2051096930539; Fri, 23 Jun 2023 05:39:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-lp-M7NXkN0OyKta2dHTDhA-1; Fri, 23 Jun 2023 08:39:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A5683813F46; Fri, 23 Jun 2023 12:39:34 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8188314682FC; Fri, 23 Jun 2023 12:39:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 875E5194658D; Fri, 23 Jun 2023 12:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ADE191946594 for ; Fri, 23 Jun 2023 12:39:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A17E940C2072; Fri, 23 Jun 2023 12:39:30 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DAC640C2063; Fri, 23 Jun 2023 12:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687523980; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4069/wOUDLcMSmuFMEV0LZIxA7UxXNc42NQOao00rsY=; b=aYCdsx/oiN29qgA3AtRlfy6O2tuNzo6eijltzAAT8aPaoNTSmJYmgyzg0i6MXkc63p0ed+ jShiFXiGZf4Fa15azpYkArIef7APCc55n6s1W20w62gY0W49o5PET37/AdWaXgAx3IGG/Y +mQ/ET6PunhjyHadHSyCDy5Hgbsthig= X-MC-Unique: lp-M7NXkN0OyKta2dHTDhA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v3 2/3] Add discard_no_unref option for qcow2 images Date: Fri, 23 Jun 2023 14:39:23 +0200 Message-Id: <76fe5fc77eb47bee8bb75e4d6a7f49b8dc941b00.1687523851.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Krempa , Jean-Louis Dupond Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687523983122100001 Content-Type: text/plain; charset="utf-8" From: Jean-Louis Dupond Qemu 8.1.0 will add discard_no_unref option for qcow2 images. When this option is enabled (default=3Dfalse), then it will no longer unreference clusters when guest does a discard, but it will just free the blocks (useful for incremental backups for example) and pass the discard to the lower layer. This was implemented to avoid fragmentation within the qcow2 image. Signed-off-by: Jean-Louis Dupond Reviewed-by: Peter Krempa Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/formatdomain.rst | 7 ++++ src/conf/domain_conf.c | 8 ++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 14 +++++++ src/conf/schemas/domaincommon.rng | 5 +++ src/conf/storage_source_conf.c | 1 + src/conf/storage_source_conf.h | 1 + src/qemu/qemu_block.c | 11 +++-- src/qemu/qemu_domain.c | 1 + src/qemu/qemu_driver.c | 4 +- src/qemu/qemu_validate.c | 7 ++++ src/vz/vz_utils.c | 6 +++ .../disk-discard_no_unref.x86_64-latest.args | 36 ++++++++++++++++ .../disk-discard_no_unref.xml | 32 ++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../disk-discard_no_unref.x86_64-latest.xml | 42 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 17 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-discard_no_unref.x86_64-lat= est.args create mode 100644 tests/qemuxml2argvdata/disk-discard_no_unref.xml create mode 100644 tests/qemuxml2xmloutdata/disk-discard_no_unref.x86_64-l= atest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index c3526439bf..2ea440e1a1 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3284,6 +3284,13 @@ paravirtualized driver is specified via the ``disk``= element. format driver of the ``qemu`` hypervisor can be controlled via the ``max_size`` subelement (see example below). + The optional ``discard_no_unref`` attribute can be set to control th= e way + the ``qemu`` hypervisor handles guest discard commands inside the qc= ow2 + image. When enabled, a discard request from within the guest will ma= rk the + qcow2 cluster as zero, but will keep the reference/offset of that cl= uster. + But it will still pass the discard further to the lower layer. + This will resolve fragmentation within the qcow2 image. :since:`Sinc= e 9.5.0` + In the majority of cases the default configuration used by the hyper= visor is sufficient so modifying this setting should not be necessary. For specifics on how the metadata cache of ``qcow2`` in ``qemu`` behaves= refer diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0edb1bda9d..f28cb64eb5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7826,6 +7826,10 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, if (virXMLPropUInt(cur, "queue_size", 10, VIR_XML_PROP_NONE, &def->que= ue_size) < 0) return -1; + if (virXMLPropTristateSwitch(cur, "discard_no_unref", VIR_XML_PROP_NON= E, + &def->discard_no_unref) < 0) + return -1; + return 0; } @@ -22501,6 +22505,10 @@ virDomainDiskDefFormatDriver(virBuffer *buf, virBufferAsprintf(&attrBuf, " detect_zeroes=3D'%s'", virDomainDiskDetectZeroesTypeToString(disk->dete= ct_zeroes)); + if (disk->discard_no_unref) + virBufferAsprintf(&attrBuf, " discard_no_unref=3D'%s'", + virTristateSwitchTypeToString(disk->discard_no_u= nref)); + if (disk->queues) virBufferAsprintf(&attrBuf, " queues=3D'%u'", disk->queues); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 629e32c39f..cddaa3824d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -606,6 +606,7 @@ struct _virDomainDiskDef { virDomainDiskDiscard discard; unsigned int iothread; /* unused =3D 0, > 0 specific thread # */ virDomainDiskDetectZeroes detect_zeroes; + virTristateSwitch discard_no_unref; char *domain_name; /* backend domain name */ unsigned int queues; unsigned int queue_size; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 7e3c920a38..6c4cfa16d6 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -921,6 +921,20 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } + if (disk->discard_no_unref =3D=3D VIR_TRISTATE_SWITCH_ON) { + if (disk->src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'discard_no_unref' only works with qcow2 dis= k format")); + return -1; + } + + if (disk->src->readonly) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'discard_no_unref' is not compatible with re= ad-only disk")); + return -1; + } + } + return 0; } diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index c1725bb511..87822adcf7 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2514,6 +2514,11 @@ + + + + + diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 99061e4df7..dcac3a8ff6 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -809,6 +809,7 @@ virStorageSourceCopy(const virStorageSource *src, def->cachemode =3D src->cachemode; def->discard =3D src->discard; def->detect_zeroes =3D src->detect_zeroes; + def->discard_no_unref =3D src->discard_no_unref; def->sslverify =3D src->sslverify; def->readahead =3D src->readahead; def->timeout =3D src->timeout; diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index c6187dda59..f13e7c756a 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -399,6 +399,7 @@ struct _virStorageSource { int cachemode; /* enum virDomainDiskCache */ int discard; /* enum virDomainDiskDiscard */ int detect_zeroes; /* enum virDomainDiskDetectZeroes */ + virTristateSwitch discard_no_unref; bool floppyimg; /* set to true if the storage source is going to be us= ed as a source for floppy drive */ diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 8b2159f845..dcdf883926 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1117,12 +1117,11 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorag= eSource *src, * see: qemu.git/docs/qcow2-cache.txt * https://git.qemu.org/?p=3Dqemu.git;a=3Dblob;f=3Ddocs/qcow2-cache.txt */ - if (src->metadataCacheMaxSize > 0) { - if (virJSONValueObjectAdd(&props, - "U:cache-size", src->metadataCacheMaxSiz= e, - NULL) < 0) - return -1; - } + if (virJSONValueObjectAdd(&props, + "P:cache-size", src->metadataCacheMaxSize, + "T:discard-no-unref", src->discard_no_unref, + NULL) < 0) + return -1; return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8f77e8fc58..a22dac9884 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11022,6 +11022,7 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDef *d= isk, src->iomode =3D disk->iomode; src->cachemode =3D disk->cachemode; src->discard =3D disk->discard; + src->discard_no_unref =3D disk->discard_no_unref; if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) src->floppyimg =3D true; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c4bd766531..f20544590d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14242,8 +14242,10 @@ qemuDomainBlockCopyCommon(virDomainObj *vm, * into the topmost virStorage source of the disk chain. * Since 'mirror' has the ambition to replace it we need to propagate * it into the mirror too. We do it directly as otherwise we'd need - * to modify all callers of 'qemuDomainPrepareStorageSourceBlockdev' */ + * to modify all callers of 'qemuDomainPrepareStorageSourceBlockdev' + * Same for discard_no_unref */ mirror->detect_zeroes =3D disk->detect_zeroes; + mirror->discard_no_unref =3D disk->discard_no_unref; /* If reusing an external image that includes a backing file but the u= ser * did not enumerate the chain in the XML we need to detect the chain = */ diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 04d0c9df73..a53729d349 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -3266,6 +3266,13 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskD= ef *disk, return -1; } + if (disk->discard_no_unref !=3D VIR_TRISTATE_SWITCH_ABSENT && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_QCOW2_DISCARD_NO_UNREF)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'discard_no_unref' is not supported by this QEMU= binary")); + return -1; + } + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { if (qemuDomainValidateStorageSource(n, qemuCaps) < 0) return -1; diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index 2db1146149..7db7dbd419 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -347,6 +347,12 @@ vzCheckDiskUnsupportedParams(virDomainDiskDef *disk) return -1; } + if (disk->discard_no_unref) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Disk discard_no_unref is not supported by vz dri= ver.")); + return -1; + } + if (disk->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_DEFAULT) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Setting up disk startup policy is not " diff --git a/tests/qemuxml2argvdata/disk-discard_no_unref.x86_64-latest.arg= s b/tests/qemuxml2argvdata/disk-discard_no_unref.x86_64-latest.args new file mode 100644 index 0000000000..b9e2939335 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-discard_no_unref.x86_64-latest.args @@ -0,0 +1,36 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-test/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-test/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel tcg \ +-cpu qemu64 \ +-m 1024 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}= ' \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot menu=3Don,strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/f14.img","= node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"discard":"un= map","driver":"qcow2","discard-no-unref":true,"file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-1-format","id":"virtio-disk0","bootindex":2}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-discard_no_unref.xml b/tests/qemux= ml2argvdata/disk-discard_no_unref.xml new file mode 100644 index 0000000000..d5dd054a85 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-discard_no_unref.xml @@ -0,0 +1,32 @@ + + test + 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e + 1048576 + 1048576 + 1 + + hvm + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + +
+ + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d914d8cbea..2dda9c4501 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1245,6 +1245,7 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-copy_on_read"); DO_TEST_CAPS_LATEST("disk-discard"); DO_TEST_CAPS_LATEST("disk-detect-zeroes"); + DO_TEST_CAPS_LATEST("disk-discard_no_unref"); DO_TEST_CAPS_LATEST("disk-snapshot"); DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-same-targets"); DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-missing-target-invalid"); diff --git a/tests/qemuxml2xmloutdata/disk-discard_no_unref.x86_64-latest.x= ml b/tests/qemuxml2xmloutdata/disk-discard_no_unref.x86_64-latest.xml new file mode 100644 index 0000000000..c57acf99dc --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-discard_no_unref.x86_64-latest.xml @@ -0,0 +1,42 @@ + + test + 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e + 1048576 + 1048576 + 1 + + hvm + + + + + + qemu64 + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + + + +
+ + +
+ + +
+ + + + +