Bug 1049529 - virsh mishandles inactive configuration on device hot(un)plug commands
virsh mishandles inactive configuration on device hot(un)plug commands
Status: CLOSED CURRENTRELEASE
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.0
Unspecified Unspecified
medium Severity medium
: rc
: ---
Assigned To: Peter Krempa
Virtualization Bugs
:
Depends On: 921398
Blocks: 921407 1125194
  Show dependency treegraph
 
Reported: 2014-01-07 12:08 EST by Peter Krempa
Modified: 2014-07-31 05:39 EDT (History)
12 users (show)

See Also:
Fixed In Version: libvirt-1.1.1-18.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 921398
: 1125194 (view as bug list)
Environment:
Last Closed: 2014-06-13 06:33:15 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Peter Krempa 2014-01-07 12:08:50 EST
Description of problem:
virsh update-device with option "--config" should not be affect before next boot

Version-Release number of selected component (if applicable):
libvirt-1.1.1-16.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
Problem 1:
Attach/detach with --config
steps:
1. attach-disk with --config when domain is running
# virsh list
 Id    Name                           State
----------------------------------------------------
 15    virt-tests-vm1                 running

# virsh attach-disk virt-tests-vm1 /tmp/aa.img vdd --config
Disk attached successfully

2. detach with --config
# virsh detach-disk --domain virt-tests-vm1 --target vdd --config
error: No found disk whose source path or target is vdd 

The attach/detach with --config here is little confusing, since the semantic of --config is updated in this bug. With running domain, if the user want use this work, need do it as follow ways:

1. attach-disk with --config --live, then detach will success
# virsh attach-disk virt-tests-vm1 /tmp/test.img vdd --config --live
Disk attached successfully

# virsh detach-disk virt-tests-vm1 vdd --config
Disk detached successfully

Problem 2:
--current when domain shut off
steps:
# virsh destroy virt-tests-vm1
Domain virt-tests-vm1 destroyed

# virsh attach-disk virt-tests-vm1 /tmp/test.img vdd
error: Failed to attach disk
error: Requested operation is not valid: cannot do live update a device on inactive domain

# virsh attach-disk virt-tests-vm1 /tmp/test.img vdd --current
error: Failed to attach disk
error: Requested operation is not valid: cannot do live update a device on inactive domain

--current should be equal to --config when domain is shut off, and by default is --current. It should not fail here and no need to specify --config when domain is shut off.

Reported by Wayne Sun.
Comment 1 Peter Krempa 2014-01-08 04:04:17 EST
Fixed upstream:

commit f9d06ebcef9faffc085bab68968b8bb78f49f2d0
Author: Peter Krempa <pkrempa@redhat.com>
Date:   Tue Jan 7 17:58:47 2014 +0100

    virsh: Use inactive definition when removing disk from config
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1049529
    
    The 'detach-disk' command in virsh used the active XML definition of a
    domain even when attempting to remove a disk from the config only. If
    the disk was only in the inactive definition the operation failed. Fix
    this by using the inactive XML in case that only the config is affected.

commit 0bb64df1fcbf8248d8b71c44c8c882ae7b17d846
Author: Peter Krempa <pkrempa@redhat.com>
Date:   Tue Jan 7 16:44:02 2014 +0100

    virsh: Don't use legacy API if --current is used on device hot(un)plug
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1049529
    
    The legacy virDomainAttachDevice and virDomainDetachDevice operate only
    on active domains. When a user specified --current flag with an inactive
    domain the old API was used and reported an error. Fix it by calling the
    new API if --current is specified explicitly.
Comment 4 Wayne Sun 2014-01-09 02:09:42 EST
pkgs
libvirt-1.1.1-18.el7.x86_64
qemu-kvm-rhev-1.5.3-30.el7.x86_64
kernel-3.10.0-64.el7.x86_64

steps:
scenario 1:
attach/detach with --config when domain is running
1. attach with --config when domain is running
# qemu-img create /tmp/aa.img 10M
Formatting '/tmp/aa.img', fmt=raw size=10485760 

# virsh list
 Id    Name                           State
----------------------------------------------------
 2     kvm-rhel6.5-x86_64-qcow2-virtio running

# virsh attach-disk kvm-rhel6.5-x86_64-qcow2-virtio /tmp/aa.img vdd --config
Disk attached successfully

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio --inactive
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img
vdd        /tmp/aa.img

2. detach with --config when domain is running
# virsh detach-disk kvm-rhel6.5-x86_64-qcow2-virtio vdd --config
Disk detached successfully

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio --inactive
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img

--config works with running domain now.

scenario 2:
attach/detach with --current
# virsh attach-disk kvm-rhel6.5-x86_64-qcow2-virtio /tmp/aa.img vdd
error: Failed to attach disk
error: Requested operation is not valid: cannot do live update a device on inactive domain

seems here by default is --live if not given flags, maybe by default should be --current here which will work like follow as --current specific given (@pkrempa, is it worth a fix?)

# virsh attach-disk kvm-rhel6.5-x86_64-qcow2-virtio /tmp/aa.img vdd --current
Disk attached successfully

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img
vdd        /tmp/aa.img

# virsh detach-disk kvm-rhel6.5-x86_64-qcow2-virtio vdd
error: Failed to detach disk
error: Requested operation is not valid: cannot do live update a device on inactive domain

same here as default flag is not --current

# virsh detach-disk kvm-rhel6.5-x86_64-qcow2-virtio vdd --current
Disk detached successfully

# virsh domblklist kvm-rhel6.5-x86_64-qcow2-virtio
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/kvm-rhel6.5-x86_64-qcow2.img


Hi Peter,

Could you help check the default flag problem raised in scenario 2, if it not worth a fix, then I'll mark this as verified, thx!
Comment 5 Peter Krempa 2014-01-09 03:19:54 EST
Hi Wayne,


(In reply to Wayne Sun from comment #4)

...

> scenario 2:
> attach/detach with --current
> # virsh attach-disk kvm-rhel6.5-x86_64-qcow2-virtio /tmp/aa.img vdd
> error: Failed to attach disk
> error: Requested operation is not valid: cannot do live update a device on
> inactive domain
> 
> seems here by default is --live if not given flags, maybe by default should
> be --current here which will work like follow as --current specific given
> (@pkrempa, is it worth a fix?)

This is correct according to the man page for the hotplug APIs:

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. When no flag is specified legacy API is used whose behavior depends on the hypervisor driver.


> 
> Hi Peter,
> 
> Could you help check the default flag problem raised in scenario 2, if it
> not worth a fix, then I'll mark this as verified, thx!
Comment 6 Wayne Sun 2014-01-09 03:52:48 EST
(In reply to Peter Krempa from comment #5)
> Hi Wayne,
> 
> 
> (In reply to Wayne Sun from comment #4)
> 
> ...
> 
> > 
> > seems here by default is --live if not given flags, maybe by default should
> > be --current here which will work like follow as --current specific given
> > (@pkrempa, is it worth a fix?)
> 
> This is correct according to the man page for the hotplug APIs:
> 
> 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. When no flag is specified legacy API is
> used whose behavior depends on the hypervisor driver.
> 
> 

Got it, thx for explain this.

Forget to add the --print-xml test in last comment, so added it here:
1. non-exist domain
# virsh attach-disk fake_non_exist /tmp/aa.img vdd --print-xml
<disk type='file'>
  <source file='/tmp/aa.img'/>
  <target dev='vdd'/>
</disk>

2. with exist domain
# virsh attach-disk kvm-rhel6.5-x86_64-qcow2-virtio /tmp/aa.img vdd --print-xml
<disk type='file'>
  <source file='/tmp/aa.img'/>
  <target dev='vdd'/>
</disk>

it's working as expected, so mark verified.
Comment 7 Ludek Smid 2014-06-13 06:33:15 EDT
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

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