[PATCH atomic snapshot 4/4] plugin: add optional atomic snapshot creation

Demayl denis.kanchev at storpool.com
Mon Jun 9 09:32:12 CEST 2025


This will allow creating atomic snapshots from the custom plugins when they support it

Signed-off-by: Demayl <denis.kanchev at storpool.com>
---
 src/PVE/Storage.pm        | 52 +++++++++++++++++++++++++++++++++++++--
 src/PVE/Storage/Plugin.pm | 16 ++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index d0a696a..9b044cc 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -42,11 +42,11 @@ use PVE::Storage::BTRFSPlugin;
 use PVE::Storage::ESXiPlugin;
 
 # Storage API version. Increment it on changes in storage API interface.
-use constant APIVER => 11;
+use constant APIVER => 12;
 # Age is the number of versions we're backward compatible with.
 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
-use constant APIAGE => 2;
+use constant APIAGE => 3;
 
 our $KNOWN_EXPORT_FORMATS = ['raw+size', 'tar+size', 'qcow2+size', 'vmdk+size', 'zfs', 'btrfs'];
 
@@ -347,6 +347,54 @@ sub volume_rollback_is_possible {
     }
 }
 
+
+sub get_volumes_storecfg {
+    my ($cfg, $volume_data) = @_;
+    my $vol_cfg = {};
+    for my $volid (keys %{$volume_data}) {
+	my ($storeid, $volname) = parse_volume_id($volume_data->{$volid}->{file}, 1);
+	if ($storeid) {
+	    $vol_cfg->{$volname} = {
+		storeid => $storeid,
+		scfg => storage_config($cfg, $storeid),
+	    };
+	}
+	elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+	    die "snapshot file/device '$volid' is not possible\n";
+	} else {
+	    die "unable to parse volume ID '$volid'\n";
+	}
+    }
+    return $vol_cfg;
+}
+
+sub volumes_atomic_snapshot_possible {
+    my ($cfg, $disk_data) = @_;
+    my $last_type;
+    my $voldata = get_volumes_storecfg($cfg, $disk_data);
+    for my $key (keys %$voldata) {
+	my $type = $voldata->{ $key }->{scfg}->{type};
+	if (defined($last_type) && $last_type ne $type) {
+	    return (0, 0, $voldata);
+	}
+	$last_type = $type;
+    }
+    my $plugin = PVE::Storage::Plugin->lookup($last_type);
+    return (
+	$plugin->volumes_atomic_snapshot_possible($voldata),
+	$plugin->atomic_snapshot_preferred($voldata),
+	$voldata,
+    )
+}
+
+sub volumes_atomic_snapshot {
+    my ($voldata, $snapname) = @_;
+    my $type   = $voldata->{(keys %{$voldata})[0]}->{scfg}->{type};
+    my $plugin = PVE::Storage::Plugin->lookup($type);
+
+    $plugin->volumes_atomic_snapshot($voldata, $snapname);
+}
+
 sub volume_snapshot {
     my ($cfg, $volid, $snap) = @_;
 
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index 4e16420..391dd0b 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -1904,4 +1904,20 @@ sub config_aware_base_mkdir {
     }
 }
 
+sub volumes_atomic_snapshot_possible {
+    my ($class, $voldata) = @_;
+    return 0;
+}
+
+sub atomic_snapshot_preferred {
+    my ($class, $volata) = @_;
+    return 0;
+}
+
+# Performs an atomic (crash-consistent) snapshot of all volumes at once.
+sub volumes_atomic_snapshot {
+    my ($class, $voldata, $snap) = @_;
+    die "volumes_atomic_snapshot is not implemented for $class";
+}
+
 1;
-- 
2.43.0




More information about the pve-devel mailing list