pacemaker  2.1.5-b7adf64e51
Scalable High-Availability cluster resource manager
cib.c
Go to the documentation of this file.
1 /*
2  * Original copyright 2004 International Business Machines
3  * Later changes copyright 2008-2021 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 
18 /*
19  * Functions to help find particular sections of the CIB
20  */
21 
22 // Map CIB element names to their parent elements and XPath searches
23 static struct {
24  const char *name; // Name of this CIB element
25  const char *parent; // CIB element that this element is a child of
26  const char *path; // XPath to find this CIB element
27 } cib_sections[] = {
28  {
29  // This first entry is also the default if a NULL is compared
31  NULL,
32  "//" XML_TAG_CIB
33  },
34  {
36  "/" XML_TAG_CIB,
38  },
39  {
41  "/" XML_TAG_CIB,
43  },
44  {
48  },
49  {
53  },
54  {
58  },
59  {
63  },
64  {
68  },
69  {
73  },
74  {
78  },
79  {
83  },
84  {
88  },
89  {
93  },
94  {
96  NULL,
97  "//" XML_TAG_CIB
98  },
99 };
100 
109 const char *
110 pcmk_cib_xpath_for(const char *element_name)
111 {
112  for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
113  // A NULL element_name will match the first entry
114  if (pcmk__str_eq(element_name, cib_sections[lpc].name,
116  return cib_sections[lpc].path;
117  }
118  }
119  return NULL;
120 }
121 
130 const char *
131 pcmk_cib_parent_name_for(const char *element_name)
132 {
133  for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
134  // A NULL element_name will match the first entry
135  if (pcmk__str_eq(element_name, cib_sections[lpc].name,
137  return cib_sections[lpc].parent;
138  }
139  }
140  return NULL;
141 }
142 
152 xmlNode *
153 pcmk_find_cib_element(xmlNode *cib, const char *element_name)
154 {
155  return get_xpath_object(pcmk_cib_xpath_for(element_name), cib, LOG_TRACE);
156 }
#define LOG_TRACE
Definition: logging.h:37
const char * pcmk_cib_xpath_for(const char *element_name)
Get the XPath needed to find a specified CIB element name.
Definition: cib.c:110
#define XML_CIB_TAG_SECTION_ALL
Definition: msg_xml.h:183
const char * name
Definition: cib.c:24
#define XML_CIB_TAG_CONSTRAINTS
Definition: msg_xml.h:189
#define XML_TAG_FENCING_TOPOLOGY
Definition: msg_xml.h:447
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:131
#define XML_CIB_TAG_NODES
Definition: msg_xml.h:187
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:214
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
Definition: cib.c:153
#define XML_CIB_TAG_RESOURCES
Definition: msg_xml.h:186
#define PCMK__NELEM(a)
Definition: internal.h:41
#define XML_CIB_TAG_ACLS
Definition: msg_xml.h:193
#define XML_TAG_CIB
Definition: msg_xml.h:115
const char * path
Definition: cib.c:26
#define XML_CIB_TAG_CRMCONFIG
Definition: msg_xml.h:190
#define XML_CIB_TAG_RSCCONFIG
Definition: msg_xml.h:192
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:185
#define XML_CIB_TAG_TAGS
Definition: msg_xml.h:443
#define XML_CIB_TAG_ALERTS
Definition: msg_xml.h:194
#define XML_CIB_TAG_CONFIGURATION
Definition: msg_xml.h:184
const char * parent
Definition: cib.c:25
#define XML_CIB_TAG_OPCONFIG
Definition: msg_xml.h:191