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

[Cluster-devel] cluster/fence/fence_tool Makefile fence_tool.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rpeterso sourceware org	2006-10-04 19:16:52

Modified files:
	fence/fence_tool: Makefile fence_tool.c 

Log message:
	Add the "-w" (wait) and "-t" (timeout) parameters back in
	to fence_tool.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/fence_tool/Makefile.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/fence_tool/fence_tool.c.diff?cvsroot=cluster&r1=1.21&r2=1.22

--- cluster/fence/fence_tool/Makefile	2006/08/11 15:18:09	1.10
+++ cluster/fence/fence_tool/Makefile	2006/10/04 19:16:51	1.11
@@ -23,10 +23,10 @@
 CFLAGS+= -O2 -D_FILE_OFFSET_BITS=64 -DFENCE_RELEASE_NAME=\"${RELEASE}\"
 endif
 
-INCLUDE = -I${top_srcdir}/include -I${ccsincdir} -I${cmanincdir} -I${incdir} -I${top_srcdir}/config
+INCLUDE = -I${top_srcdir}/include -I${ccsincdir} -I${cmanincdir} -I${incdir} -I${top_srcdir}/config -I${top_srcdir}/../group/lib
 
-LDFLAGS+= -L${ccslibdir} -L${libdir} -L${top_srcdir}/../cman/lib -lcman
-LOADLIBES+= -lccs -lcman
+LDFLAGS+= -L${ccslibdir} -L${libdir} -L${top_srcdir}/../cman/lib -L${top_srcdir}/../group/lib
+LOADLIBES+= -lccs -lcman -lgroup
 
 FENCE_TOOL_SRC = \
 	agent.c \
--- cluster/fence/fence_tool/fence_tool.c	2006/07/10 17:04:08	1.21
+++ cluster/fence/fence_tool/fence_tool.c	2006/10/04 19:16:51	1.22
@@ -29,13 +29,14 @@
 
 #include "ccs.h"
 #include "copyright.cf"
+#include "libgroup.h"
 
 #ifndef TRUE
 #define TRUE 1
 #define FALSE 0
 #endif
 
-#define OPTION_STRING			("Vhcj:f:")
+#define OPTION_STRING			("Vhcj:f:t:w")
 #define FENCED_SOCK_PATH                "fenced_socket"
 #define MAXLINE				256
 
@@ -55,8 +56,22 @@
 
 char *prog_name;
 int operation;
+int child_wait = FALSE;
+int fenced_start_timeout = 30;
 
-int dispatch_fence_agent(int cd, char *victim, char *self);
+static int get_int_arg(char argopt, char *arg)
+{
+	char *tmp;
+	int val;                                                                                 
+	val = strtol(arg, &tmp, 10);
+	if (tmp == arg || tmp != arg + strlen(arg))
+		die("argument to %c (%s) is not an integer", argopt, arg);
+	
+	if (val < 0)
+		die("argument to %c cannot be negative", argopt);
+	
+	return val;
+}
 
 static int check_mounted(void)
 {
@@ -79,6 +94,7 @@
 	}
 
 	fclose(file);
+	return 0;
 }
 
 int fenced_connect(void)
@@ -105,6 +121,35 @@
 	return fd;
 }
 
+static int we_are_in_fence_domain(void)
+{
+	group_data_t gdata;
+	int rv;
+
+	memset(&gdata, 0, sizeof(gdata));
+	rv = group_get_group(0, "default", &gdata);
+
+	if (rv || strcmp(gdata.client_name, "fence"))
+		return 0;
+
+	return gdata.member;
+}
+
+static int do_wait(void)
+{
+	int i;
+
+	for (i=0; !fenced_start_timeout || i < fenced_start_timeout; i++) {
+		if (we_are_in_fence_domain())
+			return 0;
+		if (!(i % 5))
+			printf("Waiting for fenced to join the fence group.\n");
+		sleep(1);
+	}
+	printf("Error joining the fence group.\n");
+	return -1;
+}
+
 static int do_join(int argc, char *argv[])
 {
 	int i, fd, rv;
@@ -130,8 +175,11 @@
 
 	memset(buf, 0, sizeof(buf));
 	rv = read(fd, buf, sizeof(buf));
-
 	/* printf("join result %d %s\n", rv, buf); */
+
+	if (child_wait)
+		do_wait();
+	close(fd);
 	return EXIT_SUCCESS;
 }
 
@@ -146,7 +194,6 @@
 
 	check_mounted();
 
-
 	memset(buf, 0, sizeof(buf));
 	sprintf(buf, "leave default");
 
@@ -158,6 +205,7 @@
 	rv = read(fd, buf, sizeof(buf));
 
 	/* printf("leave result %d %s\n", rv, buf); */
+	close(fd);
 	return EXIT_SUCCESS;
 }
 
@@ -182,6 +230,7 @@
 		printf("%s", buf);
 	}
 
+	close(fd);
 	return EXIT_SUCCESS;
 }
 
@@ -197,8 +246,10 @@
 	printf("  wait             Wait for node to be member of default fence domain\n");
 	printf("\n");
 	printf("Options:\n");
+	printf("  -w               Wait for join to complete\n");
 	printf("  -V               Print program version information, then exit\n");
 	printf("  -h               Print this help, then exit\n");
+	printf("  -t               Maximum time in seconds to wait\n");
 	printf("\n");
 	printf("Fenced options:\n");
 	printf("  these are passed on to fenced when it's started\n");
@@ -230,6 +281,10 @@
 			exit(EXIT_SUCCESS);
 			break;
 
+		case 'w':
+			child_wait = TRUE;
+			break;
+
 		case ':':
 		case '?':
 			fprintf(stderr, "Please use '-h' for usage.\n");
@@ -240,6 +295,10 @@
 			cont = FALSE;
 			break;
 
+		case 't':
+			fenced_start_timeout = get_int_arg(optchar, optarg);
+			break;
+
 		case 'c':
 		case 'j':
 		case 'f':


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