Bug 1591636 - Fails to hotplug/unplug guestfwd character device
Summary: Fails to hotplug/unplug guestfwd character device
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.0
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: 8.0
Assignee: Michal Privoznik
QA Contact: jiyan
URL:
Whiteboard:
Depends On: 1677200
Blocks: 1624204
TreeView+ depends on / blocked
 
Reported: 2018-06-15 07:31 UTC by Fangge Jin
Modified: 2020-11-14 08:10 UTC (History)
10 users (show)

Fixed In Version: libvirt-5.3.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1624204 1677200 (view as bug list)
Environment:
Last Closed: 2019-11-06 07:11:37 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2019:3723 0 None None None 2019-11-06 07:11:52 UTC

Description Fangge Jin 2018-06-15 07:31:35 UTC
Description of problem:
Fails to hotplug/unplug guestfwd character device

Version-Release number of selected component (if applicable):
libvirt-4.4.0-2.virtcov.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Start a guest

2.Attach guestfwd to guest:
# cat guestfwd.xml 
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='10.0.2.1' port='4600'/>
    </channel>

# virsh attach-device 1 guestfwd.xml 
error: Failed to attach device from guestfwd.xml
error: internal error: unable to execute QEMU command 'device_add': 'user' is not a valid device model name


3.Coldplug guestfwd to guest and restart guest

4.Hotunplug guestfwd:
# virsh detach-device 1 guestfwd.xml 
error: Failed to detach device from guestfwd.xml
error: internal error: unable to execute QEMU command 'device_del': Device 'channel3' not found


Actual results:
Hotplug/unplug guestfwd fails

Expected results:
Hotplug/unplug guestfwd succeeds

Additional info:
Log:
2018-06-15 07:26:49.954+0000: 26130: info : qemuMonitorIOWrite:535 : QEMU_MONITOR_IO_WRITE: mon=0x7fc67402c030 buf={"execute":"device_add","arguments":{"driver":"user","guestfwd":"tcp:10.0.2.1:4600-chardev:charchannel3","id":"user-channel3"},"id":"libvirt-22"}

2018-06-15 07:28:13.555+0000: 26136: debug : qemuMonitorJSONCheckError:383 : unable to execute QEMU command {"execute":"device_del","arguments":{"id":"channel3"},"id":"libvirt-21"}: {"id":"libvirt-21","error":{"class":"DeviceNotFound","desc":"Device 'channel3' not found"}}

Comment 2 jiyan 2018-07-05 08:53:04 UTC
Besides, this kind of device does not accept 'ua-' alias.
Record this issue here, Please pay attention to it when verifying this bug.
https://bugzilla.redhat.com/show_bug.cgi?id=1586027#c5
https://bugzilla.redhat.com/show_bug.cgi?id=1586027#c6

Comment 3 jiyan 2018-07-30 09:59:51 UTC
Version:
kernel-3.10.0-927.el7.x86_64
libvirt-4.5.0-4.el7.x86_64
qemu-kvm-rhev-2.12.0-8.el7.x86_64

Steps:
S1:
# virsh dumpxml vm1 --inactive|grep "<channel" -A7
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='10.0.2.1' port='4600'/>
    </channel>

# virsh start vm1
Domain vm1 started

S2:
# virsh dumpxml vm1 --inactive|grep "<channel" -A7
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='5.0.2.1' port='4600'/>
    </channel>

# virsh destroy vm1;virsh start vm1
Domain vm1 destroyed

error: Failed to start domain vm1
error: internal error: qemu unexpectedly closed the monitor: 2018-07-30T09:55:24.546820Z qemu-kvm: Conflicting/invalid host:port in guest forwarding rule 'tcp:5.0.2.1:4600-chardev:charchannel0'

Hi michal, It seems that guestfwd character device can only accept this address "address='10.0.2.1'" even through I did not configure interface for VM or Vm can not receive data packet when ping 10.0.2.1

Is there any rule for this device or is that a bug?
Could you please help to check it? Thx

Comment 5 Michal Privoznik 2019-02-14 08:35:17 UTC
I've just merged patches upstream:

17ddfd420a qemuhotplugtest: Test guestfwd attach and detach
112f3a8d0f qemu_hotplug: Detach guestfwd using netdev_del
903315dc8f qemu_hotplug: Attach guestfwd using netdev_add
18b8f67745 qemuL: Drop "user-" prefix for guestfwd netdev
f538f5ed3a qemu: Use @tmpChr in qemuDomainDetachChrDevice to build device string

v5.0.0-387-g17ddfd420a

However, as mentioned here:

https://www.redhat.com/archives/libvir-list/2019-February/msg00798.html

it is important to use new enough qemu (at the time I'm writing these lines there's no qemu released that has the fix and thus only qemu from git works). The qemu commit that fixes qemu behaviour is:

commit e47f81b617684c4546af286d307b69014a83538a
Merge: ff372bb5c4 ee261c0233
Author:     Peter Maydell <peter.maydell>
AuthorDate: Thu Feb 7 18:53:25 2019 +0000
Commit:     Peter Maydell <peter.maydell>
CommitDate: Thu Feb 7 18:53:25 2019 +0000

    Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging
    
    More work towards libslirp

Comment 6 Michal Privoznik 2019-02-14 09:17:04 UTC
(In reply to jiyan from comment #3)
> Hi michal, It seems that guestfwd character device can only accept this
> address "address='10.0.2.1'" even through I did not configure interface for
> VM or Vm can not receive data packet when ping 10.0.2.1
> 
> Is there any rule for this device or is that a bug?
> Could you please help to check it? Thx

The thing is, that guestfwd is really just an attribute of slirp (also known as <interface type='user'/>) and libvirt handles this as a separate object:

https://www.redhat.com/archives/libvir-list/2019-February/msg00780.html

I had to use qemu cmd line passthrough to fill missing attributes and now I'm able to get it work:

  <qemu:commandline>
    <qemu:arg value='-chardev'/>
    <qemu:arg value='socket,path=/tmp/sock,server,nowait,id=charchannel3'/>
    <qemu:arg value='-netdev'/>
    <qemu:arg value='user,net=172.17.2.0/24,ipv6-net=2001:db8:ac10:fd01::/64,guestfwd=tcp:172.17.2.4:4600-chardev:charchannel3,id=channel3'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='rtl8139,netdev=channel3,id=net3,mac=00:11:22:33:44:55,bus=pci.0,addr=0x6'/>
  </qemu:commandline>

Comment 9 jiyan 2019-07-03 07:02:32 UTC
Verified this bug on libvirt-5.4.0-2.module+el8.1.0+3523+b348b848.x86_64

Version:
libvirt-5.4.0-2.module+el8.1.0+3523+b348b848.x86_64
qemu-kvm-4.0.0-4.module+el8.1.0+3523+b348b848.x86_64
kernel-4.18.0-109.el8.x86_64

Steps:
1. Prepare a running VM and the following guestfwd xml file
# virsh domstate test
running

# cat guestfwd.xml 
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='10.0.2.1' port='4600'/>
      <alias name="ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c"/>
    </channel>

2. Hot-plug the guestfwd device to VM twice and check the dumpxml, then hot-unplug twice
# virsh attach-device test guestfwd.xml 
Device attached successfully

# virsh attach-device test guestfwd.xml 
error: Failed to attach device from guestfwd.xml
error: XML error: non unique alias detected: ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c

# virsh dumpxml test |grep "<channel" -A5
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='10.0.2.1' port='4600'/>
      <alias name='ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c'/>
    </channel>

# virsh detach-device test guestfwd.xml 
Device detached successfully

# virsh detach-device test guestfwd.xml 
error: Failed to detach device from guestfwd.xml
error: device not found: chr type 'channel' device not present in domain configuration

# virsh dumpxml test |grep "<channel" -A5
No channel related info

3. Cold-plug the guestfwd device to VM, restart VM and check dumpxml
# virsh attach-device test guestfwd.xml --config
Device attached successfully

# virsh destroy test;virsh start test
Domain test destroyed

Domain test started

# virsh dumpxml test |grep "<channel" -A5
    <channel type='unix'>
      <source mode='bind' path='/tmp/guestfwd'/>
      <target type='guestfwd' address='10.0.2.1' port='4600'/>
      <alias name='ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c'/>
    </channel>
    <input type='tablet' bus='usb'>

4. hot-unplug/cold-unplug the device twice
# virsh detach-device-alias test ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c
Device detach request sent successfully

# virsh detach-device-alias test ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c
error: Failed to detach device with alias ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c
error: internal error: no device found with alias ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c

# virsh detach-device-alias test ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c --config
Device detach request sent successfully

# virsh detach-device-alias test ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c --config
error: Failed to detach device with alias ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c
error: internal error: no device found with alias ua-daf12aa7-9bf6-4c92-a816-fe61b923bd2c

# systemctl restart libvirtd

# virsh dumpxml test |grep "<channel" -A5
No channel related info

# virsh dumpxml test --inactive |grep "<channel" -A5
No channel related info

The test result is as expected, move this bug to be verified.

Comment 11 errata-xmlrpc 2019-11-06 07:11:37 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/RHBA-2019:3723


Note You need to log in before you can comment on or make changes to this bug.