[PATCH] qemu: Restored original console alias

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Because of some crazy backward compatibility, console device is in
some cases just an alias to a serial device. This means, in the process
of generating XML description of a domain, all the interesting info is
taken from corresponding serial device, if that's the case. Including
the device alias. That means, we produce:
    <console type='pty' tty='/dev/pts/20'>
      ...
      <alias name='serial0'/>
    </console>

(notice the assigned alias)

Maybe this is okay, maybe its wrong either. Anyway, later, when libvirtd
restarts, and we parse the state XML file, we read the wrong alias back.
Hence, the internal representation is different to the state it was in
prior the libvirtd restart.
---
 src/qemu/qemu_domain.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8d79066..96d88ec 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -804,6 +804,34 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         dev->data.chr->source.data.nix.listen = true;
     }
 
+    /* For some really crazy back compat in virDomainDefFormatInternal we must
+     * restore the original console alias. For hvm domains, we are formatting
+     * a dummy console device (based on a serial device which it refers to)
+     * instead of the original one.  That means the device aliases in memory
+     * and in the formatted XML are not in sync. While in memory we still have
+     * 'consoleN', in the formatted XML we have 'serialN'. */
+    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
+        dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
+        dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL &&
+        STREQ(def->os.type, "hvm")) {
+        int id;
+        char *alias = dev->data.chr->info.alias;
+        const char *serial_alias = "serial";
+
+        if (alias && STRPREFIX(alias, serial_alias)) {
+            alias += strlen(serial_alias);
+
+            if (virStrToLong_i(alias, NULL, 10, &id) < 0)
+                goto cleanup;
+
+            VIR_FREE(dev->data.chr->info.alias);
+            if (virAsprintf(&dev->data.chr->info.alias, "console%d", id) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        }
+    }
+
     ret = 0;
 
 cleanup:
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]