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.
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 (new packages: qemu-kvm), 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-2022:2307
Description of problem: The target image size is incorrect when converting a badly fragmented file. The target image size isn't 0 when the source image that is fully allocated with zero bytes. According to Kevin's feedback, qemu-img convert should detect the zeroes and keep the target image sparse. Version-Release number of selected component (if applicable): kernel-4.18.0-234.el8.x86_64 qemu-kvm-5.1.0-9.module+el8.3.0+8182+ac9ced32 How reproducible: 5/5 Steps to Reproduce: (Tested it on XFS file system) 1. create an image, size=10G # qemu-img create -f raw -o extent_size_hint=1M test.raw 10G 2. Create the badly fragmented file with qemu-img bench. Don't specify --pattern, write zero bytes. # qemu-img bench -f raw -t none -n -w test.raw -c 1000000 -S 8192 -o 0 Sending 1000000 write requests, 4096 bytes each, 64 in parallel (starting at offset 0, step size 8192) Run completed in 26.615 seconds. # qemu-img bench -f raw -t none -n -w test.raw -c 1000000 -S 8192 -o 4096 Sending 1000000 write requests, 4096 bytes each, 64 in parallel (starting at offset 4096, step size 8192) Run completed in 21.748 seconds. 3. check file fragmentation # filefrag test.raw test.raw: 7380 extents found 4. convert test.raw to convert.raw # qemu-img convert -p -f raw -O raw -T none -t none test.raw convert.raw 5. convert test.raw to convert.qcow2 # qemu-img convert -p -f raw -O qcow2 -T none -t none test.raw convert.qcow2 6. check image size # qemu-img info test.raw image: test.raw file format: raw virtual size: 10 GiB (10737418240 bytes) disk size: 7.63 GiB # qemu-img info convert.raw image: convert.raw file format: raw virtual size: 10 GiB (10737418240 bytes) disk size: 2.82 GiB # qemu-img info convert.qcow2 image: convert.qcow2 file format: qcow2 virtual size: 10 GiB (10737418240 bytes) disk size: 182 MiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false Actual results: After step 6, the target image size isn't 0 Expected results: Since the source image that is fully allocated with zero bytes, the target image size should be 0. Additional info: 1. write the badly fragmented file with --pattern=1, the size is as expected. Details: (1)# qemu-img create -f raw -o extent_size_hint=1M test.raw 10G (2)# qemu-img bench -f raw -t none -n -w test.raw -c 1000000 -S 8192 -o 0 --pattern=1 # qemu-img bench -f raw -t none -n -w test.raw -c 1000000 -S 8192 -o 4096 --pattern=1 (3)# filefrag test.raw test.raw: 7408 extents found (4)# qemu-img convert -p -f raw -O raw -T none -t none test.raw convert.raw (5)# qemu-img convert -p -f raw -O qcow2 -T none -t none test.raw convert.qcow2 (6)# qemu-img info test.raw image: test.raw file format: raw virtual size: 10 GiB (10737418240 bytes) disk size: 7.63 GiB # qemu-img info convert.raw image: convert.raw file format: raw virtual size: 10 GiB (10737418240 bytes) disk size: 7.63 GiB # qemu-img info convert.qcow2 image: convert.qcow2 file format: qcow2 virtual size: 10 GiB (10737418240 bytes) disk size: 7.63 GiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false 2. Tested on a unfragmented file, all work well. 2.1 Tested with -P0: # qemu-img create -f raw base.raw 1G # qemu-io -c 'write -P0 0 200M' base.raw -f raw wrote 209715200/209715200 bytes at offset 0 200 MiB, 1 ops; 00.13 sec (1.451 GiB/sec and 7.4285 ops/sec) # qemu-img convert -p -f raw -O raw -T none -t none base.raw base_convert.raw (100.00/100%) # qemu-img convert -p -f raw -O qcow2 -T none -t none base.raw base_convert.qcow2 (100.00/100%) # qemu-img info base.raw image: base.raw file format: raw virtual size: 1 GiB (1073741824 bytes) disk size: 200 MiB # qemu-img info base_convert.raw image: base_convert.raw file format: raw virtual size: 1 GiB (1073741824 bytes) disk size: 1 MiB # qemu-img info base_convert.qcow2 image: base_convert.qcow2 file format: qcow2 virtual size: 1 GiB (1073741824 bytes) disk size: 196 KiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false 2.2 Tested with -P1 # qemu-img create -f raw base.raw 1G # qemu-io -c 'write -P1 0 200M' base.raw -f raw # qemu-img convert -p -f raw -O raw -T none -t none base.raw base_convert.raw # qemu-img convert -p -f raw -O qcow2 -T none -t none base.raw base_convert.qcow2 # qemu-img info base.raw image: base.raw file format: raw virtual size: 1 GiB (1073741824 bytes) disk size: 200 MiB # qemu-img info base_convert.raw image: base_convert.raw file format: raw virtual size: 1 GiB (1073741824 bytes) disk size: 200 MiB # qemu-img info base_convert.qcow2 image: base_convert.qcow2 file format: qcow2 virtual size: 1 GiB (1073741824 bytes) disk size: 200 MiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false