[pve-devel] [RFC ha-manager 7/8] move upid_wait from PVE2 env to HA::Tools

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 22 17:06:41 CET 2016


This is needed when stop calling the resource plugin method from
inside the PVE2 class.
We can now also use the new wait_upid from PVE::Tools and we
out put a "Task still active" every three seconds not every seconds
so we trash the log less while still seeing if something goes on.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Env/PVE2.pm        | 12 ------------
 src/PVE/HA/Resources/PVECT.pm |  6 +++---
 src/PVE/HA/Resources/PVEVM.pm |  6 +++---
 src/PVE/HA/Tools.pm           | 18 ++++++++++++++++++
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index bafd4ae..e2a4e8e 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -388,18 +388,6 @@ sub watchdog_close {
     }
 }
 
-sub upid_wait {
-    my ($self, $upid) = @_;
-
-    my $task = PVE::Tools::upid_decode($upid);
-
-    CORE::sleep(1);
-    while (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart})) {
-	$self->log('debug', "Task still active, waiting");
-	CORE::sleep(1);
-    }
-}
-
 sub can_fork {
     my ($self) = @_;
 
diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index b6f936f..4bde66f 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -68,7 +68,7 @@ sub start {
     };
 
     my $upid = PVE::API2::LXC::Status->vm_start($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 sub shutdown {
@@ -85,7 +85,7 @@ sub shutdown {
     };
 
     my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 sub migrate {
@@ -106,7 +106,7 @@ sub migrate {
     }
 
     my $upid = PVE::API2::LXC->migrate_vm($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 sub check_running {
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index 43e1074..7ca469a 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -67,7 +67,7 @@ sub start {
     };
 
     my $upid = PVE::API2::Qemu->vm_start($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 sub shutdown {
@@ -84,7 +84,7 @@ sub shutdown {
     };
 
     my $upid = PVE::API2::Qemu->vm_shutdown($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 
@@ -106,7 +106,7 @@ sub migrate {
     }
 
     my $upid = PVE::API2::Qemu->migrate_vm($params);
-    $haenv->upid_wait($upid);
+    PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
 sub check_running {
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
index a04fd2e..88c14dd 100644
--- a/src/PVE/HA/Tools.pm
+++ b/src/PVE/HA/Tools.pm
@@ -165,6 +165,24 @@ sub count_fenced_services {
     return $count;
 }
 
+sub upid_wait {
+    my ($upid, $haenv) = @_;
+
+    my $skip = 0;
+    my $waitfunc = sub {
+	my $task = PVE::Tools::upid_encode(shift);
+	# do not spam to the log for long running tasks
+	if ($skip >= 2) {
+	    $haenv->log('info', "Task '$task' still active, waiting");
+	    $skip = 0;
+	} else {
+	    $skip++;
+	}
+    };
+
+    PVE::Tools::upid_wait($upid, $waitfunc);
+}
+
 # bash auto completion helper
 
 sub complete_sid {
-- 
2.1.4





More information about the pve-devel mailing list