pacemaker 2.1.7-2.1.7
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-2023 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/msg_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 "//" XML_TAG_CIB
35 },
36 {
38 "/" XML_TAG_CIB,
40 },
41 {
43 "/" XML_TAG_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 "//" XML_TAG_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 get_xpath_object(pcmk_cib_xpath_for(element_name), cib, LOG_TRACE);
175}
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
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:46
#define LOG_TRACE
Definition logging.h:38
#define XML_TAG_CIB
Definition msg_xml.h:137
#define XML_CIB_TAG_RESOURCES
Definition msg_xml.h:205
#define XML_CIB_TAG_TAGS
Definition msg_xml.h:449
#define XML_CIB_TAG_ACLS
Definition msg_xml.h:211
#define XML_CIB_TAG_RSCCONFIG
Definition msg_xml.h:210
#define XML_CIB_TAG_ALERTS
Definition msg_xml.h:212
#define XML_CIB_TAG_CRMCONFIG
Definition msg_xml.h:208
#define XML_CIB_TAG_SECTION_ALL
Definition msg_xml.h:202
#define XML_CIB_TAG_CONSTRAINTS
Definition msg_xml.h:207
#define XML_CIB_TAG_CONFIGURATION
Definition msg_xml.h:203
#define XML_TAG_FENCING_TOPOLOGY
Definition msg_xml.h:453
#define XML_CIB_TAG_NODES
Definition msg_xml.h:206
#define XML_CIB_TAG_STATUS
Definition msg_xml.h:204
#define XML_CIB_TAG_OPCONFIG
Definition msg_xml.h:209
@ pcmk__str_null_matches
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition xpath.c:211