[PATCH pve-storage 05/13] plugin: add qemu_img_resize
Alexandre Derumier
alexandre.derumier at groupe-cyllene.com
Wed Jul 9 18:21:54 CEST 2025
and add missing preallocation
https://github.com/qemu/qemu/commit/dc5f690b97ccdffa79fe7169bb26b0ebf06688bf
Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
src/PVE/Storage/Plugin.pm | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index b7c9524..ed310a2 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -733,6 +733,30 @@ sub qemu_img_measure {
return PVE::Storage::Common::run_qemu_img_json($cmd, $timeout);
}
+=pod
+
+=head3 qemu_img_resize
+
+ qemu_img_resize($scfg, $path, $format, $size, $timeout)
+
+Resize a qemu image C<$path> with format C<$format> to a target Kb size C<$size>.
+Default timeout C<$timeout> is 10s if not specified.
+=cut
+
+sub qemu_img_resize {
+ my ($scfg, $path, $format, $size, $timeout) = @_;
+
+ die "format is missing" if !$format;
+
+ my $prealloc_opt = preallocation_cmd_option($scfg, $format);
+ my $cmd = ['/usr/bin/qemu-img', 'resize'];
+ push $cmd->@*, "--$prealloc_opt" if $prealloc_opt;
+ push $cmd->@*, '-f', $format, $path, $size;
+
+ $timeout = 10 if !$timeout;
+ run_command($cmd, timeout => $timeout);
+}
+
# Storage implementation
# called during addition of storage (before the new storage config got written)
@@ -1284,9 +1308,7 @@ sub volume_resize {
my $format = ($class->parse_volname($volname))[6];
- my $cmd = ['/usr/bin/qemu-img', 'resize', '-f', $format, $path, $size];
-
- run_command($cmd, timeout => 10);
+ qemu_img_resize($scfg, $path, $format, $size, 10);
return undef;
}
--
2.39.5
More information about the pve-devel
mailing list