File bsc#1224183-0001-Refactor-libcib-new-function-cib__signon_attempts.patch of Package pacemaker.36799
From 7ab61e764df38b7ec8349d54e46b66a1447b0b59 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Tue, 2 Jul 2024 00:12:14 +0200
Subject: [PATCH 1/2] Refactor: libcib: new function cib__signon_attempts()
... for future use
It's similar to how it's done in pcmk__connect_ipc().
---
include/crm/cib/internal.h | 3 +++
lib/cib/cib_utils.c | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/include/crm/cib/internal.h b/include/crm/cib/internal.h
index d191009ff5..b4f46e61ca 100644
--- a/include/crm/cib/internal.h
+++ b/include/crm/cib/internal.h
@@ -288,6 +288,9 @@ cib_callback_client_t* cib__lookup_id (int call_id);
*/
int cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object);
+int cib__signon_attempts(cib_t *cib, const char *name, enum cib_conn_type type,
+ int attempts);
+
int cib__clean_up_connection(cib_t **cib);
int cib__update_node_attr(pcmk__output_t *out, cib_t *cib, int call_options,
diff --git a/lib/cib/cib_utils.c b/lib/cib/cib_utils.c
index 7ef378929e..34652dc97a 100644
--- a/lib/cib/cib_utils.c
+++ b/lib/cib/cib_utils.c
@@ -1015,6 +1015,33 @@ done:
return rc;
}
+int
+cib__signon_attempts(cib_t *cib, const char *name, enum cib_conn_type type,
+ int attempts)
+{
+ int rc = pcmk_rc_ok;
+
+ crm_trace("Attempting connection to CIB manager (up to %d time%s)",
+ attempts, pcmk__plural_s(attempts));
+
+ for (int remaining = attempts - 1; remaining >= 0; --remaining) {
+ rc = cib->cmds->signon(cib, name, type);
+
+ if ((rc == pcmk_rc_ok)
+ || (remaining == 0)
+ || ((errno != EAGAIN) && (errno != EALREADY))) {
+ break;
+ }
+
+ // Retry after soft error (interrupted by signal, etc.)
+ pcmk__sleep_ms((attempts - remaining) * 500);
+ crm_debug("Re-attempting connection to CIB manager (%d attempt%s remaining)",
+ remaining, pcmk__plural_s(remaining));
+ }
+
+ return rc;
+}
+
int
cib__clean_up_connection(cib_t **cib)
{
--
2.35.3