[pve-devel] [PATCH ha-manager 3/3] move upid_wait from PVE2 env to HA::Tools
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Jan 27 13:16:35 CET 2016
We can now use the new wait_upid from PVE::Tools and we output a
"Task still active" every five seconds instead of every second,
so we trash the log less.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/Env/PVE2.pm | 12 ------------
src/PVE/HA/Resources/PVECT.pm | 8 +++++---
src/PVE/HA/Resources/PVEVM.pm | 8 +++++---
src/PVE/HA/Tools.pm | 12 ++++++++++++
4 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index c20fbef..77e75ac 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -395,18 +395,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 781a36a..939d888 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -3,6 +3,8 @@ package PVE::HA::Resources::PVECT;
use strict;
use warnings;
+use PVE::HA::Tools;
+
use PVE::LXC;
use PVE::API2::LXC;
use PVE::API2::LXC::Status;
@@ -59,7 +61,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 {
@@ -76,7 +78,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 {
@@ -99,7 +101,7 @@ sub migrate {
my $oldconfig = $class->config_file($id, $nodename);
my $upid = PVE::API2::LXC->migrate_vm($params);
- $haenv->upid_wait($upid);
+ PVE::HA::Tools::upid_wait($upid, $haenv);
# check if vm really moved
return !(-f $oldconfig);
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index fd96ed3..cb03d23 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -3,6 +3,8 @@ package PVE::HA::Resources::PVEVM;
use strict;
use warnings;
+use PVE::HA::Tools;
+
use PVE::QemuServer;
use PVE::API2::Qemu;
@@ -58,7 +60,7 @@ sub start {
};
my $upid = PVE::API2::Qemu->vm_start($params);
- $haenv->upid_wait($upid);
+ PVE::HA::Tools::upid_wait($upid, $haenv);
}
sub shutdown {
@@ -75,7 +77,7 @@ sub shutdown {
};
my $upid = PVE::API2::Qemu->vm_shutdown($params);
- $haenv->upid_wait($upid);
+ PVE::HA::Tools::upid_wait($upid, $haenv);
}
@@ -99,7 +101,7 @@ sub migrate {
my $oldconfig = $class->config_file($id, $nodename);
my $upid = PVE::API2::Qemu->migrate_vm($params);
- $haenv->upid_wait($upid);
+ PVE::HA::Tools::upid_wait($upid, $haenv);
# check if vm really moved
return !(-f $oldconfig);
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
index a04fd2e..2814453 100644
--- a/src/PVE/HA/Tools.pm
+++ b/src/PVE/HA/Tools.pm
@@ -6,6 +6,7 @@ use JSON;
use PVE::JSONSchema;
use PVE::Tools;
use PVE::Cluster;
+use PVE::ProcFSTools;
# return codes used in the ha environment
# mainly by the resource agents
@@ -165,6 +166,17 @@ sub count_fenced_services {
return $count;
}
+sub upid_wait {
+ my ($upid, $haenv) = @_;
+
+ my $waitfunc = sub {
+ my $task = PVE::Tools::upid_encode(shift);
+ $haenv->log('info', "Task '$task' still active, waiting");
+ };
+
+ PVE::ProcFSTools::upid_wait($upid, $waitfunc, 5);
+}
+
# bash auto completion helper
sub complete_sid {
--
2.1.4
More information about the pve-devel
mailing list