[Ocfs2-tools-commits] jlbec commits r1401 - in branches/cman-based: libo2cb ocfs2_controld

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Aug 22 18:48:49 PDT 2007


Author: jlbec
Date: 2007-08-22 18:48:48 -0700 (Wed, 22 Aug 2007)
New Revision: 1401

Modified:
   branches/cman-based/libo2cb/o2cb_abi.c
   branches/cman-based/ocfs2_controld/action.c
   branches/cman-based/ocfs2_controld/main.c
Log:

Teach ocfs2_controld to use the o2cb_create/remove_heartbeat_region()
functions.  This involves ocfs2_controld also initializing o2cb.

Also, fix a bug in o2cb_create_heartbeat_region() where we tried to create
the basename, not the full path.



Modified: branches/cman-based/libo2cb/o2cb_abi.c
===================================================================
--- branches/cman-based/libo2cb/o2cb_abi.c	2007-08-23 00:08:00 UTC (rev 1400)
+++ branches/cman-based/libo2cb/o2cb_abi.c	2007-08-23 01:48:48 UTC (rev 1401)
@@ -755,7 +755,7 @@
 		goto out;
 	}
 
-	ret = mkdir(desc->r_name,
+	ret = mkdir(region_path,
 		    S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
 	if (ret) {
 		switch (errno) {

Modified: branches/cman-based/ocfs2_controld/action.c
===================================================================
--- branches/cman-based/ocfs2_controld/action.c	2007-08-23 00:08:00 UTC (rev 1400)
+++ branches/cman-based/ocfs2_controld/action.c	2007-08-23 01:48:48 UTC (rev 1401)
@@ -272,7 +272,6 @@
 	};
 	struct mountgroup *mg = &mg_error;
 
-	fprintf(stderr, "%d \"%s\"\n", strlen(uuid), uuid);
 	log_debug("mount: MOUNT %s %s %s %s %s",
 		  fstype, uuid, cluster, device, mountpoint);
 
@@ -665,51 +664,24 @@
 	return find_memb_nodeid(mg, nodeid) != NULL;
 }
 
-static int path_exists(const char *path)
-{
-	struct stat buf;
 
-	if (stat(path, &buf) < 0) {
-		if (errno != ENOENT)
-			log_error("%s: stat failed: %d", path, errno);
-		return 0;
-	}
-	return 1;
-}
-
-static int create_path(char *path)
-{
-	mode_t old_umask;
-	int rv;
-
-	old_umask = umask(0022);
-	rv = mkdir(path, 0777);
-	umask(old_umask);
-
-	if (rv < 0) {
-		rv = -errno;
-		log_error("%s: mkdir failed: %d", path, -rv);
-		if (-rv == EEXIST)
-			rv = 0;
-	}
-	return rv;
-}
-
-#define REGION_FORMAT "/sys/kernel/config/cluster/%s/heartbeat/%s"
 static int initialize_region(struct mountgroup *mg)
 {
 	int rc = 0;
-	char path[PATH_MAX+1];
+	errcode_t err;
+	struct o2cb_region_desc desc = {
+		.r_name = mg->uuid,
+	};
 
-	snprintf(path, PATH_MAX, REGION_FORMAT, clustername, mg->uuid);
-
-	if (!path_exists(path)) {
-		rc = create_path(path);
-		if (rc) {
-			fill_error(mg, -rc, "Unable to create region %s",
-				   mg->uuid);
-			mg->group_leave_on_finish = 1;
-		}
+	err = o2cb_create_heartbeat_region(clustername, &desc);
+	if (err == O2CB_ET_REGION_EXISTS)
+		err = 0;
+	if (err) {
+		rc = -ENOENT;
+		fill_error(mg, -rc,
+			   "%s while trying to initialize region %s",
+			   error_message(err), mg->uuid);
+		mg->group_leave_on_finish = 1;
 	}
 
 	return rc;
@@ -718,17 +690,18 @@
 static int drop_region(struct mountgroup *mg)
 {
 	int rc = 0;
-	char path[PATH_MAX+1];
+	errcode_t err;
+	struct o2cb_region_desc desc = {
+		.r_name = mg->uuid,
+	};
 
-	snprintf(path, PATH_MAX, REGION_FORMAT, clustername, mg->uuid);
-
-	if (path_exists(path)) {
-		rc = rmdir(path);
-		if (rc) {
-			rc = -errno;
-			fill_error(mg, -rc, "Unable to remove region %s",
-				   mg->uuid);
-		}
+	err = o2cb_remove_heartbeat_region(clustername, &desc);
+	if (err) {
+		/* XXX: Should we ignore EBUSY or ENOENT? */
+		rc = -ENOENT;
+		fill_error(mg, -rc,
+			   "%s while trying to remove region %s",
+			   error_message(err), mg->uuid);
 	}
 
 	return rc;

Modified: branches/cman-based/ocfs2_controld/main.c
===================================================================
--- branches/cman-based/ocfs2_controld/main.c	2007-08-23 00:08:00 UTC (rev 1400)
+++ branches/cman-based/ocfs2_controld/main.c	2007-08-23 01:48:48 UTC (rev 1401)
@@ -22,6 +22,7 @@
  *  of the GNU General Public License v.2.
  */
 
+#include "o2cb.h"
 #include "o2cb_client_proto.h"
 #include "ocfs2_controld_internal.h"
 
@@ -645,10 +646,18 @@
 
 int main(int argc, char **argv)
 {
+	errcode_t err;
 	prog_name = argv[0];
 	INIT_LIST_HEAD(&mounts);
 	/* INIT_LIST_HEAD(&withdrawn_mounts); */
 
+	initialize_o2cb_error_table();
+	err = o2cb_init();
+	if (err) {
+		com_err(prog_name, err, "while trying to initialize o2cb");
+		return 1;
+	}
+
 	decode_arguments(argc, argv);
 
 	if (!daemon_debug_opt)




More information about the Ocfs2-tools-commits mailing list