This source file includes following definitions.
- pcmk__set_flags_as
- pcmk__clear_flags_as
- pcmk__realloc
- pcmk__getpid_s
- pcmk__list_of_1
- pcmk__list_of_multiple
- pcmk__fail_attr_name
- pcmk__failcount_name
- pcmk__lastfailure_name
1
2
3
4
5
6
7
8
9
10 #ifndef CRM_COMMON_INTERNAL__H
11 #define CRM_COMMON_INTERNAL__H
12
13 #include <unistd.h>
14 #include <stdbool.h>
15 #include <stdint.h>
16
17 #include <glib.h>
18 #include <libxml/tree.h>
19
20 #include <crm/common/util.h>
21 #include <crm/common/logging.h>
22 #include <crm/common/mainloop.h>
23 #include <crm/common/health_internal.h>
24 #include <crm/common/io_internal.h>
25 #include <crm/common/iso8601_internal.h>
26 #include <crm/common/results_internal.h>
27 #include <crm/common/messages_internal.h>
28 #include <crm/common/strings_internal.h>
29 #include <crm/common/acl_internal.h>
30
31
32
33
34
35
36
37
38 extern bool pcmk__is_daemon;
39
40
41 extern char *pcmk__our_nodename;
42
43
44 #define PCMK__NELEM(a) ((int) (sizeof(a)/sizeof(a[0])) )
45
46 #if SUPPORT_CIBSECRETS
47
48
49 int pcmk__substitute_secrets(const char *rsc_id, GHashTable *params);
50 #endif
51
52
53
54
55 bool pcmk__verify_digest(xmlNode *input, const char *expected);
56
57
58
59
60 int pcmk__add_mainloop_ipc(crm_ipc_t *ipc, int priority, void *userdata,
61 const struct ipc_client_callbacks *callbacks,
62 mainloop_io_t **source);
63 guint pcmk__mainloop_timer_get_period(const mainloop_timer_t *timer);
64
65
66
67
68
69
70
71
72
73
74
75
76 void pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid);
77
78
79
80
81 int pcmk__scan_nvpair(const char *input, char **name, char **value);
82 char *pcmk__format_nvpair(const char *name, const char *value,
83 const char *units);
84
85
86
87
88
89
90
91
92
93 void
94 pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value);
95
96
97
98
99
100
101
102
103
104
105
106 bool
107 pcmk__xe_attr_is_true(const xmlNode *node, const char *name);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 int
125 pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value);
126
127
128
129
130 pid_t pcmk__procfs_pid_of(const char *name);
131 unsigned int pcmk__procfs_num_cores(void);
132 int pcmk__procfs_pid2path(pid_t pid, char path[], size_t path_size);
133 bool pcmk__procfs_has_pids(void);
134
135
136
137 void crm_schema_init(void);
138 void crm_schema_cleanup(void);
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 int pcmk__pid_active(pid_t pid, const char *daemon);
160
161 int pcmk__read_pidfile(const char *filename, pid_t *pid);
162 int pcmk__pidfile_matches(const char *filename, pid_t expected_pid,
163 const char *expected_name, pid_t *pid);
164 int pcmk__lock_pidfile(const char *filename, const char *name);
165
166
167
168
169
170 #define PCMK__OP_FMT "%s_%s_%u"
171
172 char *pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms);
173 char *pcmk__notify_key(const char *rsc_id, const char *notify_type,
174 const char *op_type);
175 char *pcmk__transition_key(int transition_id, int action_id, int target_rc,
176 const char *node);
177 void pcmk__filter_op_for_digest(xmlNode *param_set);
178 bool pcmk__is_fencing_action(const char *action);
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 static inline uint64_t
199 pcmk__set_flags_as(const char *function, int line, uint8_t log_level,
200 const char *flag_type, const char *target,
201 uint64_t flag_group, uint64_t flags, const char *flags_str)
202 {
203 uint64_t result = flag_group | flags;
204
205 if (result != flag_group) {
206 do_crm_log_unlikely(log_level,
207 "%s flags %#.8llx (%s) for %s set by %s:%d",
208 ((flag_type == NULL)? "Group of" : flag_type),
209 (unsigned long long) flags,
210 ((flags_str == NULL)? "flags" : flags_str),
211 ((target == NULL)? "target" : target),
212 function, line);
213 }
214 return result;
215 }
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 static inline uint64_t
233 pcmk__clear_flags_as(const char *function, int line, uint8_t log_level,
234 const char *flag_type, const char *target,
235 uint64_t flag_group, uint64_t flags, const char *flags_str)
236 {
237 uint64_t result = flag_group & ~flags;
238
239 if (result != flag_group) {
240 do_crm_log_unlikely(log_level,
241 "%s flags %#.8llx (%s) for %s cleared by %s:%d",
242 ((flag_type == NULL)? "Group of" : flag_type),
243 (unsigned long long) flags,
244 ((flags_str == NULL)? "flags" : flags_str),
245 ((target == NULL)? "target" : target),
246 function, line);
247 }
248 return result;
249 }
250
251
252
253 void pcmk__daemonize(const char *name, const char *pidfile);
254 void pcmk__panic(const char *origin);
255 pid_t pcmk__locate_sbd(void);
256 void pcmk__sleep_ms(unsigned int ms);
257
258 extern int pcmk__score_red;
259 extern int pcmk__score_green;
260 extern int pcmk__score_yellow;
261
262
263
264
265
266
267
268
269
270
271
272
273
274 static inline void *
275 pcmk__realloc(void *ptr, size_t size)
276 {
277 void *new_ptr;
278
279
280 CRM_ASSERT(size > 0);
281
282 new_ptr = realloc(ptr, size);
283 if (new_ptr == NULL) {
284 free(ptr);
285 abort();
286 }
287 return new_ptr;
288 }
289
290
291 static inline char *
292 pcmk__getpid_s(void)
293 {
294 return crm_strdup_printf("%lu", (unsigned long) getpid());
295 }
296
297
298 static inline bool
299 pcmk__list_of_1(GList *list)
300 {
301 return list && (list->next == NULL);
302 }
303
304
305 static inline bool
306 pcmk__list_of_multiple(GList *list)
307 {
308 return list && (list->next != NULL);
309 }
310
311
312
313 #define PCMK__FAIL_COUNT_PREFIX "fail-count"
314 #define PCMK__LAST_FAILURE_PREFIX "last-failure"
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333 static inline char *
334 pcmk__fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
335 guint interval_ms)
336 {
337 CRM_CHECK(prefix && rsc_id && op, return NULL);
338 return crm_strdup_printf("%s-%s#%s_%u", prefix, rsc_id, op, interval_ms);
339 }
340
341 static inline char *
342 pcmk__failcount_name(const char *rsc_id, const char *op, guint interval_ms)
343 {
344 return pcmk__fail_attr_name(PCMK__FAIL_COUNT_PREFIX, rsc_id, op,
345 interval_ms);
346 }
347
348 static inline char *
349 pcmk__lastfailure_name(const char *rsc_id, const char *op, guint interval_ms)
350 {
351 return pcmk__fail_attr_name(PCMK__LAST_FAILURE_PREFIX, rsc_id, op,
352 interval_ms);
353 }
354
355
356 int pcmk__effective_rc(int rc);
357
358 #endif