diff --git a/Makefile b/Makefile index 6e43e746..fbebf51b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ RELEASE=2.0 VERSION=2.0 PACKAGE=qemu-server -PKGREL=11 +PKGREL=12 DESTDIR= PREFIX=/usr diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index b40149ed..56fefff8 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -991,6 +991,12 @@ __PACKAGE__->register_method({ type => 'integer', minimum => 0, optional => 1, + }, + forceStop => { + description => "Make sure the VM stops.", + type => 'boolean', + optional => 1, + default => 0, } }, }, @@ -1021,7 +1027,8 @@ __PACKAGE__->register_method({ syslog('info', "shutdown VM $vmid: $upid\n"); - PVE::QemuServer::vm_shutdown($storecfg, $vmid, $skiplock, $param->{timeout}); + PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, + $param->{timeout}, 1, $param->{forceStop}); return; }; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 10c7d8e4..6561462d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2575,43 +2575,14 @@ sub vm_stop_cleanup { PVE::Storage::deactivate_volumes($storecfg, $vollist); } -sub vm_shutdown { - my ($storecfg, $vmid, $skiplock, $timeout) = @_; - - $timeout = 60 if !$timeout; - - lock_config($vmid, sub { - - my $conf = load_config($vmid); - - check_lock($conf) if !$skiplock; - - vm_monitor_command($vmid, "system_powerdown"); - - my $pid = check_running($vmid); - - if ($pid && $timeout) { - print "waiting until VM $vmid stopps (PID $pid)\n"; - - my $count = 0; - while (($count < $timeout) && check_running($vmid)) { - $count++; - sleep 1; - } - - die "shutdown failed - got timeout\n" if check_running($vmid); - } - - vm_stop_cleanup($storecfg, $vmid, $conf); - }); -} - # Note: use $nockeck to skip tests if VM configuration file exists. # We need that when migration VMs to other nodes (files already moved) sub vm_stop { - my ($storecfg, $vmid, $skiplock, $nocheck, $timeout) = @_; + my ($storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force) = @_; - $timeout = 60 if !$timeout; + $timeout = 60 if !defined($timeout); + + $force = 1 if !defined($force) && !$shutdown; lock_config($vmid, sub { @@ -2624,7 +2595,13 @@ sub vm_stop { check_lock($conf) if !$skiplock; } - eval { vm_monitor_command($vmid, "quit", $nocheck); }; + eval { + if ($shutdown) { + vm_monitor_command($vmid, "system_powerdown", $nocheck); + } else { + vm_monitor_command($vmid, "quit", $nocheck); + } + }; my $err = $@; if (!$err) { @@ -2635,12 +2612,23 @@ sub vm_stop { } if ($count >= $timeout) { - warn "VM still running - terminating now with SIGTERM\n"; - kill 15, $pid; + if ($force) { + warn "VM still running - terminating now with SIGTERM\n"; + kill 15, $pid; + } else { + die "VM quit/powerdown failed - got timeout\n"; + } + } else { + vm_stop_cleanup($storecfg, $vmid, $conf) if $conf; + return; } } else { - warn "VM quit failed - terminating now with SIGTERM\n"; - kill 15, $pid; + if ($force) { + warn "VM quit/powerdown failed - terminating now with SIGTERM\n"; + kill 15, $pid; + } else { + die "VM quit/powerdown failed\n"; + } } # wait again diff --git a/changelog.Debian b/changelog.Debian index bb1a557a..6dda9074 100644 --- a/changelog.Debian +++ b/changelog.Debian @@ -1,3 +1,9 @@ +qemu-server (2.0-12) unstable; urgency=low + + * implement forceStop option for shutdown + + -- Proxmox Support Team Thu, 15 Dec 2011 12:58:00 +0100 + qemu-server (2.0-11) unstable; urgency=low * do not use ehci by default