Bug 1089914

Summary: first serial console is not formatted when other consoles are present
Product: Red Hat Enterprise Linux 7 Reporter: Hu Jianwei <jiahu>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: medium    
Version: 7.0CC: dyuan, honzhang, jtomko, mzhan, rbalakri, shyu, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 05:45:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hu Jianwei 2014-04-22 08:41:01 UTC
Description of problem:
Libvirt can not dumpxml serial type console device after hot-plugging a virtio console device

Version-Release number of selected component (if applicable):
libvirt-1.1.1-29.el7.x86_64
qemu-kvm-rhev-1.5.3-60.el7ev.x86_64
kernel-3.10.0-121.el7.x86_64

How reproducible:
100%

Steps to Reproduce:

[root@localhost ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     r7                             shut off

1. Remove below serial console part from inactive domain. Exactly, the serial console device will be added by libvirt automatically if we remove it purposely.(I think it works as design. )

    <console type='pty'>
      <target type='serial' port='0'/>
    </console>

[root@localhost ~]# virsh edit r7
Domain r7 XML configuration edited.

[root@localhost ~]# virsh dumpxml r7 | grep "<console" -A5
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
...

2. Start the domain and check the <console> device
[root@localhost ~]# virsh start r7
Domain r7 started

[root@localhost ~]# virsh dumpxml r7 | grep "<console" -A5
    <console type='pty' tty='/dev/pts/2'>
      <source path='/dev/pts/2'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
...

3. Attach a virtio console device to doamin, and check the console devices using dumpxml command line
[root@localhost ~]# cat console.xml 
<console type='pty'>
<target type='virtio'/>
</console>
[root@localhost ~]# virsh attach-device r7 console.xml
Device attached successfully

[root@localhost ~]# virsh dumpxml r7 | grep "<console" -A5
    <console type='pty' tty='/dev/pts/5'>
      <source path='/dev/pts/5'/>
      <target type='virtio' port='0'/>
      <alias name='console0'/>
    </console>
...

4. Check the serial console in guest

In guest, type below command line:
[root@localhost ~]# echo hello > /dev/ttyS0

In host, we can receive the word from the source side.
[root@localhost ~]# cat /dev/pts/2
hello
^C

Actual results:
As shown above, after step 3, the existing serial console device can not be displayed when using dumpxml to check it.

Expected results:
When we deleted the serial console device purposely, libvirt can add it back to domain and should show it normally even though we take some actions on console type devices.

Comment 2 Ján Tomko 2014-08-13 14:38:00 UTC
Upstream patch:
https://www.redhat.com/archives/libvir-list/2014-August/msg00577.html

Comment 4 Ján Tomko 2015-05-28 13:55:54 UTC
I rebased and resent the patch from last year:
https://www.redhat.com/archives/libvir-list/2015-May/msg01085.html

Comment 5 Ján Tomko 2015-06-04 08:36:27 UTC
Now pushed:
commit 8728a78e904de7ddfa32b7761b40d6339fa15030
Author:     Ján Tomko <jtomko>
CommitDate: 2015-06-04 10:04:44 +0200

    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 <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

git describe: v1.2.16-59-g8728a78

Comment 8 Shanzhi Yu 2015-07-13 08:20:54 UTC
1. Define a guest with below xml file(without console)
# virsh define /dev/stdin <<EOF
<domain type='kvm'>
  <name>r7</name>
  <memory unit='KiB'>1049600</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.2.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/r7.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
  </devices>
</domain>
EOF
Domain r7 defined from /dev/stdin

2. delete '<console></console>' part with 'virsh edit guest'
Domain r7 XML configuration edited.

3. check console part of guest 

# virsh dumpxml r7|grep console -A3 
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>

4. Start guest, check the console part and hotplug another console 
# virsh start r7 
Domain r7 started

# cat console.xml 
<console type='pty'>
    <target type='virtio'/>
</console>

# virsh attach-device  r7 console.xml 
error: Failed to attach device from console.xml
error: internal error: no virtio-serial controllers are available

# virsh dumpxml r7|grep console -A3 
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>

5. Cold-plug another console 

# virsh attach-device  r7 console.xml --config
Device attached successfully

# virsh dumpxml r7 --inactive |grep console -A3  
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <console type='pty'>
      <target type='virtio' port='1'/>
    </console>

6. Destroy/start guest, then check console again
# virsh destroy r7 
Domain r7 destroyed

# virsh start r7 
Domain r7 started

# virsh dumpxml r7   |grep console -A3  
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <console type='pty'>
      <source path='/dev/pts/5'/>
      <target type='virtio' port='1'/>
      <alias name='console1'/>
    </console>

The failure in step 4 is because there is no virtio-serial type controller, if I add '<controller type='virtio-serial></controller>', then the hot-plug will succeed. 
So, should libvirt will auto add this controller when I hot-plug a pty type console?

I'd change this bug to be verified status if it's acceptable

Comment 9 Ján Tomko 2015-07-13 12:14:47 UTC
Auto-adding a virtio-serial controller on hotplug is unrelated to this bug.

Please file a separate bug if you think the functionality would be helpful. Personally, I do not see the need for it - we don't auto add a controller for PCI devices either. And a virtio-serial controller can be hotplugged separately.

Comment 10 Shanzhi Yu 2015-07-13 12:29:17 UTC
Jan, thanks
Verify this bug.

Comment 12 errata-xmlrpc 2015-11-19 05:45:48 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2202.html