[Ocfs2-tools-commits] jlbec commits r668 - in trunk: clusterbo
libo2cb libo2cb/include libocfs2 mkfs.ocfs2 mount.ocfs2
ocfs2console/blkid vendor/common
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Mar 18 00:00:26 CST 2005
Author: jlbec
Signed-off-by: mfasheh
Date: 2005-03-18 00:00:24 -0600 (Fri, 18 Mar 2005)
New Revision: 668
Removed:
trunk/libo2cb/include/ocfs2_heartbeat.h
trunk/libo2cb/include/ocfs2_nodemanager.h
trunk/libo2cb/include/ocfs2_tcp.h
Modified:
trunk/clusterbo/o2cb_config.c
trunk/clusterbo/o2cb_config.h
trunk/clusterbo/o2cb_ctl.c
trunk/libo2cb/include/o2cb.h
trunk/libo2cb/include/o2cb_abi.h
trunk/libo2cb/o2cb_abi.c
trunk/libo2cb/o2cb_err.et.in
trunk/libocfs2/dlm.c
trunk/mkfs.ocfs2/Makefile
trunk/mount.ocfs2/Makefile
trunk/mount.ocfs2/mount.ocfs2.c
trunk/mount.ocfs2/mount.ocfs2.h
trunk/ocfs2console/blkid/
trunk/vendor/common/o2cb.init
Log:
o Merge the usysfsify branch. The o2cb ABI is now usysfs.
Signed-off-by: mfasheh
Modified: trunk/clusterbo/o2cb_config.c
===================================================================
--- trunk/clusterbo/o2cb_config.c 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/clusterbo/o2cb_config.c 2005-03-18 06:00:24 UTC (rev 668)
@@ -38,10 +38,14 @@
struct _O2CBConfig {
+ GList *co_clusters;
+ gboolean co_valid;
+};
+
+struct _O2CBCluster {
gchar *c_name;
guint c_num_nodes;
GList *c_nodes;
- gboolean c_valid;
};
struct _O2CBNode {
@@ -63,16 +67,14 @@
if (!config)
return NULL;
- config->c_name = NULL;
- config->c_num_nodes = 0;
- config->c_nodes = NULL;
- config->c_valid = FALSE;
+ config->co_clusters = NULL;
+ config->co_valid = FALSE;
return config;
} /* o2cb_config_initialize() */
-static gint o2cb_config_fill_node(O2CBConfig *config,
- JConfigStanza *cfs)
+static gint o2cb_cluster_fill_node(O2CBCluster *cluster,
+ JConfigStanza *cfs)
{
O2CBNode *node;
gchar *num_s, *name, *addr, *port_s;
@@ -82,7 +84,7 @@
/* NB: _add_node() gives us a node number, but we're going to
* override it, because we know better. */
- node = o2cb_config_add_node(config);
+ node = o2cb_cluster_add_node(cluster);
if (!node)
return -ENOMEM;
@@ -96,7 +98,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;
@@ -137,25 +139,27 @@
return rc;
} /* o2cb_config_fill_node() */
-static gint o2cb_config_fill(O2CBConfig *config, JConfig *cf)
+static gint o2cb_config_fill_cluster(O2CBConfig *config, JConfig *cf,
+ JConfigStanza *c_cfs)
{
gint rc;
gulong val;
gchar *count, *ptr;
+ O2CBCluster *cluster;
JIterator *iter;
- JConfigStanza *c_cfs, *n_cfs;
+ JConfigStanza *n_cfs;
JConfigMatch match = {J_CONFIG_MATCH_VALUE, "cluster", NULL};
- c_cfs = j_config_get_stanza_nth(cf, "cluster", 0);
- if (!c_cfs)
- return -ENOENT;
-
rc = -ENOENT;
match.value = j_config_get_attribute(c_cfs, "name");
if (!match.value && !*match.value)
goto out_error;
- rc = o2cb_config_set_cluster_name(config, match.value);
+ cluster = o2cb_config_add_cluster(config);
+ if (!cluster)
+ goto out_error;
+
+ rc = o2cb_cluster_set_name(cluster, match.value);
if (rc)
goto out_error;
@@ -168,7 +172,7 @@
while (j_iterator_has_more(iter))
{
n_cfs = (JConfigStanza *)j_iterator_get_next(iter);
- rc = o2cb_config_fill_node(config, n_cfs);
+ rc = o2cb_cluster_fill_node(cluster, n_cfs);
if (rc)
break;
}
@@ -187,7 +191,7 @@
rc = -ERANGE;
if ((val == ULONG_MAX) || (val > UINT_MAX))
goto out_error;
- config->c_num_nodes = val;
+ cluster->c_num_nodes = val;
rc = 0;
@@ -195,8 +199,33 @@
g_free(match.value);
return rc;
-} /* o2cb_config_fill() */
+} /* o2cb_config_fill_cluster() */
+static gint o2cb_config_fill(O2CBConfig *config, JConfig *cf)
+{
+ int rc;
+ JIterator *iter;
+ JConfigStanza *c_cfs;
+
+ rc = -ENOMEM;
+ iter = j_config_get_stanzas(cf, "cluster", NULL, 0);
+ if (!iter)
+ goto out_error;
+
+ rc = 0;
+ while (j_iterator_has_more(iter))
+ {
+ c_cfs = (JConfigStanza *)j_iterator_get_next(iter);
+ rc = o2cb_config_fill_cluster(config, cf, c_cfs);
+ if (rc)
+ break;
+ }
+ j_iterator_free(iter);
+
+out_error:
+ return rc;
+}
+
O2CBConfig *o2cb_config_load(const char *filename)
{
gint rc;
@@ -233,7 +262,7 @@
config = NULL;
}
else
- config->c_valid = TRUE;
+ config->co_valid = TRUE;
}
j_config_free(cf);
@@ -241,33 +270,17 @@
return config;
} /* o2cb_config_load() */
-static gint o2cb_node_store(JConfig *cf, O2CBNode *node)
+static gint o2cb_node_store(JConfig *cf, O2CBCluster *cluster,
+ O2CBNode *node)
{
gchar *val;
JConfigStanza *cfs;
- cfs = j_config_get_stanza_nth(cf, "cluster", 0);
- if (!cfs)
- return -EINVAL;
-
- val = j_config_get_attribute(cfs, "name");
- if (!val)
- return -ENOMEM;
- if (!*val)
- {
- g_free(val);
- return -EINVAL;
- }
-
cfs = j_config_add_stanza(cf, "node");
if (!cfs)
- {
- g_free(val);
return -ENOMEM;
- }
- j_config_set_attribute(cfs, "cluster", val);
- g_free(val);
+ j_config_set_attribute(cfs, "cluster", cluster->c_name);
j_config_set_attribute(cfs, "name", node->n_name);
j_config_set_attribute(cfs, "ip_address", node->n_addr);
@@ -287,39 +300,61 @@
return 0;
} /* o2cb_node_store() */
-gint o2cb_config_store(O2CBConfig *config, const gchar *filename)
+static gint o2cb_cluster_store(JConfig *cf, O2CBCluster *cluster)
{
int rc;
- JConfig *cf;
+ gchar *count;
+ GList *list;
JConfigStanza *cfs;
O2CBNode *node;
- gchar *count;
- GList *list;
- cf = j_config_parse_memory("", strlen(""));
- if (!cf)
- return -ENOMEM;
-
cfs = j_config_add_stanza(cf, "cluster");
- j_config_set_attribute(cfs, "name", config->c_name);
+ j_config_set_attribute(cfs, "name", cluster->c_name);
- count = g_strdup_printf("%u", config->c_num_nodes);
+ count = g_strdup_printf("%u", cluster->c_num_nodes);
j_config_set_attribute(cfs, "node_count", count);
g_free(count);
rc = 0;
- list = config->c_nodes;
+ list = cluster->c_nodes;
while (list)
{
node = (O2CBNode *)list->data;
- rc = o2cb_node_store(cf, node);
+ rc = o2cb_node_store(cf, cluster, node);
if (rc)
break;
list = list->next;
}
+ return rc;
+}
+
+
+gint o2cb_config_store(O2CBConfig *config, const gchar *filename)
+{
+ int rc;
+ JConfig *cf;
+ O2CBCluster *cluster;
+ GList *list;
+
+ cf = j_config_parse_memory("", strlen(""));
+ if (!cf)
+ return -ENOMEM;
+
+ rc = 0;
+ list = config->co_clusters;
+ while (list)
+ {
+ cluster = (O2CBCluster *)list->data;
+ rc = o2cb_cluster_store(cf, cluster);
+ if (rc)
+ break;
+
+ list = list->next;
+ }
+
if (!rc)
{
if (!j_config_dump_file(cf, filename))
@@ -339,15 +374,15 @@
g_free(node);
} /* o2cb_node_free() */
-void o2cb_config_free(O2CBConfig *config)
+static void o2cb_cluster_free(O2CBCluster *cluster)
{
GList *list;
O2CBNode *node;
- while (config->c_nodes)
+ while (cluster->c_nodes)
{
- list = config->c_nodes;
- config->c_nodes = list->next;
+ list = cluster->c_nodes;
+ cluster->c_nodes = list->next;
node = (O2CBNode *)list->data;
g_list_free(list);
@@ -355,50 +390,113 @@
o2cb_node_free(node);
}
- if (config->c_name)
- g_free(config->c_name);
+ if (cluster->c_name)
+ g_free(cluster->c_name);
+ g_free(cluster);
+} /* o2cb_cluster_free() */
+
+void o2cb_config_free(O2CBConfig *config)
+{
+ GList *list;
+ O2CBCluster *cluster;
+
+ while (config->co_clusters)
+ {
+ list = config->co_clusters;
+ config->co_clusters = list->next;
+
+ cluster = (O2CBCluster *)list->data;
+ g_list_free(list);
+
+ o2cb_cluster_free(cluster);
+ }
+
g_free(config);
-} /* o2cb_config_free() */
+}
-gchar *o2cb_config_get_cluster_name(O2CBConfig *config)
+O2CBCluster *o2cb_config_add_cluster(O2CBConfig *config)
{
+ O2CBCluster *cluster;
+
g_return_val_if_fail(config != NULL, NULL);
- return g_strdup(config->c_name);
-} /* o2cb_config_get_cluster_name() */
+ cluster = g_new(O2CBCluster, 1);
-gint o2cb_config_set_cluster_name(O2CBConfig *config, const gchar *name)
+ cluster->c_name = NULL;
+ cluster->c_num_nodes = 0;
+ cluster->c_nodes = NULL;
+
+ config->co_clusters = g_list_append(config->co_clusters, cluster);
+
+ config->co_valid = TRUE;
+
+ return cluster;
+} /* o2cb_cluster_add_node() */
+
+O2CBCluster *o2cb_config_get_cluster_by_name(O2CBConfig *config,
+ const gchar *name)
{
+ GList *list;
+ O2CBCluster *cluster;
+
+ g_return_val_if_fail(config != NULL, NULL);
+
+ list = config->co_clusters;
+ while (list)
+ {
+ cluster = (O2CBCluster *)list->data;
+ if (!strcmp(cluster->c_name, name))
+ return cluster;
+ list = list->next;
+ }
+
+ return NULL;
+} /* o2cb_config_get_cluster_by_name() */
+
+JIterator *o2cb_config_get_clusters(O2CBConfig *config)
+{
+ g_return_val_if_fail(config != NULL, NULL);
+
+ return j_iterator_new_from_list(config->co_clusters);
+} /* o2cb_config_get_clusters() */
+
+gchar *o2cb_cluster_get_name(O2CBCluster *cluster)
+{
+ g_return_val_if_fail(cluster != NULL, NULL);
+
+ return g_strdup(cluster->c_name);
+} /* o2cb_cluster_get_name() */
+
+gint o2cb_cluster_set_name(O2CBCluster *cluster, const gchar *name)
+{
gchar *new_name;
new_name = g_strdup(name);
if (!new_name)
return -ENOMEM;
- g_free(config->c_name);
- config->c_name = new_name;
+ g_free(cluster->c_name);
+ cluster->c_name = new_name;
- config->c_valid = TRUE;
-
return 0;
} /* o2cb_config_set_cluster_name() */
-JIterator *o2cb_config_get_nodes(O2CBConfig *config)
+JIterator *o2cb_cluster_get_nodes(O2CBCluster *cluster)
{
- g_return_val_if_fail(config != NULL, NULL);
+ g_return_val_if_fail(cluster != NULL, NULL);
- return j_iterator_new_from_list(config->c_nodes);
-} /* o2cb_config_get_nodes() */
+ return j_iterator_new_from_list(cluster->c_nodes);
+} /* o2cb_cluster_get_nodes() */
-O2CBNode *o2cb_config_get_node(O2CBConfig *config, guint n)
+O2CBNode *o2cb_cluster_get_node(O2CBCluster *cluster, guint n)
{
GList *list;
O2CBNode *node;
- g_return_val_if_fail(config != NULL, NULL);
+ g_return_val_if_fail(cluster != NULL, NULL);
- list = config->c_nodes;
+ list = cluster->c_nodes;
while (list)
{
node = (O2CBNode *)list->data;
@@ -408,30 +506,50 @@
}
return NULL;
-} /* o2cb_config_get_node() */
+} /* o2cb_cluster_get_node() */
-O2CBNode *o2cb_config_add_node(O2CBConfig *config)
+O2CBNode *o2cb_cluster_get_node_by_name(O2CBCluster *cluster,
+ const gchar *name)
{
+ GList *list;
O2CBNode *node;
- g_return_val_if_fail(config != NULL, NULL);
+ g_return_val_if_fail(cluster != NULL, NULL);
+ list = cluster->c_nodes;
+ while (list)
+ {
+ node = (O2CBNode *)list->data;
+ if (!strcmp(node->n_name, name))
+ return node;
+ list = list->next;
+ }
+
+ return NULL;
+} /* o2cb_cluster_get_node_by_name() */
+
+O2CBNode *o2cb_cluster_add_node(O2CBCluster *cluster)
+{
+ O2CBNode *node;
+
+ g_return_val_if_fail(cluster != NULL, NULL);
+
node = g_new(O2CBNode, 1);
node->n_name = NULL;
node->n_addr = NULL;
node->n_port = 0;
- node->n_number = config->c_num_nodes;
- config->c_num_nodes++;
+ node->n_number = cluster->c_num_nodes;
+ cluster->c_num_nodes++;
- config->c_nodes = g_list_append(config->c_nodes, node);
+ cluster->c_nodes = g_list_append(cluster->c_nodes, node);
return node;
-} /* o2cb_config_add_node() */
+} /* o2cb_cluster_add_node() */
-void o2cb_config_delete_node(O2CBConfig *config, O2CBNode *node)
+void o2cb_cluster_delete_node(O2CBCluster *cluster, O2CBNode *node)
{
-} /* o2cb_config_delete_node() */
+} /* o2cb_cluster_delete_node() */
gint o2cb_node_get_number(O2CBNode *node)
{
Modified: trunk/clusterbo/o2cb_config.h
===================================================================
--- trunk/clusterbo/o2cb_config.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/clusterbo/o2cb_config.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -26,6 +26,7 @@
#define _O2CB_CONFIG_H
typedef struct _O2CBConfig O2CBConfig;
+typedef struct _O2CBCluster O2CBCluster;
typedef struct _O2CBNode O2CBNode;
O2CBConfig *o2cb_config_initialize(void);
@@ -33,14 +34,21 @@
gint o2cb_config_store(O2CBConfig *config, const gchar *filename);
void o2cb_config_free(O2CBConfig *config);
-gchar *o2cb_config_get_cluster_name(O2CBConfig *config);
-gint o2cb_config_set_cluster_name(O2CBConfig *config,
- const gchar *name);
+O2CBCluster *o2cb_config_add_cluster(O2CBConfig *config);
+void o2cb_config_delete_cluster(O2CBConfig *config,
+ O2CBCluster *cluster);
+JIterator *o2cb_config_get_clusters(O2CBConfig *config);
+O2CBCluster *o2cb_config_get_cluster_by_name(O2CBConfig *config,
+ const gchar *name);
-JIterator *o2cb_config_get_nodes(O2CBConfig *config);
-O2CBNode *o2cb_config_get_node(O2CBConfig *config, guint n);
-O2CBNode *o2cb_config_add_node(O2CBConfig *config);
-void o2cb_config_delete_node(O2CBConfig *config, O2CBNode *node);
+gchar *o2cb_cluster_get_name(O2CBCluster *cluster);
+gint o2cb_cluster_set_name(O2CBCluster *cluster, const gchar *name);
+JIterator *o2cb_cluster_get_nodes(O2CBCluster *cluster);
+O2CBNode *o2cb_cluster_get_node(O2CBCluster *cluster, guint n);
+O2CBNode *o2cb_cluster_get_node_by_name(O2CBCluster *cluster,
+ const gchar *name);
+O2CBNode *o2cb_cluster_add_node(O2CBCluster *cluster);
+void o2cb_cluster_delete_node(O2CBCluster *cluster, O2CBNode *node);
gint o2cb_node_get_number(O2CBNode *node);
gchar *o2cb_node_get_name(O2CBNode *node);
Modified: trunk/clusterbo/o2cb_ctl.c
===================================================================
--- trunk/clusterbo/o2cb_ctl.c 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/clusterbo/o2cb_ctl.c 2005-03-18 06:00:24 UTC (rev 668)
@@ -1,5 +1,7 @@
/* -*- mode: c; c-basic-offset: 4; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:
*
+ *
* o2cb_ctl.c
*
* Control program for O2CB.
@@ -62,7 +64,6 @@
{
O2CBOperation oc_op;
O2CBType oc_type;
- gchar *oc_manager;
GList *oc_objects;
GList *oc_attrs;
gboolean oc_compact_info;
@@ -89,10 +90,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");
@@ -118,6 +119,7 @@
{O2CB_TYPE_CLUSTER, "name"},
{O2CB_TYPE_CLUSTER, "online"},
{O2CB_TYPE_NODE, "name"},
+ {O2CB_TYPE_NODE, "cluster"},
{O2CB_TYPE_NODE, "number"},
{O2CB_TYPE_NODE, "ip_address"},
{O2CB_TYPE_NODE, "ip_port"},
@@ -302,7 +304,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 +369,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 +440,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))
@@ -527,80 +514,99 @@
int rc;
gchar *object, *name;
gulong num;
- JIterator *iter;
+ JIterator *c_iter;
O2CBNode *node;
+ O2CBCluster *cluster;
object = (gchar *)ctxt->oc_objects->data;
- name = o2cb_config_get_cluster_name(ctxt->oc_config);
- if (!strcmp(name, object))
+ cluster = o2cb_config_get_cluster_by_name(ctxt->oc_config,
+ object);
+ if (cluster)
{
+ rc = 0;
ctxt->oc_type = O2CB_TYPE_CLUSTER;
- return 0;
+ goto out;
}
- g_free(name);
num = strtoul(object, &name, 10);
- if (name && !*name && (num < UINT_MAX))
+ if (!name || *name || (num == UINT_MAX))
+ num = UINT_MAX;
+
+ rc = -ENOMEM;
+ c_iter = o2cb_config_get_clusters(ctxt->oc_config);
+ if (!c_iter)
+ goto out;
+
+ rc = -ENOENT;
+ while (j_iterator_has_more(c_iter))
{
- /* The object key is a number, hence a node number.
- * object == NULL means check num, not object. */
- g_free(object);
- object = NULL;
- }
+ cluster = (O2CBCluster *)j_iterator_get_next(c_iter);
- iter = o2cb_config_get_nodes(ctxt->oc_config);
- if (!iter)
- return -ENOMEM;
+ node = o2cb_cluster_get_node_by_name(cluster, object);
+ if (!node && (num < UINT_MAX))
+ node = o2cb_cluster_get_node(cluster, num);
- rc = -ENOENT;
- while (j_iterator_has_more(iter))
- {
- node = (O2CBNode *)j_iterator_get_next(iter);
- if (object)
+ if (node)
{
- name = o2cb_node_get_name(node);
- rc = strcmp(name, object);
- g_free(name);
- if (!rc)
- {
- ctxt->oc_type = O2CB_TYPE_NODE;
- break;
- }
+ ctxt->oc_type = O2CB_TYPE_NODE;
+ rc = 0;
+ break;
}
- else
- {
- if (num == o2cb_node_get_number(node))
- {
- ctxt->oc_type = O2CB_TYPE_NODE;
- rc = 0;
- break;
- }
- }
}
-
- j_iterator_free(iter);
-
+ j_iterator_free(c_iter);
+
+out:
return rc;
} /* find_type_for_objects() */
-static gint online_cluster(O2CBContext *ctxt)
+static gchar *o2cb_node_is_local(gchar *node_name)
{
+ int ret;
+ char hostname[PATH_MAX]; /* la la la */
+ gchar *local = NULL;
+
+ ret = gethostname(hostname, sizeof(hostname));
+ if (ret)
+ return NULL;
+
+ /* XXX no g_strcasecmp()? */
+ if (strcasecmp(hostname, node_name) == 0)
+ local = g_strdup("1");
+ else
+ local = g_strdup("0");
+
+ return local;
+}
+
+static gint online_cluster(O2CBContext *ctxt, O2CBCluster *cluster)
+{
errcode_t ret;
gint rc;
- gchar *name, *node_name;
+ gchar *name, *node_name, *node_num, *ip_address, *ip_port, *local;
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);
+ name = o2cb_cluster_get_name(cluster);
if (!name)
goto out_error;
- iter = o2cb_config_get_nodes(ctxt->oc_config);
+ 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_cluster_get_nodes(cluster);
if (!iter)
goto out_error;
@@ -608,76 +614,52 @@
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);
+ local = o2cb_node_is_local(node_name);
+
+ ret = o2cb_add_node(name, node_name, node_num, ip_address,
+ ip_port, local);
+ if (ret)
+ {
+ if (ret != O2CB_ET_NODE_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);
+ g_free(local);
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() */
-static gint offline_cluster(O2CBContext *ctxt)
+static gint offline_cluster(O2CBContext *ctxt, O2CBCluster *cluster)
{
fprintf(stderr,
PROGNAME ": Offline of cluster not supported yet\n");
return -ENOTSUP;
} /* offline_cluster() */
-static gint run_change_cluster(O2CBContext *ctxt)
+static gint run_change_cluster_one(O2CBContext *ctxt,
+ O2CBCluster *cluster)
{
gint rc = 0;
const gchar *val;
@@ -697,7 +679,7 @@
PROGNAME ": Empty name for cluster\n");
return -EINVAL;
}
- rc = o2cb_config_set_cluster_name(ctxt->oc_config, val);
+ rc = o2cb_cluster_set_name(cluster, val);
if (rc)
return rc;
}
@@ -705,14 +687,44 @@
if (attr_set(ctxt, "online"))
{
if (attr_boolean(ctxt, "online", FALSE))
- rc = online_cluster(ctxt);
+ rc = online_cluster(ctxt, cluster);
else
- rc = offline_cluster(ctxt);
+ rc = offline_cluster(ctxt, cluster);
}
return rc;
-} /* run_change_cluster() */
+} /* run_change_cluster_one() */
+static gint run_change_clusters(O2CBContext *ctxt)
+{
+ gint rc = 0;
+ O2CBCluster *cluster;
+ GList *list;
+
+ list = ctxt->oc_objects;
+ while (list)
+ {
+ cluster = o2cb_config_get_cluster_by_name(ctxt->oc_config,
+ (gchar *)list->data);
+ if (!cluster)
+ {
+ rc = -ENOENT;
+ fprintf(stderr,
+ PROGNAME ": Cluster \"%s\" does not exist\n",
+ (gchar *)list->data);
+ break;
+ }
+
+ rc = run_change_cluster_one(ctxt, cluster);
+ if (rc)
+ break;
+
+ list = list->next;
+ }
+
+ return rc;
+}
+
static gint run_change(O2CBContext *ctxt)
{
gint rc;
@@ -754,7 +766,7 @@
}
else if (ctxt->oc_type == O2CB_TYPE_CLUSTER)
{
- rc = run_change_cluster(ctxt);
+ rc = run_change_clusters(ctxt);
if (rc)
goto out_error;
}
@@ -766,7 +778,6 @@
goto out_error;
}
-
rc = write_config(ctxt);
out_error:
Modified: trunk/libo2cb/include/o2cb.h
===================================================================
--- trunk/libo2cb/include/o2cb.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/include/o2cb.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -43,21 +43,25 @@
#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_activate_networking(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,
+ const char *local);
+errcode_t o2cb_list_clusters(char ***clusters);
+void o2cb_free_cluster_list(char **clusters);
+
+errcode_t o2cb_create_heartbeat_region_disk(const char *cluster_name,
+ const char *region_name,
+ const char *device_name,
+ int block_bytes,
+ uint64_t start_block,
+ uint64_t blocks);
+
+
#endif /* _O2CB_H */
Modified: trunk/libo2cb/include/o2cb_abi.h
===================================================================
--- trunk/libo2cb/include/o2cb_abi.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/include/o2cb_abi.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -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,15 @@
#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"
+#define O2CB_FORMAT_HEARTBEAT_REGION O2CB_FORMAT_HEARTBEAT_DIR "/%s"
+#define O2CB_FORMAT_HEARTBEAT_REGION_ATTR O2CB_FORMAT_HEARTBEAT_REGION "/%s"
+
#endif /* _O2CB_ABI_H */
Deleted: trunk/libo2cb/include/ocfs2_heartbeat.h
===================================================================
--- trunk/libo2cb/include/ocfs2_heartbeat.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/include/ocfs2_heartbeat.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -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: trunk/libo2cb/include/ocfs2_nodemanager.h
===================================================================
--- trunk/libo2cb/include/ocfs2_nodemanager.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/include/ocfs2_nodemanager.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -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: trunk/libo2cb/include/ocfs2_tcp.h
===================================================================
--- trunk/libo2cb/include/ocfs2_tcp.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/include/ocfs2_tcp.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -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: trunk/libo2cb/o2cb_abi.c
===================================================================
--- trunk/libo2cb/o2cb_abi.c 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/o2cb_abi.c 2005-03-18 06:00:24 UTC (rev 668)
@@ -31,9 +31,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <limits.h>
#include <linux/types.h>
@@ -41,185 +43,612 @@
#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;
+static int do_read(int fd, void *bytes, size_t count)
+{
+ int total = 0;
+ int ret;
- ret = O2CB_ET_IO; /* FIXME */
- if (buf[0] == '0')
- ret = 0;
+ 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;
+ }
-out_close:
- close(fd);
-out:
- free(buf);
+ return total;
+}
- return ret;
-} /* o2cb_set_cluster_name() */
+static errcode_t do_write(int fd, const void *bytes, size_t count)
+{
+ int total = 0;
+ int ret;
+ int err = 0;
+ 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;
+ }
-errcode_t o2cb_add_node(nm_node_info *node)
+ total += ret;
+ }
+
+ return err;
+}
+
+static errcode_t o2cb_set_node_attribute(const char *cluster_name,
+ const char *node_name,
+ const char *attr_name,
+ const char *attr_value)
{
- errcode_t ret;
- int fd, rc, page_size = getpagesize();
- char *buf;
- nm_op *op;
+ int ret;
+ errcode_t err = 0;
+ char attr_path[PATH_MAX];
+ int fd;
- buf = malloc(sizeof(char*) * page_size);
- if (!buf)
- return O2CB_ET_NO_MEMORY;
+ 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;
- 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));
+ fd = open(attr_path, O_WRONLY);
+ if (fd < 0) {
+ switch (errno) {
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- fd = open(O2CB_CLUSTER_FILE, O_RDWR);
- if (fd < 0)
+ case ENOTDIR:
+ case ENOENT:
+ case EISDIR:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ err = O2CB_ET_PERMISSION_DENIED;
+ break;
+ }
+ } else {
+ err = do_write(fd, attr_value, strlen(attr_value));
+ close(fd);
+ }
+
+ return err;
+}
+
+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 = 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;
+
+ fd = open(attr_path, O_RDONLY);
+ if (fd < 0) {
+ switch (errno) {
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+
+ case ENOTDIR:
+ case ENOENT:
+ case EISDIR:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ 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';
+ }
+
+ return err;
+}
+
+/* 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,
+ const char *local)
+{
+ char node_path[PATH_MAX];
+ int ret;
+ errcode_t err;
+
+ 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;
+ }
- 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;
+ 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;
- memset(buf, 0, page_size);
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ err = O2CB_ET_PERMISSION_DENIED;
+ break;
- rc = read(fd, buf, page_size);
- if (rc < 0)
- goto out_close;
+ case ENOMEM:
+ err = O2CB_ET_NO_MEMORY;
+ break;
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- if (!rc)
- goto out_close;
+ case ENOTDIR:
+ case ENOENT:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
- ret = O2CB_ET_IO; /* FIXME */
- if (buf[0] == '0')
- ret = 0;
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+ }
-out_close:
- close(fd);
+ goto out;
+ }
+
+ 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);
+ if (err)
+ goto out_rmdir;
+
+ err = o2cb_set_node_attribute(cluster_name, node_name,
+ "local", local);
+out_rmdir:
+ if (err)
+ rmdir(node_path);
+
out:
- free(buf);
+ return err;
+}
- return ret;
-} /* o2cb_add_node() */
+static errcode_t o2cb_set_region_attribute(const char *cluster_name,
+ const char *region_name,
+ const char *attr_name,
+ const char *attr_value)
+{
+ int ret;
+ errcode_t err = 0;
+ char attr_path[PATH_MAX];
+ int fd;
-errcode_t o2cb_activate_cluster()
+ ret = snprintf(attr_path, PATH_MAX - 1,
+ O2CB_FORMAT_HEARTBEAT_REGION_ATTR,
+ cluster_name, region_name, attr_name);
+ if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+ return O2CB_ET_INTERNAL_FAILURE;
+
+ fd = open(attr_path, O_WRONLY);
+ if (fd < 0) {
+ switch (errno) {
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+
+ case ENOTDIR:
+ case ENOENT:
+ case EISDIR:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ err = O2CB_ET_PERMISSION_DENIED;
+ break;
+ }
+ } else {
+ err = do_write(fd, attr_value, strlen(attr_value));
+ close(fd);
+ }
+
+ return err;
+}
+
+static errcode_t o2cb_get_region_attribute(const char *cluster_name,
+ const char *region_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 = snprintf(attr_path, PATH_MAX - 1,
+ O2CB_FORMAT_HEARTBEAT_REGION_ATTR,
+ cluster_name, region_name, attr_name);
+ if ((ret <= 0) || (ret == (PATH_MAX - 1)))
+ return O2CB_ET_INTERNAL_FAILURE;
+
+ fd = open(attr_path, O_RDONLY);
+ if (fd < 0) {
+ switch (errno) {
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+
+ case ENOTDIR:
+ case ENOENT:
+ case EISDIR:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ 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';
+ }
+
+ return err;
+}
+
+static errcode_t _fake_default_cluster(char *cluster)
+{
errcode_t ret;
- int fd, rc, page_size = getpagesize();
- char *buf;
- nm_op *op;
+ char **clusters;
- buf = malloc(sizeof(char*) * page_size);
- if (!buf)
- return O2CB_ET_NO_MEMORY;
+ ret = o2cb_list_clusters(&clusters);
+ if (ret)
+ return ret;
- op = (nm_op *)buf;
- op->magic = NM_OP_MAGIC;
- op->opcode = NM_OP_CREATE_CLUSTER;
+ snprintf(cluster, NAME_MAX - 1, "%s", clusters[0]);
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- fd = open(O2CB_CLUSTER_FILE, O_RDWR);
- if (fd < 0)
+ o2cb_free_cluster_list(clusters);
+
+ return 0;
+}
+
+errcode_t o2cb_create_heartbeat_region_disk(const char *cluster_name,
+ const char *region_name,
+ const char *device_name,
+ int block_bytes,
+ uint64_t start_block,
+ uint64_t blocks)
+{
+ char _fake_cluster_name[NAME_MAX];
+ char region_path[PATH_MAX];
+ char num_buf[NAME_MAX];
+ int ret, fd;
+ errcode_t err;
+
+ if (!cluster_name) {
+ ret = _fake_default_cluster(_fake_cluster_name);
+ if (ret)
+ return ret;
+ cluster_name = _fake_cluster_name;
+ }
+
+#define O2CB_MAXIMUM_HEARTBEAT_BLOCKSIZE 4096
+ if (block_bytes > O2CB_MAXIMUM_HEARTBEAT_BLOCKSIZE) {
+ err = O2CB_ET_INVALID_BLOCK_SIZE;
goto out;
+ }
- rc = write(fd, op, sizeof(nm_op));
- if (rc < 0)
- goto out_close;
+#define O2CB_MAX_NODE_COUNT 255
+ if (!blocks || (blocks > O2CB_MAX_NODE_COUNT)) {
+ err = O2CB_ET_INVALID_BLOCK_COUNT;
+ goto out;
+ }
- ret = O2CB_ET_IO;
- if (rc < sizeof(nm_op))
- goto out_close;
+ ret = snprintf(region_path, PATH_MAX - 1,
+ O2CB_FORMAT_HEARTBEAT_REGION,
+ cluster_name, region_name);
+ if (ret <= 0 || ret == PATH_MAX - 1) {
+ err = O2CB_ET_INTERNAL_FAILURE;
+ goto out;
+ }
- memset(buf, 0, page_size);
+ ret = mkdir(region_path,
+ S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+ if (ret) {
+ switch (errno) {
+ case EEXIST:
+ err = O2CB_ET_REGION_EXISTS;
+ break;
- rc = read(fd, buf, page_size);
- if (rc < 0)
- goto out_close;
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ err = O2CB_ET_PERMISSION_DENIED;
+ break;
- ret = O2CB_ET_SERVICE_UNAVAILABLE;
- if (!rc)
+ case ENOMEM:
+ err = O2CB_ET_NO_MEMORY;
+ break;
+
+ case ENOTDIR:
+ case ENOENT:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+ }
+
+ goto out;
+ }
+
+ ret = snprintf(num_buf, NAME_MAX - 1, "%d", block_bytes);
+ if (ret <= 0 || ret == PATH_MAX - 1) {
+ err = O2CB_ET_INTERNAL_FAILURE;
+ goto out_rmdir;
+ }
+
+ err = o2cb_set_region_attribute(cluster_name, region_name,
+ "block_bytes", num_buf);
+ if (err)
+ goto out_rmdir;
+
+ ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64, start_block);
+ if (ret <= 0 || ret == PATH_MAX - 1) {
+ err = O2CB_ET_INTERNAL_FAILURE;
+ goto out_rmdir;
+ }
+
+ err = o2cb_set_region_attribute(cluster_name, region_name,
+ "start_block", num_buf);
+ if (err)
+ goto out_rmdir;
+
+ ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64, blocks);
+ if (ret <= 0 || ret == PATH_MAX - 1) {
+ err = O2CB_ET_INTERNAL_FAILURE;
+ goto out_rmdir;
+ }
+
+ err = o2cb_set_region_attribute(cluster_name, region_name,
+ "blocks", num_buf);
+ if (err)
+ goto out_rmdir;
+
+ fd = open(device_name, O_RDWR);
+ if (fd < 0) {
+ switch (errno) {
+ default:
+ err = O2CB_ET_INTERNAL_FAILURE;
+ break;
+
+ case ENOTDIR:
+ case ENOENT:
+ case EISDIR:
+ err = O2CB_ET_SERVICE_UNAVAILABLE;
+ break;
+
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ err = O2CB_ET_PERMISSION_DENIED;
+ break;
+ }
+
+ goto out_rmdir;
+ }
+
+ ret = snprintf(num_buf, NAME_MAX - 1, "%d", fd);
+ if (ret <= 0 || ret == PATH_MAX - 1) {
+ err = O2CB_ET_INTERNAL_FAILURE;
goto out_close;
+ }
- ret = O2CB_ET_IO; /* FIXME */
- if (buf[0] == '0')
- ret = 0;
+ err = o2cb_set_region_attribute(cluster_name, region_name,
+ "dev", num_buf);
out_close:
close(fd);
+
+out_rmdir:
+ if (err)
+ rmdir(region_path);
+
out:
- free(buf);
+ return err;
+}
- return ret;
-} /* o2cb_activate_cluster() */
-
-/* FIXME: does this really belong here? */
-errcode_t o2cb_activate_networking()
+errcode_t o2cb_list_clusters(char ***clusters)
{
errcode_t ret;
- int fd;
- net_ioc net;
+ int count;
+ DIR *dir;
+ struct dirent *dirent;
+ struct clist {
+ struct clist *next;
+ char *cluster;
+ } *tmp, *list;
- 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)) {
+ dir = opendir(O2CB_FORMAT_CLUSTER_DIR);
+ if (!dir) {
switch (errno) {
default:
ret = O2CB_ET_INTERNAL_FAILURE;
break;
- case ENOTTY:
+ case ENOTDIR:
+ case ENOENT:
ret = O2CB_ET_SERVICE_UNAVAILABLE;
break;
+
+ case ENOMEM:
+ ret = O2CB_ET_NO_MEMORY;
+ break;
+
+ case EACCES:
+ ret = O2CB_ET_PERMISSION_DENIED;
+ break;
}
+
+ goto out;
}
- close(fd);
+ ret = O2CB_ET_NO_MEMORY;
+ count = 0;
+ list = NULL;
+ while ((dirent = readdir(dir)) != NULL) {
+ tmp = malloc(sizeof(struct clist));
+ if (!tmp)
+ goto out_free_list;
+
+ tmp->cluster = strdup(dirent->d_name);
+ if (!tmp->cluster) {
+ free(tmp);
+ goto out_free_list;
+ }
+
+ tmp->next = list;
+ list = tmp;
+ count++;
+ }
+
+ *clusters = malloc(sizeof(char *) * (count + 1));
+ if (!*clusters)
+ goto out_free_list;
+
+ tmp = list;
+ count = 0;
+ for (tmp = list, count = 0; tmp; tmp = tmp->next, count++) {
+ (*clusters)[count] = tmp->cluster;
+ tmp->cluster = NULL;
+ }
+ (*clusters)[count] = NULL;
+
+ ret = 0;
+
+out_free_list:
+ while (list) {
+ tmp = list;
+ list = list->next;
+
+ if (tmp->cluster)
+ free(tmp->cluster);
+ free(tmp);
+ }
+
+ closedir(dir);
+
+out:
return ret;
-} /* o2cb_activate_networking() */
+}
+
+void o2cb_free_cluster_list(char **clusters)
+{
+ int i;
+
+ for (i = 0; clusters[i]; i++) {
+ free(clusters[i]);
+ }
+
+ free(clusters);
+}
Modified: trunk/libo2cb/o2cb_err.et.in
===================================================================
--- trunk/libo2cb/o2cb_err.et.in 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libo2cb/o2cb_err.et.in 2005-03-18 06:00:24 UTC (rev 668)
@@ -39,4 +39,22 @@
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"
+
+ec O2CB_ET_REGION_EXISTS,
+ "Heartbeat region already exists"
+
+ec O2CB_ET_INVALID_BLOCK_SIZE,
+ "Block size is invalid"
+
+ec O2CB_ET_INVALID_BLOCK_COUNT,
+ "Block count is invalid"
+
end
Modified: trunk/libocfs2/dlm.c
===================================================================
--- trunk/libocfs2/dlm.c 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/libocfs2/dlm.c 2005-03-18 06:00:24 UTC (rev 668)
@@ -32,7 +32,7 @@
#include "ocfs2.h"
-#define DEFAULT_DLMFS_PATH "/dev/ocfs2/dlm/"
+#define DEFAULT_DLMFS_PATH "/dlm/"
#define OCFS2_LOCK_ID_MAX_LEN 32
#define OCFS2_LOCK_ID_PAD "000000"
Modified: trunk/mkfs.ocfs2/Makefile
===================================================================
--- trunk/mkfs.ocfs2/Makefile 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/mkfs.ocfs2/Makefile 2005-03-18 06:00:24 UTC (rev 668)
@@ -19,11 +19,17 @@
LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
+LIBO2CB_CFLAGS = -I$(TOPDIR)/libo2cb/include
+LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb
+LIBO2CB_DEPS = $(TOPDIR)/libo2cb/libo2cb.a
+
+LIBO2CB_CFLAGS = -I$(TOPDIR)/libo2dlm/include
LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
-INCLUDES = $(LIBOCFS2_CFLAGS) -I. -I$(TOPDIR)/libo2dlm/include
-DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
+INCLUDES = $(LIBOCFS2_CFLAGS) $(LIBO2DLM_CFLAGS) $(LIBO2CB_CFLAGS) -I.
+DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" \
+ -DO2DLM_FLAT_INCLUDES -DO2CB_FLAT_INCLUDES
CFILES = mkfs.c check.c
OBJS = $(subst .c,.o,$(CFILES))
@@ -32,7 +38,7 @@
DIST_FILES = $(CFILES) mkfs.ocfs2.8.in
-mkfs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(COM_ERR_LIBS)
+mkfs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
+ $(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
include $(TOPDIR)/Postamble.make
Modified: trunk/mount.ocfs2/Makefile
===================================================================
--- trunk/mount.ocfs2/Makefile 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/mount.ocfs2/Makefile 2005-03-18 06:00:24 UTC (rev 668)
@@ -10,6 +10,8 @@
LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb
+LIBO2CB_DEPS = $(TOPDIR)/libo2cb/libo2cb.a
ifdef OCFS_DEBUG
OPTS += -ggdb
@@ -20,7 +22,8 @@
CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations
-DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
+ -DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
CFILES = opts.c mount.ocfs2.c
CFILES += fstab.c mntent.c realpath.c sundries.c xmalloc.c
@@ -32,8 +35,8 @@
DIST_FILES = $(CFILES) $(HFILES)
-mount.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(COM_ERR_LIBS)
+mount.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
+ $(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
group: group.o $(LIBOCFS2_DEPS)
$(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
Modified: trunk/mount.ocfs2/mount.ocfs2.c
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.c 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/mount.ocfs2/mount.ocfs2.c 2005-03-18 06:00:24 UTC (rev 668)
@@ -21,6 +21,7 @@
*/
#include "mount.ocfs2.h"
+#include "o2cb.h"
int verbose = 0;
int mount_quiet = 0;
@@ -186,6 +187,7 @@
static int get_my_nodenum(uint8_t *nodenum)
{
+#if 0
FILE *file;
int ret = -EINVAL;
int retval=-EINVAL, num;
@@ -212,10 +214,14 @@
done:
fclose(file);
return ret;
+#else
+ return 0;
+#endif
}
static int create_group(char *uuid, uint8_t *group_num)
{
+#if 0
FILE *file;
int ret = -EINVAL, retval;
int groupnum = NM_INVALID_SLOT_NUM;
@@ -261,11 +267,15 @@
done:
fclose(file);
return ret;
+#else
+ return 0;
+#endif
}
static int add_to_local_group(char *uuid, uint8_t group_num, uint8_t node_num)
{
+#if 0
FILE *file;
int ret = -EINVAL, retval;
nm_op *op = (nm_op *)op_buf;
@@ -311,11 +321,15 @@
done:
fclose(file);
return ret;
+#else
+ return 0;
+#endif
}
static int activate_group(char *group_name, char *group_dev, uint8_t group_num,
uint32_t block_bits, uint64_t num_blocks, uint64_t start_block)
{
+#if 0
int dev_fd = -1;
int ret = -EINVAL, retval;
FILE *file;
@@ -357,6 +371,7 @@
close(dev_fd);
fclose(file);
+#endif
return 0;
}
@@ -373,25 +388,35 @@
ocfs2_filesys *fs = NULL;
ret = ocfs2_open(group_dev, OCFS2_FLAG_RO, 0, 0, &fs);
- if (ret)
+ if (ret) {
+ com_err(progname, ret, "while opening the device.");
return status;
+ }
heartbeat_filename = ocfs2_system_inodes[HEARTBEAT_SYSTEM_INODE].si_name;
ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, heartbeat_filename,
strlen(heartbeat_filename), NULL, &blkno);
- if (ret)
+ if (ret) {
+ com_err(progname, ret, "while looking up the hb system inode.");
goto leave;
+ }
+
ret = ocfs2_malloc_block(fs->fs_io, &buf);
- if (ret)
+ if (ret) {
+ com_err(progname, ret, "while allocating a block for hb.");
goto leave;
+ }
ret = ocfs2_read_inode(fs, blkno, buf);
- if (ret)
+ if (ret) {
+ com_err(progname, ret, "while reading hb inode.");
goto leave;
+ }
di = (ocfs2_dinode *)buf;
if (di->id2.i_list.l_tree_depth ||
di->id2.i_list.l_next_free_rec != 1) {
+ com_err(progname, 0, "when checking for contiguous hb.");
goto leave;
}
rec = &(di->id2.i_list.l_recs[0]);
@@ -412,6 +437,7 @@
static int get_node_map(uint8_t group_num, char *bitmap)
{
+#if 0
FILE *file = NULL;
hb_op *op;
int ret = -EINVAL;
@@ -457,12 +483,16 @@
done:
fclose(file);
return ret;
+#else
+ return 0;
+#endif
}
static int get_raw_node_map(uint8_t groupnum, char *groupdev,
uint32_t block_bits, uint32_t num_blocks,
uint64_t start_block, char *bitmap)
{
+#if 0
int i;
int ret = -EINVAL;
char *buf = NULL, *tmpbuf;
@@ -544,10 +574,14 @@
if (times)
free(times);
return ret;
+#else
+ return 0;
+#endif
}
static int create_remote_group(char *group_name, uint8_t node)
{
+#if 0
int ret, fd = -1, remote_node = -1;
gsd_ioc ioc;
char fname[100];
@@ -637,16 +671,48 @@
if (remote_node != -1)
close(remote_node);
return ret;
+#else
+ return 0;
+#endif
}
-/*
- * this will try to add the group (and the node to the group)
- * for every mount. luckily, there are many shortcut paths
- * along the way, so checking for -EEXIST will save time.
- */
-static int add_me_to_group(char *groupname, char *groupdev)
+static int start_heartbeat(char *hbuuid, char *device)
{
int ret;
+ char *cluster = NULL;
+ errcode_t err;
+
+ uint32_t block_bits, cluster_bits, num_clusters;
+ uint64_t start_block, num_blocks;
+
+ ret = get_ocfs2_disk_hb_params(device, &block_bits, &cluster_bits,
+ &start_block, &num_clusters);
+ if (ret < 0) {
+ printf("hb_params failed\n");
+ return ret;
+ }
+
+ num_blocks = num_clusters << cluster_bits;
+ num_blocks >>= block_bits;
+
+ /* clamp to NM_MAX_NODES */
+ if (num_blocks > 254)
+ num_blocks = 254;
+
+ /* XXX: NULL cluster is a hack for right now */
+ err = o2cb_create_heartbeat_region_disk(NULL,
+ hbuuid,
+ device,
+ 1 << block_bits,
+ start_block,
+ num_blocks);
+ if (err) {
+ com_err(progname, err, "while creating hb region with o2cb.");
+ return -EINVAL;
+ }
+
+#if 0
+ int ret;
uint8_t my_nodenum, groupnum;
uint32_t pre_nodemap[] = {0, 0, 0, 0, 0, 0, 0, 0};
uint32_t post_nodemap[] = {0, 0, 0, 0, 0, 0, 0, 0};
@@ -767,6 +833,7 @@
if (verbose)
printf("ah nothing left to care about ... leaving\n");
+#endif
return 0;
}
@@ -812,25 +879,13 @@
if (verbose)
printf("device=%s hbuuid=%s\n", mo.dev, hbuuid);
- ret = add_me_to_group(hbuuid, mo.dev);
+ ret = start_heartbeat(hbuuid, mo.dev);
if (ret < 0) {
- fprintf(stderr, "%s: Error '%d' while adding to group\n", progname, (int)ret);
+ fprintf(stderr, "%s: Error '%d' while starting heartbeat\n",
+ progname, (int)ret);
goto bail;
}
- mo.xtra_opts = realloc(mo.xtra_opts, (strlen(mo.xtra_opts) +
- strlen(hbuuid) +
- strlen("group=") + 1));
- if (!mo.xtra_opts) {
- com_err(progname, OCFS2_ET_NO_MEMORY, " ");
- goto bail;
- }
-
- if (strlen(mo.xtra_opts))
- strcat(mo.xtra_opts, ",");
- strcat(mo.xtra_opts, "group=");
- strcat(mo.xtra_opts, hbuuid);
-
ret = mount(mo.dev, mo.dir, "ocfs2", mo.flags, mo.xtra_opts);
if (ret) {
com_err(progname, errno, "while mounting %s on %s", mo.dev, mo.dir);
Modified: trunk/mount.ocfs2/mount.ocfs2.h
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.h 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/mount.ocfs2/mount.ocfs2.h 2005-03-18 06:00:24 UTC (rev 668)
@@ -55,11 +55,3 @@
#include "bitops.h"
-#include "ocfs2_nodemanager.h"
-#include "ocfs2_heartbeat.h"
-#include "ocfs2_tcp.h"
-
-#define CLUSTER_FILE "/proc/cluster/nm/.cluster"
-#define GROUP_FILE "/proc/cluster/nm/.group"
-#define NODE_FILE "/proc/cluster/nm/.node"
-#define HEARTBEAT_DISK_FILE "/proc/cluster/heartbeat/.disk"
Property changes on: trunk/ocfs2console/blkid
___________________________________________________________________
Name: svn:ignore
+ .*.sw?
.*.d
blkid_types.h
libblkid-internal.a
Modified: trunk/vendor/common/o2cb.init
===================================================================
--- trunk/vendor/common/o2cb.init 2005-03-18 05:18:22 UTC (rev 667)
+++ trunk/vendor/common/o2cb.init 2005-03-18 06:00:24 UTC (rev 668)
@@ -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_dlmfs"
+ "mount_fs ocfs2_dlmfs /dlm")
-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