Bug 751303

Summary: Persistent option of virsh detach-disk/interface/device does not work well
Product: Red Hat Enterprise Linux 6 Reporter: tingting zheng <tzheng>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 6.2CC: acathrow, ajia, jyang, mzhan, rwu, weizhan, yupzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-11-06 09:34:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description tingting zheng 2011-11-04 09:25:46 UTC
Description of problem:
Run virsh detach-disk/interface/device  with --persistent option,it does not work well

Version-Release number of selected component (if applicable):
libvirt-0.9.4-21.el6.x86_64
qemu-kvm-0.12.1.2-2.207.el6
kernel-2.6.32-214.el6 

How reproducible:
always

Steps to Reproduce:
1.Start a kvm guest
#virsh start test

2.Attach disk to the guest.
# virsh attach-disk test /var/lib/libvirt/images/foo.img vdb
Disk attached successfully

3.Check the xml file of the guest.
# virsh dumpxml test
<domain type='kvm' id='31'>
 <name>test</name>

   <disk type='block' device='disk'>
     <driver name='qemu' type='raw'/>
     <source dev='/var/lib/libvirt/images/foo.img'/>
     <target dev='vdb' bus='virtio'/>
     <alias name='virtio-disk1'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
   </disk>


4.Detach disk with --persistent option
# virsh detach-disk test vdb --persistent
error: Failed to detach disk
error: invalid argument: no target device vdb

If I run detach-disk without --persistent option it can be detached successfully.
# virsh detach-disk test vdb 
Disk detached successfully


If I run attach-disk with --persistent option,then use detach-disk with --persistent option,it will detach successfully.
# virsh attach-disk test /var/lib/libvirt/images/foo.img vdb --persistent
Disk attached successfully

# virsh detach-disk test vdb --persistent
Disk detached successfully

Actual results:
As steps 4 describes.

Expected results:
Disk detached successfully with --persistent option.
If libvirt doesn't allow user to use detach-disk/interface/device with '--persistent' option when users haven't used attach-disk/interface/device 
with '--persistent',It is better to be documented.

Additional info:
I tried attach-interface/device,it has the same error and give wrong error message.
# virsh attach-interface --domain test --type network --source default --target vnet0 --mac 52:54:00:c8:f1:42  --model e1000 
Interface attached successfully

# virsh dumpxml test
<domain type='kvm' id='31'>
 <name>test</name>

   <interface type='network'>
     <mac address='52:54:00:c8:f1:42'/>
     <source network='default'/>
     <target dev='vnet1'/>
     <model type='e1000'/>
     <alias name='net1'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
   </interface>


# virsh detach-interface test network --persistent
error: Failed to detach interface
error: invalid argument: no nic of mac 52:54:00:C8:F1:42

# virsh detach-interface test network 
Interface detached successfully

Comment 2 Osier Yang 2011-11-06 09:34:04 UTC
(In reply to comment #0)
> Description of problem:
> Run virsh detach-disk/interface/device  with --persistent option,it does not
> work well
> 
> Version-Release number of selected component (if applicable):
> libvirt-0.9.4-21.el6.x86_64
> qemu-kvm-0.12.1.2-2.207.el6
> kernel-2.6.32-214.el6 
> 
> How reproducible:
> always
> 
> Steps to Reproduce:
> 1.Start a kvm guest
> #virsh start test
> 
> 2.Attach disk to the guest.
> # virsh attach-disk test /var/lib/libvirt/images/foo.img vdb
> Disk attached successfully
> 
> 3.Check the xml file of the guest.
> # virsh dumpxml test
> <domain type='kvm' id='31'>
>  <name>test</name>
> 
>    <disk type='block' device='disk'>
>      <driver name='qemu' type='raw'/>
>      <source dev='/var/lib/libvirt/images/foo.img'/>
>      <target dev='vdb' bus='virtio'/>
>      <alias name='virtio-disk1'/>
>      <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
> function='0x0'/>
>    </disk>
> 
> 
> 4.Detach disk with --persistent option
> # virsh detach-disk test vdb --persistent
> error: Failed to detach disk
> error: invalid argument: no target device vdb


This is expected, as the disk wasn't attached persistently (to the persistent domain config, e.g. /etc/libvirt/qemu/domain.xml).

> 
> If I run detach-disk without --persistent option it can be detached
> successfully.
> # virsh detach-disk test vdb 
> Disk detached successfully
> 
> 
> If I run attach-disk with --persistent option,then use detach-disk with
> --persistent option,it will detach successfully.
> # virsh attach-disk test /var/lib/libvirt/images/foo.img vdb --persistent
> Disk attached successfully
> 
> # virsh detach-disk test vdb --persistent
> Disk detached successfully
> 
> Actual results:
> As steps 4 describes.
> 
> Expected results:
> Disk detached successfully with --persistent option.
> If libvirt doesn't allow user to use detach-disk/interface/device with
> '--persistent' option when users haven't used attach-disk/interface/device 
> with '--persistent',It is better to be documented.

The error tells you all the truth, "no target device vdb", means can't find
the disk you are detaching in the persistent domain conf.


Close this as NOTABUG.

Comment 3 tingting zheng 2011-11-07 02:36:37 UTC
> The error tells you all the truth, "no target device vdb", means can't find
> the disk you are detaching in the persistent domain conf.
> 
> 
> Close this as NOTABUG.


I think it is better to be documented that if user want to use detach-disk/interface/device with '--persistent' option,they should first use attach-disk/interface/device with '--persistent' option.

Comment 4 Alex Jia 2011-11-07 03:23:26 UTC
Hi Osier,
If you look virsh man page for {attach|detach}-{disk|interface|device} command again, you will find there are some contents are missing:

1. missing --persistent option:
detach-disk, {attach|detach}-device, detach-interface

Notes, virsh man page should synchronize these with virsh help document, and should give more details.

2. without any place to introduce relationship between attach-* command with --persistent option and detach-* command with --persistent option:

Notes, it will be better if libvirt can explain this in document.


Thanks,
Alex

Comment 5 Osier Yang 2011-11-07 03:39:15 UTC
(In reply to comment #3)
> > The error tells you all the truth, "no target device vdb", means can't find
> > the disk you are detaching in the persistent domain conf.
> > 
> > 
> > Close this as NOTABUG.
> 
> 
> I think it is better to be documented that if user want to use
> detach-disk/interface/device with '--persistent' option,they should first use
> attach-disk/interface/device with '--persistent' option.

There is no dependancy here, you can detach a device persistently successfully if the device is in the persistent domain conf, without an persistent attaching previously. Also if the device is not in the config, the error tells you all.

Comment 6 Osier Yang 2011-11-07 03:47:21 UTC
(In reply to comment #4)
> Hi Osier,
> If you look virsh man page for {attach|detach}-{disk|interface|device} command
> again, you will find there are some contents are missing:
> 
> 1. missing --persistent option:
> detach-disk, {attach|detach}-device, detach-interface
> 
> Notes, virsh man page should synchronize these with virsh help document, and
> should give more details.

That's a separate problem. File another bug please.

> 
> 2. without any place to introduce relationship between attach-* command with
> --persistent option and detach-* command with --persistent option:
> 
> Notes, it will be better if libvirt can explain this in document.
> 

See comment 5, attaching without "--persistent" and detaching with "--persistent" following is just same with you detach a device which is not in the domain persist config. Documents like "detach with '--persistent' requires attaching with '--persistent'" is just wrong.

<snip>
4.Detach disk with --persistent option
# virsh detach-disk test vdb --persistent
error: Failed to detach disk
error: invalid argument: no target device vdb
</snip>

See the "vdb" in the command, and the error "no target vdb", clearly it's sensiable enough.