cluster: master - cman: Make cman_notifyd use corosync calls rather than libcman

Christine Caulfield chrissie at fedoraproject.org
Thu Mar 11 10:27:00 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=8bdfd5ba128867b1ebd021fd34e51ce16beae56a
Commit:        8bdfd5ba128867b1ebd021fd34e51ce16beae56a
Parent:        f3f55aa3460c18d91d8ad21e7d5fc62c30619a42
Author:        Christine Caulfield <ccaulfie at redhat.com>
AuthorDate:    Thu Mar 11 10:25:58 2010 +0000
Committer:     Christine Caulfield <ccaulfie at redhat.com>
CommitterDate: Thu Mar 11 10:25:58 2010 +0000

cman: Make cman_notifyd use corosync calls rather than libcman

This is currently incomplete as it doesn't handle configuration updates,
which might need some additions to the confdb library

Signed-off-by: Christine Caulfield <ccaulfie at redhat.com>
---
 cman/notifyd/Makefile.am |    9 ++-
 cman/notifyd/main.c      |  252 +++++++++++++++++++++++++++++++---------------
 2 files changed, 178 insertions(+), 83 deletions(-)

diff --git a/cman/notifyd/Makefile.am b/cman/notifyd/Makefile.am
index edf66e6..5c80177 100644
--- a/cman/notifyd/Makefile.am
+++ b/cman/notifyd/Makefile.am
@@ -13,11 +13,16 @@ cmannotifyd_SOURCES	= main.c
 cmannotifyd_CPPFLAGS	= -D_GNU_SOURCE \
 			  -I$(top_srcdir)/common/liblogthread/ \
 			  -I$(top_srcdir)/config/libs/libccsconfdb/ \
-			  -I$(top_srcdir)/cman/services/cman/lib/
+			  $(cfg_CFLAGS)	\
+			  $(quorum_CFLAGS)	\
+			  $(confdb_CFLAGS)
+
 
 cmannotifyd_LDADD	= $(top_builddir)/common/liblogthread/liblogthread.la \
 			  $(top_builddir)/config/libs/libccsconfdb/libccs.la \
-			  $(top_builddir)/cman/services/cman/lib/libcman.la
+			  $(cfg_LIBS) \
+			  $(quorum_LIBS) \
+			  $(confdb_LIBS)
 
 $(notifyscript): $(notifyscript).in
 	cat $^ | sed \
diff --git a/cman/notifyd/main.c b/cman/notifyd/main.c
index 83e27f5..5c57b51 100644
--- a/cman/notifyd/main.c
+++ b/cman/notifyd/main.c
@@ -14,18 +14,20 @@
 #include <sys/wait.h>
 #include <sys/select.h>
 
-#include "libcman.h"
-#include "ccs.h"
+#include <corosync/cfg.h>
+#include <corosync/quorum.h>
+#include <corosync/confdb.h>
 #include "liblogthread.h"
+#include "ccs.h"
 
 #include "copyright.cf"
 
 int debug = 0;
 int daemonize = 1;
 int daemon_quit = 0;
-cman_handle_t cman_handle;
 int rr = 0;
 
+
 #define LOCKFILE_NAME	CLUSTERVARRUN "/cmannotifyd.pid"
 
 #define OPTION_STRING "hdfVr"
@@ -34,6 +36,46 @@ int rr = 0;
 #define MAX_ARGS	128
 #endif
 
+static corosync_cfg_handle_t cfg_handle;
+static quorum_handle_t quorum_handle;
+static confdb_handle_t confdb_handle;
+
+static void corosync_cfg_shutdown_callback (
+        corosync_cfg_handle_t cfg_handle,
+        corosync_cfg_shutdown_flags_t flags);
+
+static void quorum_notification_callback (
+        quorum_handle_t handle,
+        uint32_t quorate,
+        uint64_t ring_seq,
+        uint32_t view_list_entries,
+        uint32_t *view_list);
+
+static void confdb_object_create_callback (
+        confdb_handle_t handle,
+        hdb_handle_t parent_object_handle,
+        hdb_handle_t object_handle,
+        const void *name_pt,
+        size_t name_len);
+
+static corosync_cfg_callbacks_t cfg_callbacks =
+{
+	.corosync_cfg_state_track_callback = NULL,
+	.corosync_cfg_shutdown_callback = corosync_cfg_shutdown_callback
+};
+
+static quorum_callbacks_t quorum_callbacks =
+{
+	.quorum_notify_fn = quorum_notification_callback
+};
+
+static confdb_callbacks_t confdb_callbacks =
+{
+	.confdb_object_create_change_notify_fn = confdb_object_create_callback
+};
+
+
+
 static void print_usage(void)
 {
 	printf("Usage:\n\n");
@@ -283,125 +325,173 @@ out:
 		exit(EXIT_FAILURE);
 }
 
-static void cman_callback(cman_handle_t ch, void *private, int reason, int arg)
+static void corosync_cfg_shutdown_callback(corosync_cfg_handle_t handle,
+					   corosync_cfg_shutdown_flags_t flags)
 {
-	const char *str = NULL;
-
-	switch (reason) {
-	case CMAN_REASON_TRY_SHUTDOWN:
-		logt_print(LOG_DEBUG, "Received a cman shutdown request\n");
-		cman_replyto_shutdown(ch, 1);	/* allow cman to shutdown */
-		str = "CMAN_REASON_TRY_SHUTDOWN";
-		dispatch_notification(str, 0);
-		break;
-	case CMAN_REASON_STATECHANGE:
-		logt_print(LOG_DEBUG,
-			   "Received a cman statechange notification\n");
-		str = "CMAN_REASON_STATECHANGE";
-		dispatch_notification(str, &arg);
-		break;
-	case CMAN_REASON_CONFIG_UPDATE:
-		logt_print(LOG_DEBUG,
-			   "Received a cman config update notification\n");
-		init_logging(1);
-		str = "CMAN_REASON_CONFIG_UPDATE";
-		dispatch_notification(str, 0);
-		break;
-	}
+	logt_print(LOG_DEBUG, "Received a CFG shutdown request\n");
+
+	corosync_cfg_replyto_shutdown(handle, COROSYNC_CFG_SHUTDOWN_FLAG_YES);
+
+	dispatch_notification("CMAN_REASON_TRY_SHUTDOWN", 0);
 }
 
-static void byebye_cman(void)
+
+static void quorum_notification_callback(quorum_handle_t handle,
+					 uint32_t quorate,
+					 uint64_t ring_seq,
+					 uint32_t view_list_entries,
+					 uint32_t *view_list)
 {
-	if (!cman_handle)
-		return;
+	logt_print(LOG_DEBUG,
+		   "Received a quorum notification\n");
+	dispatch_notification("CMAN_REASON_STATECHANGE", quorate);
+}
 
-	cman_finish(cman_handle);
-	cman_handle = NULL;
+static void confdb_object_create_callback(confdb_handle_t handle,
+					  hdb_handle_t parent_object_handle,
+					  hdb_handle_t object_handle,
+					  const void *name_pt,
+					  size_t name_len)
+{
+	logt_print(LOG_DEBUG,
+		   "Received a config update notification\n");
+	init_logging(1);
+	dispatch_notification("CMAN_REASON_CONFIG_UPDATE", 0);
 }
 
-static void setup_cman(int forever)
+static void byebye_corosync(void)
+{
+	if (cfg_handle)
+	{
+		corosync_cfg_finalize(cfg_handle);
+		cfg_handle = NULL;
+	}
+	if (quorum_handle)
+	{
+		quorum_finalize(quorum_handle);
+		quorum_handle = NULL;
+	}
+	if (confdb_handle)
+	{
+		confdb_finalize(confdb_handle);
+		confdb_handle = NULL;
+	}
+}
+
+static void setup_corosync(int forever)
 {
 	int init = 0, active = 0;
+	cs_error_t cs_err;
 
 retry_init:
-	cman_handle = cman_init(NULL);
-	if (!cman_handle) {
-		if ((init++ < 5) || (forever)) {
-			if (daemon_quit)
-				goto out;
-
-			sleep(1);
-			goto retry_init;
-		}
-		logt_print(LOG_CRIT, "cman_init error %d\n", errno);
-		exit(EXIT_FAILURE);
-	}
 
-retry_active:
-	if (!cman_is_active(cman_handle)) {
-		if ((active++ < 5) || (forever)) {
-			if (daemon_quit)
-				goto out;
+	if (!cfg_handle) {
+		cs_err = corosync_cfg_initialize(&cfg_handle, &cfg_callbacks);
+		if (cs_err != CS_OK)
+			goto init_fail;
+	}
 
-			sleep(1);
-			goto retry_active;
-		}
-		logt_print(LOG_CRIT, "cman_is_active error %d\n", errno);
-		cman_finish(cman_handle);
-		exit(EXIT_FAILURE);
+	if (!quorum_handle) {
+		cs_err = quorum_initialize(&quorum_handle, &quorum_callbacks);
+		if (cs_err != CS_OK)
+			goto init_fail;
+		cs_err = quorum_trackstart(quorum_handle, CS_TRACK_CHANGES);
 	}
 
-	if (cman_start_notification(cman_handle, cman_callback) < 0) {
-		logt_print(LOG_CRIT, "cman_start_notification error %d\n", errno);
-		cman_finish(cman_handle);
-		exit(EXIT_FAILURE);
+	if (!confdb_handle) {
+		cs_err = confdb_initialize(&confdb_handle, &confdb_callbacks);
+		if (cs_err != CS_OK)
+			goto init_fail;
+		// TODO track changes
 	}
+	goto out_ok;
 
-	return;
+init_fail:
+	if ((init++ < 5) || (forever)) {
+		if (daemon_quit)
+			goto out;
+
+		sleep(1);
+		goto retry_init;
+	}
+	logt_print(LOG_CRIT, "corosync_init error %d\n", errno);
+	exit(EXIT_FAILURE);
 
 out:
-	byebye_cman();
+	byebye_corosync();
+out_ok:
 	exit(EXIT_SUCCESS);
 }
 
 static void loop(void)
 {
-	int cd_result, se_result;
+	cs_error_t cs_result;
+	int select_result;
 	fd_set read_fds;
-	int cman_fd;
+	int cfg_fd;
+	int quorum_fd;
+	int confdb_fd;
 
 	do {
 		FD_ZERO (&read_fds);
-		cman_fd = cman_get_fd(cman_handle);
-		FD_SET (cman_fd, &read_fds);
-		se_result = select((cman_fd + 1), &read_fds, 0, 0, 0);
+		corosync_cfg_fd_get(cfg_handle, &cfg_fd);
+		confdb_fd_get(confdb_handle, &confdb_fd);
+		quorum_fd_get(quorum_handle, &quorum_fd);
+		FD_SET (cfg_fd, &read_fds);
+		FD_SET (confdb_fd, &read_fds);
+		FD_SET (quorum_fd, &read_fds);
+		select_result = select(FD_SETSIZE, &read_fds, 0, 0, 0);
 
 		if (daemon_quit)
 			goto out;
 
-		if (se_result == -1) {
+		if (select_result == -1) {
 			logt_print(LOG_CRIT, "Unable to select on cman_fd: %s\n", strerror(errno));
-			byebye_cman();
+			byebye_corosync();
 			exit(EXIT_FAILURE);
 		}
 
-		if (FD_ISSET(cman_fd, &read_fds)) {
-			cd_result = 1;
-			while (cd_result > 0) {
-				cd_result = cman_dispatch(cman_handle, CMAN_DISPATCH_ONE);
-				if (cd_result == -1 && errno == EHOSTDOWN) {
-					byebye_cman();
-					logt_print(LOG_DEBUG, "waiting for cman to reappear..\n");
-					setup_cman(1);
-					logt_print(LOG_DEBUG, "cman is back..\n");
+		if (FD_ISSET(cfg_fd, &read_fds)) {
+			cs_result = CS_OK;
+			while (cs_result == CS_OK) {
+				cs_result = corosync_cfg_dispatch(cfg_handle, CS_DISPATCH_ONE);
+				if (cs_result != CS_OK) {
+					byebye_corosync();
+					logt_print(LOG_DEBUG, "waiting for corosync to reappear..\n");
+					setup_corosync(1);
+					logt_print(LOG_DEBUG, "corosync is back..\n");
+				}
+			}
+		}
+		if (FD_ISSET(confdb_fd, &read_fds)) {
+			cs_result = CS_OK;
+			while (cs_result == CS_OK) {
+				cs_result = confdb_dispatch(confdb_handle, CS_DISPATCH_ONE);
+				if (cs_result != CS_OK) {
+					byebye_corosync();
+					logt_print(LOG_DEBUG, "waiting for corosync to reappear..\n");
+					setup_corosync(1);
+					logt_print(LOG_DEBUG, "corosync is back..\n");
+				}
+			}
+		}
+		if (FD_ISSET(quorum_fd, &read_fds)) {
+			cs_result = CS_OK;
+			while (cs_result == CS_OK) {
+				cs_result = quorum_dispatch(quorum_handle, CS_DISPATCH_ONE);
+				if (cs_result != CS_OK) {
+					byebye_corosync();
+					logt_print(LOG_DEBUG, "waiting for corosync to reappear..\n");
+					setup_corosync(1);
+					logt_print(LOG_DEBUG, "corosync is back..\n");
 				}
 			}
 		}
-	} while (se_result && !daemon_quit);
+	} while (select_result && !daemon_quit);
 
 out:
 	logt_print(LOG_DEBUG, "shutting down...\n");
-	byebye_cman();
+	byebye_corosync();
 }
 
 int main(int argc, char **argv)
@@ -421,7 +511,7 @@ int main(int argc, char **argv)
 	if (rr)
 		set_scheduler();
 
-	setup_cman(0);
+	setup_corosync(0);
 	loop();
 
 	return 0;


More information about the cluster-commits mailing list