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-cluster 06/10] pmxcfs: notify: emit change events over the notification socket
Date: Fri, 18 Sep 2026 16:41:48 +0200	[thread overview]
Message-ID: <20260918144152.575163-7-h.laimer@proxmox.com> (raw)
In-Reply-To: <20260918144152.575163-1-h.laimer@proxmox.com>

Start the notification socket after the daemonize fork and before any
thread can mutate the tree, with the memdb hook installed and the
version of the last mutation so far handed over. That way no change
slips past the socket while it comes up, and a client resuming at that
version after a restart is current and needs no resync. A failure to
bring the socket up is logged and the daemon carries on.

Messages from the notifier are routed through the daemon's own logging
under a dedicated domain so they end up in the same journal stream as
everything else.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/pmxcfs/cfs-utils.h |  4 ++++
 src/pmxcfs/pmxcfs.c    | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/pmxcfs/cfs-utils.h b/src/pmxcfs/cfs-utils.h
index ed67264..29f844e 100644
--- a/src/pmxcfs/cfs-utils.h
+++ b/src/pmxcfs/cfs-utils.h
@@ -78,6 +78,10 @@ void ipc_log_fn(const char *file, int32_t line, int32_t severity, const char *ms
     cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
 #define cfs_dom_critical(domain, ...)                                                              \
     cfs_log(domain, G_LOG_LEVEL_CRITICAL, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
+#define cfs_warn(...)                                                                              \
+    cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
+#define cfs_dom_warn(domain, ...)                                                                  \
+    cfs_log(domain, G_LOG_LEVEL_WARNING, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
 #define cfs_message(...)                                                                           \
     cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
 #define cfs_dom_message(domain, ...)                                                               \
diff --git a/src/pmxcfs/pmxcfs.c b/src/pmxcfs/pmxcfs.c
index 14f1168..575ea3a 100644
--- a/src/pmxcfs/pmxcfs.c
+++ b/src/pmxcfs/pmxcfs.c
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include <qb/qbdefs.h>
@@ -51,6 +52,7 @@
 #include "confdb.h"
 #include "dcdb.h"
 #include "dfsm.h"
+#include "pmxcfs-notify.h"
 #include "quorum.h"
 #include "server.h"
 #include "status.h"
@@ -58,6 +60,7 @@
 #define DBFILENAME VARLIBDIR "/config.db"
 #define LOCKFILE VARLIBDIR "/.pmxcfs.lockfile"
 #define RESTART_FLAG_FILE RUNDIR "/cfs-restart-flag"
+#define NOTIFY_SOCKET RUNDIR "/pmxcfs.sock"
 
 #define CFSDIR "/etc/pve"
 
@@ -78,6 +81,18 @@ static void glib_log_handler(
     cfs_log(log_domain, log_level, NULL, 0, NULL, "%s", message);
 }
 
+static void notify_log_cb(int priority, const char *msg) {
+    if (priority <= LOG_ERR) {
+        cfs_dom_critical("notify", "%s", msg);
+    } else if (priority <= LOG_WARNING) {
+        cfs_dom_warn("notify", "%s", msg);
+    } else if (priority <= LOG_INFO) {
+        cfs_dom_message("notify", "%s", msg);
+    } else {
+        cfs_dom_debug("notify", "%s", msg);
+    }
+}
+
 static gboolean write_pidfile(pid_t pid) {
     char *strpid = g_strdup_printf("%d\n", pid);
     gboolean res = atomic_write_file(CFS_PID_FN, strpid, strlen(strpid), 0644, getgid());
@@ -1032,6 +1047,14 @@ int main(int argc, char *argv[]) {
         cfs_loop_add_service(corosync_loop, service_status, QB_LOOP_LOW);
     }
 
+    memdb_set_notify_hook(pmxcfs_notify_emit);
+
+    // brought up before any thread can mutate the tree, so the version it is
+    // handed is exact and no change slips past it while it comes up
+    if (pmxcfs_notify_init(NOTIFY_SOCKET, cfs.gid, notify_log_cb, memdb->root->version) != 0) {
+        cfs_critical("running without change notification socket");
+    }
+
     cfs_loop_start_worker(corosync_loop);
 
     server_start(memdb);
@@ -1053,6 +1076,8 @@ int main(int argc, char *argv[]) {
 
     server_stop();
 
+    pmxcfs_notify_shutdown();
+
     fuse_unmount(CFSDIR, fuse_chan);
 
     fuse_destroy(fuse);
-- 
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 ` Hannes Laimer [this message]
2026-09-18 14:41 ` [PATCH pve-cluster 07/10] cfs: add perl client for the change notification socket 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 ` [PATCH pve-manager 10/10] pvescheduler: run cluster change hooks from a listener child Hannes Laimer

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-7-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