Jelajahi Sumber

Add CS_DISPATCH_ONE_NONBLOCKING dispatch type

Add missing option for dispatch, which fills gap in combination of
block/nonblock and one/all dispatch types. New type doesn't mask
CS_ERR_TRY_AGAIN, and it means "no message was processed".

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Jan Friesse 14 tahun lalu
induk
melakukan
9260efdf47
12 mengubah file dengan 86 tambahan dan 26 penghapusan
  1. 2 1
      include/corosync/corotypes.h
  2. 10 3
      lib/cfg.c
  3. 10 4
      lib/cmap.c
  4. 10 4
      lib/cpg.c
  5. 10 4
      lib/evs.c
  6. 12 5
      lib/quorum.c
  7. 12 5
      lib/votequorum.c
  8. 4 0
      man/cmap_dispatch.3
  9. 4 0
      man/cpg_dispatch.3
  10. 4 0
      man/evs_dispatch.3
  11. 4 0
      man/quorum_dispatch.3
  12. 4 0
      man/votequorum_dispatch.3

+ 2 - 1
include/corosync/corotypes.h

@@ -66,7 +66,8 @@ typedef struct {
 typedef enum {
 	CS_DISPATCH_ONE = 1,
 	CS_DISPATCH_ALL = 2,
-	CS_DISPATCH_BLOCKING = 3
+	CS_DISPATCH_BLOCKING = 3,
+	CS_DISPATCH_ONE_NONBLOCKING = 4
 } cs_dispatch_flags_t;
 
 #define CS_TRACK_CURRENT 0x01

+ 10 - 3
lib/cfg.c

@@ -158,9 +158,10 @@ corosync_cfg_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ALL
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_flags == CS_DISPATCH_ALL) {
+	if (dispatch_flags == CS_DISPATCH_ALL || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -176,6 +177,12 @@ corosync_cfg_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_flags == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -215,7 +222,7 @@ corosync_cfg_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_flags == CS_DISPATCH_ONE) {
+		if (dispatch_flags == CS_DISPATCH_ONE || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 10 - 4
lib/cmap.c

@@ -190,10 +190,10 @@ cs_error_t cmap_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
-	 * wait indefinitely for CS_DISPATCH_BLOCKING
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_types == CS_DISPATCH_ALL) {
+	if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -210,6 +210,12 @@ cs_error_t cmap_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_types == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -268,7 +274,7 @@ cs_error_t cmap_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_types == CS_DISPATCH_ONE) {
+		if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 10 - 4
lib/cpg.c

@@ -343,10 +343,10 @@ cs_error_t cpg_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
-	 * wait indefinately for CS_DISPATCH_BLOCKING
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_types == CS_DISPATCH_ALL) {
+	if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -363,6 +363,12 @@ cs_error_t cpg_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_types == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -471,7 +477,7 @@ cs_error_t cpg_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_types == CS_DISPATCH_ONE) {
+		if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 10 - 4
lib/evs.c

@@ -230,10 +230,10 @@ cs_error_t evs_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
-	 * wait indefinately for CS_DISPATCH_BLOCKING
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_types == CS_DISPATCH_ALL) {
+	if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -249,6 +249,12 @@ cs_error_t evs_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_types == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -310,7 +316,7 @@ cs_error_t evs_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_types == CS_DISPATCH_ONE) {
+		if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 12 - 5
lib/quorum.c

@@ -355,7 +355,8 @@ cs_error_t quorum_dispatch (
 
 	if (dispatch_types != CS_DISPATCH_ONE &&
 		dispatch_types != CS_DISPATCH_ALL &&
-		dispatch_types != CS_DISPATCH_BLOCKING) {
+		dispatch_types != CS_DISPATCH_BLOCKING &&
+		dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
 
 		return (CS_ERR_INVALID_PARAM);
 	}
@@ -367,10 +368,10 @@ cs_error_t quorum_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ONE or SA_DISPATCH_ALL and
-	 * wait indefinately for CS_DISPATCH_BLOCKING
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_types == CS_DISPATCH_ALL) {
+	if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -386,6 +387,12 @@ cs_error_t quorum_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_types == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -430,7 +437,7 @@ cs_error_t quorum_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_types == CS_DISPATCH_ONE) {
+		if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 12 - 5
lib/votequorum.c

@@ -429,7 +429,8 @@ cs_error_t votequorum_dispatch (
 
 	if (dispatch_types != CS_DISPATCH_ONE &&
 		dispatch_types != CS_DISPATCH_ALL &&
-		dispatch_types != CS_DISPATCH_BLOCKING) {
+		dispatch_types != CS_DISPATCH_BLOCKING &&
+		dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
 
 		return (CS_ERR_INVALID_PARAM);
 	}
@@ -441,10 +442,10 @@ cs_error_t votequorum_dispatch (
 	}
 
 	/*
-	 * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
-	 * wait indefinitely for CS_DISPATCH_BLOCKING
+	 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
+	 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
 	 */
-	if (dispatch_types == CS_DISPATCH_ALL) {
+	if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 		timeout = 0;
 	}
 
@@ -460,6 +461,12 @@ cs_error_t votequorum_dispatch (
 			goto error_put;
 		}
 		if (error == CS_ERR_TRY_AGAIN) {
+			if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
+				/*
+				 * Don't mask error
+				 */
+				goto error_put;
+			}
 			error = CS_OK;
 			if (dispatch_types == CS_DISPATCH_ALL) {
 				break; /* exit do while cont is 1 loop */
@@ -517,7 +524,7 @@ cs_error_t votequorum_dispatch (
 		/*
 		 * Determine if more messages should be processed
 		 */
-		if (dispatch_types == CS_DISPATCH_ONE) {
+		if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
 			cont = 0;
 		}
 	} while (cont);

+ 4 - 0
man/cmap_dispatch.3

@@ -72,6 +72,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks.
 Dispatch all callbacks blocking indefinitely.  This is used in a threaded
 program where a thread is created, and then cs_dispatch() is called immediately
 from the created thread to execute callbacks.
+.TP
+.B CS_DISPATCH_ONE_NONBLOCKING
+Dispatch at most one callback. If there is no pending callback,
+CS_ERR_TRY_AGAIN is returned.
 .PP
 It's needed to call
 .B cmap_track_add(3)

+ 4 - 0
man/cpg_dispatch.3

@@ -82,6 +82,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks.
 Dispatch all callbacks, blocking indefinitely.  This is used in a threaded
 program where a thread is created, and then cpg_dispatch() is called immediately
 from the created thread to execute callbacks.
+.TP
+.B CS_DISPATCH_ONE_NONBLOCKING
+Dispatch at most one callback. If there is no pending callback,
+CS_ERR_TRY_AGAIN is returned.
 
 .SH RETURN VALUE
 This call returns the CS_OK value if successful, otherwise an error is returned.

+ 4 - 0
man/evs_dispatch.3

@@ -82,6 +82,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks.
 Dispatch all callbacks blocking indefinately.  This is used in a threaded
 program where a thread is created, and then evs_dispatch() is called immediately
 from the created thread to execute callbacks.
+.TP
+.B CS_DISPATCH_ONE_NONBLOCKING
+Dispatch at most one callback. If there is no pending callback,
+CS_ERR_TRY_AGAIN is returned.
 
 .SH RETURN VALUE
 This call returns the CS_OK value if successful, otherwise an error is returned.

+ 4 - 0
man/quorum_dispatch.3

@@ -81,6 +81,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks.
 Dispatch all callbacks blocking indefinitely.  This is used in a threaded
 program where a thread is created, and then quorum_dispatch() is called immediately
 from the created thread to execute callbacks.
+.TP
+.B CS_DISPATCH_ONE_NONBLOCKING
+Dispatch at most one callback. If there is no pending callback,
+CS_ERR_TRY_AGAIN is returned.
 
 .SH RETURN VALUE
 This call returns the CS_OK value if successful, otherwise an error is returned.

+ 4 - 0
man/votequorum_dispatch.3

@@ -81,6 +81,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks.
 Dispatch all callbacks blocking indefinitely.  This is used in a threaded
 program where a thread is created, and then votequorum_dispatch() is called immediately
 from the created thread to execute callbacks.
+.TP
+.B CS_DISPATCH_ONE_NONBLOCKING
+Dispatch at most one callback. If there is no pending callback,
+CS_ERR_TRY_AGAIN is returned.
 
 .SH RETURN VALUE
 This call returns the CS_OK value if successful, otherwise an error is returned.