public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager 10/10] pvescheduler: run cluster change hooks from a listener child
Date: Fri, 18 Sep 2026 16:41:52 +0200	[thread overview]
Message-ID: <20260918144152.575163-11-h.laimer@proxmox.com> (raw)
In-Reply-To: <20260918144152.575163-1-h.laimer@proxmox.com>

On HUP the listener is stopped rather than handed over, so the reloaded
daemon runs the newly loaded hook modules. It is recorded under a
separate marker, which frees the hook slot for its replacement to start
immediately and still has the new daemon reap it, since reaping now
covers every recorded job type rather than a fixed list.

The listener keeps its position under /run, so the one started after a
reload resumes where the stopped one left off. Around a reload the
stopped listener may still be ending its runs while the new one starts,
and both may hold a connection and record a position for that moment,
which is safe since a recorded position only ever stands for completed
runs.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 PVE/Service/pvescheduler.pm | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/PVE/Service/pvescheduler.pm b/PVE/Service/pvescheduler.pm
index f7271fc0..7c773829 100755
--- a/PVE/Service/pvescheduler.pm
+++ b/PVE/Service/pvescheduler.pm
@@ -5,6 +5,8 @@ use warnings;
 
 use POSIX qw(WNOHANG);
 
+use PVE::Cluster::Hooks;
+use PVE::HookRunner;
 use PVE::Jobs;
 use PVE::SafeSyslog;
 
@@ -17,8 +19,6 @@ my $cmdline = [$0, @ARGV];
 my %daemon_options = (stop_wait_time => 180, max_workers => 0);
 my $daemon = __PACKAGE__->new('pvescheduler', $cmdline, %daemon_options);
 
-my @JOB_TYPES = qw(replication jobs);
-
 my sub running_job_pids : prototype($) {
     my ($self) = @_;
     my $pids = [map { keys $_->%* } values $self->{jobs}->%*];
@@ -27,7 +27,7 @@ my sub running_job_pids : prototype($) {
 
 my sub finish_jobs : prototype($) {
     my ($self) = @_;
-    for my $type (@JOB_TYPES) {
+    for my $type (keys $self->{jobs}->%*) {
         for my $cpid (keys $self->{jobs}->{$type}->%*) {
             if (my $waitpid = waitpid($cpid, WNOHANG)) {
                 delete $self->{jobs}->{$type}->{$cpid} if $waitpid == $cpid || $waitpid == -1;
@@ -40,8 +40,14 @@ sub hup {
     my ($self) = @_;
 
     my $old_workers = "";
-    for my $type (@JOB_TYPES) {
+    for my $type (sort keys $self->{jobs}->%*) {
         my $worker = $self->{jobs}->{$type} // next;
+        # stopped rather than handed over, so the reload runs the new hook code
+        if ($type eq 'hooks') {
+            kill 'TERM', keys $worker->%*;
+            $old_workers .= "stopped:$_;" for keys $worker->%*;
+            next;
+        }
         $old_workers .= "$type:$_;" for keys $worker->%*;
     }
     $ENV{"PVE_DAEMON_WORKER_PIDS"} = $old_workers;
@@ -118,6 +124,18 @@ sub run {
             },
         );
 
+        # only run while a hook is registered, unlike the other job types
+        if (scalar(PVE::Cluster::Hooks->hooks()->@*)) {
+            $fork->(
+                'hooks',
+                sub {
+                    PVE::HookRunner->new(
+                        state => '/run/pvescheduler/hooks.seq',
+                    )->run();
+                },
+            );
+        }
+
         $first_run = 0;
     };
 
-- 
2.47.3





      parent reply	other threads:[~2026-09-18 14:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:41 [RFC cluster/manager 00/10] pmxcfs: add a change notification socket Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 01/10] buildsys: add rust workspace under src/rust Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 02/10] rust: notify: add change notification socket server Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 03/10] rust: ffi: add C ABI staticlib for pmxcfs Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 04/10] pmxcfs: memdb: add change notification hook Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 05/10] buildsys: link pmxcfs against the rust notify staticlib Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 06/10] pmxcfs: notify: emit change events over the notification socket Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 07/10] cfs: add perl client for the change " Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-cluster 08/10] cfs: add hook registry for change notification consumers Hannes Laimer
2026-09-18 14:41 ` [PATCH pve-manager 09/10] hooks: add runner executing cluster change hooks in children Hannes Laimer
2026-09-18 14:41 ` Hannes Laimer [this message]

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=20260918144152.575163-11-h.laimer@proxmox.com \
    --to=h.laimer@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal