pacemaker  2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
crm_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #ifndef CRM_INTERNAL__H
9 # define CRM_INTERNAL__H
10 
11 # include <config.h>
12 # include <portability.h>
13 
14 # include <glib.h>
15 # include <stdbool.h>
16 # include <libxml/tree.h>
17 
18 # include <crm/lrmd.h>
19 # include <crm/common/logging.h>
20 # include <crm/common/ipcs.h>
21 # include <crm/common/internal.h>
22 
23 /* Dynamic loading of libraries */
24 void *find_library_function(void **handle, const char *lib, const char *fn, int fatal);
25 
26 /* For ACLs */
27 char *uid2username(uid_t uid);
28 const char *crm_acl_get_set_user(xmlNode * request, const char *field, const char *peer_user);
29 
30 # if ENABLE_ACL
31 # include <string.h>
32 static inline gboolean
33 is_privileged(const char *user)
34 {
35  if (user == NULL) {
36  return FALSE;
37  } else if (strcmp(user, CRM_DAEMON_USER) == 0) {
38  return TRUE;
39  } else if (strcmp(user, "root") == 0) {
40  return TRUE;
41  }
42  return FALSE;
43 }
44 # endif
45 
46 /* CLI option processing*/
47 # ifdef HAVE_GETOPT_H
48 # include <getopt.h>
49 # else
50 # define no_argument 0
51 # define required_argument 1
52 # endif
53 
54 # define pcmk_option_default 0x00000
55 # define pcmk_option_hidden 0x00001
56 # define pcmk_option_paragraph 0x00002
57 # define pcmk_option_example 0x00004
58 
59 struct crm_option {
60  /* Fields from 'struct option' in getopt.h */
61  /* name of long option */
62  const char *name;
63  /*
64  * one of no_argument, required_argument, and optional_argument:
65  * whether option takes an argument
66  */
67  int has_arg;
68  /* if not NULL, set *flag to val when option found */
69  int *flag;
70  /* if flag not NULL, value to set *flag to; else return value */
71  int val;
72 
73  /* Custom fields */
74  const char *desc;
75  long flags;
76 };
77 
78 void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options,
79  const char *app_desc);
80 int crm_get_option(int argc, char **argv, int *index);
81 int crm_get_option_long(int argc, char **argv, int *index, const char **longname);
82 crm_exit_t crm_help(char cmd, crm_exit_t exit_code);
83 
84 /* Cluster Option Processing */
85 typedef struct pe_cluster_option_s {
86  const char *name;
87  const char *alt_name;
88  const char *type;
89  const char *values;
90  const char *default_value;
91 
92  gboolean(*is_valid) (const char *);
93 
94  const char *description_short;
95  const char *description_long;
96 
98 
99 const char *cluster_option(GHashTable * options, gboolean(*validate) (const char *),
100  const char *name, const char *old_name, const char *def_value);
101 
102 const char *get_cluster_pref(GHashTable * options, pe_cluster_option * option_list, int len,
103  const char *name);
104 
105 void config_metadata(const char *name, const char *version, const char *desc_short,
106  const char *desc_long, pe_cluster_option * option_list, int len);
107 
108 void verify_all_options(GHashTable * options, pe_cluster_option * option_list, int len);
109 gboolean check_time(const char *value);
110 gboolean check_timer(const char *value);
111 gboolean check_boolean(const char *value);
112 gboolean check_number(const char *value);
113 gboolean check_positive_number(const char *value);
114 gboolean check_quorum(const char *value);
115 gboolean check_script(const char *value);
116 gboolean check_utilization(const char *value);
117 long crm_get_sbd_timeout(void);
118 long crm_auto_watchdog_timeout(void);
119 gboolean check_sbd_timeout(const char *value);
120 void crm_args_fini(void);
121 
122 /* char2score */
123 extern int node_score_red;
124 extern int node_score_green;
125 extern int node_score_yellow;
126 
127 /* Assorted convenience functions */
128 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
129 
130 // printf-style format to create operation ID from resource, action, interval
131 #define CRM_OP_FMT "%s_%s_%u"
132 
133 static inline long long
134 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
135 {
136  long long rc = (word & ~bit);
137 
138  if (rc == word) {
139  /* Unchanged */
140  } else if (target) {
141  crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
142  } else {
143  crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
144  }
145 
146  return rc;
147 }
148 
149 static inline long long
150 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
151 {
152  long long rc = (word | bit);
153 
154  if (rc == word) {
155  /* Unchanged */
156  } else if (target) {
157  crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
158  } else {
159  crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
160  }
161 
162  return rc;
163 }
164 
165 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
166 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
167 
168 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
169 
170 const char *daemon_option(const char *option);
171 void set_daemon_option(const char *option, const char *value);
172 gboolean daemon_option_enabled(const char *daemon, const char *option);
173 void strip_text_nodes(xmlNode * xml);
174 void pcmk_panic(const char *origin);
175 pid_t pcmk_locate_sbd(void);
176 
177 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
178 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
179 
180 # define F_ATTRD_KEY "attr_key"
181 # define F_ATTRD_ATTRIBUTE "attr_name"
182 # define F_ATTRD_REGEX "attr_regex"
183 # define F_ATTRD_TASK "task"
184 # define F_ATTRD_VALUE "attr_value"
185 # define F_ATTRD_SET "attr_set"
186 # define F_ATTRD_IS_REMOTE "attr_is_remote"
187 # define F_ATTRD_IS_PRIVATE "attr_is_private"
188 # define F_ATTRD_SECTION "attr_section"
189 # define F_ATTRD_DAMPEN "attr_dampening"
190 # define F_ATTRD_HOST "attr_host"
191 # define F_ATTRD_HOST_ID "attr_host_id"
192 # define F_ATTRD_USER "attr_user"
193 # define F_ATTRD_WRITER "attr_writer"
194 # define F_ATTRD_VERSION "attr_version"
195 # define F_ATTRD_RESOURCE "attr_resource"
196 # define F_ATTRD_OPERATION "attr_clear_operation"
197 # define F_ATTRD_INTERVAL "attr_clear_interval"
198 # define F_ATTRD_IS_FORCE_WRITE "attrd_is_force_write"
199 
200 /* attrd operations */
201 # define ATTRD_OP_PEER_REMOVE "peer-remove"
202 # define ATTRD_OP_UPDATE "update"
203 # define ATTRD_OP_UPDATE_BOTH "update-both"
204 # define ATTRD_OP_UPDATE_DELAY "update-delay"
205 # define ATTRD_OP_QUERY "query"
206 # define ATTRD_OP_REFRESH "refresh"
207 # define ATTRD_OP_FLUSH "flush"
208 # define ATTRD_OP_SYNC "sync"
209 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
210 # define ATTRD_OP_CLEAR_FAILURE "clear-failure"
211 
212 # define PCMK_ENV_PHYSICAL_HOST "physical_host"
213 
214 
215 # if SUPPORT_COROSYNC
216 # include <qb/qbipc_common.h>
217 # include <corosync/corotypes.h>
218 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
219 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
220 # else
221 typedef struct {
222  int size __attribute__ ((aligned(8)));
223  int id __attribute__ ((aligned(8)));
224 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
225 
226 typedef struct {
227  int size __attribute__ ((aligned(8)));
228  int id __attribute__ ((aligned(8)));
229  int error __attribute__ ((aligned(8)));
230 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
231 
232 # endif
233 
234 void
235 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
236 void
237 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
238 
239 qb_ipcs_service_t *
240 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
241 
242 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
243  qb_ipcs_service_t **ipcs_rw,
244  qb_ipcs_service_t **ipcs_shm,
245  struct qb_ipcs_service_handlers *ro_cb,
246  struct qb_ipcs_service_handlers *rw_cb);
247 
248 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
249  qb_ipcs_service_t *ipcs_rw,
250  qb_ipcs_service_t *ipcs_shm);
251 
252 static inline void *realloc_safe(void *ptr, size_t size)
253 {
254  void *ret = realloc(ptr, size);
255 
256  if (ret == NULL) {
257  free(ptr); /* make coverity happy */
258  abort();
259  }
260 
261  return ret;
262 }
263 
264 const char *crm_xml_add_last_written(xmlNode *xml_node);
265 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
266 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
267 
268 gboolean crm_digest_verify(xmlNode *input, const char *expected);
269 
270 /* cross-platform compatibility functions */
271 char *crm_compat_realpath(const char *path);
272 
273 /* IPC Proxy Backend Shared Functions */
274 typedef struct remote_proxy_s {
275  char *node_name;
276  char *session_id;
277 
278  gboolean is_local;
279 
284 
286 
288  lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks,
289  const char *node_name, const char *session_id, const char *channel);
290 
291 int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash);
292 void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg);
295 
296 int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata);
297 void remote_proxy_disconnected(gpointer data);
298 void remote_proxy_free(gpointer data);
299 
300 void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg);
301 void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id);
302 
303 #endif /* CRM_INTERNAL__H */
void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id)
Definition: proxy_common.c:79
gboolean daemon_option_enabled(const char *daemon, const char *option)
Definition: logging.c:152
int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata)
Definition: proxy_common.c:116
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)
long crm_get_sbd_timeout(void)
Definition: watchdog.c:214
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
Definition: xml.c:3138
gboolean check_sbd_timeout(const char *value)
Definition: watchdog.c:233
struct pe_cluster_option_s pe_cluster_option
uint32_t size
Definition: internal.h:84
uint32_t last_request_id
Definition: crm_internal.h:282
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
Definition: utils.c:685
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:29
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1029
void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg)
Definition: proxy_common.c:66
void remote_proxy_ack_shutdown(lrmd_t *lrmd)
Send an acknowledgment of a remote proxy shutdown request.
Definition: proxy_common.c:42
Resource agent executor.
gboolean crm_digest_verify(xmlNode *input, const char *expected)
Definition: digest.c:226
enum crm_exit_e crm_exit_t
void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options, const char *app_desc)
Definition: utils.c:817
gboolean check_number(const char *value)
Definition: utils.c:100
const char * name
Definition: crm_internal.h:86
Wrappers for and extensions to libqb logging.
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:984
const char * type
Definition: crm_internal.h:88
long crm_auto_watchdog_timeout(void)
Definition: watchdog.c:225
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:342
int daemon(int nochdir, int noclose)
void crm_args_fini(void)
Definition: utils.c:190
const char * default_value
Definition: crm_internal.h:90
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:58
int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash)
Definition: lrmd_client.c:868
void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg)
Definition: proxy_common.c:203
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:163
gboolean check_quorum(const char *value)
Definition: utils.c:130
#define crm_trace(fmt, args...)
Definition: logging.h:255
const char * values
Definition: crm_internal.h:89
void pcmk_panic(const char *origin)
Definition: watchdog.c:143
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:1001
gboolean check_positive_number(const char *value)
Definition: utils.c:121
const char * desc
Definition: crm_internal.h:74
gboolean check_time(const char *value)
Definition: utils.c:71
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:219
#define CRM_DAEMON_USER
Definition: config.h:47
gboolean check_boolean(const char *value)
Definition: utils.c:89
const char * description_long
Definition: crm_internal.h:95
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
Definition: utils.c:864
int * flag
Definition: crm_internal.h:69
void remote_proxy_disconnected(gpointer data)
Definition: proxy_common.c:145
crm_ipc_t * ipc
Definition: crm_internal.h:280
struct remote_proxy_s remote_proxy_t
crm_exit_t crm_help(char cmd, crm_exit_t exit_code)
Definition: utils.c:909
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:57
const char * daemon_option(const char *option)
Definition: logging.c:104
void attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1017
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
Definition: utils.c:1011
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
Definition: utils.c:261
const char * description_short
Definition: crm_internal.h:94
gboolean check_script(const char *value)
Definition: utils.c:148
void remote_proxy_free(gpointer data)
Definition: proxy_common.c:105
void set_daemon_option(const char *option, const char *value)
Definition: logging.c:128
gboolean check_utilization(const char *value)
Definition: utils.c:175
mainloop_io_t * source
Definition: crm_internal.h:281
int node_score_red
Definition: utils.c:61
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:90
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
Definition: utils.c:377
Definition: lrmd.h:530
void strip_text_nodes(xmlNode *xml)
Definition: xml.c:2206
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
Definition: utils.c:390
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:174
gboolean check_timer(const char *value)
Definition: utils.c:80
int crm_get_option(int argc, char **argv, int *index)
Definition: utils.c:858
int node_score_green
Definition: utils.c:62
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
Definition: utils.c:323
gboolean is_local
Definition: crm_internal.h:278
const char * alt_name
Definition: crm_internal.h:87
int node_score_yellow
Definition: utils.c:63
const char * crm_xml_add_last_written(xmlNode *xml_node)
Definition: xml.c:2308
char * uid2username(uid_t uid)
uint32_t version
Definition: remote.c:146
const char * name
Definition: crm_internal.h:62
enum crm_proc_flag __attribute__
struct qb_ipc_request_header cs_ipc_header_request_t
Definition: crm_internal.h:218
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
Definition: xml.c:3035