[Ocfs2-tools-devel] [PATCH 03/11] libo2cb: o2cb API for the running cluster stack.
Joel Becker
joel.becker at oracle.com
Tue May 27 18:44:23 PDT 2008
We want multiple programs to be able to query the running cluster stack.
Lift the functionality out of mkfs up into libo2cb. As always, a NULL
desc->c_stack means o2cb.
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
include/o2cb/o2cb.h | 2 ++
libo2cb/o2cb_abi.c | 40 ++++++++++++++++++++++++++++++++++++++++
mkfs.ocfs2/check.c | 22 ++++++++--------------
3 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/include/o2cb/o2cb.h b/include/o2cb/o2cb.h
index d3f2b5f..d987d20 100644
--- a/include/o2cb/o2cb.h
+++ b/include/o2cb/o2cb.h
@@ -112,6 +112,8 @@ errcode_t o2cb_num_region_refs(const char *region_name,
errcode_t o2cb_get_node_num(const char *cluster_name,
const char *node_name,
uint16_t *node_num);
+void o2cb_free_cluster_desc(struct o2cb_cluster_desc *cluster);
+errcode_t o2cb_running_cluster_desc(struct o2cb_cluster_desc *cluster);
struct ocfs2_protocol_version {
uint8_t pv_major;
diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index 823a0d9..13cde70 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -1647,6 +1647,46 @@ errcode_t o2cb_group_leave(struct o2cb_cluster_desc *cluster,
return current_stack->s_ops->group_leave(&desc, region);
}
+void o2cb_free_cluster_desc(struct o2cb_cluster_desc *cluster)
+{
+ if (cluster->c_stack)
+ free(cluster->c_stack);
+ if (cluster->c_cluster)
+ free(cluster->c_cluster);
+}
+
+errcode_t o2cb_running_cluster_desc(struct o2cb_cluster_desc *cluster)
+{
+ errcode_t err;
+ const char *stack;
+ char **clusters = NULL;
+
+ err = o2cb_get_stack_name(&stack);
+ if (err)
+ return err;
+
+ cluster->c_stack = strdup(stack);
+ if (!cluster->c_stack)
+ return O2CB_ET_NO_MEMORY;
+
+ err = o2cb_list_clusters(&clusters);
+ if (err) {
+ free(cluster->c_stack);
+ return err;
+ }
+
+ /* The first cluster is the default cluster */
+ if (clusters[0]) {
+ cluster->c_cluster = strdup(clusters[0]);
+ if (!cluster->c_cluster) {
+ free(cluster->c_stack);
+ err = O2CB_ET_NO_MEMORY;
+ }
+ }
+ o2cb_free_cluster_list(clusters);
+
+ return 0;
+}
static inline int is_dots(const char *name)
{
diff --git a/mkfs.ocfs2/check.c b/mkfs.ocfs2/check.c
index 543a3c3..a3a5419 100644
--- a/mkfs.ocfs2/check.c
+++ b/mkfs.ocfs2/check.c
@@ -31,28 +31,22 @@
static void cluster_fill(char **stack_name, char **cluster_name)
{
errcode_t err;
- char **clusters = NULL;
- const char *name = NULL;
+ struct o2cb_cluster_desc cluster;
err = o2cb_init();
if (err)
return;
- err = o2cb_get_stack_name(&name);
+ err = o2cb_running_cluster_desc(&cluster);
if (err)
return;
- *stack_name = strdup(name);
-
- err = o2cb_list_clusters(&clusters);
- if (err)
- return;
-
- /* The first cluster is the default cluster */
- if (clusters[0])
- *cluster_name = strdup(clusters[0]);
-
- o2cb_free_cluster_list(clusters);
+ /*
+ * These were allocated by o2cb_running_cluster_desc(),
+ * the caller will free them.
+ */
+ *stack_name = cluster.c_stack;
+ *cluster_name = cluster.c_cluster;
}
/* For ocfs2_fill_cluster_information(). Errors are to be ignored */
--
1.5.4.5
More information about the Ocfs2-tools-devel
mailing list