dlm: master - dlm_controld/dlm_tool: dump daemon status

David Teigland teigland at fedoraproject.org
Fri Mar 30 20:44:28 UTC 2012


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=d8d82c5f026b306dad35c50a1b038105c19c3324
Commit:        d8d82c5f026b306dad35c50a1b038105c19c3324
Parent:        a2a97c61ed6bb1b0aa82954f1f29c6e317de50ad
Author:        David Teigland <teigland at redhat.com>
AuthorDate:    Fri Mar 30 13:54:12 2012 -0500
Committer:     David Teigland <teigland at redhat.com>
CommitterDate: Fri Mar 30 13:54:12 2012 -0500

dlm_controld/dlm_tool: dump daemon status

dlm_tool status to print current daemon node state.

Signed-off-by: David Teigland <teigland at redhat.com>
---
 dlm_controld/daemon_cpg.c    |  130 ++++++++++++++++++++++++++++++++++++++----
 dlm_controld/dlm_controld.h  |   17 ++++++
 dlm_controld/dlm_daemon.h    |    2 +
 dlm_controld/lib.c           |  104 +++++++++++++++++++++++++++++++++
 dlm_controld/libdlmcontrol.h |    1 +
 dlm_controld/main.c          |    4 +
 dlm_tool/main.c              |   11 ++++
 7 files changed, 257 insertions(+), 12 deletions(-)

diff --git a/dlm_controld/daemon_cpg.c b/dlm_controld/daemon_cpg.c
index 3b7e140..dc9e780 100644
--- a/dlm_controld/daemon_cpg.c
+++ b/dlm_controld/daemon_cpg.c
@@ -54,27 +54,25 @@ struct fence_result {
 struct node_daemon {
 	struct list_head list;
 	int nodeid;
-
-	uint64_t daemon_add_time;
-	uint64_t daemon_rem_time;
-	int daemon_member;
-
 	int killed;
-
-	struct protocol proto;
-
-	struct fence_config fence_config;
-
-	int fence_in_progress_unknown;
+	int daemon_member;
 	int left_reason;
 	int recover_setup;
+	int fence_in_progress_unknown;
 	int need_fence_clear;
 	int need_fencing;
 	int delay_fencing;
 	int fence_pid;
 	int fence_pid_wait;
-	int fence_actor_done;
+	int fence_actor_done; /* for status/debug */
+	int fence_actor_last; /* for status/debug */
 	int fence_actors[MAX_NODES];
+
+	struct protocol proto;
+	struct fence_config fence_config;
+
+	uint64_t daemon_add_time;
+	uint64_t daemon_rem_time;
 	uint64_t fail_walltime;
 	uint64_t fail_monotime;
 	uint64_t fence_walltime;
@@ -553,6 +551,8 @@ static int get_fence_actor(struct node_daemon *node)
 		goto retry;
 	}
 
+	node->fence_actor_last = low;
+
 	return low;
 }
 
@@ -793,6 +793,7 @@ static void daemon_fence_work(void)
 		node->delay_fencing = 0;
 		node->fence_monotime = 0;
 		node->fence_walltime = 0;
+		node->fence_actor_last = 0;
 		node->fence_actor_done = 0;
 		node->fence_pid_wait = 0;
 		node->fence_pid = 0;
@@ -1865,6 +1866,7 @@ static void confchg_cb_daemon(cpg_handle_t handle,
 			node->delay_fencing = 0;
 			node->fence_monotime = 0;
 			node->fence_walltime = 0;
+			node->fence_actor_last = 0;
 			node->fence_actor_done = 0;
 			node->fence_pid_wait = 0;
 			node->fence_pid = 0;
@@ -2011,3 +2013,107 @@ void init_daemon(void)
 	INIT_LIST_HEAD(&startup_nodes);
 
 }
+
+static int print_state_daemon_node(struct node_daemon *node, char *str)
+{
+	snprintf(str, DLMC_STATE_MAXSTR-1,
+		 "member=%d "
+		 "killed=%d "
+		 "left_reason=%d "
+		 "need_fencing=%d "
+		 "delay_fencing=%d "
+		 "fence_pid=%d "
+		 "fence_actor_last=%d "
+		 "fence_actor_done=%d "
+		 "add_time=%llu "
+		 "rem_time=%llu "
+		 "fail_walltime=%llu "
+		 "fail_monotime=%llu "
+		 "fence_walltime=%llu "
+		 "fence_monotime=%llu ",
+		 node->daemon_member,
+		 node->killed,
+		 node->left_reason,
+		 node->need_fencing,
+		 node->delay_fencing,
+		 node->fence_pid,
+		 node->fence_actor_last,
+		 node->fence_actor_done,
+		 (unsigned long long)node->daemon_add_time,
+		 (unsigned long long)node->daemon_rem_time,
+		 (unsigned long long)node->fail_walltime,
+		 (unsigned long long)node->fail_monotime,
+		 (unsigned long long)node->fence_walltime,
+		 (unsigned long long)node->fence_monotime);
+
+	return strlen(str) + 1;
+}
+
+void send_state_daemon_nodes(int fd)
+{
+	struct node_daemon *node;
+	struct dlmc_state st;
+	char str[DLMC_STATE_MAXSTR];
+	int str_len;
+
+	list_for_each_entry(node, &daemon_nodes, list) {
+		memset(&st, 0, sizeof(st));
+		st.type = DLMC_STATE_DAEMON_NODE;
+		st.nodeid = node->nodeid;
+
+		memset(str, 0, sizeof(str));
+		str_len = print_state_daemon_node(node, str);
+
+		st.str_len = str_len;
+
+		send(fd, &st, sizeof(st), MSG_NOSIGNAL);
+		if (str_len)
+			send(fd, str, str_len, MSG_NOSIGNAL);
+	}
+}
+
+static int print_state_daemon(char *str)
+{
+	snprintf(str, DLMC_STATE_MAXSTR-1,
+		 "member_count=%d "
+		 "joined_count=%d "
+		 "remove_count=%d "
+		 "daemon_ringid=%llu "
+		 "cluster_ringid=%llu "
+		 "quorate=%d "
+		 "fence_pid=%d "
+		 "fence_in_progress_unknown=%d "
+		 "zombie_count=%d ",
+		 daemon_member_count,
+		 daemon_joined_count,
+		 daemon_remove_count,
+		 (unsigned long long)daemon_ringid.seq,
+		 (unsigned long long)cluster_ringid_seq,
+		 cluster_quorate,
+		 daemon_fence_pid,
+		 fence_in_progress_unknown,
+		 zombie_count);
+
+	return strlen(str) + 1;
+}
+
+void send_state_daemon(int fd)
+{
+	struct dlmc_state st;
+	char str[DLMC_STATE_MAXSTR];
+	int str_len;
+
+	memset(&st, 0, sizeof(st));
+	st.type = DLMC_STATE_DAEMON;
+	st.nodeid = our_nodeid;
+
+	memset(str, 0, sizeof(str));
+	str_len = print_state_daemon(str);
+
+	st.str_len = str_len;
+
+	send(fd, &st, sizeof(st), MSG_NOSIGNAL);
+	if (str_len)
+		send(fd, str, str_len, MSG_NOSIGNAL);
+}
+
diff --git a/dlm_controld/dlm_controld.h b/dlm_controld/dlm_controld.h
index 96b425c..84662eb 100644
--- a/dlm_controld/dlm_controld.h
+++ b/dlm_controld/dlm_controld.h
@@ -30,6 +30,7 @@
 #define DLMC_CMD_DEADLOCK_CHECK		10
 #define DLMC_CMD_DUMP_LOG_PLOCK		11
 #define DLMC_CMD_FENCE_ACK		12
+#define DLMC_CMD_DUMP_STATUS		13
 
 struct dlmc_header {
 	unsigned int magic;
@@ -43,5 +44,21 @@ struct dlmc_header {
 	char name[DLM_LOCKSPACE_LEN]; /* no terminating null space */
 };
 
+#define DLMC_STATE_MAXSTR       4096
+#define DLMC_STATE_MAXBIN       4096
+
+#define DLMC_STATE_DAEMON       1
+#define DLMC_STATE_DAEMON_NODE  2
+
+struct dlmc_state {
+	uint32_t type; /* DLMC_STATE_ */
+	uint32_t flags;
+	int32_t nodeid;
+	uint32_t data32;
+	uint32_t data64;
+	uint32_t str_len;
+	uint32_t bin_len;
+};
+
 #endif
 
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
index 66e008e..6adb16b 100644
--- a/dlm_controld/dlm_daemon.h
+++ b/dlm_controld/dlm_daemon.h
@@ -339,6 +339,8 @@ void close_cpg_daemon(void);
 void process_cpg_daemon(int ci);
 void set_protocol_stateful(void);
 int set_protocol(void);
+void send_state_daemon_nodes(int fd);
+void send_state_daemon(int fd);
 
 void log_config(const struct cpg_name *group_name,
                 const struct cpg_address *member_list,
diff --git a/dlm_controld/lib.c b/dlm_controld/lib.c
index 228f037..a7cd443 100644
--- a/dlm_controld/lib.c
+++ b/dlm_controld/lib.c
@@ -152,6 +152,110 @@ int dlmc_dump_plocks(char *name, char *buf)
 	return do_dump(DLMC_CMD_DUMP_PLOCKS, name, buf);
 }
 
+static void print_str(char *str, int len)
+{
+	char *p;
+	int i;
+
+	p = &str[0];
+	for (i = 0; i < len-1; i++) {
+		if (str[i] == ' ') {
+			str[i] = '\0';
+			printf("    %s\n", p);
+			p = &str[i+1];
+		}
+	}
+
+	if (p)
+		printf("    %s\n", p);
+}
+
+static void print_daemon(struct dlmc_state *st, char *str, char *bin, uint32_t flags)
+{
+	printf("our_nodeid %d\n", st->nodeid);
+	print_str(str, st->str_len);
+}
+
+static void print_daemon_node(struct dlmc_state *st, char *str, char *bin, uint32_t flags)
+{
+	printf("nodeid %d\n", st->nodeid);
+	print_str(str, st->str_len);
+}
+
+int dlmc_print_status(uint32_t flags)
+{
+	struct dlmc_header h;
+	struct dlmc_state state;
+	struct dlmc_state *st;
+	char maxstr[DLMC_STATE_MAXSTR];
+	char maxbin[DLMC_STATE_MAXBIN];
+	char *str, *bin;
+	int fd, rv, off;
+
+	init_header(&h, DLMC_CMD_DUMP_STATUS, NULL, 0);
+
+	fd = do_connect(DLMC_QUERY_SOCK_PATH);
+	if (fd < 0) {
+		printf("cannot connect to dlm_controld\n");
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	if (rv < 0) {
+		printf("cannot send to dlm_controld\n");
+		goto out_close;
+	}
+
+	st = &state;
+	str = maxstr;
+	bin = maxbin;
+	off = 0;
+
+	while (1) {
+		memset(&state, 0, sizeof(state));
+		memset(maxstr, 0, sizeof(maxstr));
+		memset(maxbin, 0, sizeof(maxbin));
+
+		rv = recv(fd, st, sizeof(struct dlmc_state), MSG_WAITALL);
+		if (!rv)
+			break;
+		if (rv != sizeof(struct dlmc_state))
+			break;
+
+		if (st->str_len) {
+			rv = recv(fd, str, st->str_len, MSG_WAITALL);
+			if (rv != st->str_len)
+				break;
+		}
+
+		if (st->bin_len) {
+			rv = recv(fd, bin, st->bin_len, MSG_WAITALL);
+			if (rv != st->bin_len)
+				break;
+		}
+
+		switch (st->type) {
+		case DLMC_STATE_DAEMON:
+			print_daemon(st, str, bin, flags);
+			break;
+		case DLMC_STATE_DAEMON_NODE:
+			print_daemon_node(st, str, bin, flags);
+			break;
+		default:
+			break;
+		}
+
+		if (rv < 0)
+			break;
+	}
+
+ out_close:
+	close(fd);
+ out:
+	return rv;
+}
+
 int dlmc_node_info(char *name, int nodeid, struct dlmc_node *node)
 {
 	struct dlmc_header h, *rh;
diff --git a/dlm_controld/libdlmcontrol.h b/dlm_controld/libdlmcontrol.h
index 970f705..2af30de 100644
--- a/dlm_controld/libdlmcontrol.h
+++ b/dlm_controld/libdlmcontrol.h
@@ -86,6 +86,7 @@ int dlmc_node_info(char *lsname, int nodeid, struct dlmc_node *node);
 int dlmc_lockspaces(int max, int *count, struct dlmc_lockspace *lss);
 int dlmc_lockspace_nodes(char *lsname, int type, int max, int *count,
 			 struct dlmc_node *nodes);
+int dlmc_print_status(uint32_t flags);
 
 #define DLMC_RESULT_REGISTER	1
 #define DLMC_RESULT_NOTIFIED	2
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index 8e63bb3..794a5c8 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -823,6 +823,10 @@ static void *process_queries(void *arg)
 		case DLMC_CMD_LOCKSPACE_NODES:
 			query_lockspace_nodes(f, h.name, h.option, h.data);
 			break;
+		case DLMC_CMD_DUMP_STATUS:
+			send_state_daemon(f);
+			send_state_daemon_nodes(f);
+			break;
 		default:
 			break;
 		}
diff --git a/dlm_tool/main.c b/dlm_tool/main.c
index 7dddac9..5df5c59 100644
--- a/dlm_tool/main.c
+++ b/dlm_tool/main.c
@@ -39,6 +39,7 @@
 #define OP_LOCKDEBUG			9
 #define OP_LOG_PLOCK			10
 #define OP_FENCE_ACK			11
+#define OP_STATUS			12
 
 static char *prog_name;
 static char *lsname;
@@ -317,6 +318,12 @@ static void decode_arguments(int argc, char **argv)
 			opt_ind = optind + 1;
 			need_lsname = 0;
 			break;
+		} else if (!strncmp(argv[optind], "status", 6) &&
+			   (strlen(argv[optind]) == 6)) {
+			operation = OP_STATUS;
+			opt_ind = optind + 1;
+			need_lsname = 0;
+			break;
 		} else if (!strncmp(argv[optind], "deadlock_check", 14) &&
 			   (strlen(argv[optind]) == 14)) {
 			operation = OP_DEADLOCK_CHECK;
@@ -1322,6 +1329,10 @@ int main(int argc, char **argv)
 		do_list(lsname);
 		break;
 
+	case OP_STATUS:
+		dlmc_print_status(0);
+		break;
+
 	case OP_DUMP:
 		do_dump();
 		break;


More information about the cluster-commits mailing list