Blame SOURCES/libvirt-nodedev-conf-Split-PCI-sub-capability-parsing-to-separate-methods.patch

6d3351
From 309e27ed960e7ac34177aa1fcac34cc6faf149fb Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <309e27ed960e7ac34177aa1fcac34cc6faf149fb@dist-git>
6d3351
From: Erik Skultety <eskultet@redhat.com>
6d3351
Date: Thu, 18 May 2017 14:02:51 +0200
6d3351
Subject: [PATCH] nodedev: conf: Split PCI sub-capability parsing to separate
6d3351
 methods
6d3351
6d3351
Since there's at least SRIOV and MDEV sub-capabilities to be parsed,
6d3351
let's make the code more readable by splitting it to several logical
6d3351
blocks.
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1452072
6d3351
6d3351
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6d3351
(cherry picked from commit a5c1f3b7e028193e8cb9f9a420ac2fdd5f4a66fe)
6d3351
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 src/conf/node_device_conf.c | 142 ++++++++++++++++++++++++++------------------
6d3351
 1 file changed, 83 insertions(+), 59 deletions(-)
6d3351
6d3351
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
6d3351
index 02215f32d..56a26b578 100644
6d3351
--- a/src/conf/node_device_conf.c
6d3351
+++ b/src/conf/node_device_conf.c
6d3351
@@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
6d3351
 
6d3351
 
6d3351
 static int
6d3351
+virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt,
6d3351
+                                      virNodeDevCapPCIDevPtr pci_dev)
6d3351
+{
6d3351
+    xmlNodePtr address = virXPathNode("./address[1]", ctxt);
6d3351
+
6d3351
+    if (VIR_ALLOC(pci_dev->physical_function) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    if (!address) {
6d3351
+        virReportError(VIR_ERR_XML_ERROR, "%s",
6d3351
+                       _("Missing address in 'phys_function' capability"));
6d3351
+        return -1;
6d3351
+    }
6d3351
+
6d3351
+    if (virPCIDeviceAddressParseXML(address,
6d3351
+                                    pci_dev->physical_function) < 0)
6d3351
+        return -1;
6d3351
+
6d3351
+    pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
6d3351
+
6d3351
+    return 0;
6d3351
+}
6d3351
+
6d3351
+
6d3351
+static int
6d3351
+virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
6d3351
+                                     virNodeDevCapPCIDevPtr pci_dev)
6d3351
+{
6d3351
+    int ret = -1;
6d3351
+    xmlNodePtr *addresses = NULL;
6d3351
+    int naddresses = virXPathNodeSet("./address", ctxt, &addresses);
6d3351
+    char *maxFuncsStr = virXPathString("string(./@maxCount)", ctxt);
6d3351
+    size_t i;
6d3351
+
6d3351
+    if (naddresses < 0)
6d3351
+        goto cleanup;
6d3351
+
6d3351
+    if (maxFuncsStr &&
6d3351
+        virStrToLong_uip(maxFuncsStr, NULL, 10,
6d3351
+                         &pci_dev->max_virtual_functions) < 0) {
6d3351
+        virReportError(VIR_ERR_XML_ERROR, "%s",
6d3351
+                       _("Malformed 'maxCount' parameter"));
6d3351
+        goto cleanup;
6d3351
+    }
6d3351
+
6d3351
+    if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
6d3351
+        goto cleanup;
6d3351
+
6d3351
+    for (i = 0; i < naddresses; i++) {
6d3351
+        virPCIDeviceAddressPtr addr = NULL;
6d3351
+
6d3351
+        if (VIR_ALLOC(addr) < 0)
6d3351
+            goto cleanup;
6d3351
+
6d3351
+        if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
6d3351
+            VIR_FREE(addr);
6d3351
+            goto cleanup;
6d3351
+        }
6d3351
+
6d3351
+        if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
6d3351
+                               pci_dev->num_virtual_functions,
6d3351
+                               addr) < 0)
6d3351
+            goto cleanup;
6d3351
+    }
6d3351
+
6d3351
+    pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
6d3351
+    ret = 0;
6d3351
+ cleanup:
6d3351
+    VIR_FREE(addresses);
6d3351
+    VIR_FREE(maxFuncsStr);
6d3351
+    return ret;
6d3351
+}
6d3351
+
6d3351
+
6d3351
+static int
6d3351
 virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
6d3351
                                 xmlNodePtr node,
6d3351
                                 virNodeDevCapPCIDevPtr pci_dev)
6d3351
 {
6d3351
-    char *maxFuncsStr = virXMLPropString(node, "maxCount");
6d3351
     char *type = virXMLPropString(node, "type");
6d3351
-    xmlNodePtr *addresses = NULL;
6d3351
     xmlNodePtr orignode = ctxt->node;
6d3351
     int ret = -1;
6d3351
-    size_t i = 0;
6d3351
 
6d3351
     ctxt->node = node;
6d3351
 
6d3351
     if (!type) {
6d3351
         virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type"));
6d3351
-        goto out;
6d3351
+        goto cleanup;
6d3351
     }
6d3351
 
6d3351
-    if (STREQ(type, "phys_function")) {
6d3351
-        xmlNodePtr address = virXPathNode("./address[1]", ctxt);
6d3351
-
6d3351
-        if (VIR_ALLOC(pci_dev->physical_function) < 0)
6d3351
-            goto out;
6d3351
-
6d3351
-        if (!address) {
6d3351
-            virReportError(VIR_ERR_XML_ERROR, "%s",
6d3351
-                           _("Missing address in 'phys_function' capability"));
6d3351
-            goto out;
6d3351
-        }
6d3351
-
6d3351
-        if (virPCIDeviceAddressParseXML(address,
6d3351
-                                        pci_dev->physical_function) < 0)
6d3351
-            goto out;
6d3351
-
6d3351
-        pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
6d3351
-    } else if (STREQ(type, "virt_functions")) {
6d3351
-        int naddresses;
6d3351
-
6d3351
-        if ((naddresses = virXPathNodeSet("./address", ctxt, &addresses)) < 0)
6d3351
-            goto out;
6d3351
-
6d3351
-        if (maxFuncsStr &&
6d3351
-            virStrToLong_uip(maxFuncsStr, NULL, 10,
6d3351
-                             &pci_dev->max_virtual_functions) < 0) {
6d3351
-            virReportError(VIR_ERR_XML_ERROR, "%s",
6d3351
-                           _("Malformed 'maxCount' parameter"));
6d3351
-            goto out;
6d3351
-        }
6d3351
-
6d3351
-        if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
6d3351
-            goto out;
6d3351
-
6d3351
-        for (i = 0; i < naddresses; i++) {
6d3351
-            virPCIDeviceAddressPtr addr = NULL;
6d3351
-
6d3351
-            if (VIR_ALLOC(addr) < 0)
6d3351
-                goto out;
6d3351
-
6d3351
-            if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
6d3351
-                VIR_FREE(addr);
6d3351
-                goto out;
6d3351
-            }
6d3351
-
6d3351
-            if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
6d3351
-                                   pci_dev->num_virtual_functions,
6d3351
-                                   addr) < 0)
6d3351
-                goto out;
6d3351
-        }
6d3351
-
6d3351
-        pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
6d3351
+    if (STREQ(type, "phys_function") &&
6d3351
+        virNodeDevPCICapSRIOVPhysicalParseXML(ctxt, pci_dev) < 0) {
6d3351
+        goto cleanup;
6d3351
+    } else if (STREQ(type, "virt_functions") &&
6d3351
+               virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) {
6d3351
+        goto cleanup;
6d3351
     } else {
6d3351
         int hdrType = virPCIHeaderTypeFromString(type);
6d3351
 
6d3351
@@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
6d3351
     }
6d3351
 
6d3351
     ret = 0;
6d3351
- out:
6d3351
-    VIR_FREE(addresses);
6d3351
-    VIR_FREE(maxFuncsStr);
6d3351
+ cleanup:
6d3351
     VIR_FREE(type);
6d3351
     ctxt->node = orignode;
6d3351
     return ret;
6d3351
-- 
6d3351
2.13.0
6d3351