Skip to contentSkip to conversation

logsys in fenced

Cluster-devel David Teigland 4 participants 10 messages Jun 25, 2008 – Jun 28, 2008

lore
Share & tools
lore
#0 lore raw

Attached two patches:
fenced-revert.patch reverts the current logsys changes to fenced. fenced-logsys.patch is my own logsys conversion for fenced.

I've not compiled or tested these patches yet (the version of openais I have working on my test machines does not have logsys and I don't want to disrupt my tests on those machines.) I'll push these once they compile.

I have yet to study logsys enough to propose an alternative to the macro magic that's now isolated at the end of fd.h.

Regarding libfence which uses syslog, we can just remove the syslog calls, they're nonessential. I guess fence agents should log errors, if they don't already.

-------------- next part --------------

Quoted 3 lines

From: David Teigland <[email protected]>
Date: Wed, 25 Jun 2008 13:30:11 -0500
Subject: fenced: revert logsys commits

[FENCE] Start porting fenced to logsys
cf4c7ebac813b0b607acf6cf74bbdddfc8cfb12a

[FENCE] Make fenced ready to load logsys config
c54c56c5a09f98547ceda3bc5fa9afa28b354480

[FENCE] Move logsys configuration calls where they belong 18e085596bb8844f74689a92662f2e5e9166836b

[FENCE] Allow fenced to configure logsys
da704715c606c9c01637ae53d79f8dec6a8b0389

[FENCE] fenced: separate concept of fork and debugging 95a5c6b13294742956b13070ebc4f4513278255f

---
 fence/fenced/Makefile      |    4 +-
 fence/fenced/config.c      |  147 ++------------------------------------------
 fence/fenced/cpg.c         |  116 +++++++++++++++++------------------
 fence/fenced/fd.h          |   15 +++--
 fence/fenced/group.c       |   33 +++++-----
 fence/fenced/main.c        |   61 +++++++------------
 fence/fenced/member_cman.c |   19 +++---
 fence/fenced/recover.c     |   26 ++++----
 8 files changed, 133 insertions(+), 288 deletions(-)
fence/fenced/Makefile +2 -2
index b2b1e04..1e9bbc9 100644
@@ -22,8 +22,8 @@ CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${fenceincdir} -I${openaisincdir}
 CFLAGS += -I$(S) -I$(S)/../include -I$(S)/../libfenced -I$(SRCDIR)/group/lib
 CFLAGS += -I${incdir}
 
-LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -L${openaislibdir} -lccs -lcman -lcpg -llogsys
-LDFLAGS += -L${fencelibdir} -lfence -lpthread
+LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -L${openaislibdir} -lccs -lcman -lcpg
+LDFLAGS += -L${fencelibdir} -L${openaislibdir} -lfence -lcpg -lpthread
 LDFLAGS += -L../../group/lib -l group
 
 
fence/fenced/config.c +6 -141

196 lines not on this page · raw message

fence/fenced/cpg.c +57 -59

451 lines not on this page · raw message

fence/fenced/fd.h +9 -6
index 802d29c..5ef1756 100644
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
+#include <syslog.h>
 #include <time.h>
 #include <sched.h>
 #include <sys/ioctl.h>
@@ -23,7 +24,6 @@
 
 #include <openais/saAis.h>
 #include <openais/cpg.h>
-#include <openais/service/logsys.h>
 
 #include "list.h"
 #include "linux_endian.h"
@@ -58,7 +58,6 @@
 #define GROUP_LIBCPG            3
 
 extern int daemon_debug_opt;
-extern int daemon_fork;
 extern int daemon_quit;
 extern struct list_head domains;
 extern int cman_quorate;
@@ -69,15 +68,20 @@ extern char dump_buf[FENCED_DUMP_SIZE];
 extern int dump_point;
 extern int dump_wrap;
 extern int group_mode;
-extern int trylater;
 
 extern void daemon_dump_save(void);
 
-#define log_printf_debug(fmt, args...) \
+#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(); \
-	log_printf(LOG_DEBUG, fmt, ##args); \
+} while (0)
+
+#define log_error(fmt, args...) \
+do { \
+	log_debug(fmt, ##args); \
+	syslog(LOG_ERR, fmt, ##args); \
 } while (0)
 
 /* config option defaults */
@@ -242,7 +246,6 @@ void free_fd(struct fd *fd);
 struct fd *find_fd(char *name);
 void query_lock(void);
 void query_unlock(void);
-int get_logsys_config_data(void);
 
 /* member_cman.c */
 
fence/fenced/group.c +16 -17
index eb43bd5..5f8f08a 100644
@@ -21,7 +21,6 @@ static int cb_type;
 static int cb_member_count;
 static int cb_members[MAX_NODES];
 
-LOGSYS_DECLARE_SUBSYS ("FENCED", LOG_LEVEL_INFO);
 
 static void stop_cbfn(group_handle_t h, void *private, char *name)
 {
@@ -170,13 +169,13 @@ static void _add_first_victims(struct fd *fd)
 
 	/* complete list initialised in init_nodes() to all nodes from ccs */
 	if (list_empty(&fd->complete))
-		log_printf_debug("first complete list empty warning");
+		log_debug("first complete list empty warning");
 
 	list_for_each_entry_safe(prev_node, safe, &fd->complete, list) {
 		if (!is_cman_member(prev_node->nodeid)) {
 			list_del(&prev_node->list);
 			list_add(&prev_node->list, &fd->victims);
-			log_printf_debug("add first victim %s", prev_node->name);
+			log_debug("add first victim %s", prev_node->name);
 			prev_node->init_victim = 1;
 		}
 	}
@@ -197,7 +196,7 @@ static void _add_victims(struct fd *fd, int start_type, int member_count,
 				list_add(&node->list, &fd->complete);
 			else {
 				list_add(&node->list, &fd->victims);
-				log_printf_debug("add victim %u, was leaving",
+				log_debug("add victim %u, was leaving",
 					  node->nodeid);
 			}
 		}
@@ -207,7 +206,7 @@ static void _add_victims(struct fd *fd, int start_type, int member_count,
 	 * to victims list or leaving list, depending on the type of start. */
 
 	if (list_empty(&fd->complete))
-		log_printf_debug("complete list empty warning");
+		log_debug("complete list empty warning");
 
 	list_for_each_entry_safe(node, safe, &fd->complete, list) {
 		if (!id_in_nodeids(node->nodeid, member_count, nodeids)) {
@@ -218,7 +217,7 @@ static void _add_victims(struct fd *fd, int start_type, int member_count,
 			else
 				list_add(&node->list, &fd->leaving);
 
-			log_printf_debug("add node %u to list %u", node->nodeid,
+			log_debug("add node %u to list %u", node->nodeid,
 				  start_type);
 		}
 	}
@@ -232,7 +231,7 @@ static void add_victims(struct fd *fd, int start_type, int member_count,
 	 * start/stop/start immediately upon joining. */
 
 	if (!fd->last_finish && fd->last_stop) {
-		log_printf_debug("revert aborted first start");
+		log_debug("revert aborted first start");
 		fd->last_stop = 0;
 		fd->first_recovery = 0;
 		free_node_list(&fd->prev);
@@ -240,7 +239,7 @@ static void add_victims(struct fd *fd, int start_type, int member_count,
 		free_node_list(&fd->leaving);
 	}
 
-	log_printf_debug("add_victims stop %d start %d finish %d",
+	log_debug("add_victims stop %d start %d finish %d",
 		  fd->last_stop, fd->last_start, fd->last_finish);
 
 	if (!fd->first_recovery) {
@@ -295,13 +294,13 @@ void process_groupd(int ci)
 
 	switch (cb_action) {
 	case DO_STOP:
-		log_printf_debug("stop %s", cb_name);
+		log_debug("stop %s", cb_name);
 		fd->last_stop = fd->last_start;
 		group_stop_done(gh, cb_name);
 		break;
 
 	case DO_START:
-		log_printf_debug("start %s %d members %s", cb_name, cb_event_nr,
+		log_debug("start %s %d members %s", cb_name, cb_event_nr,
 			  str_members());
 		fd->last_start = cb_event_nr;
 
@@ -321,7 +320,7 @@ void process_groupd(int ci)
 		break;
 
 	case DO_FINISH:
-		log_printf_debug("finish %s %d", cb_name, cb_event_nr);
+		log_debug("finish %s %d", cb_name, cb_event_nr);
 		fd->last_finish = cb_event_nr;
 
 		/* we get terminate callback when all have started, which means
@@ -331,9 +330,9 @@ void process_groupd(int ci)
 		break;
 
 	case DO_TERMINATE:
-		log_printf_debug("terminate %s", cb_name);
+		log_debug("terminate %s", cb_name);
 		if (!fd->leaving_group)
-			log_printf(LOG_ERR, "process_groupd terminate not leaving");
+			log_error("process_groupd terminate not leaving");
 		list_del(&fd->list);
 		free_fd(fd);
 		break;
@@ -355,12 +354,12 @@ int setup_groupd(void)
 
 	gh = group_init(NULL, "fence", 0, &callbacks, GROUPD_TIMEOUT);
 	if (!gh) {
-		log_printf(LOG_ERR, "group_init error %p %d", gh, errno);
+		log_error("group_init error %p %d", gh, errno);
 		return -ENOTCONN;
 	}
 	rv = group_get_fd(gh);
 	if (rv < 0)
-		log_printf(LOG_ERR, "group_get_fd error %d %d", rv, errno);
+		log_error("group_get_fd error %d %d", rv, errno);
 	return rv;
 }
 
@@ -380,7 +379,7 @@ int fd_join_group(struct fd *fd)
 
 	rv = group_join(gh, fd->name);
 	if (rv) {
-		log_printf(LOG_ERR, "group_join error %d", rv);
+		log_error("group_join error %d", rv);
 		list_del(&fd->list);
 		free(fd);
 	}
@@ -395,7 +394,7 @@ int fd_leave_group(struct fd *fd)
 
 	rv = group_leave(gh, fd->name);
 	if (rv)
-		log_printf(LOG_ERR, "group_leave error %d", rv);
+		log_error("group_leave error %d", rv);
 
 	return rv;
 }
fence/fenced/main.c +22 -39

190 lines not on this page · raw message

fence/fenced/member_cman.c +9 -10
index 6ac6e1e..e85fcb6 100644
@@ -7,7 +7,6 @@ static cman_handle_t	ch;
 static cman_node_t	cman_nodes[MAX_NODES];
 static int		cman_node_count;
 
-LOGSYS_DECLARE_SUBSYS ("FENCED", LOG_LEVEL_INFO);
 
 static int name_equal(char *name1, char *name2)
 {
@@ -100,7 +99,7 @@ static void statechange(void)
 
 	rv = cman_get_nodes(ch, MAX_NODES, &cman_node_count, cman_nodes);
 	if (rv < 0)
-		log_printf(LOG_ERR, "cman_get_nodes error %d %d", rv, errno);
+		log_error("cman_get_nodes error %d %d", rv, errno);
 }
 
 static void cman_callback(cman_handle_t h, void *private, int reason, int arg)
@@ -112,7 +111,7 @@ static void cman_callback(cman_handle_t h, void *private, int reason, int arg)
 		if (list_empty(&domains))
 			cman_replyto_shutdown(ch, 1);
 		else {
-			log_printf_debug("no to cman shutdown");
+			log_debug("no to cman shutdown");
 			cman_replyto_shutdown(ch, 0);
 		}
 		break;
@@ -132,7 +131,7 @@ void process_cman(int ci)
 
 	rv = cman_dispatch(ch, CMAN_DISPATCH_ALL);
 	if (rv == -1 && errno == EHOSTDOWN) {
-		log_printf(LOG_ERR, "cluster is down, exiting");
+		log_error("cluster is down, exiting");
 		exit(1);
 	}
 }
@@ -144,13 +143,13 @@ int setup_cman(void)
 
 	ch = cman_init(NULL);
 	if (!ch) {
-		log_printf(LOG_ERR, "cman_init error %p %d", ch, errno);
+		log_error("cman_init error %p %d", ch, errno);
 		return -ENOTCONN;
 	}
 
 	rv = cman_start_notification(ch, cman_callback);
 	if (rv < 0) {
-		log_printf(LOG_ERR, "cman_start_notification error %d %d", rv, errno);
+		log_error("cman_start_notification error %d %d", rv, errno);
 		cman_finish(ch);
 		return rv;
 	}
@@ -163,7 +162,7 @@ int setup_cman(void)
 	memset(&node, 0, sizeof(node));
 	rv = cman_get_node(ch, CMAN_NODEID_US, &node);
 	if (rv < 0) {
-		log_printf(LOG_ERR, "cman_get_node us error %d %d", rv, errno);
+		log_error("cman_get_node us error %d %d", rv, errno);
 		cman_finish(ch);
 		fd = rv;
 		goto out;
@@ -173,7 +172,7 @@ int setup_cman(void)
 	strncpy(our_name, node.cn_name, CMAN_MAX_NODENAME_LEN);
 	our_nodeid = node.cn_nodeid;
 
-	log_printf_debug("our_nodeid %d our_name %s", our_nodeid, our_name);
+	log_debug("our_nodeid %d our_name %s", our_nodeid, our_name);
  out:
 	return fd;
 }
@@ -197,7 +196,7 @@ int is_cman_member(int nodeid)
 	if (cn && cn->cn_member)
 		return 1;
 
-	log_printf_debug("node %d not a cman member, cn %d", nodeid, cn ? 1 : 0);
+	log_debug("node %d not a cman member, cn %d", nodeid, cn ? 1 : 0);
 	return 0;
 }
 
@@ -217,7 +216,7 @@ struct node *get_new_node(struct fd *fd, int nodeid)
 	memset(&cn, 0, sizeof(cn));
 	rv = cman_get_node(ch, nodeid, &cn);
 	if (rv < 0)
-		log_printf_debug("get_new_node %d no cman node %d", nodeid, rv);
+		log_debug("get_new_node %d no cman node %d", nodeid, rv);
 	else
 		strncpy(node->name, cn.cn_name, MAX_NODENAME_LEN);
 
fence/fenced/recover.c +12 -14
index 55d1a12..21bf735 100644
@@ -1,7 +1,5 @@
 #include "fd.h"
 
-LOGSYS_DECLARE_SUBSYS ("FENCED", LOG_LEVEL_INFO);
-
 void free_node_list(struct list_head *head)
 {
 	struct node *node;
@@ -64,7 +62,7 @@ static int reduce_victims(struct fd *fd)
 
 	list_for_each_entry_safe(node, safe, &fd->victims, list) {
 		if (is_cman_member(node->nodeid)) {
-			log_printf_debug("reduce victim %s", node->name);
+			log_debug("reduce victim %s", node->name);
 			victim_done(fd, node->nodeid, VIC_DONE_MEMBER);
 			list_del(&node->list);
 			free(node);
@@ -118,7 +116,7 @@ static int check_override(int ofd, char *nodename, int timeout)
 
 	ret = select(ofd + 1, &rfds, NULL, NULL, &tv);
 	if (ret < 0) {
-		log_printf(LOG_ERR, "select: %s\n", strerror(errno));
+		syslog(LOG_ERR, "select: %s\n", strerror(errno));
 		return -1;
 	}
 
@@ -128,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) {
-		log_printf(LOG_ERR, "read: %s\n", strerror(errno));
+		syslog(LOG_ERR, "read: %s\n", strerror(errno));
 		return -1;
 	}
 
@@ -210,11 +208,11 @@ void delay_fencing(struct fd *fd, int node_join)
 
 	gettimeofday(&last, NULL);
 
-	log_printf_debug("delay of %ds leaves %d victims",
+	log_debug("delay of %ds leaves %d victims",
 		  (int) (last.tv_sec - first.tv_sec), victim_count);
  out:
 	list_for_each_entry(node, &fd->victims, list) {
-		log_printf(LOG_INFO, "%s not a cluster member after %d sec %s",
+		syslog(LOG_INFO, "%s not a cluster member after %d sec %s",
 		       node->name, delay, delay_type);
 	}
 }
@@ -228,8 +226,8 @@ void defer_fencing(struct fd *fd)
 
 	master_name = nodeid_to_name(fd->master);
 
-	log_printf_debug("defer fencing to %d %s", fd->master, master_name);
-	log_printf(LOG_INFO, "fencing deferred to %s", master_name);
+	log_debug("defer fencing to %d %s", fd->master, master_name);
+	syslog(LOG_INFO, "fencing deferred to %s", master_name);
 }
 
 void fence_victims(struct fd *fd)
@@ -249,7 +247,7 @@ void fence_victims(struct fd *fd)
 			fenced = 0;
 
 		if (member || fenced) {
-			log_printf_debug("averting fence of node %s "
+			log_debug("averting fence of node %s "
 				  "member %d external %d",
 				  node->name, member, fenced);
 			victim_done(fd, node->nodeid, member ? VIC_DONE_MEMBER :
@@ -259,14 +257,14 @@ void fence_victims(struct fd *fd)
 			continue;
 		}
 
-		log_printf_debug("fencing node %s", node->name);
-		log_printf(LOG_INFO, "fencing node \"%s\"", node->name);
+		log_debug("fencing node %s", node->name);
+		syslog(LOG_INFO, "fencing node \"%s\"", node->name);
 
 		query_unlock();
 		error = fence_node(node->name);
 		query_lock();
 
-		log_printf(LOG_INFO, "fence \"%s\" %s", node->name,
+		syslog(LOG_INFO, "fence \"%s\" %s", node->name,
 		       error ? "failed" : "success");
 
 		if (!error) {
@@ -288,7 +286,7 @@ void fence_victims(struct fd *fd)
 		override = open_override(comline.override_path);
 		if (check_override(override, node->name,
 				   comline.override_time) > 0) {
-			log_printf(LOG_WARNING, "fence \"%s\" overridden by "
+			syslog(LOG_WARNING, "fence \"%s\" overridden by "
 			       "administrator intervention", node->name);
 			victim_done(fd, node->nodeid, VIC_DONE_OVERRIDE);
 			list_del(&node->list);
Signature · 3 lines
1.5.3.6

-------------- next part --------------
Quoted 3 lines

From: David Teigland <[email protected]>
Date: Wed, 25 Jun 2008 15:56:34 -0500
Subject: fenced: use openais logsys

Replace calls to syslog with calls to logsys, adding a ton of related initialization and configuration. The configuration also now allows debug statements to be directed to logsys.

---
 fence/fenced/config.c  |   44 ++++++++++++++++++-
 fence/fenced/fd.h      |   29 +++++++++++-
 fence/fenced/logging.c |  109 ++++++++++++++++++++++++++++++++++++++++++++++++
 fence/fenced/main.c    |    4 +-
 fence/fenced/recover.c |   18 ++++----
 5 files changed, 189 insertions(+), 15 deletions(-)
 create mode 100644 fence/fenced/logging.c
fence/fenced/config.c +42 -2

56 lines not on this page · raw message

fence/fenced/fd.h +26 -3
index 5ef1756..a222273 100644
@@ -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,17 @@ 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); \
+	else 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)
 
 /* config option defaults */
@@ -210,6 +214,11 @@ struct fd {
 
 /* config.c */
 
+int open_ccs(void);
+void close_ccs(int cd);
+void read_ccs_name(int cd, char *path, char *name);
+void read_ccs_yesno(int cd, char *path, int *yes, int *no);
+void read_ccs_int(int cd, char *path, int *config_val);
 int read_ccs(struct fd *fd);
 
 /* cpg.c */
@@ -266,5 +275,19 @@ void delay_fencing(struct fd *fd, int node_join);
 void defer_fencing(struct fd *fd);
 void fence_victims(struct fd *fd);
 
+/* logging.c */
+
+void setup_logsys(void);
+
+/* logsys magic */
+
+#ifdef MAIN_INCLUDE
+LOGSYS_DECLARE_SYSTEM(NULL,
+	LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_BUFFER_BEFORE_CONFIG,
+	LOGDIR "/fenced.log",
+	SYSLOGFACILITY);
+#endif
+LOGSYS_DECLARE_SUBSYS("FENCED", LOG_LEVEL_INFO);
+
 #endif				/*  __FD_DOT_H__  */
 
fence/fenced/logging.c new file +109 -0

109 lines not on this page · raw message

fence/fenced/main.c +3 -1
index 83ca075..575aecb 100644
@@ -1,3 +1,4 @@
+#define MAIN_INCLUDE
 #include "fd.h"
 #include "pthread.h"
 #include "copyright.cf"
@@ -863,7 +864,7 @@ int main(int argc, char **argv)
 		}
 		umask(0);
 	}
-	openlog("fenced", LOG_PID, LOG_DAEMON);
+	setup_logsys();
 	signal(SIGTERM, sigterm_handler);
 
 	set_oom_adj(-16);
@@ -888,6 +889,7 @@ void daemon_dump_save(void)
 }
 
 int daemon_debug_opt;
+int daemon_debug_logsys;
 int daemon_quit;
 struct list_head domains;
 int cman_quorate;
fence/fenced/recover.c +9 -9
index 21bf735..e3bf7e1 100644
@@ -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_printf(LOG_ERR, "select: %s\n", 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_printf(LOG_ERR, "read: %s\n", 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_printf(LOG_INFO, "%s not a cluster member after %d sec %s",
+		           node->name, delay, delay_type);
 	}
 }
 
@@ -227,7 +227,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_printf(LOG_INFO, "fencing deferred to %s", master_name);
 }
 
 void fence_victims(struct fd *fd)
@@ -258,13 +258,13 @@ void fence_victims(struct fd *fd)
 		}
 
 		log_debug("fencing node %s", node->name);
-		syslog(LOG_INFO, "fencing node \"%s\"", node->name);
+		log_printf(LOG_INFO, "fencing node \"%s\"", node->name);
 
 		query_unlock();
 		error = fence_node(node->name);
 		query_lock();
 
-		syslog(LOG_INFO, "fence \"%s\" %s", node->name,
+		log_printf(LOG_INFO, "fence \"%s\" %s", node->name,
 		       error ? "failed" : "success");
 
 		if (!error) {
@@ -286,8 +286,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_printf(LOG_WARNING, "fence \"%s\" overridden by "
+				   "administrator intervention", node->name);
 			victim_done(fd, node->nodeid, VIC_DONE_OVERRIDE);
 			list_del(&node->list);
 			free(node);
Signature · 1 line
1.5.3.6
#1 lore raw
Quoted 2 lines · David Teigland

Attached two patches:
fenced-revert.patch reverts the current logsys changes to fenced.

If you revert, please do it by meaning of git-revert.

Quoted 8 lines

fenced-logsys.patch is my own logsys conversion for fenced.

I've not compiled or tested these patches yet (the version of openais I have working on my test machines does not have logsys and I don't want to disrupt my tests on those machines.) I'll push these once they compile.

I have yet to study logsys enough to propose an alternative to the macro magic that's now isolated at the end of fd.h.

There are few things that don't work in this patch.

fence/fenced/config.c +1 -1
index 56b7b0e..33fdbf4 100644
@@ -1,7 +1,7 @@
  #include "fd.h"
  #include "ccs.h"
 
-static int open_ccs(void)
+int open_ccs(void)
  {
  	int i = 0, cd;
 
@@ -14,7 +14,47 @@ static int open_ccs(void)
  	return cd;
  }
 

^^ You can't use open_ccs within get_logsys_config_data. open_ccs uses log_printf to log. If it's waiting for ccs, but logging is not available yet, you end up with no information of what is going on.

In the original code, we try once to access the config data. If it works good, otherwise we config logsys manually enough to log what is happening and we try later. You are missing this fallback mechanism.

@@ -74,14 +75,17 @@ 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); \
+ else if (daemon_debug_logsys) \
+ log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
} while (0)

Can those 2 go in parallel?

+ if (daemon_debug_opt) \
+ fprintf(stderr, "%s", daemon_debug_buf); \
+ if (daemon_debug_logsys) \
+ log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \

so that users can decide which one they want without worrying about preferences?

fence/fenced/logging.c new file +6 -0
new file mode 100644
index 0000000..38abc21
@@ -0,0 +1,109 @@
+#include "fd.h"
+
+#define LEVEL_PATH "/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@syslog_level"
+#define DEBUG_PATH "/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@debug"
+
+static int get_logsys_config_data(void)

Most of the configuration logic is wrong and you don't check for a bunch of return codes that could at least inform you or the users of the status of the configuration.

+{
+ int fd, level, loglevel, facility, y, n;
+ unsigned int logmode;
+ char name[PATH_MAX];
+ char *error; /* eh? */

This is for logsys file set. If the call fails to open a file it tells you why there.

+
+ fd = open_ccs();
+ if (fd < 0)
+ return fd;
+
+ /*
+ * set level
+ */
+
+ read_ccs_int(fd, LEVEL_PATH, &level);
+
+ loglevel = logsys_priority_id_get(level);
+ if (loglevel < 0)
+ loglevel = LOG_LEVEL_INFO;
+
+ logsys_config_priority_set(loglevel);
+
+ /*
+ * set mode
+ */
+
+ logmode = logsys_config_mode_get();
+
+ read_ccs_yesno(fd, "/cluster/logging/@to_stderr", &y, &n);
+ if (y)
+ logmode |= LOG_MODE_OUTPUT_STDERR;
+ if (n)
+ logmode &= ~LOG_MODE_OUTPUT_STDERR;
+
+ read_ccs_yesno(fd, "/cluster/logging/@to_syslog", &y, &n);
+ if (y)
+ logmode |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
+ if (n)
+ logmode &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
+
+ read_ccs_yesno(fd, "/cluster/logging/@to_file", &y, &n);
+ if (y)
+ logmode |= LOG_MODE_OUTPUT_FILE;
+ if (n)
+ logmode &= ~LOG_MODE_OUTPUT_FILE;
+
+ if (logmode & LOG_MODE_BUFFER_BEFORE_CONFIG) {
+ logmode &= ~LOG_MODE_BUFFER_BEFORE_CONFIG;
+ logmode |= LOG_MODE_FLUSH_AFTER_CONFIG;
+ logsys_config_mode_set(logmode);
+ }

^^^

This one will init logsys before you have finished setting it up.

+
+ /*
+ * set log file
+ */
+
+ memset(name, 0, sizeof(name));
+ read_ccs_name(fd, "/cluster/logging/@filename", name);
+
+ if (name[0])
+ logsys_config_file_set(&error, name);
+
+ /*
+ * set facility
+ */
+
+ memset(name, 0, sizeof(name));
+ read_ccs_name(fd, "/cluster/logging/@syslog_facility", name);
+
+ facility = logsys_facility_get(name);
+ if (facility < 0)
+ facility = SYSLOGFACILITY;
+
+ logsys_config_facility_set("FENCED", facility);
+
+ /*
+ * set debug (wish this was yes/no like above)
+ */
+
+ memset(name, 0, sizeof(name));
+ read_ccs_name(fd, "/cluster/logging/@debug", name);
+
+ if (!strcmp(name, "on"))
+ daemon_debug_logsys = 1;
+
+ memset(name, 0, sizeof(name));
+ read_ccs_name(fd, DEBUG_PATH, name);
+
+ if (!strcmp(name, "on"))
+ daemon_debug_logsys = 1;
+
+ close_ccs(fd);

Debug needs to be checked before log_level. In logsys debug=on is equivalent of setting syslog_level=debug. The original code I proposed does:

debug from the envvar (that i missed in my original patch) > debug from cmdline > subsystem config debug option > global config debug option.

This allows you a great deal of flexibility to specify: I want all debug on except for this or that subsystem, or i want debugging off, except for.. etc.

Then you set log_level according to that.

+}
+
+void setup_logsys(void)
+{
+ get_logsys_config_data();
+ logsys_config_mode_set(LOG_MODE_OUTPUT_STDERR |

+			       LOG_MODE_OUTPUT_SYSLOG_THREADED |
+			       LOG_MODE_OUTPUT_FILE |
+			       LOG_MODE_FLUSH_AFTER_CONFIG);

+}

this call to logsys_config_mode_set will simply override all the configyration you did for STDERR SYSLOG_THREADED and FILE by setting them all back on.

Fabio

--
I'm going to make him an offer he can't refuse.

#2 lore raw
Quoted 6 lines · Fabio M. Di Nitto
Quoted 2 lines · David Teigland

Attached two patches:
fenced-revert.patch reverts the current logsys changes to fenced.

If you revert, please do it by meaning of git-revert.

That was a series of git-revert -n which the man page suggested:

"This is useful when reverting more than one commits' effect to
your working tree in a row."

Quoted 7 lines

^^ You can't use open_ccs within get_logsys_config_data. open_ccs uses log_printf to log. If it's waiting for ccs, but logging is not available yet, you end up with no information of what is going on.

In the original code, we try once to access the config data. If it works good, otherwise we config logsys manually enough to log what is happening and we try later. You are missing this fallback mechanism.

I think I'll just avoid all the chicken/egg complication by not logging in in open_ccs. I expect it should be nearly impossible for ccs_connect() to fail now with the new ccs. (Previously, ccs_connect would always fail leaving people wondering why nothing was happening, which is why we added the logging. One of the goals of the new ccs is that reading the config should basically never fail.)

Quoted 20 lines
(quoted diff) +4 -1
@@ -74,14 +75,17 @@ 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); \
+	else if (daemon_debug_logsys) \
+		log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
 } while (0)
 

Can those 2 go in parallel?

(quoted diff) +4 -0
+       if (daemon_debug_opt) \
+               fprintf(stderr, "%s", daemon_debug_buf); \
+       if (daemon_debug_logsys) \
+               log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
Quoted 2 lines

so that users can decide which one they want without worrying about preferences?

daemon_debug_opt and daemon_debug_logsys are mutually exclusive by definition; you don't want or need logsys when you're running with -D.

Quoted 15 lines
fence/fenced/logging.c new file +3 -0
new file mode 100644
index 0000000..38abc21
@@ -0,0 +1,109 @@
+#include "fd.h"
+
+#define LEVEL_PATH 

"/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@syslog_level" +#define DEBUG_PATH "/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@debug"

fence/fenced/logging.c new file +2 -0
+
+static int get_logsys_config_data(void)
Quoted 3 lines

Most of the configuration logic is wrong and you don't check for a bunch of return codes that could at least inform you or the users of the status of the configuration.

Yeah, not understanding logsys, I couldn't make sense of the logic that was there, it was "non-obvious", so I just tried to copy it. I obviously have a lot of logsys study to do, hopefully suggesting some simplifications along the way...

Quoted 4 lines

Debug needs to be checked before log_level. In logsys debug=on is equivalent of setting syslog_level=debug. The original code I proposed does:

Quoted 8 lines

debug from the envvar (that i missed in my original patch) > debug from cmdline > subsystem config debug option > global config debug option.

This allows you a great deal of flexibility to specify: I want all debug on except for this or that subsystem, or i want debugging off, except for.. etc.

Then you set log_level according to that.

that sounds like a great deal of complexity for something that shouldn't deserve it.

Quoted 9 lines
fence/fenced/logging.c new file +8 -0
+void setup_logsys(void)
+{
+	get_logsys_config_data();
+	logsys_config_mode_set(LOG_MODE_OUTPUT_STDERR |
+			       LOG_MODE_OUTPUT_SYSLOG_THREADED |
+			       LOG_MODE_OUTPUT_FILE |
+			       LOG_MODE_FLUSH_AFTER_CONFIG);
+}
Quoted 3 lines

this call to logsys_config_mode_set will simply override all the configyration you did for STDERR SYSLOG_THREADED and FILE by setting them all back on.

That puzzled me, too... ah, looks like I mistranslated the original code.

#3 lore raw
Quoted 6 lines · David Teigland
Quoted 5 lines · Fabio M. Di Nitto
Quoted 2 lines · David Teigland

Attached two patches:
fenced-revert.patch reverts the current logsys changes to fenced.

Quoted 6 lines
Quoted 1 line

If you revert, please do it by meaning of git-revert.

That was a series of git-revert -n which the man page suggested:

"This is useful when reverting more than one commits' effect to your working tree in a row."

I missed the git header and I thought you were going to revert by meaning of one single manual patch.

Quoted 11 lines
Quoted 8 lines

^^ You can't use open_ccs within get_logsys_config_data. open_ccs uses log_printf to log. If it's waiting for ccs, but logging is not available yet, you end up with no information of what is going on.

In the original code, we try once to access the config data. If it works good, otherwise we config logsys manually enough to log what is happening and we try later. You are missing this fallback mechanism.

I think I'll just avoid all the chicken/egg complication by not logging in in open_ccs.

So if you can't connect to ccs/objdb, we will have another daemon waiting for something and users will have no idea what.

Quoted 2 lines

I expect it should be nearly impossible for ccs_connect() to
fail now with the new ccs.

Based on what assumption?

Anyway this is another pandora's box to open and should be handled in another thread. We have X different half baked solutions to connected to libccs and cman. None of them do it right. There is space for a little common library that handles it properly and it's not the first time that this issue comes up so maybe it's time to address it.

Quoted 4 lines

(Previously, ccs_connect would always fail
leaving people wondering why nothing was happening, which is why we added the logging. One of the goals of the new ccs is that reading the config should basically never fail.)

eh? so if cman/objdb are not available then what?

Quoted 22 lines
Quoted 22 lines
(quoted diff) +4 -1
@@ -74,14 +75,17 @@ 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); \
+	else if (daemon_debug_logsys) \
+		log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
 } while (0)
 

Can those 2 go in parallel?

(quoted diff) +4 -0
+       if (daemon_debug_opt) \
+               fprintf(stderr, "%s", daemon_debug_buf); \
+       if (daemon_debug_logsys) \
+               log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
Quoted 5 lines
Quoted 2 lines

so that users can decide which one they want without worrying about preferences?

daemon_debug_opt and daemon_debug_logsys are mutually exclusive by definition; you don't want or need logsys when you're running with -D.

Who says? i don't use -D, but i set debug=on and i get the exact same results. Output to stderr included if i don't fork.

Quoted 17 lines
Quoted 17 lines
fence/fenced/logging.c new file +3 -0
new file mode 100644
index 0000000..38abc21
@@ -0,0 +1,109 @@
+#include "fd.h"
+
+#define LEVEL_PATH

"/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@syslog_level" +#define DEBUG_PATH "/cluster/logging/logger_subsys[@subsys=\"FENCED\"]/@debug"

fence/fenced/logging.c new file +2 -0
+
+static int get_logsys_config_data(void)
Quoted 8 lines
Quoted 3 lines

Most of the configuration logic is wrong and you don't check for a bunch of return codes that could at least inform you or the users of the status of the configuration.

Yeah, not understanding logsys, I couldn't make sense of the logic that was there, it was "non-obvious", so I just tried to copy it. I obviously have a lot of logsys study to do, hopefully suggesting some simplifications along the way...

The configuration is dead easy. It was there. You could have just replaced my strcmp with your read_ccsyes/no thingy and it would have work without you having to spend this incredible amount of time on logsys.

Quoted 9 lines
Quoted 9 lines

Debug needs to be checked before log_level. In logsys debug=on is equivalent of setting syslog_level=debug. The original code I proposed does:

debug from the envvar (that i missed in my original patch) > debug from cmdline > subsystem config debug option > global config debug option.

Quoted 8 lines
Quoted 5 lines

This allows you a great deal of flexibility to specify: I want all debug on except for this or that subsystem, or i want debugging off, except for.. etc.

Then you set log_level according to that.

that sounds like a great deal of complexity for something that shouldn't deserve it.

It's not complex at all. It saves you a log of ccs interactions if you set debug from the command line and it allows you to do fine tuned debugging per subsystem.

Fabio

--
I'm going to make him an offer he can't refuse.

#4 lore raw
Quoted 5 lines · Fabio M. Di Nitto

Anyway this is another pandora's box to open and should be handled in another thread. We have X different half baked solutions to connected to libccs and cman. None of them do it right. There is space for a little common library that handles it properly and it's not the first time that this issue comes up so maybe it's time to address it.

For this specific issue i posted another message to cluster-devel.

http://www.redhat.com/archives/cluster-devel/2008-June/msg00217.html

Fabio

--
I'm going to make him an offer he can't refuse.

#5 lore raw
In reply to David Teigland
Quoted 2 lines · David Teigland

I have yet to study logsys enough to propose an alternative to the macro magic that's now isolated at the end of fd.h.

I've done some logsys studying and discussed it with Steve Dake. The logsys implementation and api is heavily geared toward use by openais plugins (see the entire notion of "subsystems" that logsys is built around). Using it from a general program like fenced, not an openais-plugin, makes the mismatch painfully clear.

So, I don't hold out much hope that logsys is going to be useful for non-plugins. But, just because we don't share the actual code that performs logging, doesn't mean we can't have a uniform approach for setting up logging properies for all cluster-related programs. That may still be a worthwhile goal.

#6 lore raw
Quoted 10 lines · David Teigland
Quoted 2 lines · David Teigland

I have yet to study logsys enough to propose an alternative to the macro magic that's now isolated at the end of fd.h.

I've done some logsys studying and discussed it with Steve Dake. The logsys implementation and api is heavily geared toward use by openais plugins (see the entire notion of "subsystems" that logsys is built around). Using it from a general program like fenced, not an openais-plugin, makes the mismatch painfully clear.

Quoted 5 lines

So, I don't hold out much hope that logsys is going to be useful for non-plugins. But, just because we don't share the actual code that performs logging, doesn't mean we can't have a uniform approach for setting up logging properies for all cluster-related programs. That may still be a worthwhile goal.

The hope that I do still hold out for using logsys, is that we may be able to develop a simple syslog-like api for it, that would either parallel or sit above the plugin-oriented api that's there now. Steve claims that the syslog(3) api is fundamentally broken and didn't sound at all interested in the idea, but maybe others are more open to the idea?

#7 lore raw
Quoted 17 lines · David Teigland
Quoted 10 lines · David Teigland
Quoted 2 lines · David Teigland

I have yet to study logsys enough to propose an alternative to the macro magic that's now isolated at the end of fd.h.

I've done some logsys studying and discussed it with Steve Dake. The logsys implementation and api is heavily geared toward use by openais plugins (see the entire notion of "subsystems" that logsys is built around). Using it from a general program like fenced, not an openais-plugin, makes the mismatch painfully clear.

Quoted 5 lines

So, I don't hold out much hope that logsys is going to be useful for non-plugins. But, just because we don't share the actual code that performs logging, doesn't mean we can't have a uniform approach for setting up logging properies for all cluster-related programs. That may still be a worthwhile goal.

Quoted 5 lines

The hope that I do still hold out for using logsys, is that we may be able to develop a simple syslog-like api for it, that would either parallel or sit above the plugin-oriented api that's there now. Steve claims that the syslog(3) api is fundamentally broken and didn't sound at all interested in the idea, but maybe others are more open to the idea?

My goal is to have a common logging infrastructure with the same options all over and that will provide the same output etc. for virtually everything as possible where it makes sense (daemons basically).

If you want to develop a parallel API or an API that sits on top, it's fine by me. Tho you will also have to take the responsibility to convert all code to use it, and update documentation and retain backward compatibility for cman/qdisk/rgmanager that had already their own config sets prior logsys. I for sure don't want see again half code converted and half not.

In my head it sounds a lot of extra work to do but for sure i am not going to stop you, as long this is done before we declare our API stable for 3.0 (that should happen within a reasonable amount of time == a month max).

Fabio

--
I'm going to make him an offer he can't refuse.

#8 lore raw
In reply to David Teigland
Quoted 5 lines · David Teigland

The hope that I do still hold out for using logsys, is that we may be able to develop a simple syslog-like api for it, that would either parallel or sit above the plugin-oriented api that's there now. Steve claims that the syslog(3) api is fundamentally broken and didn't sound at all interested in the idea, but maybe others are more open to the idea?

I wonder what's fundamentally broken about it. I'm sorry that
logsys doesn't use syslog internally - how does it log remotely, for example? :-)

Joel

Signature · 10 lines
Life's Little Instruction Book #94

	"Make it a habit to do nice things for people who 
	 will never find out."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
#9 lore raw
Quoted 7 lines · Joel Becker
Quoted 5 lines · David Teigland

The hope that I do still hold out for using logsys, is that we may be able to develop a simple syslog-like api for it, that would either parallel or sit above the plugin-oriented api that's there now. Steve claims that the syslog(3) api is fundamentally broken and didn't sound at all interested in the idea, but maybe others are more open to the idea?

Quoted 6 lines

I wonder what's fundamentally broken about it. I'm sorry that
logsys doesn't use syslog internally - how does it log remotely, for example? :-)

Joel

The syslog api has served thousands of applications for 20+ years. But the fact is every single application that is significant develops their own logging solution because, frankly, the syslog API is a POS.

The logsys API does use the syslogd daemon's ipc connection but not the c library api which is fundamentally flawed. As a result we support all of the syslogd features that system administrators have come to know and love, and doesn't change any of those features at all!

For logging remotely, all of that is managed by syslogd. Syslogd is a great system. My sole issue is with the c library api syslog/openlog/closelog friends. They were designed in 1970's and are missing some key features. This is the motivation behind logsys. LOGSYS IS A REPLACEMENT for SYSLOG(3) NOT SYSLOGD. It is 100% compatabile with the syslogd daemon shipped in every single distribution in the world.

The logsys api is not "plugin oriented"; it is designed for large software projects that have several components each of which may desire to log specific information at different levels, to different files, or with different tracing levels about different subsystems. Also the syslog api itself is broken because is does not allow nonblocking IO without the loss of log messages.

None of this is supported by the syslog api which is why it is insufficient.

But I can tell I'm talking to a BRICK WALL now since I've been repeating this for 6 months or more, and after everyone seemly agrees logsys is the way to roll, NOW IT IS CRITICAL TO REWRITE THE API because it uses a macro to support subsystems. I try not to take personal insult when these sorts of things happen but seriously, the api has been published for over 6 months and now it is not sufficient? Where were these posts 6 months ago? IMO the naysayers are a day late and a dollar short.

sigh
-steve