render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From f636c368f181c9f18ee135e8902490faf30186f9 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <f636c368f181c9f18ee135e8902490faf30186f9@dist-git>
3e5111
From: Erik Skultety <eskultet@redhat.com>
3e5111
Date: Thu, 18 May 2017 14:02:48 +0200
3e5111
Subject: [PATCH] conf: nodedev: Split virNodeDeviceDefFormat into more
3e5111
 functions
3e5111
3e5111
Make the code look cleaner by moving the capability specific bits into
3e5111
separate functions.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1452072
3e5111
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
(cherry picked from commit bfaaaf108da087c38cc0f2890ed96730a3734ba8)
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/conf/node_device_conf.c | 578 ++++++++++++++++++++++++--------------------
3e5111
 1 file changed, 322 insertions(+), 256 deletions(-)
3e5111
3e5111
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
3e5111
index cc3fad8b9..02215f32d 100644
3e5111
--- a/src/conf/node_device_conf.c
3e5111
+++ b/src/conf/node_device_conf.c
3e5111
@@ -155,6 +155,320 @@ virPCIEDeviceInfoFormat(virBufferPtr buf,
3e5111
 }
3e5111
 
3e5111
 
3e5111
+static void
3e5111
+virNodeDeviceCapSystemDefFormat(virBufferPtr buf,
3e5111
+                                const virNodeDevCapData *data)
3e5111
+{
3e5111
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
3e5111
+
3e5111
+    if (data->system.product_name)
3e5111
+        virBufferEscapeString(buf, "<product>%s</product>\n",
3e5111
+                              data->system.product_name);
3e5111
+    virBufferAddLit(buf, "<hardware>\n");
3e5111
+    virBufferAdjustIndent(buf, 2);
3e5111
+    if (data->system.hardware.vendor_name)
3e5111
+        virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
3e5111
+                              data->system.hardware.vendor_name);
3e5111
+    if (data->system.hardware.version)
3e5111
+        virBufferEscapeString(buf, "<version>%s</version>\n",
3e5111
+                              data->system.hardware.version);
3e5111
+    if (data->system.hardware.serial)
3e5111
+        virBufferEscapeString(buf, "<serial>%s</serial>\n",
3e5111
+                              data->system.hardware.serial);
3e5111
+    virUUIDFormat(data->system.hardware.uuid, uuidstr);
3e5111
+    virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr);
3e5111
+    virBufferAdjustIndent(buf, -2);
3e5111
+    virBufferAddLit(buf, "</hardware>\n");
3e5111
+
3e5111
+    virBufferAddLit(buf, "<firmware>\n");
3e5111
+    virBufferAdjustIndent(buf, 2);
3e5111
+    if (data->system.firmware.vendor_name)
3e5111
+        virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
3e5111
+                              data->system.firmware.vendor_name);
3e5111
+    if (data->system.firmware.version)
3e5111
+        virBufferEscapeString(buf, "<version>%s</version>\n",
3e5111
+                              data->system.firmware.version);
3e5111
+    if (data->system.firmware.release_date)
3e5111
+        virBufferEscapeString(buf, "<release_date>%s</release_date>\n",
3e5111
+                              data->system.firmware.release_date);
3e5111
+    virBufferAdjustIndent(buf, -2);
3e5111
+    virBufferAddLit(buf, "</firmware>\n");
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapPCIDefFormat(virBufferPtr buf,
3e5111
+                             const virNodeDevCapData *data)
3e5111
+{
3e5111
+    size_t i;
3e5111
+
3e5111
+    virBufferAsprintf(buf, "<domain>%d</domain>\n",
3e5111
+                      data->pci_dev.domain);
3e5111
+    virBufferAsprintf(buf, "<bus>%d</bus>\n", data->pci_dev.bus);
3e5111
+    virBufferAsprintf(buf, "<slot>%d</slot>\n",
3e5111
+                      data->pci_dev.slot);
3e5111
+    virBufferAsprintf(buf, "<function>%d</function>\n",
3e5111
+                      data->pci_dev.function);
3e5111
+    virBufferAsprintf(buf, "
3e5111
+                      data->pci_dev.product);
3e5111
+    if (data->pci_dev.product_name)
3e5111
+        virBufferEscapeString(buf, ">%s</product>\n",
3e5111
+                              data->pci_dev.product_name);
3e5111
+    else
3e5111
+        virBufferAddLit(buf, " />\n");
3e5111
+    virBufferAsprintf(buf, "
3e5111
+                      data->pci_dev.vendor);
3e5111
+    if (data->pci_dev.vendor_name)
3e5111
+        virBufferEscapeString(buf, ">%s</vendor>\n",
3e5111
+                              data->pci_dev.vendor_name);
3e5111
+    else
3e5111
+        virBufferAddLit(buf, " />\n");
3e5111
+    if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION) {
3e5111
+        virBufferAddLit(buf, "<capability type='phys_function'>\n");
3e5111
+        virBufferAdjustIndent(buf, 2);
3e5111
+        virBufferAsprintf(buf,
3e5111
+                          "
3e5111
+                          "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
+                          data->pci_dev.physical_function->domain,
3e5111
+                          data->pci_dev.physical_function->bus,
3e5111
+                          data->pci_dev.physical_function->slot,
3e5111
+                          data->pci_dev.physical_function->function);
3e5111
+        virBufferAdjustIndent(buf, -2);
3e5111
+        virBufferAddLit(buf, "</capability>\n");
3e5111
+    }
3e5111
+    if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION) {
3e5111
+        virBufferAddLit(buf, "
3e5111
+        if (data->pci_dev.max_virtual_functions)
3e5111
+            virBufferAsprintf(buf, " maxCount='%u'",
3e5111
+                              data->pci_dev.max_virtual_functions);
3e5111
+        if (data->pci_dev.num_virtual_functions == 0) {
3e5111
+            virBufferAddLit(buf, "/>\n");
3e5111
+        } else {
3e5111
+            virBufferAddLit(buf, ">\n");
3e5111
+            virBufferAdjustIndent(buf, 2);
3e5111
+            for (i = 0; i < data->pci_dev.num_virtual_functions; i++) {
3e5111
+                virBufferAsprintf(buf,
3e5111
+                                  "
3e5111
+                                  "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
+                                  data->pci_dev.virtual_functions[i]->domain,
3e5111
+                                  data->pci_dev.virtual_functions[i]->bus,
3e5111
+                                  data->pci_dev.virtual_functions[i]->slot,
3e5111
+                                  data->pci_dev.virtual_functions[i]->function);
3e5111
+            }
3e5111
+            virBufferAdjustIndent(buf, -2);
3e5111
+            virBufferAddLit(buf, "</capability>\n");
3e5111
+        }
3e5111
+    }
3e5111
+    if (data->pci_dev.hdrType) {
3e5111
+        virBufferAsprintf(buf, "<capability type='%s'/>\n",
3e5111
+                          virPCIHeaderTypeToString(data->pci_dev.hdrType));
3e5111
+    }
3e5111
+    if (data->pci_dev.nIommuGroupDevices) {
3e5111
+        virBufferAsprintf(buf, "<iommuGroup number='%d'>\n",
3e5111
+                          data->pci_dev.iommuGroupNumber);
3e5111
+        virBufferAdjustIndent(buf, 2);
3e5111
+        for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) {
3e5111
+            virBufferAsprintf(buf,
3e5111
+                              "
3e5111
+                              "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
+                              data->pci_dev.iommuGroupDevices[i]->domain,
3e5111
+                              data->pci_dev.iommuGroupDevices[i]->bus,
3e5111
+                              data->pci_dev.iommuGroupDevices[i]->slot,
3e5111
+                              data->pci_dev.iommuGroupDevices[i]->function);
3e5111
+        }
3e5111
+        virBufferAdjustIndent(buf, -2);
3e5111
+        virBufferAddLit(buf, "</iommuGroup>\n");
3e5111
+    }
3e5111
+    if (data->pci_dev.numa_node >= 0)
3e5111
+        virBufferAsprintf(buf, "<numa node='%d'/>\n",
3e5111
+                          data->pci_dev.numa_node);
3e5111
+
3e5111
+    if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE)
3e5111
+        virPCIEDeviceInfoFormat(buf, data->pci_dev.pci_express);
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapUSBDevDefFormat(virBufferPtr buf,
3e5111
+                                const virNodeDevCapData *data)
3e5111
+{
3e5111
+    virBufferAsprintf(buf, "<bus>%d</bus>\n", data->usb_dev.bus);
3e5111
+    virBufferAsprintf(buf, "<device>%d</device>\n",
3e5111
+                      data->usb_dev.device);
3e5111
+    virBufferAsprintf(buf, "
3e5111
+                      data->usb_dev.product);
3e5111
+    if (data->usb_dev.product_name)
3e5111
+        virBufferEscapeString(buf, ">%s</product>\n",
3e5111
+                              data->usb_dev.product_name);
3e5111
+    else
3e5111
+        virBufferAddLit(buf, " />\n");
3e5111
+    virBufferAsprintf(buf, "
3e5111
+                      data->usb_dev.vendor);
3e5111
+    if (data->usb_dev.vendor_name)
3e5111
+        virBufferEscapeString(buf, ">%s</vendor>\n",
3e5111
+                              data->usb_dev.vendor_name);
3e5111
+    else
3e5111
+        virBufferAddLit(buf, " />\n");
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapUSBInterfaceDefFormat(virBufferPtr buf,
3e5111
+                                      const virNodeDevCapData *data)
3e5111
+{
3e5111
+    virBufferAsprintf(buf, "<number>%d</number>\n",
3e5111
+                      data->usb_if.number);
3e5111
+    virBufferAsprintf(buf, "<class>%d</class>\n",
3e5111
+                      data->usb_if._class);
3e5111
+    virBufferAsprintf(buf, "<subclass>%d</subclass>\n",
3e5111
+                      data->usb_if.subclass);
3e5111
+    virBufferAsprintf(buf, "<protocol>%d</protocol>\n",
3e5111
+                      data->usb_if.protocol);
3e5111
+    if (data->usb_if.description)
3e5111
+        virBufferEscapeString(buf,
3e5111
+                              "<description>%s</description>\n",
3e5111
+                              data->usb_if.description);
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapNetDefFormat(virBufferPtr buf,
3e5111
+                             const virNodeDevCapData *data)
3e5111
+{
3e5111
+    size_t i;
3e5111
+
3e5111
+    virBufferEscapeString(buf, "<interface>%s</interface>\n",
3e5111
+                          data->net.ifname);
3e5111
+    if (data->net.address)
3e5111
+        virBufferEscapeString(buf, "<address>%s</address>\n",
3e5111
+                              data->net.address);
3e5111
+    virInterfaceLinkFormat(buf, &data->net.lnk);
3e5111
+    if (data->net.features) {
3e5111
+        for (i = 0; i < VIR_NET_DEV_FEAT_LAST; i++) {
3e5111
+            if (virBitmapIsBitSet(data->net.features, i)) {
3e5111
+                virBufferAsprintf(buf, "<feature name='%s'/>\n",
3e5111
+                                  virNetDevFeatureTypeToString(i));
3e5111
+            }
3e5111
+        }
3e5111
+    }
3e5111
+    if (data->net.subtype != VIR_NODE_DEV_CAP_NET_LAST) {
3e5111
+        const char *subtyp =
3e5111
+            virNodeDevNetCapTypeToString(data->net.subtype);
3e5111
+        virBufferEscapeString(buf, "<capability type='%s'/>\n",
3e5111
+                              subtyp);
3e5111
+    }
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapSCSIHostDefFormat(virBufferPtr buf,
3e5111
+                                  const virNodeDevCapData *data)
3e5111
+{
3e5111
+    virBufferAsprintf(buf, "<host>%d</host>\n",
3e5111
+                      data->scsi_host.host);
3e5111
+    if (data->scsi_host.unique_id != -1)
3e5111
+        virBufferAsprintf(buf, "<unique_id>%d</unique_id>\n",
3e5111
+                          data->scsi_host.unique_id);
3e5111
+    if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
3e5111
+        virBufferAddLit(buf, "<capability type='fc_host'>\n");
3e5111
+        virBufferAdjustIndent(buf, 2);
3e5111
+        virBufferEscapeString(buf, "<wwnn>%s</wwnn>\n",
3e5111
+                              data->scsi_host.wwnn);
3e5111
+        virBufferEscapeString(buf, "<wwpn>%s</wwpn>\n",
3e5111
+                              data->scsi_host.wwpn);
3e5111
+        virBufferEscapeString(buf, "<fabric_wwn>%s</fabric_wwn>\n",
3e5111
+                              data->scsi_host.fabric_wwn);
3e5111
+        virBufferAdjustIndent(buf, -2);
3e5111
+        virBufferAddLit(buf, "</capability>\n");
3e5111
+    }
3e5111
+    if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) {
3e5111
+        virBufferAddLit(buf, "<capability type='vport_ops'>\n");
3e5111
+        virBufferAdjustIndent(buf, 2);
3e5111
+        virBufferAsprintf(buf, "<max_vports>%d</max_vports>\n",
3e5111
+                          data->scsi_host.max_vports);
3e5111
+        virBufferAsprintf(buf, "<vports>%d</vports>\n",
3e5111
+                          data->scsi_host.vports);
3e5111
+        virBufferAdjustIndent(buf, -2);
3e5111
+        virBufferAddLit(buf, "</capability>\n");
3e5111
+    }
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapSCSIDefFormat(virBufferPtr buf,
3e5111
+                              const virNodeDevCapData *data)
3e5111
+{
3e5111
+    virBufferAsprintf(buf, "<host>%d</host>\n", data->scsi.host);
3e5111
+    virBufferAsprintf(buf, "<bus>%d</bus>\n", data->scsi.bus);
3e5111
+    virBufferAsprintf(buf, "<target>%d</target>\n",
3e5111
+                      data->scsi.target);
3e5111
+    virBufferAsprintf(buf, "<lun>%d</lun>\n", data->scsi.lun);
3e5111
+    if (data->scsi.type)
3e5111
+        virBufferEscapeString(buf, "<type>%s</type>\n",
3e5111
+                              data->scsi.type);
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static void
3e5111
+virNodeDeviceCapStorageDefFormat(virBufferPtr buf,
3e5111
+                                 const virNodeDevCapData *data)
3e5111
+{
3e5111
+    virBufferEscapeString(buf, "<block>%s</block>\n",
3e5111
+                          data->storage.block);
3e5111
+    if (data->storage.bus)
3e5111
+        virBufferEscapeString(buf, "<bus>%s</bus>\n",
3e5111
+                              data->storage.bus);
3e5111
+    if (data->storage.drive_type)
3e5111
+        virBufferEscapeString(buf, "<drive_type>%s</drive_type>\n",
3e5111
+                              data->storage.drive_type);
3e5111
+    if (data->storage.model)
3e5111
+        virBufferEscapeString(buf, "<model>%s</model>\n",
3e5111
+                              data->storage.model);
3e5111
+    if (data->storage.vendor)
3e5111
+        virBufferEscapeString(buf, "<vendor>%s</vendor>\n",
3e5111
+                              data->storage.vendor);
3e5111
+    if (data->storage.serial)
3e5111
+        virBufferEscapeString(buf, "<serial>%s</serial>\n",
3e5111
+                              data->storage.serial);
3e5111
+    if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) {
3e5111
+        int avl = data->storage.flags &
3e5111
+            VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
3e5111
+        virBufferAddLit(buf, "<capability type='removable'>\n");
3e5111
+        virBufferAdjustIndent(buf, 2);
3e5111
+        virBufferAsprintf(buf, "<media_available>%d"
3e5111
+                          "</media_available>\n", avl ? 1 : 0);
3e5111
+        virBufferAsprintf(buf, "<media_size>%llu</media_size>\n",
3e5111
+                          data->storage.removable_media_size);
3e5111
+        if (data->storage.media_label)
3e5111
+            virBufferEscapeString(buf,
3e5111
+                                  "<media_label>%s</media_label>\n",
3e5111
+                                  data->storage.media_label);
3e5111
+        if (data->storage.logical_block_size > 0)
3e5111
+            virBufferAsprintf(buf, "<logical_block_size>%llu"
3e5111
+                              "</logical_block_size>\n",
3e5111
+                              data->storage.logical_block_size);
3e5111
+        if (data->storage.num_blocks > 0)
3e5111
+            virBufferAsprintf(buf,
3e5111
+                              "<num_blocks>%llu</num_blocks>\n",
3e5111
+                              data->storage.num_blocks);
3e5111
+        virBufferAdjustIndent(buf, -2);
3e5111
+        virBufferAddLit(buf, "</capability>\n");
3e5111
+    } else {
3e5111
+        virBufferAsprintf(buf, "<size>%llu</size>\n",
3e5111
+                          data->storage.size);
3e5111
+        if (data->storage.logical_block_size > 0)
3e5111
+            virBufferAsprintf(buf, "<logical_block_size>%llu"
3e5111
+                              "</logical_block_size>\n",
3e5111
+                              data->storage.logical_block_size);
3e5111
+        if (data->storage.num_blocks > 0)
3e5111
+            virBufferAsprintf(buf, "<num_blocks>%llu</num_blocks>\n",
3e5111
+                              data->storage.num_blocks);
3e5111
+    }
3e5111
+    if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE)
3e5111
+        virBufferAddLit(buf, "<capability type='hotpluggable'/>\n");
3e5111
+}
3e5111
+
3e5111
+
3e5111
 char *
3e5111
 virNodeDeviceDefFormat(const virNodeDeviceDef *def)
3e5111
 {
3e5111
@@ -185,7 +499,6 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
3e5111
     }
3e5111
 
3e5111
     for (caps = def->caps; caps; caps = caps->next) {
3e5111
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
3e5111
         virNodeDevCapDataPtr data = &caps->data;
3e5111
 
3e5111
         virBufferAsprintf(&buf, "<capability type='%s'>\n",
3e5111
@@ -193,279 +506,32 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
3e5111
         virBufferAdjustIndent(&buf, 2);
3e5111
         switch (caps->data.type) {
3e5111
         case VIR_NODE_DEV_CAP_SYSTEM:
3e5111
-            if (data->system.product_name)
3e5111
-                virBufferEscapeString(&buf, "<product>%s</product>\n",
3e5111
-                                      data->system.product_name);
3e5111
-            virBufferAddLit(&buf, "<hardware>\n");
3e5111
-            virBufferAdjustIndent(&buf, 2);
3e5111
-            if (data->system.hardware.vendor_name)
3e5111
-                virBufferEscapeString(&buf, "<vendor>%s</vendor>\n",
3e5111
-                                      data->system.hardware.vendor_name);
3e5111
-            if (data->system.hardware.version)
3e5111
-                virBufferEscapeString(&buf, "<version>%s</version>\n",
3e5111
-                                      data->system.hardware.version);
3e5111
-            if (data->system.hardware.serial)
3e5111
-                virBufferEscapeString(&buf, "<serial>%s</serial>\n",
3e5111
-                                      data->system.hardware.serial);
3e5111
-            virUUIDFormat(data->system.hardware.uuid, uuidstr);
3e5111
-            virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuidstr);
3e5111
-            virBufferAdjustIndent(&buf, -2);
3e5111
-            virBufferAddLit(&buf, "</hardware>\n");
3e5111
-
3e5111
-            virBufferAddLit(&buf, "<firmware>\n");
3e5111
-            virBufferAdjustIndent(&buf, 2);
3e5111
-            if (data->system.firmware.vendor_name)
3e5111
-                virBufferEscapeString(&buf, "<vendor>%s</vendor>\n",
3e5111
-                                      data->system.firmware.vendor_name);
3e5111
-            if (data->system.firmware.version)
3e5111
-                virBufferEscapeString(&buf, "<version>%s</version>\n",
3e5111
-                                      data->system.firmware.version);
3e5111
-            if (data->system.firmware.release_date)
3e5111
-                virBufferEscapeString(&buf, "<release_date>%s</release_date>\n",
3e5111
-                                      data->system.firmware.release_date);
3e5111
-            virBufferAdjustIndent(&buf, -2);
3e5111
-            virBufferAddLit(&buf, "</firmware>\n");
3e5111
+            virNodeDeviceCapSystemDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_PCI_DEV:
3e5111
-            virBufferAsprintf(&buf, "<domain>%d</domain>\n",
3e5111
-                              data->pci_dev.domain);
3e5111
-            virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->pci_dev.bus);
3e5111
-            virBufferAsprintf(&buf, "<slot>%d</slot>\n",
3e5111
-                              data->pci_dev.slot);
3e5111
-            virBufferAsprintf(&buf, "<function>%d</function>\n",
3e5111
-                              data->pci_dev.function);
3e5111
-            virBufferAsprintf(&buf, "
3e5111
-                                  data->pci_dev.product);
3e5111
-            if (data->pci_dev.product_name)
3e5111
-                virBufferEscapeString(&buf, ">%s</product>\n",
3e5111
-                                      data->pci_dev.product_name);
3e5111
-            else
3e5111
-                virBufferAddLit(&buf, " />\n");
3e5111
-            virBufferAsprintf(&buf, "
3e5111
-                                  data->pci_dev.vendor);
3e5111
-            if (data->pci_dev.vendor_name)
3e5111
-                virBufferEscapeString(&buf, ">%s</vendor>\n",
3e5111
-                                      data->pci_dev.vendor_name);
3e5111
-            else
3e5111
-                virBufferAddLit(&buf, " />\n");
3e5111
-            if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION) {
3e5111
-                virBufferAddLit(&buf, "<capability type='phys_function'>\n");
3e5111
-                virBufferAdjustIndent(&buf, 2);
3e5111
-                virBufferAsprintf(&buf,
3e5111
-                                  "
3e5111
-                                  "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
-                                  data->pci_dev.physical_function->domain,
3e5111
-                                  data->pci_dev.physical_function->bus,
3e5111
-                                  data->pci_dev.physical_function->slot,
3e5111
-                                  data->pci_dev.physical_function->function);
3e5111
-                virBufferAdjustIndent(&buf, -2);
3e5111
-                virBufferAddLit(&buf, "</capability>\n");
3e5111
-            }
3e5111
-            if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION) {
3e5111
-                virBufferAddLit(&buf, "
3e5111
-                if (data->pci_dev.max_virtual_functions)
3e5111
-                    virBufferAsprintf(&buf, " maxCount='%u'",
3e5111
-                                      data->pci_dev.max_virtual_functions);
3e5111
-                if (data->pci_dev.num_virtual_functions == 0) {
3e5111
-                    virBufferAddLit(&buf, "/>\n");
3e5111
-                } else {
3e5111
-                    virBufferAddLit(&buf, ">\n");
3e5111
-                    virBufferAdjustIndent(&buf, 2);
3e5111
-                    for (i = 0; i < data->pci_dev.num_virtual_functions; i++) {
3e5111
-                        virBufferAsprintf(&buf,
3e5111
-                                          "
3e5111
-                                          "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
-                                          data->pci_dev.virtual_functions[i]->domain,
3e5111
-                                          data->pci_dev.virtual_functions[i]->bus,
3e5111
-                                          data->pci_dev.virtual_functions[i]->slot,
3e5111
-                                          data->pci_dev.virtual_functions[i]->function);
3e5111
-                    }
3e5111
-                    virBufferAdjustIndent(&buf, -2);
3e5111
-                    virBufferAddLit(&buf, "</capability>\n");
3e5111
-                }
3e5111
-            }
3e5111
-            if (data->pci_dev.hdrType) {
3e5111
-                virBufferAsprintf(&buf, "<capability type='%s'/>\n",
3e5111
-                                  virPCIHeaderTypeToString(data->pci_dev.hdrType));
3e5111
-            }
3e5111
-            if (data->pci_dev.nIommuGroupDevices) {
3e5111
-                virBufferAsprintf(&buf, "<iommuGroup number='%d'>\n",
3e5111
-                                  data->pci_dev.iommuGroupNumber);
3e5111
-                virBufferAdjustIndent(&buf, 2);
3e5111
-                for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) {
3e5111
-                    virBufferAsprintf(&buf,
3e5111
-                                      "
3e5111
-                                      "slot='0x%.2x' function='0x%.1x'/>\n",
3e5111
-                                      data->pci_dev.iommuGroupDevices[i]->domain,
3e5111
-                                      data->pci_dev.iommuGroupDevices[i]->bus,
3e5111
-                                      data->pci_dev.iommuGroupDevices[i]->slot,
3e5111
-                                      data->pci_dev.iommuGroupDevices[i]->function);
3e5111
-                }
3e5111
-                virBufferAdjustIndent(&buf, -2);
3e5111
-                virBufferAddLit(&buf, "</iommuGroup>\n");
3e5111
-            }
3e5111
-            if (data->pci_dev.numa_node >= 0)
3e5111
-                virBufferAsprintf(&buf, "<numa node='%d'/>\n",
3e5111
-                                  data->pci_dev.numa_node);
3e5111
-
3e5111
-            if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE)
3e5111
-                virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express);
3e5111
+            virNodeDeviceCapPCIDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_USB_DEV:
3e5111
-            virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->usb_dev.bus);
3e5111
-            virBufferAsprintf(&buf, "<device>%d</device>\n",
3e5111
-                              data->usb_dev.device);
3e5111
-            virBufferAsprintf(&buf, "
3e5111
-                                  data->usb_dev.product);
3e5111
-            if (data->usb_dev.product_name)
3e5111
-                virBufferEscapeString(&buf, ">%s</product>\n",
3e5111
-                                      data->usb_dev.product_name);
3e5111
-            else
3e5111
-                virBufferAddLit(&buf, " />\n");
3e5111
-            virBufferAsprintf(&buf, "
3e5111
-                                  data->usb_dev.vendor);
3e5111
-            if (data->usb_dev.vendor_name)
3e5111
-                virBufferEscapeString(&buf, ">%s</vendor>\n",
3e5111
-                                      data->usb_dev.vendor_name);
3e5111
-            else
3e5111
-                virBufferAddLit(&buf, " />\n");
3e5111
+            virNodeDeviceCapUSBDevDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_USB_INTERFACE:
3e5111
-            virBufferAsprintf(&buf, "<number>%d</number>\n",
3e5111
-                              data->usb_if.number);
3e5111
-            virBufferAsprintf(&buf, "<class>%d</class>\n",
3e5111
-                              data->usb_if._class);
3e5111
-            virBufferAsprintf(&buf, "<subclass>%d</subclass>\n",
3e5111
-                              data->usb_if.subclass);
3e5111
-            virBufferAsprintf(&buf, "<protocol>%d</protocol>\n",
3e5111
-                              data->usb_if.protocol);
3e5111
-            if (data->usb_if.description)
3e5111
-                virBufferEscapeString(&buf,
3e5111
-                                  "<description>%s</description>\n",
3e5111
-                                  data->usb_if.description);
3e5111
+            virNodeDeviceCapUSBInterfaceDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_NET:
3e5111
-            virBufferEscapeString(&buf, "<interface>%s</interface>\n",
3e5111
-                              data->net.ifname);
3e5111
-            if (data->net.address)
3e5111
-                virBufferEscapeString(&buf, "<address>%s</address>\n",
3e5111
-                                  data->net.address);
3e5111
-            virInterfaceLinkFormat(&buf, &data->net.lnk);
3e5111
-            if (data->net.features) {
3e5111
-                for (i = 0; i < VIR_NET_DEV_FEAT_LAST; i++) {
3e5111
-                    if (virBitmapIsBitSet(data->net.features, i)) {
3e5111
-                        virBufferAsprintf(&buf, "<feature name='%s'/>\n",
3e5111
-                                          virNetDevFeatureTypeToString(i));
3e5111
-                    }
3e5111
-                }
3e5111
-            }
3e5111
-            if (data->net.subtype != VIR_NODE_DEV_CAP_NET_LAST) {
3e5111
-                const char *subtyp =
3e5111
-                    virNodeDevNetCapTypeToString(data->net.subtype);
3e5111
-                virBufferEscapeString(&buf, "<capability type='%s'/>\n",
3e5111
-                                      subtyp);
3e5111
-            }
3e5111
+            virNodeDeviceCapNetDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_SCSI_HOST:
3e5111
-            virBufferAsprintf(&buf, "<host>%d</host>\n",
3e5111
-                              data->scsi_host.host);
3e5111
-            if (data->scsi_host.unique_id != -1)
3e5111
-                virBufferAsprintf(&buf, "<unique_id>%d</unique_id>\n",
3e5111
-                                  data->scsi_host.unique_id);
3e5111
-            if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
3e5111
-                virBufferAddLit(&buf, "<capability type='fc_host'>\n");
3e5111
-                virBufferAdjustIndent(&buf, 2);
3e5111
-                virBufferEscapeString(&buf, "<wwnn>%s</wwnn>\n",
3e5111
-                                      data->scsi_host.wwnn);
3e5111
-                virBufferEscapeString(&buf, "<wwpn>%s</wwpn>\n",
3e5111
-                                      data->scsi_host.wwpn);
3e5111
-                virBufferEscapeString(&buf, "<fabric_wwn>%s</fabric_wwn>\n",
3e5111
-                                      data->scsi_host.fabric_wwn);
3e5111
-                virBufferAdjustIndent(&buf, -2);
3e5111
-                virBufferAddLit(&buf, "</capability>\n");
3e5111
-            }
3e5111
-            if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) {
3e5111
-                virBufferAddLit(&buf, "<capability type='vport_ops'>\n");
3e5111
-                virBufferAdjustIndent(&buf, 2);
3e5111
-                virBufferAsprintf(&buf, "<max_vports>%d</max_vports>\n",
3e5111
-                                  data->scsi_host.max_vports);
3e5111
-                virBufferAsprintf(&buf, "<vports>%d</vports>\n",
3e5111
-                                  data->scsi_host.vports);
3e5111
-                virBufferAdjustIndent(&buf, -2);
3e5111
-                virBufferAddLit(&buf, "</capability>\n");
3e5111
-            }
3e5111
-
3e5111
+            virNodeDeviceCapSCSIHostDefFormat(&buf, data);
3e5111
             break;
3e5111
-
3e5111
         case VIR_NODE_DEV_CAP_SCSI_TARGET:
3e5111
             virBufferEscapeString(&buf, "<target>%s</target>\n",
3e5111
                                   data->scsi_target.name);
3e5111
             break;
3e5111
-
3e5111
         case VIR_NODE_DEV_CAP_SCSI:
3e5111
-            virBufferAsprintf(&buf, "<host>%d</host>\n", data->scsi.host);
3e5111
-            virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->scsi.bus);
3e5111
-            virBufferAsprintf(&buf, "<target>%d</target>\n",
3e5111
-                              data->scsi.target);
3e5111
-            virBufferAsprintf(&buf, "<lun>%d</lun>\n", data->scsi.lun);
3e5111
-            if (data->scsi.type)
3e5111
-                virBufferEscapeString(&buf, "<type>%s</type>\n",
3e5111
-                                      data->scsi.type);
3e5111
+            virNodeDeviceCapSCSIDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_STORAGE:
3e5111
-            virBufferEscapeString(&buf, "<block>%s</block>\n",
3e5111
-                                  data->storage.block);
3e5111
-            if (data->storage.bus)
3e5111
-                virBufferEscapeString(&buf, "<bus>%s</bus>\n",
3e5111
-                                      data->storage.bus);
3e5111
-            if (data->storage.drive_type)
3e5111
-                virBufferEscapeString(&buf, "<drive_type>%s</drive_type>\n",
3e5111
-                                      data->storage.drive_type);
3e5111
-            if (data->storage.model)
3e5111
-                virBufferEscapeString(&buf, "<model>%s</model>\n",
3e5111
-                                      data->storage.model);
3e5111
-            if (data->storage.vendor)
3e5111
-                virBufferEscapeString(&buf, "<vendor>%s</vendor>\n",
3e5111
-                                      data->storage.vendor);
3e5111
-            if (data->storage.serial)
3e5111
-                virBufferEscapeString(&buf, "<serial>%s</serial>\n",
3e5111
-                                      data->storage.serial);
3e5111
-            if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) {
3e5111
-                int avl = data->storage.flags &
3e5111
-                    VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
3e5111
-                virBufferAddLit(&buf, "<capability type='removable'>\n");
3e5111
-                virBufferAdjustIndent(&buf, 2);
3e5111
-                virBufferAsprintf(&buf, "<media_available>%d"
3e5111
-                                  "</media_available>\n", avl ? 1 : 0);
3e5111
-                virBufferAsprintf(&buf, "<media_size>%llu</media_size>\n",
3e5111
-                                  data->storage.removable_media_size);
3e5111
-                if (data->storage.media_label)
3e5111
-                    virBufferEscapeString(&buf,
3e5111
-                                          "<media_label>%s</media_label>\n",
3e5111
-                                          data->storage.media_label);
3e5111
-                if (data->storage.logical_block_size > 0)
3e5111
-                    virBufferAsprintf(&buf, "<logical_block_size>%llu"
3e5111
-                                      "</logical_block_size>\n",
3e5111
-                                      data->storage.logical_block_size);
3e5111
-                if (data->storage.num_blocks > 0)
3e5111
-                    virBufferAsprintf(&buf,
3e5111
-                                      "<num_blocks>%llu</num_blocks>\n",
3e5111
-                                      data->storage.num_blocks);
3e5111
-                virBufferAdjustIndent(&buf, -2);
3e5111
-                virBufferAddLit(&buf, "</capability>\n");
3e5111
-            } else {
3e5111
-                virBufferAsprintf(&buf, "<size>%llu</size>\n",
3e5111
-                                  data->storage.size);
3e5111
-                if (data->storage.logical_block_size > 0)
3e5111
-                    virBufferAsprintf(&buf, "<logical_block_size>%llu"
3e5111
-                                      "</logical_block_size>\n",
3e5111
-                                      data->storage.logical_block_size);
3e5111
-                if (data->storage.num_blocks > 0)
3e5111
-                    virBufferAsprintf(&buf, "<num_blocks>%llu</num_blocks>\n",
3e5111
-                                      data->storage.num_blocks);
3e5111
-            }
3e5111
-            if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE)
3e5111
-                virBufferAddLit(&buf, "<capability type='hotpluggable'/>\n");
3e5111
+            virNodeDeviceCapStorageDefFormat(&buf, data);
3e5111
             break;
3e5111
         case VIR_NODE_DEV_CAP_SCSI_GENERIC:
3e5111
             virBufferEscapeString(&buf, "<char>%s</char>\n",
3e5111
-- 
3e5111
2.13.0
3e5111