From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH cluster v5 03/41] pmxcfs: dfsm: add a callback that runs once all members are in sync
Date: Thu, 19 Nov 2026 20:18:35 +0100 [thread overview]
Message-ID: <20261119191914.2336934-4-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261119191914.2336934-1-t.lamprecht@proxmox.com>
A service that acts on shared state from the loop thread needs to know
when its local state matches the state of all members. The existing
synced callback is too early for that. It runs before the queued
messages are delivered. On the sync leader it also runs before the
members that need updates have received them, so their queued messages
are still pending as well.
Add an optional callback that runs after all members are marked as in
sync and the queued messages have been delivered. Call it again on every
tick of the service timer for as long as that state lasts. A service can
then decide by looking at its current state only. It does not need a
notification for every input that can change, and an action that failed
or got skipped is retried with the next tick.
The timer of the dcdb service ticks once per hour to start the data
verification. Give the verification a period of its own instead of
running it on every tick. A service can then let its timer tick more
often for the callback without verifying more often. Nothing changes as
long as the timer keeps its period.
Also add dfsm_nodeid_is_member(), which tells whether a node is a member
of the current group. Nothing uses it yet, the generation of the cluster
ID will.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes v4 -> v5:
* commit message: dfsm_nodeid_is_member() gets added here and is not
used yet
changes v3 -> v4:
* dfsm_check_in_sync() is static, only the service timer repeats the
callback now, no other event requests it
* the data verification gets a period of its own, one hour as before, so
that a service can let its timer tick more often for the callback
* commit message: plainer wording, same content
changes v2 -> v3:
* comment: the condition is what this node has marked as synced, not an
acknowledgement of the other nodes
changes v1 -> v2:
* rebase onto the dfsm rework
* also reset the in-sync state when the connection gets finalized
* reword the comment of the callback
src/pmxcfs/dfsm.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
src/pmxcfs/dfsm.h | 10 +++++++
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/src/pmxcfs/dfsm.c b/src/pmxcfs/dfsm.c
index c83cef7..697f2aa 100644
--- a/src/pmxcfs/dfsm.c
+++ b/src/pmxcfs/dfsm.c
@@ -124,6 +124,7 @@ struct dfsm {
uint32_t local_epoch_counter;
dfsm_sync_epoch_t sync_epoch;
uint32_t lowest_nodeid;
+ gboolean in_sync; /* see dfsm_in_sync_fn */
GSequence *msg_queue;
GList *sync_queue;
@@ -609,6 +610,27 @@ gboolean dfsm_restartable(dfsm_t *dfsm) {
void dfsm_set_errormode(dfsm_t *dfsm) { dfsm_set_mode(dfsm, DFSM_MODE_ERROR); }
+static void dfsm_notify_in_sync(dfsm_t *dfsm) {
+ g_return_if_fail(dfsm != NULL);
+ g_return_if_fail(dfsm->sync_info != NULL);
+
+ if (dfsm->in_sync || dfsm_get_mode(dfsm) != DFSM_MODE_SYNCED) {
+ return;
+ }
+
+ for (int i = 0; i < dfsm->sync_info->node_count; i++) {
+ if (!dfsm->sync_info->nodes[i].synced) {
+ return;
+ }
+ }
+
+ dfsm->in_sync = TRUE;
+
+ if (dfsm->dfsm_callbacks->dfsm_in_sync_fn) {
+ dfsm->dfsm_callbacks->dfsm_in_sync_fn(dfsm, dfsm->data);
+ }
+}
+
static void dfsm_release_sync_resources(
dfsm_t *dfsm, const struct cpg_address *member_list, size_t member_list_entries
) {
@@ -802,6 +824,8 @@ static void dfsm_cpg_deliver_callback(
goto leave;
}
+ dfsm_notify_in_sync(dfsm);
+
return;
} else if (base_header->type == DFSM_MESSAGE_VERIFY_REQUEST) {
@@ -990,6 +1014,8 @@ static void dfsm_cpg_deliver_callback(
goto leave;
}
+ dfsm_notify_in_sync(dfsm);
+
} else {
dfsm_set_mode(dfsm, DFSM_MODE_UPDATE);
@@ -1040,6 +1066,8 @@ static void dfsm_cpg_deliver_callback(
dfsm_release_sync_resources(dfsm, NULL, 0);
+ dfsm_notify_in_sync(dfsm);
+
return;
}
@@ -1212,6 +1240,7 @@ static void dfsm_cpg_confchg_callback(
dfsm->we_are_member = 0;
dfsm->state_sent = FALSE;
+ dfsm->in_sync = FALSE;
/* create new epoch */
dfsm->local_epoch_counter++;
@@ -1304,6 +1333,7 @@ static void dfsm_cpg_confchg_callback(
if (!dfsm_deliver_queue(dfsm)) {
goto leave;
}
+ dfsm_notify_in_sync(dfsm);
}
if (dfsm->dfsm_callbacks->dfsm_confchg_fn) {
@@ -1390,6 +1420,31 @@ gboolean dfsm_is_initialized(dfsm_t *dfsm) {
return (dfsm->cpg_handle != 0) ? TRUE : FALSE;
}
+static void dfsm_check_in_sync(dfsm_t *dfsm) {
+ g_return_if_fail(dfsm != NULL);
+
+ if (dfsm->in_sync && dfsm_get_mode(dfsm) == DFSM_MODE_SYNCED &&
+ dfsm->dfsm_callbacks->dfsm_in_sync_fn) {
+ dfsm->dfsm_callbacks->dfsm_in_sync_fn(dfsm, dfsm->data);
+ }
+}
+
+gboolean dfsm_nodeid_is_member(dfsm_t *dfsm, uint32_t nodeid) {
+ g_return_val_if_fail(dfsm != NULL, FALSE);
+
+ if (!dfsm->sync_info) {
+ return FALSE;
+ }
+
+ for (int i = 0; i < dfsm->sync_info->node_count; i++) {
+ if (dfsm->sync_info->nodes[i].nodeid == nodeid) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
gboolean dfsm_lowest_nodeid(dfsm_t *dfsm) {
g_return_val_if_fail(dfsm != NULL, FALSE);
@@ -1481,6 +1536,7 @@ cs_error_t dfsm_initialize(dfsm_t *dfsm, int *fd) {
dfsm->joined = FALSE;
g_mutex_unlock(&dfsm->cpg_mutex);
dfsm->we_are_member = 0;
+ dfsm->in_sync = FALSE;
dfsm_set_mode(dfsm, DFSM_MODE_START);
@@ -1608,6 +1664,7 @@ gboolean dfsm_finalize(dfsm_t *dfsm) {
dfsm->joined = FALSE;
g_mutex_unlock(&dfsm->cpg_mutex);
dfsm->we_are_member = 0;
+ dfsm->in_sync = FALSE;
}
return TRUE;
@@ -1656,8 +1713,12 @@ void dfsm_destroy(dfsm_t *dfsm) {
g_free(dfsm);
}
+/* seconds between the data verifications of a service, whose timer can tick more often */
+#define DFSM_VERIFY_TIME (60 * 60)
+
typedef struct {
dfsm_t *dfsm;
+ time_t last_verify;
} service_dfsm_private_t;
static gboolean service_dfsm_finalize(cfs_service_t *service, gpointer context) {
@@ -1758,7 +1819,13 @@ static void service_dfsm_timer(cfs_service_t *service, gpointer context) {
g_return_if_fail(dfsm != NULL);
- dfsm_verify_request(dfsm);
+ time_t now = time(NULL);
+ if (now - private->last_verify >= DFSM_VERIFY_TIME) {
+ private->last_verify = now;
+ dfsm_verify_request(dfsm);
+ }
+
+ dfsm_check_in_sync(dfsm);
}
static cfs_service_callbacks_t cfs_dfsm_callbacks = {
@@ -1779,6 +1846,7 @@ cfs_service_t *service_dfsm_new(dfsm_t *dfsm) {
}
private->dfsm = dfsm;
+ private->last_verify = time(NULL);
service = cfs_service_new(&cfs_dfsm_callbacks, dfsm->log_domain, private);
diff --git a/src/pmxcfs/dfsm.h b/src/pmxcfs/dfsm.h
index 5b193e8..95af10f 100644
--- a/src/pmxcfs/dfsm.h
+++ b/src/pmxcfs/dfsm.h
@@ -79,6 +79,8 @@ typedef int (*dfsm_process_state_update_fn_t)(
typedef void (*dfsm_synced_fn_t)(dfsm_t *dfsm);
+typedef void (*dfsm_in_sync_fn_t)(dfsm_t *dfsm, gpointer data);
+
/* return values:
* res < 0 ... serious error, leave group
* res >= 0 ... OK
@@ -103,6 +105,11 @@ typedef struct {
dfsm_process_update_fn_t dfsm_process_update_fn;
dfsm_checksum_fn_t dfsm_checksum_fn;
dfsm_synced_fn_t dfsm_synced_fn;
+ /* Called whenever this node has marked all members as synced and delivered the messages queued
+ * meanwhile, so that the local state matches the one of all members: first right after a sync,
+ * then again on every service timer tick while that holds. dfsm_synced_fn runs earlier, when
+ * the local node enters the synced mode and before the queued messages are delivered. */
+ dfsm_in_sync_fn_t dfsm_in_sync_fn;
} dfsm_callbacks_t;
/* what became of a message sent with dfsm_send_message_sync */
@@ -168,6 +175,9 @@ cs_error_t dfsm_send_update_complete(dfsm_t *dfsm);
gboolean dfsm_lowest_nodeid(dfsm_t *dfsm);
+/* whether a process of that node is a member of the current group, loop thread only */
+gboolean dfsm_nodeid_is_member(dfsm_t *dfsm, uint32_t nodeid);
+
gboolean dfsm_nodeid_is_local(dfsm_t *dfsm, uint32_t nodeid, uint32_t pid);
cs_error_t dfsm_verify_request(dfsm_t *dfsm);
--
2.47.3
next prev parent reply other threads:[~2026-11-19 19:19 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:18 [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
2026-11-19 19:18 ` [PATCH cluster v5 01/41] pmxcfs: reject changes to the cluster ID file from user space Thomas Lamprecht
2026-11-19 19:18 ` [PATCH cluster v5 02/41] pmxcfs: generate a cluster ID on standalone nodes Thomas Lamprecht
2026-11-19 19:18 ` Thomas Lamprecht [this message]
2026-11-19 19:18 ` [PATCH cluster v5 04/41] pmxcfs: quorum: record the corosync membership Thomas Lamprecht
2026-11-19 19:18 ` [PATCH cluster v5 05/41] pmxcfs: dcdb: generate the cluster ID once the cluster is in sync Thomas Lamprecht
2026-11-19 19:18 ` [PATCH cluster v5 06/41] cluster: add helper to read the cluster ID Thomas Lamprecht
2026-11-19 19:18 ` [PATCH cluster v5 07/41] pmxcfs: allow removing the cluster ID file in forced local mode Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 09/41] abstract config: assign a guest identity and keep it on config writes Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 10/41] abstract config: let the VMID reservation return the previous state Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 11/41] guest identity: allow adopting a uid that is unused in the cluster Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 12/41] migrate: add shared helpers for the identity command of the migration tunnel Thomas Lamprecht
2026-11-19 19:18 ` [PATCH guest-common v5 13/41] vzdump: notes template: list the uid variable Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 14/41] api: restore: release the VMID if a restore to an unused VMID fails Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 15/41] api: migrate, clone: refuse targets that would drop the guest identity Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 17/41] restore: adopt the guest uid from the backup where possible Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 18/41] api: remote migration: adopt the guest uid from the source Thomas Lamprecht
2026-11-19 19:18 ` [PATCH qemu-server v5 19/41] api: status: return the guest uid Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 20/41] restore: decide by the reservation whether the container is new Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 21/41] config: add read-only meta property with the creation time Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 22/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 23/41] api: migrate, clone: refuse targets that would drop the guest identity Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 24/41] restore: adopt the guest uid from the backup where possible Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 25/41] restore: refuse overwriting a container with another guest's backup Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 26/41] api: remote migration: adopt the guest uid from the source Thomas Lamprecht
2026-11-19 19:18 ` [PATCH container v5 27/41] api: status: return the guest uid Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 28/41] api: cluster resources: add guest uid and registration time Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 29/41] api: cluster status: add cluster ID Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 30/41] ui: datacenter summary: show the " Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 31/41] ui: restore: allow overwriting a guest with a backup of another guest Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 32/41] ui: migrate: refuse target nodes that would drop the guest identity Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 33/41] ui: guest summary: show " Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 34/41] api: bulk migrate: refuse targets that would drop " Thomas Lamprecht
2026-11-19 19:19 ` [PATCH manager v5 35/41] vzdump: notes template: add the guest uid as variable Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 36/41] vzdump: restore: describe what a failed restore can leave behind Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 38/41] pvecm: document the cluster ID and how to get a new one Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 39/41] qm: configuration: describe the read-only meta property Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 40/41] pct: " Thomas Lamprecht
2026-11-19 19:19 ` [PATCH docs v5 41/41] vzdump: notes: document the uid template variable Thomas Lamprecht
2026-11-20 3:07 ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
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=20261119191914.2336934-4-t.lamprecht@proxmox.com \
--to=t.lamprecht@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