[Ocfs2-tools-devel] [PATCH 10/32] o2cb: Add a new cluster configuration tool

Sunil Mushran sunil.mushran at oracle.com
Tue Sep 14 15:54:40 PDT 2010


This patch adds the shell of the new cluster configuration tool, o2cb.
This tool will allow the user to manipulate the o2cb cluster configuration,
register/unregister the cluster, start/stop heartbeat, etc. This tool will
eventually replace the existing configuration tool, o2cb_ctl.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 o2cb_ctl/.gitignore                       |    1 +
 o2cb_ctl/Makefile                         |   15 ++-
 o2cb_ctl/o2cbtool.c                       |  172 +++++++++++++++++++++++++++++
 o2cb_ctl/o2cbtool.h                       |   58 ++++++++++
 vendor/common/ocfs2-tools.spec-generic.in |    3 +-
 5 files changed, 243 insertions(+), 6 deletions(-)
 create mode 100644 o2cb_ctl/o2cbtool.c
 create mode 100644 o2cb_ctl/o2cbtool.h

diff --git a/o2cb_ctl/.gitignore b/o2cb_ctl/.gitignore
index 3f832a3..6c781e3 100644
--- a/o2cb_ctl/.gitignore
+++ b/o2cb_ctl/.gitignore
@@ -4,3 +4,4 @@ clusterbo
 o2cb_ctl
 o2cb_ctl.8
 cscope.*
+o2cb
diff --git a/o2cb_ctl/Makefile b/o2cb_ctl/Makefile
index 0a6cb8b..542869d 100644
--- a/o2cb_ctl/Makefile
+++ b/o2cb_ctl/Makefile
@@ -3,7 +3,7 @@ TOPDIR = ..
 include $(TOPDIR)/Preamble.make
 
 sbindir = $(root_sbindir)
-SBIN_PROGRAMS = o2cb_ctl
+SBIN_PROGRAMS = o2cb_ctl o2cb
 
 INCLUDES = -I$(TOPDIR)/include
 
@@ -25,14 +25,16 @@ endif
 
 DEFINES = -DVERSION=\"$(VERSION)\"
 
-O2CB_CTL_CFILES = o2cb_ctl.c o2cb_config.c \
-	jconfig.c jiterator.c
+O2CB_CONFIG_CFILES = o2cb_config.c jconfig.c jiterator.c
+O2CB_CTL_CFILES = ${O2CB_CONFIG_CFILES} o2cb_ctl.c
+O2CB_CFILES = ${O2CB_CONFIG_CFILES} o2cbtool.c
 
 O2CB_CTL_OBJS = $(subst .c,.o,$(O2CB_CTL_CFILES))
+O2CB_OBJS = $(subst .c,.o,$(O2CB_CFILES))
 
-HFILES = o2cb_config.h jconfig.h jiterator.h
+HFILES = o2cb_config.h jconfig.h jiterator.h o2cbtool.h
 
-CFILES = $(CLUSTERBO_CFILES) $(O2CB_CTL_CFILES)
+CFILES = $(O2CB_CTL_CFILES) $(O2CB_CFILES)
 
 MANS = o2cb_ctl.8
 
@@ -44,8 +46,11 @@ jconfig_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 jiterator_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 o2cb_config_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 o2cb_ctl_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
+o2cbtool_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 
 o2cb_ctl: $(O2CB_CTL_OBJS) $(LIBOCFS2_DEPS) $(LIBO2CB_DEPS)
 	$(LINK) $(LIBO2CB_LIBS) $(GLIB_LIBS) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
+o2cb: $(O2CB_OBJS) $(LIBOCFS2_DEPS) $(LIBO2CB_DEPS) ${LIBO2DLM_DEPS} ${LIBTOOLS_INTERNAL_DEPS}
+	$(LINK) $(LIBO2CB_LIBS) $(GLIB_LIBS) $(LIBOCFS2_LIBS) ${LIBO2DLM_LIBS} ${LIBTOOLS_INTERNAL_LIBS} $(COM_ERR_LIBS)
 
 include $(TOPDIR)/Postamble.make
diff --git a/o2cb_ctl/o2cbtool.c b/o2cb_ctl/o2cbtool.c
new file mode 100644
index 0000000..bf0c766
--- /dev/null
+++ b/o2cb_ctl/o2cbtool.c
@@ -0,0 +1,172 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * o2cbtool.c
+ *
+ * Manipulates o2cb cluster configuration
+ *
+ * Copyright (C) 2010 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include "o2cbtool.h"
+
+char *progname = "o2cbtool";
+
+struct o2cb_command o2cbtool_cmds[] = {
+	{
+		.o_name = NULL,
+		.o_action = NULL,
+	},
+};
+
+#define USAGE_STR	\
+	"[--config-file=path] [-h|--help] [-v|--verbose] [-V|--version] " \
+	"COMMAND [ARGS]"
+
+static void usage(void)
+{
+	struct o2cb_command *p = o2cbtool_cmds;
+
+	fprintf(stderr, "usage: %s %s\n", progname, USAGE_STR);
+	fprintf(stderr, "\n");
+	fprintf(stderr, "The commands are:\n");
+	while(p->o_name) {
+		fprintf(stderr, "  %-18s  %s\n", p->o_name, p->o_help);
+		++p;
+	}
+	fprintf(stderr, "\n");
+
+	exit(1);
+}
+
+static void parse_options(int argc, char *argv[], struct o2cb_command **cmd)
+{
+	int c, show_version = 0, show_help = 0;
+	char *config_file = NULL;
+	static struct option long_options[] = {
+		{ "config-file", 1, 0, CONFIG_FILE_OPTION },
+		{ "help", 0, 0, 'h' },
+		{ "verbose", 0, 0, 'v' },
+		{ "version", 0, 0, 'V' },
+		{ 0, 0, 0, 0 },
+	};
+
+	if (argc && *argv)
+		progname = basename(argv[0]);
+
+	while (1) {
+		c = getopt_long(argc, argv, "+hvV", long_options, NULL);
+
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'h':
+			show_help = 1;
+			break;
+
+		case 'v':
+			tools_verbose();
+			break;
+
+		case 'V':
+			show_version = 1;
+			break;
+
+		case CONFIG_FILE_OPTION:
+			config_file = optarg;
+			break;
+
+		default:
+			usage();
+			break;
+		}
+	}
+
+	if (!config_file)
+		config_file = O2CB_DEFAULT_CONFIG_FILE;
+
+	if (show_version) {
+		tools_version();
+		exit(1);
+	}
+
+	if (show_help)
+		usage();
+
+	if (optind == argc)
+		usage();
+
+	verbosef(VL_APP, "Using config file '%s'\n", config_file);
+
+	for (*cmd = &o2cbtool_cmds[0]; ((*cmd)->o_name); ++(*cmd)) {
+		if (!strcmp(argv[optind], (*cmd)->o_name)) {
+			(*cmd)->o_argc = argc - optind;
+			(*cmd)->o_argv = &(argv[optind]);
+			(*cmd)->o_config_file = config_file;
+			optind = 0;	/* restart opt processing */
+			return;
+		}
+	}
+
+	errorf("Unknown command '%s'\n", argv[optind]);
+	usage();
+	exit(1);
+}
+
+int main(int argc, char **argv)
+{
+	errcode_t ret;
+	struct o2cb_command *cmd;
+	O2CBConfig *oc_config = NULL;
+
+	setbuf(stdout, NULL);
+	setbuf(stderr, NULL);
+
+	initialize_o2cb_error_table();
+
+	tools_setup_argv0(argv[0]);
+
+	parse_options(argc, argv, &cmd);
+
+	ret = o2cb_config_load(cmd->o_config_file, &oc_config);
+	if (ret) {
+		tcom_err(ret, "while loading cluster configuration "
+			 "file '%s'", cmd->o_config_file);
+		goto bail;
+	}
+
+	cmd->o_config = oc_config;
+	cmd->o_modified = 0;
+
+	ret = -1;
+	if (!cmd->o_action) {
+		errorf("Command '%s' has not been implemented\n", cmd->o_name);
+		goto bail;
+	}
+
+	ret = cmd->o_action(cmd);
+
+	if (ret || !cmd->o_modified)
+		goto bail;
+
+	ret = o2cb_config_store(oc_config, cmd->o_config_file);
+	if (ret)
+		tcom_err(ret, "while storing the cluster configuration in "
+			 "file '%s'", cmd->o_config_file);
+
+bail:
+	if (oc_config)
+		o2cb_config_free(oc_config);
+
+	return ret;
+}
diff --git a/o2cb_ctl/o2cbtool.h b/o2cb_ctl/o2cbtool.h
new file mode 100644
index 0000000..0c140a4
--- /dev/null
+++ b/o2cb_ctl/o2cbtool.h
@@ -0,0 +1,58 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * o2cbtool.h
+ *
+ * Manipulates o2cb cluster configuration
+ *
+ * Copyright (C) 2010 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <errno.h>
+#include <getopt.h>
+#include <libgen.h>
+#include <signal.h>
+
+#include <glib.h>
+
+#include "jiterator.h"
+#include "o2cb_config.h"
+
+#include "o2cb/o2cb.h"
+#include "ocfs2/ocfs2.h"
+#include "tools-internal/verbose.h"
+#include "tools-internal/utils.h"
+
+#define O2CB_DEFAULT_CONFIG_FILE	"/etc/ocfs2/cluster.conf"
+
+struct o2cb_command {
+	int o_modified;
+	int o_argc;
+	char **o_argv;
+	char *o_name;
+	char *o_help;
+	char *o_usage;
+	char *o_config_file;
+	O2CBConfig *o_config;
+	errcode_t (*o_action)(struct o2cb_command *);
+};
+
+enum {
+	CONFIG_FILE_OPTION = CHAR_MAX + 1,
+};
diff --git a/vendor/common/ocfs2-tools.spec-generic.in b/vendor/common/ocfs2-tools.spec-generic.in
index 3e9b46a..876cb00 100644
--- a/vendor/common/ocfs2-tools.spec-generic.in
+++ b/vendor/common/ocfs2-tools.spec-generic.in
@@ -67,7 +67,7 @@ develop ocfs2 filesystem-specific programs.
 
 
 %build
-%configure --disable-debug --prefix=/usr --mandir=/usr/share/man --libdir=%{brokenrhlibdir}
+%configure --disable-debug --enable-dynamic-ctl --prefix=/usr --mandir=/usr/share/man --libdir=%{brokenrhlibdir}
 make
 
 
@@ -116,6 +116,7 @@ fi
 /sbin/tunefs.ocfs2
 /sbin/debugfs.ocfs2
 /sbin/o2cb_ctl
+/sbin/o2cb
 /sbin/mount.ocfs2
 /sbin/o2image
 /sbin/ocfs2_hb_ctl
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list