[libvirt] [PATCH 3/3] Create a console stub for the first serial device

Ján Tomko jtomko at redhat.com
Thu May 15 15:50:44 UTC 2014


The <console> alias for the first <serial> device was only
formatted when there were no consoles.

After removing this alias manually, a round-trip via XML
would add it again. However this was not the case when
it was removed and a virtio console was hotplugged.

https://bugzilla.redhat.com/show_bug.cgi?id=1089914
---
 src/conf/domain_conf.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3c0d2ff..69106bd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2923,6 +2923,26 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
         }
     }
 
+    /* Create a stub for the first serial device in consoles if there are none */
+    if (STREQ(def->os.type, "hvm") &&
+        def->nconsoles == 0 &&
+        def->nserials > 0) {
+
+        virDomainChrDefPtr chr;
+
+        if (VIR_ALLOC(chr) < 0)
+            return -1;
+
+        if (VIR_APPEND_ELEMENT(def->consoles,
+                               def->nconsoles,
+                               chr) < 0) {
+            VIR_FREE(chr);
+            return -1;
+        }
+        def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
+        def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
+    }
+
     if (virDomainDefRejectDuplicateControllers(def) < 0)
         return -1;
 
@@ -17739,16 +17759,6 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         if (virDomainChrDefFormat(buf, &console, flags) < 0)
             goto error;
     }
-    if (STREQ(def->os.type, "hvm") &&
-        def->nconsoles == 0 &&
-        def->nserials > 0) {
-        virDomainChrDef console;
-        memcpy(&console, def->serials[n], sizeof(console));
-        console.deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
-        console.targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
-        if (virDomainChrDefFormat(buf, &console, flags) < 0)
-            goto error;
-    }
 
     for (n = 0; n < def->nchannels; n++)
         if (virDomainChrDefFormat(buf, def->channels[n], flags) < 0)
-- 
1.8.3.2




More information about the libvir-list mailing list