[pve-devel] [PATCH v2 storage 6/7] introduce 'pve-storage-image-format' standard option for image format

Fiona Ebner f.ebner at proxmox.com
Wed Mar 5 11:49:22 CET 2025


The new 'pve-storage-image-format' standard option uses a simple enum
instead of a subroutine verifier. Since the 'pve-storage-format'
format that is replaced by it was used in pve-guest-common's
StorageTunnel, the format cannot be removed without a versioned
breaks.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/Storage/Content.pm |  8 +++-----
 src/PVE/Storage/Common.pm       | 27 +++++++++++++++++++++++++++
 src/PVE/Storage/Plugin.pm       |  9 ++++++---
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm
index 03cc4a1..f84dbb7 100644
--- a/src/PVE/API2/Storage/Content.pm
+++ b/src/PVE/API2/Storage/Content.pm
@@ -6,7 +6,7 @@ use warnings;
 use PVE::SafeSyslog;
 use PVE::Cluster;
 use PVE::Storage;
-use PVE::Storage::Plugin; # for 'pve-storage-format' format
+use PVE::Storage::Common; # for 'pve-storage-image-format' standard option
 use PVE::INotify;
 use PVE::Exception qw(raise_param_exc);
 use PVE::RPCEnvironment;
@@ -178,12 +178,10 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		pattern => '\d+[MG]?',
 	    },
-	    'format' => {
-		type => 'string',
-		format => 'pve-storage-format',
+	    format => get_standard_option('pve-storage-image-format', {
 		requires => 'size',
 		optional => 1,
-	    },
+	    }),
 	},
     },
     returns => {
diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm
index 3ae20dd..1f81234 100644
--- a/src/PVE/Storage/Common.pm
+++ b/src/PVE/Storage/Common.pm
@@ -3,6 +3,8 @@ package PVE::Storage::Common;
 use strict;
 use warnings;
 
+use PVE::JSONSchema;
+
 =pod
 
 =head1 NAME
@@ -25,6 +27,31 @@ be grouped in a submodule can also be found here.
 
 =back
 
+=head1 STANDARD OPTIONS FOR JSON SCHEMA
+
+=over
+
+=back
+
+=head3 pve-storage-image-format
+
+Possible formats a guest image can have.
+
+=cut
+
+# TODO PVE 9 - Note that currently, qemu-server allows more formats for VM images, so third party
+# storage plugins might potentially allow more too, but none of the plugins we are aware of do that.
+# Those formats should either be allowed here or support for them should be phased out (at least in
+# the storage layer). Can still be added again in the future, should any plugin provider request it.
+
+PVE::JSONSchema::register_standard_option('pve-storage-image-format', {
+    type => 'string',
+    enum => ['raw', 'qcow2', 'subvol', 'vmdk'],
+    description => "Format of the image.",
+});
+
+=pod
+
 =head1 FUNCTIONS
 
 =cut
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index dfdab16..6e23fec 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -184,11 +184,10 @@ my $defaultData = {
 	    type => 'string', format => 'pve-storage-path',
 	    optional => 1,
 	},
-	'format' => {
+	format => get_standard_option('pve-storage-image-format', {
 	    description => "Default image format.",
-	    type => 'string', format => 'pve-storage-format',
 	    optional => 1,
-	},
+	}),
 	preallocation => {
 	    description => "Preallocation mode for raw and qcow2 images. " .
 		"Using 'metadata' on raw images results in preallocation=off.",
@@ -342,6 +341,10 @@ sub verify_content {
     return $ct;
 }
 
+# NOTE the 'pve-storage-format' is deprecated, use the 'pve-storage-image-format' standard option
+# from Storage/Common.pm instead
+# TODO PVE 9 - remove after doing a versioned breaks for pve-guest-common, which was using this
+# format.
 PVE::JSONSchema::register_format('pve-storage-format', \&verify_format);
 sub verify_format {
     my ($fmt, $noerr) = @_;
-- 
2.39.5





More information about the pve-devel mailing list