]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/Sim/Resources.pm
cleanup backup & mounted locks after recovery (fixes #1100)
[pve-ha-manager.git] / src / PVE / HA / Sim / Resources.pm
index 7e13483b4fab1cc4174ed2367c5095f7a0f05c60..bccc0e6b9ef39002c6ed2089ec02d4bb790bcfa1 100644 (file)
@@ -34,27 +34,22 @@ sub config_file {
     return "$nodename/$service_type:$id";
 }
 
-sub is_on_node {
-    my ($class, $haenv, $node, $id) = @_;
-
-    my $service_type = $class->type();
-    my $hardware = $haenv->hardware();
-    my $ss = $hardware->read_service_status($node);
-
-    return defined($ss->{"$service_type:$id"}) ? 1 : 0;
-}
-
 sub start {
     my ($class, $haenv, $id) = @_;
 
-    my $service_type = $class->type();
+    my $sid = $class->type() . ":$id";
     my $nodename = $haenv->nodename();
     my $hardware = $haenv->hardware();
     my $ss = $hardware->read_service_status($nodename);
 
+    if (my $lock = $hardware->service_has_lock($sid)) {
+       $haenv->log('err', "service '$sid' locked ($lock), unable to start!");
+       return;
+    }
+
     $haenv->sleep(2);
 
-    $ss->{"$service_type:$id"} = 1;
+    $ss->{$sid} = 1;
 
     $hardware->write_service_status($nodename, $ss);
 
@@ -63,14 +58,19 @@ sub start {
 sub shutdown {
     my ($class, $haenv, $id) = @_;
 
-    my $service_type = $class->type();
+    my $sid = $class->type() . ":$id";
     my $nodename = $haenv->nodename();
     my $hardware = $haenv->hardware();
     my $ss = $hardware->read_service_status($nodename);
 
+    if (my $lock = $hardware->service_has_lock($sid)) {
+       $haenv->log('err', "service '$sid' locked ($lock), unable to shutdown!");
+       return;
+    }
+
     $haenv->sleep(2);
 
-    $ss->{"$service_type:$id"} = 0;
+    $ss->{$sid} = 0;
 
     $hardware->write_service_status($nodename, $ss);
 }
@@ -99,6 +99,11 @@ sub migrate {
     my $cmd = $online ? "migrate" : "relocate";
     $haenv->log("info", "service $sid - start $cmd to node '$target'");
 
+    if (my $lock = $hardware->service_has_lock($sid)) {
+       $haenv->log('err', "service '$sid' locked ($lock), unable to $cmd!");
+       return;
+    }
+
     # explicitly shutdown if $online isn't true (relocate)
     if (!$online && $class->check_running($haenv, $id)) {
        $haenv->log("info", "stopping service $sid (relocate)");
@@ -108,12 +113,30 @@ sub migrate {
        $haenv->sleep(2); # (live) migration time
     }
 
-    $haenv->change_service_location($sid, $nodename, $target);
+    $hardware->change_service_location($sid, $nodename, $target);
     $haenv->log("info", "service $sid - end $cmd to node '$target'");
     # ensure that the old node doesn't has the service anymore
     delete $ss->{$sid};
     $hardware->write_service_status($nodename, $ss);
+
+    # check if resource really moved
+    return defined($ss->{$sid}) ? 0 : 1;
 }
 
 
+sub remove_locks {
+    my ($self, $haenv, $id, $locks, $service_node) = @_;
+
+    my $sid = $self->type() . ":$id";
+    my $hardware = $haenv->hardware();
+
+    foreach my $lock (@$locks) {
+       if (my $removed_lock = $hardware->unlock_service($sid, $lock)) {
+           return $removed_lock;
+       }
+    }
+
+    return undef;
+}
+
 1;