Skip to content

Commit f68d60e

Browse files
committed
Refactor: libcib: cib_perform_op() takes only one CIB argument
The new approach is to set the caller's result_cib pointer to the current CIB instead of to NULL. Then pass &result_cib to cib_perform_op() as its "cib" argument. * If it doesn't make a copy, then it operates on the original CIB directly and then assign the original CIB to working_cib -- just as we were already doing. * If it does make a copy, then it's copying the original CIB, just as we were already doing. * If it makes *cib point somewhere else at the end (in the "done" section), then that changes the value of the caller's result_cib, but it DOES NOT change the value of caller's current CIB pointer (the_cib in pacemaker-based or private->cib_xml in cib_file.c). So the caller still has a reference to the original CIB. The logic is arguably a bit more complicated, but previously we had five CIB pointers (current_cib, result_cib, working_cib, old_versions, top) in cib_perform_op(). Now we only have to deal with four. That feels more manageable and thus worth it IMO. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 8e3d81b commit f68d60e

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

daemons/based/based_callbacks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,9 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
563563
* It's not important whether the client variant is cib_native or
564564
* cib_remote.
565565
*/
566+
result_cib = the_cib;
566567
rc = cib_perform_op(cib_undefined, op_function, request, &config_changed,
567-
&the_cib, &result_cib, &cib_diff, &output);
568+
&result_cib, &cib_diff, &output);
568569

569570
/* Always write to disk for successful ops with the flag set. This also
570571
* negates the need to detect ordering changes.

include/crm/cib/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ int cib__perform_query(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
196196
xmlNode **output);
197197

198198
int cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
199-
bool *config_changed, xmlNode **current_cib,
200-
xmlNode **result_cib, xmlNode **diff, xmlNode **output);
199+
bool *config_changed, xmlNode **cib, xmlNode **diff,
200+
xmlNode **output);
201201

202202
int cib__create_op(cib_t *cib, const char *op, const char *host,
203203
const char *section, xmlNode *data, int call_options,

lib/cib/cib_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ process_request(cib_t *cib, xmlNode *request, xmlNode **output)
169169
rc = cib__perform_query(op_function, request, &private->cib_xml,
170170
output);
171171
} else {
172+
result_cib = private->cib_xml;
172173
rc = cib_perform_op(cib_file, op_function, request, &changed,
173-
&private->cib_xml, &result_cib, &cib_diff, output);
174+
&result_cib, &cib_diff, output);
174175
}
175176

176177
if (pcmk__is_set(call_options, cib_transaction)) {

lib/cib/cib_utils.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ set_update_origin(xmlNode *new_cib, const xmlNode *request)
465465

466466
int
467467
cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
468-
bool *config_changed, xmlNode **current_cib,
469-
xmlNode **result_cib, xmlNode **diff, xmlNode **output)
468+
bool *config_changed, xmlNode **cib, xmlNode **diff,
469+
xmlNode **output)
470470
{
471471
int rc = pcmk_rc_ok;
472472

@@ -489,8 +489,7 @@ cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
489489

490490
pcmk__assert((fn != NULL) && (req != NULL)
491491
&& (config_changed != NULL) && (!*config_changed)
492-
&& (current_cib != NULL) && (*current_cib != NULL)
493-
&& (result_cib != NULL) && (*result_cib == NULL)
492+
&& (cib != NULL) && (*cib != NULL)
494493
&& (diff != NULL) && (*diff == NULL)
495494
&& (output != NULL) && (*output == NULL));
496495

@@ -500,39 +499,38 @@ cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
500499
pcmk__xe_get_flags(req, PCMK__XA_CIB_CALLOPT, &call_options, cib_none);
501500

502501
input = get_op_input(req);
503-
enable_acl = cib_acl_enabled(*current_cib, user);
502+
enable_acl = cib_acl_enabled(*cib, user);
504503

505504
pcmk__trace("Processing %s for section '%s', user '%s'", op,
506505
pcmk__s(section, "(null)"), pcmk__s(user, "(null)"));
507506
pcmk__log_xml_trace(req, "request");
508507

509508
if (!should_copy_cib(op, section, call_options)) {
510509
// Make a copy of the top-level element to store version details
511-
top = pcmk__xe_create(NULL, (const char *) (*current_cib)->name);
512-
pcmk__xe_copy_attrs(top, *current_cib, pcmk__xaf_none);
510+
top = pcmk__xe_create(NULL, (const char *) (*cib)->name);
511+
pcmk__xe_copy_attrs(top, *cib, pcmk__xaf_none);
513512
old_versions = top;
514513

515-
pcmk__xml_commit_changes((*current_cib)->doc);
516-
pcmk__xml_doc_set_flags((*current_cib)->doc, pcmk__xf_tracking);
514+
pcmk__xml_commit_changes((*cib)->doc);
515+
pcmk__xml_doc_set_flags((*cib)->doc, pcmk__xf_tracking);
517516
if (enable_acl) {
518-
pcmk__enable_acl(*current_cib, *current_cib, user);
517+
pcmk__enable_acl(*cib, *cib, user);
519518
}
520519

521-
rc = fn(op, call_options, section, req, input, current_cib, output);
520+
rc = fn(op, call_options, section, req, input, cib, output);
522521

523-
/* Set working_cib to *current_cib after fn(), in case *current_cib
524-
* points somewhere else now (for example, after a erase or full-CIB
525-
* replace op).
522+
/* Set working_cib to *cib after fn(), in case *cib points somewhere
523+
* else now (for example, after a erase or full-CIB replace op).
526524
*/
527-
working_cib = *current_cib;
525+
working_cib = *cib;
528526

529527
} else {
530-
working_cib = pcmk__xml_copy(NULL, *current_cib);
531-
old_versions = *current_cib;
528+
working_cib = pcmk__xml_copy(NULL, *cib);
529+
old_versions = *cib;
532530

533531
pcmk__xml_doc_set_flags(working_cib->doc, pcmk__xf_tracking);
534532
if (enable_acl) {
535-
pcmk__enable_acl(*current_cib, working_cib, user);
533+
pcmk__enable_acl(*cib, working_cib, user);
536534
}
537535

538536
rc = fn(op, call_options, section, req, input, &working_cib, output);
@@ -615,15 +613,15 @@ cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
615613
}
616614

617615
done:
618-
*result_cib = working_cib;
616+
*cib = working_cib;
619617

620618
/* @TODO This may not work correctly when !should_copy_cib(), since we don't
621619
* keep the original CIB.
622620
*/
623621
if ((rc != pcmk_rc_ok) && cib_acl_enabled(old_versions, user)
624-
&& xml_acl_filtered_copy(user, old_versions, working_cib, result_cib)) {
622+
&& xml_acl_filtered_copy(user, old_versions, working_cib, cib)) {
625623

626-
if (*result_cib == NULL) {
624+
if (*cib == NULL) {
627625
pcmk__debug("Pre-filtered the entire cib result");
628626
}
629627
pcmk__xml_free(working_cib);

0 commit comments

Comments
 (0)