[libvirt] [PATCHv2] Always add 'console' matching the 'serial' device
John Ferlan
jferlan at redhat.com
Tue Jun 2 17:33:00 UTC 2015
On 05/28/2015 09:55 AM, Ján Tomko wrote:
> 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 6e57425..ec8f9fa 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -3587,6 +3587,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 (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)
If this fails we need to VIR_FREE(chr);
Everything else seems reasonable...
ACK
John
> + 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)
> @@ -21588,6 +21607,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 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 53bcc9f..d405e71 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");
>
More information about the libvir-list
mailing list