[Linux-cluster] [PATCH 3/4] fence - Add option to fence_tool to not wait for quorum

Bastian Blank bastian at waldi.eu.org
Thu Feb 17 18:35:49 UTC 2005


The attached patch makes it possible to ask fence_tool to not wait for
quorum and just die in this case. This makes it easier to call
fence_tool join in init scripts without the problem of a blocked
startup.

Bastian

-- 
Bones: "The man's DEAD, Jim!"
-------------- next part --------------
diff -urN -x CVS -x debian cvs-patch02-gnuism/fenced/main.c cvs-patch03-quorum/fenced/main.c
--- cvs-patch02-gnuism/fenced/main.c	2005-02-17 18:13:07.000000000 +0100
+++ cvs-patch03-quorum/fenced/main.c	2005-02-17 18:34:17.000000000 +0100
@@ -23,7 +23,7 @@
 char our_name[MAX_CLUSTER_MEMBER_NAME_LEN+1];
 
 
-#define OPTION_STRING			("cj:f:Dn:hVSw")
+#define OPTION_STRING			("cj:f:Dn:hVSwQ")
 #define LOCKFILE_NAME			"/var/run/fenced.pid"
 
 
@@ -573,6 +573,7 @@
 
 		case 'S':
 		case 'w':
+		case 'Q':
 			/* do nothing, this is a fence_tool option that
 			   we ignore when fence_tool starts us */
 			break;
diff -urN -x CVS -x debian cvs-patch02-gnuism/fence_tool/fence_tool.c cvs-patch03-quorum/fence_tool/fence_tool.c
--- cvs-patch02-gnuism/fence_tool/fence_tool.c	2005-02-17 18:19:19.000000000 +0100
+++ cvs-patch03-quorum/fence_tool/fence_tool.c	2005-02-17 18:39:30.000000000 +0100
@@ -34,7 +34,7 @@
 #include "ccs.h"
 #include "copyright.cf"
 
-#define OPTION_STRING			("VhScj:f:Dw")
+#define OPTION_STRING			("VhScj:f:DwQ")
 #define LOCKFILE_NAME                   "/var/run/fenced.pid"
 #define FENCED_SOCK_PATH                "fenced_socket"
 
@@ -48,6 +48,7 @@
 int operation;
 bool skip_unfence = false;
 bool child_wait = false;
+bool wait_for_quorum = true;
 int cl_sock;
 char our_name[MAX_CLUSTER_MEMBER_NAME_LEN+1];
 
@@ -188,7 +189,7 @@
  * join/leave process.)
  */
 
-static int wait_quorum(void)
+static bool check_quorum(void)
 {
 	int rv, i = 0;
 
@@ -202,15 +203,15 @@
 
 		rv = ioctl(cl_sock, SIOCCLUSTER_ISQUORATE, NULL);
 		if (rv)
-			break;
+			return true;
+		else if (!wait_for_quorum)
+			return false;
 
 		sleep(1);
 
 		if (++i > 9 && !(i % 10))
 			printf("%s: waiting for cluster quorum\n", prog_name);
 	}
-
-	return 0;
 }
 
 /*
@@ -246,18 +247,22 @@
 		sleep(1);
 		rewind(file);
 	}
-                        
+
  out:
 	fclose(file);
-	return 0;
+
+	return EXIT_SUCCESS;
 }
 
-static void do_join(int argc, char *argv[])
+static int do_join(int argc, char *argv[])
 {
 	int cd;
 
 	setup_sock();
-	wait_quorum();
+
+	if (!check_quorum())
+		return EXIT_FAILURE;
+
 	get_our_name();
 	close(cl_sock);
 	cd = check_ccs();
@@ -293,9 +298,11 @@
 
 	execvp("fenced", argv);
 	die("starting fenced failed");
+
+	return EXIT_FAILURE;
 }
 
-static void do_leave(void)
+static int do_leave(void)
 {
 	FILE *f;
 	char buf[33] = "";
@@ -314,13 +321,18 @@
 
 	check_mounted();
 	setup_sock();
-	wait_quorum();
+
+	if (!check_quorum())
+		return EXIT_FAILURE;
+
 	close(cl_sock);
 
 	kill(pid, SIGTERM);
+
+	return EXIT_SUCCESS;
 }
 
-static void do_monitor(void)
+static int do_monitor(void)
 {
 	int sfd, error, rv;
 	struct sockaddr_un addr;
@@ -348,6 +360,8 @@
 
 		printf("%s", buf);
 	}
+
+	return EXIT_SUCCESS;
 }
 
 static void print_usage(void)
@@ -367,6 +381,7 @@
 	printf("  -h               Print this help, then exit\n");
 	printf("  -S               Skip self unfencing on join\n");
 	printf("  -D               Enable debugging, don't fork (also passed to fenced)\n");
+        printf("  -Q               Don't wait if cluster is not quorate\n");
 	printf("\n");
 	printf("Fenced options:\n");
 	printf("  these are passed on to fenced when it's started\n");
@@ -410,6 +425,10 @@
 			child_wait = true;
 			break;
 
+		case 'Q':
+			wait_for_quorum = false;
+			break;
+
 		case ':':
 		case '?':
 			fprintf(stderr, "Please use '-h' for usage.\n");
@@ -458,18 +477,14 @@
 
 	switch (operation) {
 	case OP_JOIN:
-		do_join(argc, argv);
-		break;
+		return do_join(argc, argv);
 	case OP_LEAVE:
-		do_leave();
-		break;
+		return do_leave();
 	case OP_MONITOR:
-		do_monitor();
-		break;
+		return do_monitor();
 	case OP_WAIT:
-		do_wait();
-		break;
+		return do_wait();
 	}
 
-	exit(EXIT_SUCCESS);
+	return EXIT_FAILURE;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/linux-cluster/attachments/20050217/6e5d9866/attachment.sig>


More information about the Linux-cluster mailing list