From nobody Wed Feb 11 06:16:26 2026 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.zoho.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 14932185520151020.4640448770576; Wed, 26 Apr 2017 07:55:52 -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 8DCC2C04BD28; Wed, 26 Apr 2017 14:55:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65F77871D1; Wed, 26 Apr 2017 14:55:50 +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 202CA5EC69; Wed, 26 Apr 2017 14:55:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3QEtUGq017130 for ; Wed, 26 Apr 2017 10:55:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 808F68884E; Wed, 26 Apr 2017 14:55:30 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id D950188857; Wed, 26 Apr 2017 14:55:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8DCC2C04BD28 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 8DCC2C04BD28 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:29 +0200 Message-Id: <4878a847278a551d04487edb21ffa083650816e8.1493218185.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v3 2/6] nodedev: conf: Split PCI sub-capability parsing to separate methods 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]); Wed, 26 Apr 2017 14:55:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since there's at least SRIOV and MDEV sub-capabilities to be parsed, let's make the code more readable by splitting it to several logical blocks. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 130 ++++++++++++++++++++++++++--------------= ---- 1 file changed, 77 insertions(+), 53 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 85cfd8396..d70d9942c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, =20 =20 static int -virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr node, - virNodeDevCapPCIDevPtr pci_dev) +virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt, + virNodeDevCapPCIDevPtr pci_dev) { - char *maxFuncsStr =3D virXMLPropString(node, "maxCount"); - char *type =3D virXMLPropString(node, "type"); - xmlNodePtr *addresses =3D NULL; - xmlNodePtr orignode =3D ctxt->node; - int ret =3D -1; - size_t i =3D 0; - - ctxt->node =3D node; - - if (!type) { - virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type= ")); - goto out; - } - - if (STREQ(type, "phys_function")) { - xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); + xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); =20 if (VIR_ALLOC(pci_dev->physical_function) < 0) - goto out; + return -1; =20 if (!address) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing address in 'phys_function' capabilit= y")); - goto out; + return -1; } =20 if (virPCIDeviceAddressParseXML(address, pci_dev->physical_function) < 0) - goto out; + return -1; =20 pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; - } else if (STREQ(type, "virt_functions")) { - int naddresses; - - if ((naddresses =3D virXPathNodeSet("./address", ctxt, &addresses)= ) < 0) - goto out; - - if (maxFuncsStr && - virStrToLong_uip(maxFuncsStr, NULL, 10, - &pci_dev->max_virtual_functions) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Malformed 'maxCount' parameter")); - goto out; - } =20 - if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) - goto out; + return 0; +} + + +static int +virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt, + virNodeDevCapPCIDevPtr pci_dev) +{ + int ret =3D -1; + xmlNodePtr *addresses =3D NULL; + int naddresses =3D virXPathNodeSet("./address", ctxt, &addresses); + char *maxFuncsStr =3D virXPathString("string(./@maxCount)", ctxt); + size_t i; =20 - for (i =3D 0; i < naddresses; i++) { - virPCIDeviceAddressPtr addr =3D NULL; + if (naddresses < 0) + goto cleanup; =20 - if (VIR_ALLOC(addr) < 0) - goto out; + if (maxFuncsStr && + virStrToLong_uip(maxFuncsStr, NULL, 10, + &pci_dev->max_virtual_functions) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Malformed 'maxCount' parameter")); + goto cleanup; + } =20 - if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { - VIR_FREE(addr); - goto out; - } + if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) + goto cleanup; =20 - if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, - pci_dev->num_virtual_functions, - addr) < 0) - goto out; + for (i =3D 0; i < naddresses; i++) { + virPCIDeviceAddressPtr addr =3D NULL; + + if (VIR_ALLOC(addr) < 0) + goto cleanup; + + if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { + VIR_FREE(addr); + goto cleanup; } =20 - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, + pci_dev->num_virtual_functions, + addr) < 0) + goto cleanup; + } + + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + ret =3D 0; + cleanup: + VIR_FREE(addresses); + VIR_FREE(maxFuncsStr); + return ret; +} + + +static int +virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapPCIDevPtr pci_dev) +{ + char *type =3D virXMLPropString(node, "type"); + xmlNodePtr orignode =3D ctxt->node; + int ret =3D -1; + + ctxt->node =3D node; + + if (!type) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type= ")); + goto cleanup; + } + + if (STREQ(type, "phys_function") && + virNodeDevPCICapSRIOVPhysicalParseXML(ctxt, pci_dev) < 0) { + goto cleanup; + } else if (STREQ(type, "virt_functions") && + virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) { + goto cleanup; } else { int hdrType =3D virPCIHeaderTypeFromString(type); =20 @@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, } =20 ret =3D 0; - out: - VIR_FREE(addresses); - VIR_FREE(maxFuncsStr); + cleanup: VIR_FREE(type); ctxt->node =3D orignode; return ret; --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list