From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 789296D27C
 for <pve-devel@lists.proxmox.com>; Fri, 13 Aug 2021 08:55:35 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 626CB29DDA
 for <pve-devel@lists.proxmox.com>; Fri, 13 Aug 2021 08:55:05 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 14CD929DC8
 for <pve-devel@lists.proxmox.com>; Fri, 13 Aug 2021 08:55:00 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D8B6F43311
 for <pve-devel@lists.proxmox.com>; Fri, 13 Aug 2021 08:54:59 +0200 (CEST)
To: pve-devel@lists.proxmox.com
References: <20210812110111.73883-1-f.ebner@proxmox.com>
 <20210812110111.73883-3-f.ebner@proxmox.com>
From: Fabian Ebner <f.ebner@proxmox.com>
Message-ID: <8a5d2e0f-7a3c-9d4e-122c-6b5fd7a46166@proxmox.com>
Date: Fri, 13 Aug 2021 08:54:44 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
 Thunderbird/78.12.0
MIME-Version: 1.0
In-Reply-To: <20210812110111.73883-3-f.ebner@proxmox.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.153 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [btrfsplugin.pm, plugin.pm, storage.pm, zfspoolplugin.pm]
 URI_NOVOWEL               0.5 URI hostname has long non-vowel sequence
Subject: Re: [pve-devel] [PATCH v3 storage 2/3] zfspool: add blockers
 parameter to volume_snapshot_is_possible
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
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/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 13 Aug 2021 06:55:35 -0000

Am 12.08.21 um 13:01 schrieb Fabian Ebner:
> 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>
> ---

Forgot to mention that this requires an APIVER+APIAGE bump.

>   PVE/Storage.pm               |  4 ++--
>   PVE/Storage/BTRFSPlugin.pm   |  2 +-
>   PVE/Storage/Plugin.pm        |  5 ++++-
>   PVE/Storage/ZFSPoolPlugin.pm | 23 +++++++++++++++++------
>   4 files changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index c04b5a2..3b3ce93 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -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 {
> diff --git a/PVE/Storage/BTRFSPlugin.pm b/PVE/Storage/BTRFSPlugin.pm
> index 411cab9..60fb027 100644
> --- a/PVE/Storage/BTRFSPlugin.pm
> +++ b/PVE/Storage/BTRFSPlugin.pm
> @@ -513,7 +513,7 @@ sub volume_snapshot {
>   }
>   
>   sub volume_rollback_is_possible {
> -    my ($class, $scfg, $storeid, $volname, $snap) = @_;
> +    my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
>   
>       return 1;
>   }
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index b1865cb..c265e53 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -900,8 +900,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;
>   }
> diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
> index c2a0385..8d79f38 100644
> --- a/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/PVE/Storage/ZFSPoolPlugin.pm
> @@ -480,18 +480,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;
>   }
>