From: Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Subject: [pve-devel] [PATCH pve-storage 1/9] common: add qemu_img_create an preallocation_cmd_option
Date: Tue, 3 Jun 2025 09:55:38 +0200 [thread overview]
Message-ID: <mailman.194.1748937401.395.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
[-- Attachment #1: Type: message/rfc822, Size: 8325 bytes --]
From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-storage 1/9] common: add qemu_img_create an preallocation_cmd_option
Date: Tue, 3 Jun 2025 09:55:38 +0200
Message-ID: <20250603075558.627850-4-alexandre.derumier@groupe-cyllene.com>
Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
---
src/PVE/Storage/Common.pm | 72 ++++++++++++++++++++++++++++++
src/PVE/Storage/GlusterfsPlugin.pm | 2 +-
src/PVE/Storage/Plugin.pm | 47 +------------------
3 files changed, 74 insertions(+), 47 deletions(-)
diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm
index bd9c951..4e4ad30 100644
--- a/src/PVE/Storage/Common.pm
+++ b/src/PVE/Storage/Common.pm
@@ -5,12 +5,26 @@ use warnings;
use PVE::JSONSchema;
use PVE::Syscall;
+use PVE::Tools qw(run_command);
use constant {
FALLOC_FL_KEEP_SIZE => 0x01, # see linux/falloc.h
FALLOC_FL_PUNCH_HOLE => 0x02, # see linux/falloc.h
};
+my $QCOW2_PREALLOCATION = {
+ off => 1,
+ metadata => 1,
+ falloc => 1,
+ full => 1,
+};
+
+my $RAW_PREALLOCATION = {
+ off => 1,
+ falloc => 1,
+ full => 1,
+};
+
=pod
=head1 NAME
@@ -107,4 +121,62 @@ sub deallocate : prototype($$$) {
}
}
+=pod
+
+=head3 preallocation_cmd_option
+
+ preallocation_cmd_option($scfg, $fmt)
+
+Returns the qemu-img preallocation command line for a specific image format C<$format>.
+
+=cut
+
+sub preallocation_cmd_option {
+ my ($scfg, $fmt) = @_;
+
+ my $prealloc = $scfg->{preallocation};
+
+ if ($fmt eq 'qcow2') {
+ $prealloc = $prealloc // 'metadata';
+
+ die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
+ if !$QCOW2_PREALLOCATION->{$prealloc};
+
+ return "preallocation=$prealloc";
+ } elsif ($fmt eq 'raw') {
+ $prealloc = $prealloc // 'off';
+ $prealloc = 'off' if $prealloc eq 'metadata';
+
+ die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
+ if !$RAW_PREALLOCATION->{$prealloc};
+
+ return "preallocation=$prealloc";
+ }
+
+ 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");
+}
+
1;
diff --git a/src/PVE/Storage/GlusterfsPlugin.pm b/src/PVE/Storage/GlusterfsPlugin.pm
index 18493cb..b1a541d 100644
--- a/src/PVE/Storage/GlusterfsPlugin.pm
+++ b/src/PVE/Storage/GlusterfsPlugin.pm
@@ -265,7 +265,7 @@ sub alloc_image {
my $cmd = ['/usr/bin/qemu-img', 'create'];
- my $prealloc_opt = PVE::Storage::Plugin::preallocation_cmd_option($scfg, $fmt);
+ my $prealloc_opt = PVE::Storage::Common::preallocation_cmd_option($scfg, $fmt);
push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt);
push @$cmd, '-f', $fmt, $volumepath, "${size}K";
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index b59fc72..90627b2 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -47,19 +47,6 @@ our @SHARED_STORAGE = (
'pbs',
);
-our $QCOW2_PREALLOCATION = {
- off => 1,
- metadata => 1,
- falloc => 1,
- full => 1,
-};
-
-our $RAW_PREALLOCATION = {
- off => 1,
- falloc => 1,
- full => 1,
-};
-
our $MAX_VOLUMES_PER_GUEST = 1024;
cfs_register_file ('storage.cfg',
@@ -577,31 +564,6 @@ sub parse_config {
return $cfg;
}
-sub preallocation_cmd_option {
- my ($scfg, $fmt) = @_;
-
- my $prealloc = $scfg->{preallocation};
-
- if ($fmt eq 'qcow2') {
- $prealloc = $prealloc // 'metadata';
-
- die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
- if !$QCOW2_PREALLOCATION->{$prealloc};
-
- return "preallocation=$prealloc";
- } elsif ($fmt eq 'raw') {
- $prealloc = $prealloc // 'off';
- $prealloc = 'off' if $prealloc eq 'metadata';
-
- die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
- if !$RAW_PREALLOCATION->{$prealloc};
-
- return "preallocation=$prealloc";
- }
-
- return;
-}
-
# Storage implementation
# called during addition of storage (before the new storage config got written)
@@ -926,14 +888,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 { PVE::Storage::Common::qemu_img_create($scfg, $fmt, $size, $path) };
if ($@) {
unlink $path;
rmdir $imagedir;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-06-03 7:56 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
2025-06-03 7:55 ` [pve-devel] [PATCH pve-qemu 1/1] add fake 10.0 Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 01/13] blockdev: cmdline: add blockdev syntax support Alexandre Derumier via pve-devel
2025-06-05 13:23 ` Fiona Ebner
2025-06-05 14:17 ` Fabian Grünbichler
2025-06-05 14:39 ` DERUMIER, Alexandre via pve-devel
[not found] ` <ee4940c99e9866910405b492dad15c68718c49ea.camel@groupe-cyllene.com>
2025-06-06 7:50 ` Fiona Ebner
2025-06-06 8:27 ` Fabian Grünbichler
2025-06-06 9:54 ` DERUMIER, Alexandre via pve-devel
2025-06-06 8:50 ` Fiona Ebner
2025-06-06 9:42 ` DERUMIER, Alexandre via pve-devel
[not found] ` <0605a27428cfb920ffefc51abdfec050a0a6b535.camel@groupe-cyllene.com>
2025-06-06 10:57 ` DERUMIER, Alexandre via pve-devel
2025-06-10 14:03 ` Fiona Ebner
2025-06-11 6:37 ` DERUMIER, Alexandre via pve-devel
[not found] ` <405662415075c0248618833b512b58258f80e0f7.camel@groupe-cyllene.com>
2025-06-11 7:24 ` Fiona Ebner
2025-06-11 14:02 ` DERUMIER, Alexandre via pve-devel
[not found] ` <733f5eefb25b76a0794a84d4f93ada8d70aea7be.camel@groupe-cyllene.com>
2025-06-11 14:13 ` Fiona Ebner
2025-06-12 5:20 ` DERUMIER, Alexandre via pve-devel
2025-06-03 7:55 ` Alexandre Derumier via pve-devel [this message]
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 02/13] blockdev: add support for ovmf && efidisk Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 2/9] common: add qemu_img_create_qcow2_backed Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 03/13] blockdev: vm_devices_list : fix block-query Alexandre Derumier via pve-devel
2025-06-17 14:44 ` Fiona Ebner
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 3/9] common: add qemu_img_info helper Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 04/13] blockdev: add support to qemu_driveadd && qemu_drivedel Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 4/9] common: add qemu_img_measure Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 05/13] blockdev: add support to qemu_block_set_io_throttle Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 5/9] rename_volume: add source && target snap Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 06/13] blockdev: add support for cdrom media eject/insert Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 6/9] storage: volume_snapshot: add $running param + api bump Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 07/13] blockdev: add support for block_resize Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 7/9] qcow2: add external snapshot support Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 08/13] blockdev: add support for nbd_export: block-export-add Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 8/9] lvmplugin: add qcow2 snapshot Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 09/13] blockdev: add blockdev_mirror Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH pve-storage 9/9] storage: add volume_support_qemu_snapshot Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 10/13] blockdev: change aio on target if io_uring is not default Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 11/13] qemu_img convert : add external snapshot support Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 12/13] blockdev: add backing_chain support Alexandre Derumier via pve-devel
2025-06-03 7:55 ` [pve-devel] [PATCH qemu-server 13/13] qcow2: add external snapshot support Alexandre Derumier via pve-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mailman.194.1748937401.395.pve-devel@lists.proxmox.com \
--to=pve-devel@lists.proxmox.com \
--cc=alexandre.derumier@groupe-cyllene.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal