From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 18FB91FF185
	for <inbox@lore.proxmox.com>; Mon,  9 Jun 2025 09:32:44 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 54D8D37736;
	Mon,  9 Jun 2025 09:33:03 +0200 (CEST)
To: pve-devel@lists.proxmox.com
Date: Mon,  9 Jun 2025 10:32:12 +0300
In-Reply-To: <20250609073214.7880-1-denis.kanchev@storpool.com>
References: <20250609073214.7880-1-denis.kanchev@storpool.com>
MIME-Version: 1.0
Message-ID: <mailman.305.1749454382.395.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Demayl via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Demayl <denis.kanchev@storpool.com>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH atomic snapshot 4/4] plugin: add optional atomic
 snapshot creation
Content-Type: multipart/mixed; boundary="===============9015424672896710001=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============9015424672896710001==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <denis.kanchev@storpool.com>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id 7C8FCCCDB0
	for <pve-devel@lists.proxmox.com>; Mon,  9 Jun 2025 09:33:02 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 14B7B375C9
	for <pve-devel@lists.proxmox.com>; Mon,  9 Jun 2025 09:32:32 +0200 (CEST)
Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Mon,  9 Jun 2025 09:32:30 +0200 (CEST)
Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3a52874d593so3921977f8f.0
        for <pve-devel@lists.proxmox.com>; Mon, 09 Jun 2025 00:32:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=storpool.com; s=google; t=1749454344; x=1750059144; darn=lists.proxmox.com;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=5QAecFd1Dzi/yV1sL7bVq5KdCeVH5GJ3X/kRN7d64u0=;
        b=AYUCZ4qgxT5q+AAq91OlTlYK8hsuuXKupEcSNvs297rpvxgw9mvxO5ZT0sBAW/OzNj
         vFpVtRNJfoujp2QzqJvFDt2FCEHUnVu8eDAvjW2SIrkQP5Y43KQyugaWULg4i135iO7k
         MC9aS9aEpj5Jzox8tFUHgdyt7q4jdJNPUk3iopjqwb3PknkoNNA/sRR58iHoaur8lApG
         dFpAOVSINm+EoPLRgRwYJ8749yNLN1D3JMs1PDpFnRZ5dlvqzAmgXtJI14NEwiiW4bRx
         QSKX/TIaVMu7Km2IqJFSU5nLxi/53AZ0Cno/daEe9YVKkwDrIfq0UfEZkEl49Eqcf4V4
         dJag==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1749454344; x=1750059144;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=5QAecFd1Dzi/yV1sL7bVq5KdCeVH5GJ3X/kRN7d64u0=;
        b=DqRJ2g7j9ECNPgqlRRhWoNDOyi8lVsyWh3j6sPapoqSlSdF5iuGWoNxdp/uWpPXZp4
         3k5vAaeGK1l9s6P47URzUNOSwnMjVM022MXCbVyaPVyL1eO9aMf6Q6WMoTuzNrGzDcZS
         7orMz3ayfmj7i2GjqMc0etqaOIWGgQrCFWr4JnqD8nhoJFng6UORLMZQXexJ5+mU/sAt
         Q8WYBICL4l2sucpZiCfbqmpsL+evw1LrkSLoefaAUbnGjXlyY4KPg5FoNy93Ra/zbzBd
         v7j+razWvUmyXJxptaC99Njay8LiqrXaSW3l6kP3fb+DAJD4wSOQqat0xr9XzhQ91g8J
         6afQ==
X-Gm-Message-State: AOJu0YxeYGT1S5BTWaGQrFZql23SLfawhkGcE0G6xq5drSFx2SO4lA4W
	0EprgfS5XhmQJ9ZIe5+BEinDt43I/gfalf2kObl1XTNMsWvNxeU004YgCV2JrRNLJmmJyTLdIgQ
	8hLegGlg=
X-Gm-Gg: ASbGncu/2fJtcvzo095rW29rCQ1FN8gsw2dxAwPME5Qk1Km6GWCScK5zLLd2IfIByVu
	u6YvN34uqlmj9xU88vm20Phi+XAecGeUZxV2ubte0DCpwTyJKLizFQYf8lkQw1WIvJjHd2udeGn
	iQiPwlGlWn8BKW7DUDeFQpjYE99L5IR+ShlXiP4CFh4P10HkWF90BmDjoIouCO5ldk62yZIS8f5
	F/0LQwo697O3vO3FX9iCGbA1keR1xT0uYebcuI3fj2sf6GRrguzixR0C+4bVCKINaZFY439ZYeT
	qfuW2jsqMpeRmQtff2Re3WhYGXqjM+LUEesBnjTDgnCxE2G34DvY2cmy1I38w4P+ZdRq6zTlkZ7
	D2wBDYPzs2cqSIE7Gc0Al
X-Google-Smtp-Source: AGHT+IEdZXhQkejTWx0m1hVxmCKY7UN//YPQi0fllfrXUnPr+5t/B+vy9ObFuGpRarf+JvGNfeKj2Q==
X-Received: by 2002:a05:6000:4285:b0:3a5:2599:4178 with SMTP id ffacd0b85a97d-3a53188da4amr8347497f8f.19.1749454343718;
        Mon, 09 Jun 2025 00:32:23 -0700 (PDT)
Received: from dennis.. (79-100-232-190.ip.btc-net.bg. [79.100.232.190])
        by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4521370961csm102916165e9.22.2025.06.09.00.32.22
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 09 Jun 2025 00:32:23 -0700 (PDT)
From: Demayl <denis.kanchev@storpool.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH atomic snapshot 4/4] plugin: add optional atomic snapshot creation
Date: Mon,  9 Jun 2025 10:32:12 +0300
Message-ID: <20250609073214.7880-5-denis.kanchev@storpool.com>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20250609073214.7880-1-denis.kanchev@storpool.com>
References: <20250609073214.7880-1-denis.kanchev@storpool.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
	AWL                    -0.000 Adjusted score from AWL reputation of From: address
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	KAM_SHORT               0.001 Use of a URL Shortener for very short URL
	RCVD_IN_DNSWL_NONE     -0.0001 Sender listed at https://www.dnswl.org/, no trust
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_PASS               -0.001 SPF: sender matches SPF record

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

Signed-off-by: Demayl <denis.kanchev@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



--===============9015424672896710001==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============9015424672896710001==--