pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
compatibility.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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_COMPATIBILITY__H
19 # define CRM_COMPATIBILITY__H
20 # define LOG_DEBUG_2 LOG_TRACE
21 # define LOG_DEBUG_3 LOG_TRACE
22 # define LOG_DEBUG_4 LOG_TRACE
23 # define LOG_DEBUG_5 LOG_TRACE
24 # define LOG_DEBUG_6 LOG_TRACE
25 
26 # define XML_CIB_ATTR_HASTATE "ha"
27 # define XML_CIB_ATTR_JOINSTATE XML_NODE_JOIN_STATE
28 # define XML_CIB_ATTR_EXPSTATE XML_NODE_EXPECTED
29 # define XML_CIB_ATTR_INCCM XML_NODE_IN_CLUSTER
30 # define XML_CIB_ATTR_CRMDSTATE XML_NODE_IS_PEER
31 
32 # define CRMD_STATE_ACTIVE CRMD_JOINSTATE_MEMBER
33 # define CRMD_STATE_INACTIVE CRMD_JOINSTATE_DOWN
34 
35 #define pcmk_err_dtd_validation pcmk_err_schema_validation
36 
37 /* *INDENT-OFF* */
38 enum cib_errors {
40  cib_operation = -EINVAL,
41  cib_create_msg = -EPROTO,
42  cib_not_connected = -ENOTCONN,
43  cib_not_authorized = -EACCES,
45  cib_reply_failed = -ENOMSG,
46  cib_return_code = -EPROTO,
47  cib_output_data = -ENOMSG,
48  cib_connection = -ENOTCONN,
49  cib_authentication = -EPROTO,
50  cib_missing = -EINVAL,
51  cib_variant = -EPROTONOSUPPORT,
53  cib_unknown = -EINVAL,
56  cib_NOTEXISTS = -ENXIO,
58  cib_NOOBJECT = -EINVAL,
59  cib_NOPARENT = -EINVAL,
60  cib_NOTSUPPORTED = -EPROTONOSUPPORT,
62  cib_callback_token = -EPROTO,
64  cib_client_gone = -ECONNRESET,
65  cib_not_master = -EPERM,
66  cib_missing_data = -EINVAL,
73  cib_bad_section = -EINVAL,
78 };
79 
82  stonith_pending = -EINPROGRESS,
84  st_err_internal = -EPROTO,
85  st_err_not_supported = -EPROTONOSUPPORT,
86  st_err_connection = -ENOTCONN,
87  st_err_missing = -EINVAL,
91  st_err_peer = -ENOMSG,
92  st_err_unknown_operation = -EOPNOTSUPP,
94  st_err_none_available = -EHOSTUNREACH,
95  st_err_signal = -ECONNABORTED,
96  st_err_agent_fork = -ECHILD,
98  st_err_agent = -ECONNABORTED,
100 };
101 
102 
105  lrmd_pending = -EINPROGRESS,
106  lrmd_err_generic = -EPROTONOSUPPORT,
107  lrmd_err_internal = -EPROTO,
108  lrmd_err_connection = -ENOTCONN,
109  lrmd_err_missing = -EINVAL,
111  lrmd_err_peer = -ENOMSG,
117 };
118 /* *INDENT-ON* */
119 
120 # define stonith_error2string pcmk_strerror
121 # define lrmd_error2string pcmk_strerror
122 # define cib_error2string pcmk_strerror
123 
124 static inline void
125 slist_basic_destroy(GListPtr list)
126 {
127  GListPtr gIter = NULL;
128 
129  for (gIter = list; gIter != NULL; gIter = gIter->next) {
130  free(gIter->data);
131  }
132  g_list_free(list);
133 }
134 
135 # define crm_strdup strdup
136 # define set_bit_inplace set_bit
137 # define clear_bit_inplace clear_bit
138 
139 # define crm_malloc0(malloc_obj, length) do { \
140  malloc_obj = malloc(length); \
141  if(malloc_obj == NULL) { \
142  crm_err("Failed allocation of %lu bytes", (unsigned long)length); \
143  CRM_ASSERT(malloc_obj != NULL); \
144  } \
145  memset(malloc_obj, 0, length); \
146  } while(0)
147 
148 # define crm_malloc(malloc_obj, length) do { \
149  malloc_obj = malloc(length); \
150  if(malloc_obj == NULL) { \
151  crm_err("Failed allocation of %lu bytes", (unsigned long)length); \
152  CRM_ASSERT(malloc_obj != NULL); \
153  } \
154  } while(0)
155 
156 # define crm_realloc(realloc_obj, length) do { \
157  realloc_obj = realloc(realloc_obj, length); \
158  CRM_ASSERT(realloc_obj != NULL); \
159  } while(0)
160 
161 # define crm_free(free_obj) do { free(free_obj); free_obj=NULL; } while(0)
162 
163 /* These two child iterator macros are no longer to be used
164  * They exist for compatibility reasons and will be removed in a
165  * future release
166  */
167 # define xml_child_iter(parent, child, code) do { \
168  if(parent != NULL) { \
169  xmlNode *child = NULL; \
170  xmlNode *__crm_xml_iter = parent->children; \
171  while(__crm_xml_iter != NULL) { \
172  child = __crm_xml_iter; \
173  __crm_xml_iter = __crm_xml_iter->next; \
174  if(child->type == XML_ELEMENT_NODE) { \
175  code; \
176  } \
177  } \
178  } \
179  } while(0)
180 
181 # define xml_child_iter_filter(parent, child, filter, code) do { \
182  if(parent != NULL) { \
183  xmlNode *child = NULL; \
184  xmlNode *__crm_xml_iter = parent->children; \
185  while(__crm_xml_iter != NULL) { \
186  child = __crm_xml_iter; \
187  __crm_xml_iter = __crm_xml_iter->next; \
188  if(child->type == XML_ELEMENT_NODE) { \
189  if(filter == NULL \
190  || crm_str_eq(filter, (const char *)child->name, TRUE)) { \
191  code; \
192  } \
193  } \
194  } \
195  } \
196  } while(0)
197 
198 # define xml_prop_iter(parent, prop_name, prop_value, code) do { \
199  if(parent != NULL) { \
200  xmlAttrPtr prop_iter = parent->properties; \
201  const char *prop_name = NULL; \
202  const char *prop_value = NULL; \
203  while(prop_iter != NULL) { \
204  prop_name = (const char *)prop_iter->name; \
205  prop_value = crm_element_value(parent, prop_name); \
206  prop_iter = prop_iter->next; \
207  if(prop_name) { \
208  code; \
209  } \
210  } \
211  } \
212  } while(0)
213 
214 # define xml_prop_name_iter(parent, prop_name, code) do { \
215  if(parent != NULL) { \
216  xmlAttrPtr prop_iter = parent->properties; \
217  const char *prop_name = NULL; \
218  while(prop_iter != NULL) { \
219  prop_name = (const char *)prop_iter->name; \
220  prop_iter = prop_iter->next; \
221  if(prop_name) { \
222  code; \
223  } \
224  } \
225  } \
226  } while(0)
227 
228 # define zap_xml_from_parent(parent, xml_obj) free_xml(xml_obj); xml_obj = NULL
229 
230 /* For ABI compatibility with version < 1.1.4 */
231 static inline char *
232 calculate_xml_digest(xmlNode * input, gboolean sort, gboolean do_filter)
233 {
234  return calculate_xml_digest_v1(input, sort, do_filter);
235 }
236 
237 static inline void
238 free_xml_from_parent(xmlNode * parent, xmlNode * a_node)
239 {
240  free_xml(a_node);
241 }
242 
243 /* Use something like this instead of the next macro:
244 
245  GListPtr gIter = rsc->children;
246  for(; gIter != NULL; gIter = gIter->next) {
247  resource_t *child_rsc = (resource_t*)gIter->data;
248  ...
249  }
250  */
251 # define slist_destroy(child_type, child, parent, a) do { \
252  GListPtr __crm_iter_head = parent; \
253  child_type *child = NULL; \
254  while(__crm_iter_head != NULL) { \
255  child = (child_type *) __crm_iter_head->data; \
256  __crm_iter_head = __crm_iter_head->next; \
257  { a; } \
258  } \
259  g_list_free(parent); \
260  } while(0)
261 
262 # ifdef CRM_ATTRD__H
263 static inline gboolean
264 attrd_update(crm_ipc_t * cluster, char command, const char *host, const char *name,
265  const char *value, const char *section, const char *set, const char *dampen)
266 {
267  return attrd_update_delegate(cluster, command, host, name, value, section, set, dampen,
268  NULL, attrd_opt_none) > 0;
269 }
270 
271 static inline gboolean
272 attrd_lazy_update(char command, const char *host, const char *name,
273  const char *value, const char *section, const char *set, const char *dampen)
274 {
275  return attrd_update_delegate(NULL, command, host, name, value, section, set, dampen, NULL, attrd_opt_none) > 0;
276 }
277 
278 static inline gboolean
279 attrd_update_no_mainloop(int *connection, char command, const char *host,
280  const char *name, const char *value, const char *section,
281  const char *set, const char *dampen)
282 {
283  return attrd_update_delegate(NULL, command, host, name, value, section, set, dampen, NULL, attrd_opt_none) > 0;
284 }
285 # endif
286 
287 # ifdef CIB_UTIL__H
288 static inline int
289 update_attr(cib_t * the_cib, int call_options,
290  const char *section, const char *node_uuid, const char *set_type, const char *set_name,
291  const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console)
292 {
293  return update_attr_delegate(the_cib, call_options, section, node_uuid, set_type, set_name,
294  attr_id, attr_name, attr_value, to_console, NULL, NULL);
295 }
296 
297 static inline int
298 find_nvpair_attr(cib_t * the_cib, const char *attr, const char *section, const char *node_uuid,
299  const char *set_type, const char *set_name, const char *attr_id,
300  const char *attr_name, gboolean to_console, char **value)
301 {
302  return find_nvpair_attr_delegate(the_cib, attr, section, node_uuid, set_type,
303  set_name, attr_id, attr_name, to_console, value, NULL);
304 }
305 
306 static inline int
307 read_attr(cib_t * the_cib,
308  const char *section, const char *node_uuid, const char *set_type, const char *set_name,
309  const char *attr_id, const char *attr_name, char **attr_value, gboolean to_console)
310 {
311  return read_attr_delegate(the_cib, section, node_uuid, set_type, set_name,
312  attr_id, attr_name, attr_value, to_console, NULL);
313 }
314 
315 static inline int
316 delete_attr(cib_t * the_cib, int options,
317  const char *section, const char *node_uuid, const char *set_type, const char *set_name,
318  const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console)
319 {
320  return delete_attr_delegate(the_cib, options, section, node_uuid, set_type, set_name,
321  attr_id, attr_name, attr_value, to_console, NULL);
322 }
323 
324 static inline void
325 log_cib_diff(int log_level, xmlNode * diff, const char *function)
326 {
327  xml_log_patchset(log_level, function, diff);
328 }
329 
330 static inline gboolean
331 apply_cib_diff(xmlNode * old, xmlNode * diff, xmlNode ** new)
332 {
333  *new = copy_xml(old);
334  return (xml_apply_patchset(*new, diff, TRUE) == pcmk_ok);
335 }
336 
337 # endif
338 
339 # ifdef CRM_COMMON_XML__H
340 void
341 log_xml_diff(uint8_t log_level, xmlNode * diff, const char *function)
342 {
343  xml_log_patchset(log_level, function, diff);
344 }
345 # endif
346 
347 #endif
#define ETIME
Definition: portability.h:257
#define attrd_opt_none
Definition: attrd.h:23
#define pcmk_err_old_data
Definition: error.h:49
#define pcmk_ok
Definition: error.h:42
#define EREMOTEIO
Definition: portability.h:241
cib_errors
Definition: compatibility.h:38
AIS_Host host
Definition: internal.h:52
xmlNode * copy_xml(xmlNode *src_node)
Definition: xml.c:2712
#define pcmk_err_diff_failed
Definition: error.h:50
int read_attr_delegate(cib_t *the_cib, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, char **attr_value, gboolean to_console, const char *user_name)
Definition: cib_attrs.c:331
#define pcmk_err_diff_resync
Definition: error.h:51
int find_nvpair_attr_delegate(cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value, const char *user_name)
Definition: cib_attrs.c:56
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
Definition: xml.c:2158
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:61
cib_variant
Definition: cib.h:35
#define pcmk_err_no_quorum
Definition: error.h:46
#define pcmk_err_schema_validation
Definition: error.h:47
#define pcmk_err_generic
Definition: error.h:45
stonith_errors
Definition: compatibility.h:80
#define ECOMM
Definition: portability.h:233
void free_xml(xmlNode *child)
Definition: xml.c:2706
#define pcmk_err_transform_failed
Definition: error.h:48
int attrd_update_delegate(crm_ipc_t *ipc, char command, const char *host, const char *name, const char *value, const char *section, const char *set, const char *dampen, const char *user_name, int options)
Send a request to attrd.
Definition: attrd_client.c:135
#define ENOKEY
Definition: portability.h:249
#define EUNATCH
Definition: portability.h:245
#define ENODATA
Definition: portability.h:253
#define ENOTUNIQ
Definition: portability.h:229
int delete_attr_delegate(cib_t *the_cib, int options, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console, const char *user_name)
Definition: cib_attrs.c:354
int update_attr_delegate(cib_t *the_cib, int call_options, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console, const char *user_name, const char *node_type)
Definition: cib_attrs.c:176
#define uint8_t
Definition: stdint.in.h:144
lrmd_errors
void xml_log_patchset(uint8_t level, const char *function, xmlNode *xml)
Definition: xml.c:1387
GList * GListPtr
Definition: crm.h:218
Definition: cib.h:148