Bug 1175668

Summary: Attach a usb disk to guest failed.
Product: Red Hat Enterprise Linux 7 Reporter: lcheng
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: dyuan, honzhang, jdenemar, ovasik, pzhang, rbalakri, xuzhang
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.2.8-12.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-05 07:48:29 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 lcheng 2014-12-18 10:23:30 UTC
Description of problem:
Attach a usb disk to guest failed.


Version-Release number of selected component (if applicable):
qemu-kvm-rhev-2.1.2-17.el7.x86_64
libvirt-1.2.8-10.el7.x86_64


How reproducible:
100%

Steps to Reproduce:
1. Add the following xml to guest xml. And then start guest.
    <disk type='block' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source dev='/dev/sdc'/>
      <target dev='sdg' bus='usb'/>
      <alias name='usb-disk6'/>
    </disk>

[root@localhost ~]# virsh start r7
Domain r7 started

[root@localhost ~]# virsh dumpxml r7
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/r7.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source dev='/dev/sdc'/>
      <backingStore/>
      <target dev='sdg' bus='usb'/>
      <alias name='usb-disk6'/>
    </disk>

2. Attach the disk to guest.

[root@localhost ~]# cat disk.xml
<disk type='block' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source dev='/dev/sdc'/>
      <target dev='sdh' bus='usb'/>
      <alias name='virtio-disk0'/>
</disk>

[root@localhost ~]# virsh attach-device r7 disk.xml
Device attached successfully

[root@localhost ~]# virsh dumpxml r7 | grep -A10 disk
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/r7.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source dev='/dev/sdc'/>
      <backingStore/>
      <target dev='sdg' bus='usb'/>
      <alias name='usb-disk6'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source dev='/dev/sdc'/>
      <backingStore/>
      <target dev='sdh' bus='usb'/>
      <alias name='usb-disk7'/>
    </disk>

3. Destroy guest and remove the disk from guest xml.
[root@localhost ~]# virsh destroy r7
Domain r7 destroyed

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

[root@localhost ~]# virsh start r7
Domain r7 started

[root@localhost ~]# virsh dumpxml r7 | grep -A10 disk
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/r7.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
...

4. Attach the disk to guest again.
[root@localhost ~]# virsh attach-device r7 disk.xml
error: Failed to attach device from disk.xml
error: internal error: unable to execute QEMU command '__com.redhat_drive_add': Device 'drive-usb-disk7' could not be initialized


Actual results:
As steps.

Expected results:
The disk should be attached successfully.

Additional info:

Comment 2 Jiri Denemark 2014-12-18 11:43:02 UTC
Actually, this turns out to be a regression since 7.0 caused by Peter's refactoring.

Comment 4 Ján Tomko 2014-12-18 12:12:28 UTC
Upstream patch:
https://www.redhat.com/archives/libvir-list/2014-December/msg00934.html

Comment 5 Ján Tomko 2014-12-18 12:22:15 UTC
Now fixed upstream:
commit 1cddf0001f5f1af10791181229148f36fd6d94c5
Author:     Ján Tomko <jtomko>
CommitDate: 2014-12-18 12:53:56 +0100

    Fix hotplugging of block device-backed usb disks
    
    Commit ca91ba7 moved qemuSetupDiskCgroup into the qemuDomainPrepareDisk
    helper, but failed to call it for usb disks.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1175668`

git describe: v1.2.11-58-g1cddf00

Comment 8 Pei Zhang 2015-01-15 02:01:08 UTC
verify version:
kernel-3.10.0-222.el7.x86_64
qemu-kvm-rhev-2.1.2-18.el7.x86_64
libvirt-1.2.8-12.el7.x86_64

verify steps:
1.prepare a block disk like following

# cat block-disk.xml 
<disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/sdb'/>
      <target dev='sdg' bus='usb'/>
    </disk>

2.start a guest  which has no block-backed usb disks . 

# virsh dumpxml r7 | grep disk -A 8

  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vm1.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

3.attach the block disk , attach successfully 

# virsh attach-device r7 block-disk.xml 
Device attached successfully

4.chech domaim XML  
# virsh dumpxml r7 | grep disk -A 8
  
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vm1.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/sdb'/>
      <backingStore/>
      <target dev='sdg' bus='usb'/>
      <alias name='usb-disk6'/>
    </disk>

4.detach the hotplug disk
# virsh detach-device r7 block-disk.xml 
Device detached successfully

check domain XML ,detach successfully
# virsh dumpxml r7 |grep disk -A 9 |grep sdg

5.attach block device usb disk again 

# virsh attach-device r7 block-disk.xml 
Device attached successfully

# virsh dumpxml r7 |grep disk -A 9 | grep sdg
 
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/sdb'/>
      <backingStore/>
      <target dev='sdg' bus='usb'/>
      <alias name='usb-disk6'/>
    </disk>
block-backed usb device can be hotplug , move to verified.

Comment 10 errata-xmlrpc 2015-03-05 07:48:29 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/RHSA-2015-0323.html