Bug 1220213

Summary: vol-resize with --delta --shrink does not shrink the volume
Product: Red Hat Enterprise Linux 7 Reporter: yisun
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: dyuan, jtomko, rbalakri, xuzhang, yanyang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:30:32 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 yisun 2015-05-11 02:57:17 UTC
description:
using vol-resize with a negative value and "--delta --shrink" will cause size increasing instead of decreasing.

versions:
kernel-3.10.0-242.el7.x86_64
qemu-kvm-rhev-2.3.0-1.el7.x86_64
libvirt-1.2.14-1.el7.x86_64

repro steps:
1. has a volume in default pool. 
# virsh vol-list default
 Name                 Path                                    
------------------------------------------------------------------------------
........ 
 rs.raw               /var/lib/libvirt/images/rs.raw          
.......

2. check the volume's info
# qemu-img info /var/lib/libvirt/images/rs.raw
image: /var/lib/libvirt/images/rs.raw
file format: raw
virtual size: 2.0G (2098200576 bytes)

3. use vol-resize on this volume with --shrink --delta and a positive value (200M)
# virsh vol-resize /var/lib/libvirt/images/rs.raw 200M --shrink --delta
Size of volume 'rs.raw' successfully changed by 200M

# qemu-img info /var/lib/libvirt/images/rs.raw
image: /var/lib/libvirt/images/rs.raw
file format: raw
virtual size: 2.2G (2357198848 bytes)    <==== 200M added as expected
disk size: 0

4. use vol-resize on this volume with --shrink --delta and a negative value (-200M)
# virsh vol-resize /var/lib/libvirt/images/rs.raw -200M --shrink --delta
Size of volume 'rs.raw' successfully changed by 200M

# qemu-img info /var/lib/libvirt/images/rs.raw
image: /var/lib/libvirt/images/rs.raw
file format: raw
virtual size: 2.4G (2566914048 bytes)   <==== still 200M added
disk size: 0
Actual result:
When use "vol-resize -200M --delta --shrink", the volume size was increased by 200M

Expected result:
when use a negative capacity value with "--delta --shrink", volume size should be decreased.

Comment 2 Ján Tomko 2015-05-27 15:12:39 UTC
I think even a positive value (if combined with --delta) should shrink the volume with the --shrink flag.

Upstream patches:
https://www.redhat.com/archives/libvir-list/2015-May/msg01041.html

Comment 3 Yang Yang 2015-05-28 03:01:03 UTC
Jan,

Currently a positive value (which is larger than current capacity) combined with --shrink will extend the volume. Is it the expected result ?

# virsh vol-info yy default
Name:           yy
Type:           file
Capacity:       1.00 GiB
Allocation:     1.00 GiB

# virsh vol-resize --pool default yy 2G --shrink
Size of volume 'yy' successfully changed to 2G

# virsh vol-info yy default
Name:           yy
Type:           file
Capacity:       2.00 GiB
Allocation:     1.00 GiB

Regards
Yang

Comment 4 Ján Tomko 2015-05-28 08:48:44 UTC
Yes, unfortunately.

--shrink copies the behavior of VIR_STORAGE_VOL_RESIZE_SHRINK

This flag is documented as 'allow shrinking the volume' not 'shrink the volume':
http://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolResizeFlags

Only with the DELTA flag is it documented to mean 'shrink the volume':
http://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolResize
but it was not implemented until my patch:
https://www.redhat.com/archives/libvir-list/2015-May/msg01043.html

Comment 5 Ján Tomko 2015-05-28 12:29:24 UTC
Shrinking volumes with the --delta flag is merged upstream now:
(both "-200M' and "200M" will shrink the volume by 200M)

commit 8b316fe5da8e459349b1a3ee0037bc7988d6f8aa
Author:     Ján Tomko <jtomko>
CommitDate: 2015-05-28 14:10:32 +0200

    Fix shrinking volumes with the delta flag
    
    This never worked.
    
    In 0.9.10 when this API was introduced, it was intended that
    the SHRINK flag combined with DELTA would shrink the volume by
    the specified capacity (to avoid passing negative numbers).
    See commit 055bbf4.
    
    When the SHRINK flag was finally implemented for the first backend
    in 1.2.13 (commit aa9aa6a), it was only implemented for the absolute
    values and with the delta flag the volume is always extended,
    regardless of the SHRINK flag.
    
    Treat the SHRINK flag as a minus sign when used together with DELTA,
    to allow shrinking volumes as was documented in the API since 0.9.10.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1220213

git describe: v1.2.16-rc1-9-g8b316fe

Comment 6 Ján Tomko 2015-06-01 12:02:27 UTC
Using a negative value implies --delta since:
commit 0a33bba1aeec04ccf6963b6942bac4586f04dda7
CommitDate: 2015-06-01 13:56:49 +0200

    virsh: make negative values with vol-resize more convenient
    
    When shrinking a volume by a certain size, instead of typing
      vol-resize volume 1G --delta --shrink
    we allow the convience of specifying a negative value:
      vol-resize volume -1G --delta --shrink
    getting the same results with one more character.
    
    A negative value only makes sense as a delta. Imply the
    --delta parameter if the value is negative.
    
    Still require --shrink, because the operation is potentially
    destructive.

git describe: v1.2.16-6-g0a33bba

Comment 8 yisun 2015-07-09 12:18:29 UTC
verified on libvirt-1.2.17-1.el7.x86_64

1. prepare a pool with a volume with 5GiB capacity

# virsh vol-info disk1.img pool
Name:           disk1.img
Type:           file
Capacity:       5.00 GiB
Allocation:     196.00 KiB


2. resize with negative value and --shrink
# virsh vol-resize /home/test/disk1.img -1G --shrink
Size of volume 'disk1.img' successfully changed by 1G

# virsh vol-info disk1.img pool
Name:           disk1.img
Type:           file
Capacity:       4.00 GiB    <===== expected.
Allocation:     0.00 B

3. resize with positive value with --delta --shrink
# virsh vol-resize /home/test/disk1.img 1G --delta --shrink
Size of volume 'disk1.img' successfully changed by 1G

# virsh vol-info disk1.img pool
Name:           disk1.img
Type:           file
Capacity:       3.00 GiB   <=== expected
Allocation:     0.00 B

4. resize with negative value with --delta --shrink
# virsh vol-resize /home/test/disk1.img -1G --delta --shrink
Size of volume 'disk1.img' successfully changed by 1G

# virsh vol-info disk1.img pool
Name:           disk1.img
Type:           file
Capacity:       2.00 GiB   <===== expected
Allocation:     0.00 B

5. resize with lager-than-current value with shrink
# virsh vol-resize /home/test/disk1.img 5G --shrink
Size of volume 'disk1.img' successfully changed to 5G

# virsh vol-info disk1.img pool
Name:           disk1.img
Type:           file
Capacity:       5.00 GiB  <==== expected as comment 4 pointed out
Allocation:     0.00 B

Comment 10 errata-xmlrpc 2015-11-19 06:30:32 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://rhn.redhat.com/errata/RHBA-2015-2202.html