Bug 1133443

Summary: Libvirt should report failure when detach hostdev unsuccessfully.
Product: Red Hat Enterprise Linux 6 Reporter: Hu Jianwei <jiahu>
Component: libvirtAssignee: Jiri Denemark <jdenemar>
Status: CLOSED WONTFIX QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.6CC: dyuan, honzhang, jdenemar, mzhan, pzhang, rbalakri, virt-bugs, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 993631 Environment:
Last Closed: 2015-01-19 15:55: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:
Bug Depends On: 993631    
Bug Blocks:    

Description Hu Jianwei 2014-08-25 07:26:17 UTC
Version:
libvirt-0.10.2-43.el6.x86_64
qemu-kvm-rhev-0.12.1.2-2.428.el6.x86_64

Steps:
[root@rhel6 ~]# virsh start r7
Domain r7 started

In another terminal,execute below command immediately:
[root@rhel6 ~]# virsh detach-device r7 hostdev.xml
Device detached successfully

[root@rhel6 ~]# virsh dumpxml r7 | grep -A10 hostdev
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
      </source>
      <alias name='hostdev0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
    </hostdev>
...

[root@rhel6 ~]# ll /proc/`pidof qemu-kvm`/fd | grep "/sys/devices/"
lrwx------. 1 qemu qemu 64 Aug 19 11:39 23 -> /sys/devices/pci0000:00/0000:00:1e.0/0000:02:00.0/resource0
lrwx------. 1 qemu qemu 64 Aug 19 11:39 24 -> /sys/devices/pci0000:00/0000:00:1e.0/0000:02:00.0/config
lrwx------. 1 qemu qemu 64 Aug 19 11:39 25 -> /sys/devices/pci0000:00/0000:00:1e.0/0000:02:00.0/resource1
lrwx------. 1 qemu qemu 64 Aug 19 11:39 26 -> /sys/devices/pci0000:00/0000:00:1e.0/0000:02:00.0/resource2
[root@rhel6 ~]# lspci -s 02:00.0 -vv
02:00.0 Ethernet controller: Intel Corporation 82541PI Gigabit Ethernet Controller (rev 05)
	Subsystem: Intel Corporation PRO/1000 GT Desktop Adapter
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz+ UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 32 (63750ns min), Cache Line Size: 64 bytes
	Interrupt: pin A routed to IRQ 20
	Region 0: Memory at f7c40000 (32-bit, non-prefetchable) [size=128K]
	Region 1: Memory at f7c20000 (32-bit, non-prefetchable) [size=128K]
	Region 2: I/O ports at d000 [size=64]
	Expansion ROM at cf300000 [disabled] [size=128K]
	Capabilities: [dc] Power Management version 2
		Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
		Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=1 PME-
	Capabilities: [e4] PCI-X non-bridge device
		Command: DPERE- ERO+ RBC=512 OST=1
		Status: Dev=00:00.0 64bit- 133MHz- SCD- USC- DC=simple DMMRBC=2048 DMOST=1 DMCRS=8 RSCEM- 266MHz- 533MHz-
	Kernel driver in use: pci-stub
	Kernel modules: e1000

+++ This bug was initially created as a clone of Bug #993631 +++

Description of problem:
Libvirt should report failure when detach hostdev unsuccessfully.
 
Version-Release number of selected component (if applicable):
libvirt-1.1.1-2.el7.x86_64
qemu-kvm-1.5.2-1.el7.x86_64
kernel-3.10.0-3.el7.x86_64

How reproducible:
100%

Steps:
1. Define a guest with the following hostdev device
<hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </source>
    </hostdev>

2. Execute 2.1 and 2.2 at the same time.
2.1 Start the guest.
[root@SRIOV2 ~]# virsh start r7_g
Domain r7_g started
[root@SRIOV2 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 7     r7_g                           running

2.2 In another terminal,execute below command immediately:
[root@SRIOV2 ~]# virsh detach-device r7_g hostdev.xml
Device detached successfully                           <======= this is issue.

3. Dumpxml domain xml.
[root@SRIOV2 ~]# virsh dumpxml r7_g | grep -A10 hostdev
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </hostdev>

[root@SRIOV2 ~]# virsh dumpxml r7_g --inactive| grep -A10 hostdev
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </hostdev>

4. In guest, to check the nic status, it's in the domain.
[root@test005 ~]# lspci| grep Eth
00:03.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
[root@test005 ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr B4:B5:2F:AF:A1:00  
          inet addr:10.66.71.177  Bcast:10.66.71.255  Mask:255.255.254.0
          inet6 addr: fe80::b6b5:2fff:feaf:a100/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1932 (1.8 KiB)  TX bytes:1588 (1.5 KiB)
          Interrupt:11 Memory:fc000000-fc020000

[root@test005 ~]# ping 10.66.7.130
PING 10.66.7.130 (10.66.7.130) 56(84) bytes of data.
64 bytes from 10.66.7.130: icmp_seq=1 ttl=62 time=0.324 ms
64 bytes from 10.66.7.130: icmp_seq=2 ttl=62 time=0.282 ms
64 bytes from 10.66.7.130: icmp_seq=3 ttl=62 time=0.402 ms

--- 10.66.7.130 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2391ms
rtt min/avg/max/mdev = 0.282/0.336/0.402/0.049 ms
[root@test005 ~]# 

Actual results:
As step 2.2 shown.

Expected results:
Libvirt should report an error if detach device fail.

--- Additional comment from RHEL Product and Program Management on 2013-08-06 06:38:33 EDT ---

Since this bug report was entered in bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

--- Additional comment from Ludek Smid on 2014-04-23 12:13:59 EDT ---

Since the release flag was set to ? after the pm_ack flag was set to + (was likely set for the previous release), the pm_ack flag has been reset to ? by the bugbot (pm-rhel). This action ensures the proper review by Product Management.

--- Additional comment from Jiri Denemark on 2014-08-07 10:37:45 EDT ---

Moving out of 7.1 for capacity reasons.

Comment 3 Pei Zhang 2014-09-01 10:43:28 UTC
version:
os build: RHEL-6.6-20140812.1
libvirt: libvirt-0.10.2-43.el6
qemu-kvm: qemy-kvm-rhev-0.12.1.2-2.436.el6.x86_64
kernel: kernel-2.6.32-496.el6

description: use detach-disk to detach a disk from a domain which has no system 
the output result is successful , actually it's not.
 
steps:
1>
[root@pzhang ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 18    rhel6                          running
[root@pzhang ~]# virsh dumpxml rhel6 | grep disk -A5
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none' error_policy='stop'/>
      <source file='/var/lib/libvirt/images/rhel6.img'/>
      <target dev='hdb' bus='ide'/>
      <alias name='ide0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qed' cache='none'/>
      <source file='/var/lib/libvirt/images/qed1.img'/>
      <target dev='hda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
2>
[root@pzhang ~]# virsh detach-disk rhel6 hda
Disk detached successfully

[root@pzhang ~]# virsh dumpxml rhel6 | grep disk -A5
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none' error_policy='stop'/>
      <source file='/var/lib/libvirt/images/rhel6.img'/>
      <target dev='hdb' bus='ide'/>
      <alias name='ide0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qed' cache='none'/>
      <source file='/var/lib/libvirt/images/qed1.img'/>
      <target dev='hda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>

3>
[root@pzhang ~]# virsh destroy rhel6
Domain rhel6 destroyed

[root@pzhang ~]# virsh start rhel6
Domain rhel6 started

[root@pzhang ~]# virsh dumpxml rhel6 | grep disk -A5
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none' error_policy='stop'/>
      <source file='/var/lib/libvirt/images/rhel6.img'/>
      <target dev='hdb' bus='ide'/>
      <alias name='ide0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qed' cache='none'/>
      <source file='/var/lib/libvirt/images/qed1.img'/>
      <target dev='hda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>

Expected results:
Libvirt should report an error if detach device fail.

Comment 4 Jiri Denemark 2015-01-19 15:55:14 UTC
Unfortunately, this is non-trivial to solve in a backward compatible way within our current API. And likely too much for RHEL-6. I'll try to address this upstream for bug 993631.