[Ocfs2-tools-devel] [PATCH 23/32] libocfs2: Add c_flags to struct o2cb_cluster_desc

Sunil Mushran sunil.mushran at oracle.com
Tue Sep 14 15:54:53 PDT 2010


ocfs2_fill_cluster_desc() and ocfs2_set_cluster_desc() are now aware of
cluster flags.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 include/o2cb/o2cb.h |    1 +
 libo2cb/o2cb_abi.c  |   53 +++++++++++++++++++++++++++++++++-----------------
 libo2cb/o2cb_abi.h  |    5 ++++
 libocfs2/dlm.c      |   35 +++++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+), 18 deletions(-)

diff --git a/include/o2cb/o2cb.h b/include/o2cb/o2cb.h
index 8526ad7..e1c0d43 100644
--- a/include/o2cb/o2cb.h
+++ b/include/o2cb/o2cb.h
@@ -84,6 +84,7 @@ struct o2cb_cluster_desc {
 	char *c_cluster;	/* The name of the cluster, NULL for the
 				   default cluster, which is only valid in
 				   the classic stack.  */
+	uint8_t c_flags;
 };
 
 struct o2cb_region_desc {
diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index 2f6a443..00ebcf9 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -1720,38 +1720,55 @@ errcode_t o2cb_running_cluster_desc(struct o2cb_cluster_desc *cluster)
 	errcode_t err;
 	const char *stack;
 	char **clusters = NULL;
+	int globalhb;
 
+	cluster->c_stack = NULL;
+	cluster->c_cluster = NULL;
+	cluster->c_flags = 0;
+
+	/* c_stack */
 	err = o2cb_get_stack_name(&stack);
 	if (err)
-		return err;
-
-	if (!strcmp(stack, classic_stack.s_name)) {
-		cluster->c_stack = NULL;
-		cluster->c_cluster = NULL;
-		return 0;
-	}
+		goto out;
 
+	err = O2CB_ET_NO_MEMORY;
 	cluster->c_stack = strdup(stack);
 	if (!cluster->c_stack)
-		return O2CB_ET_NO_MEMORY;
+		goto out;
 
+	/* c_cluster */
 	err = o2cb_list_clusters(&clusters);
-	if (err) {
-		free(cluster->c_stack);
-		return err;
-	}
+	if (err)
+		goto out;
 
 	/* The first cluster is the default cluster */
-	if (clusters[0]) {
+	if (!clusters[0])
+		err = O2CB_ET_SERVICE_UNAVAILABLE;
+	else {
 		cluster->c_cluster = strdup(clusters[0]);
-		if (!cluster->c_cluster) {
-			free(cluster->c_stack);
+		if (!cluster->c_cluster)
 			err = O2CB_ET_NO_MEMORY;
-		}
 	}
-	o2cb_free_cluster_list(clusters);
+	if (err)
+		goto out;
 
-	return 0;
+	/* c_flags */
+	err = o2cb_global_heartbeat_mode(cluster->c_cluster, &globalhb);
+	if (err)
+		goto out;
+
+	if (globalhb)
+		cluster->c_flags |= OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT;
+
+out:
+	if (clusters)
+		o2cb_free_cluster_list(clusters);
+	if (err) {
+		free(cluster->c_stack);
+		free(cluster->c_cluster);
+	}
+
+	return err;
 }
 
 static inline int is_dots(const char *name)
diff --git a/libo2cb/o2cb_abi.h b/libo2cb/o2cb_abi.h
index 0b387be..677944f 100644
--- a/libo2cb/o2cb_abi.h
+++ b/libo2cb/o2cb_abi.h
@@ -41,4 +41,9 @@
 #define O2CB_FORMAT_HEARTBEAT_REGION_ATTR	O2CB_FORMAT_HEARTBEAT_REGION "/%s"
 #define O2CB_FORMAT_HEARTBEAT_MODE	O2CB_FORMAT_HEARTBEAT_DIR "/mode"
 
+/*
+ * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
+ */
+#define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT	(0x01)
+
 #endif  /* _O2CB_ABI_H */
diff --git a/libocfs2/dlm.c b/libocfs2/dlm.c
index 848b795..611154c 100644
--- a/libocfs2/dlm.c
+++ b/libocfs2/dlm.c
@@ -110,6 +110,7 @@ errcode_t ocfs2_fill_cluster_desc(ocfs2_filesys *fs,
 	if (!ocfs2_clusterinfo_valid(sb)) {
 		desc->c_stack = NULL;
 		desc->c_cluster = NULL;
+		desc->c_flags = 0;
 		return 0;
 	}
 
@@ -127,16 +128,46 @@ errcode_t ocfs2_fill_cluster_desc(ocfs2_filesys *fs,
 	       OCFS2_STACK_LABEL_LEN);
 	memcpy(desc->c_cluster, sb->s_cluster_info.ci_cluster,
 	       OCFS2_CLUSTER_NAME_LEN);
+	desc->c_flags = sb->s_cluster_info.ci_stackflags;
 
 	return 0;
 }
 
+errcode_t ocfs2_set_cluster_flags(ocfs2_filesys *fs,
+				  struct o2cb_cluster_desc *desc)
+{
+	errcode_t ret = 0;
+	struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+	int globalhb;
+
+	sb->s_cluster_info.ci_stackflags = 0;
+	if (ocfs2_o2cb_stack(sb)) {
+		ret = o2cb_global_heartbeat_mode(desc->c_cluster, &globalhb);
+		if (ret)
+			goto out;
+		if (globalhb)
+			sb->s_cluster_info.ci_stackflags |=
+				OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT;
+	}
+
+out:
+	return ret;
+}
+
+
 errcode_t ocfs2_set_cluster_desc(ocfs2_filesys *fs,
 				 struct o2cb_cluster_desc *desc)
 {
 	errcode_t ret;
 	struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
 
+	if (!(sb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_CLUSTERINFO)) {
+		if (!desc->c_stack) {
+			ret = OCFS2_ET_INVALID_ARGUMENT;
+			goto out;
+		}
+	}
+
 	if (desc->c_stack) {
 		if (!desc->c_stack[0] || !desc->c_cluster ||
 		    !desc->c_cluster[0]) {
@@ -166,6 +197,10 @@ errcode_t ocfs2_set_cluster_desc(ocfs2_filesys *fs,
 		       OCFS2_STACK_LABEL_LEN);
 		memcpy(sb->s_cluster_info.ci_cluster, desc->c_cluster,
 		       OCFS2_CLUSTER_NAME_LEN);
+
+		ret = ocfs2_set_cluster_flags(fs, desc);
+		if (ret)
+			goto out;
 	} else {
 		sb->s_feature_incompat &=
 			~OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK;
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list