public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH storage] zfs: improve get_latest_snapshot
@ 2021-08-06  9:11 Fabian Ebner
  2021-08-09 11:09 ` Fabian Ebner
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2021-08-06  9:11 UTC (permalink / raw)
  To: pve-devel

by only requesting snapshots for the relevant dataset, instead of all
snapshots in all pools, and avoiding an unnecessary loop.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/Storage/ZFSPoolPlugin.pm | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index c4be70f..fd7f844 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -400,19 +400,16 @@ sub zfs_get_latest_snapshot {
 
     my $vname = ($class->parse_volname($volname))[1];
 
-    # abort rollback if snapshot is not the latest
-    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
+    # can't use -S, because zfs list won't reverse order when creation time
+    # is the same second, breaking (at least) our tests.
+    my @params = ('-H', '-t', 'snapshot', '-o', 'name', '-s', 'creation', "$scfg->{pool}\/$vname");
     my $text = $class->zfs_request($scfg, undef, 'list', @params);
     my @snapshots = split(/\n/, $text);
 
     my $recentsnap;
-    foreach (@snapshots) {
-        if (/$scfg->{pool}\/$vname/) {
-            s/^.*@//;
-            $recentsnap = $_;
-        }
+    if (scalar(@snapshots) > 0) {
+	($recentsnap = $snapshots[-1]) =~ s/^.*@//; # last element
     }
-
     return $recentsnap;
 }
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH storage] zfs: improve get_latest_snapshot
  2021-08-06  9:11 [pve-devel] [PATCH storage] zfs: improve get_latest_snapshot Fabian Ebner
@ 2021-08-09 11:09 ` Fabian Ebner
  0 siblings, 0 replies; 2+ messages in thread
From: Fabian Ebner @ 2021-08-09 11:09 UTC (permalink / raw)
  To: pve-devel

Am 06.08.21 um 11:11 schrieb Fabian Ebner:
> by only requesting snapshots for the relevant dataset, instead of all
> snapshots in all pools, and avoiding an unnecessary loop.
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
>   PVE/Storage/ZFSPoolPlugin.pm | 13 +++++--------
>   1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
> index c4be70f..fd7f844 100644
> --- a/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/PVE/Storage/ZFSPoolPlugin.pm
> @@ -400,19 +400,16 @@ sub zfs_get_latest_snapshot {
>   
>       my $vname = ($class->parse_volname($volname))[1];
>   
> -    # abort rollback if snapshot is not the latest
> -    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
> +    # can't use -S, because zfs list won't reverse order when creation time
> +    # is the same second, breaking (at least) our tests.
> +    my @params = ('-H', '-t', 'snapshot', '-o', 'name', '-s', 'creation', "$scfg->{pool}\/$vname");
>       my $text = $class->zfs_request($scfg, undef, 'list', @params);
>       my @snapshots = split(/\n/, $text);
>   
>       my $recentsnap;
> -    foreach (@snapshots) {
> -        if (/$scfg->{pool}\/$vname/) {
> -            s/^.*@//;
> -            $recentsnap = $_;
> -        }
> +    if (scalar(@snapshots) > 0) {
> +	($recentsnap = $snapshots[-1]) =~ s/^.*@//; # last element
>       }
> -
>       return $recentsnap;
>   }
>   
> 

After an off-list discussion with Fabian G. about bug #3111, the plan is 
to extend volume_rollback_is_possible to inform its caller which 
snapshots are preventing a rollback. volume_rollback_is_possible is the 
only caller of zfs_get_latest_snapshot, so this patch will most likely 
be superseded by the series fixing #3111.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-09 11:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06  9:11 [pve-devel] [PATCH storage] zfs: improve get_latest_snapshot Fabian Ebner
2021-08-09 11:09 ` Fabian Ebner

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