c313de
From 2566a32fae64fa5cc8a3d3c30778d0ea7d8c4faa Mon Sep 17 00:00:00 2001
c313de
Message-Id: <2566a32fae64fa5cc8a3d3c30778d0ea7d8c4faa@dist-git>
c313de
From: Yi Min Zhao <zyimin@linux.ibm.com>
c313de
Date: Mon, 8 Apr 2019 10:57:24 +0200
c313de
Subject: [PATCH] conf: use virXMLFormatElement() in
c313de
 virDomainDeviceInfoFormat()
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
In order to add zPCI child element for PCI address, we update
c313de
virDomainDeviceInfoFormat() to format device info by helper function
c313de
virXMLFormatElement(). Then we could simply format zPCI address into
c313de
child buffer later.
c313de
c313de
Signed-off-by: Yi Min Zhao <zyimin@linux.ibm.com>
c313de
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
c313de
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
c313de
c313de
(cherry picked from commit 0d6b87335c00451b0923ecc91d617f71e4135bf8)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1508149
c313de
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Message-Id: <20190408085732.28684-8-abologna@redhat.com>
c313de
Reviewed-by: Laine Stump <laine@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/conf/domain_conf.c | 40 ++++++++++++++++++++++------------------
c313de
 1 file changed, 22 insertions(+), 18 deletions(-)
c313de
c313de
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c313de
index e62f78471c..bcb0558bc3 100644
c313de
--- a/src/conf/domain_conf.c
c313de
+++ b/src/conf/domain_conf.c
c313de
@@ -6447,6 +6447,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
                           virDomainDeviceInfoPtr info,
c313de
                           unsigned int flags)
c313de
 {
c313de
+    virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
c313de
+
c313de
     if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) {
c313de
         virBufferAsprintf(buf, "<boot order='%u'", info->bootIndex);
c313de
 
c313de
@@ -6491,13 +6493,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
         info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
c313de
         return;
c313de
 
c313de
-    virBufferAsprintf(buf, "
c313de
+    virBufferAsprintf(&attrBuf, " type='%s'",
c313de
                       virDomainDeviceAddressTypeToString(info->type));
c313de
 
c313de
     switch ((virDomainDeviceAddressType) info->type) {
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
c313de
         if (!virPCIDeviceAddressIsEmpty(&info->addr.pci)) {
c313de
-            virBufferAsprintf(buf, " domain='0x%.4x' bus='0x%.2x' "
c313de
+            virBufferAsprintf(&attrBuf, " domain='0x%.4x' bus='0x%.2x' "
c313de
                               "slot='0x%.2x' function='0x%.1x'",
c313de
                               info->addr.pci.domain,
c313de
                               info->addr.pci.bus,
c313de
@@ -6505,13 +6507,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
                               info->addr.pci.function);
c313de
         }
c313de
         if (info->addr.pci.multi) {
c313de
-           virBufferAsprintf(buf, " multifunction='%s'",
c313de
-                             virTristateSwitchTypeToString(info->addr.pci.multi));
c313de
+            virBufferAsprintf(&attrBuf, " multifunction='%s'",
c313de
+                              virTristateSwitchTypeToString(info->addr.pci.multi));
c313de
         }
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
c313de
-        virBufferAsprintf(buf, " controller='%d' bus='%d' target='%d' unit='%d'",
c313de
+        virBufferAsprintf(&attrBuf, " controller='%d' bus='%d' target='%d' unit='%d'",
c313de
                           info->addr.drive.controller,
c313de
                           info->addr.drive.bus,
c313de
                           info->addr.drive.target,
c313de
@@ -6519,34 +6521,34 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
c313de
-        virBufferAsprintf(buf, " controller='%d' bus='%d' port='%d'",
c313de
+        virBufferAsprintf(&attrBuf, " controller='%d' bus='%d' port='%d'",
c313de
                           info->addr.vioserial.controller,
c313de
                           info->addr.vioserial.bus,
c313de
                           info->addr.vioserial.port);
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
c313de
-        virBufferAsprintf(buf, " controller='%d' slot='%d'",
c313de
+        virBufferAsprintf(&attrBuf, " controller='%d' slot='%d'",
c313de
                           info->addr.ccid.controller,
c313de
                           info->addr.ccid.slot);
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
c313de
-        virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
c313de
+        virBufferAsprintf(&attrBuf, " bus='%d'", info->addr.usb.bus);
c313de
         if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
c313de
-            virBufferAddLit(buf, " port='");
c313de
-            virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
c313de
-            virBufferAddLit(buf, "'");
c313de
+            virBufferAddLit(&attrBuf, " port='");
c313de
+            virDomainUSBAddressPortFormatBuf(&attrBuf, info->addr.usb.port);
c313de
+            virBufferAddLit(&attrBuf, "'");
c313de
         }
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
c313de
         if (info->addr.spaprvio.has_reg)
c313de
-            virBufferAsprintf(buf, " reg='0x%llx'", info->addr.spaprvio.reg);
c313de
+            virBufferAsprintf(&attrBuf, " reg='0x%llx'", info->addr.spaprvio.reg);
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
c313de
-        virBufferAsprintf(buf, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
c313de
+        virBufferAsprintf(&attrBuf, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
c313de
                           info->addr.ccw.cssid,
c313de
                           info->addr.ccw.ssid,
c313de
                           info->addr.ccw.devno);
c313de
@@ -6557,15 +6559,15 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
c313de
         if (info->addr.isa.iobase > 0)
c313de
-            virBufferAsprintf(buf, " iobase='0x%x'", info->addr.isa.iobase);
c313de
+            virBufferAsprintf(&attrBuf, " iobase='0x%x'", info->addr.isa.iobase);
c313de
         if (info->addr.isa.irq > 0)
c313de
-            virBufferAsprintf(buf, " irq='0x%x'", info->addr.isa.irq);
c313de
+            virBufferAsprintf(&attrBuf, " irq='0x%x'", info->addr.isa.irq);
c313de
         break;
c313de
 
c313de
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
c313de
-        virBufferAsprintf(buf, " slot='%u'", info->addr.dimm.slot);
c313de
+        virBufferAsprintf(&attrBuf, " slot='%u'", info->addr.dimm.slot);
c313de
         if (info->addr.dimm.base)
c313de
-            virBufferAsprintf(buf, " base='0x%llx'", info->addr.dimm.base);
c313de
+            virBufferAsprintf(&attrBuf, " base='0x%llx'", info->addr.dimm.base);
c313de
 
c313de
         break;
c313de
 
c313de
@@ -6575,7 +6577,9 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
c313de
         break;
c313de
     }
c313de
 
c313de
-    virBufferAddLit(buf, "/>\n");
c313de
+    virXMLFormatElement(buf, "address", &attrBuf, NULL);
c313de
+
c313de
+    virBufferFreeAndReset(&attrBuf);
c313de
 }
c313de
 
c313de
 static int
c313de
-- 
c313de
2.22.0
c313de