[PATCH pve-storage 01/13] plugin: add qemu_img_create
Alexandre Derumier
alexandre.derumier at groupe-cyllene.com
Wed Jul 9 18:21:46 CEST 2025
Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
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;
--
2.39.5
More information about the pve-devel
mailing list