[pve-devel] [RFC manager 1/4] fix #4474: ui: vm stop: ask if active shutdown tasks should be aborted
Friedrich Weber
f.weber at proxmox.com
Thu Jan 26 09:32:11 CET 2023
Before stopping a VM (KVM or LXC), the UI now checks if there is an
active shutdown task for the same VM by the logged-in user. If there
is at least one, the UI asks whether these tasks should be aborted
before trying to stop the VM. If the user answers "Yes", the UI sends
a VM stop request with the `overrule-shutdown` parameter set to 1. If
there are no active shutdown tasks, or the user answers "No", the UI
sends a VM stop request without `overrule-shutdown`.
To avoid an additional API request for querying active shutdown tasks,
we check the UI's current view of cluster tasks instead, which we
fetch from the `pve-cluster-tasks` store.
As the UI might hold an outdated task list, there are some
opportunities for races, e.g., the UI may miss a new shutdown task or
consider a shutdown task active even though it has already terminated.
These races either result in a surviving shutdown task that the user
still needs to abort manually, or a superfluous `override-shutdown=1`
parameter that does not actually abort any tasks. Since "stop
overrules shutdown" is merely a convenience feature, both outcomes
seem bearable.
Signed-off-by: Friedrich Weber <f.weber at proxmox.com>
---
www/manager6/Utils.js | 27 +++++++++++++++++++++++++++
www/manager6/dc/Tasks.js | 2 +-
www/manager6/lxc/CmdMenu.js | 14 +++++++++++++-
www/manager6/lxc/Config.js | 6 +++++-
www/manager6/qemu/CmdMenu.js | 14 +++++++++++++-
www/manager6/qemu/Config.js | 9 ++++++++-
6 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 3dd287e3..9e25e647 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1426,6 +1426,33 @@ Ext.define('PVE.Utils', {
}
},
+ // If there is an active task of type `taskType` by the current user for the
+ // given VMID, ask whether it should be aborted. Call `callback` accordingly.
+ askForOverruleShutdown: function(guestType, vm, taskType, callback) {
+ const vmidString = vm.vmid.toString();
+ const haEnabled = vm.hastate && vm.hastate !== 'unmanaged';
+ let shutdownTask = Ext.getStore('pve-cluster-tasks')?.findBy(function(task) {
+ return task.data.user === Proxmox.UserName &&
+ task.data.id === vmidString &&
+ task.data.status === undefined &&
+ task.data.type === taskType;
+ });
+ if (!haEnabled && shutdownTask >= 0) {
+ const msg = gettext('There are active {0} tasks for {1} {2}. Would you like to abort them before proceeding?');
+ Ext.Msg.show({
+ title: gettext('Confirm'),
+ icon: Ext.Msg.QUESTION,
+ buttons: Ext.Msg.YESNO,
+ msg: Ext.String.format(msg, taskType, guestType, vmidString),
+ callback: function(btn) {
+ callback(btn === 'yes');
+ },
+ });
+ } else {
+ callback(false);
+ }
+ },
+
// test automation helper
call_menu_handler: function(menu, text) {
let item = menu.query('menuitem').find(el => el.text === text);
diff --git a/www/manager6/dc/Tasks.js b/www/manager6/dc/Tasks.js
index 5344ede4..2001bf76 100644
--- a/www/manager6/dc/Tasks.js
+++ b/www/manager6/dc/Tasks.js
@@ -11,7 +11,7 @@ Ext.define('PVE.dc.Tasks', {
let me = this;
let taskstore = Ext.create('Proxmox.data.UpdateStore', {
- storeid: 'pve-cluster-tasks',
+ storeId: 'pve-cluster-tasks',
model: 'proxmox-tasks',
proxy: {
type: 'proxmox',
diff --git a/www/manager6/lxc/CmdMenu.js b/www/manager6/lxc/CmdMenu.js
index 56f36b5e..01631b1d 100644
--- a/www/manager6/lxc/CmdMenu.js
+++ b/www/manager6/lxc/CmdMenu.js
@@ -66,7 +66,19 @@ Ext.define('PVE.lxc.CmdMenu', {
iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
- handler: () => confirmedVMCommand('stop'),
+ handler: () => {
+ let msg = Proxmox.Utils.format_task_description('vzstop', info.vmid);
+ Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
+ if (btn === 'yes') {
+ PVE.Utils.askForOverruleShutdown('CT', info,
+ 'vzshutdown', overruleShutdown => {
+ const param = overruleShutdown ? { 'overrule-shutdown': 1 }
+ : undefined;
+ vm_command('stop', param);
+ });
+ }
+ });
+ },
},
{
text: gettext('Reboot'),
diff --git a/www/manager6/lxc/Config.js b/www/manager6/lxc/Config.js
index 23c17d2e..21d93058 100644
--- a/www/manager6/lxc/Config.js
+++ b/www/manager6/lxc/Config.js
@@ -81,7 +81,11 @@ Ext.define('PVE.lxc.Config', {
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
dangerous: true,
handler: function() {
- vm_command("stop");
+ PVE.Utils.askForOverruleShutdown('CT', vm,
+ 'vzshutdown', overruleShutdown => {
+ const param = overruleShutdown ? { 'overrule-shutdown': 1 } : undefined;
+ vm_command('stop', param);
+ });
},
iconCls: 'fa fa-stop',
}],
diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
index ccc5f74d..3edd2550 100644
--- a/www/manager6/qemu/CmdMenu.js
+++ b/www/manager6/qemu/CmdMenu.js
@@ -93,7 +93,19 @@ Ext.define('PVE.qemu.CmdMenu', {
iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
- handler: () => confirmedVMCommand('stop'),
+ handler: () => {
+ let msg = Proxmox.Utils.format_task_description('qmstop', info.vmid);
+ Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
+ if (btn === 'yes') {
+ PVE.Utils.askForOverruleShutdown('VM', info,
+ 'qmshutdown', overruleShutdown => {
+ const param = overruleShutdown ? { 'overrule-shutdown': 1 }
+ : undefined;
+ vm_command('stop', param);
+ });
+ }
+ });
+ },
},
{
text: gettext('Reboot'),
diff --git a/www/manager6/qemu/Config.js b/www/manager6/qemu/Config.js
index 94c540c5..68c41454 100644
--- a/www/manager6/qemu/Config.js
+++ b/www/manager6/qemu/Config.js
@@ -180,7 +180,14 @@ Ext.define('PVE.qemu.Config', {
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid),
handler: function() {
- vm_command("stop", { timeout: 30 });
+ PVE.Utils.askForOverruleShutdown('VM', vm,
+ 'qmshutdown', overruleShutdown => {
+ const param = { timeout: 30 };
+ if (overruleShutdown) {
+ param['overrule-shutdown'] = 1;
+ }
+ vm_command('stop', param);
+ });
},
iconCls: 'fa fa-stop',
}, {
--
2.30.2
More information about the pve-devel
mailing list