[PATCH pve-storage 08/13] storage: add rename_snapshot method

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Wed Jul 9 18:21:57 CEST 2025


Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 ApiChangeLog                     |  3 +++
 src/PVE/Storage.pm               | 25 +++++++++++++++++++++++++
 src/PVE/Storage/BTRFSPlugin.pm   |  6 ++++++
 src/PVE/Storage/ESXiPlugin.pm    |  6 ++++++
 src/PVE/Storage/LVMPlugin.pm     |  6 ++++++
 src/PVE/Storage/LvmThinPlugin.pm |  6 ++++++
 src/PVE/Storage/Plugin.pm        | 16 ++++++++++++++++
 src/PVE/Storage/RBDPlugin.pm     |  6 ++++++
 src/PVE/Storage/ZFSPoolPlugin.pm |  6 ++++++
 9 files changed, 80 insertions(+)

diff --git a/ApiChangeLog b/ApiChangeLog
index 2a01e3f..12eef1f 100644
--- a/ApiChangeLog
+++ b/ApiChangeLog
@@ -26,6 +26,9 @@ Future changes should be documented in here.
     The parameter *can* be used if some extra actions need to be done at the storage
     layer when the snapshot has already be done at qemu level when the vm is running.
 
+* Introduce rename_snapshot() plugin method
+    This method allow to rename a vm disk snapshot name to a different snapshot name.
+
 ##  Version 11:
 
 * Allow declaring storage features via plugin data
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 7f2da80..e0b79fa 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -2345,6 +2345,31 @@ sub rename_volume {
     );
 }
 
+sub rename_snapshot {
+    my ($cfg, $volid, $source_snap, $target_snap) = @_;
+
+    die "no volid provided\n" if !$volid;
+    die "no source or target snap provided\n" if !$source_snap && !$target_snap;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    activate_storage($cfg, $storeid);
+
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->cluster_lock_storage(
+        $storeid,
+        $scfg->{shared},
+        undef,
+        sub {
+            return $plugin->rename_snapshot(
+                $scfg, $storeid, $volname, $source_snap, $target_snap,
+            );
+        },
+    );
+}
+
 # Various io-heavy operations require io/bandwidth limits which can be
 # configured on multiple levels: The global defaults in datacenter.cfg, and
 # per-storage overrides. When we want to do a restore from storage A to storage
diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm
index 8c79ea4..26eef2b 100644
--- a/src/PVE/Storage/BTRFSPlugin.pm
+++ b/src/PVE/Storage/BTRFSPlugin.pm
@@ -995,6 +995,12 @@ sub rename_volume {
     return "${storeid}:$target_volname";
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not supported for $class";
+}
+
 sub get_import_metadata {
     return PVE::Storage::DirPlugin::get_import_metadata(@_);
 }
diff --git a/src/PVE/Storage/ESXiPlugin.pm b/src/PVE/Storage/ESXiPlugin.pm
index e655d7b..66ef289 100644
--- a/src/PVE/Storage/ESXiPlugin.pm
+++ b/src/PVE/Storage/ESXiPlugin.pm
@@ -497,6 +497,12 @@ sub rename_volume {
     die "renaming volumes is not supported for $class\n";
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not supported for $class";
+}
+
 sub volume_export_formats {
     my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
 
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 72eb0cd..2441e59 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -855,4 +855,10 @@ sub rename_volume {
     return "${storeid}:${target_volname}";
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not implemented for $class";
+}
+
 1;
diff --git a/src/PVE/Storage/LvmThinPlugin.pm b/src/PVE/Storage/LvmThinPlugin.pm
index e5df0b4..6bc76c9 100644
--- a/src/PVE/Storage/LvmThinPlugin.pm
+++ b/src/PVE/Storage/LvmThinPlugin.pm
@@ -468,4 +468,10 @@ sub volume_import_write {
     );
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not supported for $class";
+}
+
 1;
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index da26c0c..6b2dc32 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -2046,6 +2046,22 @@ sub rename_volume {
     return "${storeid}:${base}${target_vmid}/${target_volname}";
 }
 
+=pod
+
+=head3 rename_snapshot
+
+    $plugin->rename_snapshot($scfg, $storeid, $volname, $source_snap, $target_snap)
+
+Rename a volume source snapshot C<$source_snap> to a target snapshot C<$target_snap>.
+
+=cut
+
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not implemented for $class";
+}
+
 my sub blockdev_options_nbd_tcp {
     my ($host, $port, $export) = @_;
 
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index 38d61e9..ee33006 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -1055,4 +1055,10 @@ sub rename_volume {
     return "${storeid}:${base_name}${target_volname}";
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not implemented for $class";
+}
+
 1;
diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
index 9cdfa68..28d4795 100644
--- a/src/PVE/Storage/ZFSPoolPlugin.pm
+++ b/src/PVE/Storage/ZFSPoolPlugin.pm
@@ -895,4 +895,10 @@ sub rename_volume {
     return "${storeid}:${base_name}${target_volname}";
 }
 
+sub rename_snapshot {
+    my ($class, $scfg, $storeid, $volname, $source_snap, $target_snap) = @_;
+
+    die "rename_snapshot is not supported for $class";
+}
+
 1;
-- 
2.39.5




More information about the pve-devel mailing list