mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-29 18:45:29 +00:00
we call vm_stop to target host,
to be sure that kvm process is killed (but it should kill itself), and deactivate volumes I slightly modified this patch (orig. from Alexandre) so that it apply cleanly.
This commit is contained in:
parent
e52bd94c7e
commit
af30308f36
@ -1277,6 +1277,7 @@ __PACKAGE__->register_method({
|
|||||||
node => get_standard_option('pve-node'),
|
node => get_standard_option('pve-node'),
|
||||||
vmid => get_standard_option('pve-vmid'),
|
vmid => get_standard_option('pve-vmid'),
|
||||||
skiplock => get_standard_option('skiplock'),
|
skiplock => get_standard_option('skiplock'),
|
||||||
|
migratedfrom => get_standard_option('pve-node',{ optional => 1 }),
|
||||||
timeout => {
|
timeout => {
|
||||||
description => "Wait maximal timeout seconds.",
|
description => "Wait maximal timeout seconds.",
|
||||||
type => 'integer',
|
type => 'integer',
|
||||||
@ -1313,6 +1314,11 @@ __PACKAGE__->register_method({
|
|||||||
raise_param_exc({ keepActive => "Only root may use this option." })
|
raise_param_exc({ keepActive => "Only root may use this option." })
|
||||||
if $keepActive && $authuser ne 'root@pam';
|
if $keepActive && $authuser ne 'root@pam';
|
||||||
|
|
||||||
|
my $migratedfrom = extract_param($param, 'migratedfrom');
|
||||||
|
raise_param_exc({ migratedfrom => "Only root may use this option." })
|
||||||
|
if $migratedfrom && $authuser ne 'root@pam';
|
||||||
|
|
||||||
|
|
||||||
my $storecfg = PVE::Storage::config();
|
my $storecfg = PVE::Storage::config();
|
||||||
|
|
||||||
if (&$vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
|
if (&$vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
|
||||||
@ -1340,7 +1346,7 @@ __PACKAGE__->register_method({
|
|||||||
syslog('info', "stop VM $vmid: $upid\n");
|
syslog('info', "stop VM $vmid: $upid\n");
|
||||||
|
|
||||||
PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0,
|
PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0,
|
||||||
$param->{timeout}, 0, 1, $keepActive);
|
$param->{timeout}, 0, 1, $keepActive, $migratedfrom);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -382,6 +382,9 @@ sub phase2 {
|
|||||||
sub phase2_cleanup {
|
sub phase2_cleanup {
|
||||||
my ($self, $vmid, $err) = @_;
|
my ($self, $vmid, $err) = @_;
|
||||||
|
|
||||||
|
return if !$self->{errors};
|
||||||
|
$self->{phase2errors} = 1;
|
||||||
|
|
||||||
$self->log('info', "aborting phase 2 - cleanup resources");
|
$self->log('info', "aborting phase 2 - cleanup resources");
|
||||||
|
|
||||||
my $conf = $self->{vmconf};
|
my $conf = $self->{vmconf};
|
||||||
@ -391,15 +394,22 @@ sub phase2_cleanup {
|
|||||||
$self->log('err', $err);
|
$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 {
|
sub phase3 {
|
||||||
my ($self, $vmid) = @_;
|
my ($self, $vmid) = @_;
|
||||||
|
|
||||||
my $volids = $self->{volumes};
|
my $volids = $self->{volumes};
|
||||||
|
return if $self->{phase2errors};
|
||||||
|
|
||||||
# destroy local copies
|
# destroy local copies
|
||||||
foreach my $volid (@$volids) {
|
foreach my $volid (@$volids) {
|
||||||
@ -416,6 +426,7 @@ sub phase3_cleanup {
|
|||||||
my ($self, $vmid, $err) = @_;
|
my ($self, $vmid, $err) = @_;
|
||||||
|
|
||||||
my $conf = $self->{vmconf};
|
my $conf = $self->{vmconf};
|
||||||
|
return if $self->{phase2errors};
|
||||||
|
|
||||||
# move config to remote node
|
# move config to remote node
|
||||||
my $conffile = PVE::QemuServer::config_file($vmid);
|
my $conffile = PVE::QemuServer::config_file($vmid);
|
||||||
|
@ -2910,10 +2910,18 @@ sub vm_stop_cleanup {
|
|||||||
# We need that when migration VMs to other nodes (files already moved)
|
# 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
|
# Note: we set $keepActive in vzdump stop mode - volumes need to stay active
|
||||||
sub vm_stop {
|
sub vm_stop {
|
||||||
my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive) = @_;
|
my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive, $migratedfrom) = @_;
|
||||||
|
|
||||||
$force = 1 if !defined($force) && !$shutdown;
|
$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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock_config($vmid, sub {
|
lock_config($vmid, sub {
|
||||||
|
|
||||||
my $pid = check_running($vmid, $nocheck);
|
my $pid = check_running($vmid, $nocheck);
|
||||||
|
Loading…
Reference in New Issue
Block a user