Bug 1523065

Summary: "qemu-img resize" should fail to decrease the size of logical partition/lvm/iSCSI image with raw format
Product: Red Hat Enterprise Linux 7 Reporter: yilzhang
Component: qemu-kvm-rhevAssignee: Hanna Czenczek <hreitz>
Status: CLOSED ERRATA QA Contact: Tingting Mao <timao>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.5CC: juzhang, knoel, kwolf, michen, mrezanin, ngu, pingl, qzhang, timao, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: qemu-kvm-rhev-2.12.0-3.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-01 11:04: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 yilzhang 2017-12-07 06:46:52 UTC
Description of problem:
For logical partition/lvm/iSCSI image with raw format, "qemu-img resize" should fail to decrease its size and provide reasonable error.

Currently, "qemu-img resize" will fail and print error when trying to enlarge its size.


Version-Release number of selected component (if applicable):


How reproducible: 100%

Steps to Reproduce:
1. Create a lvm
# lvcreate -L 4G -n   yil_lv  yil_vg

2. Check the image info
# qemu-img info  /dev/yil_vg/yil_lv
image: /dev/yil_vg/yil_lv
file format: raw
virtual size: 4.0G (4294967296 bytes)  ----------------- size is 4G
disk size: 0

3. Use "qemu-img resize" to decrease its size
# qemu-img resize -f raw /dev/yil_vg/yil_lv  -2G
Image resized.

4. Check the image info again
# qemu-img info  /dev/yil_vg/yil_lv
image: /dev/yil_vg/yil_lv
file format: raw
virtual size: 4.0G (4294967296 bytes)  ----------------- size is still 4G
disk size: 0


Actual results:
In step3, decreasing the lvm image's size succeeds, but in step4 this lvm image's size is NOT changed

Expected results:
In step3, decreasing the lvm image's size should fail with error



Additional info:
Resizing a raw iSCSI image has the same problem, steps are as follows:

1. Prepare an iSCSI image
2. Check the image info 
# qemu-img info  iscsi://10.0.0.7/iqn.2017-08.com.yilzhang:libiscsi/0
image: json:{"driver": "raw", "file": {"lun": "0", "portal": "10.0.0.7", "driver": "iscsi", "transport": "tcp", "target": "iqn.2017-08.com.yilzhang:libiscsi"}}
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: unavailable

3. Use "qemu-img resize" to decrease its size 
# qemu-img  resize -f raw  iscsi://10.0.0.7/iqn.2017-08.com.yilzhang:libiscsi/0  -4G
Image resized.
[root@c155f2-u3 ~]# echo $?
0

4. Check the image info again
# qemu-img info  iscsi://10.0.0.7/iqn.2017-08.com.yilzhang:libiscsi/0
image: json:{"driver": "raw", "file": {"lun": "0", "portal": "10.0.0.7", "driver": "iscsi", "transport": "tcp", "target": "iqn.2017-08.com.yilzhang:libiscsi"}}
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: unavailable

Comment 2 yilzhang 2017-12-07 06:52:05 UTC
This is platform unrelated, kernel and qemu-kvm used when doing testing:
PPC:
 Host kernel:   4.14.0-11.el7a.ppc64le
 qemu-kvm-rhev: qemu-kvm-rhev-2.10.0-11.el7

x86:
 Host kernel:   3.10.0-799.el7.x86_64
 qemu-kvm-rhev: qemu-kvm-rhev-2.10.0-10.el7

Comment 3 Hanna Czenczek 2018-01-03 15:25:20 UTC
Hi,

This is actually intended, judging from the code.  Both the iscsi and the block device truncation code explicitly only throw an error when you try to enlarge the volume and do nothing if the volume size you want is less than what it currently is.

The commit which added truncation for iscsi (cb1b83e740384b4e0d950f3d7c81c02b8ce86c2e) actually says why this is the case: Truncation here does not work through qemu.  Instead, you have to manually resize the volume on the iscsi target and then call block_resize in a qemu instance (through QMP!) with the appropiate size so that qemu knows about the change.  The same applies to block device files (see 55b949c84761ade81ca93b2596ea45b09ad6d60a).

I won't close this bug now, though, because I think that the offline qemu-img resize command should indeed print a message for such protocol drivers that do not really implement truncation, and which instead just cause qemu to refresh the image's current length.

Max

Comment 5 Hanna Czenczek 2018-04-20 23:02:30 UTC
Sent an upstream patch:
http://lists.nongnu.org/archive/html/qemu-block/2018-04/msg00441.html

Comment 7 Miroslav Rezanina 2018-06-01 08:56:02 UTC
Fix included in qemu-kvm-rhev-2.12.0-3.el7

Comment 9 Tingting Mao 2018-06-05 07:01:53 UTC
Verified the issue with below packages and steps.

Package version:
kernel-3.10.0-896.el7
qemu-kvm-rhev-2.12.0-3.el7

Steps:
1.Resize the size of raw image of LVM
1.1 Check the info of the image
# qemu-img info /dev/vgtest/lvtest 
image: /dev/vgtest/lvtest
file format: raw
virtual size: 4.0G (4294967296 bytes)
disk size: 0
1.2 Decrease the size
# qemu-img resize -f raw --shrink /dev/vgtest/lvtest -2G -----> failed
qemu-img: Image was not resized; resizing may not be supported for this image
1.3 Check the image size
# qemu-img info /dev/vgtest/lvtest 
image: /dev/vgtest/lvtest
file format: raw
virtual size: 4.0G (4294967296 bytes) ----> the size not changed
disk size: 0


2.Resize the size of raw image of ISCSI
2.1 Check the info of the image
# qemu-img info iscsi://10.66.11.19/iqn.2018-05.com.example.t1/0
image: json:{"driver": "raw", "file": {"lun": "0", "portal": "10.66.11.19", "driver": "iscsi", "transport": "tcp", "target": "iqn.2018-05.com.example.t1"}}
file format: raw
virtual size: 80G (85899345920 bytes)
disk size: unavailable
2.2 Decrease the size
# qemu-img resize --shrink -f raw iscsi://10.66.11.19/iqn.2018-05.com.example.t1/0 -5G -----> failed
qemu-img: Image was not resized; resizing may not be supported for this image
2.3 Check the size 
# qemu-img info iscsi://10.66.11.19/iqn.2018-05.com.example.t1/0
image: json:{"driver": "raw", "file": {"lun": "0", "portal": "10.66.11.19", "driver": "iscsi", "transport": "tcp", "target": "iqn.2018-05.com.example.t1"}}
file format: raw
virtual size: 80G (85899345920 bytes) -----> the size not changed
disk size: unavailable

Comment 10 errata-xmlrpc 2018-11-01 11:04: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