[pve-devel] [RFC guest-common 4/4] guest helpers: add helper to overrule active tasks of a specific type

Friedrich Weber f.weber at proxmox.com
Thu Jan 26 09:32:14 CET 2023


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>
---
 src/PVE/GuestHelpers.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
index b4ccbaa..3cdf5d7 100644
--- a/src/PVE/GuestHelpers.pm
+++ b/src/PVE/GuestHelpers.pm
@@ -366,4 +366,22 @@ sub get_unique_tags {
     return !$no_join_result ? join(';', $res->@*) : $res;
 }
 
+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.30.2






More information about the pve-devel mailing list