Bug 1599335

Summary: Image creation locking is too tight and is not properly released
Product: Red Hat Enterprise Linux 7 Reporter: Hanna Czenczek <hreitz>
Component: qemu-kvm-rhevAssignee: Hanna Czenczek <hreitz>
Status: CLOSED ERRATA QA Contact: Tingting Mao <timao>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.6CC: chayang, coli, hreitz, juzhang, michen, ngu, pingl, qzhang, virt-maint, yhong
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-rhev-2.12.0-8.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-01 11:13:00 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 Hanna Czenczek 2018-07-09 14:24:20 UTC
Description of problem:

Instead of forbidding concurrent truncations, file-posix does the opposite.  Because qemu always needs other permissions for truncation besides RESIZE itself, this still means concurrent truncations are effectively disallowed.  But it also means that valid concurrent uses are disallowed as well.

Furthermore, the file locks are not released before the FD is closed.  This may lead to locks staying applied when working with fdsets.


Steps to Reproduce:
$ qemu-img create -f raw -o preallocation=full foo.img 1G &; qemu-io -c info -c close -r foo.img

Actual results:
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
can't open device foo.img: Failed to get "consistent read" lock
Is another process using the image?


Expected results:
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
format name: raw
cluster size: 0 bytes
vm state offset: 0 bytes

Comment 2 Hanna Czenczek 2018-07-09 14:40:28 UTC
Correction for the reproduction step:
$ qemu-img create -f raw -o preallocation=full foo.img 1G &; sleep 0.5; qemu-io -c info -c close -r foo.img

(Otherwise, the image file may or may not exist before qemu-io runs)

Comment 4 Miya Chen 2018-07-10 04:09:24 UTC
Max, we are not able to reproduce this bz by using the steps you provided:

# qemu-img create -f raw -o preallocation=full foo.img 1G &  sleep 0.5; qemu-io -c info -c close -r foo.img
[1] 16582
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
format name: raw
cluster size: 0 bytes
vm state offset: 0 bytes

# rpm -qa |grep qemu-img
qemu-img-rhev-2.12.0-1.el7.x86_64

Comment 5 Ping Li 2018-07-10 05:48:53 UTC
Based on my testing results, this bz should be a regression since qemu-kvm-rhev-2.12.0-7.el7.

# qemu-img --version
qemu-img version 2.12.0 (qemu-kvm-rhev-2.12.0-6.el7)
# qemu-img create -f raw -o preallocation=full foo.img 1G &  sleep 0.5; qemu-io -c info -c close -r foo.img
[1] 19257
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
format name: raw
cluster size: 0 bytes
vm state offset: 0 bytes

# qemu-img --version
qemu-img version 2.12.0 (qemu-kvm-rhev-2.12.0-7.el7)
# qemu-img create -f raw -o preallocation=full foo.img 1G &  sleep 0.5; qemu-io -c info -c close -r foo.img
[1] 19485
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
can't open device foo.img: Failed to get "consistent read" lock
Is another process using the image?

Comment 6 Hanna Czenczek 2018-07-11 09:56:29 UTC
Yes, that is correct.  This is an issue with the backport for BZ 1519144, which was included in 2.12.0-7.

Sorry I did not specify the downstream version.

Max

Comment 7 Miroslav Rezanina 2018-07-24 14:40:43 UTC
Fix included in qemu-kvm-rhev-2.12.0-8.el7

Comment 9 Tingting Mao 2018-07-26 05:15:57 UTC
Verified this issue like below.

Package tested:
qemu-kvm-rhev-2.12.0-8.el7
kernel-3.10.0-926.el7

Steps:
# qemu-img create -f raw -o preallocation=full foo.img 1G &  sleep 0.5; qemu-io -c info -c close -r foo.img
[1] 12008
Formatting 'foo.img', fmt=raw size=1073741824 preallocation=full
format name: raw
cluster size: 0 bytes
vm state offset: 0 bytes

Comment 10 errata-xmlrpc 2018-11-01 11:13:00 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/RHBA-2018:3443