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 <serial> device present in the XML, but no serial <console>, or if there isn't any <console> at all but the domain definition hasn't gone through a parse->format->parse round-trip, the <console> 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 | 23 +++++++++++++ .../qemuxml2argv-console-compat2.xml | 35 ++++++++++++++++++++ .../qemuxml2xmlout-console-compat2.xml | 38 ++++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 4 files changed, 97 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 934f6cb..2a9510e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2965,6 +2965,25 @@ 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 (STREQ(def->os.type, "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) + 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) @@ -18288,6 +18307,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 (STREQ(def->os.type, "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 0000000..ded204a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-console-compat2.xml @@ -0,0 +1,35 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <controller type='virtio-serial' index='0'/> + <serial type='pty'> + <target port='0'/> + </serial> + <console type='pty'> + <target type='virtio' port='0'/> + </console> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml new file mode 100644 index 0000000..636e984 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-console-compat2.xml @@ -0,0 +1,38 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <controller type='virtio-serial' index='0'/> + <serial type='pty'> + <target port='0'/> + </serial> + <console type='pty'> + <target type='serial' port='0'/> + </console> + <console type='pty'> + <target type='virtio' port='0'/> + </console> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 5941323..f87f7ea 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -278,6 +278,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"); -- 1.8.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list