pacemaker  1.1.18-7fdfbbe
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 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 /* char2score */
137 extern int node_score_red;
138 extern int node_score_green;
139 extern int node_score_yellow;
140 extern int node_score_infinity;
141 
142 /* Assorted convenience functions */
143 int crm_pid_active(long pid, const char *daemon);
144 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
145 
146 /* from operations.c */
147 char *generate_op_key(const char *rsc_id, const char *op_type, int interval);
148 char *generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type);
149 char *generate_transition_magic_v202(const char *transition_key, int op_status);
150 char *generate_transition_magic(const char *transition_key, int op_status, int op_rc);
151 char *generate_transition_key(int action, int transition_id, int target_rc, const char *node);
152 void filter_action_parameters(xmlNode *param_set, const char *version);
153 xmlNode *create_operation_update(xmlNode *parent, lrmd_event_data_t *event,
154  const char *caller_version, int target_rc,
155  const char *node, const char *origin,
156  int level);
157 
158 static inline long long
159 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
160 {
161  long long rc = (word & ~bit);
162 
163  if (rc == word) {
164  /* Unchanged */
165  } else if (target) {
166  crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
167  } else {
168  crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
169  }
170 
171  return rc;
172 }
173 
174 static inline long long
175 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
176 {
177  long long rc = (word | bit);
178 
179  if (rc == word) {
180  /* Unchanged */
181  } else if (target) {
182  crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
183  } else {
184  crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
185  }
186 
187  return rc;
188 }
189 
190 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
191 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
192 
193 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
194 
196 typedef struct crm_remote_s crm_remote_t;
197 
198 int crm_remote_send(crm_remote_t * remote, xmlNode * msg);
199 int crm_remote_ready(crm_remote_t * remote, int total_timeout /*ms */ );
200 gboolean crm_remote_recv(crm_remote_t * remote, int total_timeout /*ms */ , int *disconnected);
201 xmlNode *crm_remote_parse_buffer(crm_remote_t * remote);
202 int crm_remote_tcp_connect(const char *host, int port);
203 int crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
204  int *timer_id, void *userdata, void (*callback) (void *userdata, int sock));
205 int crm_remote_accept(int ssock);
206 void crm_sockaddr2str(void *sa, char *s);
207 
208 # ifdef HAVE_GNUTLS_GNUTLS_H
209 
217 int crm_initiate_client_tls_handshake(crm_remote_t * remote, int timeout_ms);
218 
229 void *crm_create_anon_tls_session(int sock, int type, void *credentials);
230 
241 void *create_psk_tls_session(int csock, int type, void *credentials);
242 # endif
243 
244 # define REMOTE_MSG_TERMINATOR "\r\n\r\n"
245 
246 const char *daemon_option(const char *option);
247 void set_daemon_option(const char *option, const char *value);
248 gboolean daemon_option_enabled(const char *daemon, const char *option);
249 void strip_text_nodes(xmlNode * xml);
250 void pcmk_panic(const char *origin);
251 void sysrq_init(void);
252 pid_t pcmk_locate_sbd(void);
253 long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
254 long crm_read_pidfile(const char *filename);
255 
256 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
257 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
258 
259 # define attrd_channel T_ATTRD
260 # define F_ATTRD_KEY "attr_key"
261 # define F_ATTRD_ATTRIBUTE "attr_name"
262 # define F_ATTRD_REGEX "attr_regex"
263 # define F_ATTRD_TASK "task"
264 # define F_ATTRD_VALUE "attr_value"
265 # define F_ATTRD_SET "attr_set"
266 # define F_ATTRD_IS_REMOTE "attr_is_remote"
267 # define F_ATTRD_IS_PRIVATE "attr_is_private"
268 # define F_ATTRD_SECTION "attr_section"
269 # define F_ATTRD_DAMPEN "attr_dampening"
270 # define F_ATTRD_IGNORE_LOCALLY "attr_ignore_locally"
271 # define F_ATTRD_HOST "attr_host"
272 # define F_ATTRD_HOST_ID "attr_host_id"
273 # define F_ATTRD_USER "attr_user"
274 # define F_ATTRD_WRITER "attr_writer"
275 # define F_ATTRD_VERSION "attr_version"
276 # define F_ATTRD_RESOURCE "attr_resource"
277 # define F_ATTRD_OPERATION "attr_clear_operation"
278 # define F_ATTRD_INTERVAL "attr_clear_interval"
279 
280 /* attrd operations */
281 # define ATTRD_OP_PEER_REMOVE "peer-remove"
282 # define ATTRD_OP_UPDATE "update"
283 # define ATTRD_OP_UPDATE_BOTH "update-both"
284 # define ATTRD_OP_UPDATE_DELAY "update-delay"
285 # define ATTRD_OP_QUERY "query"
286 # define ATTRD_OP_REFRESH "refresh"
287 # define ATTRD_OP_FLUSH "flush"
288 # define ATTRD_OP_SYNC "sync"
289 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
290 # define ATTRD_OP_CLEAR_FAILURE "clear-failure"
291 
292 # define PCMK_ENV_PHYSICAL_HOST "physical_host"
293 
294 
295 # if SUPPORT_COROSYNC
296 # if CS_USES_LIBQB
297 # include <qb/qbipc_common.h>
298 # include <corosync/corotypes.h>
299 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
300 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
301 # else
302 # include <corosync/corodefs.h>
303 # include <corosync/coroipcc.h>
304 # include <corosync/coroipc_types.h>
305 typedef coroipc_request_header_t cs_ipc_header_request_t;
306 typedef coroipc_response_header_t cs_ipc_header_response_t;
307 # endif
308 # else
309 typedef struct {
310  int size __attribute__ ((aligned(8)));
311  int id __attribute__ ((aligned(8)));
312 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
313 
314 typedef struct {
315  int size __attribute__ ((aligned(8)));
316  int id __attribute__ ((aligned(8)));
317  int error __attribute__ ((aligned(8)));
318 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
319 
320 # endif
321 
322 void
323 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
324 void
325 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
326 
327 qb_ipcs_service_t *
328 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
329 
330 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
331  qb_ipcs_service_t **ipcs_rw,
332  qb_ipcs_service_t **ipcs_shm,
333  struct qb_ipcs_service_handlers *ro_cb,
334  struct qb_ipcs_service_handlers *rw_cb);
335 
336 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
337  qb_ipcs_service_t *ipcs_rw,
338  qb_ipcs_service_t *ipcs_shm);
339 
340 static inline void *realloc_safe(void *ptr, size_t size)
341 {
342  void *ret = realloc(ptr, size);
343 
344  if (ret == NULL) {
345  free(ptr); /* make coverity happy */
346  abort();
347  }
348 
349  return ret;
350 }
351 
352 const char *crm_xml_add_last_written(xmlNode *xml_node);
353 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
354 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
355 
356 gboolean crm_digest_verify(xmlNode *input, const char *expected);
357 
358 /* cross-platform compatibility functions */
359 char *crm_compat_realpath(const char *path);
360 
361 /* IPC Proxy Backend Shared Functions */
362 typedef struct remote_proxy_s {
363  char *node_name;
364  char *session_id;
365 
366  gboolean is_local;
367 
372 
374 
376  lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks,
377  const char *node_name, const char *session_id, const char *channel);
378 
379 int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash);
380 void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg);
383 
384 int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata);
385 void remote_proxy_disconnected(gpointer data);
386 void remote_proxy_free(gpointer data);
387 
388 void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg);
389 void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id);
390 
391 #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: operations.c:157
int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata)
Definition: proxy_common.c:128
gboolean(* is_valid)(const char *)
Definition: crm_internal.h:108
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:718
int crm_remote_ready(crm_remote_t *remote, int total_timeout)
Definition: remote.c:455
gboolean crm_remote_recv(crm_remote_t *remote, int total_timeout, int *disconnected)
Definition: remote.c:617
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:3799
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:818
struct pe_cluster_option_s pe_cluster_option
uint32_t size
Definition: internal.h:52
uint32_t last_request_id
Definition: crm_internal.h:370
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:880
char * generate_transition_magic_v202(const char *transition_key, int op_status)
Definition: operations.c:140
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:35
int crm_help(char cmd, int exit_code)
Definition: utils.c:1104
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1224
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: operations.c:118
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:1012
gboolean check_number(const char *value)
Definition: utils.c:140
int crm_remote_accept(int ssock)
Definition: remote.c:978
void filter_action_parameters(xmlNode *param_set, const char *version)
Definition: operations.c:283
const char * name
Definition: crm_internal.h:102
int crm_remote_tcp_connect(const char *host, int port)
Definition: remote.c:943
void * convert_const_pointer(const void *ptr)
Definition: utils.c:1379
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:1179
void crm_sockaddr2str(void *sa, char *s)
Convert an IP address (IPv4 or IPv6) to a string for logging.
Definition: remote.c:959
const char * type
Definition: crm_internal.h:104
char * generate_transition_key(int action, int transition_id, int target_rc, const char *node)
Definition: operations.c:200
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:375
op_status
Definition: services.h:133
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:876
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:384
gboolean check_quorum(const char *value)
Definition: utils.c:170
#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:1196
gboolean check_positive_number(const char *value)
Definition: utils.c:161
const char * desc
Definition: crm_internal.h:90
gboolean check_time(const char *value)
Definition: utils.c:111
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:300
#define CRM_DAEMON_USER
Definition: config.h:47
gboolean check_boolean(const char *value)
Definition: utils.c:129
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:859
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:1059
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:368
struct remote_proxy_s remote_proxy_t
void remote_proxy_nack_shutdown(lrmd_t *lrmd)
We&#39;re not going to 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:1212
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1206
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
Definition: utils.c:294
const char * description_short
Definition: crm_internal.h:110
gboolean check_script(const char *value)
Definition: utils.c:188
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:215
int node_score_infinity
Definition: utils.c:75
mainloop_io_t * source
Definition: crm_internal.h:369
int node_score_red
Definition: utils.c:72
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: operations.c:457
#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:410
long crm_read_pidfile(const char *filename)
Definition: utils.c:781
Definition: lrmd.h:498
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2905
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:423
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:120
int crm_get_option(int argc, char **argv, int *index)
Definition: utils.c:1053
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Generate an operation key.
Definition: operations.c:37
void * crm_create_anon_tls_session(int sock, int type, void *credentials)
int node_score_green
Definition: utils.c:73
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:356
gboolean is_local
Definition: crm_internal.h:366
const char * alt_name
Definition: crm_internal.h:103
int crm_remote_send(crm_remote_t *remote, xmlNode *msg)
Definition: remote.c:335
int node_score_yellow
Definition: utils.c:74
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:3006
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:299
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3696