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

[Cluster-devel] Cluster Project branch, master, updated. cluster-2.99.05-48-g5f25fbd



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".

http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=5f25fbd0791fa5d2089601698d3733fc6ec58622

The branch, master has been updated
       via  5f25fbd0791fa5d2089601698d3733fc6ec58622 (commit)
      from  cfbf8e8fd634667de2b02344fadb6452080556af (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5f25fbd0791fa5d2089601698d3733fc6ec58622
Author: David Teigland <teigland redhat com>
Date:   Wed Jun 25 15:56:34 2008 -0500

    fenced: use logsys
    
    - Setup ccs connection once at the start and keep it open.
    - Read logging configuration from ccs.
    - Replace calls to syslog with calls to logsys.
    - Direct debug statements to logsys.
    - cman setup uses cman_is_active
    - cman setup retries cman_init and cman_is_active
    
    Signed-off-by: David Teigland <teigland redhat com>

-----------------------------------------------------------------------

Summary of changes:
 fence/fenced/Makefile      |    3 +-
 fence/fenced/config.c      |   77 ++++++++++++++++-----
 fence/fenced/fd.h          |   29 +++++++-
 fence/fenced/group.c       |    4 +-
 fence/fenced/logging.c     |  160 ++++++++++++++++++++++++++++++++++++++++++++
 fence/fenced/main.c        |   34 +++++++---
 fence/fenced/member_cman.c |   28 +++++++-
 fence/fenced/recover.c     |   22 +++---
 8 files changed, 305 insertions(+), 52 deletions(-)
 create mode 100644 fence/fenced/logging.c

diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index 1e9bbc9..61ec989 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -15,7 +15,8 @@ OBJS=	config.o \
 	group.o \
 	main.o \
 	member_cman.o \
-	recover.o
+	recover.o \
+	logging.o
 
 CFLAGS += -D_FILE_OFFSET_BITS=64
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${fenceincdir} -I${openaisincdir}
diff --git a/fence/fenced/config.c b/fence/fenced/config.c
index 56b7b0e..3468459 100644
--- a/fence/fenced/config.c
+++ b/fence/fenced/config.c
@@ -1,7 +1,9 @@
 #include "fd.h"
 #include "ccs.h"
 
-static int open_ccs(void)
+static int ccs_handle;
+
+int setup_ccs(void)
 {
 	int i = 0, cd;
 
@@ -9,18 +11,60 @@ static int open_ccs(void)
 		sleep(1);
 		if (++i > 9 && !(i % 10))
 			log_error("connect to ccs error %d, "
-				  "check ccsd or cluster status", cd);
+				  "check cluster status", cd);
 	}
-	return cd;
+
+	ccs_handle = cd;
+	return 0;
+}
+
+void close_ccs(void)
+{
+	ccs_disconnect(ccs_handle);
 }
 
-static void read_ccs_int(int cd, char *path, int *config_val)
+void read_ccs_name(char *path, char *name)
+{
+	char *str;
+	int error;
+
+	error = ccs_get(ccs_handle, path, &str);
+	if (error || !str)
+		return;
+
+	strcpy(name, str);
+
+	free(str);
+}
+
+void read_ccs_yesno(char *path, int *yes, int *no)
+{
+	char *str;
+	int error;
+
+	*yes = 0;
+	*no = 0;
+
+	error = ccs_get(ccs_handle, path, &str);
+	if (error || !str)
+		return;
+
+	if (!strcmp(str, "yes"))
+		*yes = 1;
+
+	else if (!strcmp(str, "no"))
+		*no = 1;
+
+	free(str);
+}
+
+void read_ccs_int(char *path, int *config_val)
 {
 	char *str;
 	int val;
 	int error;
 
-	error = ccs_get(cd, path, &str);
+	error = ccs_get(ccs_handle, path, &str);
 	if (error || !str)
 		return;
 
@@ -48,11 +92,7 @@ int read_ccs(struct fd *fd)
 {
 	char path[256];
 	char *str;
-	int error, cd, i = 0, count = 0;
-
-	cd = open_ccs();
-	if (cd < 0)
-		return cd;
+	int error, i = 0, count = 0;
 
 	/* Our own nodename must be in cluster.conf before we're allowed to
 	   join the fence domain and then mount gfs; other nodes need this to
@@ -62,7 +102,7 @@ int read_ccs(struct fd *fd)
 	memset(path, 0, 256);
 	snprintf(path, 256, OUR_NAME_PATH, our_name);
 
-	error = ccs_get(cd, path, &str);
+	error = ccs_get(ccs_handle, path, &str);
 	if (error || !str) {
 		log_error("local cman node name \"%s\" not found in the "
 			  "configuration", our_name);
@@ -77,22 +117,22 @@ int read_ccs(struct fd *fd)
 	   values set in cluster.conf. */
 
 	if (!comline.groupd_compat_opt)
-		read_ccs_int(cd, GROUPD_COMPAT_PATH, &comline.groupd_compat);
+		read_ccs_int(GROUPD_COMPAT_PATH, &comline.groupd_compat);
 	if (!comline.clean_start_opt)
-		read_ccs_int(cd, CLEAN_START_PATH, &comline.clean_start);
+		read_ccs_int(CLEAN_START_PATH, &comline.clean_start);
 	if (!comline.post_join_delay_opt)
-		read_ccs_int(cd, POST_JOIN_DELAY_PATH, &comline.post_join_delay);
+		read_ccs_int(POST_JOIN_DELAY_PATH, &comline.post_join_delay);
 	if (!comline.post_fail_delay_opt)
-		read_ccs_int(cd, POST_FAIL_DELAY_PATH, &comline.post_fail_delay);
+		read_ccs_int(POST_FAIL_DELAY_PATH, &comline.post_fail_delay);
 	if (!comline.override_time_opt)
-		read_ccs_int(cd, OVERRIDE_TIME_PATH, &comline.override_time);
+		read_ccs_int(OVERRIDE_TIME_PATH, &comline.override_time);
 
 	if (!comline.override_path_opt) {
 		str = NULL;
 		memset(path, 0, 256);
 		sprintf(path, OVERRIDE_PATH_PATH);
 
-		error = ccs_get(cd, path, &str);
+		error = ccs_get(ccs_handle, path, &str);
 		if (!error && str) {
 			free(comline.override_path);
 			comline.override_path = strdup(str);
@@ -111,7 +151,7 @@ int read_ccs(struct fd *fd)
 		memset(path, 0, 256);
 		sprintf(path, "/cluster/clusternodes/clusternode[%d]/@nodeid", i);
 
-		error = ccs_get(cd, path, &str);
+		error = ccs_get(ccs_handle, path, &str);
 		if (error || !str)
 			break;
 
@@ -122,7 +162,6 @@ int read_ccs(struct fd *fd)
 
 	log_debug("added %d nodes from ccs", count);
  out:
-	ccs_disconnect(cd);
 	return 0;
 }
 
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index 5ef1756..7fa4b07 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -10,7 +10,6 @@
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
-#include <syslog.h>
 #include <time.h>
 #include <sched.h>
 #include <sys/ioctl.h>
@@ -24,6 +23,7 @@
 
 #include <openais/saAis.h>
 #include <openais/cpg.h>
+#include <openais/service/logsys.h>
 
 #include "list.h"
 #include "linux_endian.h"
@@ -58,6 +58,7 @@
 #define GROUP_LIBCPG            3
 
 extern int daemon_debug_opt;
+extern int daemon_debug_logsys;
 extern int daemon_quit;
 extern struct list_head domains;
 extern int cman_quorate;
@@ -74,14 +75,23 @@ extern void daemon_dump_save(void);
 #define log_debug(fmt, args...) \
 do { \
 	snprintf(daemon_debug_buf, 255, "%ld " fmt "\n", time(NULL), ##args); \
-	if (daemon_debug_opt) fprintf(stderr, "%s", daemon_debug_buf); \
 	daemon_dump_save(); \
+	if (daemon_debug_opt) \
+		fprintf(stderr, "%s", daemon_debug_buf); \
+	if (daemon_debug_logsys) \
+		log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
 } while (0)
 
 #define log_error(fmt, args...) \
 do { \
 	log_debug(fmt, ##args); \
-	syslog(LOG_ERR, fmt, ##args); \
+	log_printf(LOG_ERR, fmt, ##args); \
+} while (0)
+
+#define log_level(lvl, fmt, args...) \
+do { \
+	log_debug(fmt, ##args); \
+	log_printf(lvl, fmt, ##args); \
 } while (0)
 
 /* config option defaults */
@@ -210,6 +220,11 @@ struct fd {
 
 /* config.c */
 
+int setup_ccs(void);
+void close_ccs(void);
+void read_ccs_name(char *path, char *name);
+void read_ccs_yesno(char *path, int *yes, int *no);
+void read_ccs_int(char *path, int *config_val);
 int read_ccs(struct fd *fd);
 
 /* cpg.c */
@@ -231,6 +246,7 @@ int set_domain_nodes(struct fd *fd, int option, int *node_count,
 
 void process_groupd(int ci);
 int setup_groupd(void);
+void close_groupd(void);
 int fd_join_group(struct fd *fd);
 int fd_leave_group(struct fd *fd);
 int set_node_info_group(struct fd *fd, int nodeid, struct fenced_node *node);
@@ -251,6 +267,7 @@ void query_unlock(void);
 
 void process_cman(int ci);
 int setup_cman(void);
+void close_cman(void);
 int is_cman_member(int nodeid);
 char *nodeid_to_name(int nodeid);
 int name_to_nodeid(char *name);
@@ -266,5 +283,11 @@ void delay_fencing(struct fd *fd, int node_join);
 void defer_fencing(struct fd *fd);
 void fence_victims(struct fd *fd);
 
+/* logging.c */
+
+void init_logging(void);
+void setup_logging(int *prog_debug);
+void close_logging(void);
+
 #endif				/*  __FD_DOT_H__  */
 
diff --git a/fence/fenced/group.c b/fence/fenced/group.c
index 5f8f08a..d546ec4 100644
--- a/fence/fenced/group.c
+++ b/fence/fenced/group.c
@@ -363,12 +363,10 @@ int setup_groupd(void)
 	return rv;
 }
 
-/*
-void exit_groupd(void)
+void close_groupd(void)
 {
 	group_exit(gh);
 }
-*/
 
 int fd_join_group(struct fd *fd)
 {
diff --git a/fence/fenced/logging.c b/fence/fenced/logging.c
new file mode 100644
index 0000000..ed4af39
--- /dev/null
+++ b/fence/fenced/logging.c
@@ -0,0 +1,160 @@
+#include "fd.h"
+
+#define DEFAULT_MODE		LOG_MODE_OUTPUT_SYSLOG_THREADED
+#define DEFAULT_FACILITY	SYSLOGFACILITY /* cluster config setting */
+#define DEFAULT_PRIORITY	LOG_LEVEL_INFO
+#define DEFAULT_FILE		LOGDIR "/fenced.log"
+
+#define LEVEL_PATH "/cluster/logging/logger_subsys[ subsys=\"FENCED\"]/@syslog_level"
+#define DEBUG_PATH "/cluster/logging/logger_subsys[ subsys=\"FENCED\"]/@debug"
+
+/* Read cluster.conf settings and convert them into logsys values.
+   If no cluster.conf setting exists, the default that was used in
+   logsys_init() is used.
+
+   mode from
+   "/cluster/logging/@to_stderr"
+   "/cluster/logging/@to_syslog"
+   "/cluster/logging/@to_file"
+
+   facility from
+   "/cluster/logging/@syslog_facility"
+
+   priority from
+   "/cluster/logging/logger_subsys[ subsys=\"prog_name\"]/@syslog_level"
+
+   file from
+   "/cluster/logging/@filename"
+
+   debug from
+   "/cluster/logging/@debug"
+   "/cluster/logging/logger_subsys[ subsys=\"prog_name\"]/@debug"
+*/
+
+static int read_ccs_logging(int *mode, int *facility, int *priority, char *file,
+			    int *debug)
+{
+	char name[PATH_MAX];
+	int val, y, n;
+	int m = 0, f = 0, p = 0;
+
+	/*
+	 * mode
+	 */
+
+	m = DEFAULT_MODE;
+
+	read_ccs_yesno("/cluster/logging/@to_stderr", &y, &n);
+	if (y)
+		m |= LOG_MODE_OUTPUT_STDERR;
+	if (n)
+		m &= ~LOG_MODE_OUTPUT_STDERR;
+
+	read_ccs_yesno("/cluster/logging/@to_syslog", &y, &n);
+	if (y)
+		m |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
+	if (n)
+		m &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
+
+	read_ccs_yesno("/cluster/logging/@to_file", &y, &n);
+	if (y)
+		m |= LOG_MODE_OUTPUT_FILE;
+	if (n)
+		m &= ~LOG_MODE_OUTPUT_FILE;
+
+	*mode = m;
+
+	/*
+	 * facility
+	 */
+
+	f = DEFAULT_FACILITY;
+
+	memset(name, 0, sizeof(name));
+	read_ccs_name("/cluster/logging/@syslog_facility", name);
+
+	if (name[0]) {
+		val = logsys_facility_id_get(name);
+		if (val >= 0)
+			f = val;
+	}
+
+	*facility = f;
+
+	/*
+	 * priority
+	 */
+
+	p = DEFAULT_PRIORITY;
+
+	memset(name, 0, sizeof(name));
+	read_ccs_name(LEVEL_PATH, name);
+
+	if (name[0]) {
+		val = logsys_priority_id_get(name);
+		if (val >= 0)
+			p = val;
+	}
+
+	*priority = p;
+
+	/*
+	 * file
+	 */
+
+	strcpy(file, DEFAULT_FILE);
+
+	memset(name, 0, sizeof(name));
+	read_ccs_name("/cluster/logging/@filename", name);
+
+	if (name[0])
+		strcpy(file, name);
+
+	/*
+	 * debug
+	 */
+
+	memset(name, 0, sizeof(name));
+	read_ccs_name("/cluster/logging/@debug", name);
+
+	if (!strcmp(name, "on"))
+		*debug = 1;
+
+	memset(name, 0, sizeof(name));
+	read_ccs_name(DEBUG_PATH, name);
+
+	if (!strcmp(name, "on"))
+		*debug = 1;
+	else if (!strcmp(name, "off"))
+		*debug = 0;
+
+	return 0;
+}
+
+/* initial settings until we can read cluster.conf logging settings from ccs */
+
+void init_logging(void)
+{
+	logsys_init("fenced", DEFAULT_MODE, DEFAULT_FACILITY, DEFAULT_PRIORITY,
+		    DEFAULT_FILE);
+}
+
+/* this function is also called when we get a cman config-update event */
+
+void setup_logging(int *prog_debug)
+{
+	int mode, facility, priority;
+	char file[PATH_MAX];
+
+	/* The debug setting is special, it's used by the program
+	   and not used to configure logsys. */
+
+	read_ccs_logging(&mode, &facility, &priority, file, prog_debug);
+	logsys_conf("fenced", mode, facility, priority, file);
+}
+
+void close_logging(void)
+{
+	logsys_exit();
+}
+
diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index 83ca075..c4e1caf 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -596,10 +596,10 @@ static int setup_queries(void)
 static void cluster_dead(int ci)
 {
 	log_error("cluster is down, exiting");
-	exit(1);
+	daemon_quit = 1;
 }
 
-static int loop(void)
+static void loop(void)
 {
 	int rv, i;
 	void (*workfn) (int ci);
@@ -619,6 +619,12 @@ static int loop(void)
 		goto out;
 	client_add(rv, process_cman, cluster_dead);
 
+	rv = setup_ccs();
+	if (rv < 0)
+		goto out;
+
+	setup_logging(&daemon_debug_logsys);
+
 	group_mode = GROUP_LIBCPG;
 
 	if (comline.groupd_compat) {
@@ -647,9 +653,8 @@ static int loop(void)
 	for (;;) {
 		rv = poll(pollfd, client_maxi + 1, -1);
 		if (rv == -1 && errno == EINTR) {
-			if (daemon_quit && list_empty(&domains)) {
-				exit(1);
-			}
+			if (daemon_quit && list_empty(&domains))
+				goto out;
 			daemon_quit = 0;
 			continue;
 		}
@@ -673,11 +678,16 @@ static int loop(void)
 			}
 		}
 		pthread_mutex_unlock(&query_mutex);
+
+		if (daemon_quit)
+			break;
 	}
-	rv = 0;
  out:
-	free(pollfd);
-	return rv;
+	if (comline.groupd_compat)
+		close_groupd();
+	close_logging();
+	close_ccs();
+	close_cman();
 }
 
 static void lockfile(void)
@@ -852,6 +862,8 @@ int main(int argc, char **argv)
 	comline.override_time = DEFAULT_OVERRIDE_TIME;
 	comline.override_path = strdup(DEFAULT_OVERRIDE_PATH);
 
+	init_logging();
+
 	read_arguments(argc, argv);
 
 	lockfile();
@@ -863,12 +875,13 @@ int main(int argc, char **argv)
 		}
 		umask(0);
 	}
-	openlog("fenced", LOG_PID, LOG_DAEMON);
 	signal(SIGTERM, sigterm_handler);
 
 	set_oom_adj(-16);
 
-	return loop();
+	loop();
+
+	return 0;
 }
 
 void daemon_dump_save(void)
@@ -888,6 +901,7 @@ void daemon_dump_save(void)
 }
 
 int daemon_debug_opt;
+int daemon_debug_logsys;
 int daemon_quit;
 struct list_head domains;
 int cman_quorate;
diff --git a/fence/fenced/member_cman.c b/fence/fenced/member_cman.c
index e85fcb6..71d0caa 100644
--- a/fence/fenced/member_cman.c
+++ b/fence/fenced/member_cman.c
@@ -122,6 +122,10 @@ static void cman_callback(cman_handle_t h, void *private, int reason, int arg)
 		if (!quorate && cman_quorate && (group_mode == GROUP_LIBCPG))
 			process_fd_changes();
 		break;
+
+	case CMAN_REASON_CONFIG_UPDATE:
+		setup_logging(&daemon_debug_logsys);
+		break;
 	}
 }
 
@@ -140,10 +144,28 @@ int setup_cman(void)
 {
 	cman_node_t node;
 	int rv, fd;
+	int init = 0, active = 0;
 
+ retry_init:
 	ch = cman_init(NULL);
 	if (!ch) {
-		log_error("cman_init error %p %d", ch, errno);
+		if (init++ < 2) {
+			sleep(1);
+			goto retry_init;
+		}
+		log_error("cman_init error %d", errno);
+		return -ENOTCONN;
+	}
+
+ retry_active:
+	rv = cman_is_active(ch);
+	if (!rv) {
+		if (active++ < 2) {
+			sleep(1);
+			goto retry_active;
+		}
+		log_error("cman_is_active error %d", errno);
+		cman_finish(ch);
 		return -ENOTCONN;
 	}
 
@@ -177,12 +199,10 @@ int setup_cman(void)
 	return fd;
 }
 
-/*
-void exit_member(void)
+void close_cman(void)
 {
 	cman_finish(ch);
 }
-*/
 
 int is_cman_member(int nodeid)
 {
diff --git a/fence/fenced/recover.c b/fence/fenced/recover.c
index 21bf735..b1b4091 100644
--- a/fence/fenced/recover.c
+++ b/fence/fenced/recover.c
@@ -116,7 +116,7 @@ static int check_override(int ofd, char *nodename, int timeout)
 
 	ret = select(ofd + 1, &rfds, NULL, NULL, &tv);
 	if (ret < 0) {
-		syslog(LOG_ERR, "select: %s\n", strerror(errno));
+		log_debug("check_override select: %s", strerror(errno));
 		return -1;
 	}
 
@@ -126,7 +126,7 @@ static int check_override(int ofd, char *nodename, int timeout)
 	memset(buf, 0, sizeof(buf));
 	ret = read(ofd, buf, sizeof(buf) - 1);
 	if (ret < 0) {
-		syslog(LOG_ERR, "read: %s\n", strerror(errno));
+		log_debug("check_override read: %s", strerror(errno));
 		return -1;
 	}
 
@@ -212,8 +212,8 @@ void delay_fencing(struct fd *fd, int node_join)
 		  (int) (last.tv_sec - first.tv_sec), victim_count);
  out:
 	list_for_each_entry(node, &fd->victims, list) {
-		syslog(LOG_INFO, "%s not a cluster member after %d sec %s",
-		       node->name, delay, delay_type);
+		log_debug("%s not a cluster member after %d sec %s",
+		          node->name, delay, delay_type);
 	}
 }
 
@@ -226,8 +226,7 @@ void defer_fencing(struct fd *fd)
 
 	master_name = nodeid_to_name(fd->master);
 
-	log_debug("defer fencing to %d %s", fd->master, master_name);
-	syslog(LOG_INFO, "fencing deferred to %s", master_name);
+	log_level(LOG_INFO, "fencing deferred to %s", master_name);
 }
 
 void fence_victims(struct fd *fd)
@@ -257,15 +256,14 @@ void fence_victims(struct fd *fd)
 			continue;
 		}
 
-		log_debug("fencing node %s", node->name);
-		syslog(LOG_INFO, "fencing node \"%s\"", node->name);
+		log_level(LOG_INFO, "fencing node \"%s\"", node->name);
 
 		query_unlock();
 		error = fence_node(node->name);
 		query_lock();
 
-		syslog(LOG_INFO, "fence \"%s\" %s", node->name,
-		       error ? "failed" : "success");
+		log_level(LOG_INFO, "fence \"%s\" %s", node->name,
+			  error ? "failed" : "success");
 
 		if (!error) {
 			victim_done(fd, node->nodeid, VIC_DONE_AGENT);
@@ -286,8 +284,8 @@ void fence_victims(struct fd *fd)
 		override = open_override(comline.override_path);
 		if (check_override(override, node->name,
 				   comline.override_time) > 0) {
-			syslog(LOG_WARNING, "fence \"%s\" overridden by "
-			       "administrator intervention", node->name);
+			log_level(LOG_WARNING, "fence \"%s\" overridden by "
+				  "administrator intervention", node->name);
 			victim_done(fd, node->nodeid, VIC_DONE_OVERRIDE);
 			list_del(&node->list);
 			free(node);


hooks/post-receive
--
Cluster Project


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