Bug 627143

Summary: can't successfully start guest with a hot-plugging disk after stopping
Product: Red Hat Enterprise Linux 6 Reporter: Alex Jia <ajia>
Component: libvirtAssignee: Osier Yang <jyang>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.0CC: ccui, dallan, dyuan, eblake, florin, jdenemar, llim, mfuruta, vbian, weizhan, xen-maint, yuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-0.8.7-1.el6 Doc Type: Bug Fix
Doc Text:
If the user did not specify a disk driver when hot-plugging a disk with "virsh attach-disk", virsh set "phy" as the driver value by default. Because this value is not supported everywhere, the disk did not persist over domain shutdown, and could prevent domain startup. This update corrects virsh behavior such that the driver value is not set if it is not provided by the user.
Story Points: ---
Clone Of:
: 638071 1000432 (view as bug list) Environment:
Last Closed: 2011-05-19 13:20:50 UTC Type: ---
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:    
Bug Blocks: 638071, 1000432    

Description Alex Jia 2010-08-25 08:03:32 UTC
Description of problem:
Hot-plug a disk to guest and then shut down the guest and start agian, libvirt raises the following error:
error: Failed to start domain demo
error: internal error unsupported driver name 'phy' for disk '/var/lib/libvirt/images/mytest.qcow2'

And libvirt automatically add type='raw' to 'qcow2' image in guest XML configuration.
 
Version-Release number of selected component (if applicable):
# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.0 Beta (Santiago)

# uname -r
2.6.32-63.el6.x86_64

# rpm -q libvirt
libvirt-0.8.1-27.el6.x86_64

# rpm -q qemu-kvm
qemu-kvm-0.12.1.2-2.112.el6.x86_64


How reproducible:
Always

Steps to Reproduce:
1. create a qcow2 image
2. start guest demo
3. attach disk image to guest
4. dump the guest to xml
5. shut down the guest
6. start the guest
  
Actual results:
# qemu-img create -f qcow2 /var/lib/libvirt/images/mytest.qcow2 10M
Formatting '/var/lib/libvirt/images/mytest.qcow2', fmt=qcow2 size=10485760 encryption=off cluster_size=0 

# qemu-img info /var/lib/libvirt/images/mytest.qcow2 
image: /var/lib/libvirt/images/mytest.qcow2
file format: qcow2
virtual size: 10M (10485760 bytes)
disk size: 140K
cluster_size: 65536

# virsh start demo
Domain demo started

# virsh attach-disk demo /var/lib/libvirt/images/mytest.qcow2 vdb
Disk attached successfully

# virsh dumpxml demo
......
    <disk type='block' device='disk'>
      <driver name='phy' type='raw'/>
      <source dev='/var/lib/libvirt/images/mytest.qcow2'/>
      <target dev='vdb' bus='virtio'/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
......

Note that, attach-disk hasn't provided image format argument such as img_fmt='qcow2', libvirt default format is raw, and automatically add type='raw' to a qcow2 format disk, Is it a expected result? 

Log in the guest and check the disk really exists

# virsh shutdown demo
Domain demo is being shutdown

# virsh start demo
error: Failed to start domain demo
error: internal error unsupported driver name 'phy' for disk '/var/lib/libvirt/images/mytest.qcow2'


Expected results:
fix it

Additional info:

Comment 2 Alex Jia 2010-08-25 08:34:55 UTC
Libvirt haven't check image real format instead of passing default raw format
to qemu-kvm, the following information is come from libvirtd.log:

......
16:27:37.471: debug : qemuMonitorAddDrive:1897 : mon=0x1ef3890
drive=file=/var/lib/libvirt/images/mytest.qcow2,if=none,id=drive-virtio-disk1,format=raw
......
16:27:37.471: debug : virJSONValueToString:1059 :
result={"execute":"__com.redhat_drive_add","arguments":{"file":"/var/lib/libvirt/images/mytest.qcow2","id":"drive-virtio-disk1","format":"raw"}}
16:27:37.471: debug : qemuMonitorJSONCommandWithFd:217 : Send command
'{"execute":"__com.redhat_drive_add","arguments":{"file":"/var/lib/libvirt/images/mytest.qcow2","id":"drive-virtio-disk1","format":"raw"}}'

Comment 3 dyuan 2010-08-27 02:14:18 UTC
The error report: unsupported driver name 'phy', maybe it's the focal point.

set driver name='qemu', keep type=raw
# virsh edit demo
...
<driver name='qemu' type='raw'/>
...

# virsh start demo
Domain demo started

But when I only change 'raw' to 'qcow2', guest still start fail.

# virsh edit demo
...
<driver name='phy' type='qcow2'/>
...

# virsh start demo
error: Failed to start domain demo
error: internal error unsupported driver name 'phy' for disk '/var/lib/libvirt/images/foo.img'

Comment 4 dyuan 2010-08-27 02:45:24 UTC
(In reply to comment #2)
> Libvirt haven't check image real format instead of passing default raw format
> to qemu-kvm, the following information is come from libvirtd.log:
> 
> ......
> 16:27:37.471: debug : qemuMonitorAddDrive:1897 : mon=0x1ef3890
> drive=file=/var/lib/libvirt/images/mytest.qcow2,if=none,id=drive-virtio-disk1,format=raw
> ......
> 16:27:37.471: debug : virJSONValueToString:1059 :
> result={"execute":"__com.redhat_drive_add","arguments":{"file":"/var/lib/libvirt/images/mytest.qcow2","id":"drive-virtio-disk1","format":"raw"}}
> 16:27:37.471: debug : qemuMonitorJSONCommandWithFd:217 : Send command
> '{"execute":"__com.redhat_drive_add","arguments":{"file":"/var/lib/libvirt/images/mytest.qcow2","id":"drive-virtio-disk1","format":"raw"}}'

we can use 'subdriver=qcow2' in command attach-device, but it's not the workaround of the bug.

# virsh attach-disk demo /var/lib/libvirt/images/foo.img vdb --subdriver qcow2
Disk attached successfully

# virsh dumpxml demo
...
<disk type='block' device='disk'>
      <driver name='phy' type='qcow2'/>
      <source dev='/var/lib/libvirt/images/foo.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>

Comment 5 dyuan 2010-08-27 03:04:01 UTC
Find some mismatch between attach-disk and xml.

Juxtapose the candidate of --driver in 'man virsh' and the actual value in xml, 
I think the value of --driver should be matched <disk type='phy' device='disk'>,
but it pass the value to <driver name='phy' type='qcow2'>.

# man virsh
...
    attach-disk domain-id source target optional --driver driver --subdriver subdriver --type type --mode mode

Attach a new disk device to the domain.  source and target are paths for the files and devices.  
>>>>
 driver can be file, tap or phy depending on the kind of access.
<<<  
>>>>
 type can indicate cdrom or floppy as alternative to the disk default
<<<,
although this use only replaces the media within the existing virtual cdrom or floppy device; consider using update-device for this usage instead.  mode can specify the two specific mode readonly or shareable.

# virsh edit demo
...
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/images/RHEL-Server-6-64-virtio.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/cdrom1.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='0'/>
</disk>

Comment 6 weizhang 2010-09-28 02:42:30 UTC
I test it on rc4 to attach a raw disk, it also has problem and cat not start
#virsh attach-disk demo /var/lib/libvirt/images/foo.img vdb
#virsh dumpxml demo
...
    <disk type='block' device='disk'>
      <driver name='phy' 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='0x06' function='0x0'/>
    </disk>
...

Comment 7 Florin Iucha 2010-10-11 03:18:16 UTC
FWIW I have the same problem on Fedora 14 beta.  I have added a /dev/md0 device to my guest and it works fine until I shut down.  To add insult to the injury, I can't detach the disk from the virsh console using 'detach-disk' because the domain isn't running.  But I can't start the domain.  Luckily, I can remove the device from virt-manager.

Is there a Fedora 14 bug I should subscribe to in order to follow the progress?

Comment 9 Osier Yang 2010-11-25 09:28:20 UTC
missed one upstream patch which is to address this problem: http://www.redhat.com/archives/libvir-list/2010-September/msg00156.html

though it's not addressed completely, depends on user must use the new options introduced by this patch.

- Osier

Comment 10 Osier Yang 2010-12-02 07:49:25 UTC
patch pushed upstream:

http://www.redhat.com/archives/libvir-list/2010-December/msg00097.html

- Osier

Comment 11 Yufang Zhang 2010-12-10 03:33:35 UTC
Hi Osier,

Should the patch be backported into RHEL5.6/5.7 for Xen? Xen could handle the situation when no driver was given as a default(see BZ#658712), so it is ok for libvirt not to give a default driver value.

Yufang

Comment 12 Jiri Denemark 2011-01-09 23:58:37 UTC
Built into libvirt-0.8.7-1.el6

Comment 13 weizhang 2011-01-10 08:20:51 UTC
verify PASS on libvirt-0.8.7-1.el6

after start a guest do
# virsh attach-disk test /var/lib/libvirt/images/foo.img vdb
Disk attached successfully

# virsh dumpxml test
...
<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='0x06' function='0x0'/>
</disk>
...

After shutdown, the device "foo.img" is removed.

# virsh start test
Domain test started

no error occured. 

qemu-kvm-0.12.1.2-2.128.el6.x86_64
kernel-2.6.32-94.el6.x86_64
libvirt-0.8.7-1.el6

Comment 15 Jiri Denemark 2011-01-14 12:55:15 UTC
*** Bug 632580 has been marked as a duplicate of this bug. ***

Comment 16 Cui Chun 2011-02-10 08:02:36 UTC
Blocked by new bug 676548 and will verify it later.

Comment 17 Cui Chun 2011-02-15 08:21:47 UTC
Rechecked it on the following test environment according to comment 13. It is passed.

Test environment:
libvirt-0.8.7-6.el6
qemu-kvm-0.12.1.2-2.144.el6
kernel-2.6.32-113.el6

Comment 19 Vivian Bian 2011-04-20 07:13:02 UTC
tested with 
libvirt-0.8.7-18.el6.x86_64
qemu-kvm-0.12.1.2-2.158.el6.x86_64
kernel-2.6.32-131.0.1.el6.x86_64

after hot-plug disk , shutdown guest works fine , and guest can be start after stop . 

So keep bug status as VERIFIED

Comment 20 Osier Yang 2011-05-03 07:38:29 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
virsh set a "phy" as the disk driver if user doesn't specify one when attaching a disk (virsh attach-disk), this breaks the domain start after attaching a disk without specifying the driver, this update fixed the problem.

Comment 21 Osier Yang 2011-05-03 07:40:53 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-virsh set a "phy" as the disk driver if user doesn't specify one when attaching a disk (virsh attach-disk), this breaks the domain start after attaching a disk without specifying the driver, this update fixed the problem.+virsh sets "phy" as the disk driver if user doesn't specify one when attaching a disk (virsh attach-disk), this breaks the domain start after attaching a disk without specifying the driver, this update fixed the problem.

Comment 24 Laura Bailey 2011-05-04 06:53:00 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-virsh sets "phy" as the disk driver if user doesn't specify one when attaching a disk (virsh attach-disk), this breaks the domain start after attaching a disk without specifying the driver, this update fixed the problem.+If the user did not specify a disk driver when hot-plugging a disk with "virsh attach-disk", virsh set "phy" as the driver value by default. Because this value is not supported everywhere, the disk did not persist over domain shutdown, and could prevent domain startup. This update corrects virsh behavior such that the driver value is not set if it is not provided by the user.

Comment 29 errata-xmlrpc 2011-05-19 13:20:50 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0596.html