[pve-devel] [PATCH pve-ha-manager 4/7] Sim/Hardware: allow recursive locking in queue_crm_commands

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Dec 21 16:38:05 CET 2015


To allow regression testing for service migrate/relocate actions
we need to avoid a deadlock as we queue commands from the already
locked sim_hardware_cmd method.
This isn't real recursive locking (obviously) but a easy hack to let
queue_crm_commands know that it's called from a locked context.

We _cannot_ remove the locking in queue_crm_commands as the
simulator runs threaded and thus needs atomicity here, else we could
loose crm commands.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Sim/Hardware.pm | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 8424853..0f07937 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -141,8 +141,10 @@ sub change_service_location {
     $self->write_service_config($conf);
 }
 
+# $is_locked is a hack to avoid a deadlock when we migrate/relocate
+# in the regression test
 sub queue_crm_commands {
-    my ($self, $cmd) = @_;
+    my ($self, $cmd, $is_locked) = @_;
 
     chomp $cmd;
 
@@ -155,9 +157,12 @@ sub queue_crm_commands {
 	$data .= "$cmd\n";
 	PVE::Tools::file_set_contents($filename, $data);
     };
- 
-    $self->global_lock($code);
 
+    if ($is_locked) {
+	&$code();
+    } else {
+	$self->global_lock($code);
+    }
     return undef;
 }
 
-- 
2.1.4





More information about the pve-devel mailing list