From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12264 invoked by alias); 12 May 2009 17:41:26 -0000 Received: (qmail 12256 invoked by alias); 12 May 2009 17:41:26 -0000 X-SWARE-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_33,J_CHICKENPOX_36,J_CHICKENPOX_42,J_CHICKENPOX_46,J_CHICKENPOX_65,J_CHICKENPOX_66,J_CHICKENPOX_73,SPF_HELO_PASS X-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_33,J_CHICKENPOX_36,J_CHICKENPOX_42,J_CHICKENPOX_46,J_CHICKENPOX_65,J_CHICKENPOX_66,J_CHICKENPOX_73,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bastion2.fedora.phx.redhat.com Subject: cluster: STABLE3 - cman: fix logging config and major cleanup To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: cluster.git X-Git-Refname: refs/heads/STABLE3 X-Git-Reftype: branch X-Git-Oldrev: 2d3ef0cbd850d08cab4584d98b828c37100a240f X-Git-Newrev: ed02ac5f4275e1a8e26c8639880e928b747b44f1 From: "Fabio M. Di Nitto" Message-Id: <20090512174059.2A37E120277@lists.fedorahosted.org> Date: Tue, 12 May 2009 17:41:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q2/txt/msg00298.txt.bz2 Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=ed02ac5f4275e1a8e26c8639880e928b747b44f1 Commit: ed02ac5f4275e1a8e26c8639880e928b747b44f1 Parent: 2d3ef0cbd850d08cab4584d98b828c37100a240f Author: Fabio M. Di Nitto AuthorDate: Tue May 12 19:37:08 2009 +0200 Committer: Fabio M. Di Nitto CommitterDate: Tue May 12 19:37:08 2009 +0200 cman: fix logging config and major cleanup - entirely remove all the P_ macro that are now unrequired - kill debug_mask concept and use logsys config backend to transport logging config info - CMAN_DEBUG does not need any special value. Anything >1 will enable debug - add simple code to sanitize CMAN_DEBUG values in input and retain compat with older versions of cman_tool - simplify a lot find_cman_logger as it doesn't need to create a cman entry anymore - fix all of cman-preconfig to set logsys correctly with the new logging standards - remove duplicate logging entries Signed-off-by: Fabio M. Di Nitto --- cman/daemon/Makefile | 1 - cman/daemon/ais.c | 15 ++---- cman/daemon/barrier.c | 13 +++--- cman/daemon/cman-preconfig.c | 103 ++++++++++++++++++++++++------------------ cman/daemon/cmanconfig.c | 3 +- cman/daemon/commands.c | 81 ++++++++++++++++----------------- cman/daemon/daemon.c | 33 +++++++------- cman/daemon/logging.c | 29 ------------ cman/daemon/logging.h | 17 ------- 9 files changed, 127 insertions(+), 168 deletions(-) diff --git a/cman/daemon/Makefile b/cman/daemon/Makefile index f97c56f..9a495eb 100644 --- a/cman/daemon/Makefile +++ b/cman/daemon/Makefile @@ -18,7 +18,6 @@ CFLAGS += -I${incdir} LDFLAGS += -L${libdir} OBJS1= daemon.o \ - logging.o \ ais.o \ commands.o \ barrier.o \ diff --git a/cman/daemon/ais.c b/cman/daemon/ais.c index 598bff7..6bd0d81 100644 --- a/cman/daemon/ais.c +++ b/cman/daemon/ais.c @@ -31,7 +31,6 @@ #include "cnxman-socket.h" #include "cnxman-private.h" #include "commands.h" -#include "logging.h" #include "ais.h" #include "cman.h" @@ -57,7 +56,6 @@ extern unsigned int config_version; static hdb_handle_t cluster_parent_handle; static int startup_pipe; -static unsigned int debug_mask; static int first_trans = 1; struct corosync_api_v1 *corosync; @@ -185,13 +183,10 @@ static int cman_exec_init_fn(struct corosync_api_v1 *api) objdb_get_int(api, object_handle, "quorum_dev_poll", &quorumdev_poll, DEFAULT_QUORUMDEV_POLL); objdb_get_int(api, object_handle, "shutdown_timeout", &shutdown_timeout, DEFAULT_SHUTDOWN_TIMEOUT); objdb_get_int(api, object_handle, "ccsd_poll", &ccsd_poll_interval, DEFAULT_CCSD_POLL); - objdb_get_int(api, object_handle, "debug_mask", &debug_mask, 0); - /* All other debugging options should already have been set in preconfig */ - set_debuglog(debug_mask); } corosync->object_find_destroy(find_handle); - P_DAEMON(CMAN_NAME " starting"); + log_printf(LOGSYS_LEVEL_DEBUG, CMAN_NAME " starting"); /* Open local sockets and initialise I/O queues */ if (read_cman_config(api, &config_version)) { @@ -231,7 +226,7 @@ int comms_send_message(void *buf, int len, struct cl_protheader header; int totem_flags = TOTEM_AGREED; - P_AIS("comms send message %p len = %d\n", buf,len); + log_printf(LOGSYS_LEVEL_DEBUG, "ais: comms send message %p len = %d\n", buf,len); header.tgtport = toport; header.srcport = fromport; header.flags = flags; @@ -256,7 +251,7 @@ static void cman_deliver_fn(unsigned int nodeid, const void *msg, unsigned int m struct cl_protheader header; const char *buf = msg; - P_AIS("deliver_fn source nodeid = %d, len=%d, endian_conv=%d\n", + log_printf(LOGSYS_LEVEL_DEBUG, "ais: deliver_fn source nodeid = %d, len=%d, endian_conv=%d\n", nodeid, msg_len, endian_conversion_required); if (endian_conversion_required) { @@ -290,7 +285,7 @@ static void cman_confchg_fn(enum totem_configuration_type configuration_type, static size_t saved_left_list_size; static unsigned int *saved_left_list = NULL; - P_AIS("confchg_fn called type = %d, seq=%lld\n", configuration_type, ring_id->seq); + log_printf(LOGSYS_LEVEL_DEBUG, "ais: confchg_fn called type = %d, seq=%lld\n", configuration_type, ring_id->seq); memcpy(&cman_ring_id, ring_id, sizeof(*ring_id)); incarnation = ring_id->seq; @@ -327,7 +322,7 @@ static void cman_confchg_fn(enum totem_configuration_type configuration_type, } if (configuration_type == TOTEM_CONFIGURATION_REGULAR) { - P_AIS("last memb_count = %d, current = %"PRIuFAST32"\n", last_memb_count, member_list_entries); + log_printf(LOGSYS_LEVEL_DEBUG, "ais: last memb_count = %d, current = %"PRIuFAST32"\n", last_memb_count, member_list_entries); send_transition_msg(last_memb_count, first_trans); last_memb_count = member_list_entries; if (member_list_entries > 1) diff --git a/cman/daemon/barrier.c b/cman/daemon/barrier.c index 1f414aa..f4362cf 100644 --- a/cman/daemon/barrier.c +++ b/cman/daemon/barrier.c @@ -28,7 +28,6 @@ #include "cnxman-private.h" #include "daemon.h" #include "commands.h" -#include "logging.h" #include "barrier.h" #include "cman.h" #include "ais.h" @@ -104,7 +103,7 @@ static void check_barrier_complete_phase1(struct cl_barrier *barrier) bmsg.subcmd = BARRIER_COMPLETE; strcpy(bmsg.name, barrier->name); - P_BARRIER("Sending COMPLETE for %s\n", barrier->name); + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: Sending COMPLETE for %s\n", barrier->name); comms_send_message((char *) &bmsg, sizeof (bmsg), 0, 0, 0, @@ -116,7 +115,7 @@ static void check_barrier_complete_phase1(struct cl_barrier *barrier) /* Return 1 if we deleted the barrier */ static int barrier_complete_phase2(struct cl_barrier *barrier, int status) { - P_BARRIER("complete_phase2 for %s\n", barrier->name); + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: complete_phase2 for %s\n", barrier->name); barrier->endreason = status; @@ -141,7 +140,7 @@ static void barrier_timer_fn(void *arg) { struct cl_barrier *barrier = arg; - P_BARRIER("Barrier timer_fn called for %s\n", barrier->name); + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: Barrier timer_fn called for %s\n", barrier->name); /* Ignore any futher messages, they are too late. */ barrier->phase = 0; @@ -186,7 +185,7 @@ void process_barrier_msg(struct cl_barriermsg *msg, if (!barrier) return; - P_BARRIER("Got %d for %s, from node %s\n", msg->subcmd, msg->name, + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: Got %d for %s, from node %s\n", msg->subcmd, msg->name, node ? node->name : "unknown"); switch (msg->subcmd) { @@ -228,7 +227,7 @@ static int barrier_register(struct connection *con, char *name, unsigned int fla if (flags & BARRIER_ATTR_MULTISTEP) return -EINVAL; - P_BARRIER("barrier_register %s, nodes = %d, flags =%x\n", name, nodes, flags); + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: barrier_register %s, nodes = %d, flags =%x\n", name, nodes, flags); /* See if it already exists */ if ((barrier = find_barrier(name))) { @@ -282,7 +281,7 @@ static int barrier_setattr_enabled(struct cl_barrier *barrier, barrier_timer_fn, &barrier->timer); } - P_BARRIER("Sending WAIT for %s\n", barrier->name); + log_printf(LOGSYS_LEVEL_DEBUG, "barrier: Sending WAIT for %s\n", barrier->name); status = comms_send_message((char *)&bmsg, sizeof(bmsg), 0,0, 0, MSG_TOTEM_SAFE); if (status < 0) { return status; diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c index 6f0ccf3..6221169 100644 --- a/cman/daemon/cman-preconfig.c +++ b/cman/daemon/cman-preconfig.c @@ -24,11 +24,10 @@ #define OBJDB_API struct objdb_iface_ver0 #include "cnxman-socket.h" #include "nodelist.h" -#include "logging.h" #define MAX_PATH_LEN PATH_MAX -static unsigned int debug_mask; +static unsigned int debug; static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, const char **error_string); static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const char **error_string); @@ -203,25 +202,17 @@ static hdb_handle_t find_cman_logger(struct objdb_iface_ver0 *objdb, hdb_handle_ char *str; objdb->object_find_create(object_handle, "logger_subsys", strlen("logger_subsys"), &find_handle); - while (!objdb->object_find_next(object_handle, &subsys_handle)) { - - if (objdb_get_string(objdb, subsys_handle, "subsys", &str)) { - continue; + while (!objdb->object_find_next(find_handle, &subsys_handle)) { + if (!objdb_get_string(objdb, subsys_handle, "subsys", &str)) { + if (strncmp(str, CMAN_NAME, 4) == 0) { + objdb->object_find_destroy(find_handle); + return subsys_handle; + } } - if (strcmp(str, CMAN_NAME) == 0) - return subsys_handle; } objdb->object_find_destroy(find_handle); - /* We can't find it ... create one */ - if (objdb->object_create(object_handle, &subsys_handle, - "logger_subsys", strlen("logger_subsys")) == 0) { - - objdb->object_key_create(subsys_handle, "subsys", strlen("subsys"), - CMAN_NAME, strlen(CMAN_NAME)+1); - } - - return subsys_handle; + return -1; } @@ -503,7 +494,9 @@ static int get_env_overrides(void) votes = 1; } if (getenv("CMAN_DEBUG")) { - debug_mask = atoi(getenv("CMAN_DEBUG")); + debug = atoi(getenv("CMAN_DEBUG")); + if (debug > 0) + debug = 1; } return 0; @@ -644,9 +637,9 @@ out: /* These are basically cman overrides to the totem config bits */ static void add_cman_overrides(struct objdb_iface_ver0 *objdb) { - hdb_handle_t logger_object_handle; char *logstr; char *logfacility; + char *loglevel; hdb_handle_t object_handle; hdb_handle_t find_handle; char tmp[256]; @@ -745,16 +738,17 @@ static void add_cman_overrides(struct objdb_iface_ver0 *objdb) objdb->object_find_destroy(find_handle); logfacility = facility_name_get(SYSLOGFACILITY); + loglevel = priority_name_get(SYSLOGLEVEL); - logger_object_handle = find_cman_logger(objdb, object_handle); - - if (objdb_get_string(objdb, object_handle, "syslog_facility", &logstr)) { - objdb->object_key_create(object_handle, "syslog_facility", strlen("syslog_facility"), - logfacility, strlen(logfacility)+1); + /* enable timestamps on logging */ + if (objdb_get_string(objdb, object_handle, "timestamp", &logstr)) { + objdb->object_key_create(object_handle, "timestamp", strlen("timestamp"), + "on", strlen("on")+1); } - if (objdb_get_string(objdb, object_handle, "to_file", &logstr)) { - objdb->object_key_create(object_handle, "to_file", strlen("to_file"), + /* configure logfile */ + if (objdb_get_string(objdb, object_handle, "to_logfile", &logstr)) { + objdb->object_key_create(object_handle, "to_logfile", strlen("to_logfile"), "yes", strlen("yes")+1); } @@ -763,27 +757,53 @@ static void add_cman_overrides(struct objdb_iface_ver0 *objdb) LOGDIR "/corosync.log", strlen(LOGDIR "/corosync.log")+1); } - if (objdb_get_string(objdb, object_handle, "timestamp", &logstr)) { - objdb->object_key_create(object_handle, "timestamp", strlen("timestamp"), - "on", strlen("on")+1); + if (objdb_get_string(objdb, object_handle, "logfile_priority", &logstr)) { + objdb->object_key_create(object_handle, "logfile_priority", strlen("logfile_priority"), + loglevel, strlen(loglevel)+1); } - if (debug_mask) { - objdb->object_key_create(object_handle, "to_stderr", strlen("to_stderr"), + /* syslog */ + if (objdb_get_string(objdb, object_handle, "to_syslog", &logstr)) { + objdb->object_key_create(object_handle, "to_syslog", strlen("to_syslog"), "yes", strlen("yes")+1); - objdb->object_key_create(logger_object_handle, "debug", strlen("debug"), - "on", strlen("on")+1); - objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"), - "debug", strlen("debug")+1); + } + if (objdb_get_string(objdb, object_handle, "syslog_facility", &logstr)) { + objdb->object_key_create(object_handle, "syslog_facility", strlen("syslog_facility"), + logfacility, strlen(logfacility)+1); } - else { - char *loglevel; - loglevel = priority_name_get(SYSLOGLEVEL); - objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"), + + if (objdb_get_string(objdb, object_handle, "syslog_priority", &logstr)) { + objdb->object_key_create(object_handle, "syslog_priority", strlen("syslog_priority"), loglevel, strlen(loglevel)+1); } + if (!debug) { + hdb_handle_t logger_object_handle; + + if (!objdb_get_string(objdb, object_handle, "debug", &logstr)) { + if (!strncmp(logstr, "on", 2)) { + debug=1; + } + } + + logger_object_handle = find_cman_logger(objdb, object_handle); + if (logger_object_handle > -1) { + if (!objdb_get_string(objdb, logger_object_handle, "debug", &logstr)) { + if (!strncmp(logstr, "on", 2)) { + debug=1; + } + if (!strncmp(logstr, "off", 3)) { + debug=0; + } + } + } + } + + if (debug) { + objdb->object_key_create(object_handle, "to_stderr", strlen("to_stderr"), + "yes", strlen("yes")+1); + } /* Make sure we allow connections from user/group "ais" */ objdb->object_find_create(OBJECT_PARENT_HANDLE, "aisexec", strlen("aisexec"), &find_handle); @@ -812,11 +832,6 @@ static void add_cman_overrides(struct objdb_iface_ver0 *objdb) objdb->object_key_create(object_handle, "two_node", strlen("two_node"), str, strlen(str) + 1); } - if (debug_mask) { - sprintf(str, "%d", debug_mask); - objdb->object_key_create(object_handle, "debug_mask", strlen("debug_mask"), - str, strlen(str) + 1); - } } objdb->object_find_destroy(find_handle); diff --git a/cman/daemon/cmanconfig.c b/cman/daemon/cmanconfig.c index 8c3f864..4a82525 100644 --- a/cman/daemon/cmanconfig.c +++ b/cman/daemon/cmanconfig.c @@ -18,7 +18,6 @@ #include "list.h" #include "cnxman-socket.h" #include "cnxman-private.h" -#include "logging.h" #include "commands.h" #include "cman.h" #define OBJDB_API struct corosync_api_v1 @@ -100,7 +99,7 @@ int read_cman_nodes(struct corosync_api_v1 *corosync, unsigned int *config_versi goto out_err; } - P_MEMB("Got node %s from ccs (id=%d, votes=%d)\n", nodename, this_nodeid, votes); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Got node %s from ccs (id=%d, votes=%d)\n", nodename, this_nodeid, votes); add_ccs_node(nodename, this_nodeid, votes, expected); nodes_handle = nodeslist_next(corosync, find_handle); } while (nodes_handle); diff --git a/cman/daemon/commands.c b/cman/daemon/commands.c index 11d72e6..75b41fe 100644 --- a/cman/daemon/commands.c +++ b/cman/daemon/commands.c @@ -33,7 +33,6 @@ #include "cnxman-private.h" #include "daemon.h" #include "barrier.h" -#include "logging.h" #define OBJDB_API struct corosync_api_v1 #include "cmanconfig.h" #include "nodelist.h" @@ -287,7 +286,7 @@ static struct cluster_node *add_new_node(char *name, int nodeid, int votes, int newname = strdup(name); if (newname) { - P_MEMB("replacing old node name %s with %s\n", newnode->name, name); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: replacing old node name %s with %s\n", newnode->name, name); free(newnode->name); newnode->name = newname; } @@ -298,7 +297,7 @@ static struct cluster_node *add_new_node(char *name, int nodeid, int votes, int newnode->flags |= NODE_FLAGS_REREAD; - P_MEMB("add_new_node: %s, (id=%d, votes=%d) newalloc=%d\n", + log_printf(LOGSYS_LEVEL_DEBUG, "memb: add_new_node: %s, (id=%d, votes=%d) newalloc=%d\n", name, nodeid, votes, newalloc); return newnode; @@ -542,7 +541,7 @@ static int do_cmd_get_extrainfo(char *cmdbuf, char **retbuf, int retsize, int *r outbuf = *retbuf + offset; einfo = (struct cl_extra_info *)outbuf; - P_MEMB("get_extrainfo: allocated new buffer\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: get_extrainfo: allocated new buffer\n"); } einfo->node_state = us->state; @@ -634,7 +633,7 @@ static int do_cmd_get_all_members(char *cmdbuf, char **retbuf, int retsize, int if ((retsize / sizeof(struct cl_cluster_node)) < total_nodes) { *retbuf = malloc(sizeof(struct cl_cluster_node) * total_nodes + offset); outbuf = *retbuf + offset; - P_MEMB("get_all_members: allocated new buffer (retsize=%d)\n", retsize); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: get_all_members: allocated new buffer (retsize=%d)\n", retsize); } } user_node = (struct cl_cluster_node *)outbuf; @@ -656,7 +655,7 @@ static int do_cmd_get_all_members(char *cmdbuf, char **retbuf, int retsize, int } *retlen = sizeof(struct cl_cluster_node) * num_nodes; - P_MEMB("get_all_members: retlen = %d\n", *retlen); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: get_all_members: retlen = %d\n", *retlen); return num_nodes; } @@ -698,7 +697,7 @@ static int do_cmd_get_node(char *cmdbuf, char *retbuf, int *retlen) node = find_node_by_name(u_node->name); if (!node) { - P_MEMB("cmd_get_node failed: id=%d, name='%s'\n", u_node->node_id, u_node->name); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: cmd_get_node failed: id=%d, name='%s'\n", u_node->node_id, u_node->name); return -ENOENT; } } @@ -780,7 +779,7 @@ static void send_kill(int nodeid, uint16_t reason) { struct cl_killmsg msg; - P_MEMB("Sending KILL to node %d\n", nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Sending KILL to node %d\n", nodeid); msg.cmd = CLUSTER_MSG_KILLNODE; msg.reason = reason; @@ -796,7 +795,7 @@ static void send_leave(uint16_t reason) { struct cl_leavemsg msg; - P_MEMB("Sending LEAVE, reason %d\n", reason); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Sending LEAVE, reason %d\n", reason); msg.cmd = CLUSTER_MSG_LEAVE; msg.reason = reason; @@ -868,14 +867,14 @@ static int do_cmd_islistening(struct connection *con, char *cmdbuf, int *retlen) a cluster that has been running for a while */ if (!get_port_bit(rem_node, 0)) { - P_MEMB("islistening, no data for node %d, sending PORTENQ\n", nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: islistening, no data for node %d, sending PORTENQ\n", nodeid); send_port_enquire(rem_node->node_id); /* Admit our ignorance */ return -EBUSY; } else { - P_MEMB("islistening, for node %d, low bytes are %x %x\n", nodeid, rem_node->port_bits[0], rem_node->port_bits[1]); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: islistening, for node %d, low bytes are %x %x\n", nodeid, rem_node->port_bits[0], rem_node->port_bits[1]); return get_port_bit(rem_node, rq.port); } } @@ -897,7 +896,7 @@ static int do_cmd_set_votes(char *cmdbuf, int *retlen) if (!arg.nodeid) arg.nodeid = us->node_id; - P_MEMB("Setting votes for node %d to %d\n", arg.nodeid, arg.newvotes); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Setting votes for node %d to %d\n", arg.nodeid, arg.newvotes); node = find_node_by_nodeid(arg.nodeid); if (!node) @@ -928,7 +927,7 @@ static int do_cmd_bind(struct connection *con, char *cmdbuf) memcpy(&port, cmdbuf, sizeof(int)); - P_MEMB("requested bind to port %d, (us=%p)\n", port, con); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: requested bind to port %d, (us=%p)\n", port, con); if (port == 0 || port > 255) return -EINVAL; @@ -1004,14 +1003,14 @@ static void check_shutdown_status(void) shutdown_con = NULL; } - P_MEMB("shutdown decision is: %d (yes=%d, no=%d) flags=%x\n", reply, shutdown_yes, shutdown_no, shutdown_flags); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: shutdown decision is: %d (yes=%d, no=%d) flags=%x\n", reply, shutdown_yes, shutdown_no, shutdown_flags); } } /* Not all nodes responded to the shutdown */ static void shutdown_timer_fn(void *arg) { - P_MEMB("Shutdown timer fired. flags = %x\n", shutdown_flags); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Shutdown timer fired. flags = %x\n", shutdown_flags); /* Mark undecideds as "NO" */ shutdown_no = shutdown_expected; @@ -1027,7 +1026,7 @@ static int do_cmd_shutdown_reply(struct connection *con, char *cmdbuf) if (!shutdown_con) return -EWOULDBLOCK; - P_MEMB("Shutdown reply is %d\n", response); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Shutdown reply is %d\n", response); /* We only need to keep a track of a client's response in case it pulls the connection before the shutdown process @@ -1200,7 +1199,7 @@ static void quorum_device_timer_fn(void *arg) if (!quorum_device || quorum_device->state == NODESTATE_DEAD) return; - P_MEMB("quorum_device_timer_fn\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: quorum_device_timer_fn\n"); gettimeofday(&now, NULL); if (quorum_device->last_hello.tv_sec + quorumdev_poll/1000 < now.tv_sec) { quorum_device->state = NODESTATE_DEAD; @@ -1270,7 +1269,7 @@ static int do_cmd_update_fence_info(char *cmdbuf) strcpy(fence_msg->agent, f->fence_agent); comms_send_message(msg, sizeof(msg), 0,0, 0, 0); - P_MEMB("node %d fenced by %s\n", f->nodeid, f->fence_agent); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: node %d fenced by %s\n", f->nodeid, f->fence_agent); return 0; } @@ -1350,7 +1349,7 @@ int process_command(struct connection *con, int cmd, char *cmdbuf, char *outbuf = *retbuf; int value; - P_MEMB("command to process is %x\n", cmd); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: command to process is %x\n", cmd); switch (cmd) { @@ -1376,7 +1375,11 @@ int process_command(struct connection *con, int cmd, char *cmdbuf, case CMAN_CMD_SET_DEBUGLOG: memcpy(&value, cmdbuf, sizeof(int)); - set_debuglog(value); + /* sanitize input value */ + if (value > 0) + value = 1; + + logsys_config_debug_set(CMAN_NAME, value); err = 0; break; case CMAN_CMD_START_CONFCHG: @@ -1504,7 +1507,7 @@ int process_command(struct connection *con, int cmd, char *cmdbuf, err = do_cmd_get_node_addrs(cmdbuf, retbuf, retsize, retlen, offset); break; } - P_MEMB("command return code is %d\n", err); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: command return code is %d\n", err); return err; } @@ -1533,7 +1536,7 @@ int send_to_userport(unsigned char fromport, unsigned char toport, if (port_array[toport]) { struct connection *c = port_array[toport]; - P_MEMB("send_to_userport. cmd=%d, endian_conv=%d\n", recv_buf[0],endian_conv); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: send_to_userport. cmd=%d, endian_conv=%d\n", recv_buf[0],endian_conv); send_data_reply(c, nodeid, fromport, recv_buf, len); ret = 0; @@ -1604,7 +1607,7 @@ static int send_port_open_msg(unsigned char port) void unbind_con(struct connection *con) { if (con->port) { - P_MEMB("Unbinding con for port %d\n", con->port); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Unbinding con for port %d\n", con->port); port_array[con->port] = NULL; send_port_close_msg(con->port); clear_port_bit(us, con->port); @@ -1705,7 +1708,7 @@ void send_transition_msg(int last_memb_count, int first_trans) we_are_a_cluster_member = 1; - P_MEMB("sending TRANSITION message. cluster_name = %s\n", cluster_name); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: sending TRANSITION message. cluster_name = %s\n", cluster_name); msg->cmd = CLUSTER_MSG_TRANSITION; msg->first_trans = first_trans; msg->votes = us->votes; @@ -1842,7 +1845,7 @@ static void do_fence_msg(void *data) struct cl_fencemsg *msg = data; struct cluster_node *node; - P_DAEMON("got FENCE message, node %d fenced by %s\n", msg->nodeid, msg->agent); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: got FENCE message, node %d fenced by %s\n", msg->nodeid, msg->agent); node = find_node_by_nodeid(msg->nodeid); if (!node) @@ -1869,7 +1872,7 @@ static void do_process_transition(int nodeid, char *data) nodestate_t old_state; if (valid_transition_msg(nodeid, msg) != 0) { - P_MEMB("Transition message from %d does not match current config - should quit ?\n", nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Transition message from %d does not match current config - should quit ?\n", nodeid); // Now what ?? return; } @@ -1893,7 +1896,7 @@ static void do_process_transition(int nodeid, char *data) old_expected = node->expected_votes; old_state = node->state; - P_MEMB("Got TRANSITION message. msg->flags=%x, node->flags=%x, first_trans=%d\n", + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Got TRANSITION message. msg->flags=%x, node->flags=%x, first_trans=%d\n", msg->flags, node->flags, msg->first_trans); /* Newer nodes 6.1.0 onwards, set the DIRTY flag if they have state. If the new node has been down @@ -1903,13 +1906,11 @@ static void do_process_transition(int nodeid, char *data) /* Don't duplicate messages */ if (node->state != NODESTATE_AISONLY) { if (cluster_is_quorate) { - P_MEMB("Killing node %s because it has rejoined the cluster with existing state", node->name); log_printf(LOG_CRIT, "Killing node %s because it has rejoined the cluster with existing state", node->name); node->state = NODESTATE_AISONLY; send_kill(nodeid, CLUSTER_KILL_REJOIN); } else { - P_MEMB("Node %s not joined to cman because it has existing state", node->name); log_printf(LOG_CRIT, "Node %s not joined to cman because it has existing state", node->name); node->state = NODESTATE_AISONLY; } @@ -1924,13 +1925,11 @@ static void do_process_transition(int nodeid, char *data) /* Don't duplicate messages */ if (node->state != NODESTATE_AISONLY) { if (cluster_is_quorate) { - P_MEMB("Killing node %s because it has rejoined the cluster without cman_tool join", node->name); log_printf(LOG_CRIT, "Killing node %s because it has rejoined the cluster without cman_tool join", node->name); node->state = NODESTATE_AISONLY; send_kill(nodeid, CLUSTER_KILL_REJOIN); } else { - P_MEMB("Node %s not joined to cman because it has rejoined an inquorate cluster", node->name); log_printf(LOG_CRIT, "Node %s not joined to cman because it has rejoined an inquorate cluster", node->name); node->state = NODESTATE_AISONLY; } @@ -1992,7 +1991,7 @@ static void process_internal_message(char *data, int nodeid, int need_byteswap) struct cluster_node *node = find_node_by_nodeid(nodeid); unsigned char portresult[PORT_BITS_SIZE+1]; - P_MEMB("Message on port 0 is %d\n", msg->cmd); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Message on port 0 is %d\n", msg->cmd); /* Byteswap messages if needed */ if (need_byteswap) @@ -2016,7 +2015,7 @@ static void process_internal_message(char *data, int nodeid, int need_byteswap) case CLUSTER_MSG_PORTENQ: portresult[0] = CLUSTER_MSG_PORTSTATUS; memcpy(portresult+1, us->port_bits, PORT_BITS_SIZE); - P_MEMB("Sending PORTRESULT, low bytes = %x %x\n", us->port_bits[0], us->port_bits[1]); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Sending PORTRESULT, low bytes = %x %x\n", us->port_bits[0], us->port_bits[1]); /* Broadcast reply as other new nodes may be interested */ comms_send_message(portresult, PORT_BITS_SIZE+1, 0,0, 0, 0); @@ -2024,20 +2023,20 @@ static void process_internal_message(char *data, int nodeid, int need_byteswap) case CLUSTER_MSG_PORTSTATUS: if (nodeid != us->node_id) { - P_MEMB("got PORTRESULT from %d, low bytes = %x %x\n", nodeid, data[1], data[2]); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: got PORTRESULT from %d, low bytes = %x %x\n", nodeid, data[1], data[2]); if (node) memcpy(node->port_bits, data+1, PORT_BITS_SIZE); } break; case CLUSTER_MSG_TRANSITION: - P_MEMB("got TRANSITION from node %d\n", nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: got TRANSITION from node %d\n", nodeid); do_process_transition(nodeid, data); break; case CLUSTER_MSG_KILLNODE: killmsg = (struct cl_killmsg *)data; - P_MEMB("got KILL for node %d\n", killmsg->nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: got KILL for node %d\n", killmsg->nodeid); if (killmsg->nodeid == wanted_nodeid) { /* Must use syslog directly here or the message will never arrive */ syslog(LOG_CRIT, "cman killed by node %d because %s\n", nodeid, @@ -2049,7 +2048,7 @@ static void process_internal_message(char *data, int nodeid, int need_byteswap) case CLUSTER_MSG_LEAVE: leavemsg = (struct cl_leavemsg *)data; - P_MEMB("got LEAVE from node %d, reason = %d\n", nodeid, leavemsg->reason); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: got LEAVE from node %d, reason = %d\n", nodeid, leavemsg->reason); /* We got our own leave message back. now quit */ if (node && node->node_id == us->node_id) { @@ -2142,12 +2141,12 @@ void add_ais_node(int nodeid, uint64_t incar, int total_members) { struct cluster_node *node; - P_MEMB("add_ais_node ID=%d, incarnation = %" PRIu64 "\n",nodeid, incar); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: add_ais_node ID=%d, incarnation = %" PRIu64 "\n",nodeid, incar); node = find_node_by_nodeid(nodeid); if (!node && total_members == 1) { node = us; - P_MEMB("Adding AIS node for 'us'\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: Adding AIS node for 'us'\n"); } /* This really should exist!! */ @@ -2173,7 +2172,7 @@ void del_ais_node(int nodeid) { struct cluster_node *node; time_t t; - P_MEMB("del_ais_node %d\n", nodeid); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: del_ais_node %d\n", nodeid); node = find_node_by_nodeid(nodeid); if (!node) @@ -2209,7 +2208,7 @@ void del_ais_node(int nodeid) memset(&node->port_bits, 0, sizeof(node->port_bits)); cluster_members--; - P_MEMB("del_ais_node %s, leave_reason=%x\n", node->name, node->leave_reason); + log_printf(LOGSYS_LEVEL_DEBUG, "memb: del_ais_node %s, leave_reason=%x\n", node->name, node->leave_reason); if ((node->leave_reason & 0xF) == CLUSTER_LEAVEFLAG_REMOVED) recalculate_quorum(1, 1); else diff --git a/cman/daemon/daemon.c b/cman/daemon/daemon.c index 326c828..cfaea2d 100644 --- a/cman/daemon/daemon.c +++ b/cman/daemon/daemon.c @@ -30,7 +30,6 @@ #include "cnxman-socket.h" #include "cnxman-private.h" #include "daemon.h" -#include "logging.h" #include "commands.h" #include "barrier.h" #include "ais.h" @@ -64,7 +63,7 @@ static int send_reply_message(struct connection *con, struct sock_header *msg) { int ret; - P_DAEMON("sending reply %x to fd %d\n", msg->command, con->fd); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: sending reply %x to fd %d\n", msg->command, con->fd); /* If there are already queued messages then don't send this one out of order */ @@ -82,7 +81,7 @@ static int send_reply_message(struct connection *con, struct sock_header *msg) /* Have we exceeded the allowed number of queued messages ? */ if (con->num_write_msgs > max_outstanding_messages) { - P_DAEMON("Disconnecting. client has more that %d replies outstanding (%d)\n", max_outstanding_messages, con->num_write_msgs); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: Disconnecting. client has more that %d replies outstanding (%d)\n", max_outstanding_messages, con->num_write_msgs); remove_client(cs_poll_handle, con); return -1; } @@ -101,7 +100,7 @@ static int send_reply_message(struct connection *con, struct sock_header *msg) qm->offset = 0; list_add(&con->write_msgs, &qm->list); con->num_write_msgs++; - P_DAEMON("queued last message, count is %d\n", con->num_write_msgs); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: queued last message, count is %d\n", con->num_write_msgs); poll_dispatch_modify(cs_poll_handle, con->fd, POLLIN | POLLOUT, process_client); } return 0; @@ -129,7 +128,7 @@ static void remove_client(hdb_handle_t handle, struct connection *con) msgs++; } - P_DAEMON("Freed %d queued messages\n", msgs); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: Freed %d queued messages\n", msgs); free(con); num_connections--; } @@ -161,7 +160,7 @@ static void send_queued_reply(struct connection *con) } if (list_empty(&con->write_msgs)) { /* Remove POLLOUT callback */ - P_DAEMON("Removing POLLOUT from fd %d\n", con->fd); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: Removing POLLOUT from fd %d\n", con->fd); poll_dispatch_modify(cs_poll_handle, con->fd, POLLIN, process_client); } } @@ -183,7 +182,7 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) len = read(fd, buf, sizeof(struct sock_header)); - P_DAEMON("read %d bytes from fd %d\n", len, fd); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: read %d bytes from fd %d\n", len, fd); if (len == 0) { remove_client(handle, con); @@ -200,17 +199,17 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) } if (msg->magic != CMAN_MAGIC) { - P_DAEMON("bad magic in client command %x\n", msg->magic); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: bad magic in client command %x\n", msg->magic); send_status_return(con, msg->command, -EINVAL); return 0; } if (msg->version != CMAN_VERSION) { - P_DAEMON("bad version in client command. msg = 0x%x, us = 0x%x\n", msg->version, CMAN_VERSION); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: bad version in client command. msg = 0x%x, us = 0x%x\n", msg->version, CMAN_VERSION); send_status_return(con, msg->command, -EINVAL); return 0; } if ((msg->length-len) > MAX_CLUSTER_MESSAGE) { - P_DAEMON("message on socket is too big\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: message on socket is too big\n"); send_status_return(con, msg->command, -EINVAL); return 0; } @@ -234,11 +233,11 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) totallen += len; } - P_DAEMON("client command is %x\n", msg->command); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: client command is %x\n", msg->command); /* Privileged functions can only be done on ADMIN sockets */ if (msg->command & CMAN_CMDFLAG_PRIV && con->type != CON_ADMIN) { - P_DAEMON("command disallowed from non-admin client\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: command disallowed from non-admin client\n"); send_status_return(con, msg->command, -EPERM); return 0; } @@ -249,7 +248,7 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) */ if ((msg->command == CMAN_CMD_DATA || msg->command == CMAN_CMD_BIND || msg->command == CMAN_CMD_NOTIFY) && con->type == CON_ADMIN) { - P_DAEMON("can't send data down an admin socket, sorry\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: can't send data down an admin socket, sorry\n"); send_status_return(con, msg->command, -EINVAL); return 0; } @@ -260,7 +259,7 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) uint8_t port; struct sock_data_header *dmsg = (struct sock_data_header *)msg; - P_DAEMON("sending %lu bytes of data to node %d, port %d\n", + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: sending %lu bytes of data to node %d, port %d\n", (unsigned long)(msg->length - sizeof(struct sock_data_header)), dmsg->nodeid, dmsg->port); databuf += sizeof(struct sock_data_header); @@ -291,7 +290,7 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) int ret; int retlen = 0; - P_DAEMON("About to process command\n"); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: About to process command\n"); cmdbuf += sizeof(struct sock_header); @@ -311,7 +310,7 @@ static int process_client(hdb_handle_t handle, int fd, int revent, void *data) reply->header.length = retlen + sizeof(struct sock_reply_header); reply->status = ret; - P_DAEMON("Returning command data. length = %d\n", retlen); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: Returning command data. length = %d\n", retlen); send_reply_message(con, (struct sock_header *)reply); if (retbuf != small_retbuf) @@ -415,7 +414,7 @@ int send_status_return(struct connection *con, uint32_t cmd, int status) { struct sock_reply_header msg; - P_DAEMON("send status return: %d\n", status); + log_printf(LOGSYS_LEVEL_DEBUG, "daemon: send status return: %d\n", status); msg.header.magic = CMAN_MAGIC; msg.header.command = cmd | CMAN_CMDFLAG_REPLY; msg.header.length = sizeof(msg); diff --git a/cman/daemon/logging.c b/cman/daemon/logging.c deleted file mode 100644 index e81dcec..0000000 --- a/cman/daemon/logging.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "list.h" -#include "cman.h" -#include "cnxman-socket.h" -#include "cnxman-private.h" -#include "logging.h" - -LOGSYS_DECLARE_SUBSYS (CMAN_NAME); - -int subsys_mask = 0; - -void set_debuglog(int subsystems) -{ - if (subsystems) - logsys_config_mode_set(CMAN_NAME, LOGSYS_LEVEL_DEBUG); - else - logsys_config_mode_set(CMAN_NAME, LOGSYS_LEVEL_INFO); - subsys_mask = subsystems; -} diff --git a/cman/daemon/logging.h b/cman/daemon/logging.h deleted file mode 100644 index f9ca506..0000000 --- a/cman/daemon/logging.h +++ /dev/null @@ -1,17 +0,0 @@ -//#include - -extern void set_debuglog(int subsystems); - -/* Debug macros */ -#define CMAN_DEBUG_NONE 1 -#define CMAN_DEBUG_BARRIER 2 -#define CMAN_DEBUG_MEMB 4 -#define CMAN_DEBUG_DAEMON 8 -#define CMAN_DEBUG_AIS 16 - -extern int subsys_mask; - -#define P_BARRIER(fmt, args...) if (subsys_mask & CMAN_DEBUG_BARRIER) log_printf(LOGSYS_LEVEL_DEBUG, "barrier: " fmt, ## args) -#define P_MEMB(fmt, args...) if (subsys_mask & CMAN_DEBUG_MEMB) log_printf(LOGSYS_LEVEL_DEBUG, "memb: " fmt, ## args) -#define P_DAEMON(fmt, args...) if (subsys_mask & CMAN_DEBUG_DAEMON) log_printf(LOGSYS_LEVEL_DEBUG , "daemon: " fmt, ## args) -#define P_AIS(fmt, args...) if (subsys_mask & CMAN_DEBUG_AIS) log_printf(LOGSYS_LEVEL_DEBUG, "ais " fmt, ## args)