From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Friedrich Weber <f.weber@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [RFC container 2/4] fix #4474: lxc api: add overrule-shutdown parameter to stop endpoint
Date: Fri, 17 Nov 2023 14:09:00 +0100 [thread overview]
Message-ID: <no64qbjndkwmnn62jmp5siavnwkluoalgmgiyefdxt3ibsz6h2@khuefkefgjw7> (raw)
In-Reply-To: <20230126083214.711099-3-f.weber@proxmox.com>
On Thu, Jan 26, 2023 at 09:32:12AM +0100, Friedrich Weber wrote:
> The new `overrule-shutdown` parameter is boolean and defaults to 0. If
> it is 1, all active `vzshutdown` tasks by the current user for the same
> CT are aborted before attempting to stop the CT.
>
> Passing `overrule-shutdown=1` is forbidden for HA resources.
>
> Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
> ---
> src/PVE/API2/LXC/Status.pm | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
> index f7e3128..d1d67f4 100644
> --- a/src/PVE/API2/LXC/Status.pm
> +++ b/src/PVE/API2/LXC/Status.pm
> @@ -221,6 +221,12 @@ __PACKAGE__->register_method({
> node => get_standard_option('pve-node'),
> vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
> skiplock => get_standard_option('skiplock'),
> + 'overrule-shutdown' => {
> + description => "Abort any active 'vzshutdown' task by the current user for this CT before stopping",
> + optional => 1,
> + type => 'boolean',
> + default => 0,
> + }
> },
> },
> returns => {
> @@ -238,10 +244,15 @@ __PACKAGE__->register_method({
> raise_param_exc({ skiplock => "Only root may use this option." })
> if $skiplock && $authuser ne 'root@pam';
>
> + my $overrule_shutdown = extract_param($param, 'overrule-shutdown');
> +
> 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') {
>
> + raise_param_exc({ 'overrule-shutdown' => "Not applicable for HA resources." })
> + if $overrule_shutdown;
> +
> my $hacmd = sub {
> my $upid = shift;
>
> @@ -272,6 +283,11 @@ __PACKAGE__->register_method({
> return $rpcenv->fork_worker('vzstop', $vmid, $authuser, $realcmd);
> };
>
> + if ($overrule_shutdown) {
> + my $overruled_tasks = PVE::GuestHelpers::overrule_tasks('vzshutdown', $authuser, $vmid);
> + syslog('info', "overruled vzshutdown tasks: " . join(", ", $overruled_tasks->@*) . "\n");
> + };
> +
^ So this part is fine (mostly¹)
> return PVE::LXC::Config->lock_config($vmid, $lockcmd);
^ Here we lock first, then fork the worker, then do `vm_stop` with the
config lock inherited.
This means that creating multiple shutdown tasks before using one with
override=true could cause the override task to cancel the *first* ongoing
shutdown task, then move on to the `lock_config` call - in the meantime
a second shutdown task acquires this very lock and performs another
long-running shutdown, causing the `override` parameter to be
ineffective.
We should switch the ordering here: first fork the worker, then lock.
(¹ And your new chunk would go into the worker as well)
Unless I'm missing something, but AFAICT the current ordering there is
rather ... bad :-)
next prev parent reply other threads:[~2023-11-17 13:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 8:32 [pve-devel] [RFC manager/container/qemu-server/guest-common 0/4] fix #4474: stop tasks may overrule shutdown tasks Friedrich Weber
2023-01-26 8:32 ` [pve-devel] [RFC manager 1/4] fix #4474: ui: vm stop: ask if active shutdown tasks should be aborted Friedrich Weber
2023-01-26 8:32 ` [pve-devel] [RFC container 2/4] fix #4474: lxc api: add overrule-shutdown parameter to stop endpoint Friedrich Weber
2023-11-17 13:09 ` Wolfgang Bumiller [this message]
2023-12-01 9:57 ` Friedrich Weber
2024-01-02 13:34 ` Friedrich Weber
2023-01-26 8:32 ` [pve-devel] [RFC qemu-server 3/4] fix #4474: qemu " Friedrich Weber
2023-11-17 13:12 ` Wolfgang Bumiller
2023-01-26 8:32 ` [pve-devel] [RFC guest-common 4/4] guest helpers: add helper to overrule active tasks of a specific type Friedrich Weber
2023-11-17 12:53 ` Wolfgang Bumiller
2023-12-01 9:57 ` Friedrich Weber
2023-09-27 9:04 ` [pve-devel] [RFC manager/container/qemu-server/guest-common 0/4] fix #4474: stop tasks may overrule shutdown tasks Friedrich Weber
2023-11-17 12:31 ` Wolfgang Bumiller
2023-12-01 9:57 ` Friedrich Weber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=no64qbjndkwmnn62jmp5siavnwkluoalgmgiyefdxt3ibsz6h2@khuefkefgjw7 \
--to=w.bumiller@proxmox.com \
--cc=f.weber@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox