render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
3e5111
From 0f6008b1fa9b236f673163a123b71aeebb6b4454 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <0f6008b1fa9b236f673163a123b71aeebb6b4454@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Fri, 9 Jun 2017 12:48:52 +0200
3e5111
Subject: [PATCH] Use a separate buffer for <disk><driver>
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
Eliminate the big condition at the start.
3e5111
Instead use a buffer and only format the element if the buffer
3e5111
is non-empty.
3e5111
3e5111
(cherry picked from commit d89803d27c3088aff6f4d062a578fc9938a80e04)
3e5111
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1283251
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/conf/domain_conf.c | 55 +++++++++++++++++++++++++-------------------------
3e5111
 1 file changed, 27 insertions(+), 28 deletions(-)
3e5111
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index 4228cad610..d5c5a7030b 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -21088,6 +21088,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
3e5111
     const char *sgio = virDomainDeviceSGIOTypeToString(def->sgio);
3e5111
     const char *discard = virDomainDiskDiscardTypeToString(def->discard);
3e5111
     const char *detect_zeroes = virDomainDiskDetectZeroesTypeToString(def->detect_zeroes);
3e5111
+    virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
3e5111
 
3e5111
     if (!type || !def->src->type) {
3e5111
         virReportError(VIR_ERR_INTERNAL_ERROR,
3e5111
@@ -21139,35 +21140,33 @@ virDomainDiskDefFormat(virBufferPtr buf,
3e5111
     virBufferAddLit(buf, ">\n");
3e5111
     virBufferAdjustIndent(buf, 2);
3e5111
 
3e5111
-    if (def->src->driverName || def->src->format > 0 || def->cachemode ||
3e5111
-        def->error_policy || def->rerror_policy || def->iomode ||
3e5111
-        def->ioeventfd || def->event_idx || def->copy_on_read ||
3e5111
-        def->discard || def->iothread || def->detect_zeroes) {
3e5111
+    virBufferEscapeString(&driverBuf, " name='%s'", def->src->driverName);
3e5111
+    if (def->src->format > 0)
3e5111
+        virBufferAsprintf(&driverBuf, " type='%s'",
3e5111
+                          virStorageFileFormatTypeToString(def->src->format));
3e5111
+    if (def->cachemode)
3e5111
+        virBufferAsprintf(&driverBuf, " cache='%s'", cachemode);
3e5111
+    if (def->error_policy)
3e5111
+        virBufferAsprintf(&driverBuf, " error_policy='%s'", error_policy);
3e5111
+    if (def->rerror_policy)
3e5111
+        virBufferAsprintf(&driverBuf, " rerror_policy='%s'", rerror_policy);
3e5111
+    if (def->iomode)
3e5111
+        virBufferAsprintf(&driverBuf, " io='%s'", iomode);
3e5111
+    if (def->ioeventfd)
3e5111
+        virBufferAsprintf(&driverBuf, " ioeventfd='%s'", ioeventfd);
3e5111
+    if (def->event_idx)
3e5111
+        virBufferAsprintf(&driverBuf, " event_idx='%s'", event_idx);
3e5111
+    if (def->copy_on_read)
3e5111
+        virBufferAsprintf(&driverBuf, " copy_on_read='%s'", copy_on_read);
3e5111
+    if (def->discard)
3e5111
+        virBufferAsprintf(&driverBuf, " discard='%s'", discard);
3e5111
+    if (def->iothread)
3e5111
+        virBufferAsprintf(&driverBuf, " iothread='%u'", def->iothread);
3e5111
+    if (def->detect_zeroes)
3e5111
+        virBufferAsprintf(&driverBuf, " detect_zeroes='%s'", detect_zeroes);
3e5111
+    if (virBufferUse(&driverBuf)) {
3e5111
         virBufferAddLit(buf, "
3e5111
-        virBufferEscapeString(buf, " name='%s'", def->src->driverName);
3e5111
-        if (def->src->format > 0)
3e5111
-            virBufferAsprintf(buf, " type='%s'",
3e5111
-                              virStorageFileFormatTypeToString(def->src->format));
3e5111
-        if (def->cachemode)
3e5111
-            virBufferAsprintf(buf, " cache='%s'", cachemode);
3e5111
-        if (def->error_policy)
3e5111
-            virBufferAsprintf(buf, " error_policy='%s'", error_policy);
3e5111
-        if (def->rerror_policy)
3e5111
-            virBufferAsprintf(buf, " rerror_policy='%s'", rerror_policy);
3e5111
-        if (def->iomode)
3e5111
-            virBufferAsprintf(buf, " io='%s'", iomode);
3e5111
-        if (def->ioeventfd)
3e5111
-            virBufferAsprintf(buf, " ioeventfd='%s'", ioeventfd);
3e5111
-        if (def->event_idx)
3e5111
-            virBufferAsprintf(buf, " event_idx='%s'", event_idx);
3e5111
-        if (def->copy_on_read)
3e5111
-            virBufferAsprintf(buf, " copy_on_read='%s'", copy_on_read);
3e5111
-        if (def->discard)
3e5111
-            virBufferAsprintf(buf, " discard='%s'", discard);
3e5111
-        if (def->iothread)
3e5111
-            virBufferAsprintf(buf, " iothread='%u'", def->iothread);
3e5111
-        if (def->detect_zeroes)
3e5111
-            virBufferAsprintf(buf, " detect_zeroes='%s'", detect_zeroes);
3e5111
+        virBufferAddBuffer(buf, &driverBuf);
3e5111
         virBufferAddLit(buf, "/>\n");
3e5111
     }
3e5111
 
3e5111
-- 
3e5111
2.13.1
3e5111