Skip to content

Commit 8f600af

Browse files
committed
Refactor: libcib: New cib__set_calldata()
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent b765bde commit 8f600af

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

daemons/based/based_callbacks.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ create_cib_reply(const char *op, const char *call_id, const char *client_id,
6969
pcmk__xe_set(reply, PCMK__XA_CIB_CLIENTID, client_id);
7070
pcmk__xe_set_int(reply, PCMK__XA_CIB_CALLOPT, call_options);
7171
pcmk__xe_set_int(reply, PCMK__XA_CIB_RC, rc);
72-
73-
if (call_data != NULL) {
74-
xmlNode *wrapper = pcmk__xe_create(reply, PCMK__XE_CIB_CALLDATA);
75-
76-
pcmk__trace("Attaching reply output");
77-
pcmk__xml_copy(wrapper, call_data);
78-
}
72+
cib__set_calldata(reply, call_data);
7973

8074
crm_log_xml_explicit(reply, "cib:reply");
8175
return reply;

daemons/based/based_messages.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,18 @@ based_process_ping(xmlNode *req, xmlNode *input, xmlNode **cib,
110110
const char *seq = pcmk__xe_get(req, PCMK__XA_CIB_PING_ID);
111111
char *digest = pcmk__digest_xml(the_cib, true);
112112

113-
xmlNode *wrapper = NULL;
114-
115113
*answer = pcmk__xe_create(NULL, PCMK__XE_PING_RESPONSE);
116114

117115
pcmk__xe_set(*answer, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
118116
pcmk__xe_set(*answer, PCMK_XA_DIGEST, digest);
119117
pcmk__xe_set(*answer, PCMK__XA_CIB_PING_ID, seq);
120118

121-
wrapper = pcmk__xe_create(*answer, PCMK__XE_CIB_CALLDATA);
122-
123119
if (the_cib != NULL) {
124-
xmlNode *shallow = pcmk__xe_create(wrapper,
125-
(const char *) the_cib->name);
120+
xmlNode *shallow = pcmk__xe_create(NULL, (const char *) the_cib->name);
126121

127122
pcmk__xe_copy_attrs(shallow, the_cib, pcmk__xaf_none);
123+
cib__set_calldata(*answer, shallow);
124+
pcmk__xml_free(shallow);
128125
}
129126

130127
pcmk__info("Reporting our current digest to %s: %s for %s.%s.%s",
@@ -374,7 +371,6 @@ sync_our_cib(xmlNode *request, bool all)
374371
const char *op = pcmk__xe_get(request, PCMK__XA_CIB_OP);
375372
pcmk__node_status_t *peer = NULL;
376373
xmlNode *replace_request = NULL;
377-
xmlNode *wrapper = NULL;
378374

379375
CRM_CHECK(the_cib != NULL, return EINVAL);
380376
CRM_CHECK(all || (host != NULL), return EINVAL);
@@ -401,8 +397,7 @@ sync_our_cib(xmlNode *request, bool all)
401397
digest = pcmk__digest_xml(the_cib, true);
402398
pcmk__xe_set(replace_request, PCMK_XA_DIGEST, digest);
403399

404-
wrapper = pcmk__xe_create(replace_request, PCMK__XE_CIB_CALLDATA);
405-
pcmk__xml_copy(wrapper, the_cib);
400+
cib__set_calldata(replace_request, the_cib);
406401

407402
if (!all) {
408403
peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster_member);

include/crm/cib/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ cib__client_triggers_refresh(const char *name)
191191

192192
int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset);
193193
xmlNode *cib__get_calldata(const xmlNode *request);
194+
void cib__set_calldata(xmlNode *request, xmlNode *data);
194195

195196
int cib__perform_query(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
196197
xmlNode **output);

lib/cib/cib_utils.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ cib_acl_enabled(xmlNode *xml, const char *user)
177177
*
178178
* \param[in] request CIB request XML
179179
*
180-
* \return Call data, or \c NULL if none is found
180+
* \return Call data added by \c cib__set_calldata(), or \c NULL if none is
181+
* found
181182
*/
182183
xmlNode *
183184
cib__get_calldata(const xmlNode *request)
@@ -188,6 +189,28 @@ cib__get_calldata(const xmlNode *request)
188189
return pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
189190
}
190191

192+
/*!
193+
* \internal
194+
* \brief Add call data to a CIB request
195+
*
196+
* Add a copy of \p data to a new \c PCMK__XE_CIB_CALLDATA child of \p request.
197+
*
198+
* \param[in,out] request CIB request XML
199+
* \param[in] data Call data to add a copy of (if \c NULL, do nothing)
200+
*/
201+
void
202+
cib__set_calldata(xmlNode *request, xmlNode *data)
203+
{
204+
xmlNode *wrapper = NULL;
205+
206+
if (data == NULL) {
207+
return;
208+
}
209+
210+
wrapper = pcmk__xe_create(request, PCMK__XE_CIB_CALLDATA);
211+
pcmk__xml_copy(wrapper, data);
212+
}
213+
191214
int
192215
cib__perform_query(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
193216
xmlNode **output)
@@ -647,12 +670,7 @@ cib__create_op(cib_t *cib, const char *op, const char *host,
647670
pcmk__trace("Sending call options: %.8lx, %d", (long) call_options,
648671
call_options);
649672
pcmk__xe_set_int(*op_msg, PCMK__XA_CIB_CALLOPT, call_options);
650-
651-
if (data != NULL) {
652-
xmlNode *wrapper = pcmk__xe_create(*op_msg, PCMK__XE_CIB_CALLDATA);
653-
654-
pcmk__xml_copy(wrapper, data);
655-
}
673+
cib__set_calldata(*op_msg, data);
656674

657675
return pcmk_rc_ok;
658676
}

0 commit comments

Comments
 (0)