pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
util.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CRM_COMMON_UTIL__H
19 # define CRM_COMMON_UTIL__H
20 
27 # include <sys/types.h>
28 # include <stdlib.h>
29 # include <stdbool.h>
30 # include <limits.h>
31 # include <signal.h>
32 # include <sysexits.h>
33 # include <glib.h>
34 
35 # include <libxml/tree.h>
36 
37 # include <crm/lrmd.h>
38 
39 # if SUPPORT_HEARTBEAT
40 # include <heartbeat.h>
41 # else
42 # define NORMALNODE "normal"
43 # define ACTIVESTATUS "active"/* fully functional, and all links are up */
44 # define DEADSTATUS "dead"
45  /* Status of non-working link or machine */
46 # define PINGSTATUS "ping"
47  /* Status of a working ping node */
48 # define JOINSTATUS "join"
49  /* Status when an api client joins */
50 # define LEAVESTATUS "leave"
51  /* Status when an api client leaves */
52 # define ONLINESTATUS "online"/* Status of an online client */
53 # define OFFLINESTATUS "offline"
54  /* Status of an offline client */
55 # endif
56 
57 /* public Pacemaker Remote functions (from remote.c) */
58 int crm_default_remote_port(void);
59 
60 /* public string functions (from strings.c) */
61 char *crm_itoa_stack(int an_int, char *buf, size_t len);
62 char *crm_itoa(int an_int);
63 gboolean crm_is_true(const char *s);
64 int crm_str_to_boolean(const char *s, int *ret);
65 int crm_parse_int(const char *text, const char *default_text);
66 char * crm_strip_trailing_newline(char *str);
67 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
68 gboolean safe_str_neq(const char *a, const char *b);
69 guint crm_strcase_hash(gconstpointer v);
70 guint g_str_hash_traditional(gconstpointer v);
71 
72 # define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
73 # define crm_str_hash g_str_hash_traditional
74 
75 /* used with hash tables where case does not matter */
76 static inline gboolean
77 crm_strcase_equal(gconstpointer a, gconstpointer b)
78 {
79  return crm_str_eq((const char *) a, (const char *) b, FALSE);
80 }
81 
89 static inline GHashTable *
90 crm_str_table_new()
91 {
92  return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
93 }
94 
102 static inline GHashTable *
103 crm_strcase_table_new()
104 {
105  return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal, free, free);
106 }
107 
108 GHashTable *crm_str_table_dup(GHashTable *old_table);
109 
110 # define crm_atoi(text, default_text) crm_parse_int(text, default_text)
111 
112 /* public I/O functions (from io.c) */
113 void crm_build_path(const char *path_c, mode_t mode);
114 
115 long long crm_get_msec(const char *input);
116 unsigned long long crm_get_interval(const char *input);
117 int char2score(const char *score);
118 char *score2char(int score);
119 char *score2char_stack(int score, char *buf, size_t len);
120 
121 /* public operation functions (from operations.c) */
122 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
123  int *interval);
124 gboolean decode_transition_key(const char *key, char **uuid, int *action,
125  int *transition_id, int *target_rc);
126 gboolean decode_transition_magic(const char *magic, char **uuid,
127  int *transition_id, int *action_id,
128  int *op_status, int *op_rc, int *target_rc);
130 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
131 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
132 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
133  const char *task, const char *interval,
134  const char *timeout);
135 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
136 
137 int compare_version(const char *version1, const char *version2);
138 
139 /* coverity[+kill] */
140 void crm_abort(const char *file, const char *function, int line,
141  const char *condition, gboolean do_core, gboolean do_fork);
142 
143 static inline gboolean
144 is_not_set(long long word, long long bit)
145 {
146  return ((word & bit) == 0);
147 }
148 
149 static inline gboolean
150 is_set(long long word, long long bit)
151 {
152  return ((word & bit) == bit);
153 }
154 
155 static inline gboolean
156 is_set_any(long long word, long long bit)
157 {
158  return ((word & bit) != 0);
159 }
160 
161 static inline guint
162 crm_hash_table_size(GHashTable * hashtable)
163 {
164  if (hashtable == NULL) {
165  return 0;
166  }
167  return g_hash_table_size(hashtable);
168 }
169 
170 char *crm_meta_name(const char *field);
171 const char *crm_meta_value(GHashTable * hash, const char *field);
172 
173 char *crm_md5sum(const char *buffer);
174 
175 char *crm_generate_uuid(void);
176 bool crm_is_daemon_name(const char *name);
177 
178 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
179 
180 #ifdef HAVE_GNUTLS_GNUTLS_H
181 void crm_gnutls_global_init(void);
182 #endif
183 
184 int crm_exit(int rc);
185 bool pcmk_acl_required(const char *user);
186 
187 char *crm_generate_ra_key(const char *class, const char *provider, const char *type);
188 bool crm_provider_required(const char *standard);
189 int crm_parse_agent_spec(const char *spec, char **standard, char **provider,
190  char **type);
191 
192 #endif
bool crm_is_daemon_name(const char *name)
Check whether a string represents a cluster daemon name.
Definition: utils.c:1408
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:150
char * crm_generate_uuid(void)
Definition: utils.c:1390
guint g_str_hash_traditional(gconstpointer v)
Definition: strings.c:350
void crm_build_path(const char *path_c, mode_t mode)
Create a directory, including any parent directories needed.
Definition: io.c:50
int rsc_op_expected_rc(lrmd_event_data_t *event)
Definition: operations.c:389
int char2score(const char *score)
Definition: utils.c:230
long long crm_get_msec(const char *input)
Definition: utils.c:598
char * score2char_stack(int score, char *buf, size_t len)
Definition: utils.c:268
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:949
int crm_parse_int(const char *text, const char *default_text)
Definition: strings.c:125
Local Resource Manager.
bool crm_op_needs_metadata(const char *rsc_class, const char *op)
Check whether an operation requires resource agent meta-data.
Definition: operations.c:635
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:433
char * crm_meta_name(const char *field)
Definition: utils.c:927
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a &quot;standard[:provider]:type&quot; agent specification.
Definition: utils.c:1512
gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id, int *target_rc)
Definition: operations.c:217
op_status
Definition: services.h:133
bool pcmk_acl_required(const char *user)
Definition: utils.c:1236
unsigned long long crm_get_interval(const char *input)
Definition: utils.c:573
guint crm_strcase_hash(gconstpointer v)
Definition: strings.c:362
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval, const char *timeout)
Create a CIB XML element for an operation.
Definition: operations.c:439
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:213
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition: strings.c:50
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:176
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval)
Definition: operations.c:46
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: operations.c:404
GHashTable * crm_str_table_dup(GHashTable *old_table)
Definition: strings.c:382
int compare_version(const char *version1, const char *version2)
Definition: utils.c:486
#define crm_str_hash
Definition: util.h:73
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
Definition: operations.c:174
int crm_exit(int rc)
Definition: utils.c:83
char * crm_generate_ra_key(const char *class, const char *provider, const char *type)
Definition: utils.c:1461
char * crm_md5sum(const char *buffer)
Definition: utils.c:1424
bool crm_provider_required(const char *standard)
Check whether a resource standard requires a provider to be specified.
Definition: utils.c:1481
gboolean crm_is_true(const char *s)
Definition: strings.c:165
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:197
char * crm_itoa(int an_int)
Definition: strings.c:60
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:656
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
Definition: remote.c:1033
enum crm_ais_msg_types type
Definition: internal.h:51
char * score2char(int score)
Definition: utils.c:282