[Ocfs2-tools-devel] [PATCH 11/32] o2cb: Add ops add-cluster and remove-cluster
Sunil Mushran
sunil.mushran at oracle.com
Tue Sep 14 15:54:41 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 | 6 +++
o2cb_ctl/op_cluster.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 131 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 bf0c766..156a3da 100644
--- a/o2cb_ctl/o2cbtool.c
+++ b/o2cb_ctl/o2cbtool.c
@@ -23,6 +23,18 @@ char *progname = "o2cbtool";
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 0c140a4..59d6066 100644
--- a/o2cb_ctl/o2cbtool.h
+++ b/o2cb_ctl/o2cbtool.h
@@ -28,6 +28,7 @@
#include <getopt.h>
#include <libgen.h>
#include <signal.h>
+#include <ctype.h>
#include <glib.h>
@@ -56,3 +57,8 @@ struct o2cb_command {
enum {
CONFIG_FILE_OPTION = CHAR_MAX + 1,
};
+
+errcode_t o2cbtool_validate_clustername(char *clustername);
+
+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..533fa04
--- /dev/null
+++ b/o2cb_ctl/op_cluster.c
@@ -0,0 +1,111 @@
+/* -*- 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"
+
+errcode_t o2cbtool_validate_clustername(char *clustername)
+{
+ char *p;
+ int len;
+ errcode_t ret = O2CB_ET_INVALID_CLUSTER_NAME;
+
+ p = tools_strstrip(clustername);
+ len = strlen(p);
+
+ if (!len) {
+ tcom_err(O2CB_ET_INVALID_CLUSTER_NAME, "; zero length");
+ return ret;
+ }
+
+ if (len > OCFS2_CLUSTER_NAME_LEN) {
+ tcom_err(ret, "; max %d characters", OCFS2_CLUSTER_NAME_LEN);
+ return ret;
+ }
+
+ while(isalnum(*p++) && len--);
+ if (len) {
+ tcom_err(ret, "; only alpha-numeric characters allowed");
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * 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];
+
+ ret = o2cbtool_validate_clustername(clustername);
+ if (ret)
+ goto bail;
+
+ 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 || !strlen(tools_strstrip(cmd->o_argv[1]))) {
+ 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