[Ocfs2-tools-commits] jlbec commits r1400 - in branches/cman-based/libo2cb: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Aug 22 17:08:02 PDT 2007


Author: jlbec
Date: 2007-08-22 17:08:00 -0700 (Wed, 22 Aug 2007)
New Revision: 1400

Modified:
   branches/cman-based/libo2cb/include/o2cb.h
   branches/cman-based/libo2cb/o2cb_abi.c
Log:

Export o2cb_create/remove_heartbeat_region().

The low-level o2cb_create/remove_heartbeat_region() functions are needed by
ocfs2_controld to create user regions.  Heartbeat2 might want it as well.
Everyone else should be using the join/leave API, which will communicate
with the proper actors to get the configfs stuff munged.

The functions correctly handle creating disk regions for the o2cb stack and
plain directory regions for the user heartbeat stack.

o2cb.h is also reorganized a little to comment on functions that are for
low-level use and those that are more useful for high-level programs.



Modified: branches/cman-based/libo2cb/include/o2cb.h
===================================================================
--- branches/cman-based/libo2cb/include/o2cb.h	2007-08-20 21:03:44 UTC (rev 1399)
+++ branches/cman-based/libo2cb/include/o2cb.h	2007-08-23 00:08:00 UTC (rev 1400)
@@ -63,6 +63,21 @@
 
 #define OCFS2_FS_NAME		"ocfs2"
 
+/* Expected use case for the region descriptor is to allocate it on
+ * the stack and completely fill it before calling
+ * begin_group_join().  Regular programs (not mount.ocfs2) should provide
+ * a mountpoint that does not begin with a '/'.  Eg, fsck could use ":fsck"
+ */
+struct o2cb_region_desc {
+	char		*r_name;	/* The uuid of the region */
+	char		*r_device_name; /* The device the region is on */
+	char		*r_service;	/* A program or mountpoint */
+	int		r_block_bytes;
+	uint64_t	r_start_block;
+	uint64_t	r_blocks;
+	int		r_persist;	/* Persist past process exit */
+};
+
 enum o2cb_known_stacks {
 	O2CB_STACK_NONE = 0,
 	O2CB_STACK_O2CB,
@@ -76,35 +91,45 @@
 
 errcode_t o2cb_get_stack(enum o2cb_known_stacks *stack);
 errcode_t o2cb_get_stack_name(const char **name);
+
+/*
+ * These functions modify the o2cb files.  They are "low level" and
+ * barely aware of the backend cluster stack.  You probably want to
+ * call o2cb_ctl(8) for configuration changes and group_join/leave for
+ * heartbeat startup.
+ */
 errcode_t o2cb_create_cluster(const char *cluster_name);
 errcode_t o2cb_remove_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_del_node(const char *cluster_name, const char *node_name);
+errcode_t o2cb_create_heartbeat_region(const char *cluster_name,
+				       struct o2cb_region_desc *desc);
+errcode_t o2cb_remove_heartbeat_region(const char *cluster_name,
+				       struct o2cb_region_desc *desc);
+errcode_t o2cb_get_region_ref(const char *region_name, int undo);
+errcode_t o2cb_put_region_ref(const char *region_name, int undo);
+errcode_t o2cb_num_region_refs(const char *region_name, int *num_refs);
+errcode_t o2cb_get_hb_ctl_path(char *buf, int count);
+errcode_t o2cb_get_hb_thread_pid (const char *cluster_name, 
+				  const char *region_name, 
+				  pid_t *pid);
 
+
+/* Get information about the current cluster */
 errcode_t o2cb_list_clusters(char ***clusters);
 void o2cb_free_cluster_list(char **clusters);
-
 errcode_t o2cb_list_nodes(char *cluster_name, char ***nodes);
 void o2cb_free_nodes_list(char **nodes);
+errcode_t o2cb_get_node_num(const char *cluster_name,
+			    const char *node_name,
+			    uint16_t *node_num);
 
-struct o2cb_region_desc {
-	char		*r_name;	/* The uuid of the region */
-	char		*r_device_name; /* The device the region is on */
-	char		*r_service;	/* A program or mountpoint */
-	int		r_block_bytes;
-	uint64_t	r_start_block;
-	uint64_t	r_blocks;
-	int		r_persist;	/* Persist past process exit */
-};
-
-/* Expected use case for the region descriptor is to allocate it on
- * the stack and completely fill it before calling
- * begin_group_join().  Regular programs (not mount.ocfs2) should provide
- * a mountpoint that does not begin with a '/'.  Eg, fsck could use ":fsck"
+/*
+ * Join or leave groups.  These functions are cluster stack aware and
+ * will do the right thing.
  */
 errcode_t o2cb_begin_group_join(const char *cluster_name,
 				struct o2cb_region_desc *desc);
@@ -114,21 +139,4 @@
 errcode_t o2cb_group_leave(const char *cluster_name,
 			   struct o2cb_region_desc *desc);
 
-errcode_t o2cb_get_hb_thread_pid (const char *cluster_name, 
-				  const char *region_name, 
-				  pid_t *pid);
-
-errcode_t o2cb_get_region_ref(const char *region_name,
-			      int undo);
-errcode_t o2cb_put_region_ref(const char *region_name,
-			      int undo);
-errcode_t o2cb_num_region_refs(const char *region_name,
-			       int *num_refs);
-
-errcode_t o2cb_get_node_num(const char *cluster_name,
-			    const char *node_name,
-			    uint16_t *node_num);
-
-errcode_t o2cb_get_hb_ctl_path(char *buf, int count);
-
 #endif  /* _O2CB_H */

Modified: branches/cman-based/libo2cb/o2cb_abi.c
===================================================================
--- branches/cman-based/libo2cb/o2cb_abi.c	2007-08-20 21:03:44 UTC (rev 1399)
+++ branches/cman-based/libo2cb/o2cb_abi.c	2007-08-23 00:08:00 UTC (rev 1400)
@@ -712,12 +712,8 @@
 	return 0;
 }
 
-static errcode_t o2cb_create_heartbeat_region(const char *cluster_name,
-					      const char *region_name,
-					      const char *device_name,
-					      int block_bytes,
-					      uint64_t start_block,
-					      uint64_t blocks)
+errcode_t o2cb_create_heartbeat_region(const char *cluster_name,
+				       struct o2cb_region_desc *desc)
 {
 	char _fake_cluster_name[NAME_MAX];
 	char region_path[PATH_MAX];
@@ -725,6 +721,9 @@
 	int ret, fd;
 	errcode_t err;
 
+	if (current_stack == O2CB_STACK_NONE)
+		return O2CB_ET_SERVICE_UNAVAILABLE;
+
 	if (!cluster_name) {
 		err = _fake_default_cluster(_fake_cluster_name);
 		if (err)
@@ -732,27 +731,31 @@
 		cluster_name = _fake_cluster_name;
 	}
 
+	if (current_stack == O2CB_STACK_O2CB) {
 #define O2CB_MAXIMUM_HEARTBEAT_BLOCKSIZE 4096
-	if (block_bytes > O2CB_MAXIMUM_HEARTBEAT_BLOCKSIZE) {
-		err = O2CB_ET_INVALID_BLOCK_SIZE;
-		goto out;
-	}
+		if (desc->r_block_bytes >
+		    O2CB_MAXIMUM_HEARTBEAT_BLOCKSIZE) {
+			err = O2CB_ET_INVALID_BLOCK_SIZE;
+			goto out;
+		}
 
 #define O2CB_MAX_NODE_COUNT 255
-	if (!blocks || (blocks > O2CB_MAX_NODE_COUNT)) {
-		err = O2CB_ET_INVALID_BLOCK_COUNT;
-		goto out;
+		if (!desc->r_blocks ||
+		    (desc->r_blocks > O2CB_MAX_NODE_COUNT)) {
+			err = O2CB_ET_INVALID_BLOCK_COUNT;
+			goto out;
+		}
 	}
 
 	ret = snprintf(region_path, PATH_MAX - 1,
 		       O2CB_FORMAT_HEARTBEAT_REGION,
-		       configfs_path, cluster_name, region_name);
+		       configfs_path, cluster_name, desc->r_name);
 	if (ret <= 0 || ret == PATH_MAX - 1) {
 		err = O2CB_ET_INTERNAL_FAILURE;
 		goto out;
 	}
 
-	ret = mkdir(region_path,
+	ret = mkdir(desc->r_name,
 		    S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
 	if (ret) {
 		switch (errno) {
@@ -783,40 +786,44 @@
 		goto out;
 	}
 
-	ret = snprintf(num_buf, NAME_MAX - 1, "%d", block_bytes);
+	if (current_stack != O2CB_STACK_O2CB)
+		goto out;
+
+	ret = snprintf(num_buf, NAME_MAX - 1, "%d", desc->r_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,
+	err = o2cb_set_region_attribute(cluster_name, desc->r_name,
 					"block_bytes", num_buf);
 	if (err)
 		goto out_rmdir;
 
-	ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64, start_block);
+	ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64,
+		       desc->r_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,
+	err = o2cb_set_region_attribute(cluster_name, desc->r_name,
 					"start_block", num_buf);
 	if (err)
 		goto out_rmdir;
 
-	ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64, blocks);
+	ret = snprintf(num_buf, NAME_MAX - 1, "%"PRIu64, desc->r_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,
+	err = o2cb_set_region_attribute(cluster_name, desc->r_name,
 					"blocks", num_buf);
 	if (err)
 		goto out_rmdir;
 
-	fd = open64(device_name, O_RDWR);
+	fd = open64(desc->r_device_name, O_RDWR);
 	if (fd < 0) {
 		switch (errno) {
 			default:
@@ -845,7 +852,7 @@
 		goto out_close;
 	}
 
-	err = o2cb_set_region_attribute(cluster_name, region_name,
+	err = o2cb_set_region_attribute(cluster_name, desc->r_name,
 					"dev", num_buf);
 
 out_close:
@@ -1091,14 +1098,17 @@
 	return ret;
 }
 
-static errcode_t o2cb_remove_heartbeat_region(const char *cluster_name,
-					      const char *region_name)
+errcode_t o2cb_remove_heartbeat_region(const char *cluster_name,
+				       struct o2cb_region_desc *desc)
 {
 	char _fake_cluster_name[NAME_MAX];
 	char region_path[PATH_MAX];
 	int ret;
 	errcode_t err = 0;
 
+	if (current_stack == O2CB_STACK_NONE)
+		return O2CB_ET_SERVICE_UNAVAILABLE;
+
 	if (!cluster_name) {
 		err = _fake_default_cluster(_fake_cluster_name);
 		if (err)
@@ -1108,7 +1118,7 @@
 
 	ret = snprintf(region_path, PATH_MAX - 1,
 		       O2CB_FORMAT_HEARTBEAT_REGION,
-		       configfs_path, cluster_name, region_name);
+		       configfs_path, cluster_name, desc->r_name);
 	if (ret <= 0 || ret == PATH_MAX - 1) {
 		err = O2CB_ET_INTERNAL_FAILURE;
 		goto out;
@@ -1183,8 +1193,7 @@
 	if (!hb_refs) {
 		/* XXX: If this fails, shouldn't we still destroy the
 		 * semaphore set? */
-		ret = o2cb_remove_heartbeat_region(cluster_name,
-						   desc->r_name);
+		ret = o2cb_remove_heartbeat_region(cluster_name, desc);
 		if (ret)
 			goto up;
 
@@ -1213,12 +1222,7 @@
 	if (ret)
 		return ret;
 
-	ret = o2cb_create_heartbeat_region(cluster_name,
-					   desc->r_name,
-					   desc->r_device_name,
-					   desc->r_block_bytes,
-					   desc->r_start_block,
-					   desc->r_blocks);
+	ret = o2cb_create_heartbeat_region(cluster_name, desc);
 	if (ret && ret != O2CB_ET_REGION_EXISTS)
 		goto up;
 




More information about the Ocfs2-tools-commits mailing list