RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1366446 - vol-resize with --shrink and --allocate behaves strangely
Summary: vol-resize with --shrink and --allocate behaves strangely
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: 7.3
Assignee: Ján Tomko
QA Contact: yisun
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-08-12 02:09 UTC by Lili Zhu
Modified: 2018-04-10 10:36 UTC (History)
5 users (show)

Fixed In Version: libvirt-3.8.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 10:36:45 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0704 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2018-04-10 15:57:35 UTC

Description Lili Zhu 2016-08-12 02:09:49 UTC
Description of problem:
vol-resize with --shrink and --allocate should fail
 
How producible
100%

Version:
kernel-3.10.0-482.el7.x86_64
Libvirt-2.0.0-4.el7.x86_64
qemu-kvm-rhev-2.6.0-18.el7.x86_64

Setup:
1. Prepare an image with the format of ‘raw’
 # qemu-img create /var/lib/libvirt/images/volds 5G


2. Refresh the list of volumes contained in default
# virsh pool-refresh default

3. Given the information about the new volume with qemu-img
# qemu-img info /var/lib/libvirt/images/volds
image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 0

4.Try to resize the capacity of the new volume, keep in mind that allocated disk size now is zero
#virsh vol-resize /var/lib/libvirt/images/volds 3G --allocate
error: Failed to change size of volume 'volds' to 3G
error: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified

5. Try to resize the volume capacity, with shrink flag, it will work successfully, but
the total virtual size will not change
# virsh vol-resize /var/lib/libvirt/images/volds 3G --allocate --shrink
Size of volume 'volds' successfully changed to 3G


Actual results:
# qemu-img info /var/lib/libvirt/images/volds

image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 3.0G



Expected results:
According to the manual: “The *new* capacity might be sparse unless --allocate is specified.”
There is no point to use --allocate when there is no new capacity. And the --allocate might wipe the existing data on the disk. 



Additional info:
 If I want to allocate the capacity, there is no necessity to using the shrink flag
# virsh vol-resize /var/lib/libvirt/images/volds 4G --allocate
Size of volume 'volds' successfully changed to 4G
# qemu-img info /var/lib/libvirt/images/volds
image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 4.0G

2. After I confronted with this problem, vol-resize with shrink and delta flag also could also not work properly.
 # virsh vol-resize /var/lib/libvirt/images/volds --shrink --delta 500M
error: Failed to change size of volume 'volds' by 500M
error: invalid argument: can't shrink capacity below existing allocation

And also:
# virsh vol-resize /var/lib/libvirt/images/volds -0G --shrink --delta
Size of volume 'volds' successfully changed by 0G
# qemu-img info /var/lib/libvirt/images/volds
image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 4.0G (4294967296 bytes)
disk size: 4.0G


Best Regards,
Lili Zhu

Comment 1 Lili Zhu 2016-08-12 05:59:29 UTC
For the additional info part:
 If I want to allocate the capacity, there is no necessity to using the shrink flag
# virsh vol-resize /var/lib/libvirt/images/volds 4G --allocate
Size of volume 'volds' successfully changed to 4G
# qemu-img info /var/lib/libvirt/images/volds
image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 4.0G

What I mean actually is When I execute the above step 5 “successfully“, then I continue to execute the following command. there is no necessity to using the shrink flag at this time, and it will give the the following results

# virsh vol-resize /var/lib/libvirt/images/volds 4G --allocate
Size of volume 'volds' successfully changed to 4G
# qemu-img info /var/lib/libvirt/images/volds
image: /var/lib/libvirt/images/volds
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 4.0G

Comment 2 Ján Tomko 2017-09-25 15:49:36 UTC
If we treat the RESIZE_ALLOCATE flag as "Make sure that the added difference" is allocated, then mixing it with RESIZE_SHRINK does not make sense.

However we try to treat RESIZE_ALLOCATE as "make sure that the whole new size is allocated" and in that case shrinking should work too.

Upstream series to fix the allocation behavior:
https://www.redhat.com/archives/libvir-list/2017-September/msg00875.html

Comment 3 Ján Tomko 2017-09-27 12:50:06 UTC
Pushed upstream as:
commit 959fe7de1f0f6fadb86e853edead6d32c3cb3559
Author:     Ján Tomko <jtomko>
CommitDate: 2017-09-27 14:40:44 +0200

    Shrink volume even with ALLOCATE flag
    
    Calling fallocate on the new (smaller) capacity ensures
    that the whole file is allocated, but it does not reduce
    the file size.
    
    Also call ftruncate after fallocate.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1366446

git describe: v3.7.0-183-g959fe7de1

Comment 5 yisun 2017-10-30 09:55:17 UTC
test with libvirt-3.8.0-1.virtcov.el7.x86_64

According to comment 3, now the behaviour should be like:
when do --allocate and --shrink together, file will be allocated (by fallocate) and shrunk (by ftruncate).

And the test result satisfies the expectation:
1. prepare a 5G sparse file
## qemu-img create -f raw /var/lib/libvirt/images/5G.raw 5g
Formatting '/var/lib/libvirt/images/5G.raw', fmt=raw size=5368709120

## virsh pool-refresh default
Pool default refreshed

## qemu-img info /var/lib/libvirt/images/5G.raw
image: /var/lib/libvirt/images/5G.raw
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 0

2. resize the image to 3.0 with --allocate (without --shrink)
## virsh vol-resize /var/lib/libvirt/images/5G.raw 3G --allocate
error: Failed to change size of volume '5G.raw' to 3G
error: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified
<== failed as expected

## qemu-img info /var/lib/libvirt/images/5G.raw
image: /var/lib/libvirt/images/5G.raw
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 0
<== not changed

2. resize the image to 3.0 with --allocate  and --shrink
## virsh vol-resize /var/lib/libvirt/images/5G.raw 3G --allocate --shrink
Size of volume '5G.raw' successfully changed to 3G

## qemu-img info /var/lib/libvirt/images/5G.raw
image: /var/lib/libvirt/images/5G.raw
file format: raw
virtual size: 3.0G (3221225472 bytes)
disk size: 3.0G
<== both 'virtual size' and 'disk size' change to 3G as expected

Comment 9 errata-xmlrpc 2018-04-10 10:36:45 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/RHEA-2018:0704


Note You need to log in before you can comment on or make changes to this bug.