From nobody Thu May 15 21:09:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1505367321514667.7980370093326; Wed, 13 Sep 2017 22:35:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C979C04B303; Thu, 14 Sep 2017 05:35:20 +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 4FDBC6294B; Thu, 14 Sep 2017 05:35:20 +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 10F7A1806107; Thu, 14 Sep 2017 05:35:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8E56kUY014437 for ; Thu, 14 Sep 2017 01:06:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id A678B2023584; Thu, 14 Sep 2017 05:06:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.rdu2.redhat.com [10.11.55.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A210F2023581 for ; Thu, 14 Sep 2017 05:06:46 +0000 (UTC) Received: from mx1.ioa.cn (mx0.ioa.cn [103.231.69.152]) by mx1.redhat.com (Postfix) with ESMTP id DDCCB7C6C4 for ; Thu, 14 Sep 2017 05:06:41 +0000 (UTC) Received: by xxx.smtp.chinacmail.com (Postfix, from userid 12301) id BE603C0699; Thu, 14 Sep 2017 13:06:37 +0800 (CST) Received: from host-172-16-90-85.localdomain (unknown [221.228.240.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by xxx.smtp.chinacmail.com (Postfix) with ESMTPSA id 88F9CC05C8; Thu, 14 Sep 2017 13:06:37 +0800 (CST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C979C04B303 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huayun.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7C979C04B303 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DDCCB7C6C4 Authentication-Results: ext-mx02.extmail.prod.ext.rdu2.redhat.com; dmarc=none (p=none dis=none) header.from=huayun.com Authentication-Results: ext-mx02.extmail.prod.ext.rdu2.redhat.com; spf=none smtp.mailfrom=liuqing@huayun.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DDCCB7C6C4 X-HY-TRUST: YES X-HY-SID: 43292.92.1505365598.475554 X-HY-SPAM: NO From: Liu Qing To: libvir-list@redhat.com Date: Thu, 14 Sep 2017 13:08:23 +0800 Message-Id: <1505365704-11941-2-git-send-email-liuqing@huayun.com> In-Reply-To: <1505365704-11941-1-git-send-email-liuqing@huayun.com> References: <1505365704-11941-1-git-send-email-liuqing@huayun.com> X-Greylist: Delayed for 19:46:59 by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 14 Sep 2017 05:06:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 14 Sep 2017 05:06:43 +0000 (UTC) for IP:'103.231.69.152' DOMAIN:'mx0.ioa.cn' HELO:'mx1.ioa.cn' FROM:'liuqing@huayun.com' RCPT:'' X-RedHat-Spam-Score: 1.5 * (BAYES_60) 103.231.69.152 mx0.ioa.cn 103.231.69.152 mx0.ioa.cn X-Scanned-By: MIMEDefang 2.78 on 10.11.55.2 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Liu Qing Subject: [libvirt] [PATCH v5 1/2] conf, docs: Add qcow2 cache configuration support 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 14 Sep 2017 05:35:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Random write IOPS will drop dramatically if qcow2 l2 cache could not cover the whole disk. This patch gives libvirt user a chance to adjust the qcow2 cache configuration. Three new qcow2 driver parameters (l2-cache-size, refcount-cache-size and cache-clean-interval) are added as attributes to a new subelement for a of a element. The QEMU source docs/qcow2-cache.txt provides the guidelines for defining/configuring values for each. Signed-off-by: Liu Qing --- docs/formatdomain.html.in | 41 +++++++++ docs/schemas/domaincommon.rng | 35 ++++++++ src/conf/domain_conf.c | 96 ++++++++++++++++++= ++-- src/qemu/qemu_driver.c | 5 ++ src/util/virstoragefile.c | 3 + src/util/virstoragefile.h | 6 ++ .../qemuxml2argv-disk-drive-qcow2-cache.xml | 43 ++++++++++ .../qemuxml2xmlout-disk-drive-qcow2-cache.xml | 43 ++++++++++ tests/qemuxml2xmltest.c | 1 + 9 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-ca= che.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow= 2-cache.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 8ca7637..4574e3a 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -3036,6 +3036,47 @@ set. (Since 3.5.0) + The driver element may contain a qcow2 s= ub + element, which to specifying further details related to a qcow2 di= sk. + For recommended setting guidelines refer to the QEMU source file + docs/qcow2-cache.txt. + Since 3.8.0 +
    +
  • + The optional l2_cache_size attribute controls how= much + memory will be consumed by qcow2 l2 table cache in bytes. This + option is only valid when the driver type is qcow2. The default + size is 2097152. + Since 3.8.0 + + In general you should leave this option alone, unless you + are very certain you know what you are doing. +
  • +
  • + The optional refcount_cache_size attribute contro= ls + how much memory will be consumed by qcow2 reference count table + cache in bytes. This option is only valid when the driver type= is + qcow2. The default size is 262144. + Since 3.8.0 + + In general you should leave this option alone, unless you + are very certain you know what you are doing. +
  • +
  • + The optional cache_clean_interval attribute defin= es + an interval (in seconds). All cache entries that haven't been + accessed during that interval are removed from memory. This op= tion + is only valid when the driver type is qcow2. The default + value is 0, which disables this feature. If the interval is too + short, it will cause frequent cache write back and load, which + impact performance. If the interval is too long, unused cache + will still consume memory until it's been written back to disk. + Since 3.8.0 + + In general you should leave this option alone, unless you + are very certain you know what you are doing. +
  • +
backenddomain
The optional backenddomain element allows specifyin= g a diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index c9a4f7a..0e25f44 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1756,6 +1756,23 @@ + + + + + + + + + + + + + + + @@ -1794,6 +1811,9 @@ + + + @@ -1889,6 +1909,21 @@ + + + + + + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a43b25c..e29ecb5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5734,6 +5734,30 @@ virDomainDeviceLoadparmIsValid(const char *loadparm) =20 =20 static void +virDomainQcow2CacheOptionsFormat(virBufferPtr buf, + virDomainDiskDefPtr def) +{ + if (def->src->l2_cache_size =3D=3D 0 && + def->src->refcount_cache_size =3D=3D 0 && + def->src->cache_clean_interval =3D=3D 0) + return; + + virBufferAddLit(buf, "src->l2_cache_size > 0) + virBufferAsprintf(buf, " l2_cache_size=3D'%llu'", + def->src->l2_cache_size); + if (def->src->refcount_cache_size > 0) + virBufferAsprintf(buf, " refcount_cache_size=3D'%llu'", + def->src->refcount_cache_size); + if (def->src->cache_clean_interval > 0) + virBufferAsprintf(buf, " cache_clean_interval=3D'%llu'", + def->src->cache_clean_interval); + virBufferAddLit(buf, "/>\n"); +} + + +static void virDomainVirtioOptionsFormat(virBufferPtr buf, virDomainVirtioOptionsPtr virtio) { @@ -8572,15 +8596,69 @@ virDomainDiskDefParseValidate(const virDomainDiskDe= f *def) } } =20 + if (def->src->format !=3D VIR_STORAGE_FILE_QCOW2 && + (def->src->l2_cache_size > 0 || def->src->refcount_cache_size > 0 = || + def->src->cache_clean_interval > 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Setting l2_cache_size, refcount_cache_size, " + "cache_clean_interval is not allowed for types " + "other than QCOW2")); + return -1; + } + return 0; } =20 =20 static int +virDomainDiskDefQcow2ParseXML(virDomainDiskDefPtr def, + xmlNodePtr cur) +{ + char *tmp =3D NULL; + int ret =3D -1; + + if ((tmp =3D virXMLPropString(cur, "l2_cache_size")) && + (virStrToLong_ullp(tmp, NULL, 10, &def->src->l2_cache_size) < 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid l2_cache_size attribute in disk " + "driver element: %s"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + + if ((tmp =3D virXMLPropString(cur, "refcount_cache_size")) && + (virStrToLong_ullp(tmp, NULL, 10, &def->src->refcount_cache_size) = < 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid refcount_cache_size attribute in disk " + "driver element: %s"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + + if ((tmp =3D virXMLPropString(cur, "cache_clean_interval")) && + (virStrToLong_ullp(tmp, NULL, 10, &def->src->cache_clean_interval)= < 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid cache_clean_interval attribute in " + "disk driver element: %s"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + + ret =3D 0; + + cleanup: + VIR_FREE(tmp); + + return ret; +} + + +static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, xmlNodePtr cur) { char *tmp =3D NULL; + xmlNodePtr child; int ret =3D -1; =20 def->src->driverName =3D virXMLPropString(cur, "name"); @@ -8683,6 +8761,13 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr d= ef, } VIR_FREE(tmp); =20 + for (child =3D cur->children; child !=3D NULL; child =3D child->next) { + if (virXMLNodeNameEqual(child, "qcow2") && + virDomainDiskDefQcow2ParseXML(def, child) < 0) { + goto cleanup; + } + } + ret =3D 0; =20 cleanup: @@ -21885,6 +21970,7 @@ virDomainDiskDefFormat(virBufferPtr buf, const char *discard =3D virDomainDiskDiscardTypeToString(def->discard); const char *detect_zeroes =3D virDomainDiskDetectZeroesTypeToString(de= f->detect_zeroes); virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer driverQcow2Buf =3D VIR_BUFFER_INITIALIZER; =20 if (!type || !def->src->type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -21966,11 +22052,11 @@ virDomainDiskDefFormat(virBufferPtr buf, if (virBufferCheckError(&driverBuf) < 0) return -1; =20 - if (virBufferUse(&driverBuf)) { - virBufferAddLit(buf, "\n"); - } + virBufferSetChildIndent(&driverQcow2Buf, buf); + virDomainQcow2CacheOptionsFormat(&driverQcow2Buf, def); + + if (virXMLFormatElement(buf, "driver", &driverBuf, &driverQcow2Buf) < = 0) + return -1; =20 if (def->src->auth) { if (virStorageAuthDefFormat(buf, def->src->auth) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e956839..c3b81e1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14318,6 +14318,11 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr= driver, if (!(dd->src =3D virStorageSourceCopy(snap->def->disks[i].src, fa= lse))) goto error; =20 + /* keep the qcow2 cache configuration */ + dd->src->l2_cache_size =3D vm->def->disks[i]->src->l2_cache_size; + dd->src->refcount_cache_size =3D vm->def->disks[i]->src->refcount_= cache_size; + dd->src->cache_clean_interval =3D vm->def->disks[i]->src->cache_cl= ean_interval; + if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false= ) < 0) goto error; =20 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index e94ad32..f23390f 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2038,6 +2038,9 @@ virStorageSourceCopy(const virStorageSource *src, ret->physical =3D src->physical; ret->readonly =3D src->readonly; ret->shared =3D src->shared; + ret->l2_cache_size =3D src->l2_cache_size; + ret->refcount_cache_size =3D src->refcount_cache_size; + ret->cache_clean_interval =3D src->cache_clean_interval; =20 /* storage driver metadata are not copied */ ret->drv =3D NULL; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 6c388b1..9b5a5f3 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -280,6 +280,12 @@ struct _virStorageSource { /* metadata that allows identifying given storage source */ char *nodeformat; /* name of the format handler object */ char *nodestorage; /* name of the storage object */ + + unsigned long long l2_cache_size; /* qcow2 l2 cache size */ + /* qcow2 reference count table cache size */ + unsigned long long refcount_cache_size; + /* clean unused cache entries interval */ + unsigned long long cache_clean_interval; }; =20 =20 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml= b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml new file mode 100644 index 0000000..3f464db --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml @@ -0,0 +1,43 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + +
+ + + + + + +
+ + +
+ + +
+ + + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache= .xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml new file mode 100644 index 0000000..3f464db --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml @@ -0,0 +1,43 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + +
+ + + + + + +
+ + +
+ + +
+ + + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0a87ced..fab1e19 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -461,6 +461,7 @@ mymain(void) DO_TEST("disk-drive-cache-v2-none", NONE); DO_TEST("disk-drive-cache-directsync", NONE); DO_TEST("disk-drive-cache-unsafe", NONE); + DO_TEST("disk-drive-qcow2-cache", NONE); DO_TEST("disk-drive-network-nbd", NONE); DO_TEST("disk-drive-network-nbd-export", NONE); DO_TEST("disk-drive-network-nbd-ipv6", NONE); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list