all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH cluster 3/4] pmxcfs: dfsm: wake waiters in dfsm_send_message_sync() on error mode
Date: Mon, 16 Nov 2026 17:01:30 +0100	[thread overview]
Message-ID: <20261116160131.344857-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20261116160131.344857-1-s.sterz@proxmox.com>

if the dfsm switches to an abnormal state (`>= DFSM_ERROR_MODE_START`)
and a thread is waiting in `dfsm_send_message_sync()` for a message to
return, it will wait indefinitely. this is because only two functions
will broadcast on the condition `&dfsm->sync_cond` that is waited for:

- `dfsm_record_local_result()`: only called by
  `dfsm_cpg_deliver_callback()` for local messages and only if mode is
  `< DFSM_ERROR_MODE_START`.
- `dfsm_send_sync_message_abort()`: only called on `dfsm_finalize()`
  or `dfsm_initialize()`. which are only called when the dfsm service
  is finalized or initialized; not on error modes.

further a call to `dcdb_deliver()` can call `dfsm_set_errormode()`
during a local delivery. then right after the abort
`dfsm_record_local_result()` will set the `msgcount_rcvd` back to that
message's number. a waiter in `dfsm_send_message_sync()` will be
woken, but the `msgcount_rcvd` will not be increased by default.
meaning the thread goes back to waiting. so a check on whether an
error mode here is set is necessary.

this patch does three things:

- wake any waiter of `&dfsm->sync_cond` upon entering an abnormal mode
- return an error on `dfsm_send_message_sync()` when in an error mode
- check whether dfsm is in an error mode when awoken in
  `dfsm_send_message_sync()`

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 src/pmxcfs/dfsm.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/pmxcfs/dfsm.c b/src/pmxcfs/dfsm.c
index 741db54..a5f241c 100644
--- a/src/pmxcfs/dfsm.c
+++ b/src/pmxcfs/dfsm.c
@@ -145,6 +145,7 @@ struct dfsm {
 
 static gboolean dfsm_deliver_queue(dfsm_t *dfsm);
 static gboolean dfsm_deliver_sync_queue(dfsm_t *dfsm);
+static dfsm_mode_t dfsm_get_mode(dfsm_t *dfsm);
 
 gboolean dfsm_nodeid_is_local(dfsm_t *dfsm, uint32_t nodeid, uint32_t pid) {
     g_return_val_if_fail(dfsm != NULL, FALSE);
@@ -262,6 +263,13 @@ cs_error_t dfsm_send_message_sync(
     g_return_val_if_fail(!len || iov != NULL, CS_ERR_INVALID_PARAM);
 
     g_mutex_lock(&dfsm->sync_mutex);
+    /* abort sending if we are in an abnormal state */
+    if (dfsm_get_mode(dfsm) >= DFSM_ERROR_MODE_START) {
+        cfs_dom_debug(dfsm->log_domain, "error mode - refusing to send message");
+        g_mutex_unlock(&dfsm->sync_mutex);
+        return CS_ERR_NOT_EXIST;
+    }
+
     /* note: hold lock until message is sent - to guarantee ordering */
     uint64_t msgcount = ++dfsm->msgcount;
     if (rp) {
@@ -303,7 +311,7 @@ cs_error_t dfsm_send_message_sync(
     if (rp) {
         g_mutex_lock(&dfsm->sync_mutex);
 
-        while (dfsm->msgcount_rcvd < msgcount) {
+        while (dfsm->msgcount_rcvd < msgcount && dfsm_get_mode(dfsm) < DFSM_ERROR_MODE_START) {
             g_cond_wait(&dfsm->sync_cond, &dfsm->sync_mutex);
         }
 
@@ -476,6 +484,11 @@ static void dfsm_set_mode(dfsm_t *dfsm, dfsm_mode_t new_mode) {
         return;
     }
 
+    if (new_mode >= DFSM_ERROR_MODE_START) {
+        /* abort waiting for sync messages to arrive if we are in an abnormal state */
+        dfsm_send_sync_message_abort(dfsm);
+    }
+
     if (new_mode == DFSM_MODE_START) {
         cfs_dom_message(dfsm->log_domain, "start cluster connection");
     } else if (new_mode == DFSM_MODE_START_SYNC) {
-- 
2.47.3





  parent reply	other threads:[~2026-11-16 16:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:01 [PATCH cluster 0/4] Fix 8325 and minor pmxcfs Clean-Up Shannon Sterz
2026-11-16 16:01 ` [PATCH cluster 1/4] tree wide: update copyright notice to current year Shannon Sterz
2026-11-16 16:01 ` [PATCH cluster 2/4] fix #8325: pmxcfs: dfsm: abort send if dfsm is not joined via a handle Shannon Sterz
2026-11-16 16:01 ` Shannon Sterz [this message]
2026-11-16 16:01 ` [PATCH cluster 4/4] pmxcfs: dfsm: make sure error results are processed correctly Shannon Sterz
2026-11-17  1:32 ` applied: [PATCH cluster 0/4] Fix 8325 and minor pmxcfs Clean-Up 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=20261116160131.344857-4-s.sterz@proxmox.com \
    --to=s.sterz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal