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