[Ocfs2-tools-commits] jlbec commits r645 - in branches/usysfsify: clusterbo libo2cb libo2cb/include vendor/common

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Mar 15 23:37:34 CST 2005


Author: jlbec
Date: 2005-03-15 23:37:32 -0600 (Tue, 15 Mar 2005)
New Revision: 645

Removed:
   branches/usysfsify/libo2cb/include/ocfs2_heartbeat.h
   branches/usysfsify/libo2cb/include/ocfs2_nodemanager.h
   branches/usysfsify/libo2cb/include/ocfs2_tcp.h
Modified:
   branches/usysfsify/clusterbo/o2cb_config.c
   branches/usysfsify/clusterbo/o2cb_ctl.c
   branches/usysfsify/libo2cb/include/o2cb.h
   branches/usysfsify/libo2cb/include/o2cb_abi.h
   branches/usysfsify/libo2cb/o2cb_abi.c
   branches/usysfsify/libo2cb/o2cb_err.et.in
   branches/usysfsify/vendor/common/o2cb.init
Log:

o Make libo2cb and o2cb_ctl happy with usysfsiness



Modified: branches/usysfsify/clusterbo/o2cb_config.c
===================================================================
--- branches/usysfsify/clusterbo/o2cb_config.c	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/clusterbo/o2cb_config.c	2005-03-16 05:37:32 UTC (rev 645)
@@ -96,7 +96,7 @@
     if (!ptr || *ptr)
         goto out_error;
     rc = -ERANGE;
-    if ((val == ULONG_MAX) || (val >= NM_MAX_NODES))
+    if ((val == ULONG_MAX) || (val >= INT_MAX))
         goto out_error;
     node->n_number = val;
 

Modified: branches/usysfsify/clusterbo/o2cb_ctl.c
===================================================================
--- branches/usysfsify/clusterbo/o2cb_ctl.c	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/clusterbo/o2cb_ctl.c	2005-03-16 05:37:32 UTC (rev 645)
@@ -62,7 +62,6 @@
 {
     O2CBOperation oc_op;
     O2CBType oc_type;
-    gchar *oc_manager;
     GList *oc_objects;
     GList *oc_attrs;
     gboolean oc_compact_info;
@@ -89,10 +88,10 @@
     FILE *output = rc ? stderr : stdout;
 
     fprintf(output,
-            "Usage: " PROGNAME " -C -l <manager> -n <object> -t <type> [-i] [-a <attribute> ] ...\n"
-            "       " PROGNAME " -D -l <manager> -n <object> [-u]\n"
-            "       " PROGNAME " -I [-o|-z] -l <manager> [-n <object>] [-t <type>] [-a <attribute>] ...\n"
-            "       " PROGNAME " -H -l <manager> [-n <object>] [-t <type>] [-a <attribute>] ...\n"
+            "Usage: " PROGNAME " -C -n <object> -t <type> [-i] [-a <attribute> ] ...\n"
+            "       " PROGNAME " -D -n <object> [-u]\n"
+            "       " PROGNAME " -I [-o|-z] [-n <object>] [-t <type>] [-a <attribute>] ...\n"
+            "       " PROGNAME " -H [-n <object>] [-t <type>] [-a <attribute>] ...\n"
             "       " PROGNAME " -h\n"
             "       " PROGNAME " -V\n");
 
@@ -302,7 +301,7 @@
 
     mi = mu = mo = mz = FALSE;
     opterr = 0;
-    while ((c = getopt(argc, argv, ":hVCDIHiuozl:n:t:a:-:")) != EOF)
+    while ((c = getopt(argc, argv, ":hVCDIHiuozn:t:a:-:")) != EOF)
     {
         switch (c)
         {
@@ -367,15 +366,6 @@
                 mo = TRUE;
                 break;
 
-            case 'l':
-                if (!optarg || !*optarg)
-                {
-                    fprintf(stderr, PROGNAME ": Argument to \'-l\' cannot be \"\"\n");
-                    return -EINVAL;
-                }
-                ctxt->oc_manager = g_strdup(optarg);
-                break;
-
             case 'n':
                 if (!optarg || !*optarg)
                 {
@@ -447,12 +437,6 @@
         return -E2BIG;
     }
 
-    if (!ctxt->oc_manager)
-    {
-        fprintf(stderr, PROGNAME ": You must specify a manager device\n");
-        return -EINVAL;
-    }
-
     if (mu && (ctxt->oc_op != O2CB_OP_DELETE))
         c = 'u';
     else if (mi && (ctxt->oc_op != O2CB_OP_CREATE))
@@ -588,18 +572,29 @@
 {
     errcode_t ret;
     gint rc;
-    gchar *name, *node_name;
+    gchar *name, *node_name, *node_num, *ip_address, *ip_port;
     JIterator *iter;
-    GList *list = NULL, *l;
     O2CBNode *node;
-    nm_node_info *node_i;
-    struct in_addr addr;
 
     rc = -ENOMEM;
     name = o2cb_config_get_cluster_name(ctxt->oc_config);
     if (!name)
         goto out_error;
 
+    rc = -EIO;
+    ret = o2cb_create_cluster(name);
+    if (ret)
+    {
+        if (ret != O2CB_ET_CLUSTER_EXISTS)
+        {
+            com_err(PROGNAME, ret, "while setting cluster name");
+            goto out_error;
+        }
+    }
+    else
+        fprintf(stdout, "Cluster %s created\n", name);
+
+    rc = -ENOMEM;
     iter = o2cb_config_get_nodes(ctxt->oc_config);
     if (!iter)
         goto out_error;
@@ -608,65 +603,38 @@
     while (j_iterator_has_more(iter))
     {
         node = (O2CBNode *)j_iterator_get_next(iter);
-        rc = -ENOMEM;
-        node_i = g_new0(nm_node_info, 1);
-        if (!node_i)
-            break;
-        list = g_list_append(list, node_i);
-        node_i->node_num = o2cb_node_get_number(node);
+        node_num = g_strdup_printf("%d", o2cb_node_get_number(node));
         node_name = o2cb_node_get_name(node);
-        if (!node_name)
-            break;
-        /* Ignore truncation */
-        g_strlcpy(node_i->node_name, node_name, NM_MAX_NAME_LEN);
+        ip_port = g_strdup_printf("%d", o2cb_node_get_port(node));
+        ip_address = o2cb_node_get_ip_string(node);
+
+        ret = o2cb_add_node(name, node_name, node_num, ip_address,
+                            ip_port);
+        if (ret)
+        {
+            if (ret != O2CB_ET_CLUSTER_EXISTS)
+            {
+                com_err(PROGNAME, ret, "while adding node %s\n",
+                        node_name);
+                rc = -EIO;
+            }
+
+            ret = 0;
+        }
+        else
+            fprintf(stdout, "Node %s added\n", node_name);
+
+        g_free(node_num);
         g_free(node_name);
-        node_i->ifaces[0].ip_port = htons(o2cb_node_get_port(node));
-        rc = o2cb_node_get_ipv4(node, &addr);
+        g_free(ip_port);
+        g_free(ip_address);
         if (rc)
             break;
-        node_i->ifaces[0].addr_u.ip_addr4 = addr.s_addr;
-        rc = 0;
     }
     j_iterator_free(iter);
-    if (rc)
-        goto out_error;
 
-    rc = -EIO;
-    ret = o2cb_set_cluster_name(name);
-    if (ret)
-    {
-        com_err(PROGNAME, ret, "while setting cluster name");
-        goto out_error;
-    }
-
-    l = list;
-    while (l)
-    {
-        node_i = (nm_node_info *)l->data;
-        rc = o2cb_add_node(node_i);
-        if (rc)
-            goto out_error;
-        l = l->next;
-    }
-
-    rc = o2cb_activate_cluster();
-    if (rc)
-        goto out_error;
-    rc = o2cb_activate_networking();
-    if (rc)
-        goto out_error;
-
 out_error:
-    g_free(name);
 
-    while (list)
-    {
-        node_i = (nm_node_info *)list->data;
-        list = g_list_delete_link(list, list);
-
-        g_free(node_i);
-    }
-
     return rc;
 }  /* online_cluster() */
 

Modified: branches/usysfsify/libo2cb/include/o2cb.h
===================================================================
--- branches/usysfsify/libo2cb/include/o2cb.h	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/include/o2cb.h	2005-03-16 05:37:32 UTC (rev 645)
@@ -43,21 +43,14 @@
 
 #if O2CB_FLAT_INCLUDES
 #include "o2cb_err.h"
-
-#include "ocfs2_heartbeat.h"
-#include "ocfs2_nodemanager.h"
-#include "ocfs2_tcp.h"
 #else
 #include <o2cb/o2cb_err.h>
-
-#include <o2cb/ocfs2_heartbeat.h>
-#include <o2cb/ocfs2_nodemanager.h>
-#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_create_cluster(const char *cluster_name);
+errcode_t o2cb_add_node(const char *cluster_name,
+			const char *node_name, const char *node_num,
+			const char *ip_address, const char *ip_port);
 errcode_t o2cb_activate_networking(void);
 
 #endif  /* _O2CB_H */

Modified: branches/usysfsify/libo2cb/include/o2cb_abi.h
===================================================================
--- branches/usysfsify/libo2cb/include/o2cb_abi.h	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/include/o2cb_abi.h	2005-03-16 05:37:32 UTC (rev 645)
@@ -3,9 +3,9 @@
  *
  * o2cb_abi.c
  *
- * Kernel<->User ABI for modifying cluster configuration.
+ * Layout of usysfs paths for O2CB cluster configuration.
  *
- * Copyright (C) 2004 Oracle.  All rights reserved.
+ * Copyright (C) 2005 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
@@ -25,10 +25,13 @@
 #ifndef _O2CB_ABI_H
 #define _O2CB_ABI_H
 
-/* Hardcoded paths to the cluster virtual files */
-#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"
+#define USYSFS_PATH "/usys"
 
+#define O2CB_FORMAT_CLUSTER_DIR		USYSFS_PATH "/cluster"
+#define O2CB_FORMAT_CLUSTER		O2CB_FORMAT_CLUSTER_DIR "/%s"
+#define O2CB_FORMAT_NODE_DIR		O2CB_FORMAT_CLUSTER "/nodes"
+#define O2CB_FORMAT_NODE		O2CB_FORMAT_NODE_DIR "/%s"
+#define O2CB_FORMAT_NODE_ATTR		O2CB_FORMAT_NODE "/%s"
+#define O2CB_FORMAT_HEARTBEAT_DIR	O2CB_FORMAT_CLUSTER "/heartbeat"
+
 #endif  /* _O2CB_ABI_H */

Deleted: branches/usysfsify/libo2cb/include/ocfs2_heartbeat.h
===================================================================
--- branches/usysfsify/libo2cb/include/ocfs2_heartbeat.h	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/include/ocfs2_heartbeat.h	2005-03-16 05:37:32 UTC (rev 645)
@@ -1,55 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; -*-
- * vim: noexpandtab sw=8 ts=8 sts=0:
- *
- * ocfs2_heartbeat.h
- *
- * Copyright (C) 2002, 2004 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 as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- * 
- * 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.
- * 
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#ifndef _OCFS2_HEARTBEAT_H
-#define _OCFS2_HEARTBEAT_H
-
-#define CLUSTER_DISK_UUID_LEN      32      // 16 byte binary == 32 char hex string
-
-
-#define HB_OP_MAGIC      0xf00d
-enum {
-	HB_OP_START_DISK_HEARTBEAT=371,
-	HB_OP_GET_NODE_MAP
-};
-
-typedef struct _hb_op
-{
-	__u16 magic;
-	__u16 opcode;
-	__u32 fd;
-	char disk_uuid[CLUSTER_DISK_UUID_LEN+1];
-	char pad1[15];  /* Pad to the __u16 following it */
-	__u8  group_num;
-	__u8  pad2;
-	__u32 bits;
-	__u32 blocks;
-	__u64 start;
-} hb_op;
-
-typedef struct _hb_disk_heartbeat_block
-{
-	__u64 time;
-} hb_disk_heartbeat_block;
-
-#endif /* _OCFS2_HEARTBEAT_H */

Deleted: branches/usysfsify/libo2cb/include/ocfs2_nodemanager.h
===================================================================
--- branches/usysfsify/libo2cb/include/ocfs2_nodemanager.h	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/include/ocfs2_nodemanager.h	2005-03-16 05:37:32 UTC (rev 645)
@@ -1,106 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; -*-
- * vim: noexpandtab sw=8 ts=8 sts=0:
- *
- * ocfs2_nodemanager.h
- *
- * Copyright (C) 2002, 2004 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 as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- * 
- * 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.
- * 
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- *
- * Authors: Kurt Hackel, Mark Fasheh, Sunil Mushran, Wim Coekaerts,
- *	    Manish Singh, Neeraj Goyal, Suchit Kaura
- */
-
-#ifndef _OCFS2_NODEMANAGER_H
-#define _OCFS2_NODEMANAGER_H
-
-#include "ocfs2_heartbeat.h"
-
-#define NM_MAX_IFACES            2
-#define NM_MAX_NODES             255
-#define NM_INVALID_SLOT_NUM      255
-
-/* host name, group name, cluster name all 64 bytes */
-#define NM_MAX_NAME_LEN          64    // __NEW_UTS_LEN
-
-
-#define NM_GROUP_INODE_START    200000
-#define NM_NODE_INODE_START     100000
-
-
-
-typedef struct _nm_network_iface
-{
-	__u16 ip_port;			/* for simplicity, just define exactly one port for this if */
-	__u16 ip_version;
-	union {
-		__u32 ip_addr4;		/* IPv4 address in NBO */
-		__u32 ip_addr6[4];	/* IPv6 address in NBO */
-	} addr_u;
-} nm_network_iface;
-
-typedef struct _nm_node_info 
-{
-	__u8 node_num;
-	__u8 pad1;
-	__u16 pad2;
-	__u32 pad3;
-	char node_name[NM_MAX_NAME_LEN+1];
-	char pad4[63];
-	nm_network_iface ifaces[NM_MAX_IFACES];
-} nm_node_info;
-
-/* transaction file nm_op stuff */
-
-#define NM_OP_MAGIC      0xbeaf
-enum {
-	NM_OP_CREATE_CLUSTER=123,
-	NM_OP_DESTROY_CLUSTER,
-	NM_OP_NAME_CLUSTER,
-	NM_OP_ADD_CLUSTER_NODE,
-	NM_OP_GET_CLUSTER_NUM_NODES,
-	NM_OP_GET_NODE_INFO,
-	NM_OP_CREATE_GROUP,
-	NM_OP_GET_GROUP_INFO,
-	NM_OP_ADD_GROUP_NODE,
-	NM_OP_GET_GLOBAL_NODE_NUM
-};
-
-typedef struct _nm_group_change
-{
-	__u8 group_num;
-	__u8 node_num;
-	__u8 slot_num;
-	__u8 pad1;
-	__u32 pad2;
-	char disk_uuid[CLUSTER_DISK_UUID_LEN+1];
-	char name[NM_MAX_NAME_LEN+1];
-} nm_group_change;
-
-typedef struct _nm_op
-{
-	__u16 magic;
-	__u16 opcode;
-	__u32 pad1;
-	union {
-		__u8 index;
-		char name[NM_MAX_NAME_LEN+1];
-		nm_node_info node;
-		nm_group_change gc;
-	} arg_u;
-} nm_op;
-
-#endif /* _OCFS2_NODEMANAGER_H */

Deleted: branches/usysfsify/libo2cb/include/ocfs2_tcp.h
===================================================================
--- branches/usysfsify/libo2cb/include/ocfs2_tcp.h	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/include/ocfs2_tcp.h	2005-03-16 05:37:32 UTC (rev 645)
@@ -1,46 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; -*-
- * vim: noexpandtab sw=8 ts=8 sts=0:
- *
- * ocfs2_tcp.h
- *
- * Copyright (C) 2002, 2004 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 as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- * 
- * 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.
- * 
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#ifndef _OCFS2_TCP_H
-#define _OCFS2_TCP_H
-
-typedef struct _gsd_ioc
-{
-	int fd;
-	int namelen;
-	char name[NM_MAX_NAME_LEN+1];
-	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)
-#define  GSD_IOC_CREATE_GROUP   _IOR(NET_IOC_MAGIC, 3, gsd_ioc)
-#define  GSD_IOC_ADD_GROUP_NODE _IOR(NET_IOC_MAGIC, 4, gsd_ioc)
-
-#endif /* _OCFS2_TCP_H */

Modified: branches/usysfsify/libo2cb/o2cb_abi.c
===================================================================
--- branches/usysfsify/libo2cb/o2cb_abi.c	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/o2cb_abi.c	2005-03-16 05:37:32 UTC (rev 645)
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <limits.h>
 
 #include <linux/types.h>
 
@@ -41,185 +42,279 @@
 
 #include "o2cb_abi.h"
 
-errcode_t o2cb_set_cluster_name(const char *cluster_name)
+#define USYSFS_PREFIX "/usys"
+
+errcode_t o2cb_create_cluster(const char *cluster_name)
 {
-	errcode_t ret;
-	int fd, rc, page_size = getpagesize();
-	char *buf;
-	nm_op *op;
+	char path[PATH_MAX];
+	int ret;
+	errcode_t err = 0;
 
-	if (strlen(cluster_name) > NM_MAX_NAME_LEN)
-		return O2CB_ET_INVALID_CLUSTER_NAME;
+	ret = snprintf(path, PATH_MAX - 1, O2CB_FORMAT_CLUSTER,
+		       cluster_name);
+	if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+		return O2CB_ET_INTERNAL_FAILURE;
 
-	buf = malloc(sizeof(char*) * page_size);
-	if (!buf)
-		return O2CB_ET_NO_MEMORY;
+	ret = mkdir(path,
+		    S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+	if (ret) {
+		switch (errno) {
+			case EEXIST:
+				err = O2CB_ET_CLUSTER_EXISTS;
+				break;
 
-	op = (nm_op *)buf;
-	op->magic = NM_OP_MAGIC;
-	op->opcode = NM_OP_NAME_CLUSTER;
-	strcpy(op->arg_u.name, cluster_name);
+			case EACCES:
+			case EPERM:
+			case EROFS:
+				err = O2CB_ET_PERMISSION_DENIED;
+				break;
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
-	if (fd < 0)
-		goto out;
+			case ENOMEM:
+				err = O2CB_ET_NO_MEMORY;
+				break;
 
-	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;
+			case ENOTDIR:
+			case ENOENT:
+				err = O2CB_ET_SERVICE_UNAVAILABLE;
+				break;
 
-	memset(buf, 0, page_size);
+			default:
+				err = O2CB_ET_INTERNAL_FAILURE;
+				break;
+		}
+	}
 
-	rc = read(fd, buf, page_size);
-	if (rc < 0)
-		goto out_close;
+	return err;
+}
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	if (!rc)
-		goto out_close;
 
-	ret = O2CB_ET_IO;  /* FIXME */
-	if (buf[0] == '0')
-		ret = 0;
+static errcode_t write_thingy(const char *path, void *bytes, size_t len)
+{
+	int fd = -1;
+	errcode_t err = O2CB_ET_INTERNAL_FAILURE;
+	ssize_t ret;
 
-out_close:
-	close(fd);
-out:
-	free(buf);
+	fd = open(path, O_WRONLY);
+	if (fd < 0)
+		goto out;
 
-	return ret;
-}  /* o2cb_set_cluster_name() */
+	ret = write(fd, bytes, len);
+	if (ret != len)
+		goto out;
 
+	err = 0;
 
-errcode_t o2cb_add_node(nm_node_info *node)
+out:
+	if (fd >= 0)
+		close(fd);
+	return err;
+}
+
+static int do_read(int fd, void *bytes, size_t count)
 {
-	errcode_t ret;
-	int fd, rc, page_size = getpagesize();
-	char *buf;
-	nm_op *op;
+	int total = 0;
+	int ret;
 
-	buf = malloc(sizeof(char*) * page_size);
-	if (!buf)
-		return O2CB_ET_NO_MEMORY;
+	while (total < count) {
+		ret = read(fd, bytes + total, count - total);
+		if (ret < 0) {
+			ret = -errno;
+			if ((ret == -EAGAIN) || (ret == -EINTR))
+				continue;
+			total = ret;
+			break;
+		}
+		if (ret == 0)
+			break;
+		total += ret;
+	}
 
-	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));
+	return total;
+}
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
-	if (fd < 0)
-		goto out;
+static errcode_t do_write(int fd, const void *bytes, size_t count)
+{
+	int total = 0;
+	int ret;
+	int err = 0;
 
-	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;
+	while (total < count) {
+		ret = write(fd, bytes + total, count - total);
+		if (ret < 0) {
+			ret = -errno;
+			if ((ret == -EAGAIN) || (ret == -EINTR))
+				continue;
+			if (ret == -EIO)
+				err = O2CB_ET_IO;
+			else
+				err = O2CB_ET_INTERNAL_FAILURE;
+			break;
+		}
 
-	memset(buf, 0, page_size);
+		total += ret;
+	}
 
-	rc = read(fd, buf, page_size);
-	if (rc < 0)
-		goto out_close;
+	return err;
+}
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	if (!rc)
-		goto out_close;
+static errcode_t o2cb_set_node_attribute(const char *cluster_name,
+					 const char *node_name,
+					 const char *attr_name,
+					 const char *attr_value)
+{
+	int ret;
+	errcode_t err = 0;
+	char attr_path[PATH_MAX];
+	int fd;
 
-	ret = O2CB_ET_IO;  /* FIXME */
-	if (buf[0] == '0')
-		ret = 0;
+	ret = snprintf(attr_path, PATH_MAX - 1, O2CB_FORMAT_NODE_ATTR,
+		       cluster_name, node_name, attr_name);
+	if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+		return O2CB_ET_INTERNAL_FAILURE;
 
-out_close:
-	close(fd);
-out:
-	free(buf);
+	fd = open(attr_path, O_WRONLY);
+	if (fd < 0) {
+		switch (errno) {
+			default:
+				err = O2CB_ET_INTERNAL_FAILURE;
+				break;
 
-	return ret;
-}  /* o2cb_add_node() */
+			case ENOTDIR:
+			case ENOENT:
+			case EISDIR:
+				err = O2CB_ET_SERVICE_UNAVAILABLE;
+				break;
 
-errcode_t o2cb_activate_cluster()
-{
-	errcode_t ret;
-	int fd, rc, page_size = getpagesize();
-	char *buf;
-	nm_op *op;
+			case EACCES:
+			case EPERM:
+			case EROFS:
+				err = O2CB_ET_PERMISSION_DENIED;
+				break;
+		}
+	} else {
+		err = do_write(fd, attr_value, strlen(attr_value));
+		close(fd);
+	}
 
-	buf = malloc(sizeof(char*) * page_size);
-	if (!buf)
-		return O2CB_ET_NO_MEMORY;
+	return err;
+}
 
-	op = (nm_op *)buf;
-	op->magic = NM_OP_MAGIC;
-	op->opcode = NM_OP_CREATE_CLUSTER;
+static errcode_t o2cb_get_node_attribute(const char *cluster_name,
+					 const char *node_name,
+					 const char *attr_name,
+					 char *attr_value,
+					 size_t count)
+{
+	int ret;
+	errcode_t err = 0;
+	char attr_path[PATH_MAX];
+	int fd;
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
-	if (fd < 0)
-		goto out;
+	ret = snprintf(attr_path, PATH_MAX - 1, O2CB_FORMAT_NODE_ATTR,
+		       cluster_name, node_name, attr_name);
+	if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+		return O2CB_ET_INTERNAL_FAILURE;
 
-	rc = write(fd, op, sizeof(nm_op));
-	if (rc < 0)
-		goto out_close;
+	fd = open(attr_path, O_RDONLY);
+	if (fd < 0) {
+		switch (errno) {
+			default:
+				err = O2CB_ET_INTERNAL_FAILURE;
+				break;
 
-	ret = O2CB_ET_IO;
-	if (rc < sizeof(nm_op))
-		goto out_close;
+			case ENOTDIR:
+			case ENOENT:
+			case EISDIR:
+				err = O2CB_ET_SERVICE_UNAVAILABLE;
+				break;
 
-	memset(buf, 0, page_size);
+			case EACCES:
+			case EPERM:
+			case EROFS:
+				err = O2CB_ET_PERMISSION_DENIED;
+				break;
+		}
+	} else {
+		ret = do_read(fd, attr_value, count);
+		close(fd);
+		if (ret == -EIO)
+			err = O2CB_ET_IO;
+		else if (ret < 0)
+			err = O2CB_ET_INTERNAL_FAILURE;
+		else if (ret < count)
+			attr_value[ret] = '\0';
+	}
 
-	rc = read(fd, buf, page_size);
-	if (rc < 0)
-		goto out_close;
+	return err;
+}
 
-	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	if (!rc)
-		goto out_close;
+/* XXX there is no commit yet, so this just creates the node in place
+ * and then sets the attributes in order.  if the ipaddr is set
+ * successfully then the node is live */
+errcode_t o2cb_add_node(const char *cluster_name,
+			const char *node_name, const char *node_num,
+			const char *ip_address, const char *ip_port)
+{
+	char node_path[PATH_MAX];
+	int ret;
+	errcode_t err;
 
-	ret = O2CB_ET_IO;  /* FIXME */
-	if (buf[0] == '0')
-		ret = 0;
+	ret = snprintf(node_path, PATH_MAX - 1,
+		       O2CB_FORMAT_NODE,
+		       cluster_name, node_name);
+	if (ret <= 0 || ret == PATH_MAX - 1) {
+		err = O2CB_ET_INTERNAL_FAILURE;
+		goto out;
+	}
 
-out_close:
-	close(fd);
-out:
-	free(buf);
+	ret = mkdir(node_path,
+		    S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+	if (ret) {
+		switch (errno) {
+			case EEXIST:
+				err = O2CB_ET_NODE_EXISTS;
+				break;
 
-	return ret;
-}  /* o2cb_activate_cluster() */
+			case EACCES:
+			case EPERM:
+			case EROFS:
+				err = O2CB_ET_PERMISSION_DENIED;
+				break;
 
-/* FIXME: does this really belong here? */
-errcode_t o2cb_activate_networking()
-{
-	errcode_t ret;
-	int fd;
-	net_ioc net;
+			case ENOMEM:
+				err = O2CB_ET_NO_MEMORY;
+				break;
 
-	memset(&net, 0, sizeof(net_ioc));
-	fd = open(O2CB_NETWORKING_FILE, O_RDONLY);
-	if (fd < 0)
-		return O2CB_ET_SERVICE_UNAVAILABLE;
+			case ENOTDIR:
+			case ENOENT:
+				err = O2CB_ET_SERVICE_UNAVAILABLE;
+				break;
 
-	ret = 0;
-	if (ioctl(fd, NET_IOC_ACTIVATE, &net)) {
-		switch (errno) {
 			default:
-				ret = O2CB_ET_INTERNAL_FAILURE;
+				err = O2CB_ET_INTERNAL_FAILURE;
 				break;
+		}
 
-			case ENOTTY:
-				ret = O2CB_ET_SERVICE_UNAVAILABLE;
-				break;
-		}
+		goto out;
 	}
 
-	close(fd);
-	return ret;
-}  /* o2cb_activate_networking() */
+	err = o2cb_set_node_attribute(cluster_name, node_name,
+				      "num", node_num);
+	if (err)
+		goto out_rmdir;
+
+	err = o2cb_set_node_attribute(cluster_name, node_name,
+				      "ipv4_port", ip_port);
+	if (err)
+		goto out_rmdir;
+
+	err = o2cb_set_node_attribute(cluster_name, node_name,
+				      "ipv4_address", ip_address);
+out_rmdir:
+	if (err)
+		rmdir(node_path);
+
+out:
+	return err;
+}
+

Modified: branches/usysfsify/libo2cb/o2cb_err.et.in
===================================================================
--- branches/usysfsify/libo2cb/o2cb_err.et.in	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/libo2cb/o2cb_err.et.in	2005-03-16 05:37:32 UTC (rev 645)
@@ -39,4 +39,13 @@
 ec	O2CB_ET_INTERNAL_FAILURE,
 	"Internal logic failure"
 
+ec	O2CB_ET_PERMISSION_DENIED,
+	"Insufficient permissions to access cluster service"
+
+ec	O2CB_ET_CLUSTER_EXISTS,
+	"Cluster already exists"
+
+ec	O2CB_ET_NODE_EXISTS,
+	"Node already exists"
+
 	end

Modified: branches/usysfsify/vendor/common/o2cb.init
===================================================================
--- branches/usysfsify/vendor/common/o2cb.init	2005-03-16 04:29:10 UTC (rev 644)
+++ branches/usysfsify/vendor/common/o2cb.init	2005-03-16 05:37:32 UTC (rev 645)
@@ -2,7 +2,7 @@
 # init fragment for O2CB.
 #
 # chkconfig: 2435 29 20
-# description: Load O2CB drivers at system boot.
+# description: Load O2CB cluster services at system boot.
 #
 ### BEGIN INIT INFO
 # Provides: o2cb
@@ -11,7 +11,7 @@
 # Required-Stop:
 # Default-Start: 2 3 5
 # Default-Stop:
-# Description: Load O2CB drivers at system boot.
+# Description: Load O2CB cluster services at system boot.
 ### END INIT INFO
 
 # Force LC_ALL=C
@@ -20,32 +20,14 @@
 # Source configuration
 [ -f /etc/sysconfig/o2cb ] && . /etc/sysconfig/o2cb
 
-if [ -z "$O2CB_MANAGER" ]
-then
-    O2CB_MANAGER=/proc/cluster
-fi
+# XXX some description of what this does
+LOAD_ACTIONS=("load_module usysfs"
+		"mount_fs usysfs /usys"
+		"load_module ocfs2_nodemanager"
+		"load_module ocfs2_heartbeat"
+		"load_module ocfs2_tcp")
 
-KVER="`uname -r`"
-MODPATH="/lib/modules/${KVER}/kernel/drivers/addon/o2cb"
-
 #
-# The module list is an ordered list of modules to load and mountpoints
-# to mount.  Each entry is formatted like so:
-#    <module>:<fstype>:<mountpoint>
-#
-# The mountpoint is underneath the O2CB_MANAGER path.  So, an entry of:
-#    ocfs2_heartbeat:hb:heartbeat
-# means to load the ocfs2_heartbeat module, and
-# mount -t hb none ${O2CB_MANAGER}/heartbeat
-#
-# If a module requires no mount, the colons must remain.  eg, 
-#    ocfs2_tcp::
-#
-MODULE_LIST="ocfs2_nodemanager:nm:nm ocfs2_heartbeat:hb:heartbeat ocfs2_tcp::"
-
-
-
-#
 # if_fail()
 #
 # Evaluates return codes.  If 0, prints "OK", if 1, prints "Failed"
@@ -171,38 +153,40 @@
             ;;
         esac
     done
+
+	# XXX ask about mount point base
 }
 
 
 #
-# dev_create()
+# make_dir()
 #
 # Create $1
 # Returns 0 on success, 1 on error, 2 if it already exists.
 #
-dev_create()
+make_dir()
 {
     if [ "$#" -lt "1" -o -z "$1" ]
     then
-        echo "dev_create(): Requires an argument" >&2
+        echo "make_dir(): Requires an argument" >&2
         return 1
     fi
-    DEV="$1"
-    if [ -e "$DEV" ]
+    DIR="$1"
+    if [ -e "$DIR" ]
     then
-        if [ -d "$DEV" ]
+        if [ -d "$DIR" ]
         then
             return 2
         fi
-        echo "dev_create(): File $DEV is not a directory" >&2
+        echo "make_dir(): File $DIR is not a directory" >&2
         return 1
     fi
 
-    echo -n "Creating $DEV mount point: "
-    mkdir "$DEV" 2>/dev/null
+    echo -n "Creating directory '$DIR': "
+    mkdir -p "$DIR" 2>/dev/null
     if [ $? != 0 ]
     then
-        echo "Unable to create mount point $DEV" >&2
+        echo "Unable to create directory '$DIR'" >&2
         return 1
     fi
     return 0
@@ -287,21 +271,15 @@
 
 
 #
-# mount_device()
-# Mount the a filesystem under the O2CB_MANAGER.
+# mount_fs()
+# Mount a filesystem.
 #
 # 0 is success, 1 is error, 2 is already mounted
 #
-mount_device()
+mount_fs()
 {
-    if [ -z "$O2CB_MANAGER" ]
-    then
-        echo "mount_device(): No manager specified!" >&2
-        return 1
-    fi
     TYPE="$1"
-    MNTPT="$2"
-    FULL_MOUNT="${O2CB_MANAGER}/${MNTPT}"
+    FULL_MOUNT="$2"
     FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
     MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
 
@@ -310,11 +288,17 @@
         return 2
     fi
 
-    echo -n "Mounting ${TYPE} driver filesystem: "
-    mount $OPTS -t ${TYPE} ${TYPE} $FULL_MOUNT
+    # XXX some policy?
+    if [ ! -e "$FULL_MOUNT" ]; then
+        make_dir $FULL_MOUNT
+        if_fail "$?"
+    fi
+	
+    echo -n "Mounting ${TYPE} filesystem at $FULL_MOUNT: "
+    mount -t ${TYPE} ${TYPE} $FULL_MOUNT
     if [ $? != 0 ]
     then
-        echo "Unable to mount ${TYPE} driver filesystem" >&2
+        echo "Unable to mount ${TYPE} filesystem" >&2
         return 1
     fi
 
@@ -323,21 +307,15 @@
 
 
 #
-# unmount_device()
-# Unmount the /dev/oracleasm filesystem
+# unmount_fs()
+# Unmount a filesystem
 #
 # 0 is success, 1 is error, 2 is not mounted
 #
-unmount_device()
+unmount_fs()
 {
-    if [ -z "$O2CB_MANAGER" ]
-    then
-        echo "mount_device(): No device specified!" >&2
-        return 1
-    fi
     TYPE="$1"
-    MNTPT="$2"
-    FULL_MOUNT="${O2CB_MANAGER}/${MNTPT}"
+    FULL_MOUNT="$2"
     FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
     MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
 
@@ -346,34 +324,22 @@
         return 2
     fi
 
-    echo -n "Unmounting ${TYPE} driver filesystem: "
+    echo -n "Unmounting ${TYPE} filesystem: "
     umount $FULL_MOUNT
     if [ $? != 0 ]
     then
-        echo "Unable to unmount ${TYPE} driver filesystem" >&2
+        echo "Unable to unmount ${TYPE} filesystem" >&2
         return 1
     fi
 
     return 0
 }
 
-
 load()
 {
-    for MODSPEC in $MODULE_LIST
-    do
-        MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
-        FSTYPE="`echo $MODSPEC | cut -d: -f2`"
-        MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
-
-        load_module "$MODULE_NAME"
+    for i in $(seq 0 $((${#LOAD_ACTIONS[*]} - 1)) ); do
+	eval ${LOAD_ACTIONS[i]}
         if_fail "$?"
-
-        if [ -n "$FSTYPE" -a -n "$MOUNT_POINT" ]
-        then
-            mount_device "$FSTYPE" "$MOUNT_POINT"
-            if_fail "$?"
-        fi
     done
 }
 
@@ -392,7 +358,7 @@
     #
 
     echo -n "Starting cluster ${CLUSTER}: "
-    OUTPUT="`o2cb_ctl -H -l "${O2CB_MANAGER}" -n "${CLUSTER}" -t cluster -a online=yes 2>&1`"
+    OUTPUT="`o2cb_ctl -H -n "${CLUSTER}" -t cluster -a online=yes 2>&1`"
     if_fail "$?" "$OUTPUT"
 }
 
@@ -409,31 +375,8 @@
 
 unload()
 {
-    # Reverse list for unloading
-    R_MODLIST=""
-    for MODSPEC in $MODULE_LIST
-    do
-        if [ -z "$R_MODLIST" ]
-        then
-            R_MODLIST="$MODSPEC"
-        else
-            R_MODLIST="${MODSPEC} ${R_MODLIST}"
-        fi
-    done
-
-    for MODSPEC in $R_MODLIST
-    do
-        MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
-        FSTYPE="`echo $MODSPEC | cut -d: -f2`"
-        MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
-
-        if [ -n "$FSTYPE" -a -n "$MOUNT_POINT" ]
-        then
-            unmount_device "$FSTYPE" "$MOUNT_POINT"
-            if_fail "$?"
-        fi
-
-        unload_module "$MODULE_NAME"
+    for i in $(seq $((${#LOAD_ACTIONS[*]} - 1)) -1 0); do
+	eval "un${LOAD_ACTIONS[i]}"
         if_fail "$?"
     done
 }
@@ -452,6 +395,8 @@
 
 status()
 {
+	echo broken
+	exit
     echo -n "Checking if O2CB is loaded: "
     RC=0
     for MODSPEC in $MODULE_LIST



More information about the Ocfs2-tools-commits mailing list