From nobody Fri May 16 05:40:11 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 1500553832389933.5312115243986; Thu, 20 Jul 2017 05:30:32 -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 074B08E3DF; Thu, 20 Jul 2017 12:30:30 +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 CAE4019EE4; Thu, 20 Jul 2017 12:30:29 +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 7E28F1853E31; Thu, 20 Jul 2017 12:30:29 +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 v6KCURRa007044 for ; Thu, 20 Jul 2017 08:30:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id F23A280920; Thu, 20 Jul 2017 12:30:26 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08D6F176BB; Thu, 20 Jul 2017 12:30:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 074B08E3DF 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 074B08E3DF From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:30:02 +0200 Message-Id: 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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 5/6] conf: domain: Split up virDomainStorageHostParse and rename it 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, 20 Jul 2017 12:30:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Split out parsing of one host into a separate function and add a new function to loop through all the host XML nodes. This change removes multiple levels of nesting due to the old XML parsing approach used. --- src/conf/domain_conf.c | 117 +++++++++++++++++++++++++++------------------= ---- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9320794de..a3fd7195a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6429,71 +6429,61 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, return ret; } + static int -virDomainStorageHostParse(xmlNodePtr node, - virStorageNetHostDefPtr *hosts, - size_t *nhosts) +virDomainStorageNetworkParseHost(xmlNodePtr hostnode, + virStorageNetHostDefPtr *hosts, + size_t *nhosts) { int ret =3D -1; - xmlNodePtr child; char *transport =3D NULL; virStorageNetHostDef host; memset(&host, 0, sizeof(host)); + host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - child =3D node->children; - while (child !=3D NULL) { - if (child->type =3D=3D XML_ELEMENT_NODE && - xmlStrEqual(child->name, BAD_CAST "host")) { - - host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - - /* transport can be tcp (default), unix or rdma. */ - if ((transport =3D virXMLPropString(child, "transport"))) { - host.transport =3D virStorageNetHostTransportTypeFromStrin= g(transport); - if (host.transport < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown protocol transport type '%s'= "), - transport); - goto cleanup; - } - } + /* transport can be tcp (default), unix or rdma. */ + if ((transport =3D virXMLPropString(hostnode, "transport"))) { + host.transport =3D virStorageNetHostTransportTypeFromString(transp= ort); + if (host.transport < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown protocol transport type '%s'"), + transport); + goto cleanup; + } + } - host.socket =3D virXMLPropString(child, "socket"); + host.socket =3D virXMLPropString(hostnode, "socket"); - if (host.transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket =3D=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing socket for unix transport")); - goto cleanup; - } + if (host.transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host.socket =3D=3D NULL) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing socket for unix transport")); + goto cleanup; + } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket !=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, - _("transport '%s' does not support " - "socket attribute"), - transport); - goto cleanup; - } + if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host.socket !=3D NULL) { + virReportError(VIR_ERR_XML_ERROR, + _("transport '%s' does not support " + "socket attribute"), + transport); + goto cleanup; + } - VIR_FREE(transport); + if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { + if (!(host.name =3D virXMLPropString(hostnode, "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing name for host")); + goto cleanup; + } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { - if (!(host.name =3D virXMLPropString(child, "name"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing name for host")); - goto cleanup; - } + host.port =3D virXMLPropString(hostnode, "port"); + } - host.port =3D virXMLPropString(child, "port"); - } + if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) + goto cleanup; - if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) - goto cleanup; - } - child =3D child->next; - } ret =3D 0; cleanup: @@ -6502,6 +6492,27 @@ virDomainStorageHostParse(xmlNodePtr node, return ret; } + +static int +virDomainStorageNetworkParseHosts(xmlNodePtr node, + virStorageNetHostDefPtr *hosts, + size_t *nhosts) +{ + xmlNodePtr child; + + for (child =3D node->children; child; child =3D child->next) { + if (child->type =3D=3D XML_ELEMENT_NODE && + xmlStrEqual(child->name, BAD_CAST "host")) { + + if (virDomainStorageNetworkParseHost(child, hosts, nhosts) < 0) + return -1; + } + } + + return 0; +} + + static int virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr sc= sisrc) @@ -6609,8 +6620,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, goto cleanup; } - if (virDomainStorageHostParse(sourcenode, &iscsisrc->hosts, - &iscsisrc->nhosts) < 0) + if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->hosts, + &iscsisrc->nhosts) < 0) goto cleanup; if (iscsisrc->nhosts < 1) { @@ -7879,7 +7890,7 @@ virDomainDiskSourceParse(xmlNodePtr node, /* config file currently only works with remote disks */ src->configFile =3D virXPathString("string(./config/@file)", ctxt); - if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0) + if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nho= sts) < 0) goto cleanup; if (virStorageSourceNetworkAssignDefaultPorts(src) < 0) --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list