Skip to content

Commit d09928f

Browse files
authored
Merge pull request #4005 from clumens/fenced-ipc-cleanup
Standardize fenced IPC/corosync code
2 parents fd7af11 + 6bdf2de commit d09928f

15 files changed

Lines changed: 691 additions & 450 deletions

daemons/attrd/attrd_corosync.c

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "pacemaker-attrd.h"
2525

26+
pcmk_cluster_t *attrd_cluster = NULL;
27+
2628
/*!
2729
* \internal
2830
* \brief Nodes removed by \c attrd_peer_remove()
@@ -133,21 +135,31 @@ attrd_peer_message(pcmk__node_status_t *peer, xmlNode *xml)
133135
}
134136
}
135137

138+
#if SUPPORT_COROSYNC
139+
/*!
140+
* \internal
141+
* \brief Callback for when a peer message is received
142+
*
143+
* \param[in] handle The cluster connection
144+
* \param[in] group_name The group that \p nodeid is a member of
145+
* \param[in] nodeid Peer node that sent \p msg
146+
* \param[in] pid Process that sent \p msg
147+
* \param[in,out] msg Received message
148+
* \param[in] msg_len Length of \p msg
149+
*/
136150
static void
137-
attrd_cpg_dispatch(cpg_handle_t handle,
138-
const struct cpg_name *groupName,
139-
uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
151+
attrd_cpg_dispatch(cpg_handle_t handle, const struct cpg_name *group_name,
152+
uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
140153
{
141154
xmlNode *xml = NULL;
142155
const char *from = NULL;
143156
char *data = pcmk__cpg_message_data(handle, nodeid, pid, msg, &from);
144157

145-
if(data == NULL) {
158+
if (data == NULL) {
146159
return;
147160
}
148161

149162
xml = pcmk__xml_parse(data);
150-
151163
if (xml == NULL) {
152164
crm_err("Bad message received from %s[%" PRIu32 "]: '%.120s'",
153165
from, nodeid, data);
@@ -161,6 +173,12 @@ attrd_cpg_dispatch(cpg_handle_t handle,
161173
free(data);
162174
}
163175

176+
/*!
177+
* \internal
178+
* \brief Callback for when the cluster object is destroyed
179+
*
180+
* \param[in] unused Unused
181+
*/
164182
static void
165183
attrd_cpg_destroy(gpointer unused)
166184
{
@@ -173,6 +191,7 @@ attrd_cpg_destroy(gpointer unused)
173191
attrd_shutdown(0);
174192
}
175193
}
194+
#endif // SUPPORT_COROSYNC
176195

177196
/*!
178197
* \internal
@@ -194,6 +213,14 @@ attrd_broadcast_value(const attribute_t *a, const attribute_value_t *v)
194213

195214
#define state_text(state) pcmk__s((state), "in unknown state")
196215

216+
/*!
217+
* \internal
218+
* \brief Callback for peer status changes
219+
*
220+
* \param[in] type What changed
221+
* \param[in] node What peer had the change
222+
* \param[in] data Previous value of what changed
223+
*/
197224
static void
198225
attrd_peer_change_cb(enum pcmk__node_update kind, pcmk__node_status_t *peer,
199226
const void *data)
@@ -462,19 +489,29 @@ attrd_cluster_connect(void)
462489

463490
attrd_cluster = pcmk_cluster_new();
464491

465-
pcmk_cluster_set_destroy_fn(attrd_cluster, attrd_cpg_destroy);
466-
pcmk_cpg_set_deliver_fn(attrd_cluster, attrd_cpg_dispatch);
467-
pcmk_cpg_set_confchg_fn(attrd_cluster, pcmk__cpg_confchg_cb);
492+
#if SUPPORT_COROSYNC
493+
if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) {
494+
pcmk_cluster_set_destroy_fn(attrd_cluster, attrd_cpg_destroy);
495+
pcmk_cpg_set_deliver_fn(attrd_cluster, attrd_cpg_dispatch);
496+
pcmk_cpg_set_confchg_fn(attrd_cluster, pcmk__cpg_confchg_cb);
497+
}
498+
#endif // SUPPORT_COROSYNC
468499

469500
pcmk__cluster_set_status_callback(&attrd_peer_change_cb);
470501

471502
rc = pcmk_cluster_connect(attrd_cluster);
472-
rc = pcmk_rc2legacy(rc);
473-
if (rc != pcmk_ok) {
503+
if (rc != pcmk_rc_ok) {
474504
crm_err("Cluster connection failed");
475-
return rc;
476505
}
477-
return pcmk_ok;
506+
507+
return rc;
508+
}
509+
510+
void
511+
attrd_cluster_disconnect(void)
512+
{
513+
pcmk_cluster_disconnect(attrd_cluster);
514+
pcmk_cluster_free(attrd_cluster);
478515
}
479516

480517
void

daemons/attrd/attrd_messages.c

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ remove_unsupported_sync_points(pcmk__request_t *request)
5555
static xmlNode *
5656
handle_unknown_request(pcmk__request_t *request)
5757
{
58-
crm_err("Unknown IPC request %s from %s %s",
58+
crm_err("Unknown %s request %s from %s %s",
59+
(request->ipc_client != NULL) ? "IPC" : "CPG",
5960
request->op, pcmk__request_origin_type(request),
6061
pcmk__request_origin(request));
6162
pcmk__format_result(&request->result, CRM_EX_PROTOCOL, PCMK_EXEC_INVALID,
@@ -104,54 +105,56 @@ handle_clear_failure_request(pcmk__request_t *request)
104105
static xmlNode *
105106
handle_confirm_request(pcmk__request_t *request)
106107
{
107-
if (request->peer != NULL) {
108-
int callid;
108+
int callid = 0;
109109

110-
crm_debug("Received confirmation from %s", request->peer);
110+
if (request->ipc_client != NULL) {
111+
return handle_unknown_request(request);
112+
}
111113

112-
if (pcmk__xe_get_int(request->xml, PCMK__XA_CALL_ID,
113-
&callid) != pcmk_rc_ok) {
114-
pcmk__set_result(&request->result, CRM_EX_PROTOCOL, PCMK_EXEC_INVALID,
115-
"Could not get callid from XML");
116-
} else {
117-
attrd_handle_confirmation(callid, request->peer);
118-
}
114+
crm_debug("Received confirmation from %s", request->peer);
119115

120-
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
121-
return NULL;
116+
if (pcmk__xe_get_int(request->xml, PCMK__XA_CALL_ID,
117+
&callid) != pcmk_rc_ok) {
118+
pcmk__set_result(&request->result, CRM_EX_PROTOCOL, PCMK_EXEC_INVALID,
119+
"Could not get callid from XML");
122120
} else {
123-
return handle_unknown_request(request);
121+
attrd_handle_confirmation(callid, request->peer);
124122
}
123+
124+
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
125+
return NULL;
125126
}
126127

127128
static xmlNode *
128129
handle_query_request(pcmk__request_t *request)
129130
{
130131
if (request->peer != NULL) {
131132
return handle_unknown_request(request);
132-
} else {
133-
return attrd_client_query(request);
134133
}
134+
135+
return attrd_client_query(request);
135136
}
136137

137138
static xmlNode *
138139
handle_remove_request(pcmk__request_t *request)
139140
{
140-
if (request->peer != NULL) {
141-
const char *host = pcmk__xe_get(request->xml, PCMK__XA_ATTR_HOST);
142-
bool reap = false;
143-
144-
if (pcmk__xe_get_bool(request->xml, PCMK__XA_REAP,
145-
&reap) != pcmk_rc_ok) {
146-
reap = true; // Default to true for backward compatibility
147-
}
148-
attrd_peer_remove(host, reap, request->peer);
149-
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
141+
const char *host = NULL;
142+
bool reap = false;
150143

151-
} else {
144+
if (request->ipc_client != NULL) {
152145
attrd_client_peer_remove(request);
146+
return NULL;
153147
}
154148

149+
host = pcmk__xe_get(request->xml, PCMK__XA_ATTR_HOST);
150+
151+
if (pcmk__xe_get_bool(request->xml, PCMK__XA_REAP,
152+
&reap) != pcmk_rc_ok) {
153+
reap = true; // Default to true for backward compatibility
154+
}
155+
156+
attrd_peer_remove(host, reap, request->peer);
157+
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
155158
return NULL;
156159
}
157160

@@ -161,31 +164,32 @@ handle_refresh_request(pcmk__request_t *request)
161164
if (request->peer != NULL) {
162165
return handle_unknown_request(request);
163166
}
167+
164168
attrd_client_refresh(request);
165169
return NULL;
166170
}
167171

168172
static xmlNode *
169173
handle_sync_response_request(pcmk__request_t *request)
170174
{
175+
pcmk__node_status_t *peer = NULL;
176+
bool peer_won = false;
177+
171178
if (request->ipc_client != NULL) {
172179
return handle_unknown_request(request);
173-
} else {
174-
if (request->peer != NULL) {
175-
pcmk__node_status_t *peer =
176-
pcmk__get_node(0, request->peer, NULL,
177-
pcmk__node_search_cluster_member);
178-
bool peer_won = attrd_check_for_new_writer(peer, request->xml);
179-
180-
if (!pcmk__str_eq(peer->name, attrd_cluster->priv->node_name,
181-
pcmk__str_casei)) {
182-
attrd_peer_sync_response(peer, peer_won, request->xml);
183-
}
184-
}
180+
}
185181

186-
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
187-
return NULL;
182+
peer = pcmk__get_node(0, request->peer, NULL,
183+
pcmk__node_search_cluster_member);
184+
peer_won = attrd_check_for_new_writer(peer, request->xml);
185+
186+
if (!pcmk__str_eq(peer->name, attrd_cluster->priv->node_name,
187+
pcmk__str_casei)) {
188+
attrd_peer_sync_response(peer, peer_won, request->xml);
188189
}
190+
191+
pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
192+
return NULL;
189193
}
190194

191195
static xmlNode *

daemons/attrd/pacemaker-attrd.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static pcmk__supported_format_t formats[] = {
5656
};
5757

5858
lrmd_t *the_lrmd = NULL;
59-
pcmk_cluster_t *attrd_cluster = NULL;
6059
crm_trigger_t *attrd_config_read = NULL;
6160
crm_exit_t attrd_exit_status = CRM_EX_OK;
6261

@@ -73,7 +72,7 @@ ipc_already_running(void)
7372

7473
rc = pcmk__connect_ipc(old_instance, pcmk_ipc_dispatch_sync, 2);
7574
if (rc != pcmk_rc_ok) {
76-
crm_debug("No existing %s manager instance found: %s",
75+
crm_debug("No existing %s instance found: %s",
7776
pcmk_ipc_name(old_instance, true), pcmk_rc_str(rc));
7877
pcmk_free_ipc_api(old_instance);
7978
return false;
@@ -164,12 +163,13 @@ main(int argc, char **argv)
164163
crm_info("CIB connection active");
165164
}
166165

167-
if (attrd_cluster_connect() != pcmk_ok) {
166+
if (attrd_cluster_connect() != pcmk_rc_ok) {
168167
attrd_exit_status = CRM_EX_FATAL;
169168
g_set_error(&error, PCMK__EXITC_ERROR, attrd_exit_status,
170169
"Could not connect to the cluster");
171170
goto done;
172171
}
172+
173173
crm_info("Cluster connection active");
174174

175175
// Initialization that requires the cluster to be connected
@@ -203,8 +203,7 @@ main(int argc, char **argv)
203203

204204
attrd_free_removed_peers();
205205
attrd_free_waitlist();
206-
pcmk_cluster_disconnect(attrd_cluster);
207-
pcmk_cluster_free(attrd_cluster);
206+
attrd_cluster_disconnect();
208207
g_hash_table_destroy(attributes);
209208
}
210209

daemons/attrd/pacemaker-attrd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ void attrd_free_removed_peers(void);
191191
void attrd_erase_removed_peer_attributes(void);
192192

193193
int attrd_cluster_connect(void);
194+
void attrd_cluster_disconnect(void);
194195
void attrd_broadcast_value(const attribute_t *a, const attribute_value_t *v);
195196
void attrd_peer_update(const pcmk__node_status_t *peer, xmlNode *xml,
196197
const char *host, bool filter);

daemons/execd/execd_messages.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ handle_unknown_request(pcmk__request_t *request)
402402
PCMK__XE_NACK, NULL, CRM_EX_PROTOCOL);
403403

404404
pcmk__format_result(&request->result, CRM_EX_PROTOCOL, PCMK_EXEC_INVALID,
405-
"Unknown IPC request type '%s' (bug?)",
405+
"Unknown request type '%s' (bug?)",
406406
pcmk__s(request->op, ""));
407407
return NULL;
408408
}

daemons/fenced/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Original Author: Sun Jiang Dong <sunjd@cn.ibm.com>
33
# Copyright 2004 International Business Machines
44
#
5-
# with later changes copyright 2004-2024 the Pacemaker project contributors.
5+
# with later changes copyright 2004-2025 the Pacemaker project contributors.
66
# The version control history for this file may have further details.
77
#
88
# This source code is licensed under the GNU General Public License version 2
@@ -42,6 +42,8 @@ pacemaker_fenced_LDADD += $(CLUSTERLIBS)
4242
pacemaker_fenced_SOURCES = pacemaker-fenced.c \
4343
fenced_cib.c \
4444
fenced_commands.c \
45+
fenced_corosync.c \
46+
fenced_ipc.c \
4547
fenced_remote.c \
4648
fenced_scheduler.c \
4749
fenced_history.c

0 commit comments

Comments
 (0)