[pve-devel] [PATCH storage 18/26] plugins: update create_base methods

Wolfgang Bumiller
2025-07-29T11:17:16Z

src/PVE/Storage/BTRFSPlugin.pm | 12 ++++++++++--
src/PVE/Storage/Plugin.pm | 9 +++++++--
src/PVE/Storage/RBDPlugin.pm | 6 +++++-
src/PVE/Storage/ZFSPlugin.pm | 6 +++++-
4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm
index 0a42c88..b3a53b0 100644
--- a/src/PVE/Storage/BTRFSPlugin.pm
+++ b/src/PVE/Storage/BTRFSPlugin.pm
@@ -260,7 +260,11 @@ sub create_base {
$class->parse_volname($volname);

my $newname = $name;
- $newname =~ s/^vm-/base-/;
+ if ($newname =~ /^vm-/) {
+ $newname =~ s/^vm-/base-/;
+ } else {
+ $newname = "base-$newname";
+ }

# If we're not working with a 'raw' file, which is the only thing that's "different" for btrfs,
# or a subvolume, we forward to the DirPlugin
@@ -441,7 +445,11 @@ sub free_image {

my ($vtype, undef, $vmid, undef, undef, undef, $format) = $class->parse_volname($volname);

- if (!defined($format) || $vtype ne 'images' || ($format ne 'subvol' && $format ne 'raw')) {
+ if (
+ !defined($format)
+ || !PVE::Storage::Common::is_volume_type($vtype)
+ || ($format ne 'subvol' && $format ne 'raw')
+ ) {
return $class->SUPER::free_image($storeid, $scfg, $volname, $isBase, $_format);
}

diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index adaca47..e4cf392 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -873,7 +873,7 @@ sub create_base {
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
$class->parse_volname($volname);

- die "create_base on wrong vtype '$vtype'\n" if $vtype ne 'images';
+ die "create_base on wrong vtype '$vtype'\n" if !PVE::Storage::Common::is_volume_type($vtype);

die "create_base not possible with base image\n" if $isBase;

@@ -886,7 +886,12 @@ sub create_base {
if $basename && (!$parent || $parent ne "../$basevmid/$basename");

my $newname = $name;
- $newname =~ s/^vm-/base-/;
+ if ($newname =~ /^vm-/) {
+ # legacy name
+ $newname =~ s/^vm-/base-/;
+ } else {
+ $newname = "base-$newname";
+ }

my $newvolname =
$basename
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index 839ff73..11639f0 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -663,7 +663,11 @@ sub create_base {
if $basename && (!$parent || $parent ne $basename . "@" . $snap);

my $newname = $name;
- $newname =~ s/^vm-/base-/;
+ if ($newname =~ /^vol-/) {
+ $newname = "base-$newname";
+ } else {
+ $newname =~ s/^vm-/base-/;
+ }

my $newvolname = $basename ? "$basename/$newname" : "$newname";

diff --git a/src/PVE/Storage/ZFSPlugin.pm b/src/PVE/Storage/ZFSPlugin.pm
index 259e468..fdbe80c 100644
--- a/src/PVE/Storage/ZFSPlugin.pm
+++ b/src/PVE/Storage/ZFSPlugin.pm
@@ -325,7 +325,11 @@ sub create_base {
die "create_base not possible with base image\n" if $isBase;

my $newname = $name;
- $newname =~ s/^vm-/base-/;
+ if ($newname =~ /^vm-/) {
+ $newname =~ s/^vm-/base-/;
+ } else {
+ $newname = "base-$newname";
+ }

my $newvolname = $basename ? "$basename/$newname" : "$newname";