]> git.proxmox.com Git - pve-storage.git/commitdiff
zfspool: add blockers parameter to volume_snapshot_is_possible
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 12 Aug 2021 11:01:01 +0000 (13:01 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 8 Nov 2021 09:34:00 +0000 (10:34 +0100)
useful for rollback, so that only the required replication snapshots
can be removed, and it's possible to abort early without deleting any
replication snapshots if there are other non-replication snasphots
blocking rollback.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage.pm
PVE/Storage/BTRFSPlugin.pm
PVE/Storage/Plugin.pm
PVE/Storage/ZFSPoolPlugin.pm

index 71d6ad78db1255286c64d48549f10894011b9094..e314bfc389163a2129b9713bbcc08e2d9e3e2aa5 100755 (executable)
@@ -269,13 +269,13 @@ sub volume_resize {
 }
 
 sub volume_rollback_is_possible {
-    my ($cfg, $volid, $snap) = @_;
+    my ($cfg, $volid, $snap, $blockers) = @_;
 
     my ($storeid, $volname) = parse_volume_id($volid, 1);
     if ($storeid) {
         my $scfg = storage_config($cfg, $storeid);
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-        return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
+        return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap, $blockers);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
         die "snapshot rollback file/device '$volid' is not possible\n";
     } else {
index 63d307df6e8f4b5fa6cbb9239cb8481a4e9cc735..04b42f130b975548cb1275c4d42813111ef6ac1f 100644 (file)
@@ -516,7 +516,7 @@ sub volume_snapshot {
 }
 
 sub volume_rollback_is_possible {
-    my ($class, $scfg, $storeid, $volname, $snap) = @_; 
+    my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
 
     return 1; 
 }
index aeb4fff3eb67c81b175b81e59ad2e6993523d742..e1f9335a973e206c1248d76e4602f01952419e80 100644 (file)
@@ -948,8 +948,11 @@ sub volume_snapshot {
     return undef;
 }
 
+# Asserts that a rollback to $snap on $volname is possible.
+# If certain snapshots are preventing the rollback and $blockers is an array
+# reference, the snapshot names can be pushed onto $blockers prior to dying.
 sub volume_rollback_is_possible {
-    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+    my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
 
     return 1;
 }
index aea2c9ecec27aee9991826ab7c0e7c541d943a32..b73d895d1a19205d0b68bc9613f1915c437fdf26 100644 (file)
@@ -483,18 +483,29 @@ sub volume_snapshot_rollback {
 }
 
 sub volume_rollback_is_possible {
-    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+    my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
 
     # can't use '-S creation', because zfs list won't reverse the order when the
     # creation time is the same second, breaking at least our tests.
     my $snapshots = $class->zfs_get_sorted_snapshot_list($scfg, $volname, ['-s', 'creation']);
-    my $recentsnap = $snapshots->[-1];
 
-    die "can't rollback, no snapshots exist at all\n"
-       if !defined($recentsnap);
+    my $found;
+    $blockers //= []; # not guaranteed to be set by caller
+    for my $snapshot ($snapshots->@*) {
+       if ($snapshot eq $snap) {
+           $found = 1;
+       } elsif ($found) {
+           push $blockers->@*, $snapshot;
+       }
+    }
+
+    my $volid = "${storeid}:${volname}";
+
+    die "can't rollback, snapshot '$snap' does not exist on '$volid'\n"
+       if !$found;
 
-    die "can't rollback, '$snap' is not most recent snapshot\n"
-       if $snap ne $recentsnap;
+    die "can't rollback, '$snap' is not most recent snapshot on '$volid'\n"
+       if scalar($blockers->@*) > 0;
 
     return 1;
 }