From 03c3db3d9aa30f5354ec433b7528f9f9385faec9 Mon Sep 17 00:00:00 2001 From: Steffen Dettmer Date: Sat, 20 Apr 2024 12:55:44 +0200 Subject: [PATCH 1/2] sanoid #912: sanoid --prune-snapshots performance boost by removing unneeded iszfsbusy() --- README.md | 4 ---- sanoid | 64 ++++++++++++++++--------------------------------------- 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index f2ce10c5..85539d5b 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,6 @@ For more full details on sanoid.conf settings see [Wiki page](https://github.com This will process your sanoid.conf file, it will NOT create snapshots, but it will purge expired ones. -+ --force-prune - - Purges expired snapshots even if a send/recv is in progress - + --monitor-snapshots This option is designed to be run by a Nagios monitoring system. It reports on the health of your snapshots. diff --git a/sanoid b/sanoid index 295957b2..22f630e4 100755 --- a/sanoid +++ b/sanoid @@ -25,7 +25,7 @@ my %args = ( GetOptions(\%args, "verbose", "debug", "cron", "readonly", "quiet", "configdir=s", "cache-dir=s", "run-dir=s", "monitor-health", "force-update", - "monitor-snapshots", "take-snapshots", "prune-snapshots", "force-prune", + "monitor-snapshots", "take-snapshots", "prune-snapshots", "monitor-capacity" ) or pod2usage(2); @@ -40,7 +40,7 @@ my $cacheTTL = 900; # 15 minutes # Allow a much older snapshot cache file than default if _only_ "--monitor-*" action commands are given # (ignore "--verbose", "--configdir" etc) -if (($args{'monitor-snapshots'} || $args{'monitor-health'} || $args{'monitor-capacity'}) && ! ($args{'cron'} || $args{'force-update'} || $args{'take-snapshots'} || $args{'prune-snapshots'} || $args{'force-prune'})) { +if (($args{'monitor-snapshots'} || $args{'monitor-health'} || $args{'monitor-capacity'}) && ! ($args{'cron'} || $args{'force-update'} || $args{'take-snapshots'} || $args{'prune-snapshots'})) { # The command combination above must not assert true for any command that takes or prunes snapshots $cacheTTL = 18000; # 5 hours if ($args{'debug'}) { print "DEBUG: command combo means that the cache file (provided it exists) will be allowed to be older than default.\n"; } @@ -349,26 +349,23 @@ sub prune_snapshots { } if ($args{'verbose'}) { print "INFO: pruning $snap ... \n"; } - if (!$args{'force-prune'} && iszfsbusy($path)) { - if ($args{'verbose'}) { print "INFO: deferring pruning of $snap - $path is currently in zfs send or receive.\n"; } - } else { - if (! $args{'readonly'}) { - if (system($zfs, "destroy", $snap) == 0) { - $pruned{$snap} = 1; - if ($config{$dataset}{'pruning_script'}) { - $ENV{'SANOID_TARGET'} = $dataset; - $ENV{'SANOID_SNAPNAME'} = $snapname; - $ENV{'SANOID_SCRIPT'} = 'prune'; - if ($args{'verbose'}) { print "executing pruning_script '".$config{$dataset}{'pruning_script'}."' on dataset '$dataset'\n"; } - my $ret = runscript('pruning_script',$dataset); - - delete $ENV{'SANOID_TARGET'}; - delete $ENV{'SANOID_SNAPNAME'}; - delete $ENV{'SANOID_SCRIPT'}; - } - } else { - warn "could not remove $snap : $?"; + + if (! $args{'readonly'}) { + if (system($zfs, "destroy", $snap) == 0) { + $pruned{$snap} = 1; + if ($config{$dataset}{'pruning_script'}) { + $ENV{'SANOID_TARGET'} = $dataset; + $ENV{'SANOID_SNAPNAME'} = $snapname; + $ENV{'SANOID_SCRIPT'} = 'prune'; + if ($args{'verbose'}) { print "executing pruning_script '".$config{$dataset}{'pruning_script'}."' on dataset '$dataset'\n"; } + my $ret = runscript('pruning_script',$dataset); + + delete $ENV{'SANOID_TARGET'}; + delete $ENV{'SANOID_SNAPNAME'}; + delete $ENV{'SANOID_SCRIPT'}; } + } else { + warn "could not remove $snap : $?"; } } } @@ -1557,30 +1554,6 @@ sub writelock { close FH; } -sub iszfsbusy { - # check to see if ZFS filesystem passed in as argument currently has a zfs send or zfs receive process referencing it. - # return true if busy (currently being sent or received), return false if not. - - my $fs = shift; - # if (args{'debug'}) { print "DEBUG: checking to see if $fs on is already in zfs receive using $pscmd -Ao args= ...\n"; } - - open PL, "$pscmd -Ao args= |"; - my @processes = ; - close PL; - - foreach my $process (@processes) { - # if ($args{'debug'}) { print "DEBUG: checking process $process...\n"; } - if ($process =~ /zfs *(send|receive|recv).*$fs/) { - # there's already a zfs send/receive process for our target filesystem - return true - # if ($args{'debug'}) { print "DEBUG: process $process matches target $fs!\n"; } - return 1; - } - } - - # no zfs receive processes for our target filesystem found - return false - return 0; -} - #######################################################################################################################3 #######################################################################################################################3 #######################################################################################################################3 @@ -1752,7 +1725,6 @@ Options: --monitor-snapshots Reports on snapshot "health", in a Nagios compatible format --take-snapshots Creates snapshots as specified in sanoid.conf --prune-snapshots Purges expired snapshots as specified in sanoid.conf - --force-prune Purges expired snapshots even if a send/recv is in progress --help Prints this helptext --version Prints the version number From cf0ecb30ae2fa62ba57910efe73cb91ccbcd1510 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Tue, 4 Jun 2024 08:40:41 +0200 Subject: [PATCH 2/2] added deprecation warning for removed force-prune --- sanoid | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sanoid b/sanoid index 4bffdf6c..3585846a 100755 --- a/sanoid +++ b/sanoid @@ -25,7 +25,7 @@ my %args = ( GetOptions(\%args, "verbose", "debug", "cron", "readonly", "quiet", "configdir=s", "cache-dir=s", "run-dir=s", "monitor-health", "force-update", - "monitor-snapshots", "take-snapshots", "prune-snapshots", + "monitor-snapshots", "take-snapshots", "prune-snapshots", "force-prune", "monitor-capacity" ) or pod2usage(2); @@ -54,6 +54,10 @@ make_path($run_dir); my $cacheTTL = 1200; # 20 minutes +if ($args{'force-prune'}) { + warn "WARN: --force-prune argument is deprecated and its behavior is now standard"; +} + # Allow a much older snapshot cache file than default if _only_ "--monitor-*" action commands are given # (ignore "--verbose", "--configdir" etc) if (