pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
crmcommon_private.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2020 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 /*
28  * XML and ACLs
29  */
30 
32  xpf_none = 0x0000,
33  xpf_dirty = 0x0001,
34  xpf_deleted = 0x0002,
35  xpf_created = 0x0004,
36  xpf_modified = 0x0008,
37 
38  xpf_tracking = 0x0010,
39  xpf_processed = 0x0020,
40  xpf_skip = 0x0040,
41  xpf_moved = 0x0080,
42 
43  xpf_acl_enabled = 0x0100,
44  xpf_acl_read = 0x0200,
45  xpf_acl_write = 0x0400,
46  xpf_acl_deny = 0x0800,
47 
48  xpf_acl_create = 0x1000,
49  xpf_acl_denied = 0x2000,
50  xpf_lazy = 0x4000,
51 };
52 
53 /* When deleting portions of an XML tree, we keep a record so we can know later
54  * (e.g. when checking differences) that something was deleted.
55  */
56 typedef struct pcmk__deleted_xml_s {
57  char *path;
58  int position;
60 
61 typedef struct xml_private_s {
62  long check;
63  uint32_t flags;
64  char *user;
65  GList *acls;
66  GList *deleted_objs; // List of pcmk__deleted_xml_t
68 
69 #define pcmk__set_xml_flags(xml_priv, flags_to_set) do { \
70  (xml_priv)->flags = pcmk__set_flags_as(__func__, __LINE__, \
71  LOG_NEVER, "XML", "XML node", (xml_priv)->flags, \
72  (flags_to_set), #flags_to_set); \
73  } while (0)
74 
75 #define pcmk__clear_xml_flags(xml_priv, flags_to_clear) do { \
76  (xml_priv)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
77  LOG_NEVER, "XML", "XML node", (xml_priv)->flags, \
78  (flags_to_clear), #flags_to_clear); \
79  } while (0)
80 
81 G_GNUC_INTERNAL
82 void pcmk__xml2text(xmlNode *data, int options, char **buffer, int *offset,
83  int *max, int depth);
84 
85 G_GNUC_INTERNAL
86 void pcmk__buffer_add_char(char **buffer, int *offset, int *max, char c);
87 
88 G_GNUC_INTERNAL
89 void pcmk__set_xml_doc_flag(xmlNode *xml, enum xml_private_flags flag);
90 
91 G_GNUC_INTERNAL
92 bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy);
93 
94 G_GNUC_INTERNAL
95 int pcmk__element_xpath(const char *prefix, xmlNode *xml, char *buffer,
96  int offset, size_t buffer_size);
97 
98 G_GNUC_INTERNAL
99 void pcmk__mark_xml_created(xmlNode *xml);
100 
101 G_GNUC_INTERNAL
102 int pcmk__xml_position(xmlNode *xml, enum xml_private_flags ignore_if_set);
103 
104 G_GNUC_INTERNAL
105 xmlNode *pcmk__xml_match(xmlNode *haystack, xmlNode *needle, bool exact);
106 
107 G_GNUC_INTERNAL
108 void pcmk__xe_log(int log_level, const char *file, const char *function,
109  int line, const char *prefix, xmlNode *data, int depth,
110  int options);
111 
112 G_GNUC_INTERNAL
113 void pcmk__xml_update(xmlNode *parent, xmlNode *target, xmlNode *update,
114  bool as_diff);
115 
116 G_GNUC_INTERNAL
117 xmlNode *pcmk__xc_match(xmlNode *root, xmlNode *search_comment, bool exact);
118 
119 G_GNUC_INTERNAL
120 void pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update);
121 
122 G_GNUC_INTERNAL
123 void pcmk__free_acls(GList *acls);
124 
125 G_GNUC_INTERNAL
126 void pcmk__unpack_acl(xmlNode *source, xmlNode *target, const char *user);
127 
128 G_GNUC_INTERNAL
129 bool pcmk__check_acl(xmlNode *xml, const char *name,
130  enum xml_private_flags mode);
131 
132 G_GNUC_INTERNAL
133 void pcmk__apply_acl(xmlNode *xml);
134 
135 G_GNUC_INTERNAL
136 void pcmk__apply_creation_acl(xmlNode *xml, bool check_top);
137 
138 G_GNUC_INTERNAL
139 void pcmk__mark_xml_attr_dirty(xmlAttr *a);
140 
141 G_GNUC_INTERNAL
142 bool pcmk__xa_filterable(const char *name);
143 
144 static inline xmlAttr *
145 pcmk__first_xml_attr(const xmlNode *xml)
146 {
147  return xml? xml->properties : NULL;
148 }
149 
150 static inline const char *
151 pcmk__xml_attr_value(const xmlAttr *attr)
152 {
153  return ((attr == NULL) || (attr->children == NULL))? NULL
154  : (const char *) attr->children->content;
155 }
156 
157 /*
158  * IPC
159  */
160 
161 #define PCMK__IPC_VERSION 1
162 
163 #define PCMK__CONTROLD_API_MAJOR "1"
164 #define PCMK__CONTROLD_API_MINOR "0"
165 
166 // IPC behavior that varies by daemon
167 typedef struct pcmk__ipc_methods_s {
176  int (*new_data)(pcmk_ipc_api_t *api);
177 
184  void (*free_data)(void *api_data);
185 
201 
211  bool (*reply_expected)(pcmk_ipc_api_t *api, xmlNode *request);
212 
220  void (*dispatch)(pcmk_ipc_api_t *api, xmlNode *msg);
221 
230 
231 // Implementation of pcmk_ipc_api_t
233  enum pcmk_ipc_server server; // Daemon this IPC API instance is for
234  enum pcmk_ipc_dispatch dispatch_type; // How replies should be dispatched
235  size_t ipc_size_max; // maximum IPC buffer size
236  crm_ipc_t *ipc; // IPC connection
237  mainloop_io_t *mainloop_io; // If using mainloop, I/O source for IPC
238  bool free_on_disconnect; // Whether disconnect should free object
239  pcmk_ipc_callback_t cb; // Caller-registered callback (if any)
240  void *user_data; // Caller-registered data (if any)
241  void *api_data; // For daemon-specific use
242  pcmk__ipc_methods_t *cmds; // Behavior that varies by daemon
243 };
244 
245 typedef struct pcmk__ipc_header_s {
246  struct qb_ipc_response_header qb;
248  uint32_t size_compressed;
249  uint32_t flags;
250  uint8_t version;
252 
253 G_GNUC_INTERNAL
254 int pcmk__send_ipc_request(pcmk_ipc_api_t *api, xmlNode *request);
255 
256 G_GNUC_INTERNAL
258  enum pcmk_ipc_event event_type,
259  crm_exit_t status, void *event_data);
260 
261 G_GNUC_INTERNAL
262 unsigned int pcmk__ipc_buffer_size(unsigned int max);
263 
264 G_GNUC_INTERNAL
265 bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header);
266 
267 G_GNUC_INTERNAL
269 
270 G_GNUC_INTERNAL
272 
273 
274 /*
275  * Logging
276  */
277 
278 /* This says whether the current application is a Pacemaker daemon or not,
279  * and is used to change default logging settings such as whether to log to
280  * stderr, etc., as well as a few other details such as whether blackbox signal
281  * handling is enabled.
282  *
283  * It is set when logging is initialized, and does not need to be set directly.
284  */
285 G_GNUC_INTERNAL
286 extern bool pcmk__is_daemon;
287 
288 #endif // CRMCOMMON_PRIVATE__H
void(* dispatch)(pcmk_ipc_api_t *api, xmlNode *msg)
enum pcmk_ipc_dispatch dispatch_type
G_GNUC_INTERNAL void pcmk__buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:1971
G_GNUC_INTERNAL pcmk__ipc_methods_t * pcmk__pacemakerd_api_methods(void)
G_GNUC_INTERNAL int pcmk__element_xpath(const char *prefix, xmlNode *xml, char *buffer, int offset, size_t buffer_size)
Definition: xpath.c:268
G_GNUC_INTERNAL void pcmk__mark_xml_attr_dirty(xmlAttr *a)
Definition: xml.c:174
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:32
enum crm_exit_e crm_exit_t
struct pcmk__ipc_header_s pcmk__ipc_header_t
G_GNUC_INTERNAL xmlNode * pcmk__xc_match(xmlNode *root, xmlNode *search_comment, bool exact)
Definition: xml.c:2415
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:144
G_GNUC_INTERNAL void pcmk__set_xml_doc_flag(xmlNode *xml, enum xml_private_flags flag)
Definition: xml.c:118
struct qb_ipc_response_header qb
struct pcmk__deleted_xml_s pcmk__deleted_xml_t
pcmk_ipc_server
Available IPC interfaces.
Definition: ipc.h:68
G_GNUC_INTERNAL void pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update)
Definition: xml.c:2464
G_GNUC_INTERNAL bool pcmk__check_acl(xmlNode *xml, const char *name, enum xml_private_flags mode)
Definition: acl.c:615
G_GNUC_INTERNAL void pcmk__apply_creation_acl(xmlNode *xml, bool check_top)
Definition: acl.c:545
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:162
pcmk_ipc_callback_t cb
G_GNUC_INTERNAL bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
Definition: ipc_common.c:75
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:584
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:110
int(* post_connect)(pcmk_ipc_api_t *api)
xml_private_flags
G_GNUC_INTERNAL void pcmk__apply_acl(xmlNode *xml)
Definition: acl.c:243
G_GNUC_INTERNAL unsigned int pcmk__ipc_buffer_size(unsigned int max)
Definition: ipc_common.c:31
G_GNUC_INTERNAL xmlNode * pcmk__xml_match(xmlNode *haystack, xmlNode *needle, bool exact)
Definition: xml.c:371
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:1423
G_GNUC_INTERNAL bool pcmk__xa_filterable(const char *name)
Definition: digest.c:252
const char * target
Definition: pcmk_fence.c:29
G_GNUC_INTERNAL void pcmk__xml2text(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:1854
int(* new_data)(pcmk_ipc_api_t *api)
pcmk_ipc_dispatch
How IPC replies should be dispatched.
Definition: ipc.h:87
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Definition: ipc.h:79
mainloop_io_t * mainloop_io
G_GNUC_INTERNAL bool pcmk__is_daemon
Definition: logging.c:38
void(* free_data)(void *api_data)
struct xml_private_s xml_private_t
char data[0]
Definition: internal.h:90
G_GNUC_INTERNAL void pcmk__free_acls(GList *acls)
Definition: acl.c:46
bool(* reply_expected)(pcmk_ipc_api_t *api, xmlNode *request)
G_GNUC_INTERNAL void pcmk__unpack_acl(xmlNode *source, xmlNode *target, const char *user)
Definition: acl.c:302
G_GNUC_INTERNAL pcmk__ipc_methods_t * pcmk__controld_api_methods(void)
Definition: ipc_controld.c:244
pcmk__ipc_methods_t * cmds
G_GNUC_INTERNAL bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy)
Definition: xml.c:52
void(* post_disconnect)(pcmk_ipc_api_t *api)
enum pcmk_ipc_server server
char * name
Definition: pcmk_fence.c:31
G_GNUC_INTERNAL void pcmk__mark_xml_created(xmlNode *xml)
Definition: xml.c:156
G_GNUC_INTERNAL void pcmk__xml_update(xmlNode *parent, xmlNode *target, xmlNode *update, bool as_diff)
Definition: xml.c:2495
G_GNUC_INTERNAL int pcmk__xml_position(xmlNode *xml, enum xml_private_flags ignore_if_set)
Definition: xml.c:315