Bug 638055

Summary: Allow qemu-img re-base with undersized backing files
Product: Red Hat Enterprise Linux 6 Reporter: Shirley Zhou <szhou>
Component: qemu-kvmAssignee: Kevin Wolf <kwolf>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.0CC: areis, juzhang, kwolf, lihuang, minovotn, mkenneth, mshao, shu, sluo, tburke, virt-maint, wdai
Target Milestone: beta   
Target Release: 6.2   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.237.el6 Doc Type: Bug Fix
Doc Text:
Cause: qemu-img rebase assumed in safe mode that backing files have the same size as the rebased image. This is not true, they may be smaller and the rest of the image is considered to be backed by sectors filled with zeros. Consequence: Rebase an image, where the old or the new backing file is smaller than the image itself. In order to compare its content to the backing files, qemu-img tries to read after the end of the backing file and fails with error message "qemu-img: error while reading from new backing file" Fix: Before reading a sector from the new or old backing file for comparison, check if it is even contained in the backing file and use a sector of zeros otherwise. Result: qemu-img rebase succeeds even with backing files that are smaller than the rebased image.
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 11:32:28 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: 580953    

Description Shirley Zhou 2010-09-28 04:51:54 UTC
Description of problem:
qemu-img should check new disk image size is same to base image or not when rebase snapshot to new disk.

Version-Release number of selected component (if applicable):
qemu-kvm-0.12.1.2-2.113.el6_0.1.x86_64

How reproducible:
3/3

Steps to Reproduce:
1.there is a previous installed images, which actually size is 30000M(29.3G)
# qemu-img info win7x64.img
image: win7x64.img
file format: qcow2
virtual size: 29G (31457280000 bytes)
disk size: 9.2G
cluster_size: 65536
2.create 3 snapshot one by one as following
qemu-img create -f qcow2 -F qcow2 -b win7x64.img A
qemu-img create -f qcow2 -F qcow2 -b A B
qemu-img create -f qcow2 -F qcow2 -b B C
3.create a new disk image with 29G image size
qemu-img create -f qcow2 base_new.img 29G 
it is litter less than base image.
4.rebase snapshot C to new base image
# qemu-img rebase -b base_new.img -f qcow2 -F qcow2 C
5.after more than 30mins later, one error prompts
qemu-img: error while reading from new backing file

Actual results:
After write and read 29G data, error prompts.

Expected results:
before rebase, qemu should check the new base image, if the size is not correct, should prompt error at once.

Additional info:
If I create a 30000M new base image, can rebase successfully.

Comment 4 Kevin Wolf 2010-10-07 16:23:45 UTC
Actually, I think it shouldn't abort. If I remember correctly, it's legal to have a snapshot that is larger than its backing file. Probably not a common use case, though.

Comment 5 Shirley Zhou 2010-10-08 10:44:36 UTC
In function bdrv_check_byte_request, it will check validity of parameter len and size, for this bug, it return -EIO, the rebase will end with error "error while reading from new backing file".

    if ((offset > len) || (len - offset < size))
        return -EIO;

When create snapshot for backing file, the size of snapshot is equal to backing file, when rebase to new disk,the size of new disk may be smaller than backing file, at that time, the error is acceptable. 
But the error should be show up before rebase start,it should not prompt after write 29G file. QE prefer to compare size of backing file and new disk before rebase.

Thanks.

Comment 12 Sibiao Luo 2012-03-09 10:42:07 UTC
I have reproduced this issue on qemu-kvm-0.12.1.2-2.236.el6.x86_64 and verified
this issue on qemu-kvm-0.12.1.2-2.237.el6.x86_64 with the same steps.

The result of reproduce is that a error prompts after rebase snapshot C to the new base image:
# qemu-img rebase -b base_new.qcow2 -f qcow2 -F qcow2 C
qemu-img: error while reading from new backing file

The result of verify is that rebase snapshot C to the new base image successfully.
# qemu-img rebase -b base_new.qcow2 -f qcow2 -F qcow2 C
# qemu-img info C
image: C
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 3.2G
cluster_size: 65536
backing file: base_new.qcow2 (actual path: base_new.qcow2)

Above all, this issue has been fixed.

Comment 14 Michal Novotny 2012-05-03 16:59:20 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:
Cause:
Create several snapshots of a backing image and rebase one of them to higher size than the backing file.

Consequence:
qemu-img fails with error message "qemu-img: error while reading from new backing file"

Fix:
Rebase backing image as well and fill sectors after the end of original backing file by zeros.

Result:
File is being rebased to the new size.

Comment 15 Kevin Wolf 2012-05-07 08:57:58 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,11 +1,11 @@
 Cause:
-Create several snapshots of a backing image and rebase one of them to higher size than the backing file.
+qemu-img rebase assumed in safe mode that backing files have the same size as the rebased image. This is not true, they may be smaller and the rest of the image is considered to be backed by sectors filled with zeros.
 
 Consequence:
-qemu-img fails with error message "qemu-img: error while reading from new backing file"
+Rebase an image, where the old or the new backing file is smaller than the image itself. In order to compare its content to the backing files, qemu-img tries to read after the end of the backing file and fails with error message "qemu-img: error while reading from new backing file"
 
 Fix:
-Rebase backing image as well and fill sectors after the end of original backing file by zeros.
+Before reading a sector from the new or old backing file for comparison, check if it is even contained in the backing file and use a sector of zeros otherwise.
 
 Result:
-File is being rebased to the new size.+qemu-img rebase succeeds even with backing files that are smaller than the rebased image.

Comment 16 errata-xmlrpc 2012-06-20 11:32:28 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.

http://rhn.redhat.com/errata/RHBA-2012-0746.html