Bug 1598087

Summary: Improve documentation description for 'virsh detach-device-alias' cmd
Product: Red Hat Enterprise Linux 7 Reporter: jiyan <jiyan>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: jiyan <jiyan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.6CC: dyuan, jdenemar, jiyan, lhuang, lmen, mprivozn, xuzhang, yalzhang
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-4.5.0-2.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-30 09:57:31 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 jiyan 2018-07-04 10:11:46 UTC
Description of problem:
'virsh detach-device-alias' should report failure when detaching memory failed

Version-Release number of selected component (if applicable):
kernel-3.10.0-918.el7.x86_64
qemu-kvm-rhev-2.12.0-6.el7.x86_64
libvirt-4.5.0-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Prepare a running VM with the following configuration and the XML file
# virsh domstate b1
running

# virsh dumpxml b1
  <maxMemory slots='16' unit='KiB'>2124800</maxMemory>
  <memory unit='KiB'>1155072</memory>
  <currentMemory unit='KiB'>917504</currentMemory>
  <cpu mode='custom' match='exact' check='full'>
    <numa>
      <cell id='0' cpus='0-7' memory='512000' unit='KiB'/>
      <cell id='1' cpus='8-15' memory='512000' unit='KiB'/>
    </numa>
  </cpu>
  <device>
    <memory model='dimm'>
      <source>
        <nodemask>0</nodemask>
        <pagesize unit='KiB'>2048</pagesize>
      </source>
      <target>
        <size unit='KiB'>131072</size>
        <node>1</node>
      </target>
      <alias name='ua-9874229d-d867-4932-ad28-279e9a777f42'/>
      <address type='dimm' slot='1' base='0x100000000'/>
    </memory>
  </device>

# cat memory.xml 
    <memory model='dimm'>
      <source>
        <nodemask>0</nodemask>
        <pagesize unit='KiB'>2048</pagesize>
      </source>
      <target>
        <size unit='KiB'>131072</size>
        <node>1</node>
      </target>
      <alias name='ua-9874229d-d867-4932-ad28-279e9a777f42'/>
      <address type='dimm' slot='1' base='0x100000000'/>
    </memory>

2. Detach memory device through 'virsh detach-device'
# virsh detach-device b1 memory.xml 
error: Failed to detach device from memory.xml
error: operation failed: unplug of device was rejected by the guest

# virsh dumpxml b1 |grep "<memory m" -A11
    <memory model='dimm'>
      <source>
        <nodemask>0</nodemask>
        <pagesize unit='KiB'>2048</pagesize>
      </source>
      <target>
        <size unit='KiB'>131072</size>
        <node>1</node>
      </target>
      <alias name='ua-9874229d-d867-4932-ad28-279e9a777f42'/>
      <address type='dimm' slot='1' base='0x100000000'/>
    </memory>

3. Detach memory device through 'virsh detach-device-alias'
# virsh detach-device-alias b1 ua-9874229d-d867-4932-ad28-279e9a777f42
Device detach request sent successfully

# virsh dumpxml b1 |grep "<memory m" -A11
    <memory model='dimm'>
      <source>
        <nodemask>0</nodemask>
        <pagesize unit='KiB'>2048</pagesize>
      </source>
      <target>
        <size unit='KiB'>131072</size>
        <node>1</node>
      </target>
      <alias name='ua-9874229d-d867-4932-ad28-279e9a777f42'/>
      <address type='dimm' slot='1' base='0x100000000'/>
    </memory>

Actual results:
As step-3 shows

Expected results:
As step-2 shows

Additional info:
Bug 1320447 - [RFE] Report memory hotunplug failure​

Comment 2 Michal Privoznik 2018-07-04 10:19:21 UTC
I don't think this is a bug. The documentation states:

 * In contrast to virDomainDetachDeviceFlags() this API is
 * asynchronous - it returns immediately after sending the detach
 * request to the hypervisor. It's caller's responsibility to
 * wait for VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event to signal
 * actual device removal.

Comment 3 Jiri Denemark 2018-07-04 10:29:17 UTC
Right, the caller should get VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED event
in this case. I think we should improve the documentation to mention this
event too.

Comment 4 Michal Privoznik 2018-07-04 11:55:19 UTC
Okay. Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2018-July/msg00271.html

Comment 6 jiyan 2018-07-05 01:32:28 UTC
Hi Michal, got it.
And there is another doc problem. Could you please modify it? 

# man virsh
       detach-device-alias domain alias [[[--live] [--config] | [--current]] | [--persistent]]
           Detach a device with given alias from the domain.

           If --live is specified, affect a running domain.  If --config is specified, affect the next startup of a persistent domain.  If
           --current is specified, affect the current domain state.  Both --live and --config flags may be given, but --current is exclusive.

# virsh detach-device-alias b1 ua-9874229d-d867-4932-ad28-279e9a777f37 --persistent
error: command 'detach-device-alias' doesn't support option --persistent

Comment 9 jiyan 2018-07-10 01:31:03 UTC
Verified in libvirt-4.5.0-2.el7.x86_64.
The two problems have already been fixed, move this bug to be verified.

Comment 11 errata-xmlrpc 2018-10-30 09:57:31 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/RHSA-2018:3113