From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage] zfs: improve get_latest_snapshot
Date: Fri, 6 Aug 2021 11:11:06 +0200 [thread overview]
Message-ID: <20210806091106.48473-1-f.ebner@proxmox.com> (raw)
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
next reply other threads:[~2021-08-06 9:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 9:11 Fabian Ebner [this message]
2021-08-09 11:09 ` Fabian Ebner
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=20210806091106.48473-1-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.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