Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/include/crm/common/cib.h b/include/crm/common/cib.h
index 360e73ea92..a8658cc8d5 100644
--- a/include/crm/common/cib.h
+++ b/include/crm/common/cib.h
@@ -1,23 +1,24 @@
/*
* Copyright 2021 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__COMMON_CIB__H
# define PCMK__COMMON_CIB__H
#ifdef __cplusplus
extern "C" {
#endif
const char *pcmk_cib_xpath_for(const char *element_name);
+const char *pcmk_cib_parent_name_for(const char *element_name);
#ifdef __cplusplus
}
#endif
#endif // PCMK__COMMON_CIB__H
diff --git a/lib/common/cib.c b/lib/common/cib.c
index 1e33922143..042fcd5253 100644
--- a/lib/common/cib.c
+++ b/lib/common/cib.c
@@ -1,123 +1,143 @@
/*
* Original copyright 2004 International Business Machines
* Later changes copyright 2008-2021 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.
*/
#include <crm_internal.h>
#include <stdio.h>
#include <crm/msg_xml.h>
/*
* Functions to help find particular sections of the CIB
*/
// Map CIB element names to their parent elements and XPath searches
static struct {
const char *name; // Name of this CIB element
const char *parent; // CIB element that this element is a child of
const char *path; // XPath to find this CIB element
} cib_sections[] = {
{
NULL,
NULL,
"//" XML_TAG_CIB
},
{
XML_TAG_CIB,
NULL,
"//" XML_TAG_CIB
},
{
XML_CIB_TAG_STATUS,
"/" XML_TAG_CIB,
"//" XML_TAG_CIB "/" XML_CIB_TAG_STATUS
},
{
XML_CIB_TAG_CONFIGURATION,
"/" XML_TAG_CIB,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION
},
{
XML_CIB_TAG_CRMCONFIG,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_CRMCONFIG
},
{
XML_CIB_TAG_NODES,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES
},
{
XML_CIB_TAG_RESOURCES,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES
},
{
XML_CIB_TAG_CONSTRAINTS,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_CONSTRAINTS
},
{
XML_CIB_TAG_OPCONFIG,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_OPCONFIG
},
{
XML_CIB_TAG_RSCCONFIG,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RSCCONFIG
},
{
XML_CIB_TAG_ACLS,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_ACLS
},
{
XML_TAG_FENCING_TOPOLOGY,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_TAG_FENCING_TOPOLOGY
},
{
XML_CIB_TAG_TAGS,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_TAGS
},
{
XML_CIB_TAG_ALERTS,
"/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
"//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_ALERTS
},
{
XML_CIB_TAG_SECTION_ALL,
NULL,
"//" XML_TAG_CIB
},
};
/*!
* \brief Get the XPath needed to find a specified CIB element name
*
* \param[in] element_name Name of CIB element
*
* \return XPath for finding \p element_name in CIB XML (or NULL if unknown)
* \note The return value is constant and should not be freed.
*/
const char *
pcmk_cib_xpath_for(const char *element_name)
{
for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
if (((element_name == NULL) && (cib_sections[lpc].name == NULL))
|| pcmk__str_eq(element_name, cib_sections[lpc].name,
pcmk__str_none)) {
return cib_sections[lpc].path;
}
}
return NULL;
}
+
+/*!
+ * \brief Get the parent element name of a given CIB element name
+ *
+ * \param[in] element_name Name of CIB element
+ *
+ * \return Parent element of \p element_name (or NULL if unknown)
+ * \note The return value is constant and should not be freed.
+ */
+const char *
+pcmk_cib_parent_name_for(const char *element_name)
+{
+ for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
+ if (pcmk__str_eq(element_name, cib_sections[lpc].name,
+ pcmk__str_none)) {
+ return cib_sections[lpc].parent;
+ }
+ }
+ return NULL;
+}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 4:48 PM (14 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1018970
Default Alt Text
(5 KB)

Event Timeline