Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors from cluster_status #3735

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
11 changes: 9 additions & 2 deletions lib/pacemaker/pcmk_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ int
pcmk__init_scheduler(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *date,
pcmk_scheduler_t **scheduler)
{
int rc = pcmk_rc_ok;

// Allows for cleaner syntax than dereferencing the scheduler argument
pcmk_scheduler_t *new_scheduler = NULL;

Expand All @@ -857,7 +859,7 @@ pcmk__init_scheduler(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *da
}

} else {
int rc = cib__signon_query(out, NULL, &(new_scheduler->input));
rc = cib__signon_query(out, NULL, &(new_scheduler->input));

if (rc != pcmk_rc_ok) {
pe_free_working_set(new_scheduler);
Expand All @@ -873,7 +875,12 @@ pcmk__init_scheduler(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *da
}

// Unpack everything
pcmk_unpack_scheduler_input(new_scheduler);
rc = pcmk_unpack_scheduler_input(new_scheduler);
if (rc != pcmk_rc_ok) {
pe_free_working_set(new_scheduler);
return rc;
}
clumens marked this conversation as resolved.
Show resolved Hide resolved

*scheduler = new_scheduler;

return pcmk_rc_ok;
Expand Down
19 changes: 15 additions & 4 deletions lib/pacemaker/pcmk_simulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,11 @@ pcmk__simulate(pcmk_scheduler_t *scheduler, pcmk__output_t *out,
}

reset(scheduler, input, out, use_date, flags);
pcmk_unpack_scheduler_input(scheduler);
rc = pcmk_unpack_scheduler_input(scheduler);

if (rc != pcmk_rc_ok) {
goto simulate_done;
}

if (!out->is_quiet(out)) {
const bool show_pending = pcmk_is_set(flags, pcmk_sim_show_pending);
Expand Down Expand Up @@ -862,6 +866,11 @@ pcmk__simulate(pcmk_scheduler_t *scheduler, pcmk__output_t *out,

cleanup_calculations(scheduler);
reset(scheduler, input, out, use_date, flags);
/* pcmk_unpack_scheduler_input only returns error on scheduler being
* NULL or the feature set being unsupported. Neither of those
* conditions could have changed since the first call, so there's no
* need to check the return value again.
*/
clumens marked this conversation as resolved.
Show resolved Hide resolved
pcmk_unpack_scheduler_input(scheduler);
}

Expand Down Expand Up @@ -972,9 +981,11 @@ pcmk__simulate(pcmk_scheduler_t *scheduler, pcmk__output_t *out,
pcmk__set_scheduler_flags(scheduler, pcmk__sched_show_utilization);
}

pcmk_unpack_scheduler_input(scheduler);
print_cluster_status(scheduler, 0, section_opts, "Revised Cluster Status",
true);
rc = pcmk_unpack_scheduler_input(scheduler);
if (rc == pcmk_rc_ok) {
print_cluster_status(scheduler, 0, section_opts, "Revised Cluster Status",
true);
}

simulate_done:
cib__clean_up_connection(&cib);
Expand Down
9 changes: 8 additions & 1 deletion lib/pacemaker/pcmk_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ pcmk__output_cluster_status(pcmk_scheduler_t *scheduler, stonith_t *stonith,

pe_reset_working_set(scheduler);
scheduler->input = cib_copy;
pcmk_unpack_scheduler_input(scheduler);
rc = pcmk_unpack_scheduler_input(scheduler);

if (rc != pcmk_rc_ok) {
/* Now that we've set up the scheduler, it's up to the caller to clean up.
* Doing cleanup here can result in double frees of XML or CIB data.
*/
return rc;
}

/* Unpack constraints if any section will need them
* (tickets may be referenced in constraints but not granted yet,
Expand Down