diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7b1dc06c32b7cf6b77a8335d920a1c96ea9f2820..d2c1d2e8a92d61c49e69184ab1fb6fc8926afb5a 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 0000000000000000000000000000000000000000..ded204a4fcc37449e66b56a365d003cd369be34a --- /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 0000000000000000000000000000000000000000..636e984265e88855fe2638999f533a6a4c2665d7 --- /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 4cc1b6a57cdbe04ddf9fdafcfe62aa745d947f19..44b388c43aa6eade19d71330f9a4dd6df98aa815 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");