[pve-devel] [PATCH v2 storage] Align size to 512 before calling 'qemu-img resize'

Fabian Ebner f.ebner at proxmox.com
Mon Jan 13 11:47:45 CET 2020


since for qcow2, qemu-img expects a multiple of 512 and
for raw it aligns to 512 with a warning, which we avoid

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/Storage/Plugin.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 0c39cbd..7382140 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -747,6 +747,11 @@ sub volume_resize {
 
     my $format = ($class->parse_volname($volname))[6];
 
+    # for qcow2 images 'qemu-img resize' requires that the size
+    # is aligned to 512 and for raw images we avoid a warning
+    my $padding = (512 - $size % 512) % 512;
+    $size = $size + $padding;
+
     my $cmd = ['/usr/bin/qemu-img', 'resize', '-f', $format, $path , $size];
 
     run_command($cmd, timeout => 10);
-- 
2.20.1





More information about the pve-devel mailing list