[pve-devel] [PATCH cluster v2 3/3] cfs_lock: save and restore outer alarm
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Nov 6 12:44:50 CET 2017
allow our caller to set alarm on us.
Ensure that the new alarm sub gets assigned before the new alarm gets set.
---
new in v2
maybe there should be even:
alarm(0)
local $SIG{ALRM} = sub {...};
alarm(60);
to ensure we always call the matching alarm sub, but as this is not a
likely nor big problem just keep it this way.
data/PVE/Cluster.pm | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index f634c84..3da86bc 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -860,6 +860,8 @@ sub cfs_write_file {
my $cfs_lock = sub {
my ($lockid, $timeout, $code, @param) = @_;
+ my $prev_alarm = alarm(0); # suspend outer alarm early
+
my $res;
my $got_lock = 0;
@@ -899,8 +901,8 @@ my $cfs_lock = sub {
# fixed command timeout: cfs locks have a timeout of 120
# using 60 gives us another 60 seconds to abort the task
- alarm(60);
local $SIG{ALRM} = sub { die "got lock timeout - aborting command\n"; };
+ alarm(60);
cfs_update(); # make sure we read latest versions inside code()
@@ -911,12 +913,12 @@ my $cfs_lock = sub {
my $err = $@;
- alarm(0);
-
$err = "$msg: no quorum!\n" if !$got_lock && !check_cfs_quorum(1);
rmdir $filename if $got_lock; # if we held the lock always unlock again
+ alarm($prev_alarm);
+
if ($err) {
$@ = $err;
return undef;
--
2.11.0
More information about the pve-devel
mailing list