diff --git a/daemons/controld/controld_fencing.c b/daemons/controld/controld_fencing.c index 281aa0f6fba..c3df6d5d2d4 100644 --- a/daemons/controld/controld_fencing.c +++ b/daemons/controld/controld_fencing.c @@ -654,11 +654,6 @@ controld_timer_fencer_connect(void *user_data) if (fencer_api == NULL) { fencer_api = stonith__api_new(); - if (fencer_api == NULL) { - pcmk__err("Could not connect to fencer: API memory allocation " - "failed"); - return G_SOURCE_REMOVE; - } } if (fencer_api->state != stonith_disconnected) { diff --git a/daemons/execd/pacemaker-execd.c b/daemons/execd/pacemaker-execd.c index 26b780e8e9a..45241da86c6 100644 --- a/daemons/execd/pacemaker-execd.c +++ b/daemons/execd/pacemaker-execd.c @@ -76,11 +76,6 @@ execd_get_fencer_connection(void) int rc = pcmk_ok; fencer_api = stonith__api_new(); - if (fencer_api == NULL) { - pcmk__err("Could not connect to fencer: API memory allocation " - "failed"); - return NULL; - } rc = stonith__api_connect_retry(fencer_api, crm_system_name, 10); if (rc != pcmk_rc_ok) { diff --git a/daemons/fenced/cts-fence-helper.c b/daemons/fenced/cts-fence-helper.c index 2de750c3e1a..3fde1c88698 100644 --- a/daemons/fenced/cts-fence-helper.c +++ b/daemons/fenced/cts-fence-helper.c @@ -644,12 +644,6 @@ main(int argc, char **argv) } st = stonith__api_new(); - if (st == NULL) { - exit_code = CRM_EX_DISCONNECT; - g_set_error(&error, PCMK__EXITC_ERROR, exit_code, - "Could not connect to fencer: API memory allocation failed"); - goto done; - } switch (options.mode) { case test_standard: diff --git a/daemons/fenced/fenced_commands.c b/daemons/fenced/fenced_commands.c index 9c8f0667b36..8efc136be96 100644 --- a/daemons/fenced/fenced_commands.c +++ b/daemons/fenced/fenced_commands.c @@ -1033,12 +1033,6 @@ get_agent_metadata(const char *agent, xmlNode ** metadata) st = stonith__api_new(); - if (st == NULL) { - pcmk__warn("Could not get agent meta-data: API memory allocation " - "failed"); - return EAGAIN; - } - rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, 10); stonith__api_free(st); diff --git a/include/crm/fencing/internal.h b/include/crm/fencing/internal.h index d2a670544c3..1124a9456f4 100644 --- a/include/crm/fencing/internal.h +++ b/include/crm/fencing/internal.h @@ -1,5 +1,5 @@ /* - * Copyright 2011-2025 the Pacemaker project contributors + * Copyright 2011-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -166,8 +166,8 @@ stonith__op_state_pending(enum op_state state) return state != st_failed && state != st_done; } -gboolean stonith__watchdog_fencing_enabled_for_node(const char *node); -gboolean stonith__watchdog_fencing_enabled_for_node_api(stonith_t *st, const char *node); +bool stonith__watchdog_fencing_enabled_for_node(const char *node); +bool stonith__watchdog_fencing_enabled_for_node_api(stonith_t *st, const char *node); /*! * \internal diff --git a/lib/fencing/st_client.c b/lib/fencing/st_client.c index 33e41d7ff8f..41e455d18ac 100644 --- a/lib/fencing/st_client.c +++ b/lib/fencing/st_client.c @@ -176,71 +176,73 @@ get_namespace_from_agent(const char *agent) return st_namespace_invalid; } -gboolean -stonith__watchdog_fencing_enabled_for_node_api(stonith_t *st, const char *node) +bool +stonith__watchdog_fencing_enabled_for_node_api(stonith_t *stonith, + const char *node) { - gboolean rv = FALSE; - stonith_t *stonith_api = (st != NULL)? st : stonith__api_new(); + int rc = pcmk_ok; + bool enabled = false; char *list = NULL; + GList *targets = NULL; - if(stonith_api) { - if (stonith_api->state == stonith_disconnected) { - int rc = stonith_api->cmds->connect(stonith_api, "stonith-api", NULL); + pcmk__assert((stonith != NULL) && (stonith->state != stonith_disconnected)); - if (rc != pcmk_ok) { - pcmk__err("Failed connecting to Stonith-API for " - "watchdog-fencing-query"); - } - } + /* caveat!!! + * this might fail when the fencer is just updating the device-list + * probably something we should fix as well for other api-calls */ + rc = stonith->cmds->list(stonith, st_opt_sync_call, STONITH_WATCHDOG_ID, + &list, 0); - if (stonith_api->state != stonith_disconnected) { - /* caveat!!! - * this might fail when the fencer is just updating the device-list - * probably something we should fix as well for other api-calls */ - int rc = stonith_api->cmds->list(stonith_api, st_opt_sync_call, STONITH_WATCHDOG_ID, &list, 0); - if ((rc != pcmk_ok) || (list == NULL)) { - /* due to the race described above it can happen that - * we drop in here - so as not to make remote nodes - * panic on that answer - */ - if (rc == -ENODEV) { - pcmk__notice("Cluster does not have watchdog fencing " - "device"); - } else { - pcmk__warn("Could not check for watchdog fencing device: %s", - pcmk_strerror(rc)); - } - } else if (list[0] == '\0') { - rv = TRUE; - } else { - GList *targets = stonith__parse_targets(list); - rv = pcmk__str_in_list(node, targets, pcmk__str_casei); - g_list_free_full(targets, free); - } - free(list); - if (!st) { - /* if we're provided the api we still might have done the - * connection - but let's assume the caller won't bother - */ - stonith_api->cmds->disconnect(stonith_api); - } - } + if ((rc != pcmk_ok) || (list == NULL)) { + /* due to the race described above it can happen that + * we drop in here - so as not to make remote nodes + * panic on that answer + */ + if (rc == -ENODEV) { + pcmk__debug("Cluster does not have watchdog fencing device"); - if (!st) { - stonith__api_free(stonith_api); + } else { + pcmk__warn("Could not check for watchdog fencing device: %s", + pcmk_strerror(rc)); } - } else { - pcmk__err("Stonith-API for watchdog-fencing-query couldn't be created"); + + goto done; + } + + if (list[0] == '\0') { + enabled = true; + goto done; } - pcmk__trace("Pacemaker assumes node %s %sto do watchdog-fencing", node, - (rv? "" : "not ")); - return rv; + + targets = stonith__parse_targets(list); + enabled = pcmk__str_in_list(node, targets, pcmk__str_casei); + +done: + free(list); + g_list_free_full(targets, free); + return enabled; } -gboolean +bool stonith__watchdog_fencing_enabled_for_node(const char *node) { - return stonith__watchdog_fencing_enabled_for_node_api(NULL, node); + stonith_t *stonith = stonith__api_new(); + int rc = pcmk_ok; + bool enabled = false; + + rc = stonith->cmds->connect(stonith, "stonith-api", NULL); + if (rc != pcmk_ok) { + pcmk__err("Failed to connect to fencer API for watchdog query: %s", + pcmk_strerror(rc)); + goto done; + } + + enabled = stonith__watchdog_fencing_enabled_for_node_api(stonith, node); + +done: + stonith->cmds->disconnect(stonith); + stonith__api_free(stonith); + return enabled; } /* when cycling through the list we don't want to delete items @@ -2105,11 +2107,6 @@ stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off) const char *action = off? PCMK_ACTION_OFF : PCMK_ACTION_REBOOT; api_log_open(); - if (st == NULL) { - api_log(LOG_ERR, "API initialization failed, could not kick (%s) node %u/%s", - action, nodeid, uname); - return -EPROTO; - } rc = st->cmds->connect(st, "stonith-api", NULL); if (rc != pcmk_ok) { @@ -2147,12 +2144,6 @@ stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress) stonith_t *st = stonith__api_new(); stonith_history_t *history = NULL, *hp = NULL; - if (st == NULL) { - api_log(LOG_ERR, "Could not retrieve fence history for %u/%s: " - "API initialization failed", nodeid, uname); - return when; - } - rc = st->cmds->connect(st, "stonith-api", NULL); if (rc != pcmk_ok) { api_log(LOG_NOTICE, "Connection failed: %s (%d)", pcmk_strerror(rc), rc); @@ -2224,10 +2215,6 @@ stonith__agent_exists(const char *name) } stonith_api = stonith__api_new(); - if (stonith_api == NULL) { - pcmk__err("Could not list fence agents: API memory allocation failed"); - return false; - } // The list_agents method ignores its timeout argument stonith_api->cmds->list_agents(stonith_api, st_opt_sync_call, NULL, &agents, diff --git a/lib/lrmd/lrmd_client.c b/lib/lrmd/lrmd_client.c index 65b23df8edd..d88b93fac0b 100644 --- a/lib/lrmd/lrmd_client.c +++ b/lib/lrmd/lrmd_client.c @@ -1955,10 +1955,6 @@ list_stonith_agents(lrmd_list_t **resources) stonith_key_value_t *stonith_resources = NULL; stonith_key_value_t *dIter = NULL; - if (stonith_api == NULL) { - pcmk__err("Could not list fence agents: API memory allocation failed"); - return -ENOMEM; - } stonith_api->cmds->list_agents(stonith_api, st_opt_sync_call, NULL, &stonith_resources, 0); stonith_api->cmds->free(stonith_api); @@ -2111,12 +2107,6 @@ stonith_get_metadata(const char *type, char **output) int rc = pcmk_ok; stonith_t *stonith_api = stonith__api_new(); - if (stonith_api == NULL) { - pcmk__err("Could not get fence agent meta-data: API memory allocation " - "failed"); - return -ENOMEM; - } - rc = stonith_api->cmds->metadata(stonith_api, st_opt_sync_call, type, NULL, output, 0); if ((rc == pcmk_ok) && (*output == NULL)) { diff --git a/lib/pacemaker/pcmk_setup.c b/lib/pacemaker/pcmk_setup.c index 80a78c5fb66..61b8d836c78 100644 --- a/lib/pacemaker/pcmk_setup.c +++ b/lib/pacemaker/pcmk_setup.c @@ -1,5 +1,5 @@ /* - * Copyright 2024-2025 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -104,9 +104,6 @@ pcmk__setup_output_fencing(pcmk__output_t **out, stonith_t **st, xmlNode **xml) } *st = stonith__api_new(); - if (*st == NULL) { - return ENOMEM; - } rc = (*st)->cmds->connect(*st, crm_system_name, NULL); if (rc < 0) { diff --git a/lib/pacemaker/pcmk_status.c b/lib/pacemaker/pcmk_status.c index 49f897b3498..c38eabe66e8 100644 --- a/lib/pacemaker/pcmk_status.c +++ b/lib/pacemaker/pcmk_status.c @@ -39,10 +39,6 @@ fencing_connect(void) stonith_t *st = stonith__api_new(); int rc = pcmk_rc_ok; - if (st == NULL) { - return NULL; - } - rc = st->cmds->connect(st, crm_system_name, NULL); if (rc == pcmk_rc_ok) { return st; diff --git a/tools/crm_mon.c b/tools/crm_mon.c index c45a4dfe2a4..a9b54aa399e 100644 --- a/tools/crm_mon.c +++ b/tools/crm_mon.c @@ -902,7 +902,7 @@ setup_fencer_connection(void) st = stonith__api_new(); } - if (!options.fence_connect || st == NULL || st->state != stonith_disconnected) { + if (!options.fence_connect || (st->state != stonith_disconnected)) { return rc; } diff --git a/tools/stonith_admin.c b/tools/stonith_admin.c index ef8face6f3d..24cb91f6f3e 100644 --- a/tools/stonith_admin.c +++ b/tools/stonith_admin.c @@ -570,11 +570,11 @@ main(int argc, char **argv) out->quiet = args->quiet; st = stonith__api_new(); - if (st == NULL) { - rc = -ENOMEM; - } else if (!no_connect) { + + if (!no_connect) { rc = st->cmds->connect(st, name, NULL); } + if (rc < 0) { out->err(out, "Could not connect to fencer: %s", pcmk_strerror(rc)); exit_code = CRM_EX_DISCONNECT;