cluster: RHEL55 - fenced: fence_tool dumpconfig and readconfig
David Teigland
teigland at fedoraproject.org
Tue Dec 15 20:18:33 UTC 2009
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=3234bbd17557cf9cb86d648bb2ad3d43f4c003b7
Commit: 3234bbd17557cf9cb86d648bb2ad3d43f4c003b7
Parent: b5be828615a2ed7bd95a3796d96f5cc536e2adc7
Author: David Teigland <teigland at redhat.com>
AuthorDate: Tue Dec 15 15:09:21 2009 -0600
Committer: David Teigland <teigland at redhat.com>
CommitterDate: Tue Dec 15 15:13:25 2009 -0600
fenced: fence_tool dumpconfig and readconfig
bz 514662
fence_tool dumpconfig to dump the existing fenced config settings.
fence_tool readconfig to tell fenced to reread config settings
from cluster.conf.
Original patch from edamato at redhat.com
Signed-off-by: David Teigland <teigland at redhat.com>
---
fence/fence_tool/fence_tool.c | 63 ++++++++++++++++++++++++++++++++++++-
fence/fenced/main.c | 69 +++++++++++++++++++++++++++++++++++++++++
fence/man/fence_tool.8 | 5 ++-
3 files changed, 134 insertions(+), 3 deletions(-)
diff --git a/fence/fence_tool/fence_tool.c b/fence/fence_tool/fence_tool.c
index 0b7ea62..4edc4d7 100644
--- a/fence/fence_tool/fence_tool.c
+++ b/fence/fence_tool/fence_tool.c
@@ -47,6 +47,8 @@
#define OP_LEAVE 2
#define OP_WAIT 3
#define OP_DUMP 4
+#define OP_READCONFIG 5
+#define OP_DUMPCONFIG 6
/* 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 */
@@ -432,11 +434,62 @@ static int do_dump(void)
return 0;
}
+static int do_readconfig(void)
+{
+ char buf[MAXLINE];
+ int fd, rv;
+
+ fd = fenced_connect();
+
+ memset(buf, 0, sizeof(buf));
+
+ sprintf(buf, "readconfig");
+
+ rv = do_write(fd, buf, sizeof(buf));
+ if (rv < 0)
+ die("can't communicate with fenced");
+
+ memset(buf, 0, sizeof(buf));
+ rv = do_read(fd, buf, sizeof(buf));
+ if (rv < 0)
+ printf("readconfig: %s\n", strerror(errno));
+
+ close(fd);
+ return 0;
+}
+
+static int do_dumpconfig(void)
+{
+ char inbuf[DUMP_SIZE];
+ char outbuf[MAXLINE];
+ int fd, rv;
+
+ fd = fenced_connect();
+
+ memset(inbuf, 0, sizeof(inbuf));
+ memset(outbuf, 0, sizeof(outbuf));
+
+ sprintf(outbuf, "dumpconfig");
+
+ rv = do_write(fd, outbuf, sizeof(outbuf));
+ if (rv < 0)
+ die("can't communicate with fenced");
+
+ rv = do_read(fd, inbuf, sizeof(inbuf));
+ if (rv < 0)
+ printf("dumpconfig: %s\n", strerror(errno));
+
+ do_write(STDOUT_FILENO, inbuf, strlen(inbuf));
+
+ close(fd);
+ return 0;
+}
+
static void print_usage(void)
{
printf("Usage:\n");
printf("\n");
- printf("%s <join|leave|dump> [options]\n", prog_name);
+ printf("%s <join|leave|dump|dumpconfig|readconfig> [options]\n", prog_name);
printf("\n");
printf("Actions:\n");
printf(" join Join the default fence domain\n");
@@ -515,6 +568,10 @@ static void decode_arguments(int argc, char *argv[])
operation = OP_LEAVE;
} else if (strcmp(argv[optind], "dump") == 0) {
operation = OP_DUMP;
+ } else if (strcmp(argv[optind], "dumpconfig") == 0) {
+ operation = OP_DUMPCONFIG;
+ } else if (strcmp(argv[optind], "readconfig") == 0) {
+ operation = OP_READCONFIG;
} else
die("unknown option %s\n", argv[optind]);
optind++;
@@ -537,6 +594,10 @@ int main(int argc, char *argv[])
return do_leave();
case OP_DUMP:
return do_dump();
+ case OP_READCONFIG:
+ return do_readconfig();
+ case OP_DUMPCONFIG:
+ return do_dumpconfig();
case OP_WAIT:
return -1;
}
diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index f2b5d07..3d553b2 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -379,6 +379,71 @@ static int do_dump(int fd)
return 0;
}
+static int do_readconfig(void)
+{
+ char path[256], *str = NULL;
+ int error, cd, i = 0;
+
+ while ((cd = ccs_connect()) < 0) {
+ sleep(1);
+ if (++i > 9) {
+ log_error("ccs_connect error %d, "
+ "check ccsd or cluster status", cd);
+ return -1;
+ }
+ }
+
+ if (comline.post_join_delay_opt == FALSE) {
+ str = NULL;
+ memset(path, 0, 256);
+ sprintf(path, "/cluster/fence_daemon/@post_join_delay");
+
+ error = ccs_get(cd, path, &str);
+ if (!error)
+ comline.post_join_delay = atoi(str);
+ else
+ comline.post_join_delay = DEFAULT_POST_JOIN_DELAY;
+ if (str)
+ free(str);
+ }
+
+ if (comline.post_fail_delay_opt == FALSE) {
+ str = NULL;
+ memset(path, 0, 256);
+ sprintf(path, "/cluster/fence_daemon/@post_fail_delay");
+
+ error = ccs_get(cd, path, &str);
+ if (!error)
+ comline.post_fail_delay = atoi(str);
+ else
+ comline.post_fail_delay = DEFAULT_POST_FAIL_DELAY;
+ if (str)
+ free(str);
+ }
+
+ ccs_disconnect(cd);
+ return 0;
+}
+
+static int do_dumpconfig(int fd)
+{
+ char buf[DUMP_SIZE];
+
+ memset(buf, 0, sizeof(buf));
+ sprintf(buf, "post_fail_delay = %d\n"
+ "post_join_delay = %d\n"
+ "clean_start = %d\n"
+ "skip_undefined = %d\n"
+ "override_path = %s\n",
+ comline.post_fail_delay, comline.post_join_delay,
+ comline.clean_start, comline.skip_undefined,
+ comline.override_path);
+
+ do_write(fd, buf, sizeof(buf));
+
+ return 0;
+}
+
static int client_process(int ci)
{
char buf[MAXLINE], *argv[MAXARGS], *cmd, *name, out[MAXLINE];
@@ -408,6 +473,10 @@ static int client_process(int ci)
rv = do_join(name);
else if (!strcmp(cmd, "leave"))
rv = do_leave(name);
+ else if (!strcmp(cmd, "readconfig"))
+ rv = do_readconfig();
+ else if (!strcmp(cmd, "dumpconfig"))
+ rv = do_dumpconfig(client[ci].fd);
else if (!strcmp(cmd, "dump")) {
do_dump(client[ci].fd);
close(client[ci].fd);
diff --git a/fence/man/fence_tool.8 b/fence/man/fence_tool.8
index 7477f6f..66c378d 100644
--- a/fence/man/fence_tool.8
+++ b/fence/man/fence_tool.8
@@ -13,12 +13,13 @@ fence_tool - A program to join and leave the fence domain
.SH SYNOPSIS
.B
fence_tool
-<\fBjoin | leave | dump\fP>
+<\fBjoin | leave | dump | dumpconfig | readconfig\fP>
[\fIOPTION\fR]...
.SH DESCRIPTION
\fBfence_tool\fP is a program used to join or leave the default fence
-domain. It communicates with the fenced daemon. Before telling fenced
+domain, but also to dump and reread the configuration from CCS.
+It communicates with the fenced daemon. Before telling fenced
to join the domain, fence_tool waits for the cluster to have quorum,
making it easier to cancel the command if the cluster is inquorate.
More information about the cluster-commits
mailing list