[pve-devel] [PATCH container v2] fix #3927: no error code when stopping a stopped container

Daniel Tschlatscher d.tschlatscher at proxmox.com
Fri Jun 24 16:02:09 CEST 2022


Stopping a container that was already stopped now no longer returns an
error code. This behaviour was adapted to match the return values for
VMs, to get a more consistent API. Both VMs and containers now return
an error when starting an already started guest, and both do not show
an error when stopping an already stopped guest.

Even though this is a really small change, some users might rely on
the containers returning the error. Therefore, this should probably
be considered a breaking change.

This change also has another side effect:
When the stop command for an HA-managed container was invoked, but the
container would stop in the meantime (e.g. because it crashed, ...), a
condition would arise which meant that the API call would die and
never reach the HA manager. Therefore not updating the requested HA
state for the container.
As a result, the container would be started again once the next HA
check was scheduled, in spite of the expected HA state being 'stopped'

This patches fixes this issue and brings it more in line with the
expected behaviour.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher at proxmox.com>
---
Changes from v2:
* This patch no longer includes also changing the return codes for
  already started containers.

 src/PVE/API2/LXC/Status.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index f7e3128..2c8fb4a 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -238,8 +238,6 @@ __PACKAGE__->register_method({
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root at pam';
 
-	die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
-
 	if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
 
 	    my $hacmd = sub {
@@ -260,6 +258,8 @@ __PACKAGE__->register_method({
 
 		syslog('info', "stopping CT $vmid: $upid\n");
 
+		return if !PVE::LXC::check_running($vmid);
+
 		my $conf = PVE::LXC::Config->load_config($vmid);
 		if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
 		    PVE::LXC::Config->check_lock($conf);
-- 
2.30.2






More information about the pve-devel mailing list