mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-01-10 01:18:01 +03:00
refactor vm_stop locked code
we want to reuse most of the code in the locked context of vm_stop for vm_reboot (since it really is just a vm_stop with a create_reboot_request in there) so we factor that out into _do_vm_stop and note that it has to be called in a locked context Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
64457ed4aa
commit
575d19dab5
@ -5768,23 +5768,9 @@ sub vm_stop_cleanup {
|
||||
warn $@ if $@; # avoid errors - just warn
|
||||
}
|
||||
|
||||
# Note: use $nockeck to skip tests if VM configuration file exists.
|
||||
# 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, $migratedfrom) = @_;
|
||||
|
||||
$force = 1 if !defined($force) && !$shutdown;
|
||||
|
||||
if ($migratedfrom){
|
||||
my $pid = check_running($vmid, $nocheck, $migratedfrom);
|
||||
kill 15, $pid if $pid;
|
||||
my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
|
||||
vm_stop_cleanup($storecfg, $vmid, $conf, $keepActive, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
PVE::QemuConfig->lock_config($vmid, sub {
|
||||
# call only in locked context
|
||||
sub _do_vm_stop {
|
||||
my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive) = @_;
|
||||
|
||||
my $pid = check_running($vmid, $nocheck);
|
||||
return if !$pid;
|
||||
@ -5861,6 +5847,26 @@ sub vm_stop {
|
||||
}
|
||||
|
||||
vm_stop_cleanup($storecfg, $vmid, $conf, $keepActive, 1) if $conf;
|
||||
}
|
||||
|
||||
# Note: use $nocheck to skip tests if VM configuration file exists.
|
||||
# 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, $migratedfrom) = @_;
|
||||
|
||||
$force = 1 if !defined($force) && !$shutdown;
|
||||
|
||||
if ($migratedfrom){
|
||||
my $pid = check_running($vmid, $nocheck, $migratedfrom);
|
||||
kill 15, $pid if $pid;
|
||||
my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
|
||||
vm_stop_cleanup($storecfg, $vmid, $conf, $keepActive, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
PVE::QemuConfig->lock_config($vmid, sub {
|
||||
_do_vm_stop($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user