I'm using KVM to live migrate VMs from one host to another. I have already written a web ui to do that. Now I want to implement a progress bar.
My idea is to compare the file size of the disk on the source and on the target while it's migrating.
Server1:
ls -ls /data/file.raw 858963 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw Server2:
ls -ls /data/file.raw 698543 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw Now, I took the allocated value and calculated it in percent.
100 / 858963 * 698543 = 81%
Fine. but there is one problem:
The disk is not sparse. The total size of the file is 1717926 blocks. Actually, there are only 858963 blocks allocated. So the live migration is still copying the empty parts of the file while my progress bar is already at 100%
I already tried around with du and stat.
How to get only the transferred file size of the disk?
du -h /data/file.raw(real disk use) anddu -h --apparent-size /data/file.raw. What do you use (with all args) to transfer the file?virsh migrate --verbose --live --copy-storage-all $VM_NAME qemu+ssh://$TARGET/systemAccording to the docs, it is using rsync.du -hreturns858Manddu -h --apparent-sizereturns6.0G