public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* Cluster Project branch, master, updated. cluster-2.99.00-5-g91a32ad
@ 2008-04-29 21:39 teigland
  0 siblings, 0 replies; only message in thread
From: teigland @ 2008-04-29 21:39 UTC (permalink / raw)
  To: cluster-cvs, cluster-devel

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=91a32add490287c17a1aef64b0f3eb356c092a5d

The branch, master has been updated
       via  91a32add490287c17a1aef64b0f3eb356c092a5d (commit)
      from  b90340dcfc70b96388cd113487269c80031bd2f1 (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 91a32add490287c17a1aef64b0f3eb356c092a5d
Author: David Teigland <teigland@redhat.com>
Date:   Tue Apr 29 16:28:42 2008 -0500

    libdlmcontrol: new lib interface to dlm_controld
    
    Adds all the structure, most of the calls do nothing yet.
    
    Signed-off-by: David Teigland <teigland@redhat.com>

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

Summary of changes:
 {fence/libfenced => dlm/libdlmcontrol}/Makefile    |    5 +-
 .../libdlmcontrol/libdlmcontrol.h                  |   59 ++++---
 {fence/libfenced => dlm/libdlmcontrol}/main.c      |  153 +++++----------
 dlm/tool/Makefile                                  |    5 +-
 dlm/tool/main.c                                    |   49 +-----
 fence/fenced/fd.h                                  |    6 +-
 fence/fenced/main.c                                |    6 +-
 group/dlm_controld/Makefile                        |    2 +-
 group/dlm_controld/action.c                        |    2 +-
 group/dlm_controld/dlm_controld.h                  |   34 +++-
 group/dlm_controld/dlm_daemon.h                    |   21 +--
 group/dlm_controld/group.c                         |    2 +-
 group/dlm_controld/main.c                          |  194 ++++++++++++++++----
 13 files changed, 303 insertions(+), 235 deletions(-)
 copy {fence/libfenced => dlm/libdlmcontrol}/Makefile (93%)
 copy fence/libfenced/libfenced.h => dlm/libdlmcontrol/libdlmcontrol.h (51%)
 copy {fence/libfenced => dlm/libdlmcontrol}/main.c (55%)

diff --git a/fence/libfenced/Makefile b/dlm/libdlmcontrol/Makefile
similarity index 93%
copy from fence/libfenced/Makefile
copy to dlm/libdlmcontrol/Makefile
index 2191f1f..30447f3 100644
--- a/fence/libfenced/Makefile
+++ b/dlm/libdlmcontrol/Makefile
@@ -10,7 +10,7 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= libfenced
+TARGET= libdlmcontrol
 
 LIBDIRT=$(TARGET).a \
 	$(TARGET).so.$(SOMAJOR).$(SOMINOR)
@@ -35,8 +35,9 @@ include $(OBJDIR)/make/uninstall.mk
 OBJS=	main.o
 
 CFLAGS += -fPIC
-CFLAGS += -I$(S)/../fenced
+CFLAGS += -I$(S)/../../group/dlm_controld
 CFLAGS += -I${incdir}
+CFLAGS += -I$(KERNEL_SRC)/include
 
 $(TARGET).a: $(OBJS)
 	${AR} r $@ $^
diff --git a/fence/libfenced/libfenced.h b/dlm/libdlmcontrol/libdlmcontrol.h
similarity index 51%
copy from fence/libfenced/libfenced.h
copy to dlm/libdlmcontrol/libdlmcontrol.h
index 69ecb6e..69eee26 100644
--- a/fence/libfenced/libfenced.h
+++ b/dlm/libdlmcontrol/libdlmcontrol.h
@@ -20,39 +20,50 @@
 *******************************************************************************
 ******************************************************************************/
 
-#ifndef _LIBFENCED_H_
-#define _LIBFENCED_H_
+#ifndef _LIBDLMCONTROL_H_
+#define _LIBDLMCONTROL_H_
 
-#define FENCED_DUMP_SIZE (1024 * 1024)
+#define DLMC_DUMP_SIZE		(1024 * 1024)
 
-struct fenced_node {
+struct dlmc_node {
 	int nodeid;
 	int member;
-	int victim;
-	int last_fenced_master;
-	int last_fenced_how;
-	uint64_t last_fenced_time;
 };
 
-struct fenced_domain {
+struct dlmc_lockspace {
 	int member_count;
-	int victim_count;
-	int master_nodeid;
-	int current_victim;
 	int state;
 };
 
-/* fenced_domain_nodes() types */
-#define FENCED_NODES_ALL	1
-#define FENCED_NODES_MEMBERS	2
-#define FENCED_NODES_VICTIMS	3
-
-int fenced_join(void);
-int fenced_leave(void);
-int fenced_dump_debug(char *buf);
-int fenced_external(char *name);
-int fenced_node_info(int nodeid, struct fenced_node *node);
-int fenced_domain_info(struct fenced_domain *domain);
-int fenced_domain_nodes(int type, int max, int *count, struct fenced_node *nodes);
+/* dlmc_lockspace_nodes() types */
+#define DLMC_NODES_ALL		1
+#define DLMC_NODES_MEMBERS	2
+
+int dlmc_dump_debug(char *buf);
+int dlmc_dump_plocks(char *name, char *buf);
+int dlmc_node_info(char *name, int nodeid, struct dlmc_node *node);
+int dlmc_lockspace_info(char *name, struct dlmc_lockspace *ls);
+int dlmc_lockspace_nodes(char *name, int type, int max, int *count,
+			 struct dlmc_node *nodes);
+
+/* returns a local unix socket connected to dlm_controld */
+int dlmc_fs_connect(void);
+
+/* closes the unix socket */
+void dlmc_fs_disconnect(int fd);
+
+/* writes to fd: REGISTER + name */
+int dlmc_fs_register(int fd, char *name);
+
+/* writes to fd: UNREGISTER + name */
+int dlmc_fs_unregister(int fd, char *name);
+
+/* writes to fd: NOTIFIED + name + nodeid */
+int dlmc_fs_notified(int fd, char *name, int nodeid);
+
+/* reads from fd: gets name, REGISTER/NOTIFIED, nodeid, result */
+int dlmc_fs_result(int fd, char *name, int *type, int *nodeid, int *result);
+
+int dlmc_deadlk_check(char *name);
 
 #endif
diff --git a/fence/libfenced/main.c b/dlm/libdlmcontrol/main.c
similarity index 55%
copy from fence/libfenced/main.c
copy to dlm/libdlmcontrol/main.c
index 4f2a310..f52bce2 100644
--- a/fence/libfenced/main.c
+++ b/dlm/libdlmcontrol/main.c
@@ -19,8 +19,9 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
-#include "fenced.h"
-#include "libfenced.h"
+#include <linux/dlmconstants.h>
+#include "dlm_controld.h"
+#include "libdlmcontrol.h"
 
 static int do_read(int fd, void *buf, size_t count)
 {
@@ -83,91 +84,29 @@ static int do_connect(char *sock_path)
 	return fd;
 }
 
-static void init_header(struct fenced_header *h, int cmd, int len)
+static void init_header(struct dlmc_header *h, char *name, int cmd, int len)
 {
-	memset(h, 0, sizeof(struct fenced_header));
+	memset(h, 0, sizeof(struct dlmc_header));
 
-	h->magic = FENCED_MAGIC;
-	h->version = FENCED_VERSION;
+	h->magic = DLMC_MAGIC;
+	h->version = DLMC_VERSION;
 	h->len = len;
 	h->command = cmd;
-}
-
-int fenced_join(void)
-{
-	struct fenced_header h;
-	int fd, rv;
-
-	init_header(&h, FENCED_CMD_JOIN, sizeof(h));
-
-	fd = do_connect(FENCED_SOCK_PATH);
-	if (fd < 0) {
-		rv = fd;
-		goto out;
-	}
-
-	rv = do_write(fd, &h, sizeof(h));
-	close(fd);
- out:
-	return rv;
-}
-
-int fenced_leave(void)
-{
-	struct fenced_header h;
-	int fd, rv;
-
-	init_header(&h, FENCED_CMD_LEAVE, sizeof(h));
-
-	fd = do_connect(FENCED_SOCK_PATH);
-	if (fd < 0) {
-		rv = fd;
-		goto out;
-	}
 
-	rv = do_write(fd, &h, sizeof(h));
-	close(fd);
- out:
-	return rv;
+	if (name)
+		strncpy(h->name, name, DLM_LOCKSPACE_LEN); /* no term null in header */
 }
 
-int fenced_external(char *name)
+int do_dump(int type, char *name, char *buf)
 {
-	char msg[sizeof(struct fenced_header) + MAX_NODENAME_LEN + 1];
-	struct fenced_header *hd = (struct fenced_header *)msg;
-	int fd, rv;
-	int namelen;
-
-	memset(&msg, 0, sizeof(msg));
-	init_header(hd, FENCED_CMD_EXTERNAL, sizeof(msg));
-
-	namelen = strlen(name);
-	if (namelen > MAX_NODENAME_LEN)
-		namelen = MAX_NODENAME_LEN;
-	memcpy(msg + sizeof(struct fenced_header), name, namelen);
-
-	fd = do_connect(FENCED_SOCK_PATH);
-	if (fd < 0) {
-		rv = fd;
-		goto out;
-	}
-
-	rv = do_write(fd, hd, sizeof(msg));
-	close(fd);
- out:
-	return rv;
-}
-
-int fenced_dump_debug(char *buf)
-{
-	struct fenced_header h, *rh;
+	struct dlmc_header h, *rh;
 	char *reply;
 	int reply_len;
 	int fd, rv;
 
-	init_header(&h, FENCED_CMD_DUMP_DEBUG, sizeof(h));
+	init_header(&h, name, type, sizeof(h));
 
-	reply_len = sizeof(struct fenced_header) + FENCED_DUMP_SIZE;
+	reply_len = sizeof(struct dlmc_header) + DLMC_DUMP_SIZE;
 	reply = malloc(reply_len);
 	if (!reply) {
 		rv = -1;
@@ -175,7 +114,7 @@ int fenced_dump_debug(char *buf)
 	}
 	memset(reply, 0, reply_len);
 
-	fd = do_connect(FENCED_QUERY_SOCK_PATH);
+	fd = do_connect(DLMC_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -188,31 +127,41 @@ int fenced_dump_debug(char *buf)
 	/* won't always get back the full reply_len */
 	do_read(fd, reply, reply_len);
 
-	rh = (struct fenced_header *)reply;
+	rh = (struct dlmc_header *)reply;
 	rv = rh->data;
 	if (rv < 0)
 		goto out_close;
 
-	memcpy(buf, (char *)reply + sizeof(struct fenced_header),
-	       FENCED_DUMP_SIZE);
+	memcpy(buf, (char *)reply + sizeof(struct dlmc_header),
+	       DLMC_DUMP_SIZE);
  out_close:
 	close(fd);
  out:
 	return rv;
 }
 
-int fenced_node_info(int nodeid, struct fenced_node *node)
+int dlmc_dump_debug(char *buf)
+{
+	return do_dump(DLMC_CMD_DUMP_DEBUG, NULL, buf);
+}
+
+int dlmc_dump_plocks(char *name, char *buf)
+{
+	return do_dump(DLMC_CMD_DUMP_PLOCKS, name, buf);
+}
+
+int dlmc_node_info(char *name, int nodeid, struct dlmc_node *node)
 {
-	struct fenced_header h, *rh;
-	char reply[sizeof(struct fenced_header) + sizeof(struct fenced_node)];
+	struct dlmc_header h, *rh;
+	char reply[sizeof(struct dlmc_header) + sizeof(struct dlmc_node)];
 	int fd, rv;
 
-	init_header(&h, FENCED_CMD_NODE_INFO, sizeof(h));
+	init_header(&h, name, DLMC_CMD_NODE_INFO, sizeof(h));
 	h.data = nodeid;
 
 	memset(reply, 0, sizeof(reply));
 
-	fd = do_connect(FENCED_QUERY_SOCK_PATH);
+	fd = do_connect(DLMC_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -226,30 +175,30 @@ int fenced_node_info(int nodeid, struct fenced_node *node)
 	if (rv < 0)
 		goto out_close;
 
-	rh = (struct fenced_header *)reply;
+	rh = (struct dlmc_header *)reply;
 	rv = rh->data;
 	if (rv < 0)
 		goto out_close;
 
-	memcpy(node, (char *)reply + sizeof(struct fenced_header),
-	       sizeof(struct fenced_node));
+	memcpy(node, (char *)reply + sizeof(struct dlmc_header),
+	       sizeof(struct dlmc_node));
  out_close:
 	close(fd);
  out:
 	return rv;
 }
 
-int fenced_domain_info(struct fenced_domain *domain)
+int dlmc_lockspace_info(char *name, struct dlmc_lockspace *lockspace)
 {
-	struct fenced_header h, *rh;
-	char reply[sizeof(struct fenced_header) + sizeof(struct fenced_domain)];
+	struct dlmc_header h, *rh;
+	char reply[sizeof(struct dlmc_header) + sizeof(struct dlmc_lockspace)];
 	int fd, rv;
 
-	init_header(&h, FENCED_CMD_DOMAIN_INFO, sizeof(h));
+	init_header(&h, name, DLMC_CMD_LOCKSPACE_INFO, sizeof(h));
 
 	memset(reply, 0, sizeof(reply));
 
-	fd = do_connect(FENCED_QUERY_SOCK_PATH);
+	fd = do_connect(DLMC_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -263,31 +212,31 @@ int fenced_domain_info(struct fenced_domain *domain)
 	if (rv < 0)
 		goto out_close;
 
-	rh = (struct fenced_header *)reply;
+	rh = (struct dlmc_header *)reply;
 	rv = rh->data;
 	if (rv < 0)
 		goto out_close;
 
-	memcpy(domain, (char *)reply + sizeof(struct fenced_header),
-	       sizeof(struct fenced_domain));
+	memcpy(lockspace, (char *)reply + sizeof(struct dlmc_header),
+	       sizeof(struct dlmc_lockspace));
  out_close:
 	close(fd);
  out:
 	return rv;
 }
 
-int fenced_domain_nodes(int type, int max, int *count, struct fenced_node *nodes)
+int dlmc_lockspace_nodes(char *name, int type, int max, int *count, struct dlmc_node *nodes)
 {
-	struct fenced_header h, *rh;
+	struct dlmc_header h, *rh;
 	char *reply;
 	int reply_len;
 	int fd, rv, result, node_count;
 
-	init_header(&h, FENCED_CMD_DOMAIN_NODES, sizeof(h));
+	init_header(&h, name, DLMC_CMD_LOCKSPACE_NODES, sizeof(h));
 	h.option = type;
 	h.data = max;
 
-	reply_len = sizeof(struct fenced_header) + (max * sizeof(struct fenced_node));
+	reply_len = sizeof(struct dlmc_header) + (max * sizeof(struct dlmc_node));
 	reply = malloc(reply_len);
 	if (!reply) {
 		rv = -1;
@@ -295,7 +244,7 @@ int fenced_domain_nodes(int type, int max, int *count, struct fenced_node *nodes
 	}
 	memset(reply, 0, reply_len);
 
-	fd = do_connect(FENCED_QUERY_SOCK_PATH);
+	fd = do_connect(DLMC_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -308,7 +257,7 @@ int fenced_domain_nodes(int type, int max, int *count, struct fenced_node *nodes
 	/* won't usually get back the full reply_len */
 	do_read(fd, reply, reply_len);
 
-	rh = (struct fenced_header *)reply;
+	rh = (struct dlmc_header *)reply;
 	result = rh->data;
 	if (result < 0 && result != -E2BIG) {
 		rv = result;
@@ -324,8 +273,8 @@ int fenced_domain_nodes(int type, int max, int *count, struct fenced_node *nodes
 	}
 	rv = 0;
 
-	memcpy(nodes, (char *)reply + sizeof(struct fenced_header),
-	       node_count * sizeof(struct fenced_node));
+	memcpy(nodes, (char *)reply + sizeof(struct dlmc_header),
+	       node_count * sizeof(struct dlmc_node));
  out_close:
 	close(fd);
  out:
diff --git a/dlm/tool/Makefile b/dlm/tool/Makefile
index 7a082dc..dea1730 100644
--- a/dlm/tool/Makefile
+++ b/dlm/tool/Makefile
@@ -26,9 +26,10 @@ OBJS=	main.o
 
 CFLAGS += -I${dlmincdir}
 CFLAGS += -I$(SRCDIR)/group/dlm_controld/
-CFLAGS += -I${incdir}
+CFLAGS += -I${incdir} -I../libdlmcontrol
+CFLAGS += -I${KERNEL_SRC}/include/
 
-LDFLAGS += -L${dlmlibdir} -ldlm
+LDFLAGS += -L${dlmlibdir} -L../libdlmcontrol -ldlm -ldlmcontrol
 
 
 ${TARGET}: ${OBJS}
diff --git a/dlm/tool/main.c b/dlm/tool/main.c
index 814a3bb..423863c 100644
--- a/dlm/tool/main.c
+++ b/dlm/tool/main.c
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2007 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2007-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -24,8 +24,9 @@
 #include <limits.h>
 #include <netinet/in.h>
 
+#include <linux/dlmconstants.h>
 #include "libdlm.h"
-#include "dlm_controld.h"
+#include "libdlmcontrol.h"
 
 #define LKM_IVMODE -1
 
@@ -392,51 +393,9 @@ void do_spaces(void)
 	/* TODO: get info from /sys/kernel/config/ */
 }
 
-static int connect_daemon(char *path)
-{
-	struct sockaddr_un sun;
-	socklen_t addrlen;
-	int rv, fd;
-
-	fd = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (fd < 0)
-		goto out;
-
-	memset(&sun, 0, sizeof(sun));
-	sun.sun_family = AF_UNIX;
-	strcpy(&sun.sun_path[1], path);
-	addrlen = sizeof(sa_family_t) + strlen(sun.sun_path+1) + 1;
-
-	rv = connect(fd, (struct sockaddr *) &sun, addrlen);
-	if (rv < 0) {
-		close(fd);
-		fd = rv;
-	}
- out:
-	return fd;
-}
-
 static void do_deadlock_check(char *name)
 {
-	char buf[DLM_CONTROLD_MSGLEN];
-	int fd;
-	int rv;
-
-	fd = connect_daemon(DLM_CONTROLD_SOCK_PATH);
-	if (fd < 0) {
-		fprintf(stderr, "can't connect to dlm_controld: %s\n",
-			strerror(errno));
-		return;
-	}
-
-	memset(buf, 0, sizeof(buf));
-	snprintf(buf, sizeof(buf), "deadlock_check %s", name);
-
-	rv = do_write(fd, buf, DLM_CONTROLD_MSGLEN);
-	if (rv < 0)
-		fprintf(stderr, "bad write to dlm_controld: %s\n",
-			strerror(errno));
-	close(fd);
+	dlmc_deadlk_check(name);
 }
 
 int main(int argc, char **argv)
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index 7b823d1..2f27302 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -65,10 +65,6 @@
 
 #define MAXLINE			256
 
-/* Size of the circular debug buffer. */
-
-#define DUMP_SIZE		(1024 * 1024)
-
 /* group_mode */
 
 #define GROUP_LIBGROUP          2
@@ -81,7 +77,7 @@ extern int cman_quorate;
 extern int our_nodeid;
 extern char our_name[MAX_NODENAME_LEN+1];
 extern char daemon_debug_buf[256];
-extern char dump_buf[DUMP_SIZE];
+extern char dump_buf[FENCED_DUMP_SIZE];
 extern int dump_point;
 extern int dump_wrap;
 extern int group_mode;
diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index 439b9d3..aec8f2c 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -306,7 +306,7 @@ static void query_dump_debug(int f)
 	do_reply(f, FENCED_CMD_DUMP_DEBUG, 0, NULL, 0);
 
 	if (dump_wrap) {
-		len = DUMP_SIZE - dump_point;
+		len = FENCED_DUMP_SIZE - dump_point;
 		do_write(f, dump_buf + dump_point, len);
 		len = dump_point;
 	} else
@@ -883,7 +883,7 @@ void daemon_dump_save(void)
 	for (i = 0; i < len; i++) {
 		dump_buf[dump_point++] = daemon_debug_buf[i];
 
-		if (dump_point == DUMP_SIZE) {
+		if (dump_point == FENCED_DUMP_SIZE) {
 			dump_point = 0;
 			dump_wrap = 1;
 		}
@@ -897,7 +897,7 @@ int cman_quorate;
 int our_nodeid;
 char our_name[MAX_NODENAME_LEN+1];
 char daemon_debug_buf[256];
-char dump_buf[DUMP_SIZE];
+char dump_buf[FENCED_DUMP_SIZE];
 int dump_point;
 int dump_wrap;
 int group_mode;
diff --git a/group/dlm_controld/Makefile b/group/dlm_controld/Makefile
index 4c6376c..7459f6b 100644
--- a/group/dlm_controld/Makefile
+++ b/group/dlm_controld/Makefile
@@ -36,7 +36,7 @@ OBJS=	action.o \
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${openaisincdir} -I${fencedincdir}
 CFLAGS += -I${KERNEL_SRC}/include/
 CFLAGS += -I$(S)/../lib/ -I$(S)/../include/
-CFLAGS += -I${incdir}
+CFLAGS += -I${incdir} -I../../dlm/libdlmcontrol/
 
 LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -L${dlmlibdir} -L${fencedlibdir} -lccs -lcman -ldlm -lfenced
 LDFLAGS += -L${openaislibdir} -lcpg -lSaCkpt
diff --git a/group/dlm_controld/action.c b/group/dlm_controld/action.c
index 6d2db05..490449a 100644
--- a/group/dlm_controld/action.c
+++ b/group/dlm_controld/action.c
@@ -17,7 +17,7 @@ static int dir_members[MAX_NODES];
 static int dir_members_count;
 static int comms_nodes[MAX_NODES];
 static int comms_nodes_count;
-static char mg_name[MAX_LS_NAME+1];
+static char mg_name[DLM_LOCKSPACE_LEN+1];
 
 #define DLM_SYSFS_DIR "/sys/kernel/dlm"
 #define CLUSTER_DIR   "/sys/kernel/config/dlm/cluster"
diff --git a/group/dlm_controld/dlm_controld.h b/group/dlm_controld/dlm_controld.h
index 2b47f4b..8b18983 100644
--- a/group/dlm_controld/dlm_controld.h
+++ b/group/dlm_controld/dlm_controld.h
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2007 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2007-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -13,8 +13,36 @@
 #ifndef __DLM_CONTROLD_DOT_H__
 #define __DLM_CONTROLD_DOT_H__
 
-#define DLM_CONTROLD_SOCK_PATH	"dlm_controld_socket"
-#define DLM_CONTROLD_MSGLEN	256
+/* This defines the interface between dlm_controld and libdlmcontrol, and
+   should only be used by libdlmcontrol. */
+
+#define DLMC_SOCK_PATH			"dlmc_sock"
+#define DLMC_QUERY_SOCK_PATH		"dlmc_query_sock"
+
+#define DLMC_MAGIC			0xD13CD13C
+#define DLMC_VERSION			0x00010001
+
+#define DLMC_CMD_DUMP_DEBUG		1
+#define DLMC_CMD_DUMP_PLOCKS		2
+#define DLMC_CMD_NODE_INFO		3
+#define DLMC_CMD_LOCKSPACE_INFO		4
+#define DLMC_CMD_LOCKSPACE_NODES	5
+#define DLMC_CMD_FS_REGISTER		6
+#define DLMC_CMD_FS_UNREGISTER		7
+#define DLMC_CMD_FS_NOTIFIED		8
+#define DLMC_CMD_DEADLK_CHECK		9
+
+struct dlmc_header {
+	unsigned int magic;
+	unsigned int version;
+	unsigned int command;
+	unsigned int option;
+	unsigned int len;
+	int data;	/* embedded command-specific data, for convenience */
+	int unused1;
+	int unsued2;
+	char name[DLM_LOCKSPACE_LEN]; /* no terminating null space */
+};
 
 #endif
 
diff --git a/group/dlm_controld/dlm_daemon.h b/group/dlm_controld/dlm_daemon.h
index e0bca8a..e1930b8 100644
--- a/group/dlm_controld/dlm_daemon.h
+++ b/group/dlm_controld/dlm_daemon.h
@@ -42,21 +42,20 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <dirent.h>
-
 #include <openais/saAis.h>
 #include <openais/saCkpt.h>
 #include <openais/cpg.h>
 
+#include <linux/dlmconstants.h>
+#include "libdlmcontrol.h"
 #include "dlm_controld.h"
 #include "list.h"
 #include "linux_endian.h"
 
-/* Maximum lockspace name length, should match MAX_LOCKSPACE_NAME in
-   linux/dlmconstants.h (copied in libdlm.h).  The libcpg limit is
-   larger at CPG_MAX_NAME_LENGTH 128.  Our cpg name includes a "dlm:"
-   prefix before the lockspace name. */
-
-#define MAX_LS_NAME	64
+/* DLM_LOCKSPACE_LEN: maximum lockspace name length, from linux/dlmconstants.h.
+   Copied in libdlm.h so apps don't need to include the kernel header.
+   The libcpg limit is larger at CPG_MAX_NAME_LENGTH 128.  Our cpg name includes
+   a "dlm:" prefix before the lockspace name. */
 
 /* Maximum members of a lockspace, should match CPG_MEMBERS_MAX in openais/cpg.h.
    There are no max defines in dlm-kernel for lockspace members. */
@@ -72,10 +71,6 @@
 
 #define MAXLINE		256
 
-/* Size of the circular debug buffer. */
-
-#define DUMP_SIZE	(1024 * 1024)
-
 extern int daemon_debug_opt;
 extern int daemon_quit;
 extern int poll_fencing;
@@ -88,7 +83,7 @@ extern struct list_head lockspaces;
 extern int cman_quorate;
 extern int our_nodeid;
 extern char daemon_debug_buf[256];
-extern char dump_buf[DUMP_SIZE];
+extern char dump_buf[DLMC_DUMP_SIZE];
 extern int dump_point;
 extern int dump_wrap;
 
@@ -156,7 +151,7 @@ struct dlm_header {
 
 struct lockspace {
 	struct list_head	list;
-	char			name[MAX_LS_NAME+1];
+	char			name[DLM_LOCKSPACE_LEN+1];
 	uint32_t		global_id;
 
 	/* lockspace membership stuff */
diff --git a/group/dlm_controld/group.c b/group/dlm_controld/group.c
index f9bfccb..8cfdd26 100644
--- a/group/dlm_controld/group.c
+++ b/group/dlm_controld/group.c
@@ -26,7 +26,7 @@
 
 group_handle_t gh;
 static int cb_action;
-static char cb_name[MAX_LS_NAME+1];
+static char cb_name[DLM_LOCKSPACE_LEN+1];
 static int cb_event_nr;
 static unsigned int cb_id;
 static int cb_type;
diff --git a/group/dlm_controld/main.c b/group/dlm_controld/main.c
index 7a5ce81..7417071 100644
--- a/group/dlm_controld/main.c
+++ b/group/dlm_controld/main.c
@@ -12,7 +12,7 @@
 
 #include "dlm_daemon.h"
 #include "config.h"
-#include <linux/dlm.h>
+#include <linux/dlmconstants.h>
 #include <linux/netlink.h>
 #include <linux/genetlink.h>
 #include <linux/dlm_netlink.h>
@@ -78,7 +78,7 @@ static void do_dump(int fd)
 	int len;
 
 	if (dump_wrap) {
-		len = DUMP_SIZE - dump_point;
+		len = DLMC_DUMP_SIZE - dump_point;
 		do_write(fd, dump_buf + dump_point, len);
 		len = dump_point;
 	} else
@@ -183,7 +183,7 @@ static struct lockspace *create_ls(char *name)
 	if (!ls)
 		goto out;
 	memset(ls, 0, sizeof(*ls));
-	strncpy(ls->name, name, MAX_LS_NAME);
+	strncpy(ls->name, name, DLM_LOCKSPACE_LEN);
 
 	INIT_LIST_HEAD(&ls->changes);
 	INIT_LIST_HEAD(&ls->node_history);
@@ -380,42 +380,77 @@ static int setup_uevent(void)
 	return s;
 }
 
-/* FIXME: use a library?  Add ability to list lockspaces and their state. */
-
 static void process_connection(int ci)
 {
-	char buf[DLM_CONTROLD_MSGLEN], *argv[MAXARGS];
-	int argc = 0, rv;
-	struct lockspace *ls;
-
-	memset(buf, 0, sizeof(buf));
-	memset(argv, 0, sizeof(char *) * MAXARGS);
+	struct dlmc_header h;
+	char *extra = NULL;
+	int rv, extra_len;
 
-	rv = do_read(client[ci].fd, buf, DLM_CONTROLD_MSGLEN);
+	rv = do_read(client[ci].fd, &h, sizeof(h));
 	if (rv < 0) {
-		log_error("client %d fd %d read error %d %d", ci,
-			  client[ci].fd, rv, errno);
-		client_dead(ci);
-		return;
+		log_debug("connection %d read error %d", ci, rv);
+		goto out;
+	}
+
+	if (h.magic != DLMC_MAGIC) {
+		log_debug("connection %d magic error %x", ci, h.magic);
+		goto out;
 	}
 
-	log_debug("ci %d read %s", ci, buf);
+	if ((h.version & 0xFFFF0000) != (DLMC_VERSION & 0xFFFF0000)) {
+		log_debug("connection %d version error %x", ci, h.version);
+		goto out;
+	}
+
+	if (h.len > sizeof(h)) {
+		extra_len = h.len - sizeof(h);
+		extra = malloc(extra_len);
+		if (!extra) {
+			log_error("process_connection no mem %d", extra_len);
+			goto out;
+		}
+		memset(extra, 0, extra_len);
+
+		rv = do_read(client[ci].fd, extra, extra_len);
+		if (rv < 0) {
+			log_debug("connection %d extra read error %d", ci, rv);
+			goto out;
+		}
+	}
 
-	get_args(buf, &argc, argv, ' ', 2);
+	switch (h.command) {
+	case DLMC_CMD_FS_REGISTER:
+		break;
 
-	if (!strncmp(argv[0], "deadlock_check", 14)) {
-		ls = find_ls(argv[1]);
+	case DLMC_CMD_FS_UNREGISTER:
+		break;
+
+	case DLMC_CMD_FS_NOTIFIED:
+		break;
+
+	case DLMC_CMD_DEADLK_CHECK:
+#if 0
+		ls = find_ls(hd.name);
 		if (ls)
 			send_cycle_start(ls);
-		else
-			log_debug("deadlock_check ls name not found");
-	} else if (!strncmp(argv[0], "dump", 4)) {
-		do_dump(client[ci].fd);
-		client_dead(ci);
-	} else if (!strncmp(argv[0], "plocks", 6)) {
-		dump_plocks(argv[1], client[ci].fd);
-		client_dead(ci);
+#endif
+		break;
+
+	case DLMC_CMD_DUMP_DEBUG:
+	case DLMC_CMD_DUMP_PLOCKS:
+	case DLMC_CMD_NODE_INFO:
+	case DLMC_CMD_LOCKSPACE_INFO:
+	case DLMC_CMD_LOCKSPACE_NODES:
+		log_error("process_connection query on wrong socket");
+		break;
+	default:
+		log_error("process_connection %d unknown command %d",
+			  ci, h.command);
 	}
+ out:
+	if (extra)
+		free(extra);
+	client_dead(ci);
 }
 
 static void process_listener(int ci)
@@ -433,7 +468,7 @@ static void process_listener(int ci)
 	log_debug("client connection %d fd %d", i, fd);
 }
 
-static int setup_listener(void)
+static int setup_listener(char *sock_path)
 {
 	struct sockaddr_un addr;
 	socklen_t addrlen;
@@ -449,7 +484,7 @@ static int setup_listener(void)
 
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	strcpy(&addr.sun_path[1], DLM_CONTROLD_SOCK_PATH);
+	strcpy(&addr.sun_path[1], sock_path);
 	addrlen = sizeof(sa_family_t) + strlen(addr.sun_path+1) + 1;
 
 	rv = bind(s, (struct sockaddr *) &addr, addrlen);
@@ -468,6 +503,91 @@ static int setup_listener(void)
 	return s;
 }
 
+void query_lock(void)
+{
+	pthread_mutex_lock(&query_mutex);
+}
+
+void query_unlock(void)
+{
+	pthread_mutex_unlock(&query_mutex);
+}
+
+/* This is a thread, so we have to be careful, don't call log_ functions.
+   We need a thread to process queries because the main thread may block
+   for long periods when writing to sysfs to stop dlm-kernel (any maybe
+   other places). */
+
+static void *process_queries(void *arg)
+{
+	struct dlmc_header h;
+	int s = *((int *)arg);
+	int f, rv;
+
+	for (;;) {
+		f = accept(s, NULL, NULL);
+
+		rv = do_read(f, &h, sizeof(h));
+		if (rv < 0) {
+			goto out;
+		}
+
+		if (h.magic != DLMC_MAGIC) {
+			goto out;
+		}
+
+		if ((h.version & 0xFFFF0000) != (DLMC_VERSION & 0xFFFF0000)) {
+			goto out;
+		}
+
+		pthread_mutex_lock(&query_mutex);
+
+		switch (h.command) {
+		case DLMC_CMD_DUMP_DEBUG:
+			query_dump_debug(f);
+			break;
+		case DLMC_CMD_DUMP_PLOCKS:
+			query_dump_plocks(f);
+			break;
+		case DLMC_CMD_NODE_INFO:
+			query_node_info(f, h.data);
+			break;
+		case DLMC_CMD_LOCKSPACE_INFO:
+			query_lockspace_info(f);
+			break;
+		case DLMC_CMD_LOCKSPACE_NODES:
+			query_lockspace_nodes(f, h.option, h.data);
+			break;
+		default:
+			break;
+		}
+		pthread_mutex_unlock(&query_mutex);
+
+ out:
+		close(f);
+	}
+}
+
+static int setup_queries(void)
+{
+	int rv, s;
+
+	rv = setup_listener(DLMC_QUERY_SOCK_PATH);
+	if (rv < 0)
+		return rv;
+	s = rv;
+
+	pthread_mutex_init(&query_mutex, NULL);
+
+	rv = pthread_create(&query_thread, NULL, process_queries, &s);
+	if (rv < 0) {
+		log_error("can't create query thread");
+		close(s);
+		return rv;
+	}
+	return 0;
+}
+
 static void cluster_dead(int ci)
 {
 	log_error("cluster is down, exiting");
@@ -482,7 +602,11 @@ static int loop(void)
 	void (*workfn) (int ci);
 	void (*deadfn) (int ci);
 
-	rv = setup_listener();
+	rv = setup_queries();
+	if (rv < 0)
+		goto out;
+
+	rv = setup_listener(DLMC_SOCK_PATH);
 	if (rv < 0)
 		goto out;
 	client_add(rv, process_listener, NULL);
@@ -570,6 +694,8 @@ static int loop(void)
 			goto out;
 		}
 
+		query_lock();
+
 		for (i = 0; i <= client_maxi; i++) {
 			if (client[i].fd < 0)
 				continue;
@@ -597,6 +723,8 @@ static int loop(void)
 			}
 			poll_timeout = 1000;
 		}
+
+		query_unlock();
 	}
 	rv = 0;
  out:
@@ -867,7 +995,7 @@ void daemon_dump_save(void)
 	for (i = 0; i < len; i++) {
 		dump_buf[dump_point++] = daemon_debug_buf[i];
 
-		if (dump_point == DUMP_SIZE) {
+		if (dump_point == DLMC_DUMP_SIZE) {
 			dump_point = 0;
 			dump_wrap = 1;
 		}
@@ -886,7 +1014,7 @@ struct list_head lockspaces;
 int cman_quorate;
 int our_nodeid;
 char daemon_debug_buf[256];
-char dump_buf[DUMP_SIZE];
+char dump_buf[DLMC_DUMP_SIZE];
 int dump_point;
 int dump_wrap;
 


hooks/post-receive
--
Cluster Project


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-29 21:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-29 21:39 Cluster Project branch, master, updated. cluster-2.99.00-5-g91a32ad teigland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).