pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
cib.c
Go to the documentation of this file.
1/*
2 * Original copyright 2004 International Business Machines
3 * Later changes copyright 2008-2025 the Pacemaker project contributors
4 *
5 * The version control history for this file may have further details.
6 *
7 * This source code is licensed under the GNU Lesser General Public License
8 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
9 */
10
11#include <crm_internal.h>
12
13#include <stdio.h>
14#include <libxml/tree.h> // xmlNode
15
16#include <crm/common/xml.h>
17#include <crm/common/cib.h>
19
20/*
21 * Functions to help find particular sections of the CIB
22 */
23
24// Map CIB element names to their parent elements and XPath searches
25static struct {
26 const char *name; // Name of this CIB element
27 const char *parent; // CIB element that this element is a child of
28 const char *path; // XPath to find this CIB element
29} cib_sections[] = {
30 {
31 // This first entry is also the default if a NULL is compared
33 NULL,
34 "//" PCMK_XE_CIB
35 },
36 {
38 "/" PCMK_XE_CIB,
40 },
41 {
43 "/" PCMK_XE_CIB,
45 },
46 {
50 },
51 {
55 },
56 {
60 },
61 {
65 },
66 {
70 },
71 {
75 },
76 {
80 },
81 {
85 },
86 {
90 },
91 {
95 },
96 {
98 NULL,
99 "//" PCMK_XE_CIB
100 },
101};
102
111const char *
112pcmk_cib_xpath_for(const char *element_name)
113{
114 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
115 // A NULL element_name will match the first entry
116 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
118 return cib_sections[lpc].path;
119 }
120 }
121 return NULL;
122}
123
132const char *
133pcmk__cib_abs_xpath_for(const char *element)
134{
135 const char *xpath = pcmk_cib_xpath_for(element);
136
137 // XPaths returned by pcmk_cib_xpath_for() are relative (starting with "//")
138 return ((xpath != NULL)? (xpath + 1) : NULL);
139}
140
149const char *
150pcmk_cib_parent_name_for(const char *element_name)
151{
152 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
153 // A NULL element_name will match the first entry
154 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
156 return cib_sections[lpc].parent;
157 }
158 }
159 return NULL;
160}
161
171xmlNode *
172pcmk_find_cib_element(xmlNode *cib, const char *element_name)
173{
174 return pcmk__xpath_find_one(cib->doc, pcmk_cib_xpath_for(element_name),
175 LOG_TRACE);
176}
177
184int
185pcmk__check_feature_set(const char *cib_version)
186{
187 if (cib_version && compare_version(cib_version, CRM_FEATURE_SET) > 0) {
188 return EPROTONOSUPPORT;
189 }
190
191 return pcmk_rc_ok;
192}
const char * pcmk_cib_parent_name_for(const char *element_name)
Get the parent element name of a given CIB element name.
Definition cib.c:150
const char * pcmk__cib_abs_xpath_for(const char *element)
Definition cib.c:133
const char * parent
Definition cib.c:27
const char * path
Definition cib.c:28
int pcmk__check_feature_set(const char *cib_version)
Definition cib.c:185
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
Definition cib.c:172
const char * name
Definition cib.c:26
const char * pcmk_cib_xpath_for(const char *element_name)
Get the relative XPath needed to find a specified CIB element name.
Definition cib.c:112
#define PCMK__NELEM(a)
Definition internal.h:50
int compare_version(const char *version1, const char *version2)
Definition utils.c:206
#define CRM_FEATURE_SET
Definition crm.h:66
#define LOG_TRACE
Definition logging.h:38
@ pcmk_rc_ok
Definition results.h:159
@ pcmk__str_null_matches
Wrappers for and extensions to libxml2.
#define PCMK_XE_CONSTRAINTS
Definition xml_names.h:89
#define PCMK_XE_CIB
Definition xml_names.h:79
#define PCMK_XE_STATUS
Definition xml_names.h:204
#define PCMK_XE_OP_DEFAULTS
Definition xml_names.h:147
#define PCMK_XE_CRM_CONFIG
Definition xml_names.h:91
#define PCMK_XE_RESOURCES
Definition xml_names.h:179
#define PCMK_XE_ALERTS
Definition xml_names.h:66
#define PCMK_XE_TAGS
Definition xml_names.h:209
#define PCMK_XE_ACLS
Definition xml_names.h:59
#define PCMK_XE_FENCING_TOPOLOGY
Definition xml_names.h:118
#define PCMK_XE_CONFIGURATION
Definition xml_names.h:87
#define PCMK_XE_NODES
Definition xml_names.h:142
#define PCMK_XE_RSC_DEFAULTS
Definition xml_names.h:186
#define PCMK__XE_ALL
xmlNode * pcmk__xpath_find_one(xmlDoc *doc, const char *path, uint8_t level)
Definition xpath.c:206