]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: node_device: refactor capability mdev_types formatting
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 23 Oct 2020 17:31:47 +0000 (19:31 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 4 Nov 2020 18:14:58 +0000 (19:14 +0100)
Extract the XML formatting for mdev_types from PCI capability into
a generic standalone method for later reuse.

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

index 7fa1214c30a94945273d43f11c06299393efc73d..b483928a494c28a0b9f9a2c0b291725df3c1b7ca 100644 (file)
@@ -207,6 +207,37 @@ virNodeDeviceCapSystemDefFormat(virBufferPtr buf,
 }
 
 
+static void
+virNodeDeviceCapMdevTypesFormat(virBufferPtr buf,
+                                virMediatedDeviceTypePtr *mdev_types,
+                                const size_t nmdev_types)
+{
+    size_t i;
+
+    if (nmdev_types > 0) {
+        virBufferAddLit(buf, "<capability type='mdev_types'>\n");
+        virBufferAdjustIndent(buf, 2);
+        for (i = 0; i < nmdev_types; i++) {
+            virMediatedDeviceTypePtr type = 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, "</capability>\n");
+    }
+}
+
+
 static void
 virNodeDeviceCapPCIDefFormat(virBufferPtr buf,
                              const virNodeDevCapData *data)
@@ -277,27 +308,9 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf,
                           virPCIHeaderTypeToString(data->pci_dev.hdrType));
     }
     if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) {
-        if (data->pci_dev.nmdev_types > 0) {
-            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);
-                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, "</capability>\n");
-        }
+        virNodeDeviceCapMdevTypesFormat(buf,
+                                        data->pci_dev.mdev_types,
+                                        data->pci_dev.nmdev_types);
     }
     if (data->pci_dev.nIommuGroupDevices) {
         virBufferAsprintf(buf, "<iommuGroup number='%d'>\n",