pacemaker  1.1.24-3850484742
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 
40 /* For ACLs */
41 char *uid2username(uid_t uid);
42 void determine_request_user(const char *user, xmlNode * request, const char *field);
43 const char *crm_acl_get_set_user(xmlNode * request, const char *field, const char *peer_user);
44 
45 # if ENABLE_ACL
46 # include <string.h>
47 static inline gboolean
48 is_privileged(const char *user)
49 {
50  if (user == NULL) {
51  return FALSE;
52  } else if (strcmp(user, CRM_DAEMON_USER) == 0) {
53  return TRUE;
54  } else if (strcmp(user, "root") == 0) {
55  return TRUE;
56  }
57  return FALSE;
58 }
59 # endif
60 
61 /* CLI option processing*/
62 # ifdef HAVE_GETOPT_H
63 # include <getopt.h>
64 # else
65 # define no_argument 0
66 # define required_argument 1
67 # endif
68 
69 # define pcmk_option_default 0x00000
70 # define pcmk_option_hidden 0x00001
71 # define pcmk_option_paragraph 0x00002
72 # define pcmk_option_example 0x00004
73 
74 struct crm_option {
75  /* Fields from 'struct option' in getopt.h */
76  /* name of long option */
77  const char *name;
78  /*
79  * one of no_argument, required_argument, and optional_argument:
80  * whether option takes an argument
81  */
82  int has_arg;
83  /* if not NULL, set *flag to val when option found */
84  int *flag;
85  /* if flag not NULL, value to set *flag to; else return value */
86  int val;
87 
88  /* Custom fields */
89  const char *desc;
90  long flags;
91 };
92 
93 void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options,
94  const char *app_desc);
95 int crm_get_option(int argc, char **argv, int *index);
96 int crm_get_option_long(int argc, char **argv, int *index, const char **longname);
97 int crm_help(char cmd, int exit_code);
98 
99 /* Cluster Option Processing */
100 typedef struct pe_cluster_option_s {
101  const char *name;
102  const char *alt_name;
103  const char *type;
104  const char *values;
105  const char *default_value;
106 
107  gboolean(*is_valid) (const char *);
108 
109  const char *description_short;
110  const char *description_long;
111 
113 
114 const char *cluster_option(GHashTable * options, gboolean(*validate) (const char *),
115  const char *name, const char *old_name, const char *def_value);
116 
117 const char *get_cluster_pref(GHashTable * options, pe_cluster_option * option_list, int len,
118  const char *name);
119 
120 void config_metadata(const char *name, const char *version, const char *desc_short,
121  const char *desc_long, pe_cluster_option * option_list, int len);
122 
123 void verify_all_options(GHashTable * options, pe_cluster_option * option_list, int len);
124 gboolean check_time(const char *value);
125 gboolean check_timer(const char *value);
126 gboolean check_boolean(const char *value);
127 gboolean check_number(const char *value);
128 gboolean check_positive_number(const char *value);
129 gboolean check_quorum(const char *value);
130 gboolean check_script(const char *value);
131 gboolean check_utilization(const char *value);
132 long crm_get_sbd_timeout(void);
133 gboolean check_sbd_timeout(const char *value);
134 
135 /* char2score */
136 extern int node_score_red;
137 extern int node_score_green;
138 extern int node_score_yellow;
139 extern int node_score_infinity;
140 
141 /* Assorted convenience functions */
142 
163 int crm_pid_active(long pid, const char *daemon);
164 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
165 
166 /* from operations.c */
167 char *generate_op_key(const char *rsc_id, const char *op_type, int interval);
168 char *generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type);
169 char *generate_transition_magic_v202(const char *transition_key, int op_status);
170 char *generate_transition_magic(const char *transition_key, int op_status, int op_rc);
171 char *generate_transition_key(int action, int transition_id, int target_rc, const char *node);
172 void filter_action_parameters(xmlNode *param_set, const char *version);
173 xmlNode *create_operation_update(xmlNode *parent, lrmd_event_data_t *event,
174  const char *caller_version, int target_rc,
175  const char *node, const char *origin,
176  int level);
177 
178 static inline long long
179 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
180 {
181  long long rc = (word & ~bit);
182 
183  if (rc == word) {
184  /* Unchanged */
185  } else if (target) {
186  crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
187  } else {
188  crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
189  }
190 
191  return rc;
192 }
193 
194 static inline long long
195 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
196 {
197  long long rc = (word | bit);
198 
199  if (rc == word) {
200  /* Unchanged */
201  } else if (target) {
202  crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
203  } else {
204  crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
205  }
206 
207  return rc;
208 }
209 
210 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
211 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
212 
213 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
214 
215 const char *daemon_option(const char *option);
216 void set_daemon_option(const char *option, const char *value);
217 gboolean daemon_option_enabled(const char *daemon, const char *option);
218 void strip_text_nodes(xmlNode * xml);
219 void pcmk_panic(const char *origin);
220 void sysrq_init(void);
221 pid_t pcmk_locate_sbd(void);
222 long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
223 long crm_read_pidfile(const char *filename);
224 
225 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
226 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
227 
228 # define attrd_channel T_ATTRD
229 # define F_ATTRD_KEY "attr_key"
230 # define F_ATTRD_ATTRIBUTE "attr_name"
231 # define F_ATTRD_REGEX "attr_regex"
232 # define F_ATTRD_TASK "task"
233 # define F_ATTRD_VALUE "attr_value"
234 # define F_ATTRD_SET "attr_set"
235 # define F_ATTRD_IS_REMOTE "attr_is_remote"
236 # define F_ATTRD_IS_PRIVATE "attr_is_private"
237 # define F_ATTRD_SECTION "attr_section"
238 # define F_ATTRD_DAMPEN "attr_dampening"
239 # define F_ATTRD_IGNORE_LOCALLY "attr_ignore_locally"
240 # define F_ATTRD_HOST "attr_host"
241 # define F_ATTRD_HOST_ID "attr_host_id"
242 # define F_ATTRD_USER "attr_user"
243 # define F_ATTRD_WRITER "attr_writer"
244 # define F_ATTRD_VERSION "attr_version"
245 # define F_ATTRD_RESOURCE "attr_resource"
246 # define F_ATTRD_OPERATION "attr_clear_operation"
247 # define F_ATTRD_INTERVAL "attr_clear_interval"
248 # define F_ATTRD_IS_FORCE_WRITE "attrd_is_force_write"
249 
250 /* attrd operations */
251 # define ATTRD_OP_PEER_REMOVE "peer-remove"
252 # define ATTRD_OP_UPDATE "update"
253 # define ATTRD_OP_UPDATE_BOTH "update-both"
254 # define ATTRD_OP_UPDATE_DELAY "update-delay"
255 # define ATTRD_OP_QUERY "query"
256 # define ATTRD_OP_REFRESH "refresh"
257 # define ATTRD_OP_FLUSH "flush"
258 # define ATTRD_OP_SYNC "sync"
259 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
260 # define ATTRD_OP_CLEAR_FAILURE "clear-failure"
261 
262 # define PCMK_ENV_PHYSICAL_HOST "physical_host"
263 
264 
265 # if SUPPORT_COROSYNC
266 # if CS_USES_LIBQB
267 # include <qb/qbipc_common.h>
268 # include <corosync/corotypes.h>
269 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
270 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
271 # else
272 # include <corosync/corodefs.h>
273 # include <corosync/coroipcc.h>
274 # include <corosync/coroipc_types.h>
275 typedef coroipc_request_header_t cs_ipc_header_request_t;
276 typedef coroipc_response_header_t cs_ipc_header_response_t;
277 # endif
278 # else
279 typedef struct {
280  int size __attribute__ ((aligned(8)));
281  int id __attribute__ ((aligned(8)));
282 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
283 
284 typedef struct {
285  int size __attribute__ ((aligned(8)));
286  int id __attribute__ ((aligned(8)));
287  int error __attribute__ ((aligned(8)));
288 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
289 
290 # endif
291 
292 void
293 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
294 void
295 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
296 
297 qb_ipcs_service_t *
298 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
299 
300 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
301  qb_ipcs_service_t **ipcs_rw,
302  qb_ipcs_service_t **ipcs_shm,
303  struct qb_ipcs_service_handlers *ro_cb,
304  struct qb_ipcs_service_handlers *rw_cb);
305 
306 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
307  qb_ipcs_service_t *ipcs_rw,
308  qb_ipcs_service_t *ipcs_shm);
309 
310 static inline void *realloc_safe(void *ptr, size_t size)
311 {
312  void *ret = realloc(ptr, size);
313 
314  if (ret == NULL) {
315  free(ptr); /* make coverity happy */
316  abort();
317  }
318 
319  return ret;
320 }
321 
322 const char *crm_xml_add_last_written(xmlNode *xml_node);
323 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
324 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
325 
326 gboolean crm_digest_verify(xmlNode *input, const char *expected);
327 
328 /* cross-platform compatibility functions */
329 char *crm_compat_realpath(const char *path);
330 
331 /* IPC Proxy Backend Shared Functions */
332 typedef struct remote_proxy_s {
333  char *node_name;
334  char *session_id;
335 
336  gboolean is_local;
337 
342 
344 
346  lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks,
347  const char *node_name, const char *session_id, const char *channel);
348 
349 int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash);
350 void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg);
353 
354 int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata);
355 void remote_proxy_disconnected(gpointer data);
356 void remote_proxy_free(gpointer data);
357 
358 void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg);
359 void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id);
360 
361 #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:167
char * generate_transition_magic(const char *transition_key, int op_status, int op_rc)
Definition: operations.c:173
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:709
long crm_get_sbd_timeout(void)
Definition: watchdog.c:257
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:3194
gboolean check_sbd_timeout(const char *value)
Definition: watchdog.c:266
long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
Definition: utils.c:826
struct pe_cluster_option_s pe_cluster_option
uint32_t size
Definition: internal.h:80
uint32_t last_request_id
Definition: crm_internal.h:340
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:888
char * generate_transition_magic_v202(const char *transition_key, int op_status)
Definition: operations.c:156
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:25
int crm_help(char cmd, int exit_code)
Definition: utils.c:1112
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1232
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
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: operations.c:134
uint32_t pid
Definition: internal.h:77
void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options, const char *app_desc)
Definition: utils.c:1020
gboolean check_number(const char *value)
Definition: utils.c:131
void filter_action_parameters(xmlNode *param_set, const char *version)
Definition: operations.c:299
const char * name
Definition: crm_internal.h:101
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:1187
const char * type
Definition: crm_internal.h:103
char * generate_transition_key(int action, int transition_id, int target_rc, const char *node)
Definition: operations.c:216
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:366
op_status
Definition: services.h:133
int daemon(int nochdir, int noclose)
const char * default_value
Definition: crm_internal.h:105
void determine_request_user(const char *user, xmlNode *request, const char *field)
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:52
int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash)
Definition: lrmd_client.c:909
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
gboolean check_quorum(const char *value)
Definition: utils.c:161
#define crm_trace(fmt, args...)
Definition: logging.h:280
const char * values
Definition: crm_internal.h:104
enum crm_proc_flag __attribute__
void pcmk_panic(const char *origin)
Definition: watchdog.c:186
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:1204
gboolean check_positive_number(const char *value)
Definition: utils.c:152
const char * desc
Definition: crm_internal.h:89
gboolean check_time(const char *value)
Definition: utils.c:102
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:270
#define CRM_DAEMON_USER
Definition: config.h:47
gboolean check_boolean(const char *value)
Definition: utils.c:120
const char * description_long
Definition: crm_internal.h:110
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
Definition: utils.c:1067
int * flag
Definition: crm_internal.h:84
void remote_proxy_disconnected(gpointer data)
Definition: proxy_common.c:157
crm_ipc_t * ipc
Definition: crm_internal.h:338
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:119
void attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1220
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1214
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
Definition: utils.c:285
const char * description_short
Definition: crm_internal.h:109
gboolean check_script(const char *value)
Definition: utils.c:179
void remote_proxy_free(gpointer data)
Definition: proxy_common.c:117
void set_daemon_option(const char *option, const char *value)
Definition: logging.c:143
gboolean check_utilization(const char *value)
Definition: utils.c:206
int node_score_infinity
Definition: utils.c:66
mainloop_io_t * source
Definition: crm_internal.h:339
int node_score_red
Definition: utils.c:63
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:473
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:86
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
Definition: utils.c:401
long crm_read_pidfile(const char *filename)
Definition: utils.c:789
Definition: lrmd.h:524
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2303
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:414
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:217
gboolean check_timer(const char *value)
Definition: utils.c:111
int crm_get_option(int argc, char **argv, int *index)
Definition: utils.c:1061
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Generate an operation key.
Definition: operations.c:37
int node_score_green
Definition: utils.c:64
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:347
gboolean is_local
Definition: crm_internal.h:336
const char * alt_name
Definition: crm_internal.h:102
int node_score_yellow
Definition: utils.c:65
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:2401
char * uid2username(uid_t uid)
const char * name
Definition: crm_internal.h:77
void sysrq_init(void)
Definition: watchdog.c:40
struct qb_ipc_request_header cs_ipc_header_request_t
Definition: crm_internal.h:269
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3091