pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crm_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-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 CRM_INTERNAL__H
11 # define CRM_INTERNAL__H
12 
13 # include <config.h>
14 # include <portability.h>
15 
16 # include <glib.h>
17 # include <stdbool.h>
18 # include <libxml/tree.h>
19 
20 /* Public API headers can guard deprecated code with this symbol, thus
21  * preventing internal code (which includes this header) from using it, while
22  * still allowing external code (which can't include this header) to use it,
23  * for backward compatibility.
24  */
25 #define PCMK__NO_COMPAT
26 
27 # include <crm/lrmd.h>
28 # include <crm/common/logging.h>
31 # include <crm/common/internal.h>
32 
33 /* Assorted convenience functions */
34 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
35 
36 static inline long long
37 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
38 {
39  long long rc = (word & ~bit);
40 
41  if (rc == word) {
42  /* Unchanged */
43  } else if (target) {
44  crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
45  } else {
46  crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
47  }
48 
49  return rc;
50 }
51 
52 static inline long long
53 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
54 {
55  long long rc = (word | bit);
56 
57  if (rc == word) {
58  /* Unchanged */
59  } else if (target) {
60  crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
61  } else {
62  crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
63  }
64 
65  return rc;
66 }
67 
68 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
69 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
70 
71 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
72 
73 void strip_text_nodes(xmlNode * xml);
74 void pcmk_panic(const char *origin);
75 pid_t pcmk_locate_sbd(void);
76 
77 
78 /*
79  * XML attribute names used only by internal code
80  */
81 
82 #define PCMK__XA_ATTR_DAMPENING "attr_dampening"
83 #define PCMK__XA_ATTR_FORCE "attrd_is_force_write"
84 #define PCMK__XA_ATTR_INTERVAL "attr_clear_interval"
85 #define PCMK__XA_ATTR_IS_PRIVATE "attr_is_private"
86 #define PCMK__XA_ATTR_IS_REMOTE "attr_is_remote"
87 #define PCMK__XA_ATTR_NAME "attr_name"
88 #define PCMK__XA_ATTR_NODE_ID "attr_host_id"
89 #define PCMK__XA_ATTR_NODE_NAME "attr_host"
90 #define PCMK__XA_ATTR_OPERATION "attr_clear_operation"
91 #define PCMK__XA_ATTR_PATTERN "attr_regex"
92 #define PCMK__XA_ATTR_RESOURCE "attr_resource"
93 #define PCMK__XA_ATTR_SECTION "attr_section"
94 #define PCMK__XA_ATTR_SET "attr_set"
95 #define PCMK__XA_ATTR_USER "attr_user"
96 #define PCMK__XA_ATTR_UUID "attr_key"
97 #define PCMK__XA_ATTR_VALUE "attr_value"
98 #define PCMK__XA_ATTR_VERSION "attr_version"
99 #define PCMK__XA_ATTR_WRITER "attr_writer"
100 #define PCMK__XA_MODE "mode"
101 #define PCMK__XA_TASK "task"
102 
103 
104 /*
105  * IPC service names that are only used internally
106  */
107 
108 # define PCMK__SERVER_BASED_RO "cib_ro"
109 # define PCMK__SERVER_BASED_RW "cib_rw"
110 # define PCMK__SERVER_BASED_SHM "cib_shm"
111 
112 /*
113  * IPC commands that can be sent to Pacemaker daemons
114  */
115 
116 #define PCMK__ATTRD_CMD_PEER_REMOVE "peer-remove"
117 #define PCMK__ATTRD_CMD_UPDATE "update"
118 #define PCMK__ATTRD_CMD_UPDATE_BOTH "update-both"
119 #define PCMK__ATTRD_CMD_UPDATE_DELAY "update-delay"
120 #define PCMK__ATTRD_CMD_QUERY "query"
121 #define PCMK__ATTRD_CMD_REFRESH "refresh"
122 #define PCMK__ATTRD_CMD_FLUSH "flush"
123 #define PCMK__ATTRD_CMD_SYNC "sync"
124 #define PCMK__ATTRD_CMD_SYNC_RESPONSE "sync-response"
125 #define PCMK__ATTRD_CMD_CLEAR_FAILURE "clear-failure"
126 
127 
128 /*
129  * Environment variables used by Pacemaker
130  */
131 
132 #define PCMK__ENV_PHYSICAL_HOST "physical_host"
133 
134 
135 # if SUPPORT_COROSYNC
136 # include <qb/qbipc_common.h>
137 # include <corosync/corotypes.h>
138 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
139 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
140 # else
141 typedef struct {
142  int size __attribute__ ((aligned(8)));
143  int id __attribute__ ((aligned(8)));
144 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
145 
146 typedef struct {
147  int size __attribute__ ((aligned(8)));
148  int id __attribute__ ((aligned(8)));
149  int error __attribute__ ((aligned(8)));
150 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
151 
152 # endif
153 
154 static inline void *
155 realloc_safe(void *ptr, size_t size)
156 {
157  void *new_ptr;
158 
159  // realloc(p, 0) can replace free(p) but this wrapper can't
160  CRM_ASSERT(size > 0);
161 
162  new_ptr = realloc(ptr, size);
163  if (new_ptr == NULL) {
164  free(ptr);
165  abort();
166  }
167  return new_ptr;
168 }
169 
170 const char *crm_xml_add_last_written(xmlNode *xml_node);
171 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
172 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
173 
174 #if defined(PCMK__WITH_ATTRIBUTE_OUTPUT_ARGS)
175 # define PCMK__OUTPUT_ARGS(ARGS...) __attribute__((output_args(ARGS)))
176 #else
177 # define PCMK__OUTPUT_ARGS(ARGS...)
178 #endif
179 
180 #endif /* CRM_INTERNAL__H */
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:3293
uint32_t size
Definition: internal.h:84
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:403
Resource agent executor.
Wrappers for and extensions to libqb logging.
int rc
Definition: pcmk_fence.c:34
#define crm_trace(fmt, args...)
Definition: logging.h:369
void pcmk_panic(const char *origin)
Definition: watchdog.c:147
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:139
const char * target
Definition: pcmk_fence.c:28
#define CRM_ASSERT(expr)
Definition: results.h:42
char data[0]
Definition: internal.h:90
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2328
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:120
pid_t pcmk_locate_sbd(void)
Definition: watchdog.c:179
char * name
Definition: pcmk_fence.c:30
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:2426
enum crm_proc_flag __attribute__
struct qb_ipc_request_header cs_ipc_header_request_t
Definition: crm_internal.h:138
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3186