From nobody Mon Feb 9 07:43:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1610031626; cv=none; d=zohomail.com; s=zohoarc; b=S3aNvgA6i9eF5rjhLsHm5Idyob6otwMaPn3vO9Lv4fEfqEn8yObhZyyePrUzyXCQhOAVROi+Apjb55BwhJI/ttmmznYuZ/JU3J1V6ZyBQDK6N/RkV8mhXb1g+YZ6+so3LQK1Mdif5UqbGOnpHOAw/afNgll/hwzNfAINIdudc/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610031626; h=Content-Type:Content-Transfer-Encoding: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=Zc5dkQjJjP5GZe1+BASGpdZOEuZckqeB/hb2jYBBt5U=; b=UIA79xaGcn1QrqUOD4wmn2SkTVChM0+rSNY9GKs5jwV1BY+qaKhRNKwNk29dIfq0k0l3TuQAJ95gT4RMDFBeZ/yw0cP2G06TGY4jHxkYQSDdEkICPZdZoi8k07t7q1PQ8zFVa6GF6UMmeVfjlUCdnbpHcplrghzWnxL2kaP/RTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1610031626116524.0623876182741; Thu, 7 Jan 2021 07:00:26 -0800 (PST) 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-449-Zg7btgEvM_GBHInFjpBfog-1; Thu, 07 Jan 2021 10:00:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFB608145E5; Thu, 7 Jan 2021 14:59:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C727110013C0; Thu, 7 Jan 2021 14:59:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 917611809C9F; Thu, 7 Jan 2021 14:59:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 107ExltB005535 for ; Thu, 7 Jan 2021 09:59:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id A8131177F8; Thu, 7 Jan 2021 14:59:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95FA45E1A7 for ; Thu, 7 Jan 2021 14:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610031624; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=Zc5dkQjJjP5GZe1+BASGpdZOEuZckqeB/hb2jYBBt5U=; b=ZQ8Ym6DZZd2rzpOHDIRJC3n/zNSbGFE32p5KwQfgb+6ouQ2yr0hedRJzvJ9jezRr6/n/JB v1YpPMDVtclM2OygtWPFegwnGHetmRGi+fpMOCOypaCuVILr3w3k0zz1LcMKuCGEsiszLU BUktKnqMMcJ5D6+y5zKIx7/33bsZoMk= X-MC-Unique: Zg7btgEvM_GBHInFjpBfog-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] conf: Introduce subelement of Date: Thu, 7 Jan 2021 15:59:36 +0100 Message-Id: <7d432f4457de7e3333eb8420e1422cf75c090c80.1610031539.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In certain specific cases it might be beneficial to be able to control the metadata caching of storage image format drivers of a hypervisor. Introduce XML machinery to set the maximum size of the metadata cache which will be used by qemu's qcow2 driver. Signed-off-by: Peter Krempa --- docs/formatdomain.rst | 43 ++++++++++++++ docs/schemas/domaincommon.rng | 20 ++++++- src/conf/domain_conf.c | 51 ++++++++++++++-- src/util/virstoragefile.c | 1 + src/util/virstoragefile.h | 2 + .../qemuxml2argvdata/disk-metadata-cache.xml | 46 +++++++++++++++ .../disk-metadata-cache.x86_64-latest.xml | 58 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 8 files changed, 216 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-metadata-cache.xml create mode 100644 tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-lat= est.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 1189795974..abf85064fa 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2735,6 +2735,11 @@ paravirtualized driver is specified via the ``disk``= element. ``format`` The ``format`` element contains ``type`` attribute which specifies t= he internal format of the backing store, such as ``raw`` or ``qcow2``. + + The ``format`` element can contain ``metadata_cache`` subelement, wh= ich + has identical semantics to the identically named subelement of ``dri= ver`` + of a ``disk``. + ``source`` This element has the same structure as the ``source`` element in ``d= isk``. It specifies which file, device, or network location contains the da= ta of @@ -2947,6 +2952,44 @@ paravirtualized driver is specified via the ``disk``= element. virtio-blk. ( :since:`Since 3.9.0` ) - For virtio disks, `Virtio-specific options <#elementsVirtio>`__ can = also be set. ( :since:`Since 3.5.0` ) + - The optional ``metadata_cache`` subelement controls aspects related = to the + format specific caching of storage image metadata. Note that this se= tting + applies only on the top level image; the identically named subleleme= nt of + ``backingStore``'s ``format`` element can be used to specify cache + settings for the backing image. + + :since:`Since 7.0.0` the maximum size of the metadata cache of ``qco= w2`` + format driver of the ``qemu`` hypervisor can be controlled via the + ``max_size`` subelement (see example below). + + 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 + to the ``qemu`` + `qcow2 cache docs `__ + + **Example:** + +:: + + + + + 1234 + + + + + + + 1234 + + + + + + + ``backenddomain`` The optional ``backenddomain`` element allows specifying a backend doma= in diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 24b4994670..56946a621a 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1600,7 +1600,15 @@ - + + + + + + + + + @@ -2245,7 +2253,15 @@ - + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3e1dccb1b8..ddacc6443b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8589,6 +8589,12 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ct= xt, if (!(backingStore =3D virDomainStorageSourceParseBase(type, format, i= dx))) return -1; + if (virParseScaledValue("./format/metadata_cache/max_size", NULL, + ctxt, + &backingStore->metadataCacheMaxSize, + 1, ULLONG_MAX, false) < 0) + return -1; + /* backing store is always read-only */ backingStore->readonly =3D true; @@ -8939,9 +8945,13 @@ virDomainDiskDefParseValidate(const virDomainDiskDef= *def) static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, - xmlNodePtr cur) + xmlNodePtr cur, + xmlXPathContextPtr ctxt) { g_autofree char *tmp =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D cur; def->driverName =3D virXMLPropString(cur, "name"); @@ -9051,6 +9061,12 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr d= ef, return -1; } + if (virParseScaledValue("./metadata_cache/max_size", NULL, + ctxt, + &def->src->metadataCacheMaxSize, + 1, ULLONG_MAX, false) < 0) + return -1; + return 0; } @@ -9207,7 +9223,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) return NULL; - if (virDomainDiskDefDriverParseXML(def, cur) < 0) + if (virDomainDiskDefDriverParseXML(def, cur, ctxt) < 0) return NULL; } else if (!def->mirror && virXMLNodeNameEqual(cur, "mirror") && @@ -24050,6 +24066,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, { g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) formatAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) formatChildBuf =3D VIR_BUFFER_INIT_CHILD(&childBuf); bool inactive =3D flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE; virStorageSourcePtr backingStore =3D src->backingStore; @@ -24077,8 +24095,22 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, if (backingStore->id !=3D 0) virBufferAsprintf(&attrBuf, " index=3D'%u'", backingStore->id); - virBufferAsprintf(&childBuf, "\n", + virBufferAsprintf(&formatAttrBuf, " type=3D'%s'", virStorageFileFormatTypeToString(backingStore->forma= t)); + + if (backingStore->metadataCacheMaxSize > 0) { + g_auto(virBuffer) metadataCacheChildBuf =3D VIR_BUFFER_INIT_CHILD(= &formatChildBuf); + + virBufferAsprintf(&metadataCacheChildBuf, + "%llu\n", + backingStore->metadataCacheMaxSize); + + virXMLFormatElement(&formatChildBuf, "metadata_cache", NULL, &meta= dataCacheChildBuf); + } + + virXMLFormatElement(&childBuf, "format", &formatAttrBuf, &formatChildB= uf); + + if (virDomainDiskSourceFormat(&childBuf, backingStore, "source", 0, fa= lse, flags, false, false, xmlopt) < 0) return -1; @@ -24146,6 +24178,7 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, virDomainDiskDefPtr disk) { g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); virBufferEscapeString(&attrBuf, " name=3D'%s'", virDomainDiskGetDriver= (disk)); @@ -24197,7 +24230,17 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, virDomainVirtioOptionsFormat(&attrBuf, disk->virtio); - virXMLFormatElement(buf, "driver", &attrBuf, NULL); + if (disk->src->metadataCacheMaxSize > 0) { + g_auto(virBuffer) metadataCacheChildBuf =3D VIR_BUFFER_INIT_CHILD(= &childBuf); + + virBufferAsprintf(&metadataCacheChildBuf, + "%llu\n", + disk->src->metadataCacheMaxSize); + + virXMLFormatElement(&childBuf, "metadata_cache", NULL, &metadataCa= cheChildBuf); + } + + virXMLFormatElement(buf, "driver", &attrBuf, &childBuf); } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 3db85d8b89..f870657dd8 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2216,6 +2216,7 @@ virStorageSourceCopy(const virStorageSource *src, def->sslverify =3D src->sslverify; def->readahead =3D src->readahead; def->timeout =3D src->timeout; + def->metadataCacheMaxSize =3D src->metadataCacheMaxSize; /* storage driver metadata are not copied */ def->drv =3D NULL; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 2452b967b2..205db1b997 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -321,6 +321,8 @@ struct _virStorageSource { unsigned long long clusterSize; /* in bytes, 0 if unknown */ bool has_allocation; /* Set to true when provided in XML */ + unsigned long long metadataCacheMaxSize; /* size of the metadata cache= in bytes */ + size_t nseclabels; virSecurityDeviceLabelDefPtr *seclabels; diff --git a/tests/qemuxml2argvdata/disk-metadata-cache.xml b/tests/qemuxml= 2argvdata/disk-metadata-cache.xml new file mode 100644 index 0000000000..d79f194eee --- /dev/null +++ b/tests/qemuxml2argvdata/disk-metadata-cache.xml @@ -0,0 +1,46 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + 12345 + + + + +
+ + + + + + + + 1024 + + + + + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml= b/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml new file mode 100644 index 0000000000..7104151a10 --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-metadata-cache.x86_64-latest.xml @@ -0,0 +1,58 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + 12345 + + + + +
+ + + + + + + + 1048576 + + + + + + +
+ + +
+ + +
+ + + + + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index f8bca9f559..093fceea3e 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -294,6 +294,7 @@ mymain(void) DO_TEST_CAPS_VER("disk-cache", "2.7.0"); DO_TEST_CAPS_VER("disk-cache", "2.12.0"); DO_TEST_CAPS_LATEST("disk-cache"); + DO_TEST_CAPS_LATEST("disk-metadata-cache"); DO_TEST("disk-network-nbd", NONE); DO_TEST("disk-network-iscsi", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_BLOCK); --=20 2.29.2