[pve-devel] [PATCH ha-manager 07/10] allocate HA Env only once per service and node

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Dec 21 16:44:44 CET 2016


Do not allocate the HA Environment every time we fork a new CRM or
LRM, but once at the start of the Simulator for all nodes.
This can be done as the Env does not saves any state and thus can be
reused, we use this also in the TestHardware class.
Making the behavior of both Hardware classes more similar allows us
to refactor out some common code.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Sim/RTHardware.pm | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/PVE/HA/Sim/RTHardware.pm b/src/PVE/HA/Sim/RTHardware.pm
index 8bdd9d0..1835bee 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -40,7 +40,10 @@ sub new {
 	my $d = $self->{nodes}->{$node};
 
 	$d->{crm} = undef; # create on power on
+	$d->{crm_env} = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'crm');
+
 	$d->{lrm} = undef; # create on power on
+	$d->{lrm_env} = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'lrm');
     }
 
     $self->create_main_window();
@@ -79,7 +82,7 @@ sub read_manager_status {
 }
 
 sub fork_daemon {
-    my ($self, $lockfh, $type, $node) = @_;
+    my ($self, $lockfh, $type, $haenv) = @_;
 
     my @psync = POSIX::pipe();
 
@@ -123,8 +126,6 @@ sub fork_daemon {
 
 	if ($type eq 'crm') {
 
-	    my $haenv = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'crm');
-
 	    my $crm = PVE::HA::CRM->new($haenv);
 
 	    for (;;) {
@@ -140,8 +141,6 @@ sub fork_daemon {
 
 	} else {
 
-	    my $haenv = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'lrm');
-
 	    my $lrm = PVE::HA::LRM->new($haenv);
 
 	    for (;;) {
@@ -211,8 +210,8 @@ sub sim_hardware_cmd {
 	if ($cmd eq 'power') {
 	    if ($cstatus->{$node}->{power} ne $action) {
 		if ($action eq 'on') {
-		    $d->{crm} = $self->fork_daemon($lockfh, 'crm', $node) if !$d->{crm};
-		    $d->{lrm} = $self->fork_daemon($lockfh, 'lrm', $node) if !$d->{lrm};
+		    $d->{crm} = $self->fork_daemon($lockfh, 'crm', $d->{crm_env}) if !$d->{crm};
+		    $d->{lrm} = $self->fork_daemon($lockfh, 'lrm', $d->{lrm_env}) if !$d->{lrm};
 		} else {
 		    if ($d->{crm}) {
 			$self->log('info', "crm on node '$node' killed by poweroff");
-- 
2.1.4





More information about the pve-devel mailing list