pacemaker  1.1.14-70404b0
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 /* crm_internal.h */
2 
3 /*
4  * Copyright (C) 2006 - 2008
5  * Andrew Beekhof <andrew@beekhof.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef CRM_INTERNAL__H
23 # define CRM_INTERNAL__H
24 
25 # include <config.h>
26 # include <portability.h>
27 
28 # include <glib.h>
29 # include <stdbool.h>
30 # include <libxml/tree.h>
31 
32 # include <crm/lrmd.h>
33 # include <crm/common/logging.h>
34 # include <crm/common/io.h>
35 # include <crm/common/ipcs.h>
36 # include <crm/common/procfs.h>
37 
38 /* Dynamic loading of libraries */
39 void *find_library_function(void **handle, const char *lib, const char *fn, int fatal);
40 void *convert_const_pointer(const void *ptr);
41 
42 /* For ACLs */
43 char *uid2username(uid_t uid);
44 void determine_request_user(const char *user, xmlNode * request, const char *field);
45 const char *crm_acl_get_set_user(xmlNode * request, const char *field, const char *peer_user);
46 
47 # if ENABLE_ACL
48 # include <string.h>
49 static inline gboolean
50 is_privileged(const char *user)
51 {
52  if (user == NULL) {
53  return FALSE;
54  } else if (strcmp(user, CRM_DAEMON_USER) == 0) {
55  return TRUE;
56  } else if (strcmp(user, "root") == 0) {
57  return TRUE;
58  }
59  return FALSE;
60 }
61 # endif
62 
63 /* CLI option processing*/
64 # ifdef HAVE_GETOPT_H
65 # include <getopt.h>
66 # else
67 # define no_argument 0
68 # define required_argument 1
69 # endif
70 
71 # define pcmk_option_default 0x00000
72 # define pcmk_option_hidden 0x00001
73 # define pcmk_option_paragraph 0x00002
74 # define pcmk_option_example 0x00004
75 
76 struct crm_option {
77  /* Fields from 'struct option' in getopt.h */
78  /* name of long option */
79  const char *name;
80  /*
81  * one of no_argument, required_argument, and optional_argument:
82  * whether option takes an argument
83  */
84  int has_arg;
85  /* if not NULL, set *flag to val when option found */
86  int *flag;
87  /* if flag not NULL, value to set *flag to; else return value */
88  int val;
89 
90  /* Custom fields */
91  const char *desc;
92  long flags;
93 };
94 
95 void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options,
96  const char *app_desc);
97 int crm_get_option(int argc, char **argv, int *index);
98 int crm_get_option_long(int argc, char **argv, int *index, const char **longname);
99 int crm_help(char cmd, int exit_code);
100 
101 /* Cluster Option Processing */
102 typedef struct pe_cluster_option_s {
103  const char *name;
104  const char *alt_name;
105  const char *type;
106  const char *values;
107  const char *default_value;
108 
109  gboolean(*is_valid) (const char *);
110 
111  const char *description_short;
112  const char *description_long;
113 
115 
116 const char *cluster_option(GHashTable * options, gboolean(*validate) (const char *),
117  const char *name, const char *old_name, const char *def_value);
118 
119 const char *get_cluster_pref(GHashTable * options, pe_cluster_option * option_list, int len,
120  const char *name);
121 
122 void config_metadata(const char *name, const char *version, const char *desc_short,
123  const char *desc_long, pe_cluster_option * option_list, int len);
124 
125 void verify_all_options(GHashTable * options, pe_cluster_option * option_list, int len);
126 gboolean check_time(const char *value);
127 gboolean check_timer(const char *value);
128 gboolean check_boolean(const char *value);
129 gboolean check_number(const char *value);
130 gboolean check_quorum(const char *value);
131 gboolean check_script(const char *value);
132 gboolean check_utilization(const char *value);
133 
134 /* Shared PE/crmd functionality */
135 void filter_action_parameters(xmlNode * param_set, const char *version);
136 
137 /* Resource operation updates */
138 xmlNode *create_operation_update(xmlNode * parent, lrmd_event_data_t * event,
139  const char * caller_version, int target_rc, const char * node,
140  const char * origin, int level);
141 
142 /* char2score */
143 extern int node_score_red;
144 extern int node_score_green;
145 extern int node_score_yellow;
146 extern int node_score_infinity;
147 
148 /* Assorted convenience functions */
149 static inline int
150 crm_strlen_zero(const char *s)
151 {
152  return !s || *s == '\0';
153 }
154 
155 char *add_list_element(char *list, const char *value);
156 
157 int crm_pid_active(long pid, const char *daemon);
158 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
159 
160 char *generate_op_key(const char *rsc_id, const char *op_type, int interval);
161 char *generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type);
162 char *generate_transition_magic_v202(const char *transition_key, int op_status);
163 char *generate_transition_magic(const char *transition_key, int op_status, int op_rc);
164 char *generate_transition_key(int action, int transition_id, int target_rc, const char *node);
165 
166 static inline long long
167 crm_clear_bit(const char *function, const char *target, long long word, long long bit)
168 {
169  long long rc = (word & ~bit);
170 
171  if (rc == word) {
172  /* Unchanged */
173  } else if (target) {
174  crm_trace("Bit 0x%.8llx for %s cleared by %s", bit, target, function);
175  } else {
176  crm_trace("Bit 0x%.8llx cleared by %s", bit, function);
177  }
178 
179  return rc;
180 }
181 
182 static inline long long
183 crm_set_bit(const char *function, const char *target, long long word, long long bit)
184 {
185  long long rc = (word | bit);
186 
187  if (rc == word) {
188  /* Unchanged */
189  } else if (target) {
190  crm_trace("Bit 0x%.8llx for %s set by %s", bit, target, function);
191  } else {
192  crm_trace("Bit 0x%.8llx set by %s", bit, function);
193  }
194 
195  return rc;
196 }
197 
198 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, NULL, word, bit)
199 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, NULL, word, bit)
200 
201 void g_hash_destroy_str(gpointer data);
202 
203 long long crm_int_helper(const char *text, char **end_text);
204 char *crm_concat(const char *prefix, const char *suffix, char join);
205 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
206 
207 bool crm_compress_string(const char *data, int length, int max, char **result,
208  unsigned int *result_len);
209 
211 typedef struct crm_remote_s crm_remote_t;
212 
213 int crm_remote_send(crm_remote_t * remote, xmlNode * msg);
214 int crm_remote_ready(crm_remote_t * remote, int total_timeout /*ms */ );
215 gboolean crm_remote_recv(crm_remote_t * remote, int total_timeout /*ms */ , int *disconnected);
216 xmlNode *crm_remote_parse_buffer(crm_remote_t * remote);
217 int crm_remote_tcp_connect(const char *host, int port);
218 int crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
219  int *timer_id, void *userdata, void (*callback) (void *userdata, int sock));
220 
221 # ifdef HAVE_GNUTLS_GNUTLS_H
222 
230 int crm_initiate_client_tls_handshake(crm_remote_t * remote, int timeout_ms);
231 
242 void *crm_create_anon_tls_session(int sock, int type, void *credentials);
243 
254 void *create_psk_tls_session(int csock, int type, void *credentials);
255 # endif
256 
257 # define REMOTE_MSG_TERMINATOR "\r\n\r\n"
258 
259 const char *daemon_option(const char *option);
260 void set_daemon_option(const char *option, const char *value);
261 gboolean daemon_option_enabled(const char *daemon, const char *option);
262 void strip_text_nodes(xmlNode * xml);
263 void pcmk_panic(const char *origin);
264 void sysrq_init(void);
265 pid_t pcmk_locate_sbd(void);
266 int crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
267 int crm_read_pidfile(const char *filename);
268 
269 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
270 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
271 
272 # define attrd_channel T_ATTRD
273 # define F_ATTRD_KEY "attr_key"
274 # define F_ATTRD_ATTRIBUTE "attr_name"
275 # define F_ATTRD_REGEX "attr_regex"
276 # define F_ATTRD_TASK "task"
277 # define F_ATTRD_VALUE "attr_value"
278 # define F_ATTRD_SET "attr_set"
279 # define F_ATTRD_IS_REMOTE "attr_is_remote"
280 # define F_ATTRD_IS_PRIVATE "attr_is_private"
281 # define F_ATTRD_SECTION "attr_section"
282 # define F_ATTRD_DAMPEN "attr_dampening"
283 # define F_ATTRD_IGNORE_LOCALLY "attr_ignore_locally"
284 # define F_ATTRD_HOST "attr_host"
285 # define F_ATTRD_HOST_ID "attr_host_id"
286 # define F_ATTRD_USER "attr_user"
287 # define F_ATTRD_WRITER "attr_writer"
288 # define F_ATTRD_VERSION "attr_version"
289 
290 /* attrd operations */
291 # define ATTRD_OP_PEER_REMOVE "peer-remove"
292 # define ATTRD_OP_UPDATE "update"
293 # define ATTRD_OP_QUERY "query"
294 # define ATTRD_OP_REFRESH "refresh"
295 # define ATTRD_OP_FLUSH "flush"
296 # define ATTRD_OP_SYNC "sync"
297 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
298 
299 # if SUPPORT_COROSYNC
300 # if CS_USES_LIBQB
301 # include <qb/qbipc_common.h>
302 # include <corosync/corotypes.h>
303 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
304 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
305 # else
306 # include <corosync/corodefs.h>
307 # include <corosync/coroipcc.h>
308 # include <corosync/coroipc_types.h>
309 static inline int
310 qb_to_cs_error(int a)
311 {
312  return a;
313 }
314 
315 typedef coroipc_request_header_t cs_ipc_header_request_t;
316 typedef coroipc_response_header_t cs_ipc_header_response_t;
317 # endif
318 # else
319 typedef struct {
320  int size __attribute__ ((aligned(8)));
321  int id __attribute__ ((aligned(8)));
322 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
323 
324 typedef struct {
325  int size __attribute__ ((aligned(8)));
326  int id __attribute__ ((aligned(8)));
327  int error __attribute__ ((aligned(8)));
328 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
329 
330 # endif
331 
332 void
333 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
334 void
335 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
336 
337 qb_ipcs_service_t *
338 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
339 
340 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
341  qb_ipcs_service_t **ipcs_rw,
342  qb_ipcs_service_t **ipcs_shm,
343  struct qb_ipcs_service_handlers *ro_cb,
344  struct qb_ipcs_service_handlers *rw_cb);
345 
346 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
347  qb_ipcs_service_t *ipcs_rw,
348  qb_ipcs_service_t *ipcs_shm);
349 
350 static inline void *realloc_safe(void *ptr, size_t size)
351 {
352  void *ret = realloc(ptr, size);
353 
354  if(ret == NULL) {
355  abort();
356  }
357 
358  return ret;
359 }
360 
361 const char *crm_xml_add_last_written(xmlNode *xml_node);
362 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
363 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
364 
365 gboolean crm_digest_verify(xmlNode *input, const char *expected);
366 
367 /* cross-platform compatibility functions */
368 char *crm_compat_realpath(const char *path);
369 
370 /* IPC Proxy Backend Shared Functions */
371 typedef struct remote_proxy_s {
372  char *node_name;
373  char *session_id;
374 
375  gboolean is_local;
376 
380 
382 void remote_proxy_notify_destroy(lrmd_t *lrmd, const char *session_id);
383 void remote_proxy_relay_event(lrmd_t *lrmd, const char *session_id, xmlNode *msg);
384 void remote_proxy_relay_response(lrmd_t *lrmd, const char *session_id, xmlNode *msg, int msg_id);
385 void remote_proxy_end_session(const char *session);
386 void remote_proxy_free(gpointer data);
387 
388 #endif /* CRM_INTERNAL__H */
gboolean daemon_option_enabled(const char *daemon, const char *option)
Definition: logging.c:165
char * generate_transition_magic(const char *transition_key, int op_status, int op_rc)
Definition: utils.c:931
gboolean(* is_valid)(const char *)
Definition: crm_internal.h:109
void remote_proxy_relay_response(lrmd_t *lrmd, const char *session_id, xmlNode *msg, int msg_id)
Definition: proxy_common.c:62
char * crm_compat_realpath(const char *path)
Definition: compat.c:40
void * find_library_function(void **handle, const char *lib, const char *fn, int fatal)
void remote_proxy_end_session(const char *session)
Definition: proxy_common.c:75
void remote_proxy_notify_destroy(lrmd_t *lrmd, const char *session_id)
Definition: proxy_common.c:38
int crm_pid_active(long pid, const char *daemon)
Definition: utils.c:1188
int crm_remote_ready(crm_remote_t *remote, int total_timeout)
Definition: remote.c:447
gboolean crm_remote_recv(crm_remote_t *remote, int total_timeout, int *disconnected)
Definition: remote.c:599
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:3961
struct pe_cluster_option_s pe_cluster_option
uint32_t size
Definition: internal.h:52
uint32_t last_request_id
Definition: crm_internal.h:379
internal procfs utilities
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:1352
char * generate_transition_magic_v202(const char *transition_key, int op_status)
Definition: utils.c:914
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:35
int crm_help(char cmd, int exit_code)
Definition: utils.c:1612
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1732
Local Resource Manager.
char * add_list_element(char *list, const char *value)
Definition: utils.c:2284
gboolean crm_digest_verify(xmlNode *input, const char *expected)
Return whether calculated digest of XML tree matches expected digest.
Definition: digest.c:221
AIS_Host host
Definition: internal.h:52
void g_hash_destroy_str(gpointer data)
Definition: utils.c:587
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: utils.c:892
void remote_proxy_relay_event(lrmd_t *lrmd, const char *session_id, xmlNode *msg)
Definition: proxy_common.c:49
uint32_t pid
Definition: internal.h:49
void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options, const char *app_desc)
Definition: utils.c:1520
gboolean check_number(const char *value)
Definition: utils.c:144
void filter_action_parameters(xmlNode *param_set, const char *version)
Definition: utils.c:1057
const char * name
Definition: crm_internal.h:103
internal I/O utilities
int crm_remote_tcp_connect(const char *host, int port)
Definition: remote.c:919
int crm_read_pidfile(const char *filename)
Definition: utils.c:1247
void * convert_const_pointer(const void *ptr)
Definition: utils.c:2303
Wrappers for and extensions to libqb logging.
char version[256]
Definition: plugin.c:84
void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro, qb_ipcs_service_t **ipcs_rw, qb_ipcs_service_t **ipcs_shm, struct qb_ipcs_service_handlers *ro_cb, struct qb_ipcs_service_handlers *rw_cb)
Definition: utils.c:1687
const char * type
Definition: crm_internal.h:105
char * generate_transition_key(int action, int transition_id, int target_rc, const char *node)
Definition: utils.c:974
void config_metadata(const char *name, const char *version, const char *desc_short, const char *desc_long, pe_cluster_option *option_list, int len)
Definition: utils.c:355
op_status
Definition: services.h:120
int daemon(int nochdir, int noclose)
const char * default_value
Definition: crm_internal.h:107
void determine_request_user(const char *user, xmlNode *request, const char *field)
int crm_initiate_client_tls_handshake(crm_remote_t *remote, int timeout_ms)
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:61
int crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
Definition: utils.c:1275
xmlNode * crm_remote_parse_buffer(crm_remote_t *remote)
Definition: remote.c:377
gboolean check_quorum(const char *value)
Definition: utils.c:165
#define crm_trace(fmt, args...)
Definition: logging.h:254
const char * values
Definition: crm_internal.h:106
enum crm_proc_flag __attribute__
void pcmk_panic(const char *origin)
Definition: watchdog.c:184
void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro, qb_ipcs_service_t *ipcs_rw, qb_ipcs_service_t *ipcs_shm)
Definition: utils.c:1704
const char * desc
Definition: crm_internal.h:91
gboolean check_time(const char *value)
Definition: utils.c:115
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:304
#define CRM_DAEMON_USER
Definition: config.h:47
gboolean check_boolean(const char *value)
Definition: utils.c:133
int crm_remote_tcp_connect_async(const char *host, int port, int timeout, int *timer_id, void *userdata, void(*callback)(void *userdata, int sock))
Definition: remote.c:830
const char * description_long
Definition: crm_internal.h:112
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
Definition: utils.c:1567
int * flag
Definition: crm_internal.h:86
crm_ipc_t * ipc
Definition: crm_internal.h:377
struct remote_proxy_s remote_proxy_t
const char * daemon_option(const char *option)
Definition: logging.c:117
void attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1720
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1714
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
Definition: utils.c:289
const char * description_short
Definition: crm_internal.h:111
bool crm_compress_string(const char *data, int length, int max, char **result, unsigned int *result_len)
Definition: utils.c:2358
gboolean check_script(const char *value)
Definition: utils.c:183
void remote_proxy_free(gpointer data)
Definition: proxy_common.c:90
void set_daemon_option(const char *option, const char *value)
Definition: logging.c:141
gboolean check_utilization(const char *value)
Definition: utils.c:210
int node_score_infinity
Definition: utils.c:79
mainloop_io_t * source
Definition: crm_internal.h:378
int node_score_red
Definition: utils.c:76
xmlNode * create_operation_update(xmlNode *parent, lrmd_event_data_t *event, const char *caller_version, int target_rc, const char *node, const char *origin, int level)
Definition: utils.c:1936
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:58
void * create_psk_tls_session(int csock, int type, void *credentials)
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
Definition: utils.c:390
Definition: lrmd.h:439
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:3112
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:421
const char * crm_acl_get_set_user(xmlNode *request, const char *field, const char *peer_user)
pid_t pcmk_locate_sbd(void)
Definition: watchdog.c:214
gboolean check_timer(const char *value)
Definition: utils.c:124
int crm_get_option(int argc, char **argv, int *index)
Definition: utils.c:1561
char * crm_concat(const char *prefix, const char *suffix, char join)
Definition: utils.c:403
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Definition: utils.c:803
void * crm_create_anon_tls_session(int sock, int type, void *credentials)
int node_score_green
Definition: utils.c:77
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:335
gboolean is_local
Definition: crm_internal.h:375
const char * alt_name
Definition: crm_internal.h:104
int crm_remote_send(crm_remote_t *remote, xmlNode *msg)
Definition: remote.c:329
int node_score_yellow
Definition: utils.c:78
long long crm_int_helper(const char *text, char **end_text)
Definition: utils.c:597
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:3213
char * uid2username(uid_t uid)
const char * name
Definition: crm_internal.h:79
void sysrq_init(void)
Definition: watchdog.c:49
enum crm_ais_msg_types type
Definition: internal.h:51
struct qb_ipc_request_header cs_ipc_header_request_t
Definition: crm_internal.h:303
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3858