[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-216-gd4696e2



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=d4696e2a5c137c58a6c58a87747ce423b133d7b1

The branch, master has been updated
       via  d4696e2a5c137c58a6c58a87747ce423b133d7b1 (commit)
      from  1307d58730031a6d9f7401ba7182034e73280b49 (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 d4696e2a5c137c58a6c58a87747ce423b133d7b1
Author: David Teigland <teigland redhat com>
Date:   Fri Apr 25 15:35:16 2008 -0500

    fenced: process queries in a thread
    
    Add a thread for responding to the new libfenced queries, since fenced
    blocks for long periods when fencing nodes.
    
    Signed-off-by: David Teigland <teigland redhat com>

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

Summary of changes:
 fence/fenced/Makefile  |    2 +-
 fence/fenced/fenced.h  |    1 +
 fence/fenced/main.c    |  126 ++++++++++++++++++++++++++++++++++++++----------
 fence/libfenced/main.c |   18 ++++----
 4 files changed, 111 insertions(+), 36 deletions(-)

diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index 65d4262..4104842 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -37,7 +37,7 @@ CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
 CFLAGS += -I${incdir}
 
 LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -L${openaislibdir} -lccs -lcman -lcpg
-LDFLAGS += -L${fencelibdir} -L${openaislibdir} -lfence -lcpg
+LDFLAGS += -L${fencelibdir} -L${openaislibdir} -lfence -lcpg -lpthread
 LDFLAGS += -L../../group/lib -l group
 
 
diff --git a/fence/fenced/fenced.h b/fence/fenced/fenced.h
index 3b25814..140ecd2 100644
--- a/fence/fenced/fenced.h
+++ b/fence/fenced/fenced.h
@@ -20,6 +20,7 @@
 #define MAX_NODENAME_LEN		255
 
 #define FENCED_SOCK_PATH		"fenced_socket"
+#define FENCED_QUERY_SOCK_PATH		"fenced_query_socket"
 
 #define FENCED_MAGIC			0x0FE11CED
 #define FENCED_VERSION			0x00010001
diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index 2e08355..9d10716 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -12,6 +12,7 @@
 ******************************************************************************/
 
 #include "fd.h"
+#include "pthread.h"
 #include "copyright.cf"
 
 #define LOCKFILE_NAME		"/var/run/fenced.pid"
@@ -21,6 +22,8 @@ static int client_maxi;
 static int client_size = 0;
 static struct client *client = NULL;
 static struct pollfd *pollfd = NULL;
+static pthread_t query_thread;
+static pthread_mutex_t query_mutex;
 
 struct client {
 	int fd;
@@ -54,7 +57,6 @@ static int do_write(int fd, void *buf, size_t count)
 	if (rv == -1 && errno == EINTR)
 		goto retry;
 	if (rv < 0) {
-		log_error("write errno %d", errno);
 		return rv;
 	}
 
@@ -264,7 +266,7 @@ static int do_external(char *name, char *extra, int extra_len)
 /* combines a header and the data and sends it back to the client in
    a single do_write() call */
 
-static void do_reply(int ci, int cmd, int result, char *buf, int len)
+static void do_reply(int f, int cmd, int result, char *buf, int len)
 {
 	struct fenced_header *rh;
 	char *reply;
@@ -287,7 +289,9 @@ static void do_reply(int ci, int cmd, int result, char *buf, int len)
 	if (buf)
 		memcpy(reply + sizeof(struct fenced_header), buf, len);
 
-	do_write(client[ci].fd, reply, reply_len);
+	do_write(f, reply, reply_len);
+
+	free(reply);
 }
 
 /* dump can do 1, 2, or 3 separate writes:
@@ -295,15 +299,15 @@ static void do_reply(int ci, int cmd, int result, char *buf, int len)
    second write is the tail of log,
    third is the head of the log */
 
-static void do_dump(int ci)
+static void query_dump_debug(int f)
 {
 	int len;
 
-	do_reply(ci, FENCED_CMD_DUMP_DEBUG, 0, NULL, 0);
+	do_reply(f, 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);
+		do_write(f, dump_buf + dump_point, len);
 		len = dump_point;
 	} else
 		len = dump_point;
@@ -311,10 +315,10 @@ static void do_dump(int ci)
 	/* NUL terminate the debug string */
 	dump_buf[dump_point] = '\0';
 
-	do_write(client[ci].fd, dump_buf, len);
+	do_write(f, dump_buf, len);
 }
 
-static void do_node_info(int ci, int nodeid)
+static void query_node_info(int f, int nodeid)
 {
 	struct fd *fd;
 	struct fenced_node node;
@@ -331,11 +335,10 @@ static void do_node_info(int ci, int nodeid)
 	else
 		rv = set_node_info(fd, nodeid, &node);
  out:
-	do_reply(client[ci].fd, FENCED_CMD_NODE_INFO, rv,
-		 (char *)&node, sizeof(node));
+	do_reply(f, FENCED_CMD_NODE_INFO, rv, (char *)&node, sizeof(node));
 }
 
-static void do_domain_info(int ci)
+static void query_domain_info(int f)
 {
 	struct fd *fd;
 	struct fenced_domain domain;
@@ -352,11 +355,10 @@ static void do_domain_info(int ci)
 	else
 		rv = set_domain_info(fd, &domain);
  out:
-	do_reply(client[ci].fd, FENCED_CMD_DOMAIN_INFO, rv,
-		 (char *)&domain, sizeof(domain));
+	do_reply(f, FENCED_CMD_DOMAIN_INFO, rv, (char *)&domain, sizeof(domain));
 }
 
-static void do_domain_members(int ci, int max)
+static void query_domain_members(int f, int max)
 {
 	struct fd *fd;
 	int member_count = 0;
@@ -385,8 +387,8 @@ static void do_domain_members(int ci, int max)
 		rv = member_count;
 	}
  out:
-	do_reply(client[ci].fd, FENCED_CMD_DOMAIN_MEMBERS, rv,
-		 (char *)members, member_count * sizeof(struct fenced_node));
+	do_reply(f, FENCED_CMD_DOMAIN_MEMBERS, rv,
+	         (char *)members, member_count * sizeof(struct fenced_node));
 
 	if (members)
 		free(members);
@@ -441,16 +443,10 @@ static void process_connection(int ci)
 		do_external("default", extra, extra_len);
 		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);
+		log_error("process_connection query on wrong socket");
 		break;
 	default:
 		log_error("process_connection %d unknown command %d",
@@ -477,7 +473,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;
@@ -493,7 +489,7 @@ static int setup_listener(void)
 
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	strcpy(&addr.sun_path[1], FENCED_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);
@@ -512,6 +508,77 @@ static int setup_listener(void)
 	return s;
 }
 
+/* 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 will block
+   for long periods when running fence agents. */
+
+static void *process_queries(void *arg)
+{
+	struct fenced_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 != FENCED_MAGIC) {
+			goto out;
+		}
+
+		if ((h.version & 0xFFFF0000) != (FENCED_VERSION & 0xFFFF0000)) {
+			goto out;
+		}
+
+		pthread_mutex_lock(&query_mutex);
+
+		switch (h.command) {
+		case FENCED_CMD_DUMP_DEBUG:
+			query_dump_debug(f);
+			break;
+		case FENCED_CMD_NODE_INFO:
+			query_node_info(f, h.data);
+			break;
+		case FENCED_CMD_DOMAIN_INFO:
+			query_domain_info(f);
+			break;
+		case FENCED_CMD_DOMAIN_MEMBERS:
+			query_domain_members(f, h.data);
+			break;
+		default:
+			break;
+		}
+		pthread_mutex_unlock(&query_mutex);
+
+ out:
+		close(f);
+	}
+}
+
+static int setup_queries(void)
+{
+	int rv, s;
+
+	rv = setup_listener(FENCED_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");
@@ -524,7 +591,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(FENCED_SOCK_PATH);
 	if (rv < 0)
 		goto out;
 	client_add(rv, process_listener, NULL);
@@ -573,6 +644,8 @@ static int loop(void)
 			goto out;
 		}
 
+		pthread_mutex_lock(&query_mutex);
+
 		for (i = 0; i <= client_maxi; i++) {
 			if (client[i].fd < 0)
 				continue;
@@ -585,6 +658,7 @@ static int loop(void)
 				deadfn(i);
 			}
 		}
+		pthread_mutex_unlock(&query_mutex);
 	}
 	rv = 0;
  out:
diff --git a/fence/libfenced/main.c b/fence/libfenced/main.c
index 6929049..4bd928f 100644
--- a/fence/libfenced/main.c
+++ b/fence/libfenced/main.c
@@ -59,7 +59,7 @@ static int do_write(int fd, void *buf, size_t count)
 	return 0;
 }
 
-static int do_connect(void)
+static int do_connect(char *sock_path)
 {
 	struct sockaddr_un sun;
 	socklen_t addrlen;
@@ -71,7 +71,7 @@ static int do_connect(void)
 
 	memset(&sun, 0, sizeof(sun));
 	sun.sun_family = AF_UNIX;
-	strcpy(&sun.sun_path[1], FENCED_SOCK_PATH);
+	strcpy(&sun.sun_path[1], sock_path);
 	addrlen = sizeof(sa_family_t) + strlen(sun.sun_path+1) + 1;
 
 	rv = connect(fd, (struct sockaddr *) &sun, addrlen);
@@ -100,7 +100,7 @@ int fenced_join(void)
 
 	init_header(&h, FENCED_CMD_JOIN, sizeof(h));
 
-	fd = do_connect();
+	fd = do_connect(FENCED_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -119,7 +119,7 @@ int fenced_leave(void)
 
 	init_header(&h, FENCED_CMD_LEAVE, sizeof(h));
 
-	fd = do_connect();
+	fd = do_connect(FENCED_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -146,7 +146,7 @@ int fenced_external(char *name)
 		namelen = MAX_NODENAME_LEN;
 	memcpy(msg + sizeof(struct fenced_header), name, namelen);
 
-	fd = do_connect();
+	fd = do_connect(FENCED_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -175,7 +175,7 @@ int fenced_dump_debug(char *buf)
 	}
 	memset(reply, 0, reply_len);
 
-	fd = do_connect();
+	fd = do_connect(FENCED_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -212,7 +212,7 @@ int fenced_node_info(int nodeid, struct fenced_node *node)
 
 	memset(reply, 0, sizeof(reply));
 
-	fd = do_connect();
+	fd = do_connect(FENCED_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -249,7 +249,7 @@ int fenced_domain_info(struct fenced_domain *domain)
 
 	memset(reply, 0, sizeof(reply));
 
-	fd = do_connect();
+	fd = do_connect(FENCED_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;
@@ -294,7 +294,7 @@ int fenced_domain_members(int max, int *count, struct fenced_node *members)
 	}
 	memset(reply, 0, reply_len);
 
-	fd = do_connect();
+	fd = do_connect(FENCED_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
 		goto out;


hooks/post-receive
--
Cluster Project


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