[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH][RFC] add cman_qinit to libcman



Hi guys,

during the process of killing ccsd I noticed that almost all services that
communicate with cman wait to talk to cman or for the cluster to quorate
implementing over and over loops here and there.

The patch in attachment (basically untested) implements a simple cman_w(ait)init
call within libcman to take care of all of the above in one single call and it
allows to set the kind of requested socket (admin or not), a connection to cman
timeout, a quorum timeout and the standard privdata for cman_init and
cman_admin_init.

If this patch could go in HEAD, it will simplify a lot code within all the
subsystems that need cman to be up and running and possibly a quorated cluster
before they can work.

Please consider for inclusion.

Thanks
Fabio
? libcman.so.2.1
Index: libcman.c
===================================================================
RCS file: /cvs/cluster/cluster/cman/lib/libcman.c,v
retrieving revision 1.37
diff -u -r1.37 libcman.c
--- libcman.c	18 Sep 2007 15:34:41 -0000	1.37
+++ libcman.c	5 Nov 2007 12:32:23 -0000
@@ -354,6 +354,58 @@
 	return open_socket(CLIENT_SOCKNAME, sizeof(CLIENT_SOCKNAME), privdata);
 }
 
+/* cman_w(ait)init
+ *
+ * @admin: set to 0 for standard socket, != 0 for admin socket
+ * @ctimeout: connection timeout in second to attempt to connect to cman. 0 = wait forever.
+ * @qtimeout: cluster quorum timeout in second. 0 = wait forever.
+ * @privdata: see cman_admin_init and cman_init.
+ */
+
+cman_handle_t cman_winit(int admin, int ctimeout, int qtimeout, void *privdata)
+{
+	cman_handle_t ch;
+	int i = 0;
+
+	if (!ctimeout)
+		ctimeout = -1;
+
+	while (ctimeout != i) {
+
+		if (admin) {
+			ch = cman_admin_init(privdata);
+		} else {
+			ch = cman_init(privdata);
+		}
+
+		if (ch) {
+			i = ctimeout;
+		} else {
+			sleep(1);
+			i++;
+		}	
+	}
+
+	if (!ch)
+		return ch;
+
+	if (!qtimeout)
+		qtimeout = -1;
+
+	i = 0;
+
+	while (qtimeout != i) {
+		if (cman_is_quorate(ch)) {
+			i = qtimeout;
+		} else {
+			sleep(1);
+			i++;
+		}
+	}
+
+	return ch;
+}
+
 int cman_finish(cman_handle_t handle)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
Index: libcman.h
===================================================================
RCS file: /cvs/cluster/cluster/cman/lib/libcman.h,v
retrieving revision 1.34
diff -u -r1.34 libcman.h
--- libcman.h	28 Aug 2007 13:30:23 -0000	1.34
+++ libcman.h	5 Nov 2007 12:32:23 -0000
@@ -197,6 +197,7 @@
  */
 cman_handle_t cman_init(void *privdata);
 cman_handle_t cman_admin_init(void *privdata);
+cman_handle_t cman_winit(int admin, int ctimeout, int qtimeout, void *privdata);
 int cman_finish(cman_handle_t handle);
 
 /* Update/retrieve the private data */

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]