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

[Cluster-devel] Cluster Project branch, master, updated. gfs-kernel_0_1_22-207-g8170e8d



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=8170e8d76373ffa1d7e2beaffd5b86a120a14de6

The branch, master has been updated
       via  8170e8d76373ffa1d7e2beaffd5b86a120a14de6 (commit)
      from  0083f20653ffa93bbbfc107d4a4f5d56bfae0252 (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 8170e8d76373ffa1d7e2beaffd5b86a120a14de6
Author: David Teigland <teigland redhat com>
Date:   Thu Apr 24 15:18:27 2008 -0500

    fenced: new libfenced interface
    
    A new library, libfenced, is used to communicate with fenced.  Previously,
    programs would each open fenced's local socket and write/read strings.
    
    Signed-off-by: David Teigland <teigland redhat com>

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

Summary of changes:
 fence/fence_node/Makefile                       |    4 +-
 fence/fence_node/fence_node.c                   |    5 +
 fence/fence_tool/Makefile                       |    4 +-
 fence/fence_tool/fence_tool.c                   |  122 ++-------
 fence/fenced/Makefile                           |    2 +-
 fence/fenced/cpg.c                              |   16 ++
 fence/fenced/fd.h                               |   10 +-
 fence/fenced/fenced.h                           |   29 ++-
 fence/fenced/group.c                            |   16 ++
 fence/fenced/main.c                             |  280 +++++++++++++-------
 fence/{lib => libfenced}/Makefile               |    9 +-
 fence/{lib/libfence.h => libfenced/libfenced.h} |   37 ++-
 fence/libfenced/main.c                          |  327 +++++++++++++++++++++++
 13 files changed, 639 insertions(+), 222 deletions(-)
 copy fence/{lib => libfenced}/Makefile (92%)
 copy fence/{lib/libfence.h => libfenced/libfenced.h} (62%)
 create mode 100644 fence/libfenced/main.c

diff --git a/fence/fence_node/Makefile b/fence/fence_node/Makefile
index b076479..c4dede7 100644
--- a/fence/fence_node/Makefile
+++ b/fence/fence_node/Makefile
@@ -29,9 +29,9 @@ CFLAGS += -D_FILE_OFFSET_BITS=64
 
 CFLAGS += -I${ccsincdir} -I${fenceincdir}
 CFLAGS += -I../include
-CFLAGS += -I${incdir}
+CFLAGS += -I${incdir} -I../libfenced
 
-LDFLAGS += -L${ccslibdir} -L${fencelibdir} -lccs -lfence
+LDFLAGS += -L${ccslibdir} -L${fencelibdir} -lccs -lfence -lfenced
 
 ${TARGET}: ${OBJS}
 	$(CC) -o $@ $^ $(LDFLAGS)
diff --git a/fence/fence_node/fence_node.c b/fence/fence_node/fence_node.c
index ad1234c..6662f52 100644
--- a/fence/fence_node/fence_node.c
+++ b/fence/fence_node/fence_node.c
@@ -14,10 +14,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <string.h>
 #include <syslog.h>
 
 #include "libfence.h"
+#include "libfenced.h"
 #include "copyright.cf"
 
 #define OPTION_STRING           ("huV")
@@ -105,6 +107,9 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	} else {
 		syslog(LOG_NOTICE, "Fence of \"%s\" was successful\n", victim);
+
+		fenced_external(victim);
+
 		exit(EXIT_SUCCESS);
 	}
 }
diff --git a/fence/fence_tool/Makefile b/fence/fence_tool/Makefile
index 868a439..cd64b96 100644
--- a/fence/fence_tool/Makefile
+++ b/fence/fence_tool/Makefile
@@ -28,10 +28,10 @@ OBJS=fence_tool.o
 CFLAGS += -D_FILE_OFFSET_BITS=64
 CFLAGS += -I${ccsincdir} -I${cmanincdir}
 CFLAGS += -I$(S)/../include -I$(SRCDIR)/group/lib
-CFLAGS += -I${incdir}
+CFLAGS += -I${incdir} -I../libfenced
 
 LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman
-LDFLAGS += -L../../group/lib -lgroup
+LDFLAGS += -L../../group/lib -lgroup -lfenced
 
 ${TARGET}: ${OBJS}
 	$(CC) -o $@ $^ $(LDFLAGS)
diff --git a/fence/fence_tool/fence_tool.c b/fence/fence_tool/fence_tool.c
index 2d193ea..72c262e 100644
--- a/fence/fence_tool/fence_tool.c
+++ b/fence/fence_tool/fence_tool.c
@@ -2,7 +2,7 @@
 *******************************************************************************
 **
 **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-**  Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2004-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
@@ -32,25 +32,15 @@
 #include "copyright.cf"
 #include "libcman.h"
 #include "libgroup.h"
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
+#include "libfenced.h"
 
 #define OPTION_STRING			("Vht:wQ")
-#define FENCED_SOCK_PATH                "fenced_socket"
-#define MAXLINE				256
 
 #define OP_JOIN  			1
 #define OP_LEAVE 			2
 #define OP_WAIT				3
 #define OP_DUMP				4
 
-/* needs to match the same in cluster/group/daemon/gd_internal.h and
-   cluster/group/gfs_controld/lock_dlm.h and cluster/fence/fenced/fd.h */
-#define DUMP_SIZE                       (1024 * 1024)
-
 #define die(fmt, args...) \
 do \
 { \
@@ -62,8 +52,8 @@ while (0)
 
 char *prog_name;
 int operation;
-int child_wait = FALSE;
-int quorum_wait = TRUE;
+int child_wait = 0;
+int quorum_wait = 1;
 int fenced_start_timeout = 300; /* five minutes */
 int signalled = 0;
 cman_handle_t ch;
@@ -87,6 +77,7 @@ static int do_write(int fd, void *buf, size_t count)
 	return 0;
 }
 
+#if 0
 static int do_read(int fd, void *buf, size_t count)
 {
 	int rv, off = 0;
@@ -103,6 +94,7 @@ static int do_read(int fd, void *buf, size_t count)
 	}
 	return 0;
 }
+#endif
 
 static int get_int_arg(char argopt, char *arg)
 {
@@ -148,30 +140,6 @@ static void sigalarm_handler(int sig)
 	signalled = 1;
 }
 
-int fenced_connect(void)
-{
-	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], FENCED_SOCK_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 int we_are_in_fence_domain(void)
 {
 	group_data_t gdata;
@@ -216,9 +184,9 @@ static int check_quorum(void)
 	while (!signalled) {
 		rv = cman_is_quorate(ch);
 		if (rv)
-			return TRUE;
+			return 1;
 		else if (!quorum_wait)
-			return FALSE;
+			return 0;
 
 		sleep(1);
 
@@ -227,7 +195,7 @@ static int check_quorum(void)
 	}
 
 	errno = ETIMEDOUT;
-	return FALSE;
+	return 0;
 }
 
 static int do_wait(int joining)
@@ -248,8 +216,7 @@ static int do_wait(int joining)
 
 static int do_join(int argc, char *argv[])
 {
-	int i, fd, rv;
-	char buf[MAXLINE];
+	int rv;
 
 	ch = cman_init(NULL);
 
@@ -267,86 +234,41 @@ static int do_join(int argc, char *argv[])
 	}
 	cman_finish(ch);
 
-	i = 0;
-	do {
-		sleep(1);
-		fd = fenced_connect();
-		if (!fd)
-			fprintf(stderr, "waiting for fenced to start\n");
-	} while (!fd && ++i < 10);
-
-	if (!fd)
-		die("fenced not running");
-
-	memset(buf, 0, sizeof(buf));
-	sprintf(buf, "join default");
-
-	rv = write(fd, buf, sizeof(buf));
+	rv = fenced_join();
 	if (rv < 0)
-		die("can't communicate with fenced %d", rv);
-
-	memset(buf, 0, sizeof(buf));
-	rv = read(fd, buf, sizeof(buf));
-	/* printf("join result %d %s\n", rv, buf); */
+		die("can't communicate with fenced");
 
 	if (child_wait)
 		do_wait(1);
-	close(fd);
 	return EXIT_SUCCESS;
 }
 
 static int do_leave(void)
 {
-	int fd, rv;
-	char buf[MAXLINE];
-
-	fd = fenced_connect();
-	if (!fd)
-		die("fenced not running");
+	int rv;
 
 	check_mounted();
 
-	memset(buf, 0, sizeof(buf));
-	sprintf(buf, "leave default");
-
-	rv = write(fd, buf, sizeof(buf));
+	rv = fenced_leave();
 	if (rv < 0)
 		die("can't communicate with fenced");
 
-	memset(buf, 0, sizeof(buf));
-	rv = read(fd, buf, sizeof(buf));
-
-	/* printf("leave result %d %s\n", rv, buf); */
 	if (child_wait)
 		do_wait(0);
-	close(fd);
 	return EXIT_SUCCESS;
 }
 
 static int do_dump(void)
 {
-	char inbuf[DUMP_SIZE];
-	char outbuf[MAXLINE];
-	int fd, rv;
-
-	fd = fenced_connect();
-
-	memset(inbuf, 0, sizeof(inbuf));
-	memset(outbuf, 0, sizeof(outbuf));
-
-	sprintf(outbuf, "dump");
+	char buf[FENCED_DUMP_SIZE];
+	int rv;
 
-	rv = do_write(fd, outbuf, sizeof(outbuf));
+	rv = fenced_dump_debug(buf);
 	if (rv < 0)
 		die("can't communicate with fenced");
 
-	rv = do_read(fd, inbuf, sizeof(inbuf));
-	if (rv < 0)
-		printf("dump read: %s\n", strerror(errno));
-
-	do_write(STDOUT_FILENO, inbuf, sizeof(inbuf));
+	do_write(STDOUT_FILENO, buf, sizeof(buf));
 
-	close(fd);
 	return 0;
 }
 
@@ -372,7 +294,7 @@ static void print_usage(void)
 
 static void decode_arguments(int argc, char *argv[])
 {
-	int cont = TRUE;
+	int cont = 1;
 	int optchar;
 
 	while (cont) {
@@ -393,11 +315,11 @@ static void decode_arguments(int argc, char *argv[])
 			break;
 
 		case 'Q':
-			quorum_wait = FALSE;
+			quorum_wait = 0;
 			break;
 
 		case 'w':
-			child_wait = TRUE;
+			child_wait = 1;
 			break;
 
 		case ':':
@@ -407,7 +329,7 @@ static void decode_arguments(int argc, char *argv[])
 			break;
 
 		case EOF:
-			cont = FALSE;
+			cont = 0;
 			break;
 
 		case 't':
diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index bc94f39..5a39356 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -33,7 +33,7 @@ OBJS=	config.o \
 CFLAGS += -D_FILE_OFFSET_BITS=64
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${fenceincdir} -I${openaisincdir}
 CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
-CFLAGS += -I${incdir}
+CFLAGS += -I${incdir} -I../libfenced
 
 LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -L${openaislibdir} -lccs -lcman -lcpg
 LDFLAGS += -L${fencelibdir} -L${openaislibdir} -lfence -lcpg
diff --git a/fence/fenced/cpg.c b/fence/fenced/cpg.c
index e0b9685..0ab6a60 100644
--- a/fence/fenced/cpg.c
+++ b/fence/fenced/cpg.c
@@ -1247,3 +1247,19 @@ int fd_leave(struct fd *fd)
 	return 0;
 }
 
+int set_node_info(struct fd *fd, int nodeid, struct fenced_node *node)
+{
+	return 0;
+}
+
+int set_domain_info(struct fd *fd, struct fenced_domain *domain)
+{
+	return 0;
+}
+
+int set_domain_members(struct fd *fd, int *member_count,
+		       struct fenced_node **members)
+{
+	return 0;
+}
+
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index 3765db1..605cb1b 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -30,7 +30,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
-#include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/poll.h>
 #include <sys/select.h>
@@ -42,6 +41,7 @@
 #include "list.h"
 #include "linux_endian.h"
 #include "libfence.h"
+#include "libfenced.h"
 #include "fenced.h"
 
 /* Max name length for a group, pointless since we only ever create the
@@ -239,6 +239,10 @@ void send_victim_done(struct fd *fd, int victim, int how);
 void process_fd_changes(void);
 int fd_join(struct fd *fd);
 int fd_leave(struct fd *fd);
+int set_node_info(struct fd *fd, int nodeid, struct fenced_node *node);
+int set_domain_info(struct fd *fd, struct fenced_domain *domain);
+int set_domain_members(struct fd *fd, int *member_count,
+	struct fenced_node **members);
 
 /* group.c */
 
@@ -246,6 +250,10 @@ void process_groupd(int ci);
 int setup_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);
+int set_domain_info_group(struct fd *fd, struct fenced_domain *domain);
+int set_domain_members_group(struct fd *fd, int *member_count,
+	struct fenced_node **members);
 
 /* main.c */
 
diff --git a/fence/fenced/fenced.h b/fence/fenced/fenced.h
index 737c3cd..3b25814 100644
--- a/fence/fenced/fenced.h
+++ b/fence/fenced/fenced.h
@@ -13,8 +13,33 @@
 #ifndef __FENCED_DOT_H__
 #define __FENCED_DOT_H__
 
-#define FENCED_SOCK_PATH	"fenced_socket"
-#define FENCED_MSGLEN		256
+/* This defines the interface between fenced and libfenced, and should
+   only be used by libfenced. */
+
+/* should match the same in fd.h */
+#define MAX_NODENAME_LEN		255
+
+#define FENCED_SOCK_PATH		"fenced_socket"
+
+#define FENCED_MAGIC			0x0FE11CED
+#define FENCED_VERSION			0x00010001
+
+#define FENCED_CMD_JOIN			1
+#define FENCED_CMD_LEAVE		2
+#define FENCED_CMD_DUMP_DEBUG		3
+#define FENCED_CMD_EXTERNAL		4
+#define FENCED_CMD_NODE_INFO		5
+#define FENCED_CMD_DOMAIN_INFO		6
+#define FENCED_CMD_DOMAIN_MEMBERS	7
+
+struct fenced_header {
+	unsigned int magic;
+	unsigned int version;
+	unsigned int command;
+	unsigned int pad;
+	unsigned int len;
+	int data;	/* embedded command-specific data, for convenience */
+};
 
 #endif
 
diff --git a/fence/fenced/group.c b/fence/fenced/group.c
index 92386fe..01db901 100644
--- a/fence/fenced/group.c
+++ b/fence/fenced/group.c
@@ -411,3 +411,19 @@ int fd_leave_group(struct fd *fd)
 	return rv;
 }
 
+int set_node_info_group(struct fd *fd, int nodeid, struct fenced_node *node)
+{
+	return 0;
+}
+
+int set_domain_info_group(struct fd *fd, struct fenced_domain *domain)
+{
+	return 0;
+}
+
+int set_domain_members_group(struct fd *fd, int *member_count,
+			     struct fenced_node **members)
+{
+	return 0;
+}
+
diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index 811ad7c..f208378 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -66,23 +66,6 @@ static int do_write(int fd, void *buf, size_t count)
 	return 0;
 }
 
-static void do_dump(int fd)
-{
-	int len;
-
-	if (dump_wrap) {
-		len = DUMP_SIZE - dump_point;
-		do_write(fd, dump_buf + dump_point, len);
-		len = dump_point;
-	} else
-		len = dump_point;
-
-	/* NUL terminate the debug string */
-	dump_buf[dump_point] = '\0';
-
-	do_write(fd, dump_buf, len);
-}
-
 static void client_alloc(void)
 {
 	int i;
@@ -261,65 +244,205 @@ static int do_leave(char *name)
 	return rv;
 }
 
-#define MAXARGS 8
+static int do_external(char *name, int ci)
+{
+	struct fd *fd;
+	int nodeid = 0;
+
+	fd = find_fd(name);
+	if (!fd)
+		return -EINVAL;
+
+	if (group_mode == GROUP_LIBGROUP)
+		return -EINVAL;
+
+	/* FIXME: do_read(client[ci].fd, buf, MAX_NODENAME_LEN);
+	   which gets the nodename, then translate the nodename to nodeid */
+
+	send_external(fd, nodeid);
+	return 0;
+}
+
+/* combines a header and the data and sends it back to the client in
+   a single do_write() call */
 
-static void make_args(char *buf, int *argc, char **argv, char sep)
+static void do_reply(int ci, int cmd, int result, char *buf, int len)
 {
-	char *p = buf;
-	int i;
+	struct fenced_header *rh;
+	char *reply;
+	int reply_len;
+
+	reply_len = sizeof(struct fenced_header) + len;
+	reply = malloc(reply_len);
+	if (!reply)
+		return;
+	memset(reply, 0, reply_len);
 
-	argv[0] = p;
+	rh = (struct fenced_header *)reply;
 
-	for (i = 1; i < MAXARGS; i++) {
-		p = strchr(buf, sep);
-		if (!p)
-			break;
-		*p = '\0';
-		argv[i] = p + 1;
-		buf = p + 1;
+	rh->magic = FENCED_MAGIC;
+	rh->version = FENCED_VERSION;
+	rh->len = reply_len;
+	rh->command = cmd;
+	rh->data = result;
+
+	if (buf)
+		memcpy(reply + sizeof(struct fenced_header), buf, len);
+
+	do_write(client[ci].fd, reply, reply_len);
+}
+
+/* dump can do 1, 2, or 3 separate writes:
+   first write is the header,
+   second write is the tail of log,
+   third is the head of the log */
+
+static void do_dump(int ci)
+{
+	int len;
+
+	do_reply(ci, FENCED_CMD_DUMP_DEBUG, 0, NULL, 0);
+
+	if (dump_wrap) {
+		len = DUMP_SIZE - dump_point;
+		do_write(client[ci].fd, dump_buf + dump_point, len);
+		len = dump_point;
+	} else
+		len = dump_point;
+
+	/* NUL terminate the debug string */
+	dump_buf[dump_point] = '\0';
+
+	do_write(client[ci].fd, dump_buf, len);
+}
+
+static void do_node_info(int ci, int nodeid)
+{
+	struct fd *fd;
+	struct fenced_node node;
+	int rv;
+
+	fd = find_fd("default");
+	if (!fd) {
+		rv = -ENOENT;
+		goto out;
 	}
-	*argc = i;
+
+	if (group_mode == GROUP_LIBGROUP)
+		rv = set_node_info_group(fd, nodeid, &node);
+	else
+		rv = set_node_info(fd, nodeid, &node);
+ out:
+	do_reply(client[ci].fd, FENCED_CMD_NODE_INFO, rv,
+		 (char *)&node, sizeof(node));
 }
 
-static void process_connection(int ci)
+static void do_domain_info(int ci)
+{
+	struct fd *fd;
+	struct fenced_domain domain;
+	int rv;
+
+	fd = find_fd("default");
+	if (!fd) {
+		rv = -ENOENT;
+		goto out;
+	}
+
+	if (group_mode == GROUP_LIBGROUP)
+		rv = set_domain_info_group(fd, &domain);
+	else
+		rv = set_domain_info(fd, &domain);
+ out:
+	do_reply(client[ci].fd, FENCED_CMD_DOMAIN_INFO, rv,
+		 (char *)&domain, sizeof(domain));
+}
+
+static void do_domain_members(int ci, int max)
 {
-	char buf[FENCED_MSGLEN];
-	char out[FENCED_MSGLEN];
-	char *argv[MAXARGS];
-	char *cmd, *name;
-	int argc = 0, rv;
+	struct fd *fd;
+	int member_count = 0;
+	struct fenced_node *members = NULL;
+	int rv;
 
-	memset(buf, 0, sizeof(buf));
-	memset(out, 0, sizeof(out));
-	memset(argv, 0, sizeof(char *) * MAXARGS);
+	fd = find_fd("default");
+	if (!fd) {
+		rv = -ENOENT;
+		goto out;
+	}
+
+	if (group_mode == GROUP_LIBGROUP)
+		rv = set_domain_members(fd, &member_count, &members);
+	else
+		rv = set_domain_members(fd, &member_count, &members);
 
-	rv = do_read(client[ci].fd, buf, FENCED_MSGLEN);
 	if (rv < 0) {
-		log_error("client %d fd %d read error %d %d", ci,
-			   client[ci].fd, rv, errno);
-		client_dead(ci);
-		return;
+		member_count = 0;
+		goto out;
+	}
+	if (member_count > max) {
+		rv = -E2BIG;
+		member_count = max;
+	} else {
+		rv = member_count;
 	}
+ out:
+	do_reply(client[ci].fd, FENCED_CMD_DOMAIN_MEMBERS, rv,
+		 (char *)members, member_count * sizeof(struct fenced_node));
+
+	if (members)
+		free(members);
+}
 
-	log_debug("ci %d read %s", ci, buf);
+static void process_connection(int ci)
+{
+	struct fenced_header h;
+	int rv;
 
-	make_args(buf, &argc, argv, ' ');
-	cmd = argv[0];
-	name = argv[1];
+	rv = do_read(client[ci].fd, &h, sizeof(h));
+	if (rv < 0) {
+		log_debug("connection %d read error %d", ci, rv);
+		goto out;
+	}
 
-	if (!strcmp(cmd, "join"))
-		rv = do_join(name);
-	else if (!strcmp(cmd, "leave"))
-		rv = do_leave(name);
-	else if (!strcmp(cmd, "dump")) {
-		do_dump(client[ci].fd);
-		close(client[ci].fd);
+	if (h.magic != FENCED_MAGIC) {
+		log_debug("connection %d magic error %x", ci, h.magic);
+		goto out;
 	}
 
-	sprintf(out, "%d", rv);
-	write(client[ci].fd, out, FENCED_MSGLEN);
+	if ((h.version & 0xFFFF0000) != (FENCED_VERSION & 0xFFFF0000)) {
+		log_debug("connection %d version error %x", ci, h.version);
+		goto out;
+	}
 
-	/* exit: cause fenced loop to exit */
+	switch (h.command) {
+	case FENCED_CMD_JOIN:
+		do_join("default");
+		break;
+	case FENCED_CMD_LEAVE:
+		do_leave("default");
+		break;
+	case FENCED_CMD_EXTERNAL:
+		do_external("default", ci);
+		break;
+	case FENCED_CMD_DUMP_DEBUG:
+		do_dump(ci);
+		break;
+	case FENCED_CMD_NODE_INFO:
+		do_node_info(ci, h.data);
+		break;
+	case FENCED_CMD_DOMAIN_INFO:
+		do_domain_info(ci);
+		break;
+	case FENCED_CMD_DOMAIN_MEMBERS:
+		do_domain_members(ci, h.data);
+		break;
+	default:
+		log_error("process_connection %d unknown command %d",
+			  ci, h.command);
+	}
+ out:
+	client_dead(ci);
 }
 
 static void process_listener(int ci)
@@ -672,44 +795,3 @@ int dump_wrap;
 int group_mode;
 struct commandline comline;
 
-#if 0
-   libfenced
-
-   struct fenced_node:
-   nodeid, name,
-   given node is pending victim?,
-   last time given node was successfully fenced, how, and by whom,
-   last failed fence time (only master will know),
-   last domain join time, last domain leave time
-
-   struct fenced_domain
-   name,
-   current number of members,
-   master nodeid
-   current number of victims,
-   current pending victim,
-   state
-
-   /* tell fenced that an external program has fenced a node, e.g. fence_node;
-      fenced will try to suppress its own fencing of this node a second time */
-   fenced_external(int nodeid);
-
-   /* fenced gives info about a single node */
-   fenced_node_info(int nodeid, char *name, struct fenced_node *info);
-
-   /* fenced gives info about the domain */
-   fenced_domain_info(struct fenced_domain *info);
-
-   /* fenced copies a node struct for each member */
-   fenced_domain_members(int num, struct fenced_node **info);
-
-   fenced_debug_dump(char **buf, int len);
-   fenced_join(void);
-   fenced_leave(void);
-
-   for all of these, libfenced connects to fenced, writes a structure that
-   defines the type, then for some, reads back data, copies data into
-   buffers provided by caller, disconnects from fenced
-
-#endif
-
diff --git a/fence/lib/Makefile b/fence/libfenced/Makefile
similarity index 92%
copy from fence/lib/Makefile
copy to fence/libfenced/Makefile
index 94a5064..0d500f5 100644
--- a/fence/lib/Makefile
+++ b/fence/libfenced/Makefile
@@ -10,7 +10,7 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= libfence
+TARGET= libfenced
 
 LIBDIRT=$(TARGET).a \
 	$(TARGET).so.$(SOMAJOR).$(SOMINOR)
@@ -32,13 +32,10 @@ include $(OBJDIR)/make/clean.mk
 include $(OBJDIR)/make/install.mk
 include $(OBJDIR)/make/uninstall.mk
 
-OBJS=	agent.o
+OBJS=	main.o
 
 CFLAGS += -fPIC
-CFLAGS += -I${ccsincdir}
-CFLAGS += -I${incdir}
-
-LDFLAGS += -L${ccslibdir} -lccs
+CFLAGS += -I${incdir} -I../fenced
 
 $(TARGET).a: $(OBJS)
 	${AR} r $@ $^
diff --git a/fence/lib/libfence.h b/fence/libfenced/libfenced.h
similarity index 62%
copy from fence/lib/libfence.h
copy to fence/libfenced/libfenced.h
index 6cdbd85..b10055b 100644
--- a/fence/lib/libfence.h
+++ b/fence/libfenced/libfenced.h
@@ -20,17 +20,36 @@
 *******************************************************************************
 ******************************************************************************/
 
-#ifndef _LIBFENCE_H_
-#define _LIBFENCE_H_
+#ifndef _LIBFENCED_H_
+#define _LIBFENCED_H_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#define FENCED_DUMP_SIZE (1024 * 1024)
 
-int fence_node(char *name);
+struct fenced_node {
+	int nodeid;
+	int member;
+	int victim;
+	int last_fenced_master;
+	int last_fenced_how;
+	uint64_t last_fenced_time;
+	uint64_t last_joined_time;
+	uint64_t last_remove_time;
+};
 
-#ifdef __cplusplus
-}
-#endif
+struct fenced_domain {
+	int member_count;
+	int victim_count;
+	int master_nodeid;
+	int current_victim;
+	int state;
+};
+
+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_members(int max, int *count, struct fenced_node *members);
 
 #endif
diff --git a/fence/libfenced/main.c b/fence/libfenced/main.c
new file mode 100644
index 0000000..6929049
--- /dev/null
+++ b/fence/libfenced/main.c
@@ -0,0 +1,327 @@
+/******************************************************************************
+*******************************************************************************
+**
+**  Copyright (C) 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
+**  of the GNU General Public License v.2.
+**
+*******************************************************************************
+******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "fenced.h"
+#include "libfenced.h"
+
+static int do_read(int fd, void *buf, size_t count)
+{
+	int rv, off = 0;
+
+	while (off < count) {
+		rv = read(fd, buf + off, count - off);
+		if (rv == 0)
+			return -1;
+		if (rv == -1 && errno == EINTR)
+			continue;
+		if (rv == -1)
+			return -1;
+		off += rv;
+	}
+	return 0;
+}
+
+static int do_write(int fd, void *buf, size_t count)
+{
+	int rv, off = 0;
+
+ retry:
+	rv = write(fd, buf + off, count);
+	if (rv == -1 && errno == EINTR)
+		goto retry;
+	if (rv < 0) {
+		return rv;
+	}
+
+	if (rv != count) {
+		count -= rv;
+		off += rv;
+		goto retry;
+	}
+	return 0;
+}
+
+static int do_connect(void)
+{
+	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], FENCED_SOCK_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 init_header(struct fenced_header *h, int cmd, int len)
+{
+	memset(h, 0, sizeof(struct fenced_header));
+
+	h->magic = FENCED_MAGIC;
+	h->version = FENCED_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();
+	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();
+	if (fd < 0) {
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	close(fd);
+ out:
+	return rv;
+}
+
+int fenced_external(char *name)
+{
+	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();
+	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;
+	char *reply;
+	int reply_len;
+	int fd, rv;
+
+	init_header(&h, FENCED_CMD_DUMP_DEBUG, sizeof(h));
+
+	reply_len = sizeof(struct fenced_header) + FENCED_DUMP_SIZE;
+	reply = malloc(reply_len);
+	if (!reply) {
+		rv = -1;
+		goto out;
+	}
+	memset(reply, 0, reply_len);
+
+	fd = do_connect();
+	if (fd < 0) {
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	if (rv < 0)
+		goto out_close;
+
+	/* won't always get back the full reply_len */
+	do_read(fd, reply, reply_len);
+
+	rh = (struct fenced_header *)reply;
+	rv = rh->data;
+	if (rv < 0)
+		goto out_close;
+
+	memcpy(buf, (char *)reply + sizeof(struct fenced_header),
+	       FENCED_DUMP_SIZE);
+ out_close:
+	close(fd);
+ out:
+	return rv;
+}
+
+int fenced_node_info(int nodeid, struct fenced_node *node)
+{
+	struct fenced_header h, *rh;
+	char reply[sizeof(struct fenced_header) + sizeof(struct fenced_node)];
+	int fd, rv;
+
+	init_header(&h, FENCED_CMD_NODE_INFO, sizeof(h));
+	h.data = nodeid;
+
+	memset(reply, 0, sizeof(reply));
+
+	fd = do_connect();
+	if (fd < 0) {
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	if (rv < 0)
+		goto out_close;
+
+	rv = do_read(fd, reply, sizeof(reply));
+	if (rv < 0)
+		goto out_close;
+
+	rh = (struct fenced_header *)reply;
+	rv = rh->data;
+	if (rv < 0)
+		goto out_close;
+
+	memcpy(node, (char *)reply + sizeof(struct fenced_header),
+	       sizeof(struct fenced_node));
+ out_close:
+	close(fd);
+ out:
+	return rv;
+}
+
+int fenced_domain_info(struct fenced_domain *domain)
+{
+	struct fenced_header h, *rh;
+	char reply[sizeof(struct fenced_header) + sizeof(struct fenced_domain)];
+	int fd, rv;
+
+	init_header(&h, FENCED_CMD_DOMAIN_INFO, sizeof(h));
+
+	memset(reply, 0, sizeof(reply));
+
+	fd = do_connect();
+	if (fd < 0) {
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	if (rv < 0)
+		goto out_close;
+
+	rv = do_read(fd, reply, sizeof(reply));
+	if (rv < 0)
+		goto out_close;
+
+	rh = (struct fenced_header *)reply;
+	rv = rh->data;
+	if (rv < 0)
+		goto out_close;
+
+	memcpy(domain, (char *)reply + sizeof(struct fenced_header),
+	       sizeof(struct fenced_domain));
+ out_close:
+	close(fd);
+ out:
+	return rv;
+}
+
+int fenced_domain_members(int max, int *count, struct fenced_node *members)
+{
+	struct fenced_header h, *rh;
+	char *reply;
+	int reply_len;
+	int fd, rv;
+
+	init_header(&h, FENCED_CMD_DOMAIN_MEMBERS, sizeof(h));
+	h.data = max;
+
+	reply_len = sizeof(struct fenced_header) + (max * sizeof(struct fenced_node));
+	reply = malloc(reply_len);
+	if (!reply) {
+		rv = -1;
+		goto out;
+	}
+	memset(reply, 0, reply_len);
+
+	fd = do_connect();
+	if (fd < 0) {
+		rv = fd;
+		goto out;
+	}
+
+	rv = do_write(fd, &h, sizeof(h));
+	if (rv < 0)
+		goto out_close;
+
+	/* won't usually get back the full reply_len */
+	do_read(fd, reply, reply_len);
+
+	rh = (struct fenced_header *)reply;
+	rv = rh->data;
+	if (rv < 0 && rv != -E2BIG)
+		goto out_close;
+
+	if (rv == -E2BIG)
+		*count = max;
+	else
+		*count = rh->data;
+
+	memcpy(members, (char *)reply + sizeof(struct fenced_header),
+	       *count * sizeof(struct fenced_node));
+ out_close:
+	close(fd);
+ out:
+	return rv;
+}
+


hooks/post-receive
--
Cluster Project


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