~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to include/crm/crm.h

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-07-16 16:40:24 UTC
  • mfrom: (1.1.11) (2.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130716164024-lvwrf4xivk1wdr3c
Tags: 1.1.9+git20130321-1ubuntu1
* Resync from debian expiremental.
* debian/control:
  - Use lower version for Build-Depends on libcorosync-dev
    and libqb-dev.
  - Build-Depends on libcfg-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#ifndef CRM__H
19
19
#  define CRM__H
20
20
 
 
21
/**
 
22
 * \file
 
23
 * \brief A dumping ground
 
24
 * \ingroup core
 
25
 */
 
26
 
21
27
#  include <crm_config.h>
22
28
#  include <stdlib.h>
23
29
#  include <glib.h>
24
30
#  include <stdbool.h>
25
 
#  include <assert.h>
26
31
 
27
32
#  undef MIN
28
33
#  undef MAX
29
34
#  include <string.h>
30
35
 
31
 
#  if LIBQB_LOGGING
32
 
#    include <qb/qblog.h>
33
 
#  else
34
 
#    include <clplumbing/cl_log.h>
35
 
#  endif
36
 
 
37
36
#  include <libxml/tree.h>
38
37
 
39
 
extern int log_data_element(int log_level, const char *file, const char *function, int line,
40
 
                            const char *prefix, xmlNode * data, int depth, gboolean formatted);
41
 
 
42
 
#  define CRM_FEATURE_SET               "3.0.6"
 
38
#  define CRM_FEATURE_SET               "3.0.7"
43
39
#  define MINIMUM_SCHEMA_VERSION        "pacemaker-1.0"
44
 
#  define LATEST_SCHEMA_VERSION "pacemaker-"CRM_DTD_VERSION
 
40
#  define LATEST_SCHEMA_VERSION         "pacemaker-"CRM_DTD_VERSION
45
41
 
46
42
#  define EOS           '\0'
47
43
#  define DIMOF(a)      ((int) (sizeof(a)/sizeof(a[0])) )
48
44
 
 
45
#  ifndef MAX_NAME
 
46
#    define MAX_NAME    256
 
47
#  endif
 
48
 
49
49
#  ifndef __GNUC__
50
50
#    define __builtin_expect(expr, result) (expr)
51
51
#  endif
54
54
#  define __likely(expr) __builtin_expect(expr, 1)
55
55
#  define __unlikely(expr) __builtin_expect(expr, 0)
56
56
 
57
 
#  define CRM_DEPRECATED_SINCE_2_0_1 0
58
 
#  define CRM_DEPRECATED_SINCE_2_0_2 0
59
 
#  define CRM_DEPRECATED_SINCE_2_0_3 0
60
 
#  define CRM_DEPRECATED_SINCE_2_0_4 0
61
 
#  define CRM_DEPRECATED_SINCE_2_0_5 0
62
 
#  define CRM_DEPRECATED_SINCE_2_0_6 1
63
 
#  define CRM_DEPRECATED_SINCE_2_0_7 1
64
 
#  define CRM_DEPRECATED_SINCE_2_0_8 1
65
 
#  define CRM_DEPRECATED_SINCE_2_1_0 1
66
 
 
67
57
#  define CRM_META                      "CRM_meta"
68
58
 
69
 
#  define CRM_ASSERT(expr) do {                                         \
70
 
        if(__unlikely((expr) == FALSE)) {                               \
71
 
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, TRUE, FALSE); \
72
 
        }                                                               \
73
 
    } while(0)
74
 
 
75
59
extern const char *crm_system_name;
76
60
 
77
61
/* *INDENT-OFF* */
102
86
#  define CRM_SYSTEM_PENGINE    "pengine"
103
87
#  define CRM_SYSTEM_TENGINE    "tengine"
104
88
#  define CRM_SYSTEM_STONITHD   "stonithd"
 
89
#  define CRM_SYSTEM_MCP        "pacemakerd"
105
90
 
106
91
/* Valid operations */
107
92
#  define CRM_OP_NOOP           "noop"
134
119
#  define CRM_OP_TETIMEOUT      "te_timeout"
135
120
#  define CRM_OP_TRANSITION     "transition"
136
121
#  define CRM_OP_REGISTER               "register"
 
122
#  define CRM_OP_IPC_FWD                "ipc_fwd"
137
123
#  define CRM_OP_DEBUG_UP               "debug_inc"
138
124
#  define CRM_OP_DEBUG_DOWN     "debug_dec"
139
125
#  define CRM_OP_INVOKE_LRM     "lrm_invoke"
145
131
#  define CRM_OP_REPROBE                "probe_again"
146
132
#  define CRM_OP_CLEAR_FAILCOUNT  "clear_failcount"
147
133
#  define CRM_OP_RELAXED_SET  "one-or-more"
148
 
 
149
 
#  define CRMD_STATE_ACTIVE     "member"
150
 
#  define CRMD_STATE_INACTIVE   "down"
151
 
 
152
 
#  define CRMD_JOINSTATE_DOWN   CRMD_STATE_INACTIVE
153
 
#  define CRMD_JOINSTATE_PENDING        "pending"
154
 
#  define CRMD_JOINSTATE_MEMBER CRMD_STATE_ACTIVE
155
 
#  define CRMD_JOINSTATE_NACK   "banned"
 
134
#  define CRM_OP_RM_NODE_CACHE "rm_node_cache"
 
135
 
 
136
#  define CRMD_JOINSTATE_DOWN           "down"
 
137
#  define CRMD_JOINSTATE_PENDING        "pending"
 
138
#  define CRMD_JOINSTATE_MEMBER         "member"
 
139
#  define CRMD_JOINSTATE_NACK           "banned"
156
140
 
157
141
#  define CRMD_ACTION_DELETE            "delete"
158
142
#  define CRMD_ACTION_CANCEL            "cancel"
202
186
 
203
187
typedef GList *GListPtr;
204
188
 
205
 
/* LOG_DEBUG = 7, make LOG_TRACE ::= -VVVVV */
206
 
#  ifdef LOG_TRACE
207
 
#    undef LOG_TRACE
208
 
#  endif
209
 
 
210
 
#  ifndef LOG_TRACE
211
 
#    define LOG_TRACE    12
212
 
#  endif
213
 
#  define LOG_DEBUG_2  LOG_TRACE
214
 
#  define LOG_DEBUG_3  LOG_TRACE
215
 
#  define LOG_DEBUG_4  LOG_TRACE
216
 
#  define LOG_DEBUG_5  LOG_TRACE
217
 
#  define LOG_DEBUG_6  LOG_TRACE
218
 
 
219
 
#  define LOG_MSG  LOG_TRACE
220
 
 
221
 
/*
222
 
 * Throughout the macros below, note the leading, pre-comma, space in the
223
 
 * various ' , ##args' occurences to aid portability across versions of 'gcc'.
224
 
 *      http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
225
 
 */
226
 
#  if LIBQB_LOGGING
227
 
 
228
 
#    define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
229
 
 
230
 
#    define do_crm_log(level, fmt, args...) do {                        \
231
 
        qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, 0, ##args); \
232
 
    } while(0)
233
 
 
234
 
/* level /MUST/ be a constant or compilation will fail */
235
 
#    define do_crm_log_unlikely(level, fmt, args...) do {               \
236
 
        static struct qb_log_callsite *trace_cs = NULL;                 \
237
 
        if(trace_cs == NULL) {                                          \
238
 
            trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
239
 
        }                                                               \
240
 
        if (trace_cs && trace_cs->targets) {                            \
241
 
            qb_log_from_external_source(                                \
242
 
                __func__, __FILE__, fmt, level, __LINE__, 0,  ##args);  \
243
 
        }                                                               \
244
 
    } while(0)
245
 
 
246
 
#    define CRM_LOG_ASSERT(expr) do {                                   \
247
 
        if(__unlikely((expr) == FALSE)) {                               \
248
 
            static struct qb_log_callsite *core_cs = NULL;              \
249
 
            if(core_cs == NULL) {                                       \
250
 
                qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
251
 
            }                                                           \
252
 
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
253
 
                      core_cs?core_cs->targets:FALSE, TRUE);            \
254
 
        }                                                               \
255
 
    } while(0)
256
 
 
257
 
#    define CRM_CHECK(expr, failure_action) do {                                \
258
 
        if(__unlikely((expr) == FALSE)) {                               \
259
 
            static struct qb_log_callsite *core_cs = NULL;              \
260
 
            if(core_cs == NULL) {                                       \
261
 
                qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
262
 
            }                                                           \
263
 
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
264
 
                      core_cs?core_cs->targets:FALSE, TRUE);            \
265
 
            failure_action;                                             \
266
 
        }                                                               \
267
 
    } while(0)
268
 
 
269
 
#    define do_crm_log_xml(level, text, xml) do {                       \
270
 
        static struct qb_log_callsite *xml_cs = NULL;                   \
271
 
        if(xml_cs == NULL) {                                            \
272
 
            qb_log_callsite_get(__func__, __FILE__, "xml-blog", LOG_TRACE, __LINE__, 0); \
273
 
        }                                                               \
274
 
        if (xml_cs && xml_cs->targets) {                                            \
275
 
            log_data_element(level, __FILE__, __PRETTY_FUNCTION__, __LINE__, text, xml, 0, TRUE); \
276
 
        }                                                               \
277
 
    } while(0)
278
 
 
279
 
#    define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
280
 
        qb_log_from_external_source(function, file, fmt, level, line, 0,  ##args); \
281
 
    } while(0)
282
 
 
283
 
#    define do_crm_log_always(level, fmt, args...) qb_log(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args)
284
 
 
285
 
#    define crm_crit(fmt, args...)    qb_logt(LOG_CRIT,    0, fmt , ##args)
286
 
#    define crm_err(fmt, args...)     qb_logt(LOG_ERR,     0, fmt , ##args)
287
 
#    define crm_warn(fmt, args...)    qb_logt(LOG_WARNING, 0, fmt , ##args)
288
 
#    define crm_notice(fmt, args...)  qb_logt(LOG_NOTICE,  0, fmt , ##args)
289
 
#    define crm_info(fmt, args...)    qb_logt(LOG_INFO,    0, fmt , ##args)
290
 
#    define crm_debug(fmt, args...)   qb_logt(LOG_DEBUG,   0, fmt , ##args)
291
 
#    define crm_trace(fmt, args...)   do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
292
 
 
293
 
#  else
294
 
#    define CRM_TRACE_INIT_DATA(name)
295
 
 
296
 
#    define do_crm_log(level, fmt, args...) do {                                \
297
 
        if(__likely((level) <= crm_log_level)) {                        \
298
 
            cl_log((level)>LOG_DEBUG?LOG_DEBUG:(level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args);      \
299
 
        }                                                               \
300
 
    } while(0)
301
 
 
302
 
#    define do_crm_log_unlikely(level, fmt, args...) do {                       \
303
 
        if(__unlikely((level) <= crm_log_level)) {                      \
304
 
            cl_log((level)>LOG_DEBUG?LOG_DEBUG:(level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
305
 
        }                                                               \
306
 
    } while(0)
307
 
 
308
 
#    define do_crm_log_xml(level, text, xml) do {                               \
309
 
        if(xml == NULL) {                                               \
310
 
        } else if(__unlikely((level) <= crm_log_level)) {               \
311
 
            log_data_element((level)>LOG_DEBUG?LOG_DEBUG:(level), __FILE__, __PRETTY_FUNCTION__, 0, text, xml, 0, TRUE); \
312
 
        }                                                               \
313
 
    } while(0)
314
 
 
315
 
#    define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
316
 
        if((level) <= crm_log_level) {                                  \
317
 
            cl_log((level)>LOG_DEBUG?LOG_DEBUG:(level), "%s: "fmt, function, ##args); \
318
 
        }                                                               \
319
 
    } while(0)
320
 
 
321
 
#    define do_crm_log_always(level, fmt, args...) cl_log(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args)
322
 
 
323
 
#    define crm_crit(fmt, args...)    do_crm_log_always(LOG_CRIT,    fmt , ##args)
324
 
#    define crm_err(fmt, args...)     do_crm_log(LOG_ERR,     fmt , ##args)
325
 
#    define crm_warn(fmt, args...)    do_crm_log(LOG_WARNING, fmt , ##args)
326
 
#    define crm_notice(fmt, args...)  do_crm_log(LOG_NOTICE,  fmt , ##args)
327
 
#    define crm_info(fmt, args...)    do_crm_log(LOG_INFO,    fmt , ##args)
328
 
#    define crm_debug(fmt, args...)   do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
329
 
#    define crm_trace(fmt, args...)   do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
330
 
 
331
 
#    define CRM_LOG_ASSERT(expr) do {                                   \
332
 
        if(__unlikely((expr) == FALSE)) {                               \
333
 
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
334
 
                      FALSE, TRUE);                                     \
335
 
        }                                                               \
336
 
    } while(0)
337
 
 
338
 
#    define CRM_CHECK(expr, failure_action) do {                                \
339
 
        if(__unlikely((expr) == FALSE)) {                               \
340
 
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
341
 
                      FALSE, TRUE);                                     \
342
 
            failure_action;                                             \
343
 
        }                                                               \
344
 
    } while(0)
345
 
 
346
 
#  endif
347
 
 
348
 
#  define crm_debug_2 crm_trace
349
 
#  define crm_debug_3 crm_trace
350
 
#  define crm_debug_4 crm_trace
351
 
#  define crm_debug_5 crm_trace
352
 
#  define crm_debug_6 crm_trace
353
 
 
354
 
#  define crm_perror(level, fmt, args...) do {                          \
355
 
        const char *err = strerror(errno);                              \
356
 
        fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno);         \
357
 
        do_crm_log(level, fmt ": %s (%d)", ##args, err, errno);         \
358
 
    } while(0)
359
 
 
 
189
#  include <crm/common/logging.h>
360
190
#  include <crm/common/util.h>
361
 
 
362
 
#  define crm_log_xml_crit(xml, text)    do_crm_log_xml(LOG_CRIT,    text, xml)
363
 
#  define crm_log_xml_err(xml, text)     do_crm_log_xml(LOG_ERR,     text, xml)
364
 
#  define crm_log_xml_warn(xml, text)    do_crm_log_xml(LOG_WARNING, text, xml)
365
 
#  define crm_log_xml_notice(xml, text)  do_crm_log_xml(LOG_NOTICE,  text, xml)
366
 
#  define crm_log_xml_info(xml, text)    do_crm_log_xml(LOG_INFO,    text, xml)
367
 
#  define crm_log_xml_debug(xml, text)   do_crm_log_xml(LOG_DEBUG,   text, xml)
368
 
#  define crm_log_xml_trace(xml, text)   do_crm_log_xml(LOG_TRACE,   text, xml)
369
 
 
370
 
#  define crm_log_xml do_crm_log_xml
371
 
#  define crm_log_xml_debug_2 crm_log_xml_trace
372
 
#  define crm_log_xml_debug_3 crm_log_xml_trace
373
 
#  define crm_log_xml_debug_4 crm_log_xml_trace
374
 
#  define crm_log_xml_debug_5 crm_log_xml_trace
375
 
 
376
 
#  define crm_str(x)    (const char*)(x?x:"<null>")
377
 
 
378
 
#  define crm_malloc0(malloc_obj, length) do {                          \
379
 
        malloc_obj = malloc(length);                                    \
380
 
        if(malloc_obj == NULL) {                                        \
381
 
            crm_err("Failed allocation of %lu bytes", (unsigned long)length); \
382
 
            CRM_ASSERT(malloc_obj != NULL);                             \
383
 
        }                                                               \
384
 
        memset(malloc_obj, 0, length);                                  \
385
 
    } while(0)
386
 
 
387
 
#  define crm_malloc(malloc_obj, length) do {                           \
388
 
        malloc_obj = malloc(length);                                    \
389
 
        if(malloc_obj == NULL) {                                        \
390
 
            crm_err("Failed allocation of %lu bytes", (unsigned long)length); \
391
 
            CRM_ASSERT(malloc_obj != NULL);                             \
392
 
        }                                                               \
393
 
    } while(0)
394
 
 
395
 
#  define crm_realloc(realloc_obj, length) do {                         \
396
 
        realloc_obj = realloc(realloc_obj, length);                     \
397
 
        CRM_ASSERT(realloc_obj != NULL);                                \
398
 
    } while(0)
399
 
 
400
 
#  define crm_free(free_obj) do { free(free_obj); free_obj=NULL; } while(0)
401
 
#  define crm_msg_del(msg) do { if(msg != NULL) { ha_msg_del(msg); msg = NULL; } } while(0)
402
 
 
403
 
#  define crm_strdup(str) crm_strdup_fn(str, __FILE__, __PRETTY_FUNCTION__, __LINE__)
 
191
#  include <crm/error.h>
404
192
 
405
193
#  define crm_str_hash g_str_hash_traditional
406
 
extern guint g_str_hash_traditional(gconstpointer v);
407
 
 
408
 
extern void update_all_trace_data(void);
409
 
 
410
 
static inline void
411
 
slist_basic_destroy(GListPtr list)
412
 
{
413
 
    GListPtr gIter = NULL;
414
 
 
415
 
    for (gIter = list; gIter != NULL; gIter = gIter->next) {
416
 
        free(gIter->data);
417
 
    }
418
 
    g_list_free(list);
419
 
}
420
 
 
421
 
/* These two macros are no longer to be used
422
 
 * They exist for compatability reasons and will be removed in a
423
 
 * future release
424
 
 * Use something like this instead:
425
 
 
426
 
    GListPtr gIter = rsc->children;
427
 
    for(; gIter != NULL; gIter = gIter->next) {
428
 
        resource_t *child_rsc = (resource_t*)gIter->data;
429
 
        ...
430
 
    }
431
 
 *
432
 
 */
433
 
#  define slist_destroy(child_type, child, parent, a) do {              \
434
 
        GListPtr __crm_iter_head = parent;                              \
435
 
        child_type *child = NULL;                                       \
436
 
        while(__crm_iter_head != NULL) {                                \
437
 
            child = (child_type *) __crm_iter_head->data;               \
438
 
            __crm_iter_head = __crm_iter_head->next;                    \
439
 
            { a; }                                                      \
440
 
        }                                                               \
441
 
        g_list_free(parent);                                            \
442
 
    } while(0)
443
 
 
444
 
#  define slist_iter(child, child_type, parent, counter, a) do {                \
445
 
        GListPtr __crm_iter_head = parent;                              \
446
 
        child_type *child = NULL;                                       \
447
 
        int counter = 0;                                                \
448
 
        for(; __crm_iter_head != NULL; counter++) {                     \
449
 
            child = (child_type *) __crm_iter_head->data;               \
450
 
            __crm_iter_head = __crm_iter_head->next;                    \
451
 
            { a; }                                                      \
452
 
        }                                                               \
453
 
    } while(0)
 
194
 
 
195
guint g_str_hash_traditional(gconstpointer v);
454
196
 
455
197
#endif