[pve-devel] [PATCH guest-common v2 1/6] guest helpers: add helper to overrule active tasks of a specific type

Friedrich Weber f.weber at proxmox.com
Tue Jan 30 18:10:52 CET 2024


This helper is used to abort any active qmshutdown/vzshutdown tasks
before attempting to stop a VM/CT (if requested).

Signed-off-by: Friedrich Weber <f.weber at proxmox.com>
---

Notes:
    no changes v1 -> v2

 src/PVE/GuestHelpers.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
index 961a7b8..bd94ed2 100644
--- a/src/PVE/GuestHelpers.pm
+++ b/src/PVE/GuestHelpers.pm
@@ -416,4 +416,22 @@ sub check_vnet_access {
 	if !($tag || $trunks);
 }
 
+sub overrule_tasks {
+    my ($type, $user, $vmid) = @_;
+
+    my $active_tasks = PVE::INotify::read_file('active');
+    my $res = [];
+    for my $task (@$active_tasks) {
+       if (!$task->{saved}
+           && $task->{type} eq $type
+           && $task->{user} eq $user
+           && $task->{id} eq $vmid
+       ) {
+           PVE::RPCEnvironment->check_worker($task->{upid}, 1);
+           push @$res, $task->{upid};
+       }
+    }
+    return $res;
+}
+
 1;
-- 
2.39.2





More information about the pve-devel mailing list