[libvirt-users] after snapshot-delete, the qcow2 image file size doesn't decrease

After snapshot-delete, the qcow2 image file size doesn't decrease, isn't that a waste of disk space? Would someone please tell me how to decrease the file size when snapshot-delete, if that's possible? The image file name of my virtual machine is d0.qcow As follows: [root@test1 ]# virsh list Id Name State ---------------------------------------------------- 32 bfbe8ca8-8579-11e2-844a-001018951f48 running [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 3.6G cluster_size: 65536 [root@test1 ]# ls -lh total 3.6G -rw------- 1 qemu qemu 3.6G Apr 12 17:13 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-list bfbe8ca8-8579-11e2-844a-001018951f48 Name Creation Time State ------------------------------------------------------------ [root@test1 8]# virsh snapshot-create bfbe8ca8-8579-11e2-844a-001018951f48 Domain snapshot 1365758005 created [root@test1 ]# virsh snapshot-create bfbe8ca8-8579-11e2-844a-001018951f48 Domain snapshot 1365758022 created [root@test1 bfbe8ca8-8579-11e2-844a-001018951f48]# virsh snapshot-list bfbe8ca8-8579-11e2-844a-001018951f48 Name Creation Time State ------------------------------------------------------------ 1365758005 2013-04-12 17:13:25 +0800 running 1365758022 2013-04-12 17:13:42 +0800 running [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 3.8G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1365758005 127M 2013-04-12 17:13:25 00:00:53.141 2 1365758022 127M 2013-04-12 17:13:42 00:01:09.508 [root@test1 ]# ls -lh total 3.9G -rw------- 1 qemu qemu 3.9G Apr 12 17:14 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-delete bfbe8ca8-8579-11e2-844a-001018951f48 1365758022 Domain snapshot 1365758022 deleted [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 3.8G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 0 1970-01-01 08:00:00 00:00:00.000 [root@test1 ]# ls -lh total 3.9G -rw------- 1 qemu qemu 3.9G Apr 12 17:14 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-delete bfbe8ca8-8579-11e2-844a-001018951f48 1365758005 Domain snapshot 1365758005 deleted [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 3.8G cluster_size: 65536 [root@test1 ]# ls -lh total 3.9G -rw------- 1 qemu qemu 3.9G Apr 12 17:14 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-create bfbe8ca8-8579-11e2-844a-001018951f48 Domain snapshot 1365758311 created [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 3.8G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1365758311 252M 2013-04-12 17:18:32 00:05:58.136 [root@test1 ]# ls -lh total 3.9G -rw------- 1 qemu qemu 3.9G Apr 12 17:18 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-create bfbe8ca8-8579-11e2-844a-001018951f48 Domain snapshot 1365758338 created [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 4.1G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1365758311 252M 2013-04-12 17:18:32 00:05:58.136 2 1365758338 252M 2013-04-12 17:18:58 00:06:24.272 [root@test1 ]# ls -lh total 4.1G -rw------- 1 qemu qemu 4.1G Apr 12 17:19 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-list bfbe8ca8-8579-11e2-844a-001018951f48 Name Creation Time State ------------------------------------------------------------ 1365758311 2013-04-12 17:18:31 +0800 running 1365758338 2013-04-12 17:18:58 +0800 running [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 4.1G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1365758311 252M 2013-04-12 17:18:32 00:05:58.136 2 1365758338 252M 2013-04-12 17:18:58 00:06:24.272 [root@test1 ]# virsh snapshot-delete bfbe8ca8-8579-11e2-844a-001018951f48 1365758338 Domain snapshot 1365758338 deleted [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 4.1G cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1365758311 252M 2013-04-12 17:18:32 00:05:58.136 [root@test1 ]# ls -lh total 4.1G -rw------- 1 qemu qemu 4.1G Apr 12 17:20 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-delete bfbe8ca8-8579-11e2-844a-001018951f48 1365758311 Domain snapshot 1365758311 deleted [root@test1 ]# qemu-img info d0.qcow image: d0.qcow file format: qcow2 virtual size: 8.0G (8589934592 bytes) disk size: 4.1G cluster_size: 65536 [root@test1 ]# ls -lh total 4.1G -rw------- 1 qemu qemu 4.1G Apr 12 17:20 d0.qcow drwx------ 2 root root 4.0K Apr 12 17:12 held [root@test1 ]# virsh snapshot-list bfbe8ca8-8579-11e2-844a-001018951f48 Name Creation Time State ------------------------------------------------------------

On Fri, Apr 12, 2013 at 05:25:23PM +0800, me,apporc wrote:
After snapshot-delete, the qcow2 image file size doesn't decrease, isn't that a waste of disk space?
Yes, but that's life. When deleting an internal qcow2 snapshot, QEMU will just mark the clusters as unused, it won't return them to the underlying filesystem. These unused clusters will, however, be re-used if the qcow2 file needs to grow later.
Would someone please tell me how to decrease the file size when snapshot-delete, if that's possible?
You can't do it in place. The only option would be to use qemu-img to clone the qcow2 file to a new qcow2 file & delete the original. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 04/12/2013 03:53 AM, Daniel P. Berrange wrote:
On Fri, Apr 12, 2013 at 05:25:23PM +0800, me,apporc wrote:
After snapshot-delete, the qcow2 image file size doesn't decrease, isn't that a waste of disk space?
Yes, but that's life. When deleting an internal qcow2 snapshot, QEMU will just mark the clusters as unused, it won't return them to the underlying filesystem. These unused clusters will, however, be re-used if the qcow2 file needs to grow later.
Would someone please tell me how to decrease the file size when snapshot-delete, if that's possible?
You can't do it in place. The only option would be to use qemu-img to clone the qcow2 file to a new qcow2 file & delete the original.
Check out 'virt-sparsify' from libguestfs-tools, which is designed to help you minimize disk space (including this trick of copying from one qcow2 to another to reduce space occupied by now-unused clusters). Meanwhile, if you are really ambitious, write a patch to upstream qemu that can do a defrag pass on an existing qcow2 image, and expose it through both qemu-img (for manipulating offline disks) and a QMP monitor command (so that we can request an online defrag without any noticeable guest downtime). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
me,apporc