From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 5DFC31FF0BC for ; Mon, 16 Nov 2026 17:01:46 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C10FE215FD; Mon, 16 Nov 2026 17:01:38 +0100 (CET) From: Shannon Sterz 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 Message-ID: <20261116160131.344857-4-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261116160131.344857-1-s.sterz@proxmox.com> References: <20261116160131.344857-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794844894236 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.607 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: GPQJLB5K75ZSW6P7AXV3XH4WUFC6ZFJ3 X-Message-ID-Hash: GPQJLB5K75ZSW6P7AXV3XH4WUFC6ZFJ3 X-MailFrom: s.sterz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Signed-off-by: Shannon Sterz --- 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