Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 1675743

Summary: virt-clone does not honor '--nonsparse' argument
Product: Red Hat Enterprise Linux 7 Reporter: amashah
Component: virt-managerAssignee: Cole Robinson <crobinso>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.6CC: amashah, crobinso, dyuan, juzhou, mxie, phrdina, tzheng, xiaodwan, zili
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: virt-manager-1.5.0-5.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 13:08:01 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:
Attachments:
Description Flags
virt-clone debug log in virt-manager-1.5.0-4.el7.noarch none

Description amashah 2019-02-11 21:35:09 UTC
Description of problem:

virt-clone does not honor '--nonsparse' argument. If passed, the new disk should be thick provisioned, but is instead sparse.

Version-Release number of selected component (if applicable):
virt-install-1.5.0-1

How reproducible:
100%

Steps to Reproduce:
1. virt-clone --connect qemu:///system --original originalVM --name newVM --nonsparse --file /VM/newdisk --debug

2. # ls -lh /VM/newdisk
  -rw-------. 1 root root 28G Feb  8 21:53 /VM/newdisk

3. # qemu-img info /VM/newdisk
image: /VM/newdisk
file format: qcow2
virtual size: 100G (107374182400 bytes)
disk size: 28G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true

Actual results:
Disk is thin provisioned, file size 28G rather than 100G

Expected results:
Disk should be preallocated, file size 100G

Additional info:

Comment 5 Cole Robinson 2019-03-04 19:06:14 UTC
Thanks for the report, I've fixed it upstream now:

commit 4f66c423f7833e270b61536d53a0772ce1242abc
Author: Cole Robinson <crobinso>
Date:   Mon Mar 4 13:20:51 2019 -0500

    cloner: Handle --nonsparse for qcow2 images (bz 1675743)

Comment 9 zhoujunqin 2019-05-13 07:54:59 UTC
Created attachment 1567812 [details]
virt-clone debug log in virt-manager-1.5.0-4.el7.noarch

Comment 10 zhoujunqin 2019-05-13 07:55:56 UTC
I can reproduce this bug with build:
virt-manager-1.5.0-3.el7

Steps:
1. Prepare a health qcow2 disk format vm.
# qemu-img info /var/lib/libvirt/images/rhel7.7-2.qcow2
image: /var/lib/libvirt/images/rhel7.7-2.qcow2
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 1.5G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

2. Clone the original to a new vm with option "--nonsparse"

# virt-clone -o rhel7.7-1675743 -n rhel7.7-1675743-old --nonsparse --file /tmp/rhel7.7-1675743-old
Allocating 'rhel7.7-1675743-old'                                                                                                                                           | 9.0 GB  00:00:24     

Clone 'rhel7.7-1675743-old' created successfully.

3. Check the disk info of newly clone vm.

# qemu-img info /tmp/rhel7.7-1675743-old 
image: /tmp/rhel7.7-1675743-old
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Result: Newly cloned disk is not preallocated.

Then try to verify this bug with build:
virt-manager-1.5.0-4.el7.noarch

Steps:
1. Clone the original to a new vm with option "--nonsparse"

# virt-clone -o rhel7.7-1675743 -n rhel7.7-1675743-new --nonsparse --file /tmp/rhel7.7-1675743-new
Allocating 'rhel7.7-1675743-new'                                                                                                                                           | 9.0 GB  00:00:30     

Clone 'rhel7.7-1675743-new' created successfully.

2. Check the disk info of newly clone vm.

# qemu-img info /tmp/rhel7.7-1675743-new 
image: /tmp/rhel7.7-1675743-new
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 1.9G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Result: The newly disk is also not preallocated, please help me have a look, thanks.

Comment 11 Cole Robinson 2019-05-13 13:47:13 UTC
Whoops I confused myself with this patch and my testing, the --nonsparse check is inverted. So you will see preallocation when --nonsparse is _not_ specified. Thanks for catching it, I'll fix it

Comment 15 zhoujunqin 2019-05-16 08:45:13 UTC
Verify this bug with new build:
virt-manager-1.5.0-5.el7.noarch
libvirt-4.5.0-17.el7.x86_64
virt-install-1.5.0-5.el7.noarch
qemu-kvm-rhev-2.12.0-28.el7.x86_64

Steps:
1. Prepare a healthy vm which disk format is "qcow2".
# virsh dumpxml testvm
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/testvm'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>

# qemu-img info /var/lib/libvirt/images/testvm
image: /var/lib/libvirt/images/testvm
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 4.4G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

2. Clone the original to a new vm.
Scenario-1 with '--nonsparse' argument
2.1.1
# virt-clone  -o testvm -n testvm-with-nonsparse --nonsparse --file /tmp/testvm-with-nonsparse
Allocating 'testvm-with-nonsparse'                                                                                                                                                          | 9.0 GB  00:01:58     

Clone 'testvm-with-nonsparse' created successfully.

2.1.2 Check the disk info of newly clone vm.

# qemu-img info /tmp/testvm-with-nonsparse
image: /tmp/testvm-with-nonsparse
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 9.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Result: The newly disk is preallocated when "--nonsparse" is specified. it's as expected. 

Scenario-2 without '--nonsparse' argument
2.2.1 
# virt-clone  -o testvm -n testvm-without --file /tmp/testvm-without
Allocating 'testvm-without'                                                                                                                                                                 | 9.0 GB  00:01:44     

Clone 'testvm-without' created successfully.

2.2.2 Check the disk info of newly clone vm.

# qemu-img info /tmp/testvm-without 
image: /tmp/testvm-without
file format: qcow2
virtual size: 9.0G (9663676416 bytes)
disk size: 4.3G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Result: The newly disk is not preallocated when "--nonsparse" is not specified. it's also as expected. 

So I move this bug from ON_QA to VERIFIED, thanks.

Comment 19 errata-xmlrpc 2019-08-06 13:08:01 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-2019:2232