[Ocfs2-tools-devel] [PATCH 10/25] o2cb: Add ops add-cluster aand remove-cluster

Sunil Mushran sunil.mushran at oracle.com
Wed Jun 23 11:44:20 PDT 2010


add-cluster and remove-cluster manipulate the cluster info in
the o2cb config file.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 o2cb_ctl/Makefile     |    3 +-
 o2cb_ctl/o2cbtool.c   |   12 +++++++
 o2cb_ctl/o2cbtool.h   |    3 ++
 o2cb_ctl/op_cluster.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 1 deletions(-)
 create mode 100644 o2cb_ctl/op_cluster.c

diff --git a/o2cb_ctl/Makefile b/o2cb_ctl/Makefile
index 542869d..1f5cbac 100644
--- a/o2cb_ctl/Makefile
+++ b/o2cb_ctl/Makefile
@@ -27,7 +27,7 @@ DEFINES = -DVERSION=\"$(VERSION)\"
 
 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_CFILES = ${O2CB_CONFIG_CFILES} o2cbtool.c op_cluster.c
 
 O2CB_CTL_OBJS = $(subst .c,.o,$(O2CB_CTL_CFILES))
 O2CB_OBJS = $(subst .c,.o,$(O2CB_CFILES))
@@ -47,6 +47,7 @@ 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
+op_cluster_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)
diff --git a/o2cb_ctl/o2cbtool.c b/o2cb_ctl/o2cbtool.c
index 31b6637..316535a 100644
--- a/o2cb_ctl/o2cbtool.c
+++ b/o2cb_ctl/o2cbtool.c
@@ -24,6 +24,18 @@ char *config_file = O2CB_DEFAULT_CONFIG_FILE;
 
 struct o2cb_command o2cbtool_cmds[] = {
 	{
+		.o_name = "add-cluster",
+		.o_action = o2cbtool_add_cluster,
+		.o_usage = "<clustername>",
+		.o_help = "Add cluster to the config file.",
+	},
+	{
+		.o_name = "remove-cluster",
+		.o_action = o2cbtool_remove_cluster,
+		.o_usage = "<clustername>",
+		.o_help = "Removes cluster from the config file.",
+	},
+	{
 		.o_name = NULL,
 		.o_action = NULL,
 	},
diff --git a/o2cb_ctl/o2cbtool.h b/o2cb_ctl/o2cbtool.h
index 4ef7db1..76ac0f0 100644
--- a/o2cb_ctl/o2cbtool.h
+++ b/o2cb_ctl/o2cbtool.h
@@ -54,3 +54,6 @@ struct o2cb_command {
 enum {
 	CONFIG_FILE_OPTION = CHAR_MAX + 1,
 };
+
+errcode_t o2cbtool_add_cluster(struct o2cb_command *cmd);
+errcode_t o2cbtool_remove_cluster(struct o2cb_command *cmd);
diff --git a/o2cb_ctl/op_cluster.c b/o2cb_ctl/op_cluster.c
new file mode 100644
index 0000000..5f20489
--- /dev/null
+++ b/o2cb_ctl/op_cluster.c
@@ -0,0 +1,79 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * op_cluster.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"
+
+/*
+ * add-cluster <clustername>
+ */
+errcode_t o2cbtool_add_cluster(struct o2cb_command *cmd)
+{
+	O2CBCluster *cluster;
+	errcode_t ret = -1;
+	gchar *clustername;
+
+	if (cmd->o_argc < 2) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	clustername = cmd->o_argv[1];
+
+	cluster = o2cb_config_add_cluster(cmd->o_config, clustername);
+	if (!cluster) {
+		errorf("cluster '%s' already exists\n", clustername);
+		goto bail;
+	}
+
+	cmd->o_modified = 1;
+	ret = 0;
+	verbosef(VL_APP, "Added cluster '%s'\n", clustername);
+
+bail:
+	return ret;
+}
+
+/*
+ * remove-cluster <clustername>
+ */
+errcode_t o2cbtool_remove_cluster(struct o2cb_command *cmd)
+{
+	errcode_t ret = -1;
+	gchar *clustername;
+
+	if (cmd->o_argc < 2) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	clustername = cmd->o_argv[1];
+
+	ret = o2cb_config_remove_cluster(cmd->o_config, clustername);
+	if (ret) {
+		errorf("cluster '%s' not found\n", clustername);
+		goto bail;
+	}
+
+	cmd->o_modified = 1;
+	ret = 0;
+	verbosef(VL_APP, "Removed cluster '%s'\n", clustername);
+
+bail:
+	return ret;
+}
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list