Skip to content

Commit 844f341

Browse files
committed
Low: libcib: Move CIB op input transformation to ops that need it
I've been testing full-CIB replacements and encountered some problems due to the early input transformation (currently in get_op_input()), particularly with XPath. When we're treating the section string as an XPath expression, it doesn't make sense to try to find it as an element of input. (That is, unless we want to do an XPath search, which we can think about if necessary.) This moves the input transformation to the operations that need it, and performs it only when NOT treating the section as XPath. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent fd059dc commit 844f341

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

lib/cib/cib_ops.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,19 @@ cib__process_create(const char *op, int options, const char *section,
300300
int rc = pcmk_rc_ok;
301301
xmlNode *update_section = NULL;
302302

303-
if (pcmk__str_eq(PCMK__XE_ALL, section, pcmk__str_casei)) {
304-
section = NULL;
305-
306-
} else if (pcmk__str_eq(section, PCMK_XE_CIB, pcmk__str_casei)) {
307-
section = NULL;
308-
309-
} else if (pcmk__xe_is(input, PCMK_XE_CIB)) {
310-
section = NULL;
303+
if ((section != NULL) && pcmk__xe_is(input, PCMK_XE_CIB)) {
304+
input = pcmk_find_cib_element(input, section);
311305
}
312306

313-
CRM_CHECK(strcmp(op, PCMK__CIB_REQUEST_CREATE) == 0, return -EINVAL);
314-
315307
if (input == NULL) {
316308
pcmk__err("Cannot perform modification with no data");
317309
return EINVAL;
318310
}
319311

320-
if (section == NULL) {
321-
return cib__process_modify(op, options, section, req, input, cib,
312+
if (pcmk__strcase_any_of(section, PCMK__XE_ALL, PCMK_XE_CIB, NULL)
313+
|| pcmk__xe_is(input, PCMK_XE_CIB)) {
314+
315+
return cib__process_modify(op, options, NULL, req, input, cib,
322316
answer);
323317
}
324318

@@ -446,6 +440,10 @@ process_delete_section(const char *section, xmlNode *input, xmlNode *cib)
446440
{
447441
xmlNode *obj_root = NULL;
448442

443+
if ((section != NULL) && pcmk__xe_is(input, PCMK_XE_CIB)) {
444+
input = pcmk_find_cib_element(input, section);
445+
}
446+
449447
if (input == NULL) {
450448
pcmk__err("Cannot find matching section to delete with no input data");
451449
return EINVAL;
@@ -556,6 +554,10 @@ process_modify_section(int options, const char *section, xmlNode *input,
556554
const uint32_t flags = (score? pcmk__xaf_score_update : pcmk__xaf_none);
557555
xmlNode *obj_root = NULL;
558556

557+
if ((section != NULL) && pcmk__xe_is(input, PCMK_XE_CIB)) {
558+
input = pcmk_find_cib_element(input, section);
559+
}
560+
559561
if (input == NULL) {
560562
pcmk__err("Cannot complete CIB modify request with no input data");
561563
return EINVAL;
@@ -875,6 +877,10 @@ process_replace_section(const char *section, xmlNode *request, xmlNode *input,
875877
int rc = pcmk_rc_ok;
876878
xmlNode *obj_root = NULL;
877879

880+
if ((section != NULL) && pcmk__xe_is(input, PCMK_XE_CIB)) {
881+
input = pcmk_find_cib_element(input, section);
882+
}
883+
878884
if (input == NULL) {
879885
pcmk__err("Cannot find matching section to replace with no input data");
880886
return EINVAL;

lib/cib/cib_utils.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,17 @@ cib_acl_enabled(xmlNode *xml, const char *user)
173173

174174
/*!
175175
* \internal
176-
* \brief Get input data from a CIB request, based on section and call data
176+
* \brief Get input data from a CIB request
177177
*
178178
* \param[in] request CIB request XML
179179
*/
180180
static xmlNode *
181181
get_op_input(const xmlNode *request)
182182
{
183-
const char *section = pcmk__xe_get(request, PCMK__XA_CIB_SECTION);
184183
xmlNode *wrapper = pcmk__xe_first_child(request, PCMK__XE_CIB_CALLDATA,
185184
NULL, NULL);
186-
xmlNode *input = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
187185

188-
if ((section == NULL) || !pcmk__xe_is(input, PCMK_XE_CIB)) {
189-
return input;
190-
}
191-
192-
return pcmk_find_cib_element(input, section);
186+
return pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
193187
}
194188

195189
int

0 commit comments

Comments
 (0)