Bug 1454671

Summary: libvirt reports a strange error when hotplugging an rng device with connect host attribute missing
Product: Red Hat Enterprise Linux 7 Reporter: Fangge Jin <fjin>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Yanqiu Zhang <yanqzhan>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.4CC: dyuan, jtomko, rbalakri, xuzhang, yanqzhan, zpeng
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-3.8.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 10:44:33 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 Fangge Jin 2017-05-23 09:42:56 UTC
Description of problem:
Libvirt should report proper error when host attribute of connect mode is missing for a udp-backend rng device

Version-Release number of selected component (if applicable):


How reproducible:
100%

Steps to Reproduce:
1.Prepare a rng xml file as below, host attribute is missing for connect mode:
# cat rng.xml
<rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1' service='2234' /> 
   <source mode='connect' service='1234' />
  </backend>
 </rng>

2.Hotplug rng device:
# virsh attach-device vm1 /tmp/rng.xml 
error: Failed to attach device from /tmp/rng.xml
error: internal error: argument key 'host' must not have null value

3.Add the same rng device to guest xml by virsh edit.

4.Start a guest:
# virsh start vm1
error: Failed to start domain vm1
error: internal error: process exited while connecting to monitor: 2017-05-23T09:29:24.139160Z qemu-kvm: -chardev pty,id=charserial0: char device redirected to /dev/pts/1 (label charserial0)
2017-05-23T09:29:24.140595Z qemu-kvm: -chardev udp,id=charrng0,host=,port=1234,localaddr=127.0.0.1,localport=2234: address resolution failed for 127.0.0.1:2234: Address family for hostname not supported


Actual results:
As step2 and step4 shown, host is required for connect mode. But libvirt doesn't check it when parsing xml

Expected results:
Libvirt check host attribute when parsing xml and output proper error like below:
error: internal error: Missing bind host attribute for rng device

Additional info:

Comment 1 Ján Tomko 2017-09-26 12:01:40 UTC
If you do not specify the host, qemu tries to use localhost.

Here's the patch that fixes the hotplug case:
https://www.redhat.com/archives/libvir-list/2017-September/msg00926.html

The QEMU error happens for me even if I specify host='localhost' explicitly, unless I comment out the ::1 localhost entry in /etc/hosts. So that bug is in QEMU.

Comment 2 Ján Tomko 2017-09-27 10:43:46 UTC
Pushed upstream as:
commit 955caf171c0370cf4a32eec9a18aca2b653e6b82
Author:     Ján Tomko <jtomko>
CommitDate: 2017-09-27 12:38:27 +0200

    qemu: fix hotplug of udp device with no connect host
    
    Use an empty string to let qemu fill out the default.
    This matches what's done in qemuBuildChrChardevStr.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1454671
    
    Signed-off-by: Ján Tomko <jtomko>
    Reviewed-by: John Ferlan <jferlan>

git describe: v3.7.0-177-g955caf171

Comment 4 Yanqiu Zhang 2017-10-24 12:36:52 UTC
Verify this bug with libvirt-3.8.0-1.el7.x86_64.

Steps to verify:
# cat connect-miss-host.xml
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' host='127.0.0.1' service='2234'/>
        <source mode='connect' service='1024'/>
      </backend>
    </rng>

# virsh attach-device V connect-miss-host.xml
error: Failed to attach device from connect-miss-host.xml
error: internal error: unable to execute QEMU command 'chardev-add': address resolution failed for 127.0.0.1:2234: Address family for hostname not supported


The error info is consistent with the 'start' error:
# virsh start V
error: Failed to start domain V
error: internal error: process exited while connecting to monitor: 2017-10-24T11:58:00.750126Z qemu-kvm: -chardev pty,id=charserial0: char device redirected to /dev/pts/1 (label charserial0)
2017-10-24T11:58:00.751434Z qemu-kvm: -chardev udp,id=charrng0,host=,port=1024,localaddr=127.0.0.1,localport=2234: address resolution failed for 127.0.0.1:2234: Address family for hostname not supported

Comment 5 Yanqiu Zhang 2017-10-24 13:11:07 UTC
Hi Jan,
  Here are my some test results and conclusions, could you help to confirm?

1.tcp 'connect' mode without 'host' will report "missing source host" error:
# cat tcp-connect.xml 
    <rng model='virtio'>
      <backend model='egd' type='tcp'>
        <source mode='connect' service='1024'/>
      </backend>
    </rng>

# virsh attach-device V tcp-connect.xml 
error: Failed to attach device from tcp-connect.xml
error: internal error: Missing source host attribute for char device

2.udp 'connect' mode without 'host' will successfully hotplug:
# cat only-connect.xml 
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='connect' service='1024'/>
      </backend>
    </rng>

# netstat -tunap|grep 1024
udp6       0      0 ::1:34130               ::1:1024                ESTABLISHED 22826/qemu-kvm   

3.udp 'bind + connect' mode, bind host='::1' or bind without 'host' will also successfully hotplug:
# cat bind-v6-host.xml 
 <rng model='virtio'>
  <backend model='egd' [host='::1'] type='udp'>
   <source mode='bind' service='2234'/>
   <source mode='connect' service='1024'/>
  </backend>
 </rng>

# virsh attach-device V bind-v6-host.xml 
Device attached successfully

# netstat -tunap|grep 1024
udp6       0      0 ::1:2234                ::1:1024                ESTABLISHED 23142/qemu-kvm    

4.udp 'bind + connect' mode, bind without 'host', connect with 'host'
# cat connect-v6-host.xml 
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' service='1234'/>
   <source mode='connect' host='127.0.0.1' service='1024'/>
  </backend>
 </rng>

# virsh attach-device V connect-v6-host.xml 
Device attached successfully

# netstat -tunap|grep 1024
udp        0      0 127.0.0.1:1234          127.0.0.1:1024          ESTABLISHED 23530/qemu-kvm      


Conclusion:
1. So the udp type will automatically connect to a ipv6 address "::1" if no 'connect host' attribute specified. (I also tried serial device, same performance). Is it correct and reasonable?

2.The error "127.0.0.1:2234: Address family for hostname not supported" means that the 'bind host' should also be a ipv6 address, to be consistent with the 'connect host'.  Is it possible to give a more clear indication for users?

3.For the 4th scenario, it can succeed. So why 'bind host' address must obey the family of 'connect host' address? Can 'connect host' address obey the family of 'connect host' address? Then user can succeed to do hotplug if specify any address of them two.


Thank you in advance!

Comment 6 Yanqiu Zhang 2017-10-25 07:16:29 UTC
Sorry a mistake, the 3rd scenario's xml in comment 5 should be:
# cat bind-v6-host.xml 
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' [host='::1'] service='2234'/>
   <source mode='connect' service='1024'/>
  </backend>
 </rng>

Comment 7 Ján Tomko 2017-10-26 08:18:52 UTC
If you do not specify the host, libvirt leaves it up to QEMU and libvirt should not be making any claims about what exactly will happen. The purpose of my patches was to unify the behavior without restricting something that possibly worked in libvirt before.

Ad. 2) 3) see comment 1, the address family error is a QEMU bug.

Comment 8 Yanqiu Zhang 2017-10-27 09:22:30 UTC
Thanks Jan!

Mark this bug as verified according to comment 4.

Comment 9 Yanqiu Zhang 2017-11-03 12:49:36 UTC
Filed a bug BZ-1509265 to track the related qemu issue after confirmed with qemu qe.

Comment 13 errata-xmlrpc 2018-04-10 10:44:33 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://access.redhat.com/errata/RHEA-2018:0704