Просмотр исходного кода

Add support for user specified timeouts from openais.conf

(Logical change 1.191)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@628 fd59a12c-fef9-0310-b244-a6a79926bd2f
Mark Haverkamp 21 лет назад
Родитель
Сommit
4c203d518d
7 измененных файлов с 141 добавлено и 16 удалено
  1. 2 1
      exec/main.c
  2. 28 1
      exec/parse.c
  3. 5 0
      exec/parse.h
  4. 4 2
      exec/totempg.c
  5. 2 1
      exec/totempg.h
  6. 80 10
      exec/totemsrp.c
  7. 20 1
      exec/totemsrp.h

+ 2 - 1
exec/main.c

@@ -1150,7 +1150,8 @@ int main (int argc, char **argv)
 		sizeof (private_key),
 		0,
 		0,
-		deliver_fn, confchg_fn);
+		deliver_fn, confchg_fn,
+		openais_config.timeouts);
 	
 	this_ip = &openais_config.interfaces[0].boundto;
 

+ 28 - 1
exec/parse.c

@@ -63,7 +63,8 @@ typedef enum {
 	MAIN_HEAD,
 	MAIN_NETWORK,
 	MAIN_LOGGING,
-	MAIN_KEY
+	MAIN_KEY,
+	MAIN_TIMEOUT
 } main_parse_t;
 
 void setSaNameT (SaNameT *name, char *str) {
@@ -416,6 +417,7 @@ extern int openais_main_config_read (char **error_string,
 	int network_parsed = 0;
 	int logging_parsed = 0;
 	int key_parsed = 0;
+	int timeout_parsed = 0;
 	char *loc;
 	int i;
 	int parse_done = 0;
@@ -477,6 +479,10 @@ extern int openais_main_config_read (char **error_string,
 			if (key_parsed == 0 && strstr_rs (line, "key{")) {
 				key_parsed = 1;
 				parse = MAIN_KEY;
+			} else
+			if (timeout_parsed == 0 && strstr_rs (line, "timeout{")) {
+				timeout_parsed = 1;
+				parse = MAIN_TIMEOUT;
 			} else {
 				goto parse_error;
 			}
@@ -550,6 +556,27 @@ extern int openais_main_config_read (char **error_string,
 				goto parse_error;
 			}
 			break;
+		case MAIN_TIMEOUT:
+			if ((loc = strstr_rs (line, "token:"))) {
+					openais_config->timeouts[TOTEM_TOKEN]= atoi(loc);
+			} else if ((loc = strstr_rs (line, "retransmit:"))) {
+					openais_config->timeouts[TOTEM_RETRANSMIT_TOKEN] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "join:"))) {
+					openais_config->timeouts[TOTEM_JOIN] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "consensus:"))) {
+					openais_config->timeouts[TOTEM_CONSENSUS] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "merge:"))) {
+					openais_config->timeouts[TOTEM_MERGE] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "downcheck:"))) {
+					openais_config->timeouts[TOTEM_DOWNCHECK] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "fail_recv_const:"))) {
+					openais_config->timeouts[TOTEM_FAIL_RECV_CONST] = atoi(loc);
+			} else if ((loc = strstr_rs (line, "}"))) {
+				parse = MAIN_HEAD;
+			} else {
+				goto parse_error;
+			}
+			break;
 
 		default:
 			assert (0 == 1); /* SHOULDN'T HAPPEN */

+ 5 - 0
exec/parse.h

@@ -74,6 +74,11 @@ struct openais_config {
 	 */
 	unsigned char *key;
 	int keylen;
+
+	/*
+	 * Timeout
+	 */
+	unsigned int timeouts[MAX_TOTEM_TIMEOUTS];
 };
 
 struct saAmfUnit {

+ 4 - 2
exec/totempg.c

@@ -453,7 +453,8 @@ int totempg_initialize (
 		struct in_addr *member_list, int member_list_entries,
 		struct in_addr *left_list, int left_list_entries,
 		struct in_addr *joined_list, int joined_list_entries,
-		struct memb_ring_id *ring_id))
+		struct memb_ring_id *ring_id),
+	unsigned int *timeouts)
 {
 	int res;
 
@@ -466,7 +467,8 @@ int totempg_initialize (
 		poll_handle,
 		private_key, private_key_len,
 		member_private, member_private_len,
-		totempg_deliver_fn, totempg_confchg_fn);
+		totempg_deliver_fn, totempg_confchg_fn, 
+		timeouts);
  
 	totemsrp_callback_token_create (&callback_token_received_handle, 
 		TOTEM_CALLBACK_TOKEN_RECEIVED,

+ 2 - 1
exec/totempg.h

@@ -81,7 +81,8 @@ int totempg_initialize (
 		struct in_addr *member_list, int member_list_entries,
 		struct in_addr *left_list, int left_list_entries,
 		struct in_addr *joined_list, int joined_list_entries,
-		struct memb_ring_id *ring_id));
+		struct memb_ring_id *ring_id),
+	unsigned int *timeouts);
 
 /*
  * Multicast a message

+ 80 - 10
exec/totemsrp.c

@@ -214,6 +214,21 @@ static int my_retrans_flg_count = 0;
 
 static unsigned int my_high_ring_delivered = 0;
 
+static unsigned int timeout_token = TIMEOUT_TOKEN;
+
+static unsigned int timeout_token_retransmit = TIMEOUT_TOKEN_RETRANSMIT;
+
+static unsigned int timeout_state_gather_join = TIMEOUT_STATE_GATHER_JOIN;
+
+static unsigned int timeout_state_gather_consensus = TIMEOUT_STATE_GATHER_CONSENSUS;
+
+static unsigned int timeout_merge_detect = TIMEOUT_MERGE_DETECT;
+
+static unsigned int timeout_downcheck = TIMEOUT_DOWNCHECK;
+
+static unsigned int fail_to_recv_const = FAIL_TO_RECV_CONST;
+
+
 struct token_callback_instance {
 	struct list_head list;
 	int (*callback_fn) (enum totem_callback_token_type type, void *);
@@ -573,8 +588,10 @@ int totemsrp_initialize (
 		struct in_addr *member_list, int member_list_entries,
 		struct in_addr *left_list, int left_list_entries,
 		struct in_addr *joined_list, int joined_list_entries,
-		struct memb_ring_id *ring_id))
+		struct memb_ring_id *ring_id),
+	unsigned int *timeouts)
 {
+	int i;
 
 	/*
 	 * Initialize random number generator for later use to generate salt
@@ -592,6 +609,57 @@ int totemsrp_initialize (
 	memset (&next_memb, 0, sizeof (struct sockaddr_in));
 	memset (iov_buffer, 0, PACKET_SIZE_MAX);
 
+	/*
+	 * Update our timeout values if they were specified in the openais.conf
+	 * file.
+	 */
+	for (i = TOTEM_TOKEN; i < MAX_TOTEM_TIMEOUTS; i++) {
+		if (!timeouts[i]) {
+			continue;
+		}
+		switch (i) {
+		case TOTEM_TOKEN:
+			timeout_token = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Token Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_RETRANSMIT_TOKEN:
+			timeout_token_retransmit = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Token Retransmit Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_JOIN:
+			timeout_state_gather_join = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Join Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_CONSENSUS:
+			timeout_state_gather_consensus = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Consensus Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_MERGE:
+			timeout_merge_detect = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Merge Detect Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_DOWNCHECK:
+			timeout_downcheck = timeouts[i];
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Downcheck Timeout set to %u ms\n", timeouts[i]);
+			break;
+		case TOTEM_FAIL_RECV_CONST:
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Failed To Receive Const set to %u\n", timeouts[i]);
+			fail_to_recv_const = timeouts[i];
+			break;
+		default:
+			totemsrp_log_printf (totemsrp_log_level_notice,
+					"Received unknown timeout type: %d\n", timeouts[i]);
+			break;
+		}
+	}
+
 	queue_init (&new_message_queue, NEW_MESSAGE_QUEUE_SIZE_MAX,
 		sizeof (struct message_item));
 
@@ -859,7 +927,7 @@ void reset_token_retransmit_timeout (void)
 {
 			poll_timer_delete (*totemsrp_poll_handle,
 				timer_orf_token_retransmit_timeout);
-			poll_timer_add (*totemsrp_poll_handle, TIMEOUT_TOKEN_RETRANSMIT, 0,
+			poll_timer_add (*totemsrp_poll_handle, timeout_token_retransmit, 0,
 				timer_function_token_retransmit_timeout,
 				&timer_orf_token_retransmit_timeout);
 
@@ -868,7 +936,7 @@ void reset_token_retransmit_timeout (void)
 void start_merge_detect_timeout (void)
 {
 	if (my_merge_detect_timeout_outstanding == 0) {
-		poll_timer_add (*totemsrp_poll_handle, TIMEOUT_MERGE_DETECT, 0,
+		poll_timer_add (*totemsrp_poll_handle, timeout_merge_detect, 0,
 			timer_function_merge_detect_timeout, &timer_merge_detect_timeout);
 		my_merge_detect_timeout_outstanding = 1;
 	}
@@ -937,7 +1005,7 @@ static void old_ring_state_reset (void)
 
 void reset_token_timeout (void) {
 			poll_timer_delete (*totemsrp_poll_handle, timer_orf_token_timeout);
-			poll_timer_add (*totemsrp_poll_handle, TIMEOUT_TOKEN, (void *)9999,
+			poll_timer_add (*totemsrp_poll_handle, timeout_token, (void *)9999,
 				timer_function_orf_token_timeout, &timer_orf_token_timeout);
 }
 
@@ -1021,7 +1089,7 @@ static void memb_timer_function_state_gather (void *data)
 		`*/
 		poll_timer_delete (*totemsrp_poll_handle, memb_timer_state_gather_join_timeout);
 	
-		poll_timer_add (*totemsrp_poll_handle, TIMEOUT_STATE_GATHER_JOIN, 0,
+		poll_timer_add (*totemsrp_poll_handle, timeout_state_gather_join, 0,
 			memb_timer_function_state_gather, &memb_timer_state_gather_join_timeout);
 		break;
 	}
@@ -1225,7 +1293,7 @@ static void memb_state_gather_enter (void)
 	 */
 	poll_timer_delete (*totemsrp_poll_handle, memb_timer_state_gather_join_timeout);
 
-	poll_timer_add (*totemsrp_poll_handle, TIMEOUT_STATE_GATHER_JOIN, 0,
+	poll_timer_add (*totemsrp_poll_handle, timeout_state_gather_join, 0,
 		memb_timer_function_state_gather, &memb_timer_state_gather_join_timeout);
 
 	/*
@@ -1234,7 +1302,7 @@ static void memb_state_gather_enter (void)
 	poll_timer_delete (*totemsrp_poll_handle,
 		memb_timer_state_gather_consensus_timeout);
 
-	poll_timer_add (*totemsrp_poll_handle, TIMEOUT_STATE_GATHER_CONSENSUS, 0,
+	poll_timer_add (*totemsrp_poll_handle, timeout_state_gather_consensus, 0,
 		memb_timer_function_gather_consensus_timeout,
 		&memb_timer_state_gather_consensus_timeout);
 
@@ -1293,7 +1361,9 @@ static void memb_state_commit_enter (struct memb_commit_token *commit_token)
 void memb_state_recovery_enter (struct memb_commit_token *commit_token)
 {
 	int i;
+#ifdef COMPILE_OUT
 	int local_received_flg = 1;
+#endif
 	unsigned int low_ring_aru;
 	unsigned int messages_originated = 0;
 
@@ -1888,7 +1958,7 @@ static void timer_function_netif_check_timeout ()
 		 * be detected by token loss when the interface is downed
 		 */
 		if (my_memb_entries <= 1) {
-			poll_timer_add (*totemsrp_poll_handle, TIMEOUT_DOWNCHECK, (void *)1,
+			poll_timer_add (*totemsrp_poll_handle, timeout_downcheck, (void *)1,
 				timer_function_netif_check_timeout,
 				&timer_netif_check_timeout);
 		}
@@ -1905,7 +1975,7 @@ static void timer_function_netif_check_timeout ()
 		*/
 		cancel_token_retransmit_timeout ();
 		cancel_token_timeout ();
-		poll_timer_add (*totemsrp_poll_handle, TIMEOUT_DOWNCHECK, (void *)1,
+		poll_timer_add (*totemsrp_poll_handle, timeout_downcheck, (void *)1,
 			timer_function_netif_check_timeout,
 			&timer_netif_check_timeout);
 	}
@@ -3144,7 +3214,7 @@ if (random () % 100 < 10) {
 			my_aru_count = 0;
 		}
 
-		if (my_aru_count > FAIL_TO_RECV_CONST &&
+		if (my_aru_count > fail_to_recv_const &&
 			token->aru_addr.s_addr != my_id.sin_addr.s_addr) {
 			
 printf ("FAILED TO RECEIVE\n");

+ 20 - 1
exec/totemsrp.h

@@ -77,7 +77,26 @@ int totemsrp_initialize (
 		struct in_addr *member_list, int member_list_entries,
 		struct in_addr *left_list, int left_list_entries,
 		struct in_addr *joined_list, int joined_list_entries,
-		struct memb_ring_id *ring_id));
+		struct memb_ring_id *ring_id),
+	unsigned int *timeouts);
+
+/*
+ * Array location of various timeouts as
+ * specified in openais.conf.  The last enum
+ * specifies the size of the timeouts array and
+ * needs to remain the last item in the list.
+ */
+enum {
+	TOTEM_TOKEN,
+	TOTEM_RETRANSMIT_TOKEN,
+	TOTEM_JOIN,
+	TOTEM_CONSENSUS,
+	TOTEM_MERGE,
+	TOTEM_DOWNCHECK,
+	TOTEM_FAIL_RECV_CONST,
+
+	MAX_TOTEM_TIMEOUTS	/* Last item */
+} totem_timeout_types;
 
 /*
  * Multicast a message