Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1599277

Summary: qemu-img commit "-b" option does not work when specifying the overlay by relative path
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Tingting Mao <timao>
Component: qemu-kvmAssignee: Hanna Czenczek <hreitz>
qemu-kvm sub component: Storage QA Contact: Xueqiang Wei <xuwei>
Status: CLOSED ERRATA Docs Contact:
Severity: low    
Priority: low CC: chaoyang, coli, juzhang, mrezanin, ngu, rbalakri, virt-maint, yfu
Version: ---Keywords: Triaged
Target Milestone: rcFlags: knoel: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-5.2.0-1.module+el8.4.0+9091+650b220a Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-25 06:41: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:
Bug Depends On: 1594747    
Bug Blocks:    

Description Tingting Mao 2018-07-09 11:53:04 UTC
Description of problem:
Can not find the backing file when executing qemu-img commit specifying the overlay by relative path

Version-Release number of selected component (if applicable):
qemu-kvm-rhev-2.12.0-7.el7
kernel-3.10.0-918.el7

How reproducible:
100%

Steps to Reproduce:
1.Create base.qcow2->sn1.qcow2->sn2.qcow2
# qemu-img create -f qcow2 base.qcow2 10G
# qemu-img create -f qcow2 -b base.qcow2 sn1.qcow2
# qemu-img create -f qcow2 -b sn1.qcow2 sn2.qcow2
2.Write data to the sn2.qcow2
# qemu-io -c 'write -P 1 0 1G' sn2.qcow2
3.Check the backing-chain info for sn2.qcow2
# qemu-img info test/sn2.qcow2 --backing-chain
image: test/sn2.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.0G
cluster_size: 65536
backing file: sn1.qcow2 (actual path: test/sn1.qcow2)
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

image: test/sn1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 196K
cluster_size: 65536
backing file: base.qcow2 (actual path: test/base.qcow2)
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

image: test/base.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
4.Commit sn2.qcow2 to base.qcow2
4.1 Specify the base.qcow2 by relative path
# qemu-img commit -f qcow2 -b base.qcow2 test/sn2.qcow2 
qemu-img: Did not find 'base.qcow2' in the backing chain of 'test/sn2.qcow2'
# qemu-img commit -f qcow2 -b test/base.qcow2 test/sn2.qcow2 
qemu-img: Did not find 'test/base.qcow2' in the backing chain of 'test/sn2.qcow2'
4.1 Specify the base.qcow2 by full path
# qemu-img commit -f qcow2 -b /home/test/new_bug_for_commit/test/base.qcow2 test/sn2.qcow2 
qemu-img: Did not find '/home/test/new_bug_for_commit/test/base.qcow2' in the backing chain of 'test/sn2.qcow2'


Actual results:


Expected results:
Commit should success when executing "qemu-img commit -f qcow2 -b base.qcow2 test/sn2.qcow2", and descriptions for commit with relative path should be in qemu-img manpage also.


Additional info:
There is the same issue in rhel7.5, so it is not a regression.

Comment 2 Hanna Czenczek 2018-07-11 13:26:31 UTC
This is interesting.  This one’s not very easy to fix, in fact I don’t know an approach off the top of my hat.  I know what’s broken, though.

The qemu-internal string pointing to the backing file is updated when the backing file is actually opened.  So in this case it is modified from “base.qcow2” to “test/base.qcow2”.  However, when looking for the backing file, we try to make it an absolute filename, so now we interpret it relative to the overlay again.  This yields basically “test/test/base.qcow2”.  On top of that we do a realpath(), which fails, because that path does not exist.

So the base issue is that half of the block layer interprets bs->backing_file like it was the string in the image header (which it is before bdrv_open_backing_file()), and the other half interprets it as kind of a cache of bs->backing->bs->filename.  Those are different things, though.

The bottom line is that there probably won’t be a quick fix for this.

Max

Comment 4 Ademar Reis 2019-08-19 17:34:31 UTC
Missed qemu-4.1, so we'll wait for the next rebase.

Comment 5 Hanna Czenczek 2019-11-19 10:46:56 UTC
This is fixed by the same series as BZ 1594747.  Unfortunately, it is rather far from being merged upstream.

Max

Comment 6 Ademar Reis 2020-02-05 22:48:12 UTC
QEMU has been recently split into sub-components and as a one-time operation to avoid breakage of tools, we are setting the QEMU sub-component of this BZ to "General". Please review and change the sub-component if necessary the next time you review this BZ. Thanks

Comment 8 Ademar Reis 2020-11-02 15:01:00 UTC
The filter series has been merged upstream. Max will provide more details and reproducer here before we move it to POST.

Comment 10 Hanna Czenczek 2020-11-10 12:04:12 UTC
The steps provided in comment 0 work well as a reproducer.

Result with qemu 5.2:

$ qemu-img commit -f qcow2 -b base.qcow2 test/sn2.qcow2
Image committed.

$ qemu-img commit -f qcow2 -b test/base.qcow2 test/sn2.qcow2
qemu-img: Did not find 'test/base.qcow2' in the backing chain of 'test/sn2.qcow2'

$ qemu-img commit -f qcow2 -b $PWD/test/base.qcow2 test/sn2.qcow2
Image committed.


(The second variant isn't expected to work.  The base filename either has to match the string that was given as the backing image during qemu-img create, i.e. "base.qcow2" in this case, or be an absolute path, as in the third variant.)

Comment 11 Xueqiang Wei 2020-12-10 15:24:36 UTC
Tested with qemu-kvm-5.2.0-1.module+el8.4.0+9091+650b220a, not hit this issue.

Versions:
kernel-4.18.0-259.el8.x86_64
qemu-kvm-5.2.0-1.module+el8.4.0+9091+650b220a


Steps:

1.Create base.qcow2->sn1.qcow2->sn2.qcow2
# qemu-img create -f qcow2 base.qcow2 10G
# qemu-img create -f qcow2 -b base.qcow2 sn1.qcow2
# qemu-img create -f qcow2 -b sn1.qcow2 sn2.qcow2

2.Write data to the sn2.qcow2
# qemu-io -c 'write -P 1 0 1G' sn2.qcow2

3.Check the backing-chain info for sn2.qcow2
# qemu-img info bug_verify/sn2.qcow2 --backing-chain
image: bug_verify/sn2.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1 GiB
cluster_size: 65536
backing file: sn1.qcow2 (actual path: bug_verify/sn1.qcow2)
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

image: bug_verify/sn1.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: base.qcow2 (actual path: bug_verify/base.qcow2)
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

image: bug_verify/base.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 196 KiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false


4.Commit sn2.qcow2 to base.qcow2
4.1 Specify the base.qcow2 by relative path
# qemu-img commit -f qcow2 -b base.qcow2 bug_verify/sn2.qcow2
Image committed.

# qemu-img info bug_verify/base.qcow2 
image: bug_verify/base.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false


4.2 repeat step 1 to step 3
# qemu-img commit -f qcow2 -b bug_verify/base.qcow2 bug_verify/sn2.qcow2 
qemu-img: Did not find 'bug_verify/base.qcow2' in the backing chain of 'bug_verify/sn2.qcow2'


4.3 Specify the base.qcow2 by full path
# qemu-img commit -f qcow2 -b /home/bug_verify/base.qcow2 /home/bug_verify/sn2.qcow2 
Image committed.

# qemu-img info /home/bug_verify/base.qcow2 
image: /home/bug_verify/base.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

Comment 15 Xueqiang Wei 2020-12-16 01:58:46 UTC
According to Comment 11, set status to VERIFIED.

Comment 19 errata-xmlrpc 2021-05-25 06:41:16 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 (virt:av bug fix and enhancement update), 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-2021:2098