pacemaker  1.1.17-b36b869ca8
Scalable High-Availability cluster resource manager
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 Lesser 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 Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser 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/ipcs.h>
35 # include <crm/common/internal.h>
36 
37 /* Dynamic loading of libraries */
38 void *find_library_function(void **handle, const char *lib, const char *fn, int fatal);
39 void *convert_const_pointer(const void *ptr);
40 
41 /* For ACLs */
42 char *uid2username(uid_t uid);
43 void determine_request_user(const char *user, xmlNode * request, const char *field);
44 const char *crm_acl_get_set_user(xmlNode * request, const char *field, const char *peer_user);
45 
46 # if ENABLE_ACL
47 # include <string.h>
48 static inline gboolean
49 is_privileged(const char *user)
50 {
51  if (user == NULL) {
52  return FALSE;
53  } else if (strcmp(user, CRM_DAEMON_USER) == 0) {
54  return TRUE;
55  } else if (strcmp(user, "root") == 0) {
56  return TRUE;
57  }
58  return FALSE;
59 }
60 # endif
61 
62 /* CLI option processing*/
63 # ifdef HAVE_GETOPT_H
64 # include <getopt.h>
65 # else
66 # define no_argument 0
67 # define required_argument 1
68 # endif
69 
70 # define pcmk_option_default 0x00000
71 # define pcmk_option_hidden 0x00001
72 # define pcmk_option_paragraph 0x00002
73 # define pcmk_option_example 0x00004
74 
75 struct crm_option {
76  /* Fields from 'struct option' in getopt.h */
77  /* name of long option */
78  const char *name;
79  /*
80  * one of no_argument, required_argument, and optional_argument:
81  * whether option takes an argument
82  */
83  int has_arg;
84  /* if not NULL, set *flag to val when option found */
85  int *flag;
86  /* if flag not NULL, value to set *flag to; else return value */
87  int val;
88 
89  /* Custom fields */
90  const char *desc;
91  long flags;
92 };
93 
94 void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options,
95  const char *app_desc);
96 int crm_get_option(int argc, char **argv, int *index);
97 int crm_get_option_long(int argc, char **argv, int *index, const char **longname);
98 int crm_help(char cmd, int exit_code);
99 
100 /* Cluster Option Processing */
101 typedef struct pe_cluster_option_s {
102  const char *name;
103  const char *alt_name;
104  const char *type;
105  const char *values;
106  const char *default_value;
107 
108  gboolean(*is_valid) (const char *);
109 
110  const char *description_short;
111  const char *description_long;
112 
114 
115 const char *cluster_option(GHashTable * options, gboolean(*validate) (const char *),
116  const char *name, const char *old_name, const char *def_value);
117 
118 const char *get_cluster_pref(GHashTable * options, pe_cluster_option * option_list, int len,
119  const char *name);
120 
121 void config_metadata(const char *name, const char *version, const char *desc_short,
122  const char *desc_long, pe_cluster_option * option_list, int len);
123 
124 void verify_all_options(GHashTable * options, pe_cluster_option * option_list, int len);
125 gboolean check_time(const char *value);
126 gboolean check_timer(const char *value);
127 gboolean check_boolean(const char *value);
128 gboolean check_number(const char *value);
129 gboolean check_positive_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 long crm_get_sbd_timeout(void);
134 gboolean check_sbd_timeout(const char *value);
135 
136 /* Shared PE/crmd functionality */
137 void filter_action_parameters(xmlNode * param_set, const char *version);
138 
139 /* Resource operation updates */
140 xmlNode *create_operation_update(xmlNode * parent, lrmd_event_data_t * event,
141  const char * caller_version, int target_rc, const char * node,
142  const char * origin, int level);
143 
144 /* char2score */
145 extern int node_score_red;
146 extern int node_score_green;
147 extern int node_score_yellow;
148 extern int node_score_infinity;
149 
150 /* Assorted convenience functions */
151 int crm_pid_active(long pid, const char *daemon);
152 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
153 
154 char *generate_op_key(const char *rsc_id, const char *op_type, int interval);
155 char *generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type);
156 char *generate_transition_magic_v202(const char *transition_key, int op_status);
157 char *generate_transition_magic(const char *transition_key, int op_status, int op_rc);
158 char *generate_transition_key(int action, int transition_id, int target_rc, const char *node);
159 
160 static inline long long
161 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
162 {
163  long long rc = (word & ~bit);
164 
165  if (rc == word) {
166  /* Unchanged */
167  } else if (target) {
168  crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
169  } else {
170  crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
171  }
172 
173  return rc;
174 }
175 
176 static inline long long
177 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
178 {
179  long long rc = (word | bit);
180 
181  if (rc == word) {
182  /* Unchanged */
183  } else if (target) {
184  crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
185  } else {
186  crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
187  }
188 
189  return rc;
190 }
191 
192 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
193 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
194 
195 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
196 
198 typedef struct crm_remote_s crm_remote_t;
199 
200 int crm_remote_send(crm_remote_t * remote, xmlNode * msg);
201 int crm_remote_ready(crm_remote_t * remote, int total_timeout /*ms */ );
202 gboolean crm_remote_recv(crm_remote_t * remote, int total_timeout /*ms */ , int *disconnected);
203 xmlNode *crm_remote_parse_buffer(crm_remote_t * remote);
204 int crm_remote_tcp_connect(const char *host, int port);
205 int crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
206  int *timer_id, void *userdata, void (*callback) (void *userdata, int sock));
207 int crm_remote_accept(int ssock);
208 void crm_sockaddr2str(void *sa, char *s);
209 
210 # ifdef HAVE_GNUTLS_GNUTLS_H
211 
219 int crm_initiate_client_tls_handshake(crm_remote_t * remote, int timeout_ms);
220 
231 void *crm_create_anon_tls_session(int sock, int type, void *credentials);
232 
243 void *create_psk_tls_session(int csock, int type, void *credentials);
244 # endif
245 
246 # define REMOTE_MSG_TERMINATOR "\r\n\r\n"
247 
248 const char *daemon_option(const char *option);
249 void set_daemon_option(const char *option, const char *value);
250 gboolean daemon_option_enabled(const char *daemon, const char *option);
251 void strip_text_nodes(xmlNode * xml);
252 void pcmk_panic(const char *origin);
253 void sysrq_init(void);
254 pid_t pcmk_locate_sbd(void);
255 long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
256 long crm_read_pidfile(const char *filename);
257 
258 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
259 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
260 
261 # define attrd_channel T_ATTRD
262 # define F_ATTRD_KEY "attr_key"
263 # define F_ATTRD_ATTRIBUTE "attr_name"
264 # define F_ATTRD_REGEX "attr_regex"
265 # define F_ATTRD_TASK "task"
266 # define F_ATTRD_VALUE "attr_value"
267 # define F_ATTRD_SET "attr_set"
268 # define F_ATTRD_IS_REMOTE "attr_is_remote"
269 # define F_ATTRD_IS_PRIVATE "attr_is_private"
270 # define F_ATTRD_SECTION "attr_section"
271 # define F_ATTRD_DAMPEN "attr_dampening"
272 # define F_ATTRD_IGNORE_LOCALLY "attr_ignore_locally"
273 # define F_ATTRD_HOST "attr_host"
274 # define F_ATTRD_HOST_ID "attr_host_id"
275 # define F_ATTRD_USER "attr_user"
276 # define F_ATTRD_WRITER "attr_writer"
277 # define F_ATTRD_VERSION "attr_version"
278 # define F_ATTRD_RESOURCE "attr_resource"
279 # define F_ATTRD_OPERATION "attr_clear_operation"
280 # define F_ATTRD_INTERVAL "attr_clear_interval"
281 
282 /* attrd operations */
283 # define ATTRD_OP_PEER_REMOVE "peer-remove"
284 # define ATTRD_OP_UPDATE "update"
285 # define ATTRD_OP_UPDATE_BOTH "update-both"
286 # define ATTRD_OP_UPDATE_DELAY "update-delay"
287 # define ATTRD_OP_QUERY "query"
288 # define ATTRD_OP_REFRESH "refresh"
289 # define ATTRD_OP_FLUSH "flush"
290 # define ATTRD_OP_SYNC "sync"
291 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
292 # define ATTRD_OP_CLEAR_FAILURE "clear-failure"
293 
294 # if SUPPORT_COROSYNC
295 # if CS_USES_LIBQB
296 # include <qb/qbipc_common.h>
297 # include <corosync/corotypes.h>
298 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
299 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
300 # else
301 # include <corosync/corodefs.h>
302 # include <corosync/coroipcc.h>
303 # include <corosync/coroipc_types.h>
304 typedef coroipc_request_header_t cs_ipc_header_request_t;
305 typedef coroipc_response_header_t cs_ipc_header_response_t;
306 # endif
307 # else
308 typedef struct {
309  int size __attribute__ ((aligned(8)));
310  int id __attribute__ ((aligned(8)));
311 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
312 
313 typedef struct {
314  int size __attribute__ ((aligned(8)));
315  int id __attribute__ ((aligned(8)));
316  int error __attribute__ ((aligned(8)));
317 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
318 
319 # endif
320 
321 void
322 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
323 void
324 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
325 
326 qb_ipcs_service_t *
327 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
328 
329 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
330  qb_ipcs_service_t **ipcs_rw,
331  qb_ipcs_service_t **ipcs_shm,
332  struct qb_ipcs_service_handlers *ro_cb,
333  struct qb_ipcs_service_handlers *rw_cb);
334 
335 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
336  qb_ipcs_service_t *ipcs_rw,
337  qb_ipcs_service_t *ipcs_shm);
338 
339 static inline void *realloc_safe(void *ptr, size_t size)
340 {
341  void *ret = realloc(ptr, size);
342 
343  if (ret == NULL) {
344  free(ptr); /* make coverity happy */
345  abort();
346  }
347 
348  return ret;
349 }
350 
351 const char *crm_xml_add_last_written(xmlNode *xml_node);
352 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
353 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
354 
355 gboolean crm_digest_verify(xmlNode *input, const char *expected);
356 
357 /* cross-platform compatibility functions */
358 char *crm_compat_realpath(const char *path);
359 
360 /* IPC Proxy Backend Shared Functions */
361 typedef struct remote_proxy_s {
362  char *node_name;
363  char *session_id;
364 
365  gboolean is_local;
366 
371 
373 
375  lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks,
376  const char *node_name, const char *session_id, const char *channel);
377 
378 int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash);
379 void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg);
382 
383 int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata);
384 void remote_proxy_disconnected(gpointer data);
385 void remote_proxy_free(gpointer data);
386 
387 void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg);
388 void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id);
389 
390 
391 #ifdef ENABLE_VERSIONED_ATTRS
392 char* crm_versioned_param_summary(xmlNode *versioned_params, const char *name);
393 void crm_summarize_versioned_params(xmlNode *param_set, xmlNode *versioned_params);
394 #endif
395 #endif /* CRM_INTERNAL__H */
void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id)
Definition: proxy_common.c:91
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:772
int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata)
Definition: proxy_common.c:128
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)
int crm_pid_active(long pid, const char *daemon)
Definition: utils.c:1032
int crm_remote_ready(crm_remote_t *remote, int total_timeout)
Definition: remote.c:451
gboolean crm_remote_recv(crm_remote_t *remote, int total_timeout, int *disconnected)
Definition: remote.c:613
long crm_get_sbd_timeout(void)
Definition: watchdog.c:246
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:3823
gboolean check_sbd_timeout(const char *value)
Definition: watchdog.c:255
long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
Definition: utils.c:1132
struct pe_cluster_option_s pe_cluster_option
uint32_t size
Definition: internal.h:52
uint32_t last_request_id
Definition: crm_internal.h:369
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:1194
char * generate_transition_magic_v202(const char *transition_key, int op_status)
Definition: utils.c:755
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:35
int crm_help(char cmd, int exit_code)
Definition: utils.c:1418
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1538
void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg)
Definition: proxy_common.c:78
void remote_proxy_ack_shutdown(lrmd_t *lrmd)
Send an acknowledgment of a remote proxy shutdown request.
Definition: proxy_common.c:54
Local Resource Manager.
gboolean crm_digest_verify(xmlNode *input, const char *expected)
Definition: digest.c:222
AIS_Host host
Definition: internal.h:52
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: utils.c:733
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:1326
gboolean check_number(const char *value)
Definition: utils.c:143
int crm_remote_accept(int ssock)
Definition: remote.c:964
void filter_action_parameters(xmlNode *param_set, const char *version)
Definition: utils.c:898
const char * name
Definition: crm_internal.h:102
int crm_remote_tcp_connect(const char *host, int port)
Definition: remote.c:929
void * convert_const_pointer(const void *ptr)
Definition: utils.c:1941
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:1493
void crm_sockaddr2str(void *sa, char *s)
Convert an IP address (IPv4 or IPv6) to a string for logging.
Definition: remote.c:945
const char * type
Definition: crm_internal.h:104
char * generate_transition_key(int action, int transition_id, int target_rc, const char *node)
Definition: utils.c:815
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:363
op_status
Definition: services.h:130
int daemon(int nochdir, int noclose)
const char * default_value
Definition: crm_internal.h:106
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 remote_proxy_check(lrmd_t *lrmd, GHashTable *hash)
Definition: lrmd_client.c:899
void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg)
Definition: proxy_common.c:215
remote_proxy_t * remote_proxy_new(lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks, const char *node_name, const char *session_id, const char *channel)
Definition: proxy_common.c:175
xmlNode * crm_remote_parse_buffer(crm_remote_t *remote)
Definition: remote.c:380
gboolean check_quorum(const char *value)
Definition: utils.c:173
#define crm_trace(fmt, args...)
Definition: logging.h:254
const char * values
Definition: crm_internal.h:105
enum crm_proc_flag __attribute__
void pcmk_panic(const char *origin)
Definition: watchdog.c:177
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:1510
gboolean check_positive_number(const char *value)
Definition: utils.c:164
const char * desc
Definition: crm_internal.h:90
gboolean check_time(const char *value)
Definition: utils.c:114
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:299
#define CRM_DAEMON_USER
Definition: config.h:47
gboolean check_boolean(const char *value)
Definition: utils.c:132
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:844
const char * description_long
Definition: crm_internal.h:111
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
Definition: utils.c:1373
int * flag
Definition: crm_internal.h:85
void remote_proxy_disconnected(gpointer data)
Definition: proxy_common.c:157
crm_ipc_t * ipc
Definition: crm_internal.h:367
struct remote_proxy_s remote_proxy_t
void remote_proxy_nack_shutdown(lrmd_t *lrmd)
We&#39;re not gonna shutdown as response to a remote proxy shutdown request.
Definition: proxy_common.c:69
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:1526
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1520
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
Definition: utils.c:297
const char * description_short
Definition: crm_internal.h:110
gboolean check_script(const char *value)
Definition: utils.c:191
void remote_proxy_free(gpointer data)
Definition: proxy_common.c:117
void set_daemon_option(const char *option, const char *value)
Definition: logging.c:141
gboolean check_utilization(const char *value)
Definition: utils.c:218
int node_score_infinity
Definition: utils.c:78
mainloop_io_t * source
Definition: crm_internal.h:368
int node_score_red
Definition: utils.c:75
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:1629
#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:398
long crm_read_pidfile(const char *filename)
Definition: utils.c:1095
Definition: lrmd.h:459
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2929
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:411
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:208
gboolean check_timer(const char *value)
Definition: utils.c:123
int crm_get_option(int argc, char **argv, int *index)
Definition: utils.c:1367
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Generate an operation key.
Definition: utils.c:652
void * crm_create_anon_tls_session(int sock, int type, void *credentials)
int node_score_green
Definition: utils.c:76
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:343
gboolean is_local
Definition: crm_internal.h:365
const char * alt_name
Definition: crm_internal.h:103
int crm_remote_send(crm_remote_t *remote, xmlNode *msg)
Definition: remote.c:332
int node_score_yellow
Definition: utils.c:77
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:3030
char * uid2username(uid_t uid)
const char * name
Definition: crm_internal.h:78
void sysrq_init(void)
Definition: watchdog.c:38
enum crm_ais_msg_types type
Definition: internal.h:51
struct qb_ipc_request_header cs_ipc_header_request_t
Definition: crm_internal.h:298
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3720