]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: migration: Fix blockdev config with VIR_MIGRATE_PARAM_MIGRATE_DISKS_DETECT_ZEROES
authorPeter Krempa <pkrempa@redhat.com>
Fri, 11 Oct 2024 16:31:28 +0000 (18:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 14 Oct 2024 14:25:21 +0000 (16:25 +0200)
The idea of migration with VIR_MIGRATE_PARAM_MIGRATE_DISKS_DETECT_ZEROES
populated is to sparsify the image. The QEMU NBD client as it was
configured in commit 621f879adf98e2c93ac5c8c869733a57f06cd9aa would
signal to the destination to do thick allocation of holes which would
result in a non-sparse image for any backend except a qcow2 image which
I used to test it.

Switch to VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP and
VIR_DOMAIN_DISK_DISCARD_UNMAP which tells the NBD client (and that in
turn the NBD server) to preserve the sparse blocks it detected from the
image.

Fixes: 621f879adf98e2c93ac5c8c869733a57f06cd9aa
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_migration.c

index 179e9d7c83f225938bc073d7154e6e3845494d06..832b2946e0d5d68e57d5d014cc5fe6d1591317ef 100644 (file)
@@ -1092,8 +1092,14 @@ qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(virDomainDiskDef *disk,
     copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
     copysrc->format = VIR_STORAGE_FILE_RAW;
 
-    if (detect_zeroes)
-        copysrc->detect_zeroes = VIR_DOMAIN_DISK_DETECT_ZEROES_ON;
+    if (detect_zeroes) {
+        /* We need to use both VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP and
+         * VIR_DOMAIN_DISK_DISCARD_UNMAP as the qemu NBD client otherwise singals
+         * to the server to fully allocate the zero blocks
+         */
+        copysrc->detect_zeroes = VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP;
+        copysrc->discard = VIR_DOMAIN_DISK_DISCARD_UNMAP;
+    }
 
     copysrc->backingStore = virStorageSourceNew();