[pve-devel] [PATCH ha-manager 1/7] sim: allocate HA Env only once per service and node

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 13 14:22:13 CET 2017


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 in following commits.

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 0b29340..145d73b 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -39,7 +39,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();
@@ -78,7 +81,7 @@ sub read_manager_status {
 }
 
 sub fork_daemon {
-    my ($self, $lockfh, $type, $node) = @_;
+    my ($self, $lockfh, $type, $haenv) = @_;
 
     my @psync = POSIX::pipe();
 
@@ -122,8 +125,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 (;;) {
@@ -139,8 +140,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 (;;) {
@@ -207,8 +206,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