root/include/crm/compatibility.h

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. slist_basic_destroy
  2. calculate_xml_digest
  3. free_xml_from_parent
  4. attrd_update
  5. attrd_lazy_update
  6. attrd_update_no_mainloop
  7. update_attr
  8. find_nvpair_attr
  9. read_attr
  10. delete_attr
  11. log_cib_diff
  12. apply_cib_diff
  13. log_xml_diff

   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 {
  39     cib_ok                      =  pcmk_ok,
  40     cib_operation               = -EINVAL,
  41     cib_create_msg              = -EPROTO,
  42     cib_not_connected           = -ENOTCONN,
  43     cib_not_authorized          = -EACCES,
  44     cib_send_failed             = -ECOMM,
  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,
  52     CIBRES_MISSING_FIELD        = -EINVAL,
  53     cib_unknown                 = -EINVAL,
  54     cib_STALE                   = -ENOKEY,
  55     cib_EXISTS                  = -ENOTUNIQ,
  56     cib_NOTEXISTS               = -ENXIO,
  57     cib_ACTIVATION              = -ENODATA,
  58     cib_NOOBJECT                = -EINVAL,
  59     cib_NOPARENT                = -EINVAL,
  60     cib_NOTSUPPORTED            = -EPROTONOSUPPORT,
  61     cib_registration_msg        = -EPROTO,
  62     cib_callback_token          = -EPROTO,
  63     cib_callback_register       = -ECOMM,
  64     cib_client_gone             = -ECONNRESET,
  65     cib_not_master              = -EPERM,
  66     cib_missing_data            = -EINVAL,
  67     cib_remote_timeout          = -ETIME,
  68     cib_no_quorum               = -pcmk_err_no_quorum,
  69     cib_diff_failed             = -pcmk_err_diff_failed,
  70     cib_diff_resync             = -pcmk_err_diff_resync,
  71     cib_old_data                = -pcmk_err_old_data,
  72     cib_dtd_validation          = -pcmk_err_schema_validation,
  73     cib_bad_section             = -EINVAL,
  74     cib_bad_permissions         = -EACCES,
  75     cib_invalid_argument        = -EINVAL,
  76     cib_transform_failed        = -pcmk_err_transform_failed,
  77     cib_permission_denied       = -EACCES,
  78 };
  79 
  80 enum stonith_errors {
  81     stonith_ok                  =  pcmk_ok,
  82     stonith_pending             = -EINPROGRESS,
  83     st_err_generic              = -pcmk_err_generic,
  84     st_err_internal             = -EPROTO,
  85     st_err_not_supported        = -EPROTONOSUPPORT,
  86     st_err_connection           = -ENOTCONN,
  87     st_err_missing              = -EINVAL,
  88     st_err_exists               = -ENOTUNIQ,
  89     st_err_timeout              = -ETIME,
  90     st_err_ipc                  = -ECOMM,
  91     st_err_peer                 = -ENOMSG,
  92     st_err_unknown_operation    = -EOPNOTSUPP,
  93     st_err_unknown_device       = -ENODEV,
  94     st_err_none_available       = -EHOSTUNREACH,
  95     st_err_signal               = -ECONNABORTED,
  96     st_err_agent_fork           = -ECHILD,
  97     st_err_agent_args           = -EREMOTEIO,
  98     st_err_agent                = -ECONNABORTED,
  99     st_err_invalid_level        = -EINVAL,
 100 };
 101 
 102 
 103 enum lrmd_errors {
 104     lrmd_ok                      =  pcmk_ok,
 105     lrmd_pending                 = -EINPROGRESS,
 106     lrmd_err_generic             = -EPROTONOSUPPORT,
 107     lrmd_err_internal            = -EPROTO,
 108     lrmd_err_connection          = -ENOTCONN,
 109     lrmd_err_missing             = -EINVAL,
 110     lrmd_err_ipc                 = -ECOMM,
 111     lrmd_err_peer                = -ENOMSG,
 112     lrmd_err_unknown_operation   = -EOPNOTSUPP,
 113     lrmd_err_unknown_rsc         = -ENODEV,
 114     lrmd_err_no_metadata         = -EIO,
 115     lrmd_err_stonith_connection  = -EUNATCH,
 116     lrmd_err_provider_required   = -EINVAL,
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 342 {
 343     xml_log_patchset(log_level, function, diff);
 344 }
 345 #  endif
 346 
 347 #endif

/* [previous][next][first][last][top][bottom][index][help] */