render / rpms / libvirt

Forked from rpms/libvirt 7 months ago
Clone
3e5111
From c8fc71708382f37cfc7437b15f58e3d5ab1f2cb1 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <c8fc71708382f37cfc7437b15f58e3d5ab1f2cb1@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Fri, 9 Jun 2017 12:48:51 +0200
3e5111
Subject: [PATCH] Use a separate buffer for <input> subelements
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
Instead of figuring out upfront whether <input> will be a single
3e5111
or a pair element, format the subelements into a separate buffer
3e5111
and close <input/> early if this buffer is empty.
3e5111
3e5111
(cherry picked from commit 51219e11b8c57c7a9755eedd72986269b78ccfb7)
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 | 21 +++++++++++----------
3e5111
 1 file changed, 11 insertions(+), 10 deletions(-)
3e5111
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index b473ce6b1e..4228cad610 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -23152,6 +23152,7 @@ virDomainInputDefFormat(virBufferPtr buf,
3e5111
 {
3e5111
     const char *type = virDomainInputTypeToString(def->type);
3e5111
     const char *bus = virDomainInputBusTypeToString(def->bus);
3e5111
+    virBuffer childbuf = VIR_BUFFER_INITIALIZER;
3e5111
 
3e5111
     /* don't format keyboard into migratable XML for backward compatibility */
3e5111
     if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
3e5111
@@ -23174,17 +23175,17 @@ virDomainInputDefFormat(virBufferPtr buf,
3e5111
     virBufferAsprintf(buf, "
3e5111
                       type, bus);
3e5111
 
3e5111
-    if (virDomainDeviceInfoNeedsFormat(&def->info, flags) ||
3e5111
-        def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
3e5111
-        virBufferAddLit(buf, ">\n");
3e5111
-        virBufferAdjustIndent(buf, 2);
3e5111
-        virBufferEscapeString(buf, "<source evdev='%s'/>\n", def->source.evdev);
3e5111
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
3e5111
-            return -1;
3e5111
-        virBufferAdjustIndent(buf, -2);
3e5111
-        virBufferAddLit(buf, "</input>\n");
3e5111
-    } else {
3e5111
+    virBufferAdjustIndent(&childbuf, virBufferGetIndent(buf, false) + 2);
3e5111
+    virBufferEscapeString(&childbuf, "<source evdev='%s'/>\n", def->source.evdev);
3e5111
+    if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0)
3e5111
+        return -1;
3e5111
+
3e5111
+    if (!virBufferUse(&childbuf)) {
3e5111
         virBufferAddLit(buf, "/>\n");
3e5111
+    } else {
3e5111
+        virBufferAddLit(buf, ">\n");
3e5111
+        virBufferAddBuffer(buf, &childbuf);
3e5111
+        virBufferAddLit(buf, "</input>\n");
3e5111
     }
3e5111
 
3e5111
     return 0;
3e5111
-- 
3e5111
2.13.1
3e5111