Bug 1387666

Summary: USB addresses are not assigned on hotplug after libvirtd restart
Product: Red Hat Enterprise Linux 7 Reporter: Ján Tomko <jtomko>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Pei Zhang <pzhang>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.3CC: dyuan, jdenemar, jtomko, pzhang, rbalakri, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-2.5.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 17:19:14 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 Ján Tomko 2016-10-21 13:41:36 UTC
Version-Release number of selected component (if applicable):
libvirt-2.0.0-10.el7

How reproducible:
100 %

Steps to Reproduce:
1. start a new domain
2. restart libvirtd
3. attach a USB device:
$ cat disk.xml
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/raw'/>
      <backingStore/>
      <target dev='sda' bus='usb'/>
    </disk>
$ virsh attach-device domain disk.xml

Actual results:
The device does not get a USB address.

Expected results:
The device does get a USB address.

Additional info:

Comment 1 Ján Tomko 2016-10-21 14:00:06 UTC
Proposed upstream patch:
https://www.redhat.com/archives/libvir-list/2016-October/msg00972.html

Comment 2 Pei Zhang 2016-10-25 05:51:14 UTC
I can reproduce it.

Version:
libvirt-2.0.0-10.el7.x86_64
qemu-kvm-rhev-2.6.0-28.el7.x86_64

Steps : 
1. start a guest 
# virsh list 
 Id    Name                           State
----------------------------------------------------
 19    vm1                            running

2. restart libvirtd 
# systemctl restart libvirtd

3. prepare an usb virtual disk, hotplug to guest 
# cat usb_file_disk1.xml 
<disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/USB/usb1.img'/>
      <target dev='sdc' bus='usb'/>
    </disk>

# virsh attach-device vm1  usb_file_disk1.xml 
Device attached successfully

4. dumpxml to check 
# virsh dumpxml vm1 | grep disk -A 9 
......
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/USB/usb1.img'>
        <seclabel model='selinux' labelskip='yes'/>
      </source>
      <backingStore/>
      <target dev='sdc' bus='usb'/>
      <alias name='usb-disk2'/>
    </disk>
......

5. prepare a usb host device 

# cat usb_hostdev.xml 
<hostdev mode='subsystem' type='usb' managed='no'>
<source startupPolicy='optional'>
<address bus='2' device='4'/>
</source>
</hostdev>

# virsh attach-device vm1 usb_hostdev.xml 
Device attached successfully

# virsh dumpxml vm1 | grep hostdev -A 5
......
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <address bus='2' device='4'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>
......
After libvirtd restart, hotplugged USB devices cannot generate addresses.

Comment 3 Ján Tomko 2016-10-27 11:46:37 UTC
Fixed upstream by:
commit dc67d00cd22844dbe4c57134e3ab21abd6742235
Author:     Ján Tomko <jtomko>
CommitDate: 2016-10-27 13:38:56 +0200

    Recreate the USB address cache at reconnect
    
    When starting a new domain, we allocate the USB addresses and keep
    an address cache in the domain object's private data.
    
    However this data is lost on libvirtd restart.
    
    Also generate the address cache if all the addresses have been
    specified, so that devices hotplugged after libvirtd restart
    also get theirs assigned.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1387666

git describe: v2.3.0-220-gdc67d00

Comment 5 Pei Zhang 2017-04-26 02:16:12 UTC
Verify version :

libvirt-3.2.0-3.el7.x86_64
qemu-kvm-rhev-2.9.0-1.el7.x86_64

Steps :
1. Prepare a guest with USB controller.
# virsh list 
 Id    Name                           State
----------------------------------------------------
 5     r74                            running

2. Restart libvirtd service
# systemctl restart libvirtd

3.Prepare an usb disk with address, hotplug this disk

# cat vusb.xml 
  <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/sdb9'/>
      <target dev='sde' bus='usb'/>
    </disk>


# virsh attach-device r74 vusb.xml 
Device attached successfully

4. Check guest xml, the hotplugged USB device can generated address

# virsh dumpxml r74|grep disk -A 9
 <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/sdb9'/>
      <backingStore/>
      <target dev='sde' bus='usb'/>
      <alias name='usb-disk4'/>
      <address type='usb' bus='0' port='3'/>
    </disk>

5. Prepare a USB hostdev device with address, hotplug it to guest 

# cat hostdev.xml 
<hostdev mode='subsystem' type='usb' managed='no'>
<source startupPolicy='optional'>
<address bus='2' device='6'/>
</source>
</hostdev>

# virsh attach-device r74 hostdev.xml 
Device attached successfully

6.check guest xml, hotplugged USB hostdev device can generated address

# virsh dumpxml r74 | grep hostdev -A 6
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <address bus='2' device='6'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='4'/>
    </hostdev>

As above, after libvirtd restart, hotplugged USB devices can generate addresses.

Comment 8 Pei Zhang 2017-05-03 03:17:45 UTC
Thanks for your info.
Filed Bug 1447505 to track comment 6.
As steps in comment 5, move this bug to verified.

Comment 9 errata-xmlrpc 2017-08-01 17:19:14 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-2017:1846

Comment 10 errata-xmlrpc 2017-08-01 23:59:00 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-2017:1846