]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
replace can_fork with get_max_workers
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 10 Feb 2016 10:58:24 +0000 (11:58 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 11 Feb 2016 09:03:47 +0000 (10:03 +0100)
This patch implements the use of the new max_workers setting from
the datacenter.cfg.

Adding a 'get_max_worker' method to the enviornment allows us to
do that and to replace 'can_fork' with that method.

can_fork isn't needed anymore as get_max_worker may simply return 0
to signal that the respective enviornment can not fork.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Env.pm
src/PVE/HA/Env/PVE2.pm
src/PVE/HA/LRM.pm
src/PVE/HA/Sim/Env.pm
src/PVE/HA/Sim/TestEnv.pm

index b5aba32e9aedf30a3717ddc71d8a84c35ec5385d..3d96a6e870fff779da644115b04e41d2af427370 100644 (file)
@@ -205,17 +205,18 @@ sub watchdog_close {
     return $self->{plug}->watchdog_close($wfh);
 }
 
-# hack to support regression tests
-sub can_fork {
+sub after_fork {
     my ($self) = @_;
 
-    return $self->{plug}->can_fork();
+    return $self->{plug}->after_fork();
 }
 
-sub after_fork {
+# maximal number of workers to fork,
+# return 0 as a hack to support regression tests
+sub get_max_workers {
     my ($self) = @_;
 
-    return $self->{plug}->after_fork();
+    return $self->{plug}->get_max_workers();
 }
 
 1;
index e4b0535d9e179dafb537b0ef732e1ef83ed90a42..7e2906da23a957e8dd43c07d164989a86fe3e375 100644 (file)
@@ -389,12 +389,6 @@ sub watchdog_close {
     }
 }
 
-sub can_fork {
-    my ($self) = @_;
-
-    return 1;
-}
-
 sub after_fork {
     my ($self) = @_;
 
@@ -405,4 +399,12 @@ sub after_fork {
     PVE::Cluster::cfs_update();
 }
 
+sub get_max_workers {
+    my ($self) = @_;
+
+    my $datacenterconfig = cfs_read_file('datacenter.cfg');
+
+    return $datacenterconfig->{max_workers} || 4;
+}
+
 1;
index d7b54da6bdaed63b90c5dad56381c4b087740f1b..1f554fa5dd9b4e015f615746f0be80c28034dac5 100644 (file)
@@ -366,8 +366,8 @@ sub run_workers {
 
     my $starttime = $haenv->get_time();
 
-    # start workers
-    my $max_workers = 4;
+    # number of workers to start, if 0 we exec the command directly witouth forking
+    my $max_workers = $haenv->get_max_workers();
 
     my $sc = $haenv->read_service_config();
 
@@ -375,10 +375,13 @@ sub run_workers {
        my $count =  $self->check_active_workers();
 
        foreach my $sid (keys %{$self->{workers}}) {
-           last if $count >= $max_workers;
+           last if $count >= $max_workers && $max_workers > 0;
+
            my $w = $self->{workers}->{$sid};
            if (!$w->{pid}) {
-               if ($haenv->can_fork()) {
+               # only fork if we may else call exec_resource_agent
+               # directly (e.g. for regression tests)
+               if ($max_workers > 0) {
                    my $pid = fork();
                    if (!defined($pid)) {
                        $haenv->log('err', "fork worker failed");
index e1549889296827bff586485e2ae9cc7b7f1883b3..246ac6046358531d7b35d3155aef1629cdb4409f 100644 (file)
@@ -308,16 +308,17 @@ sub watchdog_close {
     return $self->{hardware}->watchdog_close($wfh);
 }
 
-sub can_fork {
+sub after_fork {
     my ($self) = @_;
 
-    return 1;
+    # nothing to clean up in the simulation environment
 }
 
-sub after_fork {
+
+sub get_max_workers {
     my ($self) = @_;
 
-    # nothing to clean up in the simulation environment
+    return 4;
 }
 
 1;
index 414c27438d705e3d747f27d8b5774bd877be7092..f4f70c977b14f821474afd35aab364a49b1a74e2 100644 (file)
@@ -109,12 +109,6 @@ sub loop_end_hook {
     $self->{cur_time} += 1; # easier for simulation
 }
 
-sub can_fork {
-    my ($self) = @_;
-
-    return 0;
-}
-
 sub is_node_shutdown {
     my ($self) = @_;
 
@@ -126,4 +120,11 @@ sub is_node_shutdown {
     return defined($cstatus->{$node}->{shutdown}) ? 1 : 0;
 }
 
+# must be 0 as we do not want to fork in the regression tests
+sub get_max_workers {
+    my ($self) = @_;
+
+    return 0;
+}
+
 1;