Skip to content

Commit

Permalink
Refactor: libcrmcommon: make pcmk_update_configured_schema() return a…
Browse files Browse the repository at this point in the history
… standard code

The callers can now just return the code directly (which does change the code
in a few cases, but for the better)
  • Loading branch information
kgaillot committed May 9, 2024
1 parent 2a6666d commit 05e8f1b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions daemons/execd/cts-exec-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ generate_params(void)
if (rc != pcmk_rc_ok) {
return rc;
}
if (!pcmk_update_configured_schema(&cib_xml_copy, false)) {
crm_err("Could not update CIB");
return pcmk_rc_cib_corrupt;
rc = pcmk_update_configured_schema(&cib_xml_copy, false);
if (rc != pcmk_rc_ok) {
return rc;
}

// Calculate cluster status
Expand Down
2 changes: 1 addition & 1 deletion daemons/schedulerd/schedulerd_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ handle_pecalc_request(pcmk__request_t *request)
digest = calculate_xml_versioned_digest(xml_data, FALSE, FALSE,
CRM_FEATURE_SET);
converted = pcmk__xml_copy(NULL, xml_data);
if (!pcmk_update_configured_schema(&converted, true)) {
if (pcmk_update_configured_schema(&converted, true) != pcmk_rc_ok) {
scheduler->graph = pcmk__xe_create(NULL, PCMK__XE_TRANSITION_GRAPH);
crm_xml_add_int(scheduler->graph, "transition_id", 0);
crm_xml_add_int(scheduler->graph, PCMK_OPT_CLUSTER_DELAY, 0);
Expand Down
2 changes: 1 addition & 1 deletion include/crm/common/schemas.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
* \ingroup core
*/

bool pcmk_update_configured_schema(xmlNode **xml, bool to_logs);
int pcmk_update_configured_schema(xmlNode **xml, bool to_logs);

#ifdef __cplusplus
}
Expand Down
14 changes: 8 additions & 6 deletions lib/common/schemas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,12 +1243,12 @@ pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
* \param[in] to_logs If false, certain validation errors will be
* sent to stderr rather than logged
*
* \return true if XML was successfully updated, otherwise false
* \return Standard Pacemaker return code
*/
bool
int
pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
{
bool rc = true;
int rc = pcmk_rc_ok;
char *original_schema_name = NULL;

// @COMPAT Not specifying a schema name is deprecated since 2.1.8
Expand All @@ -1258,6 +1258,8 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
pcmk__schema_t *x_0_schema = pcmk__find_x_0_schema()->data;
GList *entry = NULL;

CRM_CHECK(xml != NULL, return EINVAL);

original_schema_name = crm_element_value_copy(*xml, PCMK_XA_VALIDATE_WITH);
pcmk__warn_if_schema_deprecated(original_schema_name);
entry = pcmk__get_schema(original_schema_name);
Expand Down Expand Up @@ -1326,7 +1328,7 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)

free_xml(converted);
converted = NULL;
rc = false;
rc = pcmk_rc_transform_failed;

} else {
// Updated configuration schema is acceptable
Expand Down Expand Up @@ -1718,7 +1720,7 @@ validate_xml_verbose(const xmlNode *xml_blob)
gboolean
cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
{
bool rc = pcmk_update_configured_schema(xml, to_logs);
int rc = pcmk_update_configured_schema(xml, to_logs);

if (best_version != NULL) {
const char *name = crm_element_value(*xml, PCMK_XA_VALIDATE_WITH);
Expand All @@ -1732,7 +1734,7 @@ cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
*best_version = (schema == NULL)? -1 : schema->schema_index;
}
}
return rc? TRUE: FALSE;
return (rc == pcmk_rc_ok)? TRUE: FALSE;
}

// LCOV_EXCL_STOP
Expand Down
2 changes: 1 addition & 1 deletion lib/pacemaker/pcmk_simulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ profile_file(const char *xml_file, long long repeat,
pcmk__xe_create(cib_object, PCMK_XE_STATUS);
}

if (!pcmk_update_configured_schema(&cib_object, false)) {
if (pcmk_update_configured_schema(&cib_object, false) != pcmk_rc_ok) {
free_xml(cib_object);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pacemaker/pcmk_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ pcmk__output_cluster_status(pcmk__output_t *out, stonith_t *stonith, cib_t *cib,

int rc = pcmk_rc_ok;

if (!pcmk_update_configured_schema(&cib_copy, false)) {
rc = pcmk_update_configured_schema(&cib_copy, false);
if (rc != pcmk_rc_ok) {
cib__clean_up_connection(&cib);
free_xml(cib_copy);
rc = pcmk_rc_schema_validation;
out->err(out, "Upgrade failed: %s", pcmk_rc_str(rc));
return rc;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/pacemaker/pcmk_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ pcmk__verify(pcmk_scheduler_t *scheduler, pcmk__output_t *out, xmlNode *cib_obje
crm_config_error = TRUE;
rc = pcmk_rc_schema_validation;
goto verify_done;
}

} else if (!pcmk_update_configured_schema(&cib_object, false)) {
rc = pcmk_update_configured_schema(&cib_object, false);
if (rc != pcmk_rc_ok) {
crm_config_error = TRUE;
out->err(out, "The cluster will NOT be able to use this configuration.\n"
"Please manually update the configuration to conform to the %s syntax.",
pcmk__highest_schema_name());
rc = pcmk_rc_schema_validation;
goto verify_done;
}

Expand Down
13 changes: 5 additions & 8 deletions tools/crm_resource_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,19 +1237,16 @@ static void display_list(pcmk__output_t *out, GList *items, const char *tag)
* \return Standard Pacemaker return code
* \note On success, caller is responsible for freeing memory allocated for
* scheduler->now.
* \todo This follows the example of other callers of
* pcmk_update_configured_schema() and returns ENOKEY ("Required key not
* available") if that fails, but perhaps pcmk_rc_schema_validation would
* be better in that case.
*/
int
update_scheduler_input(pcmk_scheduler_t *scheduler, xmlNode **xml)
{
if (!pcmk_update_configured_schema(xml, false)) {
return ENOKEY;
int rc = pcmk_update_configured_schema(xml, false);

if (rc == pcmk_rc_ok) {
scheduler->input = *xml;
scheduler->now = crm_time_new(NULL);
}
scheduler->input = *xml;
scheduler->now = crm_time_new(NULL);
return pcmk_rc_ok;
}

Expand Down
5 changes: 3 additions & 2 deletions tools/crm_simulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,10 @@ setup_input(pcmk__output_t *out, const char *input, const char *output,
pcmk__xe_create(cib_object, PCMK_XE_STATUS);
}

if (!pcmk_update_configured_schema(&cib_object, false)) {
rc = pcmk_update_configured_schema(&cib_object, false);
if (rc != pcmk_rc_ok) {
free_xml(cib_object);
return pcmk_rc_transform_failed;
return rc;
}

if (!pcmk__validate_xml(cib_object, NULL, NULL, NULL)) {
Expand Down
5 changes: 3 additions & 2 deletions tools/crm_ticket.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ main(int argc, char **argv)
}
}

if (!pcmk_update_configured_schema(&cib_xml_copy, false)) {
exit_code = CRM_EX_CONFIG;
rc = pcmk_update_configured_schema(&cib_xml_copy, false);
if (rc != pcmk_rc_ok) {
exit_code = pcmk_rc2exitc(rc);
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Could not update local CIB to latest schema version");
goto done;
Expand Down

0 comments on commit 05e8f1b

Please sign in to comment.