From 8728a78e904de7ddfa32b7761b40d6339fa15030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 13 Aug 2014 13:06:04 +0200 Subject: [PATCH] Always add 'console' matching the 'serial' device We have been formatting the first serial device also as a console device, but only if there were no other consoles. If there is a device present in the XML, but no serial , or if there isn't any at all but the domain definition hasn't gone through a parse->format->parse round-trip, the device would not be formatted. Change the code to always add the stub device for the first serial device. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1089914 --- src/conf/domain_conf.c | 25 ++++++++++++ .../qemuxml2argv-console-compat2.xml | 35 +++++++++++++++++ .../qemuxml2xmlout-console-compat2.xml | 38 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 4 files changed, 99 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-console-compat2.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7b1dc06c32..d2c1d2e8a9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3588,6 +3588,27 @@ virDomainDefPostParseInternal(virDomainDefPtr def, def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; } + } else if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && def->nserials > 0 && + def->serials[0]->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && + def->serials[0]->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA) { + /* Create a stub console to match the serial port. + * console[0] either does not exist + * or has a different type than SERIAL or NONE. + */ + virDomainChrDefPtr chr; + if (VIR_ALLOC(chr) < 0) + return -1; + + if (VIR_INSERT_ELEMENT(def->consoles, + 0, + 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) @@ -21540,6 +21561,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (virDomainChrDefFormat(buf, &console, flags) < 0) goto error; } + /* The back-compat console device stub is added when parsing the domain XML + * and handled above, this is for formatting definitions created via other + * means. + */ if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0 && def->nserials > 0) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-console-compat2.xml b/tests/qemuxml2argvdata/qemuxml2argv-console-compat2.xml new file mode 100644 index 0000000000..ded204a4fc --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-console-compat2.xml @@ -0,0 +1,35 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + +
+ + + + + + + + + + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml new file mode 100644 index 0000000000..636e984265 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml @@ -0,0 +1,38 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + +
+ + + + + + + + + + + + + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 4cc1b6a57c..44b388c43a 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -472,6 +472,7 @@ mymain(void) DO_TEST("serial-spiceport-nospice"); DO_TEST("parallel-tcp"); DO_TEST("console-compat"); + DO_TEST_DIFFERENT("console-compat2"); DO_TEST("console-virtio-many"); DO_TEST("channel-guestfwd"); DO_TEST("channel-virtio"); -- GitLab