]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: node_device: refactor mdev_types XML parsing
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 23 Oct 2020 17:31:48 +0000 (19:31 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 4 Nov 2020 18:15:05 +0000 (19:15 +0100)
Extract PCI code from virNodeDevPCICapMdevTypesParseXML to make
method virNodeDevCapMdevTypesParseXML generic for later reuse.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/conf/node_device_conf.c

index b483928a494c28a0b9f9a2c0b291725df3c1b7ca..b2aa7771a03e17bb76775666495970c73730ba61 100644 (file)
@@ -768,6 +768,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,
@@ -1532,72 +1598,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,
@@ -1620,9 +1620,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);