Bug 1134294

Summary: libvirt can't acquire state change lock after do blockjob --pivot before block copy job is finished
Product: Red Hat Enterprise Linux 7 Reporter: Shanzhi Yu <shyu>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED DUPLICATE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: agedosier, dyuan, eblake, jmiao, mzhan, rbalakri, xuzhang, yanyang, zpeng
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: 2015-01-14 04:59:16 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 Shanzhi Yu 2014-08-27 09:03:32 UTC
Description of problem:

libvirt can't acquire state change lock after do blockjob --pivot before block copy job is finished


Version-Release number of selected component (if applicable):
libvirt-1.2.7-2.el7.x86_64
qemu-kvm-rhev-2.1.0-2.el7.x86_64


How reproducible:

100%

Steps to Reproduce:

1.Prepare a transient guest

# virsh list --transient
 Id    Name                           State
----------------------------------------------------
 2     rhel6                          running

2.Do blockcopy without --pivot in first terminal

# virsh blockcopy rhel6 vda /var/lib/libvirt/copy.img
Block Copy started

3.Before block copy job is finished, do blockjob --pivot in second terminal

# virsh blockjob rhel6 vda --info ;virsh blockjob rhel6 vda --pivot ;
Block Copy: [ 31 %]


4.Check blockjob info in first terminal
# virsh blockjob rhel6 vda --info
error: Timed out during operation: cannot acquire state change lock

# virsh blockjob rhel6 vda --abort
error: Timed out during operation: cannot acquire state change lock


Actual results:

Guest will keep having one block job and can't do any block job related operations

Expected results:

In step 3, libvirt should post error like "error: can't do pivot: domain still in block copy job"


Additional info:

This can be reproduced on RHEL6.6

Comment 1 Osier Yang 2014-09-13 03:51:51 UTC
Hi, Shanzhi

The bug is not always reproduceable, am I right? I got the similar problem (2 times) when long running our test cases in 2 days.

The command I used is:

# virsh blockcopy $domain $head_disk $snapshot_img --shallow --reuse-external --wait --pivot

When the problem occurred, all the blockjob command fails with "can't acquire lock", since the lock is held forever.  There is no way to recover except restarting libvirtd.

Regards,
Osier

Comment 2 Osier Yang 2014-09-13 04:03:17 UTC
Forgot to mention, I used libvirt-1.2.7 too. 

And when the hanging problem happened, the mirroring phase of "blockcopy" was actually finished.

Comment 3 Shanzhi Yu 2014-09-14 15:43:13 UTC
(In reply to Osier Yang from comment #1)
> Hi, Shanzhi
> 
> The bug is not always reproduceable, am I right? I got the similar problem
> (2 times) when long running our test cases in 2 days.
> 
> The command I used is:
> 
> # virsh blockcopy $domain $head_disk $snapshot_img --shallow
> --reuse-external --wait --pivot
> 
> When the problem occurred, all the blockjob command fails with "can't
> acquire lock", since the lock is held forever.  There is no way to recover
> except restarting libvirtd.
> 
> Regards,
> Osier

Hi Osier,

Thanks for your info. 
Actually I can reproduce it 100 percents. There is a little difference between my steps and yours. My steps is for negative test. Do pivot before copy is ready.
I will try to reproduce it by your steps. 

To comment 2,
When the hanging problem happened, I found the copy job(first phase of 'blockcopy') still be running in backgrand.

Thanks again.

Comment 4 Shanzhi Yu 2014-09-15 03:27:17 UTC
I met another error after try many times. QEMU command 'block-job-complete' can not be completed.


1. Set log_level=1,log_outputs="1:file:/tmp/libvirtd.log" in libvirtd.conf
# grep -v "^#" /etc/libvirt/libvirtd.conf
log_level=1
log_outputs="1:file:/tmp/libvirtd.log"

2. Do blockcopy in one terminal

# for i in `seq 1 100`;do virsh blockcopy rh7 vda /var/lib/libvirt/images/copy-$i.img --verbose --wait --pivot --shallow ;done
Block Copy: [100 %]
Successfully pivoted
Block Copy: [100 %]
Successfully pivoted
Block Copy: [100 %]
Successfully pivoted
Block Copy: [100 %]
Successfully pivoted
Block Copy: [100 %]


3. Check error in another terminal

# tailf /tmp/libvirtd.log |grep error
2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorIOProcess:399 : QEMU_MONITOR_IO_PROCESS: mon=0x7f1d0000bbc0 buf={"id": "libvirt-228", "error": {"class": "GenericError", "desc": "The active block job for device 'drive-virtio-disk0' cannot be completed"}}
2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorJSONIOProcessLine:179 : Line [{"id": "libvirt-228", "error": {"class": "GenericError", "desc": "The active block job for device 'drive-virtio-disk0' cannot be completed"}}]
2014-09-15 03:04:39.677+0000: 2115: debug : virJSONValueFromString:1136 : string={"id": "libvirt-228", "error": {"class": "GenericError", "desc": "The active block job for device 'drive-virtio-disk0' cannot be completed"}}
2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorJSONIOProcessLine:199 : QEMU_MONITOR_RECV_REPLY: mon=0x7f1d0000bbc0 reply={"id": "libvirt-228", "error": {"class": "GenericError", "desc": "The active block job for device 'drive-virtio-disk0' cannot be completed"}}
2014-09-15 03:04:39.678+0000: 2120: debug : virJSONValueToString:1303 : result={"id":"libvirt-228","error":{"class":"GenericError","desc":"The active block job for device 'drive-virtio-disk0' cannot be completed"}}
2014-09-15 03:04:39.678+0000: 2120: debug : qemuMonitorJSONCheckError:366 : unable to execute QEMU command {"execute":"block-job-complete","arguments":{"device":"drive-virtio-disk0"},"id":"libvirt-228"}: {"id":"libvirt-228","error":{"class":"GenericError","desc":"The active block job for device 'drive-virtio-disk0' cannot be completed"}}
2014-09-15 03:04:39.678+0000: 2120: error : qemuMonitorJSONCheckError:377 : internal error: unable to execute QEMU command 'block-job-complete': The active block job for device 'drive-virtio-disk0' cannot be completed

4. Check guest xml 

# virsh dumpxml rh7
 <disk type='file' device='disk'>
      <driver type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/images/copy-4.img'/>
      <backingStore type='block' index='1'>
        <format type='raw'/>
        <source dev='/dev/sda7'/>
        <backingStore/>
      </backingStore>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>

5. When try to get blockjob information, will met can't acquire state change lock 

# virsh blockjob rh7 vda 
error: Timed out during operation: cannot acquire state change lock

More like another bug ? 
Eirc, Can you help confirm this?

Thanks

Comment 5 Osier Yang 2014-09-15 08:05:11 UTC
(In reply to Shanzhi Yu from comment #4)
> I met another error after try many times. QEMU command 'block-job-complete'
> can not be completed.
> 
> 
> 1. Set log_level=1,log_outputs="1:file:/tmp/libvirtd.log" in libvirtd.conf
> # grep -v "^#" /etc/libvirt/libvirtd.conf
> log_level=1
> log_outputs="1:file:/tmp/libvirtd.log"
> 
> 2. Do blockcopy in one terminal
> 
> # for i in `seq 1 100`;do virsh blockcopy rh7 vda
> /var/lib/libvirt/images/copy-$i.img --verbose --wait --pivot --shallow ;done
> Block Copy: [100 %]
> Successfully pivoted
> Block Copy: [100 %]
> Successfully pivoted
> Block Copy: [100 %]
> Successfully pivoted
> Block Copy: [100 %]
> Successfully pivoted
> Block Copy: [100 %]
> 
> 
> 3. Check error in another terminal
> 
> # tailf /tmp/libvirtd.log |grep error
> 2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorIOProcess:399 :
> QEMU_MONITOR_IO_PROCESS: mon=0x7f1d0000bbc0 buf={"id": "libvirt-228",
> "error": {"class": "GenericError", "desc": "The active block job for device
> 'drive-virtio-disk0' cannot be completed"}}
> 2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorJSONIOProcessLine:179
> : Line [{"id": "libvirt-228", "error": {"class": "GenericError", "desc":
> "The active block job for device 'drive-virtio-disk0' cannot be completed"}}]
> 2014-09-15 03:04:39.677+0000: 2115: debug : virJSONValueFromString:1136 :
> string={"id": "libvirt-228", "error": {"class": "GenericError", "desc": "The
> active block job for device 'drive-virtio-disk0' cannot be completed"}}
> 2014-09-15 03:04:39.677+0000: 2115: debug : qemuMonitorJSONIOProcessLine:199
> : QEMU_MONITOR_RECV_REPLY: mon=0x7f1d0000bbc0 reply={"id": "libvirt-228",
> "error": {"class": "GenericError", "desc": "The active block job for device
> 'drive-virtio-disk0' cannot be completed"}}
> 2014-09-15 03:04:39.678+0000: 2120: debug : virJSONValueToString:1303 :
> result={"id":"libvirt-228","error":{"class":"GenericError","desc":"The
> active block job for device 'drive-virtio-disk0' cannot be completed"}}
> 2014-09-15 03:04:39.678+0000: 2120: debug : qemuMonitorJSONCheckError:366 :
> unable to execute QEMU command
> {"execute":"block-job-complete","arguments":{"device":"drive-virtio-disk0"},
> "id":"libvirt-228"}:
> {"id":"libvirt-228","error":{"class":"GenericError","desc":"The active block
> job for device 'drive-virtio-disk0' cannot be completed"}}
> 2014-09-15 03:04:39.678+0000: 2120: error : qemuMonitorJSONCheckError:377 :
> internal error: unable to execute QEMU command 'block-job-complete': The
> active block job for device 'drive-virtio-disk0' cannot be completed
> 

Thanks for the testing, Shanzhi.

These errors tells the bug is in QEMU.

Comment 6 Shanzhi Yu 2014-09-16 16:13:53 UTC
There is a qemu-kvm-rhev bug 1130489 should cause problem in comment 4

Comment 7 Eric Blake 2015-01-13 20:06:41 UTC
Upstream is reporting the same symptoms:
https://www.redhat.com/archives/libvir-list/2015-January/msg00454.html

Comment 8 Eric Blake 2015-01-14 04:59:16 UTC
After more investigation, it looks like this problem was solved by the same patch as for bug 1139567

*** This bug has been marked as a duplicate of bug 1139567 ***

Comment 9 Shanzhi Yu 2015-01-28 05:42:47 UTC
After bug 1139567 be fixed then retest this bug, it work fine.
Do pivot before copy is not finish will met error like below:

# virsh blockjob test vda --pivot 
error: block copy still active: disk 'vda' not ready for pivot yet

# virsh blockjob test vda 
Block Copy: [ 40 %]