[Ocfs2-tools-devel] [PATCH 24/32] libo2cb: Validate cluster name and cluster flags in classic_begin_group_join()

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


In the classic stack with only local heartbeat, classic_begin_group_join() would
always create a heartbeat region that would implicitly check the validity of the
cluster name.

In global heartbeat, heartbeat regions are created before hand. Thus the need
to explicitly check the cluster name.

Also, it ensures the heartbeat mode (encoded in the cluster flags) is also
the same.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 libo2cb/o2cb_abi.c  |   73 ++++++++++++++++++++++++++++++++++++++++++++-------
 libo2cb/o2cb_err.et |    3 ++
 2 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index 00ebcf9..274d455 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -48,6 +48,9 @@
 #define OCFS2_STACK_LABEL_LEN	4
 #define CONTROL_DEVICE		"/dev/misc/ocfs2_control"
 
+static errcode_t o2cb_validate_cluster_name(struct o2cb_cluster_desc *desc);
+static errcode_t o2cb_validate_cluster_flags(struct o2cb_cluster_desc *desc,
+					     int *globalhb);
 
 struct o2cb_stack_ops {
 	errcode_t (*list_clusters)(char ***clusters);
@@ -1293,30 +1296,42 @@ static errcode_t classic_group_leave(struct o2cb_cluster_desc *cluster,
 				     struct o2cb_region_desc *region)
 {
 	errcode_t ret;
-	int global = 0;
+	int globalhb;
 
-	ret = o2cb_global_heartbeat_mode(cluster->c_cluster, &global);
+	ret = o2cb_validate_cluster_name(cluster);
+	if (ret)
+		goto bail;
+
+	ret = o2cb_validate_cluster_flags(cluster, &globalhb);
 	if (ret)
 		goto bail;
 
-	if (!global)
+	if (!globalhb)
 		ret = o2cb_stop_heartbeat(cluster, region);
 
 bail:
 	return ret;
 }
 
+/*
+ * Cluster stack is validated in o2cb_begin_group_join(). Here we validate
+ * the cluster name and the cluster flags (aka heartbeat mode).
+ */
 static errcode_t classic_begin_group_join(struct o2cb_cluster_desc *cluster,
 					  struct o2cb_region_desc *region)
 {
 	errcode_t ret;
-	int global = 0;
+	int globalhb;
 
-	ret = o2cb_global_heartbeat_mode(cluster->c_cluster, &global);
+	ret = o2cb_validate_cluster_name(cluster);
+	if (ret)
+		goto bail;
+
+	ret = o2cb_validate_cluster_flags(cluster, &globalhb);
 	if (ret)
 		goto bail;
 
-	if (!global)
+	if (!globalhb)
 		ret = o2cb_start_heartbeat(cluster, region);
 
 bail:
@@ -1606,7 +1621,45 @@ out:
 	return err;
 }
 
-static errcode_t o2cb_validate_cluster_desc(struct o2cb_cluster_desc *desc)
+static errcode_t o2cb_validate_cluster_flags(struct o2cb_cluster_desc *desc,
+					     int *globalhb)
+{
+	errcode_t ret;
+	int disk_mode = 0;
+
+	ret = o2cb_global_heartbeat_mode(desc->c_cluster, globalhb);
+	if (ret)
+		goto bail;
+
+	disk_mode = !!(desc->c_flags & OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT);
+
+	if (disk_mode != *globalhb)
+		ret = O2CB_ET_INVALID_HEARTBEAT_MODE;
+
+bail:
+	return ret;
+}
+
+static errcode_t o2cb_validate_cluster_name(struct o2cb_cluster_desc *desc)
+{
+	errcode_t ret;
+	char **clusters = NULL;
+
+	ret = o2cb_list_clusters(&clusters);
+	if (ret)
+		goto bail;
+
+	/* The first cluster is the default cluster */
+	if (!clusters[0] || strcmp(clusters[0], desc->c_cluster))
+		ret = O2CB_ET_INVALID_CLUSTER_NAME;
+
+	o2cb_free_cluster_list(clusters);
+
+bail:
+	return ret;
+}
+
+static errcode_t o2cb_validate_cluster_stack(struct o2cb_cluster_desc *desc)
 {
 	errcode_t err;
 	const char *name;
@@ -1640,7 +1693,7 @@ errcode_t o2cb_begin_group_join(struct o2cb_cluster_desc *cluster,
 	if (!current_stack)
 		return O2CB_ET_SERVICE_UNAVAILABLE;
 
-	err = o2cb_validate_cluster_desc(cluster);
+	err = o2cb_validate_cluster_stack(cluster);
 	if (err)
 		return err;
 
@@ -1666,7 +1719,7 @@ errcode_t o2cb_complete_group_join(struct o2cb_cluster_desc *cluster,
 	if (!current_stack)
 		return O2CB_ET_SERVICE_UNAVAILABLE;
 
-	err = o2cb_validate_cluster_desc(cluster);
+	err = o2cb_validate_cluster_stack(cluster);
 	if (err)
 		return err;
 
@@ -1692,7 +1745,7 @@ errcode_t o2cb_group_leave(struct o2cb_cluster_desc *cluster,
 	if (!current_stack)
 		return O2CB_ET_SERVICE_UNAVAILABLE;
 
-	err = o2cb_validate_cluster_desc(cluster);
+	err = o2cb_validate_cluster_stack(cluster);
 	if (err)
 		return err;
 
diff --git a/libo2cb/o2cb_err.et b/libo2cb/o2cb_err.et
index 978954d..af0e045 100644
--- a/libo2cb/o2cb_err.et
+++ b/libo2cb/o2cb_err.et
@@ -84,4 +84,7 @@ ec      O2CB_ET_INVALID_STACK_NAME,
 ec	O2CB_ET_UNKNOWN_REGION,
 	"Heartbeat region could not be found"
 
+ec	O2CB_ET_INVALID_HEARTBEAT_MODE,
+	"Active heartbeat mode does not match the configuration on disk"
+
 	end
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list