Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cc4c360
Refactor: libcrmcommon: New pcmk__evaluate_rule()
nrwahl2 May 10, 2026
f772937
API: libcrmcommon: Deprecate pcmk_evaluate_rule()
nrwahl2 May 10, 2026
f15d8e0
Refactor: libcrmcommon: New pcmk__rule_input_t
nrwahl2 May 10, 2026
428beba
Refactor: libcrmcommon: pcmk__evaluate_rule() takes pcmk__rule_input_t
nrwahl2 May 10, 2026
c0837f5
Refactor: libcrmcommon: pcmk__nvpair_unpack_t pcmk__rule_input_t field
nrwahl2 May 10, 2026
a902d6c
Refactor: libcrmcommon: pcmk__unpack_nvpair_blocks() pcmk__rule_input_t
nrwahl2 May 10, 2026
a5a88da
Refactor: libpe_status: pe__unpack_dataset_nvpairs() pcmk__rule_input_t
nrwahl2 May 10, 2026
40c0aad
API: libcrmcommon: Deprecate pcmk_rule_input_t
nrwahl2 May 12, 2026
c04875e
API: libcrmcommon: Drop pcmk__condition_ members of enum expression_type
nrwahl2 May 12, 2026
0e51ccf
Refactor: libcrmcommon: Move enum expression_type to rules_compat.h
nrwahl2 May 12, 2026
dfd1f49
Refactor: libpacemaker: Drop pcmk__check_rule()
nrwahl2 May 13, 2026
141e168
Doc: libpacemaker: Correct rsc_location rsc-pattern subexpression syntax
nrwahl2 May 13, 2026
dd94e69
Refactor: libpacemaker: Drop redundant checks in pcmk__unpack_location()
nrwahl2 May 13, 2026
239b0e5
Refactor: libpacemaker: Some cleanup of unpack_location_tags()
nrwahl2 May 13, 2026
58c6b48
Refactor: libpacemaker: Unindent some of pcmk__expand_tags_in_sets()
nrwahl2 May 13, 2026
2e063af
Refactor: libpacemaker: Drop tag_refs from pcmk__expand_tags_in_sets()
nrwahl2 May 13, 2026
5b36bfb
Fix: libpacemaker: Ignore rsc-pattern attribute if rsc attribute is set
nrwahl2 May 13, 2026
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
2 changes: 1 addition & 1 deletion daemons/controld/controld_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void
crm_time_t *now = crm_time_new(NULL);
xmlNode *crmconfig = NULL;
xmlNode *alerts = NULL;
pcmk_rule_input_t rule_input = {
pcmk__rule_input_t rule_input = {
.now = now,
};

Expand Down
3 changes: 1 addition & 2 deletions daemons/controld/controld_remote_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <crm/common/nvpair.h> // pcmk_unpack_nvpair_blocks
#include <crm/common/options.h> // PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS
#include <crm/common/results.h> // pcmk_ok, pcmk_rc_*, pcmk_strerror
#include <crm/common/rules.h> // pcmk_rule_input_t
#include <crm/common/xml.h> // PCMK_XA_*, PCMK_XE_*, etc.
#include <crm/crm.h> // crm_system_name
#include <crm/lrmd.h> // lrmd_t
Expand Down Expand Up @@ -244,7 +243,7 @@ remote_config_check(xmlNode *msg, int call_id, int rc, xmlNode *output,
lrmd_t *lrmd = user_data;
GHashTable *config_hash = NULL;
crm_time_t *now = NULL;
pcmk_rule_input_t rule_input = { NULL, };
pcmk__rule_input_t rule_input = { NULL, };

if (rc != pcmk_ok) {
pcmk__err("Query resulted in an error: %s", pcmk_strerror(rc));
Expand Down
1 change: 1 addition & 0 deletions include/crm/common/Makefile.am

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see any way to comment on a commit message. There's a typo in the second paragraph - woudl should be would.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ header_HEADERS += results.h
header_HEADERS += results_compat.h
header_HEADERS += roles.h
header_HEADERS += rules.h
header_HEADERS += rules_compat.h
header_HEADERS += scheduler.h
header_HEADERS += scheduler_types.h
header_HEADERS += schemas.h
Expand Down
8 changes: 4 additions & 4 deletions include/crm/common/nvpair_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#ifndef PCMK__CRM_COMMON_NVPAIR_COMPAT__H
#define PCMK__CRM_COMMON_NVPAIR_COMPAT__H

#include <glib.h> // GHashTable, GSList
#include <libxml/tree.h> // xmlNode
#include <glib.h> // GHashTable, GSList
#include <libxml/tree.h> // xmlNode

#include <crm/common/iso8601.h> // crm_time_t
#include <crm/common/rules.h> // pcmk_rule_input_t
#include <crm/common/iso8601.h> // crm_time_t
#include <crm/common/rules_compat.h> // pcmk_rule_input_t

#ifdef __cplusplus
extern "C" {
Expand Down
6 changes: 3 additions & 3 deletions include/crm/common/nvpair_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <glib.h> // gboolean, GHashTable
#include <libxml/tree.h> // xmlNode

#include <crm/common/rules.h> // pcmk_rule_input_t
#include <crm/common/iso8601.h> // crm_time_t
#include <crm/common/rules_internal.h> // pcmk__rule_input_t
#include <crm/common/strings_internal.h> // pcmk__str_eq(), etc.

#ifdef __cplusplus
Expand All @@ -31,7 +31,7 @@ typedef struct {
GHashTable *values; // Where to put name/value pairs
const char *first_id; // Block with this XML ID should sort first
xmlDoc *doc; // XML document to use for resolving IDREFs
pcmk_rule_input_t rule_input; // Data used to evaluate rules
pcmk__rule_input_t rule_input; // Data used to evaluate rules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what the commit message means, but on its own (like in the context of git log) it's not clear at all. And it looks like the next several commit messages are the same kind of thing.


/* Whether each block's values should overwrite any existing ones
*
Expand All @@ -50,7 +50,7 @@ void pcmk__unpack_nvpair_block(void *data, void *user_data);

void pcmk__unpack_nvpair_blocks(const xmlNode *xml, const char *element_name,
const char *first_id,
const pcmk_rule_input_t *rule_input,
const pcmk__rule_input_t *rule_input,
GHashTable *values, crm_time_t *next_change,
xmlDoc *doc);

Expand Down
99 changes: 4 additions & 95 deletions include/crm/common/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
#ifndef PCMK__CRM_COMMON_RULES__H
#define PCMK__CRM_COMMON_RULES__H

#include <regex.h> // regmatch_t

#include <glib.h> // GHashTable
#include <libxml/tree.h> // xmlNode

#include <crm/common/iso8601.h> // crm_time_t

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -27,96 +20,12 @@ extern "C" {
* \ingroup core
*/

/* Allowed subexpressions of a rule
* @COMPAT This should be made internal at an API compatibility break
*/
//!@{
//! \deprecated For Pacemaker use only
enum expression_type {
pcmk__condition_unknown = 0, // Unknown or invalid condition
pcmk__condition_rule = 1, // Nested rule
pcmk__condition_attribute = 2, // Node attribute expression
pcmk__condition_location = 3, // Node location expression
pcmk__condition_datetime = 5, // Date/time expression
pcmk__condition_resource = 7, // Resource agent expression
pcmk__condition_operation = 8, // Operation expression

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
not_expr = pcmk__condition_unknown,
nested_rule = pcmk__condition_rule,
attr_expr = pcmk__condition_attribute,
loc_expr = pcmk__condition_location,
role_expr = 4,
time_expr = pcmk__condition_datetime,
version_expr = 6,
rsc_expr = pcmk__condition_resource,
op_expr = pcmk__condition_operation,
#endif
};
//!@}

/*!
* \brief Data used to evaluate a rule (any \c NULL items are ignored)
*
* \deprecated Use \c pcmk_rule_input_t instead of
* <tt>struct pcmk_rule_input</tt>.
*/
typedef struct pcmk_rule_input {
// Used to evaluate date expressions
/*!
* Current time for rule evaluation purposes
*/
const crm_time_t *now;

// Used to evaluate resource type expressions
const char *rsc_standard; //!< Resource standard that rule applies to
const char *rsc_provider; //!< Resource provider that rule applies to
const char *rsc_agent; //!< Resource agent that rule applies to

// Used to evaluate operation type expressions
const char *op_name; //!< Operation name that rule applies to
unsigned int op_interval_ms; //!< Operation interval that rule applies to

// Remaining members are used to evaluate node attribute expressions

/*!
* Node attributes for rule evaluation purposes
*
* \note Though not const, this is used only with g_hash_table_lookup().
*/
GHashTable *node_attrs;

// Remaining members are used only within location constraint rules

/*!
* Resource parameters that can be used as the reference value source
*
* \note Though not const, this is used only with g_hash_table_lookup().
*/
GHashTable *rsc_params;

/*!
* Resource meta-attributes that can be used as the reference value source
*
* \note Though not const, this is used only with g_hash_table_lookup().
*/
GHashTable *rsc_meta;

//! Resource ID to compare against a location constraint's resource pattern
const char *rsc_id;

//! Resource pattern submatches (as set by regexec()) for rsc_id
const regmatch_t *rsc_id_submatches;

//! Number of entries in rsc_id_submatches
int rsc_id_nmatches;
} pcmk_rule_input_t;

int pcmk_evaluate_rule(xmlNode *rule, const pcmk_rule_input_t *rule_input,
crm_time_t *next_change);

#ifdef __cplusplus
}
#endif

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/rules_compat.h>
#endif

#endif // PCMK__CRM_COMMON_RULES__H
74 changes: 74 additions & 0 deletions include/crm/common/rules_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2004-2026 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

#ifndef PCMK__CRM_COMMON_RULES_COMPAT__H
#define PCMK__CRM_COMMON_RULES_COMPAT__H

#include <regex.h> // regmatch_t

#include <glib.h> // GHashTable
#include <libxml/tree.h> // xmlNode

#include <crm/common/iso8601.h> // crm_time_t

#ifdef __cplusplus
extern "C" {
#endif

/**
* \file
* \brief Deprecated Pacemaker rules API
* \ingroup core
* \deprecated Do not include this header directly. The nvpair APIs in this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvpair should be rule or something similar.

* header, and the header itself, will be removed in a future
* release.
*/

//!@{
//! \deprecated Do not use
enum expression_type {
not_expr = 0,
nested_rule = 1,
attr_expr = 2,
loc_expr = 3,
role_expr = 4,
time_expr = 5,
version_expr = 6,
rsc_expr = 7,
op_expr = 8,
};
//!@}

//!@{
//! \deprecated Do not use
typedef struct pcmk_rule_input {
const crm_time_t *now;
const char *rsc_standard;
const char *rsc_provider;
const char *rsc_agent;
const char *op_name;
unsigned int op_interval_ms;
GHashTable *node_attrs;
GHashTable *rsc_params;
GHashTable *rsc_meta;
const char *rsc_id;
const regmatch_t *rsc_id_submatches;
int rsc_id_nmatches;
} pcmk_rule_input_t;
//!@}

//! \deprecated Do not use
int pcmk_evaluate_rule(xmlNode *rule, const pcmk_rule_input_t *rule_input,
crm_time_t *next_change);

#ifdef __cplusplus
}
#endif

#endif // PCMK__CRM_COMMON_RULES_COMPAT__H
83 changes: 80 additions & 3 deletions include/crm/common/rules_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#define PCMK__CRM_COMMON_RULES_INTERNAL__H

#include <regex.h> // regmatch_t

#include <glib.h> // GHashTable
#include <libxml/tree.h> // xmlNode

#include <crm/common/rules.h> // enum expression_type, etc.
#include <crm/common/iso8601.h> // crm_time_t

#ifdef __cplusplus
Expand All @@ -30,17 +31,93 @@ enum pcmk__combine {
pcmk__combine_or,
};

enum expression_type pcmk__condition_type(const xmlNode *condition);
/*!
* \internal
* \brief Types of conditions within a rule
*/
enum pcmk__condition {
pcmk__condition_unknown, //!< Unknown or invalid condition
pcmk__condition_rule, //!< Nested rule
pcmk__condition_attribute, //!< Node attribute expression
pcmk__condition_location, //!< Node location expression
pcmk__condition_datetime, //!< Date/time expression
pcmk__condition_resource, //!< Resource agent expression
pcmk__condition_operation, //!< Operation expression
};

/*!
* \internal
* \brief Data used to evaluate a rule (any \c NULL items are ignored)
*/
typedef struct {
// Used to evaluate date expressions
const crm_time_t *now; //!< Current time to use for rule evaluation

// Used to evaluate resource type expressions
const char *rsc_standard; //!< Resource standard that rule applies to
const char *rsc_provider; //!< Resource provider that rule applies to
const char *rsc_agent; //!< Resource agent that rule applies to

// Used to evaluate operation type expressions
const char *op_name; //!< Operation name that rule applies to
unsigned int op_interval_ms; //!< Operation interval that rule applies to

// Remaining members are used to evaluate node attribute expressions

/*!
* Node attributes for rule evaluation purposes
*
* \note Though not const, this is used only with \c g_hash_table_lookup().
*/
GHashTable *node_attrs;

// Remaining members are used only within location constraint rules

/*!
* Resource parameters that can be used as the reference value source
*
* \note Though not const, this is used only with \c g_hash_table_lookup().
*/
GHashTable *rsc_params;

/*!
* Resource meta-attributes that can be used as the reference value source
*
* \note Though not const, this is used only with \c g_hash_table_lookup().
*/
GHashTable *rsc_meta;

//! Resource ID to compare against a location constraint's resource pattern
const char *rsc_id;

//! Resource pattern submatches (as set by \c regexec()) for \c rsc_id
const regmatch_t *rsc_id_submatches;

//! Number of entries in rsc_id_submatches
int rsc_id_nmatches;
} pcmk__rule_input_t;

enum pcmk__condition pcmk__condition_type(const xmlNode *condition);
char *pcmk__replace_submatches(const char *string, const char *match,
const regmatch_t submatches[], int nmatches);
enum pcmk__combine pcmk__parse_combine(const char *combine);

int pcmk__evaluate_date_expression(const xmlNode *date_expression,
const crm_time_t *now,
crm_time_t *next_change);
int pcmk__evaluate_condition(xmlNode *expr, const pcmk_rule_input_t *rule_input,
int pcmk__evaluate_condition(xmlNode *expr,
const pcmk__rule_input_t *rule_input,
crm_time_t *next_change);

int pcmk__evaluate_rule(xmlNode *rule, const pcmk__rule_input_t *rule_input,
crm_time_t *next_change);

// Redeclare because the definition is in rules_compat.h
typedef struct pcmk_rule_input pcmk_rule_input_t;

void pcmk__rule_input_convert(const pcmk_rule_input_t *source,
pcmk__rule_input_t *target);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/crm/pengine/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ bool pe__shutdown_requested(const pcmk_node_t *node);
void pe__register_messages(pcmk__output_t *out);

void pe__unpack_dataset_nvpairs(const xmlNode *xml_obj, const char *set_name,
const pcmk_rule_input_t *rule_input,
const pcmk__rule_input_t *rule_input,
GHashTable *hash, const char *always_first,
pcmk_scheduler_t *scheduler);

Expand Down
2 changes: 1 addition & 1 deletion include/crm/pengine/rules_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
*/

// @COMPAT sbd's configure script checks for this (as of at least 1.5.2)
//! \deprecated Use pcmk_evaluate_rule() instead
//! \deprecated Do not use
gboolean test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role,
crm_time_t *now);

Expand Down
Loading