This source file includes following definitions.
- level2char
- ais_strdup
- ais_str_eq
- libais_connection_active
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef AIS_CRM_UTILS__H
20 # define AIS_CRM_UTILS__H
21
22 # include <syslog.h>
23
24 # ifdef AIS_WHITETANK
25 # include <openais/service/objdb.h>
26 # include <openais/service/print.h>
27
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
37
38
39 typedef unsigned int hdb_handle_t;
40
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
45
46 extern int openais_response_send(void *conn, void *msg, int mlen);
47 extern int openais_dispatch_send(void *conn, void *msg, int mlen);
48
49 # endif
50
51 # ifdef SUPPORT_COROSYNC
52 # include <corosync/corodefs.h>
53 # include <corosync/swab.h>
54 # include <corosync/hdb.h>
55
56 # include <corosync/engine/objdb.h>
57 # include <corosync/engine/coroapi.h>
58 # include <corosync/engine/logsys.h>
59
60 # include <corosync/lcr/lcr_comp.h>
61 LOGSYS_DECLARE_SUBSYS("pcmk");
62 # endif
63
64
65 # define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
66
67 typedef struct crm_child_s {
68 int pid;
69 long flag;
70 long flags;
71 int start_seq;
72 int respawn_count;
73 gboolean respawn;
74 const char *name;
75 const char *uid;
76 const char *command;
77 void *conn;
78 void *async_conn;
79
80 } crm_child_t;
81
82 extern void destroy_ais_node(gpointer data);
83 extern void delete_member(uint32_t id, const char *uname);
84 extern int update_member(unsigned int id, uint64_t born, uint64_t seq, int32_t votes,
85 uint32_t procs, const char *uname, const char *state, const char *version);
86
87 extern const char *member_uname(uint32_t id);
88 extern char *append_member(char *data, crm_node_t * node);
89 extern void member_loop_fn(gpointer key, gpointer value, gpointer user_data);
90
91 extern gboolean stop_child(crm_child_t * child, int signal);
92 extern gboolean spawn_child(crm_child_t * child);
93
94 extern void swap_sender(AIS_Message * msg);
95 extern char *get_ais_data(const AIS_Message * msg);
96
97 extern gboolean route_ais_message(const AIS_Message * msg, gboolean local);
98 extern gboolean process_ais_message(const AIS_Message * msg);
99
100 extern int send_plugin_msg(enum crm_ais_msg_types type, const char *host, const char *data);
101 extern int send_client_msg(void *conn, enum crm_ais_msg_class class,
102 enum crm_ais_msg_types type, const char *data);
103 extern void send_member_notification(void);
104 extern void log_ais_message(int level, const AIS_Message * msg);
105
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);
110 extern int get_config_opt(struct corosync_api_v1 *config,
111 hdb_handle_t object_service_handle,
112 char *key, char **value, const char *fallback);
113
114 extern int ais_get_boolean(const char *s);
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);
117 extern int send_client_ipc(void *conn, const AIS_Message * ais_msg);
118
119 extern GHashTable *membership_list;
120 extern pthread_t crm_wait_thread;
121 extern int plugin_log_level;
122 extern char *local_uname;
123 extern int local_uname_len;
124 extern unsigned int local_nodeid;
125
126 static inline const char *
127 level2char(int level)
128 {
129 switch (level) {
130 case LOG_CRIT:
131 return "CRIT";
132 case LOG_ERR:
133 return "ERROR";
134 case LOG_WARNING:
135 return "WARN";
136 case LOG_NOTICE:
137 return "notice";
138 case LOG_INFO:
139 return "info";
140 }
141 return "debug";
142 }
143
144 # define do_ais_log(level, fmt, args...) do { \
145 if(plugin_log_level < (level)) { \
146 continue; \
147 } else if((level) > LOG_DEBUG) { \
148 log_printf(LOG_DEBUG, "debug%d: %s: " fmt, \
149 level-LOG_INFO, __FUNCTION__ , ##args); \
150 } else { \
151 log_printf(level, "%s: %s: " fmt, level2char(level), \
152 __FUNCTION__ , ##args); \
153 } \
154 } while(0)
155
156 # define ais_perror(fmt, args...) log_printf( \
157 LOG_ERR, "%s: " fmt ": (%d) %s", \
158 __FUNCTION__ , ##args, errno, strerror(errno))
159
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)
167
168 # define ais_malloc0(malloc_obj, length) do { \
169 malloc_obj = malloc(length); \
170 if(malloc_obj == NULL) { \
171 abort(); \
172 } \
173 memset(malloc_obj, 0, length); \
174 } while(0)
175
176 # define ais_free(obj) do { \
177 if(obj) { \
178 free(obj); \
179 obj = NULL; \
180 } \
181 } while(0)
182
183 # define AIS_ASSERT(expr) if((expr) == FALSE) { \
184 ais_crit("Assertion failure line %d: %s", __LINE__, #expr); \
185 abort(); \
186 }
187
188 # define AIS_CHECK(expr, failure_action) if((expr) == FALSE) { \
189 int p = fork(); \
190 if(p == 0) { abort(); } \
191 ais_err("Child %d spawned to record non-fatal assertion failure line %d: %s", p, __LINE__, #expr); \
192 failure_action; \
193 }
194
195 static inline char *
196 ais_strdup(const char *src)
197 {
198 char *dup = NULL;
199
200 if (src == NULL) {
201 return NULL;
202 }
203 ais_malloc0(dup, strlen(src) + 1);
204 return strcpy(dup, src);
205 }
206
207 static inline gboolean
208 ais_str_eq(const char *a, const char *b)
209 {
210 if (a == NULL || b == NULL) {
211 return FALSE;
212
213 } else if (a == b) {
214 return TRUE;
215
216 } else if (strcasecmp(a, b) == 0) {
217 return TRUE;
218 }
219 return FALSE;
220 }
221
222 static inline int
223 libais_connection_active(void *conn)
224 {
225 if (conn != NULL) {
226 return TRUE;
227 }
228 return FALSE;
229 }
230
231 struct pcmk_env_s {
232 const char *debug;
233 const char *syslog;
234 const char *logfile;
235 const char *use_logd;
236 const char *quorum;
237 };
238
239 extern struct pcmk_env_s pcmk_env;
240 extern int pcmk_user_lookup(const char *name, uid_t * uid, gid_t * gid);
241
242 #endif