public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Demayl via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Demayl <denis.kanchev@storpool.com>
Subject: [pve-devel] [PATCH atomic snapshot 3/4] storage snapshot: add optional atomic snapshot creation in snapshot_create
Date: Mon,  9 Jun 2025 10:32:11 +0300	[thread overview]
Message-ID: <mailman.301.1749454349.395.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250609073214.7880-1-denis.kanchev@storpool.com>

[-- Attachment #1: Type: message/rfc822, Size: 8524 bytes --]

From: Demayl <denis.kanchev@storpool.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH atomic snapshot 3/4] storage snapshot: add optional atomic snapshot creation in snapshot_create
Date: Mon,  9 Jun 2025 10:32:11 +0300
Message-ID: <20250609073214.7880-4-denis.kanchev@storpool.com>

Signed-off-by: Demayl <denis.kanchev@storpool.com>
---
 src/PVE/AbstractConfig.pm | 60 +++++++++++++++++++++++++++++++++------
 1 file changed, 51 insertions(+), 9 deletions(-)

diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
index 3d4fcbb..8bb271d 100644
--- a/src/PVE/AbstractConfig.pm
+++ b/src/PVE/AbstractConfig.pm
@@ -811,10 +811,39 @@ sub __snapshot_activate_storages {
     return;
 }
 
+sub get_atomic_snapshot_volumes {
+    my ($class, $conf) = @_;
+    my $volumes = {};
+    $class->foreach_volume(
+        $conf,
+        sub {
+            my ($key, $volume_string) = @_;
+            $volumes->{$key} = $volume_string;
+        }
+    );
+    return $volumes;
+}
+sub check_atomic_snapshots {
+    my ($class, $conf) = @_;
+    return PVE::Storage::volumes_atomic_snapshot_possible(
+        PVE::Storage::config(),
+        $class->get_atomic_snapshot_volumes($conf),
+    );
+}
+
+sub __snapshot_volumes_atomically {
+    my ($class, $voldata, $snapname) = @_;
+    PVE::Storage::volumes_atomic_snapshot($voldata, $snapname);
+    return { map { $_ => 1 } keys %{$voldata} };
+}
+
+
 # Creates a snapshot for the VM/CT.
+# Type can be either atomic or sequential
 sub snapshot_create {
-    my ($class, $vmid, $snapname, $save_vmstate, $comment) = @_;
+    my ($class, $vmid, $snapname, $save_vmstate, $comment, $type) = @_;
 
+    my $atomic = $type && $type eq 'atomic';
     my $snap = $class->__snapshot_prepare($vmid, $snapname, $save_vmstate, $comment);
 
     $save_vmstate = 0 if !$snap->{vmstate};
@@ -823,32 +852,45 @@ sub snapshot_create {
 
     my ($running, $freezefs) = $class->__snapshot_check_freeze_needed($vmid, $conf, $snap->{vmstate});
 
+    my ($can_atomic, undef, $vol_cfg) = $class->check_atomic_snapshots($snap);
+    if ($atomic && !$can_atomic) {
+	warn "snapshot create failed: starting cleanup\n";
+	eval { $class->snapshot_delete($vmid, $snapname, 1, {}); };
+	warn "$@" if $@;
+	die "atomic snapshot impossible for mixed storage\n";
+    }
+    my $is_atomic = $atomic && $can_atomic;
+
     my $drivehash = {};
 
     eval {
 	$class->__snapshot_activate_storages($conf, 0);
 
-	if ($freezefs) {
+	if ($freezefs && !$is_atomic) {
 	    $class->__snapshot_freeze($vmid, 0);
 	}
 
 	$class->__snapshot_create_vol_snapshots_hook($vmid, $snap, $running, "before");
 
-	$class->foreach_volume($snap, sub {
-	    my ($vs, $volume) = @_;
+	if ($is_atomic) {
+	    $drivehash = $class->__snapshot_volumes_atomically($vol_cfg, $snapname);
+	} else {
+	    $class->foreach_volume($snap, sub {
+		my ($vs, $volume) = @_;
 
-	    $class->__snapshot_create_vol_snapshot($vmid, $vs, $volume, $snapname);
-	    $drivehash->{$vs} = 1;
-	});
+		$class->__snapshot_create_vol_snapshot($vmid, $vs, $volume, $snapname);
+		$drivehash->{$vs} = 1;
+	    });
+	}
     };
     my $err = $@;
 
     if ($running) {
 	$class->__snapshot_create_vol_snapshots_hook($vmid, $snap, $running, "after");
-	if ($freezefs) {
+	if ($freezefs && !$is_atomic) {
 	    $class->__snapshot_freeze($vmid, 1);
+	    $class->__snapshot_create_vol_snapshots_hook($vmid, $snap, $running, "after-unfreeze");
 	}
-	$class->__snapshot_create_vol_snapshots_hook($vmid, $snap, $running, "after-unfreeze");
     }
 
     if ($err) {
-- 
2.43.0



[-- 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

  parent reply	other threads:[~2025-06-09  7:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250609073214.7880-1-denis.kanchev@storpool.com>
2025-06-09  7:32 ` [pve-devel] [PATCH atomic snapshot 1/4] ui: snapshot: add atomic option Demayl via pve-devel
2025-06-09  7:32 ` [pve-devel] [PATCH atomic_snapshot 2/4] snapshot api: add type option when making snapshots Demayl via pve-devel
2025-06-09  7:32 ` Demayl via pve-devel [this message]
2025-06-09  7:32 ` [pve-devel] [PATCH atomic snapshot 4/4] plugin: add optional atomic snapshot creation Demayl 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.301.1749454349.395.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=denis.kanchev@storpool.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