19 #ifndef AIS_CRM_UTILS__H
20 # define AIS_CRM_UTILS__H
25 # include <openais/service/objdb.h>
26 # include <openais/service/print.h>
28 # define OPENAIS_EXTERNAL_SERVICE insane_ais_header_hack_in__totem_h
29 # include <openais/saAis.h>
30 # include <openais/service/swab.h>
31 # include <openais/totem/totempg.h>
32 # include <openais/service/service.h>
33 # include <openais/lcr/lcr_comp.h>
34 # include <openais/lcr/lcr_ifact.h>
35 # include <openais/service/config.h>
36 # define COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED OPENAIS_FLOW_CONTROL_NOT_REQUIRED
39 typedef unsigned int hdb_handle_t;
41 # define corosync_api_v1 objdb_iface_ver0
42 # define corosync_lib_handler openais_lib_handler
43 # define corosync_exec_handler openais_exec_handler
44 # define corosync_service_engine openais_service_handler
46 extern int openais_response_send(
void *conn,
void *msg,
int mlen);
47 extern int openais_dispatch_send(
void *conn,
void *msg,
int mlen);
51 # ifdef SUPPORT_COROSYNC
52 # include <corosync/corodefs.h>
53 # include <corosync/swab.h>
54 # include <corosync/hdb.h>
56 # include <corosync/engine/objdb.h>
57 # include <corosync/engine/coroapi.h>
58 # include <corosync/engine/logsys.h>
60 # include <corosync/lcr/lcr_comp.h>
61 LOGSYS_DECLARE_SUBSYS(
"pcmk");
65 # define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
89 extern void member_loop_fn(gpointer key, gpointer value, gpointer user_data);
106 extern hdb_handle_t
config_find_init(
struct corosync_api_v1 *config,
char *name);
107 extern hdb_handle_t
config_find_next(
struct corosync_api_v1 *config,
char *name,
108 hdb_handle_t top_handle);
109 extern void config_find_done(
struct corosync_api_v1 *config, hdb_handle_t local_handle);
111 hdb_handle_t object_service_handle,
112 char *key,
char **value,
const char *fallback);
115 extern long long ais_get_int(
const char *text,
char **end_text);
116 extern char *
ais_concat(
const char *prefix,
const char *suffix,
char join);
126 static inline const char *
127 level2char(
int level)
144 # define do_ais_log(level, fmt, args...) do { \
145 if(plugin_log_level < (level)) { \
147 } else if((level) > LOG_DEBUG) { \
148 log_printf(LOG_DEBUG, "debug%d: %s: " fmt, \
149 level-LOG_INFO, __FUNCTION__ , ##args); \
151 log_printf(level, "%s: %s: " fmt, level2char(level), \
152 __FUNCTION__ , ##args); \
156 # define ais_perror(fmt, args...) log_printf( \
157 LOG_ERR, "%s: " fmt ": (%d) %s", \
158 __FUNCTION__ , ##args, errno, strerror(errno))
160 # define ais_crit(fmt, args...) do_ais_log(LOG_CRIT, fmt , ##args)
161 # define ais_err(fmt, args...) do_ais_log(LOG_ERR, fmt , ##args)
162 # define ais_warn(fmt, args...) do_ais_log(LOG_WARNING, fmt , ##args)
163 # define ais_notice(fmt, args...) do_ais_log(LOG_NOTICE, fmt , ##args)
164 # define ais_info(fmt, args...) do_ais_log(LOG_INFO, fmt , ##args)
165 # define ais_debug(fmt, args...) do_ais_log(LOG_DEBUG, fmt , ##args)
166 # define ais_trace(fmt, args...) do_ais_log(LOG_DEBUG+1, fmt , ##args)
168 # define ais_malloc0(malloc_obj, length) do { \
169 malloc_obj = malloc(length); \
170 if(malloc_obj == NULL) { \
173 memset(malloc_obj, 0, length); \
176 # define ais_free(obj) do { \
183 # define AIS_ASSERT(expr) if((expr) == FALSE) { \
184 ais_crit("Assertion failure line %d: %s", __LINE__, #expr); \
188 # define AIS_CHECK(expr, failure_action) if((expr) == FALSE) { \
190 if(p == 0) { abort(); } \
191 ais_err("Child %d spawned to record non-fatal assertion failure line %d: %s", p, __LINE__, #expr); \
196 ais_strdup(
const char *src)
204 return strcpy(dup, src);
207 static inline gboolean
208 ais_str_eq(
const char *a,
const char *b)
210 if (a == NULL || b == NULL) {
216 }
else if (strcasecmp(a, b) == 0) {
223 libais_connection_active(
void *conn)
gboolean route_ais_message(const AIS_Message *msg, gboolean local_origin)
hdb_handle_t config_find_init(struct corosync_api_v1 *config, char *name)
int pcmk_user_lookup(const char *name, uid_t *uid, gid_t *gid)
long long ais_get_int(const char *text, char **end_text)
void log_ais_message(int level, const AIS_Message *msg)
struct crm_child_s crm_child_t
void config_find_done(struct corosync_api_v1 *config, hdb_handle_t local_handle)
#define ais_malloc0(malloc_obj, length)
pthread_t crm_wait_thread
struct pcmk_env_s pcmk_env
int ais_get_boolean(const char *value)
int update_member(unsigned int id, uint64_t born, uint64_t seq, int32_t votes, uint32_t procs, const char *uname, const char *state, const char *version)
void send_member_notification(void)
int get_config_opt(struct corosync_api_v1 *config, hdb_handle_t object_service_handle, char *key, char **value, const char *fallback)
int send_plugin_msg(enum crm_ais_msg_types type, const char *host, const char *data)
gboolean stop_child(crm_child_t *child, int signal)
const char * member_uname(uint32_t id)
void member_loop_fn(gpointer key, gpointer value, gpointer user_data)
char * ais_concat(const char *prefix, const char *suffix, char join)
void swap_sender(AIS_Message *msg)
hdb_handle_t config_find_next(struct corosync_api_v1 *config, char *name, hdb_handle_t top_handle)
void destroy_ais_node(gpointer data)
char * get_ais_data(const AIS_Message *msg)
gboolean spawn_child(crm_child_t *child)
char * append_member(char *data, crm_node_t *node)
void delete_member(uint32_t id, const char *uname)
gboolean process_ais_message(const AIS_Message *msg)
int send_client_msg(void *conn, enum crm_ais_msg_class class, enum crm_ais_msg_types type, const char *data)
int send_client_ipc(void *conn, const AIS_Message *ais_msg)
GHashTable * membership_list
enum crm_ais_msg_types type