[PATCH 06/10] conf: node_device: refactor mdev_types XML parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extract PCI code from virNodeDevPCICapMdevTypesParseXML to make
method virNodeDevCapMdevTypesParseXML generic for later reuse.

Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxx>
---
 src/conf/node_device_conf.c | 141 ++++++++++++++++++------------------
 1 file changed, 72 insertions(+), 69 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index dce04ad4f0..6fd5b1b038 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -757,6 +757,72 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt,
 }
 
 
+static int
+virNodeDevCapMdevTypesParseXML(xmlXPathContextPtr ctxt,
+                               virMediatedDeviceTypePtr **mdev_types,
+                               size_t *nmdev_types)
+{
+    int ret = -1;
+    xmlNodePtr orignode = NULL;
+    xmlNodePtr *nodes = NULL;
+    int ntypes = -1;
+    virMediatedDeviceTypePtr type = NULL;
+    size_t i;
+
+    if ((ntypes = virXPathNodeSet("./type", ctxt, &nodes)) < 0)
+        goto cleanup;
+
+    if (nmdev_types == 0) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing <type> element in <capability> element"));
+        goto cleanup;
+    }
+
+    orignode = ctxt->node;
+    for (i = 0; i < ntypes; i++) {
+        ctxt->node = nodes[i];
+
+        type = g_new0(virMediatedDeviceType, 1);
+
+        if (!(type->id = virXPathString("string(./@id[1])", ctxt))) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("missing 'id' attribute for mediated device's "
+                             "<type> element"));
+            goto cleanup;
+        }
+
+        if (!(type->device_api = virXPathString("string(./deviceAPI[1])", ctxt))) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("missing device API for mediated device type '%s'"),
+                           type->id);
+            goto cleanup;
+        }
+
+        if (virXPathUInt("number(./availableInstances)", ctxt,
+                         &type->available_instances) < 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("missing number of available instances for "
+                             "mediated device type '%s'"),
+                           type->id);
+            goto cleanup;
+        }
+
+        type->name = virXPathString("string(./name)", ctxt);
+
+        if (VIR_APPEND_ELEMENT(*mdev_types,
+                               *nmdev_types, type) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(nodes);
+    virMediatedDeviceTypeFree(type);
+    ctxt->node = orignode;
+    return ret;
+}
+
+
 static int
 virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt,
                          virNodeDeviceDefPtr def,
@@ -1521,72 +1587,6 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
 }
 
 
-static int
-virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr ctxt,
-                                  virNodeDevCapPCIDevPtr pci_dev)
-{
-    int ret = -1;
-    xmlNodePtr orignode = NULL;
-    xmlNodePtr *nodes = NULL;
-    int nmdev_types = -1;
-    virMediatedDeviceTypePtr type = NULL;
-    size_t i;
-
-    if ((nmdev_types = virXPathNodeSet("./type", ctxt, &nodes)) < 0)
-        goto cleanup;
-
-    if (nmdev_types == 0) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing <type> element in <capability> element"));
-        goto cleanup;
-    }
-
-    orignode = ctxt->node;
-    for (i = 0; i < nmdev_types; i++) {
-        ctxt->node = nodes[i];
-
-        type = g_new0(virMediatedDeviceType, 1);
-
-        if (!(type->id = virXPathString("string(./@id[1])", ctxt))) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("missing 'id' attribute for mediated device's "
-                             "<type> element"));
-            goto cleanup;
-        }
-
-        if (!(type->device_api = virXPathString("string(./deviceAPI[1])", ctxt))) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("missing device API for mediated device type '%s'"),
-                           type->id);
-            goto cleanup;
-        }
-
-        if (virXPathUInt("number(./availableInstances)", ctxt,
-                         &type->available_instances) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("missing number of available instances for "
-                             "mediated device type '%s'"),
-                           type->id);
-            goto cleanup;
-        }
-
-        type->name = virXPathString("string(./name)", ctxt);
-
-        if (VIR_APPEND_ELEMENT(pci_dev->mdev_types,
-                               pci_dev->nmdev_types, type) < 0)
-            goto cleanup;
-    }
-
-    pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
-    ret = 0;
- cleanup:
-    VIR_FREE(nodes);
-    virMediatedDeviceTypeFree(type);
-    ctxt->node = orignode;
-    return ret;
-}
-
-
 static int
 virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
                                 xmlNodePtr node,
@@ -1609,9 +1609,12 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
     } else if (STREQ(type, "virt_functions") &&
                virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) {
         goto cleanup;
-    } else if (STREQ(type, "mdev_types") &&
-        virNodeDevPCICapMdevTypesParseXML(ctxt, pci_dev) < 0) {
-        goto cleanup;
+    } else if (STREQ(type, "mdev_types")) {
+        if (virNodeDevCapMdevTypesParseXML(ctxt,
+                                           &pci_dev->mdev_types,
+                                           &pci_dev->nmdev_types) < 0)
+            goto cleanup;
+        pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
     } else {
         int hdrType = virPCIHeaderTypeFromString(type);
 
-- 
2.25.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux