Skip to content
Open
5 changes: 0 additions & 5 deletions daemons/controld/controld_fencing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions daemons/execd/pacemaker-execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions daemons/fenced/cts-fence-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions daemons/fenced/fenced_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions include/crm/fencing/internal.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
123 changes: 55 additions & 68 deletions lib/fencing/st_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions lib/lrmd/lrmd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 1 addition & 4 deletions lib/pacemaker/pcmk_setup.c
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions lib/pacemaker/pcmk_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/crm_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions tools/stonith_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down