41 #include <sys/types.h>
43 #include <sys/socket.h>
46 #include <sys/ioctl.h>
47 #include <sys/param.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
64 #include <qb/qbdefs.h>
65 #include <qb/qbloop.h>
66 #define LOGSYS_UTILS_ONLY 1
75 unsigned int msg_len);
112 void * (*initialize) (
118 unsigned int iface_no,
121 unsigned int msg_len);
126 unsigned int msg_len);
131 unsigned int msg_len);
135 unsigned int iface_no,
138 unsigned int msg_len,
139 unsigned int token_seqid);
144 unsigned int msg_len);
162 unsigned int iface_no);
166 unsigned int iface_no);
174 unsigned int iface_no);
179 unsigned int iface_no);
183 #define STATUS_STR_LEN 512
198 unsigned int msg_len);
203 unsigned int iface_no);
208 unsigned int *token_is);
233 const char *
function,
258 unsigned int iface_no,
int is_faulty);
263 static void none_mcast_recv (
265 unsigned int iface_no,
268 unsigned int msg_len);
270 static void none_mcast_noflush_send (
273 unsigned int msg_len);
275 static void none_mcast_flush_send (
278 unsigned int msg_len);
280 static void none_token_recv (
282 unsigned int iface_no,
285 unsigned int msg_len,
286 unsigned int token_seqid);
288 static void none_token_send (
291 unsigned int msg_len);
293 static void none_recv_flush (
296 static void none_send_flush (
299 static void none_iface_check (
302 static void none_processor_count_set (
304 unsigned int processor_count_set);
306 static void none_token_target_set (
309 unsigned int iface_no);
311 static void none_ring_reenable (
313 unsigned int iface_no);
315 static int none_mcast_recv_empty (
318 static int none_member_add (
321 unsigned int iface_no);
323 static int none_member_remove (
326 unsigned int iface_no);
330 static void *passive_instance_initialize (
334 static void passive_mcast_recv (
336 unsigned int iface_no,
339 unsigned int msg_len);
341 static void passive_mcast_noflush_send (
344 unsigned int msg_len);
346 static void passive_mcast_flush_send (
349 unsigned int msg_len);
351 static void passive_monitor (
353 unsigned int iface_no,
354 int is_token_recv_count);
356 static void passive_token_recv (
358 unsigned int iface_no,
361 unsigned int msg_len,
362 unsigned int token_seqid);
364 static void passive_token_send (
367 unsigned int msg_len);
369 static void passive_recv_flush (
372 static void passive_send_flush (
375 static void passive_iface_check (
378 static void passive_processor_count_set (
380 unsigned int processor_count_set);
382 static void passive_token_target_set (
385 unsigned int iface_no);
387 static void passive_ring_reenable (
389 unsigned int iface_no);
391 static int passive_mcast_recv_empty (
394 static int passive_member_add (
397 unsigned int iface_no);
399 static int passive_member_remove (
402 unsigned int iface_no);
406 static void *active_instance_initialize (
410 static void active_mcast_recv (
412 unsigned int iface_no,
415 unsigned int msg_len);
417 static void active_mcast_noflush_send (
420 unsigned int msg_len);
422 static void active_mcast_flush_send (
425 unsigned int msg_len);
427 static void active_token_recv (
429 unsigned int iface_no,
432 unsigned int msg_len,
433 unsigned int token_seqid);
435 static void active_token_send (
438 unsigned int msg_len);
440 static void active_recv_flush (
443 static void active_send_flush (
446 static void active_iface_check (
449 static void active_processor_count_set (
451 unsigned int processor_count_set);
453 static void active_token_target_set (
456 unsigned int iface_no);
458 static void active_ring_reenable (
460 unsigned int iface_no);
462 static int active_mcast_recv_empty (
465 static int active_member_add (
468 unsigned int iface_no);
470 static int active_member_remove (
473 unsigned int iface_no);
475 static void active_timer_expired_token_start (
478 static void active_timer_expired_token_cancel (
481 static void active_timer_problem_decrementer_start (
484 static void active_timer_problem_decrementer_cancel (
490 #define MESSAGE_TYPE_RING_TEST_ACTIVE 6
491 #define MESSAGE_TYPE_RING_TEST_ACTIVATE 7
493 #define ENDIAN_LOCAL 0xff22
504 #define ARR_SEQNO_START_TOKEN 0x0
517 #define PASSIVE_RECV_COUNT_THRESHOLD (INT_MAX / 2)
536 .mcast_recv = none_mcast_recv,
537 .mcast_noflush_send = none_mcast_noflush_send,
538 .mcast_flush_send = none_mcast_flush_send,
539 .token_recv = none_token_recv,
540 .token_send = none_token_send,
541 .recv_flush = none_recv_flush,
542 .send_flush = none_send_flush,
543 .iface_check = none_iface_check,
544 .processor_count_set = none_processor_count_set,
545 .token_target_set = none_token_target_set,
546 .ring_reenable = none_ring_reenable,
547 .mcast_recv_empty = none_mcast_recv_empty,
548 .member_add = none_member_add,
549 .member_remove = none_member_remove
554 .initialize = passive_instance_initialize,
555 .mcast_recv = passive_mcast_recv,
556 .mcast_noflush_send = passive_mcast_noflush_send,
557 .mcast_flush_send = passive_mcast_flush_send,
558 .token_recv = passive_token_recv,
559 .token_send = passive_token_send,
560 .recv_flush = passive_recv_flush,
561 .send_flush = passive_send_flush,
562 .iface_check = passive_iface_check,
563 .processor_count_set = passive_processor_count_set,
564 .token_target_set = passive_token_target_set,
565 .ring_reenable = passive_ring_reenable,
566 .mcast_recv_empty = passive_mcast_recv_empty,
567 .member_add = passive_member_add,
568 .member_remove = passive_member_remove
573 .initialize = active_instance_initialize,
574 .mcast_recv = active_mcast_recv,
575 .mcast_noflush_send = active_mcast_noflush_send,
576 .mcast_flush_send = active_mcast_flush_send,
577 .token_recv = active_token_recv,
578 .token_send = active_token_send,
579 .recv_flush = active_recv_flush,
580 .send_flush = active_send_flush,
581 .iface_check = active_iface_check,
582 .processor_count_set = active_processor_count_set,
583 .token_target_set = active_token_target_set,
584 .ring_reenable = active_ring_reenable,
585 .mcast_recv_empty = active_mcast_recv_empty,
586 .member_add = active_member_add,
587 .member_remove = active_member_remove
596 #define RRP_ALGOS_COUNT 3
598 #define log_printf(level, format, args...) \
600 rrp_instance->totemrrp_log_printf ( \
601 level, rrp_instance->totemrrp_subsys_id, \
602 __FUNCTION__, __FILE__, __LINE__, \
607 unsigned int iface_no,
int is_faulty)
609 rrp_instance->
stats.
faulty[iface_no] = (is_faulty ? 1 : 0);
621 static void timer_function_test_ring_timeout (
void *context)
625 unsigned int *faulty = NULL;
626 int iface_no = deliver_fn_context->
iface_no;
637 assert (faulty != NULL);
639 if (faulty[iface_no] == 1) {
648 (
void *)deliver_fn_context,
649 timer_function_test_ring_timeout,
658 static void none_mcast_recv (
660 unsigned int iface_no,
663 unsigned int msg_len)
671 static void none_mcast_flush_send (
674 unsigned int msg_len)
679 static void none_mcast_noflush_send (
682 unsigned int msg_len)
687 static void none_token_recv (
689 unsigned int iface_no,
692 unsigned int msg_len,
701 static void none_token_send (
704 unsigned int msg_len)
726 static void none_processor_count_set (
728 unsigned int processor_count)
734 static void none_token_target_set (
737 unsigned int iface_no)
742 static void none_ring_reenable (
744 unsigned int iface_no)
751 static int none_mcast_recv_empty (
761 static int none_member_add (
764 unsigned int iface_no)
771 static int none_member_remove (
774 unsigned int iface_no)
785 void *passive_instance_initialize (
798 instance->
faulty = malloc (
sizeof (
int) * interface_count);
799 if (instance->
faulty == 0) {
804 memset (instance->
faulty, 0, sizeof (
int) * interface_count);
806 for (i = 0; i < interface_count; i++) {
807 stats_set_interface_faulty (rrp_instance, i, 0);
830 return ((
void *)instance);
833 static void timer_function_passive_token_expired (
void *context)
840 passive_instance->
token,
854 static void passive_timer_expired_token_start (
855 struct passive_instance *passive_instance)
861 (
void *)passive_instance,
862 timer_function_passive_token_expired,
866 static void passive_timer_expired_token_cancel (
867 struct passive_instance *passive_instance)
902 static void passive_monitor (
904 unsigned int iface_no,
905 int is_token_recv_count)
907 struct passive_instance *passive_instance = (
struct passive_instance *)rrp_instance->
rrp_algo_instance;
908 unsigned int *recv_count;
911 unsigned int min_all, min_active;
912 unsigned int threshold;
917 if (is_token_recv_count) {
925 recv_count[iface_no] += 1;
929 if (
max < recv_count[i]) {
938 min_all = min_active = recv_count[iface_no];
941 if (recv_count[i] < min_all) {
942 min_all = recv_count[i];
945 if (passive_instance->
faulty[i] == 0 &&
946 recv_count[i] < min_active) {
947 min_active = recv_count[i];
956 recv_count[i] -= min_all;
964 if (passive_instance->
faulty[i] == 0) {
965 recv_count[i] -= min_active;
976 if (
max < recv_count[i]) {
983 if ((passive_instance->
faulty[i] == 0) &&
984 (
max - recv_count[i] > threshold)) {
985 passive_instance->
faulty[i] = 1;
991 timer_function_test_ring_timeout,
994 stats_set_interface_faulty (rrp_instance, i, passive_instance->
faulty[i]);
997 "Marking ringid %u interface %s FAULTY",
1003 rrp_instance->
status[i]);
1008 static void passive_mcast_recv (
1010 unsigned int iface_no,
1013 unsigned int msg_len)
1015 struct passive_instance *passive_instance = (
struct passive_instance *)rrp_instance->
rrp_algo_instance;
1029 passive_instance->
token,
1031 passive_timer_expired_token_cancel (passive_instance);
1034 passive_monitor (rrp_instance, iface_no, 0);
1037 static void passive_mcast_flush_send (
1040 unsigned int msg_len)
1042 struct passive_instance *passive_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1048 }
while ((i <= instance->interface_count) && (passive_instance->
faulty[passive_instance->
msg_xmit_iface] == 1));
1050 if (i <= instance->interface_count) {
1055 static void passive_mcast_noflush_send (
1058 unsigned int msg_len)
1060 struct passive_instance *passive_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1066 }
while ((i <= instance->interface_count) && (passive_instance->
faulty[passive_instance->
msg_xmit_iface] == 1));
1068 if (i <= instance->interface_count) {
1073 static void passive_token_recv (
1075 unsigned int iface_no,
1078 unsigned int msg_len,
1079 unsigned int token_seq)
1081 struct passive_instance *passive_instance = (
struct passive_instance *)rrp_instance->
rrp_algo_instance;
1091 memcpy (passive_instance->
token, msg, msg_len);
1092 passive_timer_expired_token_start (passive_instance);
1096 passive_monitor (rrp_instance, iface_no, 1);
1099 static void passive_token_send (
1102 unsigned int msg_len)
1104 struct passive_instance *passive_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1110 }
while ((i <= instance->interface_count) && (passive_instance->
faulty[passive_instance->
token_xmit_iface] == 1));
1112 if (i <= instance->interface_count) {
1122 struct passive_instance *rrp_algo_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1126 if (rrp_algo_instance->
faulty[i] == 0) {
1135 struct passive_instance *rrp_algo_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1139 if (rrp_algo_instance->
faulty[i] == 0) {
1148 struct passive_instance *rrp_algo_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1152 if (rrp_algo_instance->
faulty[i] == 0) {
1159 static void passive_processor_count_set (
1161 unsigned int processor_count)
1163 struct passive_instance *rrp_algo_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1167 if (rrp_algo_instance->
faulty[i] == 0) {
1175 static void passive_token_target_set (
1178 unsigned int iface_no)
1183 static int passive_mcast_recv_empty (
1187 int msgs_emptied = 0;
1200 return (msgs_emptied);
1203 static int passive_member_add (
1206 unsigned int iface_no)
1213 static int passive_member_remove (
1216 unsigned int iface_no)
1224 static void passive_ring_reenable (
1226 unsigned int iface_no)
1228 struct passive_instance *rrp_algo_instance = (
struct passive_instance *)instance->
rrp_algo_instance;
1237 memset (rrp_algo_instance->
faulty, 0, sizeof (
unsigned int) *
1240 stats_set_interface_faulty (instance, i, 0);
1243 rrp_algo_instance->
faulty[iface_no] = 0;
1244 stats_set_interface_faulty (instance, iface_no, 0);
1251 void *active_instance_initialize (
1253 int interface_count)
1259 if (instance == 0) {
1264 instance->
faulty = malloc (
sizeof (
int) * interface_count);
1265 if (instance->
faulty == 0) {
1270 memset (instance->
faulty, 0, sizeof (
unsigned int) * interface_count);
1272 for (i = 0; i < interface_count; i++) {
1273 stats_set_interface_faulty (rrp_instance, i, 0);
1283 memset (instance->
last_token_recv, 0, sizeof (
unsigned int) * interface_count);
1293 memset (instance->
counter_problems, 0, sizeof (
unsigned int) * interface_count);
1304 return ((
void *)instance);
1306 static void timer_function_active_problem_decrementer (
void *context)
1310 unsigned int problem_found = 0;
1319 "ring %d active with no faults", i);
1322 "Decrementing problem counter for iface %s to [%d of %d]",
1330 rrp_instance->
status[i]);
1333 if (problem_found) {
1334 active_timer_problem_decrementer_start (active_instance);
1340 static void timer_function_active_token_expired (
void *context)
1342 struct active_instance *active_instance = (
struct active_instance *)context;
1351 active_timer_problem_decrementer_start (active_instance);
1354 "Incrementing problem counter for seqid %d iface %s to [%d of %d]",
1362 rrp_instance->
status[i]);
1367 active_instance->
faulty[i] == 0) {
1368 active_instance->
faulty[i] = 1;
1374 timer_function_test_ring_timeout,
1377 stats_set_interface_faulty (rrp_instance, i, active_instance->
faulty[i]);
1380 "Marking seqid %d ringid %u interface %s FAULTY",
1387 rrp_instance->
status[i]);
1388 active_timer_problem_decrementer_cancel (active_instance);
1394 active_instance->
token,
1398 static void active_timer_expired_token_start (
1399 struct active_instance *active_instance)
1405 (
void *)active_instance,
1406 timer_function_active_token_expired,
1410 static void active_timer_expired_token_cancel (
1411 struct active_instance *active_instance)
1418 static void active_timer_problem_decrementer_start (
1419 struct active_instance *active_instance)
1425 (
void *)active_instance,
1426 timer_function_active_problem_decrementer,
1430 static void active_timer_problem_decrementer_cancel (
1431 struct active_instance *active_instance)
1442 static void active_mcast_recv (
1444 unsigned int iface_no,
1447 unsigned int msg_len)
1455 static void active_mcast_flush_send (
1458 unsigned int msg_len)
1461 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1464 if (rrp_algo_instance->
faulty[i] == 0) {
1470 static void active_mcast_noflush_send (
1473 unsigned int msg_len)
1476 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1479 if (rrp_algo_instance->
faulty[i] == 0) {
1485 static void active_token_recv (
1487 unsigned int iface_no,
1490 unsigned int msg_len,
1491 unsigned int token_seq)
1494 struct active_instance *active_instance = (
struct active_instance *)rrp_instance->
rrp_algo_instance;
1497 if (sq_lt_compare (active_instance->
last_token_seq, token_seq)) {
1498 memcpy (active_instance->
token, msg, msg_len);
1505 active_timer_expired_token_start (active_instance);
1518 active_instance->
faulty[i] == 0) {
1522 active_timer_expired_token_cancel (active_instance);
1531 static void active_token_send (
1534 unsigned int msg_len)
1536 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1540 if (rrp_algo_instance->
faulty[i] == 0) {
1551 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1555 if (rrp_algo_instance->
faulty[i] == 0) {
1564 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1568 if (rrp_algo_instance->
faulty[i] == 0) {
1575 static int active_member_add (
1578 unsigned int iface_no)
1585 static int active_member_remove (
1588 unsigned int iface_no)
1597 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1601 if (rrp_algo_instance->
faulty[i] == 0) {
1608 static void active_processor_count_set (
1610 unsigned int processor_count)
1612 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1616 if (rrp_algo_instance->
faulty[i] == 0) {
1624 static void active_token_target_set (
1627 unsigned int iface_no)
1632 static int active_mcast_recv_empty (
1636 int msgs_emptied = 0;
1649 return (msgs_emptied);
1652 static void active_ring_reenable (
1654 unsigned int iface_no)
1656 struct active_instance *rrp_algo_instance = (
struct active_instance *)instance->
rrp_algo_instance;
1660 memset (rrp_algo_instance->
last_token_recv, 0, sizeof (
unsigned int) *
1662 memset (rrp_algo_instance->
faulty, 0, sizeof (
unsigned int) *
1668 stats_set_interface_faulty (instance, i, 0);
1672 rrp_algo_instance->
faulty[iface_no] = 0;
1675 stats_set_interface_faulty (instance, iface_no, 0);
1684 static int totemrrp_algorithm_set (
1688 unsigned int res = -1;
1692 if (strcmp (totem_config->
rrp_mode, rrp_algos[i]->
name) == 0) {
1694 if (rrp_algos[i]->initialize) {
1706 "ring %d active with no faults", i);
1714 unsigned int msg_len)
1716 unsigned int token_seqid;
1717 unsigned int token_is;
1719 struct deliver_fn_context *deliver_fn_context = (
struct deliver_fn_context *)context;
1735 "received message requesting test of ring now active");
1738 test_active_msg_endian_convert(hdr, &tmp_msg);
1765 "Automatically recovered ring %d", hdr->
ring_number);
1768 test_active_msg_endian_convert(hdr, &tmp_msg);
1807 struct deliver_fn_context *deliver_fn_context = (
struct deliver_fn_context *)context;
1830 static void rrp_target_set_completed (
void *context)
1832 struct deliver_fn_context *deliver_fn_context = (
struct deliver_fn_context *)context;
1846 qb_loop_t *poll_handle,
1848 struct totem_config *totem_config,
1852 void (*deliver_fn) (
1855 unsigned int msg_len),
1857 void (*iface_change_fn) (
1860 unsigned int iface_no),
1862 void (*token_seqid_get) (
1864 unsigned int *seqid,
1865 unsigned int *token_is),
1867 unsigned int (*msgs_missing) (
void),
1869 void (*target_set_completed) (
void *context))
1876 if (instance == 0) {
1880 totemrrp_instance_initialize (instance);
1887 res = totemrrp_algorithm_set (
1929 struct deliver_fn_context *deliver_fn_context;
1931 deliver_fn_context = malloc (
sizeof (
struct deliver_fn_context));
1932 assert (deliver_fn_context);
1944 (
void *)deliver_fn_context,
1947 rrp_target_set_completed);
1963 assert (instance != NULL);
1970 assert (instance != NULL);
1976 unsigned int processor_count)
1989 unsigned int iface_no)
2016 unsigned int msg_len)
2027 unsigned int msg_len)
2041 unsigned int msg_len)
2070 unsigned int *iface_count)
2073 *status = instance->
status;
2084 const char *cipher_type,
2085 const char *hash_type)
2103 unsigned int iface_no)
2114 "ring %d active with no faults", i);
2118 "ring %d active with no faults", iface_no);