From nobody Sun Feb 8 16:12:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1675183515; cv=none; d=zohomail.com; s=zohoarc; b=XDXKQ3QTnu3wRYO8sTLcpYhhliKlViLeXLfYIs+IB2BAsf26sSwJJkoq8+SbPWKOU79dvpqD96jKuBE3Hr4ifru6/c2r+smXexiGYRbJC9SU9lUBa8zbc0zHE82YITC4PT7N2XBxhCfO/63psY8ZG3newKICeqNUzXWR+H6mzsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675183515; 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=Hjc3ikm+l98HPDkX0dTdyNVVGBApO+pHGl+5ribDCfg=; b=WPNPgo7RuNTfaJY5Bzz41k3RD6FU5lkcjzCXXsiqsamWqGHfFUzIqPLvcfIjXJR8LcqgcLaZ95dEy1EWqFiZx4VW0+HB/ftHmSvX2XRmUVwZu+Vs22Up6vqHdVZCvz/A7Fh3c1bjRwDCAmkB0vTyhx5F7RLdVjlXSx1AcS2irqc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1675183515474329.81741031352055; Tue, 31 Jan 2023 08:45:15 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-15-XFHvfIt-Pmqf6zmqnEfWWA-1; Tue, 31 Jan 2023 11:44:38 -0500 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 40D8D87AA0A; Tue, 31 Jan 2023 16:44:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ADE414171BB; Tue, 31 Jan 2023 16:44:28 +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 7EFBA1946A4C; Tue, 31 Jan 2023 16:44:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7D3F31946587 for ; Tue, 31 Jan 2023 16:44:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 53521492B06; Tue, 31 Jan 2023 16:44:26 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E4A0492B05 for ; Tue, 31 Jan 2023 16:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675183514; 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=Hjc3ikm+l98HPDkX0dTdyNVVGBApO+pHGl+5ribDCfg=; b=R/8qO0e8PHMbmTUeSV71gMQCvEo9cmdUEC2cv0IhZww9yYoWCeFF5vvakCdWEN5NuNrzt2 yeq2nUzukFyJ0gIHLxsKZ9v6Zh/oFph+PH9bqFo60Hqub1SgZaOJxUhiPUG5z35uQcoBol OqZCouecVlZqagZJC6fpprrPCX23Np4= X-MC-Unique: XFHvfIt-Pmqf6zmqnEfWWA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/7] virDomainNetDefFormat: Modernize formatting Date: Tue, 31 Jan 2023 17:44:19 +0100 Message-Id: <433ccd3c7e3bbbf9c267697944e13296099dcdef.1675183375.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: , 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: 1675183516681100003 Content-Type: text/plain; charset="utf-8"; x-default="true" The child element of is formatted the old way. Switch to virXMLFormatElement(). Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 103 ++++++++++++----------------------------- 1 file changed, 30 insertions(+), 73 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bab8f09e26..fb2455840a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23681,7 +23681,6 @@ virDomainNetDefFormat(virBuffer *buf, { virDomainNetType actualType =3D virDomainNetGetActualType(def); bool publicActual =3D false; - int sourceLines =3D 0; const char *typeStr; virDomainHostdevDef *hostdef =3D NULL; char macstr[VIR_MAC_STRING_BUFLEN]; @@ -23745,6 +23744,8 @@ virDomainNetDefFormat(virBuffer *buf, if (virDomainActualNetDefContentsFormat(buf, def, false, flags, xm= lopt) < 0) return -1; } else { + g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) sourceChildBuf =3D VIR_BUFFER_INIT_CHILD(buf); /* ...but if we've asked for the inactive XML (rather than * status), or to report the ActualDef as a separate * subelement (this is how we privately store interface @@ -23754,17 +23755,16 @@ virDomainNetDefFormat(virBuffer *buf, */ switch (def->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: - virBufferEscapeString(buf, "data.network.name); - virBufferEscapeString(buf, " portgroup=3D'%s'", + virBufferEscapeString(&sourceAttrBuf, " portgroup=3D'%s'", def->data.network.portgroup); if (virUUIDIsValid(def->data.network.portid) && !(flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { char portidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(def->data.network.portid, portidstr); - virBufferEscapeString(buf, " portid=3D'%s'", portidstr); + virBufferEscapeString(&sourceAttrBuf, " portid=3D'%s'", po= rtidstr); } - sourceLines++; break; =20 case VIR_DOMAIN_NET_TYPE_ETHERNET: @@ -23772,31 +23772,23 @@ virDomainNetDefFormat(virBuffer *buf, =20 case VIR_DOMAIN_NET_TYPE_VHOSTUSER: if (def->data.vhostuser->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX)= { - virBufferAddLit(buf, "data.vhostuser->data.nix.path); - virBufferAsprintf(buf, " mode=3D'%s'", + virBufferAsprintf(&sourceAttrBuf, " mode=3D'%s'", def->data.vhostuser->data.nix.listen ? "server" : "client"); - sourceLines++; if (def->data.vhostuser->data.nix.reconnect.enabled) { - virBufferAddLit(buf, ">\n"); - sourceLines++; - virBufferAdjustIndent(buf, 2); - virDomainChrSourceReconnectDefFormat(buf, + virDomainChrSourceReconnectDefFormat(&sourceChildBuf, &def->data.vhostu= ser->data.nix.reconnect); - virBufferAdjustIndent(buf, -2); } =20 } break; =20 case VIR_DOMAIN_NET_TYPE_BRIDGE: - if (def->data.bridge.brname) { - virBufferEscapeString(buf, "data.bridge.brname); - sourceLines++; - } + virBufferEscapeString(&sourceAttrBuf, " bridge=3D'%s'", + def->data.bridge.brname); break; =20 case VIR_DOMAIN_NET_TYPE_SERVER: @@ -23804,42 +23796,32 @@ virDomainNetDefFormat(virBuffer *buf, case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_UDP: if (def->data.socket.address) { - virBufferAsprintf(buf, "data.socket.address, def->data.socket.port); } else { - virBufferAsprintf(buf, "data.socket.port); } - sourceLines++; =20 if (def->type !=3D VIR_DOMAIN_NET_TYPE_UDP) break; =20 - virBufferAddLit(buf, ">\n"); - sourceLines++; - virBufferAdjustIndent(buf, 2); - - virBufferAsprintf(buf, "\n", + virBufferAsprintf(&sourceChildBuf, "\n", def->data.socket.localaddr, def->data.socket.localport); - virBufferAdjustIndent(buf, -2); break; =20 case VIR_DOMAIN_NET_TYPE_INTERNAL: - if (def->data.internal.name) { - virBufferEscapeString(buf, "data.internal.name); - sourceLines++; - } + virBufferEscapeString(&sourceAttrBuf, " name=3D'%s'", + def->data.internal.name); break; =20 case VIR_DOMAIN_NET_TYPE_DIRECT: - virBufferEscapeString(buf, "data.direct.linkdev); - virBufferAsprintf(buf, " mode=3D'%s'", + virBufferAsprintf(&sourceAttrBuf, " mode=3D'%s'", virNetDevMacVLanModeTypeToString(def->data.d= irect.mode)); - sourceLines++; break; =20 case VIR_DOMAIN_NET_TYPE_HOSTDEV: @@ -23850,33 +23832,24 @@ virDomainNetDefFormat(virBuffer *buf, break; =20 case VIR_DOMAIN_NET_TYPE_VDPA: - if (def->data.vdpa.devicepath) { - virBufferEscapeString(buf, "data.vdpa.devicepath); - sourceLines++; - } - break; + virBufferEscapeString(&sourceAttrBuf, " dev=3D'%s'", + def->data.vdpa.devicepath); + break; =20 case VIR_DOMAIN_NET_TYPE_VDS: { char switchidstr[VIR_UUID_STRING_BUFLEN]; =20 virUUIDFormat(def->data.vds.switch_id, switchidstr); - virBufferEscapeString(buf, "data.vds.port_= id); - virBufferEscapeString(buf, " portgroupid=3D'%s'", def->data.vd= s.portgroup_id); - virBufferAsprintf(buf, " connectionid=3D'%lld'", def->data.vds= .connection_id); - - sourceLines++; - + virBufferEscapeString(&sourceAttrBuf, " switchid=3D'%s'", swit= chidstr); + virBufferAsprintf(&sourceAttrBuf, " portid=3D'%lld'", def->dat= a.vds.port_id); + virBufferEscapeString(&sourceAttrBuf, " portgroupid=3D'%s'", d= ef->data.vds.portgroup_id); + virBufferAsprintf(&sourceAttrBuf, " connectionid=3D'%lld'", de= f->data.vds.connection_id); break; } =20 case VIR_DOMAIN_NET_TYPE_USER: - if (def->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST && - def->sourceDev) { - virBufferEscapeString(buf, "sour= ceDev); - sourceLines++; - } + if (def->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) + virBufferEscapeString(&sourceAttrBuf, " dev=3D'%s'", def->= sourceDev); break; =20 case VIR_DOMAIN_NET_TYPE_NULL: @@ -23884,27 +23857,12 @@ virDomainNetDefFormat(virBuffer *buf, break; } =20 - /* if sourceLines =3D=3D 0 - no info at all so far - * sourceLines =3D=3D 1 - first line written, no terminating ">" - * sourceLines > 1 - multiple lines, including subelements - */ if (def->hostIP.nips || def->hostIP.nroutes) { - if (sourceLines =3D=3D 0) { - virBufferAddLit(buf, "\n"); - sourceLines +=3D 2; - } else if (sourceLines =3D=3D 1) { - virBufferAddLit(buf, ">\n"); - sourceLines++; - } - virBufferAdjustIndent(buf, 2); - if (virDomainNetIPInfoFormat(buf, &def->hostIP) < 0) + if (virDomainNetIPInfoFormat(&sourceChildBuf, &def->hostIP) < = 0) return -1; - virBufferAdjustIndent(buf, -2); } - if (sourceLines =3D=3D 1) - virBufferAddLit(buf, "/>\n"); - else if (sourceLines > 1) - virBufferAddLit(buf, "\n"); + + virXMLFormatElement(buf, "source", &sourceAttrBuf, &sourceChildBuf= ); =20 if (virNetDevVlanFormat(&def->vlan, buf) < 0) return -1; @@ -23922,7 +23880,6 @@ virDomainNetDefFormat(virBuffer *buf, (flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) && (virDomainActualNetDefFormat(buf, def, flags, xmlopt) < 0)) return -1; - } =20 if (virDomainNetIPInfoFormat(buf, &def->guestIP) < 0) --=20 2.39.1