[Ocfs2-tools-commits] jlbec commits r494 - in trunk: clusterbo fsck.ocfs2 libo2cb libo2cb/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Dec 16 12:07:23 CST 2004


Author: jlbec
Date: 2004-12-16 12:07:21 -0600 (Thu, 16 Dec 2004)
New Revision: 494

Modified:
   trunk/clusterbo/Makefile
   trunk/clusterbo/clusterbo.c
   trunk/fsck.ocfs2/
   trunk/libo2cb/include/o2cb.h
   trunk/libo2cb/include/o2cb_abi.h
   trunk/libo2cb/include/ocfs2_tcp.h
   trunk/libo2cb/o2cb_abi.c
   trunk/libo2cb/o2cb_err.et.in
Log:

o Move the kernel<->user ABI of clusterbo to libo2cb.



Modified: trunk/clusterbo/Makefile
===================================================================
--- trunk/clusterbo/Makefile	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/clusterbo/Makefile	2004-12-16 18:07:21 UTC (rev 494)
@@ -21,7 +21,7 @@
 CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
            -Wmissing-declarations
 
-DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+DEFINES = -DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
 
 CLUSTERBO_CFILES = clusterbo.c
 CLUSTERBO_OBJS = $(subst .c,.o,$(CLUSTERBO_CFILES))
@@ -38,8 +38,8 @@
 DIST_FILES = $(CFILES) $(HEADERS)
 DIST_RULES = dist-subdircreate
 
-clusterbo: $(CLUSTERBO_OBJS) $(LIBOCFS2_DEPS)
-	$(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
+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

Modified: trunk/clusterbo/clusterbo.c
===================================================================
--- trunk/clusterbo/clusterbo.c	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/clusterbo/clusterbo.c	2004-12-16 18:07:21 UTC (rev 494)
@@ -15,11 +15,8 @@
 #include <errno.h>
 #include <sys/ioctl.h>
 
-#define __u8 unsigned char 
-#define u8 unsigned char 
-#define u16 unsigned short int
-#define u32 unsigned int       
-#define u64 unsigned long long
+#include "o2cb.h"
+
 #define atomic_t int
 #define spinlock_t unsigned long
 typedef unsigned short kdev_t;
@@ -28,8 +25,6 @@
         struct list_head *next, *prev;
 } list_t;
 
-#include "ocfs2_nodemanager.h"
-
 #define NIPQUAD(addr) \
         ((unsigned char *)&addr)[0], \
         ((unsigned char *)&addr)[1], \
@@ -37,35 +32,17 @@
         ((unsigned char *)&addr)[3]
 
 
-#define CLUSTER_FILE   "/proc/cluster/nm/.cluster"
-#define GROUP_FILE     "/proc/cluster/nm/.group"
-#define NODE_FILE      "/proc/cluster/nm/.node"
-
 #define CONF_FILE   "/etc/cluster.conf"
 
 /* are these right ? */
 #define MIN_PORT_NUM   1024
 #define MAX_PORT_NUM   65535
 
-#define  NET_IOC_MAGIC          'O'
-#define  NET_IOC_ACTIVATE       _IOR(NET_IOC_MAGIC, 1, net_ioc)
-#define  NET_IOC_GETSTATE       _IOR(NET_IOC_MAGIC, 2, net_ioc)
-
-
-typedef struct _net_ioc
-{
-	unsigned int status;
-} net_ioc;
-
 #define OCFS2_NM_MODULE  "ocfs2_nodemanager"
 #define OCFS2_HB_MODULE  "ocfs2_heartbeat"
 #define OCFS2_TCP_MODULE "ocfs2_tcp"
 
 
-int activate_cluster(void);
-int add_node(nm_node_info *newnode);
-int set_cluster_name(char *cluster_name);
-int activate_net(void);
 int load_module(char *module, char *mountpoint, char *fstype);
 
 
@@ -118,7 +95,7 @@
 		int node_num, port;
 		char *node_name = NULL;
 		char *ip = NULL;
-		u32 real_ip;
+		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) {
@@ -160,7 +137,7 @@
 	}
 	fclose(conf);
 	
-	set_cluster_name(cluster_name);
+	ret = o2cb_set_cluster_name(cluster_name);
 	i=0;
 	while (1) {
 		if (!total_nodes--)
@@ -169,167 +146,18 @@
 			i++;
 			continue;
 		}
-		add_node(&nodes[i]);
+		ret = o2cb_add_node(&nodes[i]);
 		i++;
 	}
 	printf("done.  activating cluster now...\n");
-	activate_cluster();
+	ret = o2cb_activate_cluster();
 	printf("done.  nm ready!\n");
-	activate_net();
+	ret = o2cb_activate_networking();
 	printf("done.  net ready!\n");
 	free(nodes);
 	return 0;
 }
 
-int set_cluster_name(char *cluster_name)
-{
-	int fd;
-	nm_op *op;
-	int ret;
-	char *buf;
-	
-	buf = malloc(4096);
-	op = (nm_op *)buf;
-	memset(buf, 0, 4096);
-	op->magic = NM_OP_MAGIC;
-
-	printf("setting cluster name...\n");
-	fd = open(CLUSTER_FILE, O_RDWR);
-	if (fd == -1) {
-		printf("failed to open %s\n", CLUSTER_FILE);
-		exit(1);
-	}
-	op->opcode = NM_OP_NAME_CLUSTER;
-	strcpy(&op->arg_u.name[0], cluster_name);
-
-	ret = write(fd, op, sizeof(nm_op));
-	printf("write called returned %d\n", ret);
-	if (ret < 0) {
-		printf("error is: %s\n", strerror(errno));
-		exit(1);
-	}
-	memset(buf, 0, 4096);
-	ret = read(fd, buf, 4096);
-	printf("read returned %d\n", ret);
-	if (ret < 0)
-		exit(1);
-	printf("<<<<%*s>>>>\n", ret, buf);
-	close(fd);
-	free(buf);
-	return 0;
-
-}
-
-int add_node(nm_node_info *newnode)
-{
-	int fd;
-	nm_op *op;
-	int ret;
-	char *buf;
-	nm_node_info *node;
-	
-	buf = malloc(4096);
-	op = (nm_op *)buf;
-	memset(buf, 0, 4096);
-	op->magic = NM_OP_MAGIC;
-
-
-	printf("adding cluster node....\n");
-	fd = open(CLUSTER_FILE, O_RDWR);
-	if (fd == -1) {
-		printf("failed to open %s\n", CLUSTER_FILE);
-		exit(1);
-	}
-	op->opcode = NM_OP_ADD_CLUSTER_NODE;
-	node = &(op->arg_u.node);
-	memcpy(node, newnode, sizeof(nm_node_info));
-	printf("passing port=%u, vers=%u, addr=%d.%d.%d.%d\n",
-	       node->ifaces[0].ip_port,
-	       node->ifaces[0].ip_version,
-	       NIPQUAD(node->ifaces[0].addr_u.ip_addr4));
-
-	ret = write(fd, op, sizeof(nm_op));
-	printf("write called returned %d\n", ret);
-	if (ret < 0) {
-		printf("error is: %s\n", strerror(errno));
-		exit(1);
-	}
-	memset(buf, 0, 4096);
-	ret = read(fd, buf, 4096);
-	printf("read returned %d\n", ret);
-	if (ret < 0)
-		exit(1);
-	printf("<<<<%*s>>>>\n", ret, buf);
-	close(fd);
-
-	free(buf);
-	return 0;
-
-}
-
-int activate_cluster(void)
-{
-	int fd;
-	nm_op *op;
-	int ret;
-	char *buf;
-	
-	buf = malloc(4096);
-	op = (nm_op *)buf;
-	memset(buf, 0, 4096);
-	op->magic = NM_OP_MAGIC;
-
-	printf("activating cluster....\n");
-	fd = open(CLUSTER_FILE, O_RDWR);
-	if (fd == -1) {
-		printf("failed to open %s\n", CLUSTER_FILE);
-		exit(1);
-	}
-	op->opcode = NM_OP_CREATE_CLUSTER;
-
-	ret = write(fd, op, sizeof(nm_op));
-	printf("write called returned %d\n", ret);
-	if (ret < 0) {
-		printf("error is: %s\n", strerror(errno));
-		exit(1);
-	}
-	memset(buf, 0, 4096);
-	ret = read(fd, buf, 4096);
-	printf("read returned %d\n", ret);
-	if (ret < 0)
-		exit(1);
-	printf("<<<<%*s>>>>\n", ret, buf);
-	close(fd);
-
-	free(buf);
-	return 0;
-
-}
-
-
-int activate_net(void)
-{
-	int fd;
-	net_ioc net;
-
-	memset(&net, 0, sizeof(net_ioc));
-	fd = open("/proc/cluster/net", O_RDONLY);
-	if (fd == -1) {
-		printf("eeek.  failed to open\n");
-		exit(1);
-	}
-	
-	if (ioctl(fd, NET_IOC_ACTIVATE, &net) == -1) {
-		printf("eeek.  ioctl failed\n");
-		close(fd);
-		exit(1);
-	}
-	close(fd);
-	printf("ioctl returned: %u\n", net.status);
-	return 0;
-}
-
-
 int load_module(char *module, char *mountpoint, char *fstype)
 {
 	int ret;


Property changes on: trunk/fsck.ocfs2
___________________________________________________________________
Name: svn:ignore
   - cscope*
stamp-md5
.*.sw?
.*.cmd
fsck.ocfs2
*.8
*.d

   + cscope*
stamp-md5
.*.sw?
.*.cmd
fsck.ocfs2
*.8
*.d
prompt-codes.h


Modified: trunk/libo2cb/include/o2cb.h
===================================================================
--- trunk/libo2cb/include/o2cb.h	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/libo2cb/include/o2cb.h	2004-12-16 18:07:21 UTC (rev 494)
@@ -55,4 +55,9 @@
 #include <o2cb/ocfs2_tcp.h>
 #endif
 
+errcode_t o2cb_set_cluster_name(const char *cluster_name);
+errcode_t o2cb_add_node(nm_node_info *node);
+errcode_t o2cb_activate_cluster(void);
+errcode_t o2cb_activate_networking(void);
+
 #endif  /* _O2CB_H */

Modified: trunk/libo2cb/include/o2cb_abi.h
===================================================================
--- trunk/libo2cb/include/o2cb_abi.h	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/libo2cb/include/o2cb_abi.h	2004-12-16 18:07:21 UTC (rev 494)
@@ -29,7 +29,6 @@
 #define O2CB_CLUSTER_FILE 	"/proc/cluster/nm/.cluster"
 #define O2CB_GROUP_FILE		"/proc/cluster/nm/.group"
 #define O2CB_NODE_FILE		"/proc/cluster/nm/.node"
+#define O2CB_NETWORKING_FILE	"/proc/cluster/net"
 
-int o2cb_set_cluster_name(const char *cluster_name);
-
 #endif  /* _O2CB_ABI_H */

Modified: trunk/libo2cb/include/ocfs2_tcp.h
===================================================================
--- trunk/libo2cb/include/ocfs2_tcp.h	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/libo2cb/include/ocfs2_tcp.h	2004-12-16 18:07:21 UTC (rev 494)
@@ -28,10 +28,6 @@
 
 #ifndef DLMNET_H
 #define DLMNET_H
-#include <linux/socket.h>
-#include <sys/socket.h>
-#include <linux/inet.h>
-#include <linux/in.h>
 
 typedef struct _gsd_ioc
 {
@@ -41,6 +37,11 @@
 	int status;
 } gsd_ioc;
 
+typedef struct _net_ioc
+{
+	__u32 status;
+} net_ioc;
+
 #define  NET_IOC_MAGIC          'O'
 #define  NET_IOC_ACTIVATE       _IOR(NET_IOC_MAGIC, 1, net_ioc)
 #define  NET_IOC_GETSTATE       _IOR(NET_IOC_MAGIC, 2, net_ioc)

Modified: trunk/libo2cb/o2cb_abi.c
===================================================================
--- trunk/libo2cb/o2cb_abi.c	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/libo2cb/o2cb_abi.c	2004-12-16 18:07:21 UTC (rev 494)
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
@@ -40,8 +41,9 @@
 
 #include "o2cb_abi.h"
 
-int o2cb_set_cluster_name(const char *cluster_name)
+errcode_t o2cb_set_cluster_name(const char *cluster_name)
 {
+	errcode_t ret;
 	int fd, rc, page_size = getpagesize();
 	char *buf;
 	nm_op *op;
@@ -51,45 +53,173 @@
 
 	buf = malloc(sizeof(char*) * page_size);
 	if (!buf)
-		return -errno;
+		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);
-	if (fd < 0) {
-		rc = -errno;
+	if (fd < 0)
 		goto out;
-	}
 
 	rc = write(fd, op, sizeof(nm_op));
-	if (rc < 0) {
-		rc = -errno;
+	if (rc < 0)
 		goto out_close;
-	} else if (rc < sizeof(nm_op)) {
-		/* FIXME: What to do here? */
-	}
+	ret = O2CB_ET_IO;
+	if (rc < sizeof(nm_op))
+		goto out_close;
 
 	memset(buf, 0, page_size);
+
 	rc = read(fd, buf, page_size);
-	if (rc < 0) {
-		rc = -errno;
+	if (rc < 0)
 		goto out_close;
-	} else if (!rc) {
-		/* FIXME: What to do here? */
-	} else {
-		if (buf[0] == '\0')
-			rc = 0;
-		/* FIXME: genericize, make better, etc */
-	}
 
+	ret = O2CB_ET_SERVICE_UNAVAILABLE;
+	if (!rc)
+		goto out_close;
+
+	ret = O2CB_ET_IO;  /* FIXME */
+	if (buf[0] == '0')
+		ret = 0;
+
 out_close:
 	close(fd);
 out:
 	free(buf);
 
-	return rc;
+	return ret;
 }  /* o2cb_set_cluster_name() */
 
+
+errcode_t o2cb_add_node(nm_node_info *node)
+{
+	errcode_t ret;
+	int fd, rc, page_size = getpagesize();
+	char *buf;
+	nm_op *op;
+
+	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_ADD_CLUSTER_NODE;
+	memcpy(&(op->arg_u.node), node, sizeof(nm_node_info));
+
+	ret = O2CB_ET_SERVICE_UNAVAILABLE;
+	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
+	if (fd < 0)
+		goto out;
+
+	rc = write(fd, op, sizeof(nm_op));
+	if (rc < 0)
+		goto out_close;
+	ret = O2CB_ET_IO;
+	if (rc < sizeof(nm_op))
+		goto out_close;
+
+	memset(buf, 0, page_size);
+
+	rc = read(fd, buf, page_size);
+	if (rc < 0)
+		goto out_close;
+
+	ret = O2CB_ET_SERVICE_UNAVAILABLE;
+	if (!rc)
+		goto out_close;
+
+	ret = O2CB_ET_IO;  /* FIXME */
+	if (buf[0] == '0')
+		ret = 0;
+
+out_close:
+	close(fd);
+out:
+	free(buf);
+
+	return ret;
+}  /* o2cb_add_node() */
+
+errcode_t o2cb_activate_cluster()
+{
+	errcode_t ret;
+	int fd, rc, page_size = getpagesize();
+	char *buf;
+	nm_op *op;
+
+	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_CREATE_CLUSTER;
+
+	ret = O2CB_ET_SERVICE_UNAVAILABLE;
+	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
+	if (fd < 0)
+		goto out;
+
+	rc = write(fd, op, sizeof(nm_op));
+	if (rc < 0)
+		goto out_close;
+
+	ret = O2CB_ET_IO;
+	if (rc < sizeof(nm_op))
+		goto out_close;
+
+	memset(buf, 0, page_size);
+
+	rc = read(fd, buf, page_size);
+	if (rc < 0)
+		goto out_close;
+
+	ret = O2CB_ET_SERVICE_UNAVAILABLE;
+	if (!rc)
+		goto out_close;
+
+	ret = O2CB_ET_IO;  /* FIXME */
+	if (buf[0] == '0')
+		ret = 0;
+
+out_close:
+	close(fd);
+out:
+	free(buf);
+
+	return ret;
+}  /* o2cb_activate_cluster() */
+
+/* FIXME: does this really belong here? */
+errcode_t o2cb_activate_networking()
+{
+	errcode_t ret;
+	int fd;
+	net_ioc net;
+
+	memset(&net, 0, sizeof(net_ioc));
+	fd = open(O2CB_NETWORKING_FILE, O_RDONLY);
+	if (fd < 0)
+		return O2CB_ET_SERVICE_UNAVAILABLE;
+
+	ret = 0;
+	if (ioctl(fd, NET_IOC_ACTIVATE, &net)) {
+		switch (errno) {
+			default:
+				ret = O2CB_ET_INTERNAL_FAILURE;
+				break;
+
+			case ENOTTY:
+				ret = O2CB_ET_SERVICE_UNAVAILABLE;
+				break;
+		}
+	}
+
+	close(fd);
+	return ret;
+}  /* o2cb_activate_networking() */

Modified: trunk/libo2cb/o2cb_err.et.in
===================================================================
--- trunk/libo2cb/o2cb_err.et.in	2004-12-15 01:22:14 UTC (rev 493)
+++ trunk/libo2cb/o2cb_err.et.in	2004-12-16 18:07:21 UTC (rev 494)
@@ -27,4 +27,16 @@
 ec	O2CB_ET_INVALID_CLUSTER_NAME,
 	"Invalid name for a cluster"
 
+ec	O2CB_ET_NO_MEMORY,
+	"Memory allocation failed"
+
+ec	O2CB_ET_IO,
+	"I/O error on channel"
+
+ec	O2CB_ET_SERVICE_UNAVAILABLE,
+	"Unable to access cluster service"
+
+ec	O2CB_ET_INTERNAL_FAILURE,
+	"Internal logic failure"
+
 	end



More information about the Ocfs2-tools-commits mailing list