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 1613746 - vol-resize with --shrink can't shrink encrypted volume
Summary: vol-resize with --shrink can't shrink encrypted volume
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.6
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: John Ferlan
QA Contact: Meina Li
URL:
Whiteboard:
Depends On:
Blocks: 1622534
TreeView+ depends on / blocked
 
Reported: 2018-08-08 09:34 UTC by Meina Li
Modified: 2018-10-30 09:59 UTC (History)
8 users (show)

Fixed In Version: libvirt-4.5.0-8.el7
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
: 1622534 (view as bug list)
Environment:
Last Closed: 2018-10-30 09:58:28 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2018:3113 0 None None None 2018-10-30 09:59:31 UTC

Description Meina Li 2018-08-08 09:34:12 UTC
Description of problem:
vol-resize with --shrink doesn't shrink encrypted volume

Version-Release number of selected component (if applicable):
libvirt-4.5.0-6.el7.x86_64
qemu-kvm-rhev-2.12.0-9.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Prepare an encrypted volume encrypt1.img.

# virsh secret-list 
 UUID                                  Usage
--------------------------------------------------------------------------------
 33406385-1633-425a-a7e8-a02243603283  volume 

# qemu-img info /var/lib/libvirt/images/encrypt1.img 
image: /var/lib/libvirt/images/encrypt1.img
file format: luks
virtual size: 200M (209715200 bytes)
disk size: 256K
encrypted: yes
Format specific information:
    ivgen alg: plain64
    hash alg: sha256
    cipher alg: aes-256
    uuid: daa9aeff-8230-4e76-ba0b-660c2a0f172f
...

2. Resize the encrypted volume.
# virsh vol-resize /var/lib/libvirt/images/encrypt1.img 100M --shrink
error: Failed to change size of volume 'encrypt1.img' to 100M
error: internal error: Child process (/usr/bin/qemu-img resize --object secret,id=encrypt1.img_encrypt0,file=/var/run/libvirt/storage/default.encrypt1.img.secret.AoZ4XV --image-opts driver=luks,key-secret=encrypt1.img_encrypt0,file.filename=/var/lib/libvirt/images/encrypt1.img 104857600) unexpected exit status 1: 2018-08-08 09:15:46.693+0000: 8719: debug : virFileClose:111 : Closed fd 25
2018-08-08 09:15:46.693+0000: 8719: debug : virFileClose:111 : Closed fd 27
2018-08-08 09:15:46.693+0000: 8719: debug : virFileClose:111 : Closed fd 22
qemu-img: warning: Shrinking an image will delete all data beyond the shrunken image's end. Before performing such an operation, make sure there is no important data there.
qemu-img: Use the --shrink option to perform a shrink operation.

Actual results:
vol-resize with --shrink doesn't shrink encrypted volume

Expected results:
# virsh vol-resize /var/lib/libvirt/images/encrypt1.img 100M --shrink
Size of volume 'encrypt1.img' successfully changed to 100M

Additional info:
Resize luks encrypted volume in libvirt-3.9.0-14.el7_5.7.x86_64 successfully.

Comment 4 John Ferlan 2018-08-17 20:02:17 UTC
Posted a patch upstream:

https://www.redhat.com/archives/libvir-list/2018-August/msg01135.html

Testing:

# virsh vol-info demo.luks default
Name:           demo.luks
Type:           file
Capacity:       100.00 MiB
Allocation:     256.00 KiB

# virsh vol-dumpxml demo.luks default
<volume type='file'>
  <name>demo.luks</name>
  <key>/home/vm-images/demo.luks</key>
...
    <encryption format='luks'>
      <secret type='passphrase' uuid='6fd3f62d-9fe7-4a4d-a869-7acd6376d8ea'/>
    </encryption>
  </target>
</volume>

# virsh vol-info bzvol.qcow2 default
Name:           bzvol.qcow2
Type:           file
Capacity:       100.00 MiB
Allocation:     260.00 KiB

# virsh vol-dumpxml bzvol.qcow2 default
<volume type='file'>
  <name>bzvol.qcow2</name>
  <key>/home/vm-images/bzvol.qcow2</key>
...
  <target>
...
    <format type='qcow2'/>
...


# virsh vol-resize demo.luks 50M default --shrink
Size of volume 'demo.luks' successfully changed to 50M

# virsh vol-resize demo.luks 100M default
Size of volume 'demo.luks' successfully changed to 100M

# virsh vol-resize bzvol.qcow2 50M default --shrink
Size of volume 'bzvol.qcow2' successfully changed to 50M

# virsh vol-resize bzvol.qcow2 100M default
Size of volume 'bzvol.qcow2' successfully changed to 100M

Comment 5 John Ferlan 2018-08-24 13:16:47 UTC
Patch pushed upstream:

commit b04d1b6a35f9fb826f7bb83fdac364a127ec75ca
Author: John Ferlan <jferlan>
Date:   Fri Aug 17 15:53:29 2018 -0400

    storage: Add --shrink to qemu-img command when shrinking vol
    
    ...
    
    When shrinking the capacity of a qcow2 or luks volume using
    the qemu-img program, the --shrink qualifier must be added.
    
    Signed-off-by: John Ferlan <jferlan>
    Reviewed-by: Daniel P. Berrangé <berrange>

...

$ git describe b04d1b6a35f9fb826f7bb83fdac364a127ec75ca
v4.6.0-304-gb04d1b6a35
$

Comment 10 Meina Li 2018-09-07 06:18:15 UTC
Verified on libvirt-4.5.0-9.el7.x86_64.

Test steps:
1.Prepare an encrypted volume and a qcow2 volume.
# virsh vol-dumpxml encrypt.luks default
<volume type='file'>
  <name>encrypt.luks</name>
  <key>/var/lib/libvirt/images/encrypt.luks</key>
  ...
  <target>
    <path>/var/lib/libvirt/images/encrypt.luks</path>
    ...
    <encryption format='luks'>
      <secret type='passphrase' uuid='4d55f845-32f6-49e0-b5c8-f062f89955d4'/>
    </encryption>
  </target>
</volume>

# virsh vol-list default
 name               path
------------------------------------------------------------------------------
 encrypt.luks         /var/lib/libvirt/images/encrypt.luks
 lmn.qcow2            /var/lib/libvirt/images/lmn.qcow2
 noencrypt.qcow2      /var/lib/libvirt/images/noencrypt.qcow2

2. Check the capability of two volumes.
# virsh vol-info encrypt.luks default
Name:       encrypt.luks
Type:       file
Capability:       500.00 MiB
Allocation:       256.00 KiB
# virsh vol-info noencrypt.qcow2 default
Name:       noencrypt.qcow2
Type:       file
Capability:       500.00 MiB
Allocation:       196.00 KiB

3. Resize the two volumes.
# virsh vol-resize /var/lib/libvirt/images/encrypt.luks 300M --shrink
Size of volume 'encrypt.luks' successfully changed to 300M
# virsh vol-info encrypt.luks default
Name:       encrypt.luks
Type:       file
Capability:       300.00 MiB
Allocation:       256.00 KiB

# virsh vol-resize noencrypt.qcow2 300M default --shrink
Size of volume noencrypt.qcow2 successfully changed to 300M
# virsh vol-info noencrypt.qcow2 default
Name:       noencrypt.qcow2
Type:       file
Capability:       300.00 MiB
Allocation:       260.00 KiB

Comment 12 errata-xmlrpc 2018-10-30 09:58: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.

https://access.redhat.com/errata/RHSA-2018:3113


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