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

Re: [Cluster-devel] [PATCH][RFC] add cman_winit to libcman



Sorry for the previous mail.. it had the wrong patch in attachment.

Here is the right one.

Fabio

Fabio Massimo Di Nitto wrote:
> 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
> 

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:50:43 -0000
@@ -354,6 +354,61 @@
 	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, -1 = do not wait.
+ * @qtimeout: cluster quorum timeout in second.
+ *            0 = wait forever, -1 = do not wait.
+ * @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)
+		i = 1;
+
+	while (ctimeout != i) {
+
+		if (admin) {
+			ch = cman_admin_init(privdata);
+		} else {
+			ch = cman_init(privdata);
+		}
+
+		if ((ch) || (ctimeout = -1)) {
+			i = ctimeout;
+		} else {
+			sleep(1);
+			i++;
+		}
+	}
+
+	if (!ch)
+		return ch;
+
+	if (!qtimeout) {
+		i = 1;
+	} else {
+		i = 0;
+	}
+
+	while (qtimeout != i) {
+		if ((cman_is_quorate(ch)) || (qtimeout = -1)) {
+			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:50:43 -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]