Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Cluster Development (http://www.linux-archive.org/cluster-development/)
-   -   cluster/fence/fence_tool fence_tool.c (http://www.linux-archive.org/cluster-development/8307-cluster-fence-fence_tool-fence_tool-c.html)

11-29-2007 01:46 PM

cluster/fence/fence_tool fence_tool.c
 
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL5
Changes by: teigland@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=RH EL5&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.
",
(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
", strerror(errno));
+
+ do_write(STDOUT_FILENO, inbuf, sizeof(inbuf));

close(fd);
- return EXIT_SUCCESS;
+ return 0;
}

static void print_usage(void)
{
printf("Usage:
");
printf("
");
- printf("%s <join|leave|wait> [options]
", prog_name);
+ printf("%s <join|leave|dump> [options]
", prog_name);
printf("
");
printf("Actions:
");
printf(" join Join the default fence domain
");
printf(" leave Leave default fence domain
");
- printf(" wait Wait for node to be member of default fence domain
");
+ printf(" dump Dump debug buffer from fenced
");
printf("
");
printf("Options:
");
printf(" -w Wait for join to complete
");
@@ -324,12 +367,6 @@
printf(" -t Maximum time in seconds to wait
");
printf(" -Q Fail if cluster is not quorate, don't wait
");
printf("
");
- printf("Fenced options:
");
- printf(" these are passed on to fenced when it's started
");
- printf(" -c All nodes are in a clean state to start
");
- printf(" -j <secs> Post-join fencing delay
");
- printf(" -f <secs> Post-fail fencing delay
");
- printf("
");
}

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
", 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
", 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;
}


All times are GMT. The time now is 01:23 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.