[PATCH 6/8] Use a separate buffer for <hub> subelements

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

 



Switch virDomainHubDefFormat to use a separate buffer for subelements.
---
 src/conf/domain_conf.c | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fdac0e0ba..7728321cb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3529,23 +3529,6 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device)
     return NULL;
 }
 
-static bool
-virDomainDeviceInfoNeedsFormat(virDomainDeviceInfoPtr info, unsigned int flags)
-{
-    if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
-        return true;
-    if (info->alias && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))
-        return true;
-    if (info->mastertype != VIR_DOMAIN_CONTROLLER_MASTER_NONE)
-        return true;
-    if ((info->rombar != VIR_TRISTATE_SWITCH_ABSENT) ||
-        info->romfile)
-        return true;
-    if (info->bootIndex)
-        return true;
-    return false;
-}
-
 
 static int
 virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED,
@@ -24304,6 +24287,9 @@ virDomainHubDefFormat(virBufferPtr buf,
                       unsigned int flags)
 {
     const char *type = virDomainHubTypeToString(def->type);
+    virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -24311,14 +24297,16 @@ virDomainHubDefFormat(virBufferPtr buf,
         return -1;
     }
 
-    virBufferAsprintf(buf, "<hub type='%s'", type);
+    if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
+        return -1;
+
+    if (virBufferCheckError(&childBuf) < 0)
+        return -1;
 
-    if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
+    virBufferAsprintf(buf, "<hub type='%s'", type);
+    if (virBufferUse(&childBuf)) {
         virBufferAddLit(buf, ">\n");
-        virBufferAdjustIndent(buf, 2);
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
-            return -1;
-        virBufferAdjustIndent(buf, -2);
+        virBufferAddBuffer(buf, &childBuf);
         virBufferAddLit(buf, "</hub>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
-- 
2.13.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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