From dd2bd851caa7d659731513187f5abd6deee3ee91 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Wed, 9 Jul 2025 18:21:46 +0200 Subject: [PATCH] plugin: add qemu_img_create Signed-off-by: Alexandre Derumier --- src/PVE/Storage/Plugin.pm | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index c2f376b..65a34b1 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -631,6 +631,29 @@ sub preallocation_cmd_option { return; } +=pod + +=head3 qemu_img_create + + qemu_img_create($scfg, $fmt, $size, $path) + +Create a new qemu image with a specific format C<$format> and size C<$size> for a target C<$path>. + +=cut + +sub qemu_img_create { + my ($scfg, $fmt, $size, $path) = @_; + + my $cmd = ['/usr/bin/qemu-img', 'create']; + + my $prealloc_opt = preallocation_cmd_option($scfg, $fmt); + push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt); + + push @$cmd, '-f', $fmt, $path, "${size}K"; + + run_command($cmd, errmsg => "unable to create image"); +} + # Storage implementation # called during addition of storage (before the new storage config got written) @@ -969,14 +992,7 @@ sub alloc_image { umask $old_umask; die $err if $err; } else { - my $cmd = ['/usr/bin/qemu-img', 'create']; - - my $prealloc_opt = preallocation_cmd_option($scfg, $fmt); - push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt); - - push @$cmd, '-f', $fmt, $path, "${size}K"; - - eval { run_command($cmd, errmsg => "unable to create image"); }; + eval { qemu_img_create($scfg, $fmt, $size, $path) }; if ($@) { unlink $path; rmdir $imagedir;