[pve-devel] [PATCH ha-manager 1/3] add after_fork method to HA environment and use it in LRM

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jan 27 13:16:33 CET 2016


As both the realtime simulator and the real world Environment can
fork but we only need to clean up after a fork in the real world
introduce a after_fork method

In PVE2 it closes the inherited INotify fd and reopens it for the
worker.
Also a cfs_update gets triggered as (other) workers may change the
cluster state.

also use the new introduction HA-Env method to clean up after
we forked an LRM worker.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Env.pm      |  6 ++++++
 src/PVE/HA/Env/PVE2.pm | 10 ++++++++++
 src/PVE/HA/LRM.pm      |  8 ++------
 src/PVE/HA/Sim/Env.pm  |  6 ++++++
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index dc75985..f60c90b 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -218,4 +218,10 @@ sub can_fork {
     return $self->{plug}->can_fork();
 }
 
+sub after_fork {
+    my ($self) = @_;
+
+    return $self->{plug}->after_fork();
+}
+
 1;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 648aeef..c20fbef 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -413,4 +413,14 @@ sub can_fork {
     return 1;
 }
 
+sub after_fork {
+    my ($self) = @_;
+
+    # close inherited inotify FD from parent and reopen our own
+    PVE::INotify::inotify_close();
+    PVE::INotify::inotify_init();
+
+    PVE::Cluster::cfs_update();
+}
+
 1;
diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 4d60f7b..a1d466f 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -388,6 +388,8 @@ sub run_workers {
 			$haenv->log('err', "fork worker failed");
 			$count = 0; last; # abort, try later
 		    } elsif ($pid == 0) {
+			$haenv->after_fork(); # cleanup
+
 			# do work
 			my $res = -1;
 			eval {
@@ -609,12 +611,6 @@ sub exec_resource_agent {
 
     $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
-    PVE::INotify::inotify_close();
-
-    PVE::INotify::inotify_init();
-
-    PVE::Cluster::cfs_update();
-
     my $haenv = $self->{haenv};
 
     my $nodename = $haenv->nodename();
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index 4c3d167..5760192 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -320,4 +320,10 @@ sub can_fork {
     return 1;
 }
 
+sub after_fork {
+    my ($self) = @_;
+
+    # nothing to clean up in the simulation environment
+}
+
 1;
-- 
2.1.4





More information about the pve-devel mailing list