device: 0.969 graphic: 0.949 virtual: 0.918 performance: 0.879 files: 0.869 architecture: 0.829 hypervisor: 0.819 debug: 0.816 PID: 0.792 KVM: 0.756 ppc: 0.736 x86: 0.732 kernel: 0.725 i386: 0.725 boot: 0.690 semantic: 0.669 risc-v: 0.659 network: 0.658 arm: 0.657 peripherals: 0.656 vnc: 0.651 permissions: 0.648 VMM: 0.645 mistranslation: 0.645 register: 0.636 socket: 0.617 TCG: 0.611 user-level: 0.589 assembly: 0.505 qcow2: disk size exceeds virtual size Description of problem: Disk size of qcow2 image file exceeds its virtual size after repeatedly writing, and deleting data in qemu vm. Steps to reproduce: 1. qemu-img create -f qcow2 tmp.qcow2 32M 2. attach tmp.qcow2 as a device to qemu vm 3. mount the device in qemu vm, and repeatedly writing, and deleting data Additional information: xml for attaching tmp.qcow2 ```xml ``` in fact, set discard="unmap" or not seems has `little impact` on the final result. reproducible shell script. ```sh #! /bin/sh for i in {1..1000}; do for j in {1..27}; do dd if=/dev/zero of=/mnt/test-$j bs=1M count=1 & done sync sleep 10 rm -f /mnt/test-* fstrim /mnt done ``` MOUNT the device and run this script, problem happens about 30 minutes. final result looks like: ```sh # qemu-img info tmp.qcow2 --force image: tmp.qcow2 file format: qcow2 virtual size: 32 MiB (33554432 bytes) disk size: 33 MiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false extended l2: false Child node '/file': filename: tmp.qcow2 protocol type: file file length: 32.3 MiB (33882112 bytes) disk size: 33 MiB Format specific information: extent size hint: 1048576 ```