[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] Switch qdisk to logsys




Hi Lon,

in attachement there is my proposed patch to switch qdisk to logsys and it is untested at the moment. My qdisk cluster is temporary under full reinstallation.

Could you please give it a shot and let me know?

Thanks
Fabio

--
I'm going to make him an offer he can't refuse.
diff --git a/cman/qdisk/Makefile b/cman/qdisk/Makefile
index 0751601..4bb7355 100644
--- a/cman/qdisk/Makefile
+++ b/cman/qdisk/Makefile
@@ -25,17 +25,17 @@ include $(OBJDIR)/make/uninstall.mk
 
 CFLAGS += -D_GNU_SOURCE
 CFLAGS += -Werror -Wstrict-prototypes -Wshadow
-CFLAGS += -I${ccsincdir} -I${cmanincdir}
+CFLAGS += -I${ccsincdir} -I${cmanincdir} -L${openaisincdir}
 CFLAGS += -I$(S)
 CFLAGS += -I${incdir}
 
 EXTRA_LDFLAGS += -L${cmanlibdir} -L${ccslibdir} -lcman -lccs
+EXTRA_LDFLAGS += -L${openaislibdir} -llogsys
 EXTRA_LDFLAGS += -lpthread
 
 OBJS1=	main.o \
 	score.o \
 	bitmap.o \
-	clulog.o \
 	gettid.o \
 	daemon_init.o
 
diff --git a/cman/qdisk/clulog.c b/cman/qdisk/clulog.c
deleted file mode 100644
index 6b998f1..0000000
--- a/cman/qdisk/clulog.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
-  Copyright Red Hat, Inc. 2002
-  Copyright Mission Critical Linux, 2000
-
-  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, or (at your option) any
-  later version.
-
-  This program 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 program; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
-  MA 02139, USA.
-*/
-/** @file
- * Library routines for communicating with the logging daemon.
- *
- *  Author: Jeff Moyer <moyer missioncriticallinux com>
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <malloc.h>
-#include <dirent.h>
-#include <signal.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <ccs.h>
-#define SYSLOG_NAMES
-#include <sys/syslog.h>
-#undef SYSLOG_NAMES
-
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <linux/unistd.h>
-#include <pthread.h>
-#include <gettid.h>
-#include <clulog.h>
-#include <string.h>
-
-
-#ifdef DEBUG
-#include <assert.h>
-#define Dprintf(fmt,args...) printf(fmt,##args)
-#define DBG_ASSERT(x)  assert(x)
-#else
-#define Dprintf(fmt,args...)
-#define DBG_ASSERT(x)
-#endif
-
-/*
- * Globals
- */
-static int   log_is_open = 0;
-static int   useconsole = 0;
-static int   loglevel = LOGLEVEL_DFLT;
-static int   syslog_facility = LOG_DAEMON;
-static char  *daemon_name = NULL;
-static pid_t daemon_pid = -1;
-static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-CODE logger_prioritynames[] = 
-{ {"emerg", LOG_EMERG},
-  {"alert", LOG_ALERT},
-  {"crit", LOG_CRIT},
-  {"err", LOG_ERR},
-  {"warning", LOG_WARNING},
-  {"notice", LOG_NOTICE},
-  {"info", LOG_INFO},
-  {"debug", LOG_DEBUG}
-};
-
-/*
- *  Exported Functions.
- */
-
-/**
- * @return The current cluster log level.
- */
-int
-clu_get_loglevel(void)
-{
-	return loglevel;
-}
-
-
-/**
- * Set the cluster log level.
- *
- * @param severity	New log level.
- * @return 		Old log level, or -1 if 'severity' is an invalid log
- *			level.
- */
-int
-clu_set_loglevel(int severity)
-{
-	int ret = loglevel;
-
-	if (severity > 0) {
-		loglevel = severity;
-		return ret;
-	}
-
-	return -1;
-}
-
-
-/**
- * @return The current cluster log facility.
- */
-char *
-clu_get_facility(void)
-{
-	int x = 0;
-
-	pthread_mutex_lock(&log_mutex);
-	for (; facilitynames[x].c_name; x++) {
-		if (syslog_facility == facilitynames[x].c_val) {
-			pthread_mutex_unlock(&log_mutex);
-			return facilitynames[x].c_name;
-		}
-	}
-	
-	pthread_mutex_unlock(&log_mutex);
-	return "daemon";
-}
-
-
-/**
- * Set the cluster log facility.
- *
- * @param facilityname  New log facility (see /usr/include/sys/syslog.h).
- * @return 		0
- */
-int
-clu_set_facility(char *facilityname)
-{
-	int x = 0, old;
-
-	pthread_mutex_lock(&log_mutex);
-	old = syslog_facility;
-
-	for (; facilitynames[x].c_name; x++) {
-		if (strcmp(facilityname, facilitynames[x].c_name))
-			continue;
-		syslog_facility = facilitynames[x].c_val;
-		break;
-	}
-
-	if (syslog_facility == old) {
-		pthread_mutex_unlock(&log_mutex);
-		return 0;
-	}
-
-	closelog();
-	log_is_open = 0;
-	pthread_mutex_unlock(&log_mutex);
-	return 0;
-}
-
-
-/**
- * Set the console logging mode.  Does not work for daemons.
- *
- * @param onoff		0 = off, otherwise on.
- * @return		Old log-to-console state.
- */
-int
-clu_log_console(int onoff)
-{
-	int ret = useconsole;
-
-	useconsole = !!onoff;
-	return ret;
-}
-
-
-/**
- * Cluster logging function.  Talks to syslog and writes to the
- * console, if necessary.
- */
-int
-do_clulog(int        severity,
-	  int        write_to_cons,
-	  pid_t      pid,
-	  char       *prog,
-	  const char *fmt, ...)
-{
-	va_list      args;
-	char         logmsg[MAX_LOGMSG_LEN];	/* message to go to the log */
-	char         printmsg[MAX_LOGMSG_LEN];	/* message to go to stdout */
-	int          syslog_flags = LOG_NDELAY;
-
-	pthread_mutex_lock(&log_mutex);
-	if (severity > loglevel) {
-		pthread_mutex_unlock(&log_mutex);
-		return 0;
-	}
-
-	memset(logmsg, 0, MAX_LOGMSG_LEN);
-	memset(printmsg, 0, MAX_LOGMSG_LEN);
-
-	/*
-	 * Check to see if the caller has forked.
-	 */
-	if (!pid) {
-
-		/* Use thread IDs */
-		if (daemon_pid != gettid()) {
-
-			daemon_pid = gettid();
-			log_is_open = 0;
-		}
-
-		syslog_flags |= LOG_PID;
-
-	} else {
-
-		daemon_pid = pid;
-		closelog();
-		log_is_open = 0;
-		snprintf(logmsg, MAX_LOGMSG_LEN, "[%d]: ", pid);
-	}
-
-	if (prog) {
-
-		if (daemon_name) {
-
-			free(daemon_name);
-			daemon_name = NULL;
-		}
-
-		daemon_name = strdup(prog);
-	}
-
-	if (!log_is_open) {
-
-		openlog(daemon_name, syslog_flags, syslog_facility);
-		log_is_open = 1;
-	}
-	/*
-	 * Note: This can be called in the context of a CGI program, in which
-	 * case anything printed to stdout goes to the web page.  This can
-	 * cause problems if we have our standard <warning> strings b/c
-	 * the web client will try to interpret this as an html tag.
-	 */
-	snprintf(logmsg + strlen(logmsg), MAX_LOGMSG_LEN - strlen(logmsg), 
-		 "<%s> ", logger_prioritynames[severity].c_name);
-
-	va_start(args, fmt);
-	vsnprintf(logmsg + strlen(logmsg), MAX_LOGMSG_LEN - strlen(logmsg), 
-		  fmt, args);
-	va_end(args);
-
-	if (write_to_cons || useconsole) {
-		snprintf(printmsg, MAX_LOGMSG_LEN, "[%d] %s: ", daemon_pid,
-			 logger_prioritynames[severity].c_name);
-
-		va_start(args, fmt);
-		vsnprintf(printmsg + strlen(printmsg),
-			  MAX_LOGMSG_LEN - strlen(printmsg), fmt, args);
-		va_end(args);
-
-		fprintf(stdout, "%s", printmsg);
-	}
-
-	syslog(severity, "%s", logmsg);
-
-	pthread_mutex_unlock(&log_mutex);
-
-	return 0;
-}
-
-
-/**
- * Stop the cluster logging facility.
- */
-void
-clulog_close(void)
-{
-	closelog();
-}
diff --git a/cman/qdisk/clulog.h b/cman/qdisk/clulog.h
deleted file mode 100644
index 856d83c..0000000
--- a/cman/qdisk/clulog.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
-  Copyright Red Hat, Inc. 2002
-  Copyright Mission Critical Linux, 2000
-
-  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, or (at your option) any
-  later version.
-
-  This program 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 program; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
-  MA 02139, USA.
-*/
-/** @file
- * Header for clulog.c
- */
-/*
- *  author: Jeff Moyer <moyer missioncriticallinux com>
- */
-
-#ifndef __CLUSTER_LOG_H
-#define __CLUSTER_LOG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <syslog.h>
-#include <sys/types.h>
-
-#define LOGLEVEL_DFLT         LOG_INFO
-#define MAX_LOGMSG_LEN        512
-
-/*
- * int clu_set_loglevel(int severity)
- *
- * DESCRIPTION
- *   Set the logging level for this daemon.  This is not a 
- *   system-wide setting.
- *
- * ARGUMENTS
- *   severity  Severity as documented in sys/syslog.h (i.e. LOG_ERR)
- *
- * RETURN VALUES
- *   On success, the previous loglevel is returned.  On error -1 is returned.
- *
- * NOTES
- *   The only way of generating errors for this call is to give a negative
- *   value for severity.  Currently, syslog lists severities up to 8, but
- *   I see no reason for this restriction if, in the future, we decided to
- *   add more levels.  Thus, any number up to MAXINT will be supported.
- */
-int clu_set_loglevel(int severity);
-int clu_set_facility(char *facility);
-int clu_log_console(int onoff);
-
-/*
- * int clu_get_loglevel(void)
- *
- * DESCRIPTION
- *   Get the current logging level.
- *
- * ARGUMENTS
- *   none
- *
- * RETURN VALUES
- *   The current logging level is returned.
- */
-int clu_get_loglevel(void);
-
-/*
- * DESCRIPTION
- *   Cluster logging facility.  This is the actual function that does the
- *   logging.  No one should call this, you should call the wrappers provided.
- *   i.e. clulog and clulog_and_print.
- */
-int do_clulog(int severity, int write_to_cons, pid_t pid,
-	      char *prog, const char *fmt, ...);
-/*
- * int clulog(int severity, const char *fmt, ...)
- *
- * DESCRIPTION
- *   Cluster logging facility.  This is a library routine which sends the 
- *   supplied parameters to the syslog daemon.  If the supplied severity is 
- *   numerically larger than the current loglevel, the message is never sent 
- *   to the log.
- *
- * ARGUMENTS
- *   severity  Severity as documented in sys/syslog.h (i.e. LOG_ERR)
- *   fmt       Format string as used with printf.
- *
- * RETURN VALUES
- *   On success, 0 is returned.  On error, -1 is returned.
- *
- * NOTES
- *   Inability to contact the logging daemon is the only source of error
- *   for this function.  Thus, it would behoove you to try a clulog before
- *   daemonizing your process.  If it fails, print a message to stderr
- *   explaining that the cluster logging daemon should probably be started.
- *   If you really want your message to be heard by someone, use
- *   clulog_and_print().
- */
-#define clulog(x,fmt,args...)              do_clulog(x,0,0,NULL,fmt,##args)
-#define clulog_pid(x,pid,prog,fmt,args...) do_clulog(x,0,pid,prog,fmt,##args)
-
-/*
- * int clulog_and_print(int severity, int write_to_cons, const char *fmt, ...)
- *
- * DESCRIPTION
- *   Cluster logging facility.  This is a library routine which sends the 
- *   supplied parameters to the syslog daemon.  If the supplied severity is 
- *   numerically larger than the current loglevel, the message is never sent 
- *   to the log.  This version also prints the given message to the terminal.
- *
- * ARGUMENTS
- *   severity       Severity as documented in sys/syslog.h (i.e. LOG_ERR)
- *   fmt            Format string as used with printf.
- *
- * RETURN VALUES
- *   On success, 0 is returned.  On error, -1 is returned.
- */
-#define clulog_and_print(x,fmt,args...)   do_clulog(x,1,0,NULL,fmt,##args)
-
-
-/*
- * void clulog_close(void)
- *
- * DESCRIPTION
- *   This is an optional call to close the logfile.  This translates into a
- *   closelog() call.
- *
- * ARGUMENTS
- *   none
- *
- * RETURN VALUES
- *   This function does not return anything.
- */
-void clulog_close(void);
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif				/* __CLUSTER_LOG_H */
-/*
- * Local variables:
- *  c-basic-offset: 8
- *  c-indent-level: 8
- *  tab-width: 8
- * End:
- */
diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index b953367..e537c8d 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -41,8 +41,8 @@
 #include <sched.h>
 #include <signal.h>
 #include <ccs.h>
+#include <openais/service/logsys.h>
 #include "score.h"
-#include "clulog.h"
 #if (!defined(LIBCMAN_VERSION) || \
      (defined(LIBCMAN_VERSION) && LIBCMAN_VERSION < 2))
 #include <cluster/cnxman-socket.h>
@@ -72,6 +72,13 @@ void update_local_status(qd_ctx *ctx, node_info_t *ni, int max, int score,
 		    	 int score_req, int score_max);
 
 
+LOGSYS_DECLARE_SYSTEM (NULL,
+        LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_DISPLAY_DEBUG | LOG_MODE_BUFFER_BEFORE_CONFIG,
+        LOGDIR "/qdisk.log",
+        SYSLOGFACILITY);
+
+LOGSYS_DECLARE_SUBSYS ("QDISK", LOG_LEVEL_INFO);
+
 static void
 int_handler(int sig)
 {
@@ -127,7 +134,7 @@ check_self(qd_ctx *ctx, status_block_t *sb)
 		/* Someone told us to die. */
 		reboot(RB_AUTOBOOT);
 	default:
-		clulog(LOG_EMERG, "Unhandled state: %d\n", sb->ps_state);
+		log_printf(LOG_EMERG, "Unhandled state: %d\n", sb->ps_state);
 		raise(SIGSTOP);
 	}
 }
@@ -151,7 +158,7 @@ read_node_blocks(qd_ctx *ctx, node_info_t *ni, int max)
 		if (qdisk_read(&ctx->qc_disk,
 			       qdisk_nodeid_offset(x+1, ctx->qc_disk.d_blksz),
 			       sb, sizeof(*sb)) < 0) {
-			clulog(LOG_WARNING,"Error reading node ID block %d\n",
+			log_printf(LOG_WARNING,"Error reading node ID block %d\n",
 			       x+1);
 			continue;
 		}
@@ -176,7 +183,7 @@ read_node_blocks(qd_ctx *ctx, node_info_t *ni, int max)
 			/* XXX check for average + allow grace */
 			ni[x].ni_misses++;
 			if (ni[x].ni_misses > 1) {
-				clulog(LOG_DEBUG,
+				log_printf(LOG_DEBUG,
 					"Node %d missed an update (%d/%d)\n",
 					x+1, ni[x].ni_misses, ctx->qc_tko);
 			}
@@ -219,11 +226,11 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 		       ni[x].ni_status.ps_incarnation))) {
 
 			if (ni[x].ni_status.ps_state == S_EVICT) {
-				clulog(LOG_NOTICE, "Node %d evicted\n",
+				log_printf(LOG_NOTICE, "Node %d evicted\n",
 				       ni[x].ni_status.ps_nodeid);
 			} else {
 				/* State == S_NONE or incarnation change */
-				clulog(LOG_INFO, "Node %d shutdown\n",
+				log_printf(LOG_INFO, "Node %d shutdown\n",
 				       ni[x].ni_status.ps_nodeid);
 				ni[x].ni_evil_incarnation = 0;
 			}
@@ -257,13 +264,13 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 			   Write eviction notice if we're the master.
 			 */
 			if (ctx->qc_status == S_MASTER) {
-				clulog(LOG_NOTICE,
+				log_printf(LOG_NOTICE,
 				       "Writing eviction notice for node %d\n",
 				       ni[x].ni_status.ps_nodeid);
 				qd_write_status(ctx, ni[x].ni_status.ps_nodeid,
 						S_EVICT, NULL, NULL, NULL);
 				if (ctx->qc_flags & RF_ALLOW_KILL) {
-					clulog(LOG_DEBUG, "Telling CMAN to "
+					log_printf(LOG_DEBUG, "Telling CMAN to "
 						"kill the node\n");
 					cman_kill_node(ctx->qc_ch,
 						ni[x].ni_status.ps_nodeid);
@@ -277,7 +284,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 			 */
 			if (ni[x].ni_status.ps_state >= S_RUN &&
 			    ni[x].ni_seen) {
-				clulog(LOG_DEBUG, "Node %d DOWN\n",
+				log_printf(LOG_DEBUG, "Node %d DOWN\n",
 				       ni[x].ni_status.ps_nodeid);
 				ni[x].ni_seen = 0;	
 			}
@@ -304,10 +311,10 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 		if (ni[x].ni_evil_incarnation &&
                     (ni[x].ni_evil_incarnation == 
 		     ni[x].ni_status.ps_incarnation)) {
-			clulog(LOG_CRIT, "Node %d is undead.\n",
+			log_printf(LOG_CRIT, "Node %d is undead.\n",
 			       ni[x].ni_status.ps_nodeid);
 
-			clulog(LOG_ALERT,
+			log_printf(LOG_ALERT,
 			       "Writing eviction notice for node %d\n",
 			       ni[x].ni_status.ps_nodeid);
 			qd_write_status(ctx, ni[x].ni_status.ps_nodeid,
@@ -316,7 +323,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 
 			/* XXX Need to fence it again */
 			if (ctx->qc_flags & RF_ALLOW_KILL) {
-				clulog(LOG_DEBUG, "Telling CMAN to "
+				log_printf(LOG_DEBUG, "Telling CMAN to "
 					"kill the node\n");
 				cman_kill_node(ctx->qc_ch,
 					ni[x].ni_status.ps_nodeid);
@@ -339,7 +346,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 			   right now.
 			 */
 			ni[x].ni_state = S_RUN;
-			clulog(LOG_DEBUG, "Node %d is UP\n",
+			log_printf(LOG_DEBUG, "Node %d is UP\n",
 			       ni[x].ni_status.ps_nodeid);
 			ni[x].ni_incarnation =
 			    ni[x].ni_status.ps_incarnation;
@@ -356,7 +363,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
 		 */
 		if (ni[x].ni_state == S_RUN &&
 		    ni[x].ni_status.ps_state == S_MASTER) {
-			clulog(LOG_INFO, "Node %d is the master\n",
+			log_printf(LOG_INFO, "Node %d is the master\n",
 			       ni[x].ni_status.ps_nodeid);
 			ni[x].ni_state = S_MASTER;
 			if (mask)
@@ -417,7 +424,7 @@ master_exists(qd_ctx *ctx, node_info_t *ni, int max, int *low_id, int *count)
 		/* Look for dead master */
 		if (ni[x].ni_state < S_RUN &&
 		    ni[x].ni_status.ps_state == S_MASTER) {
-			clulog(LOG_DEBUG,
+			log_printf(LOG_DEBUG,
 			       "Node %d is marked master, but is dead.\n",
 			       ni[x].ni_status.ps_nodeid);
 			continue;
@@ -455,28 +462,28 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
 {
 	int x = 0, score, maxscore, score_req;
 
-	clulog(LOG_INFO, "Quorum Daemon Initializing\n");
+	log_printf(LOG_INFO, "Quorum Daemon Initializing\n");
 	
 	if (mlockall(MCL_CURRENT|MCL_FUTURE) != 0) {
-		clulog(LOG_ERR, "Unable to mlockall()\n");
+		log_printf(LOG_ERR, "Unable to mlockall()\n");
 	}
 
 	if (qdisk_validate(ctx->qc_device) < 0)
 		return -1;
 
 	if (qdisk_open(ctx->qc_device, &ctx->qc_disk) < 0) {
-		clulog(LOG_CRIT, "Failed to open %s: %s\n", ctx->qc_device,
+		log_printf(LOG_CRIT, "Failed to open %s: %s\n", ctx->qc_device,
 		       strerror(errno));
 		return -1;
 	}
 
-	clulog(LOG_DEBUG, "I/O Size: %d  Page Size: %d\n",
+	log_printf(LOG_DEBUG, "I/O Size: %lu  Page Size: %lu\n",
 	       ctx->qc_disk.d_blksz, ctx->qc_disk.d_pagesz);
 	
 	if (h && maxh) {
 		start_score_thread(ctx, h, maxh);
 	} else {
-		clulog(LOG_DEBUG, "Permanently setting score to 1/1\n");
+		log_printf(LOG_DEBUG, "Permanently setting score to 1/1\n");
 		fudge_scoring();
 	}
 
@@ -484,7 +491,7 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
 	ctx->qc_status = S_INIT;
 	if (qd_write_status(ctx, ctx->qc_my_id,
 			    S_INIT, NULL, NULL, NULL) != 0) {
-		clulog(LOG_CRIT, "Could not initialize status block!\n");
+		log_printf(LOG_CRIT, "Could not initialize status block!\n");
 		return -1;
 	}
 
@@ -494,7 +501,7 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
 
 		if (qd_write_status(ctx, ctx->qc_my_id,
 				    S_INIT, NULL, NULL, NULL) != 0) {
-			clulog(LOG_CRIT, "Initialization failed\n");
+			log_printf(LOG_CRIT, "Initialization failed\n");
 			return -1;
 		}
 
@@ -508,8 +515,8 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
 	}
 
 	get_my_score(&score, &maxscore);
-	clulog(LOG_INFO, "Initial score %d/%d\n", score, maxscore);
-	clulog(LOG_INFO, "Initialization complete\n");
+	log_printf(LOG_INFO, "Initial score %d/%d\n", score, maxscore);
+	log_printf(LOG_INFO, "Initialization complete\n");
 
 	return 0;
 }
@@ -807,7 +814,7 @@ set_priority(int queue, int prio)
 	}
 	
 	if (ret < 0 && errno) {
-		clulog(LOG_WARNING, "set_priority [%s] failed: %s\n", func,
+		log_printf(LOG_WARNING, "set_priority [%s] failed: %s\n", func,
 		       strerror(errno));
 	}
 }
@@ -852,7 +859,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 	
 	get_my_score(&score, &score_max);
 	if (score_max < ctx->qc_scoremin) {
-		clulog(LOG_WARNING, "Minimum score (%d) is impossible to "
+		log_printf(LOG_WARNING, "Minimum score (%d) is impossible to "
 		       "achieve (heuristic total = %d)\n",
 		       ctx->qc_scoremin, score_max);
 	}
@@ -882,7 +889,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		if (score < score_req) {
 			clear_bit(mask, (ctx->qc_my_id-1), sizeof(mask));
 			if (ctx->qc_status > S_NONE) {
-				clulog(LOG_NOTICE,
+				log_printf(LOG_NOTICE,
 				       "Score insufficient for master "
 				       "operation (%d/%d; required=%d); "
 				       "downgrading\n",
@@ -892,7 +899,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 				++msg.m_seq;
 				bid_pending = 0;
 				if (cman_alive(ctx->qc_ch) < 0) {
-					clulog(LOG_ERR, "cman: %s\n",
+					log_printf(LOG_ERR, "cman: %s\n",
 					       strerror(errno));
 				} else {
 					cman_poll_quorum_device(ctx->qc_ch, 0);
@@ -903,7 +910,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		}  else {
 			set_bit(mask, (ctx->qc_my_id-1), sizeof(mask));
 			if (ctx->qc_status == S_NONE) {
-				clulog(LOG_NOTICE,
+				log_printf(LOG_NOTICE,
 				       "Score sufficient for master "
 				       "operation (%d/%d; required=%d); "
 				       "upgrading\n",
@@ -922,7 +929,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		/* Resolve master conflict, if one exists */
 		if (count >= 1 && ctx->qc_status == S_MASTER &&
 		    ctx->qc_master != ctx->qc_my_id) {
-			clulog(LOG_WARNING, "Master conflict: abdicating\n");
+			log_printf(LOG_WARNING, "Master conflict: abdicating\n");
 
 			/* Handle just like a recent upgrade */
 			ctx->qc_status = S_RUN;
@@ -945,7 +952,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 			   upgraded.
 			 */
 
-			clulog(LOG_DEBUG,"Making bid for master\n");
+			log_printf(LOG_DEBUG,"Making bid for master\n");
 			msg.m_msg = M_BID;
 			++msg.m_seq;
 			bid_pending = 1;
@@ -972,7 +979,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 				if (bid_pending < (ctx->qc_master_wait))
 					break;
 				
-				clulog(LOG_INFO,
+				log_printf(LOG_INFO,
 				       "Assuming master role\n");
 				ctx->qc_status = S_MASTER;
 			case 2:
@@ -988,7 +995,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 			/* We think we're master, but someone else claims
 			   that they are master. */
 
-			clulog(LOG_CRIT,
+			log_printf(LOG_CRIT,
 			       "A master exists, but it's not me?!\n");
 			/* XXX Handle this how? Should not happen*/
 			/* reboot(RB_AUTOBOOT); */
@@ -1000,9 +1007,9 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 			   We can't be the master unless we score high
 			   enough on our heuristics. */
 			if (cman_alive(ctx->qc_ch) < 0) {
-				clulog(LOG_ERR, "cman_dispatch: %s\n",
+				log_printf(LOG_ERR, "cman_dispatch: %s\n",
 				       strerror(errno));
-				clulog(LOG_ERR,
+				log_printf(LOG_ERR,
 				       "Halting qdisk operations\n");
 				return -1;
 			}
@@ -1020,9 +1027,9 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 				       ctx->qc_my_id-1,
 				       sizeof(memb_mask_t))) {
 				if (cman_alive(ctx->qc_ch) < 0) {
-					clulog(LOG_ERR, "cman_dispatch: %s\n",
+					log_printf(LOG_ERR, "cman_dispatch: %s\n",
 						strerror(errno));
-					clulog(LOG_ERR,
+					log_printf(LOG_ERR,
 						"Halting qdisk operations\n");
 					return -1;
 				}
@@ -1033,7 +1040,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		/* Write out our status */
 		if (qd_write_status(ctx, ctx->qc_my_id, ctx->qc_status,
 				    &msg, mask, master_mask) != 0) {
-			clulog(LOG_ERR, "Error writing to quorum disk\n");
+			log_printf(LOG_ERR, "Error writing to quorum disk\n");
 		}
 
 		/* write out our local status */
@@ -1049,7 +1056,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		 */
 		if (_cmp_tv(&maxtime, &diff) == 1 &&
 		    ctx->qc_flags & RF_PARANOID) {
-			clulog(LOG_EMERG, "Failed to complete a cycle within "
+			log_printf(LOG_EMERG, "Failed to complete a cycle within "
 			       "%d second%s (%d.%06d) - REBOOTING\n",
 			       (int)maxtime.tv_sec,
 			       maxtime.tv_sec==1?"":"s",
@@ -1068,7 +1075,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
 		if (_cmp_tv(&diff, &interval) == 1) {
 			_diff_tv(&sleeptime, &diff, &interval);
 		} else {
-			clulog(LOG_WARNING, "qdisk cycle took more "
+			log_printf(LOG_WARNING, "qdisk cycle took more "
 			       "than %d second%s to complete (%d.%06d)\n",
 			       ctx->qc_interval, ctx->qc_interval==1?"":"s",
 			       (int)diff.tv_sec, (int)diff.tv_usec);
@@ -1093,7 +1100,7 @@ quorum_logout(qd_ctx *ctx)
 	/* Write out our status */
 	if (qd_write_status(ctx, ctx->qc_my_id, S_NONE,
 			    NULL, NULL, NULL) != 0) {
-		clulog(LOG_WARNING,
+		log_printf(LOG_WARNING,
 		       "Error writing to quorum disk during logout\n");
 	}
 	return 0;
@@ -1111,11 +1118,11 @@ get_config_data(char *cluster_name, qd_ctx *ctx, struct h_data *h, int maxh,
 	char query[256];
 	char *val;
 
-	clulog(LOG_DEBUG, "Loading configuration information\n");
+	log_printf(LOG_DEBUG, "Loading configuration information\n");
 
 	ccsfd = ccs_force_connect(cluster_name, 1);
 	if (ccsfd < 0) {
-		clulog(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
+		log_printf(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
 		return -1;
 	}
 
@@ -1126,16 +1133,19 @@ get_config_data(char *cluster_name, qd_ctx *ctx, struct h_data *h, int maxh,
 			/* | RF_STOP_CMAN;*/
 	if (debug)
 		ctx->qc_flags |= RF_DEBUG;
+
 	ctx->qc_sched = SCHED_RR;
 	ctx->qc_sched_prio = 1;
 
 	/* Get log log_facility */
+/* XXX this needs fixing. val is a string, facility expects a value...
 	snprintf(query, sizeof(query), "/cluster/quorumd/@log_facility");
 	if (ccs_get(ccsfd, query, &val) == 0) {
-		clu_set_facility(val);
-		clulog(LOG_DEBUG, "Log facility: %s\n", val);
+		logsys_config_facility_set ("QDISK", val);
+		log_printf(LOG_DEBUG, "Log facility: %s\n", val);
 		free(val);
 	}
+*/
 
 	/* Get log level */
 	snprintf(query, sizeof(query), "/cluster/quorumd/@log_level");
@@ -1146,7 +1156,7 @@ get_config_data(char *cluster_name, qd_ctx *ctx, struct h_data *h, int maxh,
 			loglevel = 4;
 
 		if (!debug)
-			clu_set_loglevel(loglevel);
+			logsys_config_priority_set (loglevel);
 	}
 
 	/* Get interval */
@@ -1258,7 +1268,7 @@ get_config_data(char *cluster_name, qd_ctx *ctx, struct h_data *h, int maxh,
 			ctx->qc_sched = SCHED_OTHER;
 			break;
 		default:
-			clulog(LOG_WARNING, "Invalid scheduling queue '%s'\n",
+			log_printf(LOG_WARNING, "Invalid scheduling queue '%s'\n",
 			       val);
 			break;
 		}
@@ -1350,10 +1360,10 @@ get_config_data(char *cluster_name, qd_ctx *ctx, struct h_data *h, int maxh,
 
 	*cfh = configure_heuristics(ccsfd, h, maxh);
 
-	clulog(LOG_DEBUG,
+	log_printf(LOG_DEBUG,
 	       "Quorum Daemon: %d heuristics, %d interval, %d tko, %d votes\n",
 	       *cfh, ctx->qc_interval, ctx->qc_tko, ctx->qc_votes);
-	clulog(LOG_DEBUG, "Run Flags: %08x\n", ctx->qc_flags);
+	log_printf(LOG_DEBUG, "Run Flags: %08x\n", ctx->qc_flags);
 
 	ccs_disconnect(ccsfd);
 
@@ -1367,7 +1377,7 @@ check_stop_cman(qd_ctx *ctx)
 	if (!(ctx->qc_flags & RF_STOP_CMAN))
 		return;
 	
-	clulog(LOG_WARNING, "Telling CMAN to leave the cluster; qdisk is not"
+	log_printf(LOG_WARNING, "Telling CMAN to leave the cluster; qdisk is not"
 		" available\n");
 #if (defined(LIBCMAN_VERSION) && LIBCMAN_VERSION >= 2)
 	if (cman_shutdown(ctx->qc_ch, 0) < 0) {
@@ -1375,7 +1385,7 @@ check_stop_cman(qd_ctx *ctx)
 	int x = 0;
 	if (ioctl(cman_get_fd(ctx->qc_ch), SIOCCLUSTER_LEAVE_CLUSTER, &x) < 0) {
 #endif
-		clulog(LOG_CRIT, "Could not leave the cluster - rebooting\n");
+		log_printf(LOG_CRIT, "Could not leave the cluster - rebooting\n");
 		sleep(5);
 		if (ctx->qc_flags & RF_DEBUG)
 			return;
@@ -1398,11 +1408,13 @@ main(int argc, char **argv)
 	pid_t pid;
 	quorum_header_t qh;
 
+	logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_DISPLAY_DEBUG | LOG_MODE_FLUSH_AFTER_CONFIG);
+
 	if (check_process_running(argv[0], &pid) && pid !=getpid()) {
 		printf("QDisk services already running\n");
 		return 0;
 	}
-	
+
 	while ((rv = getopt(argc, argv, "fdQs")) != EOF) {
 		switch (rv) {
 		case 'd':
@@ -1410,7 +1422,6 @@ main(int argc, char **argv)
 			break;
 		case 'f':
 			foreground = 1;
-			clu_log_console(1);
 			break;
 		case 'Q':
 			/* Make qdisk very quiet */
@@ -1428,6 +1439,9 @@ main(int argc, char **argv)
 		}
 	}
 
+	if(debug || getenv("QDISK_DEBUGLOG"))
+		logsys_config_priority_set (LOG_LEVEL_DEBUG);
+
 #if (defined(LIBCMAN_VERSION) && LIBCMAN_VERSION >= 2)
 	ch = cman_admin_init(NULL);
 #else
@@ -1441,7 +1455,7 @@ main(int argc, char **argv)
 				forked = 1;
 		}
 		
-		clulog(LOG_INFO, "Waiting for CMAN to start\n");
+		log_printf(LOG_INFO, "Waiting for CMAN to start\n");
 		
 		do {
 			sleep(5);
@@ -1469,21 +1483,19 @@ main(int argc, char **argv)
 	signal(SIGINT, int_handler);
 	signal(SIGTERM, int_handler);
 
-        if (debug) {
-                clu_set_loglevel(LOG_DEBUG);
+        if (debug)
                 ctx.qc_flags |= RF_DEBUG;
-        }
-		
+
 	if (get_config_data(NULL, &ctx, h, 10, &cfh, debug) < 0) {
-		clulog_and_print(LOG_CRIT, "Configuration failed\n");
+		log_printf(LOG_CRIT, "Configuration failed\n");
 		check_stop_cman(&ctx);
 		goto out;
 	}
-	
+
 	if (ctx.qc_label) {
 		ret = find_partitions(ctx.qc_label, device, sizeof(device), 0);
 		if (ret < 0) {
-			clulog_and_print(LOG_CRIT, "Unable to match label"
+			log_printf(LOG_CRIT, "Unable to match label"
 					 " '%s' to any device\n",
 					 ctx.qc_label);
 			check_stop_cman(&ctx);
@@ -1496,11 +1508,11 @@ main(int argc, char **argv)
 
 		ctx.qc_device = strdup(device);
 
-		clulog(LOG_INFO, "Quorum Partition: %s Label: %s\n",
+		log_printf(LOG_INFO, "Quorum Partition: %s Label: %s\n",
 		       ctx.qc_device, ctx.qc_label);
 	} else if (ctx.qc_device) {
 		if (check_device(ctx.qc_device, NULL, &qh, 0) != 0) {
-			clulog(LOG_CRIT,
+			log_printf(LOG_CRIT,
 			       "Specified partition %s does not have a "
 			       "qdisk label\n", ctx.qc_device);
 			check_stop_cman(&ctx);
@@ -1509,9 +1521,9 @@ main(int argc, char **argv)
 
 		if (qh.qh_version == VERSION_MAGIC_V2 &&
                     qh.qh_blksz != rv) {
-			clulog(LOG_CRIT,
+			log_printf(LOG_CRIT,
 			       "Specified device %s does match kernel's "
-			       "reported sector size (%d != %d)\n",
+			       "reported sector size (%lu != %d)\n",
 			       ctx.qc_device,
 			       ctx.qc_disk.d_blksz, rv);
 			check_stop_cman(&ctx);
@@ -1527,7 +1539,7 @@ main(int argc, char **argv)
 	set_priority(ctx.qc_sched, ctx.qc_sched_prio);
 
 	if (quorum_init(&ctx, ni, MAX_NODES_DISK, h, cfh) < 0) {
-		clulog_and_print(LOG_CRIT, "Initialization failed\n");
+		log_printf(LOG_CRIT, "Initialization failed\n");
 		check_stop_cman(&ctx);
 		goto out;
 	}
@@ -1547,7 +1559,7 @@ main(int argc, char **argv)
 		
 	if ((rv = cman_register_quorum_device(ctx.qc_ch, ctx.qc_device,
 					      ctx.qc_votes)) < 0) {
-		clulog_and_print(LOG_CRIT,
+		log_printf(LOG_CRIT,
 				 "Could not register %s with CMAN; "
 				 "return = %d; error = %s\n",
 				 ctx.qc_device, rv, strerror(errno));
diff --git a/cman/qdisk/score.c b/cman/qdisk/score.c
index 3f508a2..2363197 100644
--- a/cman/qdisk/score.c
+++ b/cman/qdisk/score.c
@@ -31,7 +31,7 @@
 #include <pthread.h>
 #include <string.h>
 #include <ccs.h>
-#include <clulog.h>
+#include <openais/service/logsys.h>
 #include <sched.h>
 #include <sys/mman.h>
 #include "disk.h"
@@ -49,6 +49,7 @@ struct h_arg {
 	int count;
 };
 
+LOGSYS_DECLARE_SUBSYS ("QDISK", LOG_LEVEL_INFO);
 
 /*
   XXX Messy, but works for now... 
@@ -211,7 +212,7 @@ check_heuristic(struct h_data *h, int block)
 	/* Returned 0 and was not killed */
 	if (!h->available) {
 		h->available = 1;
-		clulog(LOG_INFO, "Heuristic: '%s' UP\n", h->program);
+		log_printf(LOG_INFO, "Heuristic: '%s' UP\n", h->program);
 	}
 	h->misses = 0;
 	return 0;
@@ -220,12 +221,12 @@ miss:
 	if (h->available) {
 		h->misses++;
 		if (h->misses >= h->tko) {
-			clulog(LOG_INFO,
+			log_printf(LOG_INFO,
 				"Heuristic: '%s' DOWN (%d/%d)\n",
 				h->program, h->misses, h->tko);
 			h->available = 0;
 		} else {
-			clulog(LOG_DEBUG,
+			log_printf(LOG_DEBUG,
 				"Heuristic: '%s' missed (%d/%d)\n",
 				h->program, h->misses, h->tko);
 		}
@@ -324,13 +325,13 @@ configure_heuristics(int ccsfd, struct h_data *h, int max)
 				h[x].tko = 1;
 		}
 
-		clulog(LOG_DEBUG,
+		log_printf(LOG_DEBUG,
 		       "Heuristic: '%s' score=%d interval=%d tko=%d\n",
 		       h[x].program, h[x].score, h[x].interval, h[x].tko);
 
 	} while (++x < max);
 
-	clulog(LOG_DEBUG, "%d heuristics loaded\n", x);
+	log_printf(LOG_DEBUG, "%d heuristics loaded\n", x);
 		
 	return x;
 }

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]