From nobody Thu May 15 17:20:39 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 1503588168035827.5040048958656; Thu, 24 Aug 2017 08:22:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EDE97F3F3; Thu, 24 Aug 2017 15:22:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5E3B7EA4C; Thu, 24 Aug 2017 15:22:45 +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 86BD24EE50; Thu, 24 Aug 2017 15:22:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7OFMis4015141 for ; Thu, 24 Aug 2017 11:22:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5114C7009C; Thu, 24 Aug 2017 15:22:44 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD4187FE86 for ; Thu, 24 Aug 2017 15:22:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2EDE97F3F3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 24 Aug 2017 17:22:08 +0200 Message-Id: <1e392c8547f396ae640f5db0e7dfa67f3e503e72.1503588082.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] conf: don't close the source element inside different function 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 24 Aug 2017 15:22:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While formatting disk or chardev element they both uses virDomainDiskSourceDefFormatSeclabel() function which also closes the source element. This is not extendable. Use the new virXMLFormatElement() to properly format the source element with possible child elements. As a side effect it fixes a bug in disk source formatting. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 99 +++++++++++++-----= ---- .../qemuxml2xmlout-seclabel-dynamic-labelskip.xml | 3 +- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b8867fd1ea..640702f723 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21489,14 +21489,8 @@ virDomainDiskSourceDefFormatSeclabel(virBufferPtr = buf, size_t n; =20 if (nseclabels && !skipSeclables) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); for (n =3D 0; n < nseclabels; n++) virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); } } =20 @@ -21569,6 +21563,10 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf, bool skipSeclabels) { const char *startupPolicy =3D NULL; + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + + virBufferSetChildIndent(&childBuf, buf); =20 if (policy) startupPolicy =3D virDomainStartupPolicyTypeToString(policy); @@ -21576,51 +21574,45 @@ virDomainDiskSourceFormatInternal(virBufferPtr bu= f, if (src->path || src->nhosts > 0 || src->srcpool || startupPolicy) { switch ((virStorageType)src->type) { case VIR_STORAGE_TYPE_FILE: - virBufferAddLit(buf, "path); - virBufferEscapeString(buf, " startupPolicy=3D'%s'", startupPol= icy); + virBufferEscapeString(&attrBuf, " file=3D'%s'", src->path); + virBufferEscapeString(&attrBuf, " startupPolicy=3D'%s'", start= upPolicy); =20 - virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + virDomainDiskSourceDefFormatSeclabel(&childBuf, src->nseclabel= s, src->seclabels, flags, skipSeclabels); break; =20 case VIR_STORAGE_TYPE_BLOCK: - virBufferAddLit(buf, "path); - virBufferEscapeString(buf, " startupPolicy=3D'%s'", startupPol= icy); + virBufferEscapeString(&attrBuf, " dev=3D'%s'", src->path); + virBufferEscapeString(&attrBuf, " startupPolicy=3D'%s'", start= upPolicy); =20 - virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + virDomainDiskSourceDefFormatSeclabel(&childBuf, src->nseclabel= s, src->seclabels, flags, skipSeclabels); break; =20 case VIR_STORAGE_TYPE_DIR: - virBufferAddLit(buf, "path); - virBufferEscapeString(buf, " startupPolicy=3D'%s'", startupPol= icy); - virBufferAddLit(buf, "/>\n"); + virBufferEscapeString(&attrBuf, " dir=3D'%s'", src->path); + virBufferEscapeString(&attrBuf, " startupPolicy=3D'%s'", start= upPolicy); break; =20 case VIR_STORAGE_TYPE_NETWORK: if (virDomainDiskSourceFormatNetwork(buf, src) < 0) - return -1; + goto error; break; =20 case VIR_STORAGE_TYPE_VOLUME: - virBufferAddLit(buf, "srcpool) { - virBufferEscapeString(buf, " pool=3D'%s'", src->srcpool->p= ool); - virBufferEscapeString(buf, " volume=3D'%s'", + virBufferEscapeString(&attrBuf, " pool=3D'%s'", src->srcpo= ol->pool); + virBufferEscapeString(&attrBuf, " volume=3D'%s'", src->srcpool->volume); if (src->srcpool->mode) - virBufferAsprintf(buf, " mode=3D'%s'", + virBufferAsprintf(&attrBuf, " mode=3D'%s'", virStorageSourcePoolModeTypeToString= (src->srcpool->mode)); } - virBufferEscapeString(buf, " startupPolicy=3D'%s'", startupPol= icy); + virBufferEscapeString(&attrBuf, " startupPolicy=3D'%s'", start= upPolicy); =20 - virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + virDomainDiskSourceDefFormatSeclabel(&childBuf, src->nseclabel= s, src->seclabels, flags, skipSeclabels); break; @@ -21629,11 +21621,19 @@ virDomainDiskSourceFormatInternal(virBufferPtr bu= f, case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected disk type %d"), src->type); - return -1; + goto error; } + + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) + goto error; } =20 return 0; + + error: + virBufferFreeAndReset(&attrBuf); + virBufferFreeAndReset(&childBuf); + return -1; } =20 =20 @@ -23059,11 +23059,15 @@ virDomainChrAttrsDefFormat(virBufferPtr buf, return 0; } =20 -static void +static int virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceDefPtr def, unsigned int flags) { + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + + virBufferSetChildIndent(&childBuf, buf); =20 switch ((virDomainChrType)def->type) { case VIR_DOMAIN_CHR_TYPE_NULL: @@ -23081,14 +23085,17 @@ virDomainChrSourceDefFormat(virBufferPtr buf, if (def->type !=3D VIR_DOMAIN_CHR_TYPE_PTY || (def->data.file.path && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { - virBufferEscapeString(buf, "data.file.path); if (def->type =3D=3D VIR_DOMAIN_CHR_TYPE_FILE && def->data.file.append !=3D VIR_TRISTATE_SWITCH_ABSENT) - virBufferAsprintf(buf, " append=3D'%s'", + virBufferAsprintf(&attrBuf, " append=3D'%s'", virTristateSwitchTypeToString(def->data.file.append)); - virDomainSourceDefFormatSeclabel(buf, def->nseclabels, + virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels, def->seclabels, flags); + + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < = 0) + goto error; } break; =20 @@ -23119,19 +23126,21 @@ virDomainChrSourceDefFormat(virBufferPtr buf, break; =20 case VIR_DOMAIN_CHR_TYPE_TCP: - virBufferAsprintf(buf, "data.tcp.listen ? "bind" : "connect"); - virBufferEscapeString(buf, "host=3D'%s' ", def->data.tcp.host); - virBufferEscapeString(buf, "service=3D'%s'", def->data.tcp.service= ); + virBufferEscapeString(&attrBuf, "host=3D'%s' ", def->data.tcp.host= ); + virBufferEscapeString(&attrBuf, "service=3D'%s'", def->data.tcp.se= rvice); if (def->data.tcp.haveTLS !=3D VIR_TRISTATE_BOOL_ABSENT && !(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && def->data.tcp.tlsFromConfig)) - virBufferAsprintf(buf, " tls=3D'%s'", + virBufferAsprintf(&attrBuf, " tls=3D'%s'", virTristateBoolTypeToString(def->data.tcp.haveTLS)); if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) - virBufferAsprintf(buf, " tlsFromConfig=3D'%d'", + virBufferAsprintf(&attrBuf, " tlsFromConfig=3D'%d'", def->data.tcp.tlsFromConfig); - virBufferAddLit(buf, "/>\n"); + + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) + goto error; =20 virBufferAsprintf(buf, "\n", virDomainChrTcpProtocolTypeToString( @@ -23140,11 +23149,14 @@ virDomainChrSourceDefFormat(virBufferPtr buf, =20 case VIR_DOMAIN_CHR_TYPE_UNIX: if (def->data.nix.path) { - virBufferAsprintf(buf, "data.nix.listen ? "bind" : "connect"); - virBufferEscapeString(buf, " path=3D'%s'", def->data.nix.path); - virDomainSourceDefFormatSeclabel(buf, def->nseclabels, + virBufferEscapeString(&attrBuf, " path=3D'%s'", def->data.nix.= path); + virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels, def->seclabels, flags); + + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < = 0) + goto error; } break; =20 @@ -23164,7 +23176,12 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 - return; + return 0; + + error: + virBufferFreeAndReset(&attrBuf); + virBufferFreeAndReset(&childBuf); + return -1; } =20 static int diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-label= skip.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelsk= ip.xml index 6688d98eb6..3f4ff0aadf 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml @@ -15,8 +15,7 @@ /usr/bin/qemu-system-i686 - - +
--=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list