diff --git a/include/crm/compatibility.h b/include/crm/compatibility.h new file mode 100644 index 0000000000..7891fcc439 --- /dev/null +++ b/include/crm/compatibility.h @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2012 Andrew Beekhof <andrew@beekhof.net> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef CRM_COMPATIBILITY__H +# define CRM_COMPATIBILITY__H +# define LOG_DEBUG_2 LOG_TRACE +# define LOG_DEBUG_3 LOG_TRACE +# define LOG_DEBUG_4 LOG_TRACE +# define LOG_DEBUG_5 LOG_TRACE +# define LOG_DEBUG_6 LOG_TRACE + +enum cib_errors { + cib_ok = pcmk_ok, + cib_operation = -EINVAL, + cib_create_msg = -EPROTO, + cib_not_connected = -ENOTCONN, + cib_not_authorized = -EACCES, + cib_send_failed = -ECOMM, + cib_reply_failed = -ENOMSG, + cib_return_code = -EPROTO, + cib_output_data = -ENOMSG, + cib_connection = -ENOTCONN, + cib_authentication = -EPROTO, + cib_missing = -EINVAL, + cib_variant = -EPROTONOSUPPORT, + CIBRES_MISSING_FIELD = -EINVAL, + cib_unknown = -EINVAL, + cib_STALE = -ENOKEY, + cib_EXISTS = -ENOTUNIQ, + cib_NOTEXISTS = -ENXIO, + cib_ACTIVATION = -ENODATA, + cib_NOOBJECT = -EINVAL, + cib_NOPARENT = -EINVAL, + cib_NOTSUPPORTED = -EPROTONOSUPPORT, + cib_registration_msg = -EPROTO, + cib_callback_token = -EPROTO, + cib_callback_register = -ECOMM, + cib_client_gone = -ECONNRESET, + cib_not_master = -EPERM, + cib_missing_data = -EINVAL, + cib_remote_timeout = -ETIME, + cib_no_quorum = -pcmk_err_no_quorum, + cib_diff_failed = -pcmk_err_diff_failed, + cib_diff_resync = -pcmk_err_diff_resync, + cib_old_data = -pcmk_err_old_data, + cib_dtd_validation = -pcmk_err_dtd_validation, + cib_bad_section = -EINVAL, + cib_bad_permissions = -EACCES, + cib_invalid_argument = -EINVAL, + cib_transform_failed = -pcmk_err_transform_failed, + cib_permission_denied = -EACCES, +}; + +enum stonith_errors { + stonith_ok = pcmk_ok, + stonith_pending = -EINPROGRESS, + st_err_generic = -pcmk_err_generic, + st_err_internal = -EPROTO, + st_err_not_supported = -EPROTONOSUPPORT, + st_err_connection = -ENOTCONN, + st_err_missing = -EINVAL, + st_err_exists = -ENOTUNIQ, + st_err_timeout = -ETIME, + st_err_ipc = -ECOMM, + st_err_peer = -ENOMSG, + st_err_unknown_operation = -EOPNOTSUPP, + st_err_unknown_device = -ENODEV, + st_err_none_available = -EHOSTUNREACH, + st_err_signal = -ECONNABORTED, + st_err_agent_fork = -ECHILD, + st_err_agent_args = -EREMOTEIO, + st_err_agent = -ECONNABORTED, + st_err_invalid_level = -EINVAL, +}; + + +enum lrmd_errors { + lrmd_ok = pcmk_ok, + lrmd_pending = -EINPROGRESS, + lrmd_err_generic = -EPROTONOSUPPORT, + lrmd_err_internal = -EPROTO, + lrmd_err_connection = -ENOTCONN, + lrmd_err_missing = -EINVAL, + lrmd_err_ipc = -ECOMM, + lrmd_err_peer = -ENOMSG, + lrmd_err_unknown_operation = -EOPNOTSUPP, + lrmd_err_unknown_rsc = -ENODEV, + lrmd_err_no_metadata = -EIO, + lrmd_err_stonith_connection = -EUNATCH, + lrmd_err_provider_required = -EINVAL, +}; + +#define stonith_error2string pcmk_strerror +#define lrmd_error2string pcmk_strerror +#define cib_error2string pcmk_strerror + +static inline void +slist_basic_destroy(GListPtr list) +{ + GListPtr gIter = NULL; + + for (gIter = list; gIter != NULL; gIter = gIter->next) { + free(gIter->data); + } + g_list_free(list); +} + +# define crm_malloc0(malloc_obj, length) do { \ + malloc_obj = malloc(length); \ + if(malloc_obj == NULL) { \ + crm_err("Failed allocation of %lu bytes", (unsigned long)length); \ + CRM_ASSERT(malloc_obj != NULL); \ + } \ + memset(malloc_obj, 0, length); \ + } while(0) + +# define crm_malloc(malloc_obj, length) do { \ + malloc_obj = malloc(length); \ + if(malloc_obj == NULL) { \ + crm_err("Failed allocation of %lu bytes", (unsigned long)length); \ + CRM_ASSERT(malloc_obj != NULL); \ + } \ + } while(0) + +# define crm_realloc(realloc_obj, length) do { \ + realloc_obj = realloc(realloc_obj, length); \ + CRM_ASSERT(realloc_obj != NULL); \ + } while(0) + +#define crm_free(free_obj) do { free(free_obj); free_obj=NULL; } while(0) + +/* These two child iterator macros are no longer to be used + * They exist for compatability reasons and will be removed in a + * future release + */ +# define xml_child_iter(parent, child, code) do { \ + if(parent != NULL) { \ + xmlNode *child = NULL; \ + xmlNode *__crm_xml_iter = parent->children; \ + while(__crm_xml_iter != NULL) { \ + child = __crm_xml_iter; \ + __crm_xml_iter = __crm_xml_iter->next; \ + if(child->type == XML_ELEMENT_NODE) { \ + code; \ + } \ + } \ + } \ + } while(0) + +# define xml_child_iter_filter(parent, child, filter, code) do { \ + if(parent != NULL) { \ + xmlNode *child = NULL; \ + xmlNode *__crm_xml_iter = parent->children; \ + while(__crm_xml_iter != NULL) { \ + child = __crm_xml_iter; \ + __crm_xml_iter = __crm_xml_iter->next; \ + if(child->type == XML_ELEMENT_NODE) { \ + if(filter == NULL \ + || crm_str_eq(filter, (const char *)child->name, TRUE)) { \ + code; \ + } \ + } \ + } \ + } \ + } while(0) + +#endif diff --git a/include/crm/logging.h b/include/crm/logging.h index 64ad118f2c..89e1838c33 100644 --- a/include/crm/logging.h +++ b/include/crm/logging.h @@ -1,169 +1,165 @@ /* * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #ifndef CRM_LOGGING__H # define CRM_LOGGING__H # include <qb/qblog.h> # ifndef LOG_TRACE # define LOG_TRACE LOG_DEBUG+1 # endif -# define LOG_DEBUG_2 LOG_TRACE -# define LOG_DEBUG_3 LOG_TRACE -# define LOG_DEBUG_4 LOG_TRACE -# define LOG_DEBUG_5 LOG_TRACE -# define LOG_DEBUG_6 LOG_TRACE extern unsigned int crm_log_level; extern gboolean crm_config_error; extern gboolean crm_config_warning; void crm_enable_blackbox(int nsig); void crm_enable_blackbox_tracing(int nsig); void crm_write_blackbox(int nsig); void crm_update_callsites(void); void crm_log_deinit(void); gboolean crm_log_cli_init(const char *entity); gboolean crm_log_init(const char *entity, int level, gboolean daemon, gboolean to_stderr, int argc, char **argv, gboolean quiet); void crm_log_args(int argc, char **argv); gboolean crm_add_logfile(const char *filename); void crm_bump_log_level(void); void crm_enable_stderr(int enable); /* returns the old value */ unsigned int set_crm_log_level(unsigned int level); unsigned int get_crm_log_level(void); /* * Throughout the macros below, note the leading, pre-comma, space in the * various ' , ##args' occurences to aid portability across versions of 'gcc'. * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros */ # define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name) # define do_crm_log(level, fmt, args...) do { \ qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, 0, ##args); \ if((level) < LOG_WARNING) { \ crm_write_blackbox(0); \ } \ } while(0) /* level /MUST/ be a constant or compilation will fail */ # define do_crm_log_unlikely(level, fmt, args...) do { \ static struct qb_log_callsite *trace_cs = NULL; \ if(trace_cs == NULL) { \ trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \ } \ if (trace_cs && trace_cs->targets) { \ qb_log_from_external_source( \ __func__, __FILE__, fmt, level, __LINE__, 0, ##args); \ } \ } while(0) # define CRM_LOG_ASSERT(expr) do { \ if(__unlikely((expr) == FALSE)) { \ static struct qb_log_callsite *core_cs = NULL; \ if(core_cs == NULL) { \ core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \ } \ crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \ core_cs?core_cs->targets:FALSE, TRUE); \ } \ } while(0) # define CRM_CHECK(expr, failure_action) do { \ if(__unlikely((expr) == FALSE)) { \ static struct qb_log_callsite *core_cs = NULL; \ if(core_cs == NULL) { \ core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \ } \ crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \ core_cs?core_cs->targets:FALSE, TRUE); \ failure_action; \ } \ } while(0) # define do_crm_log_xml(level, text, xml) do { \ static struct qb_log_callsite *xml_cs = NULL; \ if(xml_cs == NULL) { \ xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blog", level, __LINE__, 0); \ } \ if (xml_cs && xml_cs->targets) { \ log_data_element(level, __FILE__, __PRETTY_FUNCTION__, __LINE__, text, xml, 0, TRUE); \ } \ if((level) < LOG_WARNING) { \ crm_write_blackbox(0); \ } \ } while(0) # define do_crm_log_alias(level, file, function, line, fmt, args...) do { \ qb_log_from_external_source(function, file, fmt, level, line, 0, ##args); \ } while(0) # define do_crm_log_always(level, fmt, args...) qb_log(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args) # define crm_perror(level, fmt, args...) do { \ const char *err = strerror(errno); \ fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \ do_crm_log(level, fmt ": %s (%d)", ##args, err, errno); \ if((level) < LOG_WARNING) { \ crm_write_blackbox(0); \ } \ } while(0) # define crm_log_tag(level, tag, fmt, args...) do { \ qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, g_quark_try_string(tag), ##args); \ } while(0) # define crm_crit(fmt, args...) do { \ qb_logt(LOG_CRIT, 0, fmt , ##args); \ crm_write_blackbox(0); \ } while(0) # define crm_err(fmt, args...) do { \ qb_logt(LOG_ERR, 0, fmt , ##args); \ crm_write_blackbox(0); \ } while(0) # define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args) # define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args) # define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args) # define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args) # define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args) # define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml) # define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml) # define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml) # define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml) # define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml) # define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml) # define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml) # define crm_str(x) (const char*)(x?x:"<null>") #endif