[Ocfs2-tools-commits] jlbec commits r539 - in branches/kabi:
clusterbo libo2cb libo2cb/include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Jan 5 19:47:29 CST 2005
Author: jlbec
Date: 2005-01-05 19:47:27 -0600 (Wed, 05 Jan 2005)
New Revision: 539
Removed:
branches/kabi/clusterbo/clusterbo.c
Modified:
branches/kabi/clusterbo/Makefile
branches/kabi/clusterbo/o2cb_ctl.c
branches/kabi/libo2cb/include/o2cb.h
branches/kabi/libo2cb/include/o2cb_abi.h
branches/kabi/libo2cb/include/o2cb_kabi.h
branches/kabi/libo2cb/o2cb_abi.c
branches/kabi/libo2cb/o2cb_err.et.in
Log:
o Use nicer ABI to set cluster name.
Modified: branches/kabi/clusterbo/Makefile
===================================================================
--- branches/kabi/clusterbo/Makefile 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/clusterbo/Makefile 2005-01-06 01:47:27 UTC (rev 539)
@@ -2,7 +2,7 @@
include $(TOPDIR)/Preamble.make
-SBIN_PROGRAMS = clusterbo o2cb_ctl
+SBIN_PROGRAMS = o2cb_ctl
INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
-I$(TOPDIR)/libo2cb/include
@@ -23,9 +23,6 @@
DEFINES = -DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
-CLUSTERBO_CFILES = clusterbo.c
-CLUSTERBO_OBJS = $(subst .c,.o,$(CLUSTERBO_CFILES))
-
O2CB_CTL_CFILES = o2cb_ctl.c o2cb_config.c \
jconfig.c jiterator.c
@@ -33,14 +30,11 @@
HEADERS = jconfig.h jiterator.h
-CFILES = $(CLUSTERBO_CFILES) $(O2CB_CTL_CFILES)
+CFILES = $(O2CB_CTL_CFILES)
DIST_FILES = $(CFILES) $(HEADERS)
DIST_RULES = dist-subdircreate
-clusterbo: $(CLUSTERBO_OBJS) $(LIBO2CB_DEBS) $(LIBOCFS2_DEPS)
- $(LINK) $(LIBO2CB_LIBS) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
-
jconfig_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
jiterator_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
o2cb_config_CPPFLAGS = $(GLIB_CFLAGS) -DG_DISABLE_DEPRECATED
Deleted: branches/kabi/clusterbo/clusterbo.c
===================================================================
--- branches/kabi/clusterbo/clusterbo.c 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/clusterbo/clusterbo.c 2005-01-06 01:47:27 UTC (rev 539)
@@ -1,203 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/mount.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-
-#include "o2cb.h"
-
-#define atomic_t int
-#define spinlock_t unsigned long
-typedef unsigned short kdev_t;
-
-typedef struct list_head {
- struct list_head *next, *prev;
-} list_t;
-
-#define NIPQUAD(addr) \
- ((unsigned char *)&addr)[0], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[3]
-
-
-#define CONF_FILE "/etc/cluster.conf"
-
-/* are these right ? */
-#define MIN_PORT_NUM 1024
-#define MAX_PORT_NUM 65535
-
-#define OCFS2_NM_MODULE "ocfs2_nodemanager"
-#define OCFS2_HB_MODULE "ocfs2_heartbeat"
-#define OCFS2_TCP_MODULE "ocfs2_tcp"
-
-
-int load_module(char *module, char *mountpoint, char *fstype);
-
-
-nm_node_info *nodes;
-int total_nodes = 0;
-
-int main(int argc, char **argv)
-{
- int ret, i;
- FILE *conf;
- char *cluster_name = NULL;
-
- ret = load_module(OCFS2_NM_MODULE, "/proc/cluster/nm", "nm");
- if (ret) {
- fprintf(stderr, "failed to load and/or mount nm: %d\n", ret);
- exit(1);
- }
- ret = load_module(OCFS2_HB_MODULE, "/proc/cluster/heartbeat", "hb");
- if (ret) {
- fprintf(stderr, "failed to load and/or mount hb: %d\n", ret);
- exit(1);
- }
- ret = load_module(OCFS2_TCP_MODULE, NULL, NULL);
- if (ret) {
- fprintf(stderr, "failed to load tcp: %d\n", ret);
- exit(1);
- }
-
- nodes = malloc(NM_MAX_NODES * sizeof(nm_node_info));
- if (!nodes) {
- fprintf(stderr, "failed to malloc node array\n");
- exit(1);
- }
- memset(nodes, 0, NM_MAX_NODES * sizeof(nm_node_info));
-
- conf = fopen(CONF_FILE, "r");
- if (!conf) {
- fprintf(stderr, "failed to open %s: %s\n", CONF_FILE, strerror(errno));
- exit(1);
- }
-
- ret = fscanf(conf, "cluster_name=%64as\n", &cluster_name);
- if (ret != 1) {
- fprintf(stderr, "bad file format: expected cluster_name=XXX\n");
- exit(1);
- }
- printf("found cluster named %s\n", cluster_name);
-
- while (1) {
- int node_num, port;
- char *node_name = NULL;
- char *ip = NULL;
- uint32_t real_ip;
-
- ret = fscanf(conf, "%d,%64a[^,],%15a[0-9.],%d\n", &node_num, &node_name, &ip, &port);
- if (ret == 0 || ret == -1) {
- printf("done. found %d nodes\n", total_nodes);
- break;
- }
- if (ret != 4) {
- fprintf(stderr, "bad file format: node_num,node_name,ipaddr,ipport\n");
- exit(1);
- }
-
- if (node_num < 0 || node_num >= NM_MAX_NODES) {
- fprintf(stderr, "bad node number: got %d, range is 0 - %d\n", node_num, NM_MAX_NODES-1);
- exit(1);
- }
- if (nodes[node_num].node_name[0]) {
- fprintf(stderr, "already have a node in slot %d: orig=%s, this=%s\n",
- node_num, nodes[node_num].node_name, node_name);
- exit(1);
- }
- if (port < MIN_PORT_NUM || port > MAX_PORT_NUM) {
- fprintf(stderr, "bad port number: got %d, range is %d - %d\n", port, MIN_PORT_NUM, MAX_PORT_NUM);
- exit(1);
- }
- if (!inet_aton(ip, (struct in_addr*)&real_ip)) {
- fprintf(stderr, "bad ipv4 address: %s\n", ip);
- exit(1);
- }
-
-
- total_nodes++;
- nodes[node_num].node_num = node_num;
- memcpy(nodes[node_num].node_name, node_name, NM_MAX_NAME_LEN);
- nodes[node_num].node_name[NM_MAX_NAME_LEN]=0;
- nodes[node_num].ifaces[0].ip_port = htons(port);
- nodes[node_num].ifaces[0].addr_u.ip_addr4 = real_ip;
- free(ip);
- free(node_name);
- }
- fclose(conf);
-
- ret = o2cb_set_cluster_name(cluster_name);
- i=0;
- while (1) {
- if (!total_nodes--)
- break;
- if (!nodes[i].node_name[0]) {
- i++;
- continue;
- }
- ret = o2cb_add_node(&nodes[i]);
- i++;
- }
- printf("done. activating cluster now...\n");
- ret = o2cb_activate_cluster();
- printf("done. nm ready!\n");
- ret = o2cb_activate_networking();
- printf("done. net ready!\n");
- free(nodes);
- return 0;
-}
-
-int load_module(char *module, char *mountpoint, char *fstype)
-{
- int ret;
- int pid;
- int status;
- struct stat st;
-
- pid = fork();
- switch (pid) {
- case 0:
- ret = execl("/sbin/modprobe", "/sbin/modprobe", module, (char *)NULL);
- fprintf(stderr, "eeek! exec returned %d: %s\n", ret, strerror(errno));
- exit(1);
- break;
- case -1:
- fprintf(stderr, "fork failed: %s\n", strerror(errno));
- return -errno;
-
- default:
- ret = wait(&status);
- if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) != 0) {
- fprintf(stderr, "modprobe returned %d!\n", WEXITSTATUS(status));
- return -WEXITSTATUS(status);
- }
- } else {
- fprintf(stderr, "modprobe has not exited!\n");
- return -EINVAL;
- }
- break;
- }
- if (!mountpoint)
- return 0;
-
- if (stat("/proc/cluster", &st) != 0 ||
- stat(mountpoint, &st) != 0) {
- fprintf(stderr, "mountpoint %s does not exist!\n", mountpoint);
- return -EINVAL;
- }
-
- ret = mount("none", mountpoint, fstype, 0, "");
- return ret;
-}
Modified: branches/kabi/clusterbo/o2cb_ctl.c
===================================================================
--- branches/kabi/clusterbo/o2cb_ctl.c 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/clusterbo/o2cb_ctl.c 2005-01-06 01:47:27 UTC (rev 539)
@@ -601,10 +601,15 @@
{
O2CBAction *action;
+ g_return_val_if_fail(func != NULL, -EINVAL);
+
action = g_new0(O2CBAction, 1);
if (!action)
return -ENOMEM;
+ action->oa_func = func;
+ action->oa_data = user_data;
+
ctxt->oc_actions = g_list_append(ctxt->oc_actions, action);
return 0;
@@ -680,7 +685,7 @@
goto out_error;
rc = -EIO;
- ret = o2cb_set_cluster_name(name);
+ ret = o2cb_cluster_set_name(name);
if (ret)
{
com_err(PROGNAME, ret, "while setting cluster name");
@@ -697,7 +702,7 @@
l = l->next;
}
- rc = o2cb_activate_cluster();
+ rc = o2cb_cluster_activate();
if (rc)
goto out_error;
rc = o2cb_activate_networking();
@@ -716,7 +721,7 @@
}
return rc;
-} /* online_cluster() */
+} /* online_cluster_action() */
static gint offline_cluster_action(gpointer user_data)
{
@@ -816,7 +821,7 @@
rc = write_config(ctxt);
- if (rc)
+ if (!rc)
rc = process_actions(ctxt);
out_error:
Modified: branches/kabi/libo2cb/include/o2cb.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb.h 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/libo2cb/include/o2cb.h 2005-01-06 01:47:27 UTC (rev 539)
@@ -55,9 +55,11 @@
#include <o2cb/ocfs2_tcp.h>
#endif
-errcode_t o2cb_set_cluster_name(const char *cluster_name);
+errcode_t o2cb_cluster_set_name(const char *cluster_name);
+errcode_t o2cb_cluster_get_name(char *cluster_name, size_t size);
errcode_t o2cb_add_node(nm_node_info *node);
-errcode_t o2cb_activate_cluster(void);
+errcode_t o2cb_cluster_activate(void);
+errcode_t o2cb_cluster_is_active(void);
errcode_t o2cb_activate_networking(void);
#endif /* _O2CB_H */
Modified: branches/kabi/libo2cb/include/o2cb_abi.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb_abi.h 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/libo2cb/include/o2cb_abi.h 2005-01-06 01:47:27 UTC (rev 539)
@@ -30,6 +30,7 @@
#define O2CB_GROUP_FILE "/proc/cluster/nm/.group"
#define O2CB_NODE_FILE "/proc/cluster/nm/.node"
#define O2CB_LIVE_FILE "/proc/cluster/nm/.live"
+#define O2CB_NAME_FILE "/proc/cluster/nm/.name"
#define O2CB_NETWORKING_FILE "/proc/cluster/net"
#endif /* _O2CB_ABI_H */
Modified: branches/kabi/libo2cb/include/o2cb_kabi.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb_kabi.h 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/libo2cb/include/o2cb_kabi.h 2005-01-06 01:47:27 UTC (rev 539)
@@ -31,11 +31,16 @@
#define O2CB_KABI_VERSION O2CB_KABI_V1
#define O2CB_KABI_MAGIC 0x02CBCA75
+/* Common UTS name length */
+#define O2CB_NAME_MAX 65 /* Includes '\0' */
+
enum o2cb_kabi_operations
{
O2CB_OP_NONE = 0,
O2CB_OP_CLUSTER_SET_LIVE,
O2CB_OP_CLUSTER_IS_LIVE,
+ O2CB_OP_CLUSTER_SET_NAME,
+ O2CB_OP_CLUSTER_GET_NAME,
};
enum o2cb_kabi_errors
@@ -47,6 +52,7 @@
O2CB_KE_INVALID_OPERATION,
O2CB_KE_CLUSTER_ALREADY_LIVE,
O2CB_KE_NOT_SUPPORTED,
+ O2CB_KE_INVALID_NAME,
};
struct o2cb_kabi_info {
@@ -64,6 +70,13 @@
/*14*/
};
+struct o2cb_kabi_cluster_name {
+/*00*/ struct o2cb_kabi_info cn_abi;
+/*10*/ __u32 cn_len;
+ __u8 cn_name[O2CB_NAME_MAX];
+/*55*/
+};
+
/**
* o2cb_kabi_verify(k, member, size)
* @k: An O2CB KABI object embedding a struct o2cb_kabi_info.
Modified: branches/kabi/libo2cb/o2cb_abi.c
===================================================================
--- branches/kabi/libo2cb/o2cb_abi.c 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/libo2cb/o2cb_abi.c 2005-01-06 01:47:27 UTC (rev 539)
@@ -42,40 +42,52 @@
#include "o2cb_kabi.h"
#include "o2cb_abi.h"
-errcode_t o2cb_set_cluster_name(const char *cluster_name)
+#define DEBUG_O2CB
+#ifdef DEBUG_O2CB
+#define debug_print_errno(s, rc) do \
+{ \
+ if ((rc) < 0) \
+ perror((s)); \
+} while (0)
+#define stringify(contents) #contents
+#define debug_kabi_status(k, member) do \
+{ \
+ typeof(k) _k = (k); \
+ struct o2cb_kabi_info *_i = &(_k->member); \
+ if (_i->ki_status) \
+ fprintf(stderr, \
+ "KABI error status %u at %s\n", \
+ _i->ki_status, \
+ __FILE__ ":" stringify(__LINE__)); \
+} while (0)
+#else
+#define debug_kabi_status(k, member) do {} while (0)
+#define debug_print_errno(...) do {} while (0)
+#endif /* DEBUG_O2CB */
+
+static errcode_t process_transaction(const char *filename,
+ void *buf, size_t len)
{
errcode_t ret;
- int fd, rc, page_size = getpagesize();
- char *buf;
- nm_op *op;
+ int fd, rc;
- if (strlen(cluster_name) > NM_MAX_NAME_LEN)
- return O2CB_ET_INVALID_CLUSTER_NAME;
-
- buf = malloc(sizeof(char*) * page_size);
- if (!buf)
- return O2CB_ET_NO_MEMORY;
-
- op = (nm_op *)buf;
- op->magic = NM_OP_MAGIC;
- op->opcode = NM_OP_NAME_CLUSTER;
- strcpy(op->arg_u.name, cluster_name);
-
ret = O2CB_ET_SERVICE_UNAVAILABLE;
- fd = open(O2CB_CLUSTER_FILE, O_RDWR);
+ fd = open(filename, O_RDWR);
+ debug_print_errno("open", fd);
if (fd < 0)
- goto out;
+ return ret;
- rc = write(fd, op, sizeof(nm_op));
+ rc = write(fd, buf, len);
+ debug_print_errno("write", rc);
if (rc < 0)
goto out_close;
+
ret = O2CB_ET_IO;
- if (rc < sizeof(nm_op))
+ if (rc < len)
goto out_close;
- memset(buf, 0, page_size);
-
- rc = read(fd, buf, page_size);
+ rc = read(fd, buf, len);
+ debug_print_errno("read", rc);
if (rc < 0)
goto out_close;
@@ -83,19 +95,83 @@
if (!rc)
goto out_close;
- ret = O2CB_ET_IO; /* FIXME */
- if (buf[0] == '0')
- ret = 0;
+ ret = O2CB_ET_IO;
+ if (rc < len)
+ goto out_close;
+ ret = 0;
+
out_close:
close(fd);
-out:
- free(buf);
return ret;
-} /* o2cb_set_cluster_name() */
+}
+errcode_t o2cb_cluster_set_name(const char *cluster_name)
+{
+ errcode_t ret;
+ struct o2cb_kabi_cluster_name cn;
+ o2cb_kabi_init(&cn, cn_abi, O2CB_OP_CLUSTER_SET_NAME);
+
+ cn.cn_len = strlen(cluster_name);
+ if (cn.cn_len > O2CB_NAME_MAX)
+ return O2CB_ET_INVALID_CLUSTER_NAME;
+
+ strcpy(cn.cn_name, cluster_name);
+
+ ret = process_transaction(O2CB_NAME_FILE, &cn,
+ sizeof(struct o2cb_kabi_cluster_name));
+ if (!ret) {
+ debug_kabi_status(&cn, cn_abi);
+ switch (cn.cn_abi.ki_status) {
+ case O2CB_KE_CLUSTER_ALREADY_LIVE:
+ ret = O2CB_ET_CLUSTER_ALREADY_ACTIVE;
+ break;
+
+ case O2CB_KE_INVALID_NAME:
+ ret = O2CB_ET_INVALID_CLUSTER_NAME;
+ break;
+
+ case 0:
+ /* Nothing */
+ break;
+
+ default:
+ ret = O2CB_ET_INTERNAL_FAILURE;
+ break;
+ }
+ }
+
+ return ret;
+} /* o2cb_cluster_set_name() */
+
+errcode_t o2cb_cluster_get_name(char *cluster_name, size_t size)
+{
+ errcode_t ret;
+ struct o2cb_kabi_cluster_name cn;
+
+ o2cb_kabi_init(&cn, cn_abi, O2CB_OP_CLUSTER_GET_NAME);
+
+ ret = process_transaction(O2CB_NAME_FILE, &cn,
+ sizeof(struct o2cb_kabi_cluster_name));
+ if (!ret) {
+ debug_kabi_status(&cn, cn_abi);
+ if (cn.cn_abi.ki_status)
+ ret = O2CB_ET_INTERNAL_FAILURE;
+ }
+
+ if (!ret) {
+ if (size < (cn.cn_len + 1)) {
+ ret = O2CB_ET_NAME_TRUNCATED;
+ *cluster_name = '\0';
+ } else
+ strcpy(cluster_name, cn.cn_name);
+ }
+
+ return ret;
+} /* o2cb_cluster_get_name() */
+
errcode_t o2cb_add_node(nm_node_info *node)
{
errcode_t ret;
@@ -146,52 +222,50 @@
return ret;
} /* o2cb_add_node() */
-errcode_t o2cb_activate_cluster()
+errcode_t o2cb_cluster_activate()
{
errcode_t ret;
- int fd, rc;
struct o2cb_kabi_live kl;
o2cb_kabi_init(&kl, kl_abi, O2CB_OP_CLUSTER_SET_LIVE);
-
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- fd = open(O2CB_LIVE_FILE, O_RDWR);
- if (fd < 0)
- return ret;
-
kl.kl_live = 1;
- rc = write(fd, &kl, sizeof(struct o2cb_kabi_live));
- if (rc < 0)
- goto out_close;
- ret = O2CB_ET_IO;
- if (rc < sizeof(struct o2cb_kabi_live))
- goto out_close;
+ ret = process_transaction(O2CB_LIVE_FILE, &kl,
+ sizeof(struct o2cb_kabi_live));
+ if (!ret) {
+ debug_kabi_status(&kl, kl_abi);
+ if (kl.kl_abi.ki_status == O2CB_KE_CLUSTER_ALREADY_LIVE)
+ ret = O2CB_ET_CLUSTER_ALREADY_ACTIVE;
+ else if (kl.kl_abi.ki_status)
+ ret = O2CB_ET_INTERNAL_FAILURE;
+ }
- rc = read(fd, &kl, sizeof(struct o2cb_kabi_live));
- if (rc < 0)
- goto out_close;
+ return ret;
+} /* o2cb_cluster_activate() */
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- if (!rc)
- goto out_close;
+/*
+ * Returns O2CB_ET_CLUSTER_ALREADY_ACTIVE if the cluster is live, 0 if
+ * it is not.
+ */
+errcode_t o2cb_cluster_is_active()
+{
+ errcode_t ret;
+ struct o2cb_kabi_live kl;
- ret = O2CB_ET_IO;
- if (rc < sizeof(struct o2cb_kabi_live))
- goto out_close;
+ o2cb_kabi_init(&kl, kl_abi, O2CB_OP_CLUSTER_IS_LIVE);
- if (kl.kl_abi.ki_status == O2CB_KE_CLUSTER_ALREADY_LIVE)
- ret = O2CB_ET_CLUSTER_ALREADY_ACTIVE;
- else if (kl.kl_abi.ki_status)
- ret = O2CB_ET_INTERNAL_FAILURE;
- else
- ret = 0;
+ ret = process_transaction(O2CB_LIVE_FILE, &kl,
+ sizeof(struct o2cb_kabi_live));
+ if (!ret) {
+ debug_kabi_status(&kl, kl_abi);
+ if (kl.kl_abi.ki_status)
+ ret = O2CB_ET_INTERNAL_FAILURE;
+ else if (kl.kl_live)
+ ret = O2CB_ET_CLUSTER_ALREADY_ACTIVE;
+ }
-out_close:
- close(fd);
-
return ret;
-} /* o2cb_activate_cluster() */
+} /* o2cb_cluster_is_active() */
/* FIXME: does this really belong here? */
errcode_t o2cb_activate_networking()
Modified: branches/kabi/libo2cb/o2cb_err.et.in
===================================================================
--- branches/kabi/libo2cb/o2cb_err.et.in 2005-01-05 22:12:17 UTC (rev 538)
+++ branches/kabi/libo2cb/o2cb_err.et.in 2005-01-06 01:47:27 UTC (rev 539)
@@ -42,4 +42,7 @@
ec O2CB_ET_CLUSTER_ALREADY_ACTIVE,
"The cluster is already active, no changes can be made"
+ec O2CB_ET_NAME_TRUNCATED,
+ "The name string was longer than the provided buffer"
+
end
More information about the Ocfs2-tools-commits
mailing list