[PATCH qemu-server 6/6] clone: allocate && shrink lvmcow2 underlay

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Mon Aug 26 13:00:30 CEST 2024


We allocated the full size for underlay, as we can't easily known what
is the used size of the source.
(we could use qemu-img measure, but for some storage like nfs, it need full read
 to detected sparsiness for example).

Then, after the copy, we use qemu-img measure to detect the exact used size,
and we shrink the underlay

Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 PVE/QemuServer.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a6a40cd..7a9641a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -8274,7 +8274,7 @@ sub clone_disk {
 	    $size = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 10);
 	}
 	$newvolid = PVE::Storage::vdisk_alloc(
-	    $storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024)
+	    $storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024), ($size/1024)
 	);
 	push @$newvollist, $newvolid;
 
@@ -8321,6 +8321,7 @@ sub clone_disk {
 	    }
 	}
     }
+    PVE::Storage::volume_underlay_shrink($storecfg, $newvolid);
 
 no_data_clone:
     my $size = eval { PVE::Storage::volume_size_info($storecfg, $newvolid, 10) };
-- 
2.39.2




More information about the pve-devel mailing list