Skip to content

Commit

Permalink
Merge pull request #3574 from nrwahl2/nrwahl2-backport
Browse files Browse the repository at this point in the history
[2.1] Fix: tools: crm_node -i must initialize nodeid before passing pointer
  • Loading branch information
nrwahl2 authored Jul 12, 2024
2 parents f04c3b0 + d7c2330 commit 239cba3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
6 changes: 5 additions & 1 deletion daemons/controld/controld_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,11 @@ handle_node_info_request(const xmlNode *msg)
pcmk_is_set(controld_globals.flags,
controld_has_quorum));

// Check whether client requested node info by ID and/or name
/* Check whether client requested node info by ID and/or name
*
* @TODO A Corosync-layer node ID is of type uint32_t. We should be able to
* handle legitimate node IDs greater than INT_MAX, but currently we do not.
*/
crm_element_value_int(msg, PCMK_XA_ID, &node_id);
if (node_id < 0) {
node_id = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/cluster/corosync.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ pcmk__corosync_add_nodes(xmlNode *xml_parent)
if (xml_parent) {
xmlNode *node = pcmk__xe_create(xml_parent, PCMK_XE_NODE);

crm_xml_set_id(node, "%u", nodeid);
crm_xml_add_ll(node, PCMK_XA_ID, (long long) nodeid);
crm_xml_add(node, PCMK_XA_UNAME, name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ipc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ create_purge_node_request(const pcmk_ipc_api_t *api, const char *node_name,
request = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL,
pcmk_ipc_name(api, false), client, NULL);
if (nodeid > 0) {
crm_xml_set_id(request, "%lu", (unsigned long) nodeid);
crm_xml_add_ll(request, PCMK_XA_ID, (long long) nodeid);
}
crm_xml_add(request, PCMK_XA_UNAME, node_name);
break;
Expand Down
9 changes: 6 additions & 3 deletions lib/common/ipc_controld.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#include <crm_internal.h>

#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <inttypes.h> // PRIu32
#include <stdbool.h>
#include <stdint.h> // uint32_t
#include <stdio.h>

#include <libxml/tree.h>

#include <crm/crm.h>
Expand Down Expand Up @@ -417,7 +420,7 @@ pcmk_controld_api_node_info(pcmk_ipc_api_t *api, uint32_t nodeid)
return EINVAL;
}
if (nodeid > 0) {
crm_xml_set_id(request, "%lu", (unsigned long) nodeid);
crm_xml_add_ll(request, PCMK_XA_ID, nodeid);
}

rc = send_controller_request(api, request, true);
Expand Down
22 changes: 11 additions & 11 deletions lib/pacemaker/pcmk_cluster_queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,25 +586,25 @@ pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
* the controller
*
* \param[in,out] out Output object
* \param[in,out] node_id ID of node whose name to get. If \p NULL
* or 0, get the local node name. If not
* \p NULL, store the true node ID here on
* \param[in,out] node_id ID of node whose info to get. If \p NULL
* or 0, get the local node's info. If not
* \c NULL, store the true node ID here on
* success.
* \param[out] node_name If not \p NULL, where to store the node
* \param[out] node_name If not \c NULL, where to store the node
* name
* \param[out] uuid If not \p NULL, where to store the node
* \param[out] uuid If not \c NULL, where to store the node
* UUID
* \param[out] state If not \p NULL, where to store the
* \param[out] state If not \c NULL, where to store the
* membership state
* \param[out] is_remote If not \p NULL, where to store whether the
* \param[out] is_remote If not \c NULL, where to store whether the
* node is a Pacemaker Remote node
* \param[out] have_quorum If not \p NULL, where to store whether the
* \param[out] have_quorum If not \c NULL, where to store whether the
* node has quorum
* \param[in] show_output Whether to show the node info
* \param[in] message_timeout_ms How long to wait for a reply from the
* \p pacemaker-controld API. If 0,
* \p pcmk_ipc_dispatch_sync will be used.
* Otherwise, \p pcmk_ipc_dispatch_poll will
* \c pacemaker-controld API. If 0,
* \c pcmk_ipc_dispatch_sync will be used.
* Otherwise, \c pcmk_ipc_dispatch_poll will
* be used.
*
* \return Standard Pacemaker return code
Expand Down
6 changes: 3 additions & 3 deletions tools/crm_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ run_controller_mainloop(void)
static void
print_node_id(void)
{
uint32_t nodeid;
uint32_t nodeid = 0;
int rc = pcmk__query_node_info(out, &nodeid, NULL, NULL, NULL, NULL, NULL,
false, 0);

Expand Down Expand Up @@ -549,7 +549,7 @@ remove_from_section(cib_t *cib, const char *element, const char *section,

crm_xml_add(xml, PCMK_XA_UNAME, node_name);
if (node_id > 0) {
crm_xml_set_id(xml, "%ld", node_id);
crm_xml_add_ll(xml, PCMK_XA_ID, node_id);
}

rc = cib->cmds->remove(cib, section, xml, cib_transaction);
Expand Down Expand Up @@ -689,7 +689,7 @@ purge_node_from_fencer(const char *node_name, long node_id)
cmd = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL, "stonith-ng",
crm_system_name, NULL);
if (node_id > 0) {
crm_xml_set_id(cmd, "%ld", node_id);
crm_xml_add_ll(cmd, PCMK_XA_ID, node_id);
}
crm_xml_add(cmd, PCMK_XA_UNAME, node_name);

Expand Down

0 comments on commit 239cba3

Please sign in to comment.