render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 2566a32fae64fa5cc8a3d3c30778d0ea7d8c4faa Mon Sep 17 00:00:00 2001
Message-Id: <2566a32fae64fa5cc8a3d3c30778d0ea7d8c4faa@dist-git>
From: Yi Min Zhao <zyimin@linux.ibm.com>
Date: Mon, 8 Apr 2019 10:57:24 +0200
Subject: [PATCH] conf: use virXMLFormatElement() in
 virDomainDeviceInfoFormat()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In order to add zPCI child element for PCI address, we update
virDomainDeviceInfoFormat() to format device info by helper function
virXMLFormatElement(). Then we could simply format zPCI address into
child buffer later.

Signed-off-by: Yi Min Zhao <zyimin@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>

(cherry picked from commit 0d6b87335c00451b0923ecc91d617f71e4135bf8)

https://bugzilla.redhat.com/show_bug.cgi?id=1508149

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Message-Id: <20190408085732.28684-8-abologna@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/domain_conf.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e62f78471c..bcb0558bc3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6447,6 +6447,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
                           virDomainDeviceInfoPtr info,
                           unsigned int flags)
 {
+    virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
+
     if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) {
         virBufferAsprintf(buf, "<boot order='%u'", info->bootIndex);
 
@@ -6491,13 +6493,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
         return;
 
-    virBufferAsprintf(buf, "<address type='%s'",
+    virBufferAsprintf(&attrBuf, " type='%s'",
                       virDomainDeviceAddressTypeToString(info->type));
 
     switch ((virDomainDeviceAddressType) info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (!virPCIDeviceAddressIsEmpty(&info->addr.pci)) {
-            virBufferAsprintf(buf, " domain='0x%.4x' bus='0x%.2x' "
+            virBufferAsprintf(&attrBuf, " domain='0x%.4x' bus='0x%.2x' "
                               "slot='0x%.2x' function='0x%.1x'",
                               info->addr.pci.domain,
                               info->addr.pci.bus,
@@ -6505,13 +6507,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
                               info->addr.pci.function);
         }
         if (info->addr.pci.multi) {
-           virBufferAsprintf(buf, " multifunction='%s'",
-                             virTristateSwitchTypeToString(info->addr.pci.multi));
+            virBufferAsprintf(&attrBuf, " multifunction='%s'",
+                              virTristateSwitchTypeToString(info->addr.pci.multi));
         }
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
-        virBufferAsprintf(buf, " controller='%d' bus='%d' target='%d' unit='%d'",
+        virBufferAsprintf(&attrBuf, " controller='%d' bus='%d' target='%d' unit='%d'",
                           info->addr.drive.controller,
                           info->addr.drive.bus,
                           info->addr.drive.target,
@@ -6519,34 +6521,34 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
-        virBufferAsprintf(buf, " controller='%d' bus='%d' port='%d'",
+        virBufferAsprintf(&attrBuf, " controller='%d' bus='%d' port='%d'",
                           info->addr.vioserial.controller,
                           info->addr.vioserial.bus,
                           info->addr.vioserial.port);
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
-        virBufferAsprintf(buf, " controller='%d' slot='%d'",
+        virBufferAsprintf(&attrBuf, " controller='%d' slot='%d'",
                           info->addr.ccid.controller,
                           info->addr.ccid.slot);
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
-        virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
+        virBufferAsprintf(&attrBuf, " bus='%d'", info->addr.usb.bus);
         if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
-            virBufferAddLit(buf, " port='");
-            virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
-            virBufferAddLit(buf, "'");
+            virBufferAddLit(&attrBuf, " port='");
+            virDomainUSBAddressPortFormatBuf(&attrBuf, info->addr.usb.port);
+            virBufferAddLit(&attrBuf, "'");
         }
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
         if (info->addr.spaprvio.has_reg)
-            virBufferAsprintf(buf, " reg='0x%llx'", info->addr.spaprvio.reg);
+            virBufferAsprintf(&attrBuf, " reg='0x%llx'", info->addr.spaprvio.reg);
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
-        virBufferAsprintf(buf, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
+        virBufferAsprintf(&attrBuf, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
                           info->addr.ccw.cssid,
                           info->addr.ccw.ssid,
                           info->addr.ccw.devno);
@@ -6557,15 +6559,15 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
         if (info->addr.isa.iobase > 0)
-            virBufferAsprintf(buf, " iobase='0x%x'", info->addr.isa.iobase);
+            virBufferAsprintf(&attrBuf, " iobase='0x%x'", info->addr.isa.iobase);
         if (info->addr.isa.irq > 0)
-            virBufferAsprintf(buf, " irq='0x%x'", info->addr.isa.irq);
+            virBufferAsprintf(&attrBuf, " irq='0x%x'", info->addr.isa.irq);
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
-        virBufferAsprintf(buf, " slot='%u'", info->addr.dimm.slot);
+        virBufferAsprintf(&attrBuf, " slot='%u'", info->addr.dimm.slot);
         if (info->addr.dimm.base)
-            virBufferAsprintf(buf, " base='0x%llx'", info->addr.dimm.base);
+            virBufferAsprintf(&attrBuf, " base='0x%llx'", info->addr.dimm.base);
 
         break;
 
@@ -6575,7 +6577,9 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         break;
     }
 
-    virBufferAddLit(buf, "/>\n");
+    virXMLFormatElement(buf, "address", &attrBuf, NULL);
+
+    virBufferFreeAndReset(&attrBuf);
 }
 
 static int
-- 
2.22.0