pacemaker 2.1.4-dc6eb4362e
Scalable High-Availability cluster resource manager
crmcommon_private.h
Go to the documentation of this file.
1/*
2 * Copyright 2018-2021 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#ifndef CRMCOMMON_PRIVATE__H
11# define CRMCOMMON_PRIVATE__H
12
13/* This header is for the sole use of libcrmcommon, so that functions can be
14 * declared with G_GNUC_INTERNAL for efficiency.
15 */
16
17#include <stdint.h> // uint8_t, uint32_t
18#include <stdbool.h> // bool
19#include <sys/types.h> // size_t
20#include <glib.h> // GList
21#include <libxml/tree.h> // xmlNode, xmlAttr
22#include <qb/qbipcc.h> // struct qb_ipc_response_header
23
24// Decent chunk size for processing large amounts of data
25#define PCMK__BUFFER_SIZE 4096
26
27/* When deleting portions of an XML tree, we keep a record so we can know later
28 * (e.g. when checking differences) that something was deleted.
29 */
30typedef struct pcmk__deleted_xml_s {
31 char *path;
34
35typedef struct xml_private_s {
36 long check;
37 uint32_t flags;
38 char *user;
39 GList *acls;
40 GList *deleted_objs; // List of pcmk__deleted_xml_t
42
43#define pcmk__set_xml_flags(xml_priv, flags_to_set) do { \
44 (xml_priv)->flags = pcmk__set_flags_as(__func__, __LINE__, \
45 LOG_NEVER, "XML", "XML node", (xml_priv)->flags, \
46 (flags_to_set), #flags_to_set); \
47 } while (0)
48
49#define pcmk__clear_xml_flags(xml_priv, flags_to_clear) do { \
50 (xml_priv)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
51 LOG_NEVER, "XML", "XML node", (xml_priv)->flags, \
52 (flags_to_clear), #flags_to_clear); \
53 } while (0)
54
55G_GNUC_INTERNAL
56void pcmk__xml2text(xmlNode *data, int options, char **buffer, int *offset,
57 int *max, int depth);
58
59G_GNUC_INTERNAL
60void pcmk__buffer_add_char(char **buffer, int *offset, int *max, char c);
61
62G_GNUC_INTERNAL
63bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy);
64
65G_GNUC_INTERNAL
66int pcmk__element_xpath(const char *prefix, xmlNode *xml, char *buffer,
67 int offset, size_t buffer_size);
68
69G_GNUC_INTERNAL
70void pcmk__mark_xml_created(xmlNode *xml);
71
72G_GNUC_INTERNAL
73int pcmk__xml_position(xmlNode *xml, enum xml_private_flags ignore_if_set);
74
75G_GNUC_INTERNAL
76xmlNode *pcmk__xml_match(xmlNode *haystack, xmlNode *needle, bool exact);
77
78G_GNUC_INTERNAL
79void pcmk__xe_log(int log_level, const char *file, const char *function,
80 int line, const char *prefix, xmlNode *data, int depth,
81 int options);
82
83G_GNUC_INTERNAL
84void pcmk__xml_update(xmlNode *parent, xmlNode *target, xmlNode *update,
85 bool as_diff);
86
87G_GNUC_INTERNAL
88xmlNode *pcmk__xc_match(xmlNode *root, xmlNode *search_comment, bool exact);
89
90G_GNUC_INTERNAL
91void pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update);
92
93G_GNUC_INTERNAL
94void pcmk__free_acls(GList *acls);
95
96G_GNUC_INTERNAL
97void pcmk__unpack_acl(xmlNode *source, xmlNode *target, const char *user);
98
99G_GNUC_INTERNAL
100void pcmk__apply_acl(xmlNode *xml);
101
102G_GNUC_INTERNAL
103void pcmk__apply_creation_acl(xmlNode *xml, bool check_top);
104
105G_GNUC_INTERNAL
106void pcmk__mark_xml_attr_dirty(xmlAttr *a);
107
108G_GNUC_INTERNAL
109bool pcmk__xa_filterable(const char *name);
110
111static inline const char *
112pcmk__xml_attr_value(const xmlAttr *attr)
113{
114 return ((attr == NULL) || (attr->children == NULL))? NULL
115 : (const char *) attr->children->content;
116}
117
118/*
119 * IPC
120 */
121
122#define PCMK__IPC_VERSION 1
123
124#define PCMK__CONTROLD_API_MAJOR "1"
125#define PCMK__CONTROLD_API_MINOR "0"
126
127// IPC behavior that varies by daemon
128typedef struct pcmk__ipc_methods_s {
138
145 void (*free_data)(void *api_data);
146
162
172 bool (*reply_expected)(pcmk_ipc_api_t *api, xmlNode *request);
173
183 bool (*dispatch)(pcmk_ipc_api_t *api, xmlNode *msg);
184
193
194// Implementation of pcmk_ipc_api_t
196 enum pcmk_ipc_server server; // Daemon this IPC API instance is for
197 enum pcmk_ipc_dispatch dispatch_type; // How replies should be dispatched
198 size_t ipc_size_max; // maximum IPC buffer size
199 crm_ipc_t *ipc; // IPC connection
200 mainloop_io_t *mainloop_io; // If using mainloop, I/O source for IPC
201 bool free_on_disconnect; // Whether disconnect should free object
202 pcmk_ipc_callback_t cb; // Caller-registered callback (if any)
203 void *user_data; // Caller-registered data (if any)
204 void *api_data; // For daemon-specific use
205 pcmk__ipc_methods_t *cmds; // Behavior that varies by daemon
206};
207
208typedef struct pcmk__ipc_header_s {
209 struct qb_ipc_response_header qb;
212 uint32_t flags;
213 uint8_t version;
215
216G_GNUC_INTERNAL
217int pcmk__send_ipc_request(pcmk_ipc_api_t *api, xmlNode *request);
218
219G_GNUC_INTERNAL
221 enum pcmk_ipc_event event_type,
222 crm_exit_t status, void *event_data);
223
224G_GNUC_INTERNAL
225unsigned int pcmk__ipc_buffer_size(unsigned int max);
226
227G_GNUC_INTERNAL
229
230G_GNUC_INTERNAL
232
233G_GNUC_INTERNAL
235
236G_GNUC_INTERNAL
238
239
240/*
241 * Logging
242 */
243
279int pcmk__crm_ipc_is_authentic_process(qb_ipcc_connection_t *qb_ipc, int sock, uid_t refuid, gid_t refgid,
280 pid_t *gotpid, uid_t *gotuid, gid_t *gotgid);
281
282
283#endif // CRMCOMMON_PRIVATE__H
const char * parent
Definition: cib.c:25
const char * name
Definition: cib.c:24
char data[0]
Definition: cpg.c:10
G_GNUC_INTERNAL void pcmk__apply_acl(xmlNode *xml)
Definition: acl.c:243
struct pcmk__ipc_header_s pcmk__ipc_header_t
G_GNUC_INTERNAL int pcmk__element_xpath(const char *prefix, xmlNode *xml, char *buffer, int offset, size_t buffer_size)
Definition: xpath.c:269
G_GNUC_INTERNAL void pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update)
Definition: xml.c:2484
G_GNUC_INTERNAL void pcmk__xml_update(xmlNode *parent, xmlNode *target, xmlNode *update, bool as_diff)
Definition: xml.c:2515
G_GNUC_INTERNAL xmlNode * pcmk__xc_match(xmlNode *root, xmlNode *search_comment, bool exact)
Definition: xml.c:2435
struct pcmk__ipc_methods_s pcmk__ipc_methods_t
G_GNUC_INTERNAL int pcmk__send_ipc_request(pcmk_ipc_api_t *api, xmlNode *request)
Definition: ipc_client.c:616
G_GNUC_INTERNAL void pcmk__unpack_acl(xmlNode *source, xmlNode *target, const char *user)
Definition: acl.c:288
G_GNUC_INTERNAL bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy)
Definition: xml.c:51
G_GNUC_INTERNAL void pcmk__free_acls(GList *acls)
Definition: acl.c:46
G_GNUC_INTERNAL unsigned int pcmk__ipc_buffer_size(unsigned int max)
Definition: ipc_common.c:31
struct xml_private_s xml_private_t
G_GNUC_INTERNAL pcmk__ipc_methods_t * pcmk__pacemakerd_api_methods(void)
G_GNUC_INTERNAL void pcmk__xe_log(int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, int options)
Definition: xml.c:1444
G_GNUC_INTERNAL void pcmk__mark_xml_attr_dirty(xmlAttr *a)
Definition: xml.c:173
G_GNUC_INTERNAL void pcmk__buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:1989
G_GNUC_INTERNAL bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
Definition: ipc_common.c:81
G_GNUC_INTERNAL void pcmk__apply_creation_acl(xmlNode *xml, bool check_top)
Definition: acl.c:541
int pcmk__crm_ipc_is_authentic_process(qb_ipcc_connection_t *qb_ipc, int sock, uid_t refuid, gid_t refgid, pid_t *gotpid, uid_t *gotuid, gid_t *gotgid)
Check the authenticity of the IPC socket peer process.
Definition: ipc_client.c:1364
G_GNUC_INTERNAL void pcmk__mark_xml_created(xmlNode *xml)
Definition: xml.c:155
struct pcmk__deleted_xml_s pcmk__deleted_xml_t
G_GNUC_INTERNAL void pcmk__xml2text(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:1872
G_GNUC_INTERNAL bool pcmk__xa_filterable(const char *name)
Definition: digest.c:252
G_GNUC_INTERNAL int pcmk__xml_position(xmlNode *xml, enum xml_private_flags ignore_if_set)
Definition: xml.c:314
G_GNUC_INTERNAL xmlNode * pcmk__xml_match(xmlNode *haystack, xmlNode *needle, bool exact)
Definition: xml.c:369
G_GNUC_INTERNAL pcmk__ipc_methods_t * pcmk__controld_api_methods(void)
Definition: ipc_controld.c:262
G_GNUC_INTERNAL pcmk__ipc_methods_t * pcmk__schedulerd_api_methods(void)
G_GNUC_INTERNAL void pcmk__call_ipc_callback(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data)
Definition: ipc_client.c:145
void(* pcmk_ipc_callback_t)(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data, void *user_data)
Callback function type for Pacemaker daemon IPC APIs.
Definition: ipc.h:111
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Definition: ipc.h:80
pcmk_ipc_server
Available IPC interfaces.
Definition: ipc.h:69
pcmk_ipc_dispatch
How IPC replies should be dispatched.
Definition: ipc.h:88
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:163
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:33
const char * target
Definition: pcmk_fence.c:28
enum crm_exit_e crm_exit_t
struct qb_ipc_response_header qb
int(* new_data)(pcmk_ipc_api_t *api)
void(* free_data)(void *api_data)
bool(* dispatch)(pcmk_ipc_api_t *api, xmlNode *msg)
void(* post_disconnect)(pcmk_ipc_api_t *api)
bool(* reply_expected)(pcmk_ipc_api_t *api, xmlNode *request)
int(* post_connect)(pcmk_ipc_api_t *api)
enum pcmk_ipc_dispatch dispatch_type
mainloop_io_t * mainloop_io
pcmk__ipc_methods_t * cmds
pcmk_ipc_callback_t cb
enum pcmk_ipc_server server
xml_private_flags
Definition: xml_internal.h:315