[Ocfs2-tools-devel] [PATCH 12/25] o2cb: Add ops add-heartbeat, remove-heartbeat and heartbeat-mode

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


add-heartbeat, remove-heartbeat and heartbeat-mode manipulate heartbeat info
in the o2cb config file.

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

diff --git a/o2cb_ctl/Makefile b/o2cb_ctl/Makefile
index ba6e75a..743f813 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 op_cluster.c op_node.c
+O2CB_CFILES = ${O2CB_CONFIG_CFILES} o2cbtool.c op_cluster.c op_node.c op_heartbeat.c
 
 O2CB_CTL_OBJS = $(subst .c,.o,$(O2CB_CTL_CFILES))
 O2CB_OBJS = $(subst .c,.o,$(O2CB_CFILES))
@@ -49,6 +49,7 @@ o2cb_ctl_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 o2cbtool_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 op_cluster_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
 op_node_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
+op_heartbeat_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 954febd..5dff9a6 100644
--- a/o2cb_ctl/o2cbtool.c
+++ b/o2cb_ctl/o2cbtool.c
@@ -49,6 +49,26 @@ struct o2cb_command o2cbtool_cmds[] = {
 		.o_help = "Removes a node from the cluster in the config file.",
 	},
 	{
+		.o_name = "add-heartbeat",
+		.o_action = o2cbtool_add_heartbeat,
+		.o_usage = "<clustername> [<uuid>|<device>]",
+		.o_help = "Adds a heartbeat region to the cluster in the "
+			"config file.",
+	},
+	{
+		.o_name = "remove-heartbeat",
+		.o_action = o2cbtool_remove_heartbeat,
+		.o_usage = "<clustername> [<uuid>|<device>]",
+		.o_help = "Removes a heartbeat region from the cluster in "
+			"the config file.",
+	},
+	{
+		.o_name = "heartbeat-mode",
+		.o_action = o2cbtool_heartbeat_mode,
+		.o_usage = "<clustername> {global|local}",
+		.o_help = "Toggles the heartbeat mode between global and local.",
+	},
+	{
 		.o_name = NULL,
 		.o_action = NULL,
 	},
diff --git a/o2cb_ctl/o2cbtool.h b/o2cb_ctl/o2cbtool.h
index c617b47..bd5d12a 100644
--- a/o2cb_ctl/o2cbtool.h
+++ b/o2cb_ctl/o2cbtool.h
@@ -65,3 +65,7 @@ errcode_t o2cbtool_remove_cluster(struct o2cb_command *cmd);
 
 errcode_t o2cbtool_add_node(struct o2cb_command *cmd);
 errcode_t o2cbtool_remove_node(struct o2cb_command *cmd);
+
+errcode_t o2cbtool_add_heartbeat(struct o2cb_command *cmd);
+errcode_t o2cbtool_remove_heartbeat(struct o2cb_command *cmd);
+errcode_t o2cbtool_heartbeat_mode(struct o2cb_command *cmd);
diff --git a/o2cb_ctl/op_heartbeat.c b/o2cb_ctl/op_heartbeat.c
new file mode 100644
index 0000000..535557d
--- /dev/null
+++ b/o2cb_ctl/op_heartbeat.c
@@ -0,0 +1,194 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * op_heartbeat.c
+ *
+ * Manipulates heartbeat info in the 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"
+
+static int get_region(char *device, char **region)
+{
+	ocfs2_filesys *fs;
+	errcode_t ret = 0;
+
+	*region = '\0';
+
+	if (*device != '/') {
+		*region = strdup(device);
+		goto bail;
+	}
+
+	ret = ocfs2_open(device, OCFS2_FLAG_RO | OCFS2_FLAG_HEARTBEAT_DEV_OK,
+			 0, 0, &fs);
+	if (ret)
+		goto bail;
+
+	if (!ret) {
+		*region = strdup(fs->uuid_str);
+		ocfs2_close(fs);
+	}
+
+	if (*region)
+		verbosef(VL_DEBUG, "Device '%s' has uuid '%s'\n", device,
+			 *region);
+
+bail:
+	if (ret)
+		tcom_err(ret, "while reading region from device '%s'\n",
+			 device);
+
+	if (!ret && !*region) {
+		ret = O2CB_ET_NO_MEMORY;
+		tcom_err(ret, "while copying uuid '%s'", fs->uuid_str);
+	}
+
+	return ret;
+}
+
+/*
+ * o2cb add-heartbeat <clustername> <region|device>
+ */
+errcode_t o2cbtool_add_heartbeat(struct o2cb_command *cmd)
+{
+	O2CBCluster *cluster;
+	O2CBHeartbeat *hb;
+	int ret = -1;
+	gchar *clustername, *tmp, *region = '\0';
+
+	if (cmd->o_argc < 3) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	clustername = cmd->o_argv[1];
+	tmp = cmd->o_argv[2];
+
+	ret = get_region(tmp, &region);
+	if (ret)
+		goto bail;
+
+	ret = -1;
+	cluster = o2cb_config_get_cluster_by_name(cmd->o_config, clustername);
+	if (!cluster) {
+		errorf("Unknown cluster '%s'\n", clustername);
+		goto bail;
+	}
+
+	hb = o2cb_cluster_add_heartbeat(cluster, region);
+	if (!hb) {
+		errorf("Heartbeat region '%s' already exists\n", region);
+		goto bail;
+	}
+
+	cmd->o_modified = 1;
+	ret = 0;
+	verbosef(VL_APP, "Added heartbeat region '%s' to cluster '%s'\n",
+		 region, clustername);
+
+bail:
+	if (region)
+		free(region);
+	return ret;
+}
+
+/*
+ * o2cb remove-heartbeat <clustername> <region>
+ */
+errcode_t o2cbtool_remove_heartbeat(struct o2cb_command *cmd)
+{
+	O2CBCluster *cluster;
+	int ret = -1;
+	gchar *clustername, *tmp, *region = '\0';
+
+	if (cmd->o_argc < 3) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	clustername = cmd->o_argv[1];
+	tmp = cmd->o_argv[2];
+
+	ret = get_region(tmp, &region);
+	if (ret)
+		goto bail;
+
+	ret = -1;
+	cluster = o2cb_config_get_cluster_by_name(cmd->o_config, clustername);
+	if (!cluster) {
+		errorf("Unknown cluster '%s'\n", clustername);
+		goto bail;
+	}
+
+	ret = o2cb_cluster_remove_heartbeat(cluster, region);
+	if (ret) {
+		errorf("Unknown heartbeat region '%s'\n", region);
+		goto bail;
+	}
+
+	cmd->o_modified = 1;
+	ret = 0;
+	verbosef(VL_APP, "Removed heartbeat region '%s' from cluster '%s'\n",
+		 region, clustername);
+
+bail:
+	if (region)
+		free(region);
+	return ret;
+}
+
+/*
+ * o2cb heartbeat-mode <clustername> <global|local>
+ */
+errcode_t o2cbtool_heartbeat_mode(struct o2cb_command *cmd)
+{
+	O2CBCluster *cluster;
+	int ret = -1;
+	gchar *clustername, *hbmode;
+
+	if (cmd->o_argc < 3) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	clustername = cmd->o_argv[1];
+	hbmode = cmd->o_argv[2];
+
+	if (strcmp(hbmode, "global") && strcmp(hbmode, "local")) {
+		errorf("usage: %s %s\n", cmd->o_name, cmd->o_usage);
+		goto bail;
+	}
+
+	cluster = o2cb_config_get_cluster_by_name(cmd->o_config, clustername);
+	if (!cluster) {
+		errorf("Unknown cluster '%s'\n", clustername);
+		goto bail;
+	}
+
+	ret = o2cb_cluster_set_heartbeat_mode(cluster, hbmode);
+	if (ret) {
+		errorf("Could not change heartbeat mode to '%s', ret=%d,\n",
+		       hbmode, ret);
+		goto bail;
+	}
+
+	cmd->o_modified = 1;
+	ret = 0;
+	verbosef(VL_APP, "Changed heartbeat mode in cluster '%s' to '%s'\n",
+		 clustername, hbmode);
+
+bail:
+	return ret;
+}
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list