[PATCH 01/10] conf: node_device: fix mdev_types format and XML parsing code to match schema

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

 



The nodedev schema defines that a mdev_types capability must have
one or more type elements. The XML parsing and the format allows to
accept and to write mdev_types capability without any type element.
This patches fixes this.

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

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 4adfdef572..3fbe9338ee 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -276,25 +276,27 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf,
                           virPCIHeaderTypeToString(data->pci_dev.hdrType));
     }
     if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) {
-        virBufferAddLit(buf, "<capability type='mdev_types'>\n");
-        virBufferAdjustIndent(buf, 2);
-        for (i = 0; i < data->pci_dev.nmdev_types; i++) {
-            virMediatedDeviceTypePtr type = data->pci_dev.mdev_types[i];
-            virBufferEscapeString(buf, "<type id='%s'>\n", type->id);
+        if (data->pci_dev.nmdev_types > 0) {
+            virBufferAddLit(buf, "<capability type='mdev_types'>\n");
             virBufferAdjustIndent(buf, 2);
-            if (type->name)
-                virBufferEscapeString(buf, "<name>%s</name>\n",
-                                      type->name);
-            virBufferEscapeString(buf, "<deviceAPI>%s</deviceAPI>\n",
-                                  type->device_api);
-            virBufferAsprintf(buf,
-                              "<availableInstances>%u</availableInstances>\n",
-                              type->available_instances);
+            for (i = 0; i < data->pci_dev.nmdev_types; i++) {
+                virMediatedDeviceTypePtr type = data->pci_dev.mdev_types[i];
+                virBufferEscapeString(buf, "<type id='%s'>\n", type->id);
+                virBufferAdjustIndent(buf, 2);
+                if (type->name)
+                    virBufferEscapeString(buf, "<name>%s</name>\n",
+                                          type->name);
+                virBufferEscapeString(buf, "<deviceAPI>%s</deviceAPI>\n",
+                                      type->device_api);
+                virBufferAsprintf(buf,
+                                  "<availableInstances>%u</availableInstances>\n",
+                                  type->available_instances);
+                virBufferAdjustIndent(buf, -2);
+                virBufferAddLit(buf, "</type>\n");
+            }
             virBufferAdjustIndent(buf, -2);
-            virBufferAddLit(buf, "</type>\n");
+            virBufferAddLit(buf, "</capability>\n");
         }
-        virBufferAdjustIndent(buf, -2);
-        virBufferAddLit(buf, "</capability>\n");
     }
     if (data->pci_dev.nIommuGroupDevices) {
         virBufferAsprintf(buf, "<iommuGroup number='%d'>\n",
@@ -1520,6 +1522,12 @@ virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr ctxt,
     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];
-- 
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