From d7a676ece48ca9958a119aab4e04c9cec3ed69f4 Mon Sep 17 00:00:00 2001
Message-Id: <d7a676ece48ca9958a119aab4e04c9cec3ed69f4.1476980707.git.phrdina@redhat.com>
In-Reply-To: <7b70eeb03f4fe190d78f50e72a1b0e5264af5299.1476980707.git.phrdina@redhat.com>
References: <7b70eeb03f4fe190d78f50e72a1b0e5264af5299.1476980707.git.phrdina@redhat.com>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Wed, 19 Oct 2016 09:57:41 +0200
Subject: [PATCH 2/4] domain: fix migration to older libvirt

Since TLS feature was introduced in libvirt 2.3.0 we have to modify
migratable XML for specific case where 'tls' attribute is based on
setting from qemu.conf.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/conf/domain_conf.c  | 24 +++++++++++++++++++++++-
 src/conf/domain_conf.h  |  1 +
 src/qemu/qemu_process.c |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e4fa9ad..aa425e2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1999,6 +1999,7 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
             return -1;
 
         dest->data.tcp.haveTLS = src->data.tcp.haveTLS;
+        dest->data.tcp.tlsFromConfig = src->data.tcp.tlsFromConfig;
         break;
 
     case VIR_DOMAIN_CHR_TYPE_UNIX:
@@ -10043,6 +10044,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     char *slave = NULL;
     char *append = NULL;
     char *haveTLS = NULL;
+    char *tlsFromConfig = NULL;
     int remaining = 0;
 
     while (cur != NULL) {
@@ -10052,6 +10054,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
                     mode = virXMLPropString(cur, "mode");
                 if (!haveTLS)
                     haveTLS = virXMLPropString(cur, "tls");
+                if (!tlsFromConfig)
+                    tlsFromConfig = virXMLPropString(cur, "tlsFromConfig");
 
                 switch ((virDomainChrType) def->type) {
                 case VIR_DOMAIN_CHR_TYPE_FILE:
@@ -10237,6 +10241,18 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
             goto error;
         }
 
+        if (tlsFromConfig &&
+            flags & VIR_DOMAIN_DEF_PARSE_STATUS) {
+            int tmp;
+            if (virStrToLong_i(tlsFromConfig, NULL, 10, &tmp) < 0) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("Invalid tlsFromConfig value: %s"),
+                               tlsFromConfig);
+                goto error;
+            }
+            def->data.tcp.tlsFromConfig = !!tmp;
+        }
+
         if (!protocol)
             def->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW;
         else if ((def->data.tcp.protocol =
@@ -10322,6 +10338,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     VIR_FREE(logappend);
     VIR_FREE(logfile);
     VIR_FREE(haveTLS);
+    VIR_FREE(tlsFromConfig);
 
     return remaining;
 
@@ -21482,9 +21499,14 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
                           def->data.tcp.listen ? "bind" : "connect");
         virBufferEscapeString(buf, "host='%s' ", def->data.tcp.host);
         virBufferEscapeString(buf, "service='%s'", def->data.tcp.service);
-        if (def->data.tcp.haveTLS != VIR_TRISTATE_BOOL_ABSENT)
+        if (def->data.tcp.haveTLS != VIR_TRISTATE_BOOL_ABSENT &&
+            !(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
+              def->data.tcp.tlsFromConfig))
             virBufferAsprintf(buf, " tls='%s'",
                     virTristateBoolTypeToString(def->data.tcp.haveTLS));
+        if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS)
+            virBufferAsprintf(buf, " tlsFromConfig='%d'",
+                              def->data.tcp.tlsFromConfig);
         virBufferAddLit(buf, "/>\n");
 
         virBufferAsprintf(buf, "<protocol type='%s'/>\n",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fcadf6c..7e12a57 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1095,6 +1095,7 @@ struct _virDomainChrSourceDef {
             int protocol;
             bool tlscreds;
             int haveTLS; /* enum virTristateBool */
+            bool tlsFromConfig;
         } tcp;
         struct {
             char *bindHost;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index cd3d376..04bc3c6 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5083,6 +5083,7 @@ qemuProcessPrepareDomainChardevIter(virDomainDefPtr def ATTRIBUTE_UNUSED,
                 chr->source.data.tcp.haveTLS = VIR_TRISTATE_BOOL_YES;
             else
                 chr->source.data.tcp.haveTLS = VIR_TRISTATE_BOOL_NO;
+            chr->source.data.tcp.tlsFromConfig = true;
         }
     }
 
-- 
2.10.1

