[pve-devel] [PATCH 7/7] cleanup ressources on target host at phase2_cleanup.
Alexandre Derumier
aderumier at odiso.com
Thu Aug 16 07:25:27 CEST 2012
we call vm_stop to target host,
to be sure that kvm process is killed (but it should kill itself),
and deactivate volumes
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 8 +++++++-
PVE/QemuMigrate.pm | 10 ++++++++--
PVE/QemuServer.pm | 10 +++++++++-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 2087a75..71585a5 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1277,6 +1277,7 @@ __PACKAGE__->register_method({
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid'),
skiplock => get_standard_option('skiplock'),
+ migratedfrom => get_standard_option('pve-node',{ optional => 1 }),
timeout => {
description => "Wait maximal timeout seconds.",
type => 'integer',
@@ -1313,6 +1314,11 @@ __PACKAGE__->register_method({
raise_param_exc({ keepActive => "Only root may use this option." })
if $keepActive && $authuser ne 'root at pam';
+ my $migratedfrom = extract_param($param, 'migratedfrom');
+ raise_param_exc({ migratedfrom => "Only root may use this option." })
+ if $migratedfrom && $authuser ne 'root at pam';
+
+
my $storecfg = PVE::Storage::config();
if (&$vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
@@ -1340,7 +1346,7 @@ __PACKAGE__->register_method({
syslog('info', "stop VM $vmid: $upid\n");
PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0,
- $param->{timeout}, 0, 1, $keepActive);
+ $param->{timeout}, 0, 1, $keepActive, $migratedfrom);
return;
};
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index cb015cc..641318c 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -391,9 +391,15 @@ sub phase2_cleanup {
$self->log('err', $err);
}
- ## fixme : vm_stop_cleanup on target vm
-
+ ## cleanup ressources on target host
+ my $nodename = PVE::INotify::nodename();
+ my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $vmid, '--skiplock', '--migratedfrom', $nodename];
+ eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+ if (my $err = $@) {
+ $self->log('err', $err);
+ $self->{errors} = 1;
+ }
}
sub phase3 {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 70475a5..8993f4e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2770,12 +2770,20 @@ sub vm_stop_cleanup {
# We need that when migration VMs to other nodes (files already moved)
# Note: we set $keepActive in vzdump stop mode - volumes need to stay active
sub vm_stop {
- my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive) = @_;
+ my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive, $migratedfrom) = @_;
$timeout = 60 if !defined($timeout);
$force = 1 if !defined($force) && !$shutdown;
+ if($migratedfrom){
+ my $pid = check_running($vmid, $nocheck, $migratedfrom);
+ kill 15, $pid if $pid;
+ my $conf = load_config($vmid, $migratedfrom);
+ vm_stop_cleanup($storecfg, $vmid, $conf, $keepActive) if $conf;
+ return;
+ }
+
lock_config($vmid, sub {
my $pid = check_running($vmid, $nocheck);
--
1.7.2.5
More information about the pve-devel
mailing list