cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: teigland@sourceware.org <teigland@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/fence/fence_tool fence_tool.c
Date: 29 Nov 2007 14:46:41 -0000	[thread overview]
Message-ID: <20071129144641.6784.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL5
Changes by:	teigland at sourceware.org	2007-11-29 14:46:41

Modified files:
	fence/fence_tool: fence_tool.c 

Log message:
	[sync from HEAD]
	
	clean out some options that were only relevant to rhel4
	remove the monitor option which didn't do anything
	add the dump option to dump the fenced debug buffer
	(group_tool can still do this, but fence_tool wasn't oddly enough
	
	bz 404451

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/fence_tool/fence_tool.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.23.2.1&r2=1.23.2.2

--- cluster/fence/fence_tool/fence_tool.c	2007/01/23 16:54:09	1.23.2.1
+++ cluster/fence/fence_tool/fence_tool.c	2007/11/29 14:46:41	1.23.2.2
@@ -37,14 +37,18 @@
 #define FALSE 0
 #endif
 
-#define OPTION_STRING			("Vhcj:f:t:wQ")
+#define OPTION_STRING			("Vht:wQ")
 #define FENCED_SOCK_PATH                "fenced_socket"
 #define MAXLINE				256
 
 #define OP_JOIN  			1
 #define OP_LEAVE 			2
-#define OP_MONITOR			3
-#define OP_WAIT				4
+#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 \
@@ -63,10 +67,47 @@
 int signalled = 0;
 cman_handle_t ch;
 
+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_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 get_int_arg(char argopt, char *arg)
 {
 	char *tmp;
-	int val;                                                                                 
+	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);
@@ -195,7 +236,7 @@
 	for (i=0; !fenced_start_timeout || i < fenced_start_timeout; i++) {
 		if (we_are_in_fence_domain() == joining)
 			return 0;
-		if (!(i % 5))
+		if (i && !(i % 5))
 			printf("Waiting for fenced to %s the fence group.\n",
 				   (joining?"join":"leave"));
 		sleep(1);
@@ -281,41 +322,43 @@
 	return EXIT_SUCCESS;
 }
 
-static int do_monitor(void)
+static int do_dump(void)
 {
+	char inbuf[DUMP_SIZE];
+	char outbuf[MAXLINE];
 	int fd, rv;
-	char *out, buf[256];
 
 	fd = fenced_connect();
-	if (!fd)
-		die("fenced not running");
 
-	out = "monitor";
+	memset(inbuf, 0, sizeof(inbuf));
+	memset(outbuf, 0, sizeof(outbuf));
+
+	sprintf(outbuf, "dump");
 
-	rv = write(fd, out, sizeof(out));
+	rv = do_write(fd, outbuf, sizeof(outbuf));
 	if (rv < 0)
 		die("can't communicate with fenced");
 
-	while (1) {
-		memset(buf, 0, sizeof(buf));
-		rv = read(fd, buf, sizeof(buf));
-		printf("%s", buf);
-	}
+	rv = do_read(fd, inbuf, sizeof(inbuf));
+	if (rv < 0)
+		printf("dump read: %s\n", strerror(errno));
+
+	do_write(STDOUT_FILENO, inbuf, sizeof(inbuf));
 
 	close(fd);
-	return EXIT_SUCCESS;
+	return 0;
 }
 
 static void print_usage(void)
 {
 	printf("Usage:\n");
 	printf("\n");
-	printf("%s <join|leave|wait> [options]\n", prog_name);
+	printf("%s <join|leave|dump> [options]\n", prog_name);
 	printf("\n");
 	printf("Actions:\n");
 	printf("  join             Join the default fence domain\n");
 	printf("  leave            Leave default fence domain\n");
-	printf("  wait             Wait for node to be member of default fence domain\n");
+	printf("  dump		   Dump debug buffer from fenced\n");
 	printf("\n");
 	printf("Options:\n");
 	printf("  -w               Wait for join to complete\n");
@@ -324,12 +367,6 @@
 	printf("  -t               Maximum time in seconds to wait\n");
 	printf("  -Q               Fail if cluster is not quorate, don't wait\n");
 	printf("\n");
-	printf("Fenced options:\n");
-	printf("  these are passed on to fenced when it's started\n");
-	printf("  -c               All nodes are in a clean state to start\n");
-	printf("  -j <secs>        Post-join fencing delay\n");
-	printf("  -f <secs>        Post-fail fencing delay\n");
-	printf("\n");
 }
 
 static void decode_arguments(int argc, char *argv[])
@@ -376,12 +413,6 @@
 			fenced_start_timeout = get_int_arg(optchar, optarg);
 			break;
 
-		case 'c':
-		case 'j':
-		case 'f':
-			/* Do nothing, just pass these options on to fenced */
-			break;
-
 		default:
 			die("unknown option: %c\n", optchar);
 			break;
@@ -393,8 +424,8 @@
 			operation = OP_JOIN;
 		} else if (strcmp(argv[optind], "leave") == 0) {
 			operation = OP_LEAVE;
-		} else if (strcmp(argv[optind], "monitor") == 0) {
-			operation = OP_MONITOR;
+		} else if (strcmp(argv[optind], "dump") == 0) {
+			operation = OP_DUMP;
 		} else
 			die("unknown option %s\n", argv[optind]);
 		optind++;
@@ -415,8 +446,8 @@
 		return do_join(argc, argv);
 	case OP_LEAVE:
 		return do_leave();
-	case OP_MONITOR:
-		return do_monitor();
+	case OP_DUMP:
+		return do_dump();
 	case OP_WAIT:
 		return -1;
 	}



             reply	other threads:[~2007-11-29 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 14:46 teigland [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-08-15 20:57 [Cluster-devel] cluster/fence/fence_tool fence_tool.c teigland
2007-01-23 17:21 rpeterso
2007-01-23 16:54 rpeterso
2007-01-23 16:53 rpeterso
2007-01-05 16:44 rohara
2007-01-05 16:40 rohara
2007-01-05 16:24 rohara
2006-10-23 16:23 jparsons
2006-07-10 17:04 rohara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071129144641.6784.qmail@sourceware.org \
    --to=teigland@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).