Blob Blame History Raw
From 4e32b3e8ab394aaf1f94b1166d7c5e38cec8ede4 Mon Sep 17 00:00:00 2001
Message-Id: <4e32b3e8ab394aaf1f94b1166d7c5e38cec8ede4@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Fri, 9 Jun 2017 12:48:53 +0200
Subject: [PATCH] Use a separate buffer for <controller><driver>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Make adding new attributes easier.

(cherry picked from commit 5e5fc766257b05979c37593434d28cc9eb7e0cf0)
Signed-off-by: Ján Tomko <jtomko@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1283251
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d5c5a7030b..242a79a7e7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21332,6 +21332,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
     const char *model = NULL;
     const char *modelName = NULL;
     bool pcihole64 = false, pciModel = false, pciTarget = false;
+    virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -21436,26 +21437,26 @@ virDomainControllerDefFormat(virBufferPtr buf,
             }
         }
 
-        if (def->queues || def->cmd_per_lun ||
-            def->max_sectors || def->ioeventfd || def->iothread) {
+        if (def->queues)
+            virBufferAsprintf(&driverBuf, " queues='%u'", def->queues);
+
+        if (def->cmd_per_lun)
+            virBufferAsprintf(&driverBuf, " cmd_per_lun='%u'", def->cmd_per_lun);
+
+        if (def->max_sectors)
+            virBufferAsprintf(&driverBuf, " max_sectors='%u'", def->max_sectors);
+
+        if (def->ioeventfd) {
+            virBufferAsprintf(&driverBuf, " ioeventfd='%s'",
+                              virTristateSwitchTypeToString(def->ioeventfd));
+        }
+
+        if (def->iothread)
+            virBufferAsprintf(&driverBuf, " iothread='%u'", def->iothread);
+
+        if (virBufferUse(&driverBuf)) {
             virBufferAddLit(buf, "<driver");
-            if (def->queues)
-                virBufferAsprintf(buf, " queues='%u'", def->queues);
-
-            if (def->cmd_per_lun)
-                virBufferAsprintf(buf, " cmd_per_lun='%u'", def->cmd_per_lun);
-
-            if (def->max_sectors)
-                virBufferAsprintf(buf, " max_sectors='%u'", def->max_sectors);
-
-            if (def->ioeventfd) {
-                virBufferAsprintf(buf, " ioeventfd='%s'",
-                                  virTristateSwitchTypeToString(def->ioeventfd));
-            }
-
-            if (def->iothread)
-                virBufferAsprintf(buf, " iothread='%u'", def->iothread);
-
+            virBufferAddBuffer(buf, &driverBuf);
             virBufferAddLit(buf, "/>\n");
         }
 
-- 
2.13.1