[PATCH 05/10] conf: node_device: refactor capability mdev_types formating

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

 



Extract the XML formating for mdev_types from PCI capability into
a generic standalone method for later reuse.

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

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 811d102208..dce04ad4f0 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -206,6 +206,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)
@@ -276,27 +307,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",
-- 
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