Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions daemons/based/based_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,9 @@ cib_process_command(xmlNode *request, const cib__operation_t *operation,
*/
if ((operation->type == cib__op_commit_transact)
&& pcmk__str_eq(originator, OUR_NODENAME, pcmk__str_casei)
&& compare_version(pcmk__xe_get(the_cib, PCMK_XA_CRM_FEATURE_SET),
"3.19.0") < 0) {
&& (pcmk__compare_versions(pcmk__xe_get(the_cib,
PCMK_XA_CRM_FEATURE_SET),
"3.19.0") < 0)) {

sync_our_cib(request, TRUE);
}
Expand Down
5 changes: 3 additions & 2 deletions daemons/controld/controld_cib.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ build_parameter_list(const lrmd_event_data_t *op,
/* Consider all parameters only except private ones to be consistent with
* what scheduler does with calculate_secure_digest().
*/
if (param_type == ra_param_private
&& compare_version(controld_globals.dc_version, "3.16.0") >= 0) {
if ((param_type == ra_param_private)
&& (pcmk__compare_versions(controld_globals.dc_version,
"3.16.0") >= 0)) {
g_hash_table_foreach(op->params, hash2field, *result);
pcmk__filter_op_for_digest(*result);
}
Expand Down
2 changes: 1 addition & 1 deletion daemons/controld/controld_execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ process_lrm_event(lrm_state_t *lrm_state, lrmd_event_data_t *op,
CRM_CHECK(op->rsc_id != NULL, return);

// Remap new status codes for older DCs
if (compare_version(controld_globals.dc_version, "3.2.0") < 0) {
if (pcmk__compare_versions(controld_globals.dc_version, "3.2.0") < 0) {
switch (op->op_status) {
case PCMK_EXEC_NOT_CONNECTED:
lrmd__set_result(op, PCMK_OCF_CONNECTION_DIED,
Expand Down
6 changes: 4 additions & 2 deletions daemons/controld/controld_membership.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ create_node_state_update(pcmk__node_status_t *node, uint32_t flags,
* "< 3.18.0" code here and below.
*/
if (pcmk__is_set(flags, controld_node_update_cluster)) {
if (compare_version(controld_globals.dc_version, "3.18.0") >= 0) {
if (pcmk__compare_versions(controld_globals.dc_version,
"3.18.0") >= 0) {
// A value 0 means the node is not a cluster member.
pcmk__xe_set_ll(node_state, PCMK__XA_IN_CCM, node->when_member);

Expand All @@ -174,7 +175,8 @@ create_node_state_update(pcmk__node_status_t *node, uint32_t flags,

if (!pcmk__is_set(node->flags, pcmk__node_status_remote)) {
if (pcmk__is_set(flags, controld_node_update_peer)) {
if (compare_version(controld_globals.dc_version, "3.18.0") >= 0) {
if (pcmk__compare_versions(controld_globals.dc_version,
"3.18.0") >= 0) {
// A value 0 means the peer is offline in CPG.
pcmk__xe_set_ll(node_state, PCMK_XA_CRMD, node->when_online);

Expand Down
7 changes: 4 additions & 3 deletions daemons/controld/controld_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ log_ra_ocf_version(const char *ra_key, const char *ra_ocf_version)
if (pcmk__str_empty(ra_ocf_version)) {
crm_warn("%s does not advertise OCF version supported", ra_key);

} else if (compare_version(ra_ocf_version, "2") >= 0) {
} else if (pcmk__compare_versions(ra_ocf_version, "2") >= 0) {
crm_warn("%s supports OCF version %s (this Pacemaker version supports "
PCMK_OCF_VERSION " and might not work properly with agent)",
ra_key, ra_ocf_version);

} else if (compare_version(ra_ocf_version, PCMK_OCF_VERSION) > 0) {
} else if (pcmk__compare_versions(ra_ocf_version, PCMK_OCF_VERSION) > 0) {
crm_info("%s supports OCF version %s (this Pacemaker version supports "
PCMK_OCF_VERSION " and might not use all agent features)",
ra_key, ra_ocf_version);
Expand Down Expand Up @@ -151,7 +151,8 @@ controld_cache_metadata(GHashTable *mdc, const lrmd_rsc_info_t *rsc,
}
log_ra_ocf_version(key, (const char *) content);
if (content != NULL) {
ocf1_1 = (compare_version((const char *) content, "1.1") >= 0);
ocf1_1 = (pcmk__compare_versions((const char *) content,
"1.1") >= 0);
xmlFree(content);
}
}
Expand Down
3 changes: 2 additions & 1 deletion daemons/execd/execd_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,8 @@ execd_process_signon(pcmk__client_t *client, xmlNode *request, int call_id,
PCMK__XA_LRMD_PROTOCOL_VERSION);
const char *start_state = pcmk__env_option(PCMK__ENV_NODE_START_STATE);

if (compare_version(protocol_version, LRMD_COMPATIBLE_PROTOCOL) < 0) {
if (pcmk__compare_versions(protocol_version,
LRMD_COMPATIBLE_PROTOCOL) < 0) {
crm_err("Cluster API version must be greater than or equal to %s, not %s",
LRMD_COMPATIBLE_PROTOCOL, protocol_version);
rc = EPROTO;
Expand Down
2 changes: 1 addition & 1 deletion include/crm/cib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
* \ingroup cib
*/

// Use compare_version() for doing comparisons
// Use pcmk__compare_versions() for doing comparisons
# define CIB_FEATURE_SET "2.0"

/* Core functions */
Expand Down
3 changes: 1 addition & 2 deletions include/crm/common/actions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
* Copyright 2004-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand All @@ -11,7 +11,6 @@
#define PCMK__CRM_COMMON_ACTIONS__H

#include <stdbool.h> // bool
#include <strings.h> // strcasecmp()
#include <glib.h> // gboolean, guint
#include <libxml/tree.h> // xmlNode

Expand Down
1 change: 1 addition & 0 deletions include/crm/common/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pcmk__flag_text(uint64_t flag_group, uint64_t flags)

// miscellaneous utilities (from utils.c)

int pcmk__compare_versions(const char *version1, const char *version2);
int pcmk__daemon_user(uid_t *uid, gid_t *gid);
char *pcmk__generate_uuid(void);
int pcmk__lookup_user(const char *name, uid_t *uid, gid_t *gid);
Expand Down
4 changes: 2 additions & 2 deletions include/crm/common/nodes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
* Copyright 2004-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand All @@ -11,7 +11,7 @@
#define PCMK__CRM_COMMON_NODES__H

#include <stdbool.h> // bool
#include <glib.h> // gboolean, GList, GHashTable
#include <glib.h> // gboolean, GList
#include <libxml/tree.h> // xmlNode

#include <crm/common/scheduler_types.h> // pcmk_resource_t, pcmk_scheduler_t
Expand Down
5 changes: 2 additions & 3 deletions include/crm/common/nvpair.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
* Copyright 2004-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand All @@ -10,8 +10,7 @@
#ifndef PCMK__CRM_COMMON_NVPAIR__H
#define PCMK__CRM_COMMON_NVPAIR__H

#include <sys/time.h> // struct timeval
#include <glib.h> // gpointer, gboolean, guint, GHashTable
#include <glib.h> // gpointer, GHashTable
#include <libxml/tree.h> // xmlNode

#include <crm/crm.h>
Expand Down
3 changes: 1 addition & 2 deletions include/crm/common/schemas.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 the Pacemaker project contributors
* Copyright 2024-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand All @@ -10,7 +10,6 @@
#ifndef PCMK__CRM_COMMON_SCHEMAS__H
#define PCMK__CRM_COMMON_SCHEMAS__H

#include <stdbool.h> // bool
#include <libxml/tree.h> // xmlNode

#ifdef __cplusplus
Expand Down
2 changes: 0 additions & 2 deletions include/crm/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ char *pcmk_promotion_score_name(const char *rsc_id);
/* public Pacemaker Remote functions (from remote.c) */
int crm_default_remote_port(void);

int compare_version(const char *version1, const char *version2);

void pcmk_common_cleanup(void);

#ifdef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions include/crm/common/util_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ int pcmk_daemon_user(uid_t *uid, gid_t *gid);
//! \deprecated Do not use
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid);

//! \deprecated Do not use
int compare_version(const char *version1, const char *version2);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 4 additions & 2 deletions include/crm/lrmd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the Pacemaker project contributors
* Copyright 2012-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand All @@ -16,6 +16,8 @@
#include <crm/lrmd_events.h>
#include <crm/services.h>

#include <crm/common/internal.h> // pcmk__compare_versions()

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -43,7 +45,7 @@ typedef struct lrmd_key_value_s {
*/
#define LRMD_PROTOCOL_VERSION "1.2"

#define LRMD_SUPPORTS_SCHEMA_XFER(x) (compare_version((x), "1.2") >= 0)
#define LRMD_SUPPORTS_SCHEMA_XFER(x) (pcmk__compare_versions((x), "1.2") >= 0)

/* The major protocol version the client and server both need to support for
* the connection to be successful. This should only ever be the major
Expand Down
3 changes: 2 additions & 1 deletion lib/cluster/election.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ election_count_vote(pcmk_cluster_t *cluster, const xmlNode *message,
} else {
// A peer vote requires a comparison to determine which node is better
int age_result = compare_age(vote.age);
int version_result = compare_version(vote.version, CRM_FEATURE_SET);
int version_result = pcmk__compare_versions(vote.version,
CRM_FEATURE_SET);

if (version_result < 0) {
reason = "Version";
Expand Down
3 changes: 2 additions & 1 deletion lib/common/cib.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ pcmk_find_cib_element(xmlNode *cib, const char *element_name)
int
pcmk__check_feature_set(const char *cib_version)
{
if (cib_version && compare_version(cib_version, CRM_FEATURE_SET) > 0) {
if ((cib_version != NULL)
&& (pcmk__compare_versions(cib_version, CRM_FEATURE_SET) > 0)) {
return EPROTONOSUPPORT;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/common/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ char *
calculate_xml_versioned_digest(xmlNode *input, gboolean sort,
gboolean do_filter, const char *version)
{
if ((version == NULL) || (compare_version("3.0.5", version) > 0)) {
if ((version == NULL) || (pcmk__compare_versions("3.0.5", version) > 0)) {
xmlNode *sorted = NULL;
char *digest = NULL;

Expand Down
2 changes: 1 addition & 1 deletion lib/common/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ pcmk__cmp_by_type(const char *value1, const char *value2, enum pcmk__type type)
break;

case pcmk__type_version:
return compare_version(value1, value2);
return pcmk__compare_versions(value1, value2);

default: // Invalid type
return 0;
Expand Down
41 changes: 8 additions & 33 deletions lib/common/schemas.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ transform_filter(const struct dirent *entry)
* \internal
* \brief Compare transform files based on the version strings in their names
*
* This is a crude version comparison that relies on the specific structure of
* these filenames.
*
* \retval -1 if \p entry1 sorts before \p entry2
* \retval 0 if \p entry1 sorts equal to \p entry2
* \retval 1 if \p entry1 sorts after \p entry2
Expand All @@ -339,38 +336,16 @@ transform_filter(const struct dirent *entry)
static int
compare_transforms(const struct dirent **entry1, const struct dirent **entry2)
{
unsigned char major1 = 0;
unsigned char major2 = 0;
unsigned char minor1 = 0;
unsigned char minor2 = 0;
unsigned char order1 = 0;
unsigned char order2 = 0;

// If these made it through the filter, they should be of the right format
CRM_LOG_ASSERT(sscanf((*entry1)->d_name, "upgrade-%hhu.%hhu-%hhu.xsl",
&major1, &minor1, &order1) == 3);
CRM_LOG_ASSERT(sscanf((*entry2)->d_name, "upgrade-%hhu.%hhu-%hhu.xsl",
&major2, &minor2, &order2) == 3);

if (major1 < major2) {
return -1;
} else if (major1 > major2) {
return 1;
}
// We already validated the format of each filename in transform_filter()
static const size_t offset = sizeof("upgrade-") - 1;

if (minor1 < minor2) {
return -1;
} else if (minor1 > minor2) {
return 1;
}
gchar *ver1 = g_strdelimit(g_strdup((*entry1)->d_name + offset), "-", '.');
gchar *ver2 = g_strdelimit(g_strdup((*entry2)->d_name + offset), "-", '.');
int rc = pcmk__compare_versions(ver1, ver2);

if (order1 < order2) {
return -1;
} else if (order1 > order2) {
return 1;
}

return 0;
g_free(ver1);
g_free(ver2);
return rc;
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion lib/common/tests/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include $(top_srcdir)/mk/tap.mk
include $(top_srcdir)/mk/unittest.mk

# Add "_test" to the end of all test program names to simplify .gitignore.
check_PROGRAMS = compare_version_test \
check_PROGRAMS = pcmk__compare_versions_test \
pcmk__daemon_user_test \
pcmk__fail_attr_name_test \
pcmk__failcount_name_test \
Expand Down
58 changes: 0 additions & 58 deletions lib/common/tests/utils/compare_version_test.c

This file was deleted.

Loading