totemrrp.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <assert.h>
  37. #include <pthread.h>
  38. #include <sys/mman.h>
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41. #include <sys/socket.h>
  42. #include <netdb.h>
  43. #include <sys/un.h>
  44. #include <sys/ioctl.h>
  45. #include <sys/param.h>
  46. #include <netinet/in.h>
  47. #include <arpa/inet.h>
  48. #include <unistd.h>
  49. #include <fcntl.h>
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52. #include <errno.h>
  53. #include <sched.h>
  54. #include <time.h>
  55. #include <sys/time.h>
  56. #include <sys/poll.h>
  57. #include <limits.h>
  58. #include <corosync/sq.h>
  59. #include <corosync/list.h>
  60. #include <corosync/swab.h>
  61. #include <qb/qbdefs.h>
  62. #include <qb/qbloop.h>
  63. #define LOGSYS_UTILS_ONLY 1
  64. #include <corosync/logsys.h>
  65. #include "totemnet.h"
  66. #include "totemrrp.h"
  67. void rrp_deliver_fn (
  68. void *context,
  69. const void *msg,
  70. unsigned int msg_len);
  71. void rrp_iface_change_fn (
  72. void *context,
  73. const struct totem_ip_address *iface_addr);
  74. struct totemrrp_instance;
  75. struct passive_instance {
  76. struct totemrrp_instance *rrp_instance;
  77. unsigned int *faulty;
  78. unsigned int *token_recv_count;
  79. unsigned int *mcast_recv_count;
  80. unsigned char token[15000];
  81. unsigned int token_len;
  82. qb_loop_timer_handle timer_expired_token;
  83. qb_loop_timer_handle timer_problem_decrementer;
  84. void *totemrrp_context;
  85. unsigned int token_xmit_iface;
  86. unsigned int msg_xmit_iface;
  87. };
  88. struct active_instance {
  89. struct totemrrp_instance *rrp_instance;
  90. unsigned int *faulty;
  91. unsigned int *last_token_recv;
  92. unsigned int *counter_problems;
  93. unsigned char token[15000];
  94. unsigned int token_len;
  95. unsigned int last_token_seq;
  96. qb_loop_timer_handle timer_expired_token;
  97. qb_loop_timer_handle timer_problem_decrementer;
  98. void *totemrrp_context;
  99. };
  100. struct rrp_algo {
  101. const char *name;
  102. void * (*initialize) (
  103. struct totemrrp_instance *rrp_instance,
  104. int interface_count);
  105. void (*mcast_recv) (
  106. struct totemrrp_instance *instance,
  107. unsigned int iface_no,
  108. void *context,
  109. const void *msg,
  110. unsigned int msg_len);
  111. void (*mcast_noflush_send) (
  112. struct totemrrp_instance *instance,
  113. const void *msg,
  114. unsigned int msg_len);
  115. void (*mcast_flush_send) (
  116. struct totemrrp_instance *instance,
  117. const void *msg,
  118. unsigned int msg_len);
  119. void (*token_recv) (
  120. struct totemrrp_instance *instance,
  121. unsigned int iface_no,
  122. void *context,
  123. const void *msg,
  124. unsigned int msg_len,
  125. unsigned int token_seqid);
  126. void (*token_send) (
  127. struct totemrrp_instance *instance,
  128. const void *msg,
  129. unsigned int msg_len);
  130. void (*recv_flush) (
  131. struct totemrrp_instance *instance);
  132. void (*send_flush) (
  133. struct totemrrp_instance *instance);
  134. void (*iface_check) (
  135. struct totemrrp_instance *instance);
  136. void (*processor_count_set) (
  137. struct totemrrp_instance *instance,
  138. unsigned int processor_count);
  139. void (*token_target_set) (
  140. struct totemrrp_instance *instance,
  141. struct totem_ip_address *token_target,
  142. unsigned int iface_no);
  143. void (*ring_reenable) (
  144. struct totemrrp_instance *instance,
  145. unsigned int iface_no);
  146. int (*mcast_recv_empty) (
  147. struct totemrrp_instance *instance);
  148. int (*member_add) (
  149. struct totemrrp_instance *instance,
  150. const struct totem_ip_address *member,
  151. unsigned int iface_no);
  152. int (*member_remove) (
  153. struct totemrrp_instance *instance,
  154. const struct totem_ip_address *member,
  155. unsigned int iface_no);
  156. };
  157. struct totemrrp_instance {
  158. qb_loop_t *poll_handle;
  159. struct totem_interface *interfaces;
  160. struct rrp_algo *rrp_algo;
  161. void *context;
  162. char *status[INTERFACE_MAX];
  163. void (*totemrrp_deliver_fn) (
  164. void *context,
  165. const void *msg,
  166. unsigned int msg_len);
  167. void (*totemrrp_iface_change_fn) (
  168. void *context,
  169. const struct totem_ip_address *iface_addr,
  170. unsigned int iface_no);
  171. void (*totemrrp_token_seqid_get) (
  172. const void *msg,
  173. unsigned int *seqid,
  174. unsigned int *token_is);
  175. void (*totemrrp_target_set_completed) (
  176. void *context);
  177. unsigned int (*totemrrp_msgs_missing) (void);
  178. /*
  179. * Function and data used to log messages
  180. */
  181. int totemrrp_log_level_security;
  182. int totemrrp_log_level_error;
  183. int totemrrp_log_level_warning;
  184. int totemrrp_log_level_notice;
  185. int totemrrp_log_level_debug;
  186. int totemrrp_subsys_id;
  187. void (*totemrrp_log_printf) (
  188. int level,
  189. int subsys,
  190. const char *function,
  191. const char *file,
  192. int line,
  193. const char *format, ...)__attribute__((format(printf, 6, 7)));
  194. void **net_handles;
  195. void *rrp_algo_instance;
  196. int interface_count;
  197. int processor_count;
  198. int my_nodeid;
  199. struct totem_config *totem_config;
  200. void *deliver_fn_context[INTERFACE_MAX];
  201. qb_loop_timer_handle timer_active_test_ring_timeout[INTERFACE_MAX];
  202. totemrrp_stats_t stats;
  203. };
  204. static void stats_set_interface_faulty(struct totemrrp_instance *rrp_instance,
  205. unsigned int iface_no, int is_faulty);
  206. /*
  207. * None Replication Forward Declerations
  208. */
  209. static void none_mcast_recv (
  210. struct totemrrp_instance *instance,
  211. unsigned int iface_no,
  212. void *context,
  213. const void *msg,
  214. unsigned int msg_len);
  215. static void none_mcast_noflush_send (
  216. struct totemrrp_instance *instance,
  217. const void *msg,
  218. unsigned int msg_len);
  219. static void none_mcast_flush_send (
  220. struct totemrrp_instance *instance,
  221. const void *msg,
  222. unsigned int msg_len);
  223. static void none_token_recv (
  224. struct totemrrp_instance *instance,
  225. unsigned int iface_no,
  226. void *context,
  227. const void *msg,
  228. unsigned int msg_len,
  229. unsigned int token_seqid);
  230. static void none_token_send (
  231. struct totemrrp_instance *instance,
  232. const void *msg,
  233. unsigned int msg_len);
  234. static void none_recv_flush (
  235. struct totemrrp_instance *instance);
  236. static void none_send_flush (
  237. struct totemrrp_instance *instance);
  238. static void none_iface_check (
  239. struct totemrrp_instance *instance);
  240. static void none_processor_count_set (
  241. struct totemrrp_instance *instance,
  242. unsigned int processor_count_set);
  243. static void none_token_target_set (
  244. struct totemrrp_instance *instance,
  245. struct totem_ip_address *token_target,
  246. unsigned int iface_no);
  247. static void none_ring_reenable (
  248. struct totemrrp_instance *instance,
  249. unsigned int iface_no);
  250. static int none_mcast_recv_empty (
  251. struct totemrrp_instance *instance);
  252. static int none_member_add (
  253. struct totemrrp_instance *instance,
  254. const struct totem_ip_address *member,
  255. unsigned int iface_no);
  256. static int none_member_remove (
  257. struct totemrrp_instance *instance,
  258. const struct totem_ip_address *member,
  259. unsigned int iface_no);
  260. /*
  261. * Passive Replication Forward Declerations
  262. */
  263. static void *passive_instance_initialize (
  264. struct totemrrp_instance *rrp_instance,
  265. int interface_count);
  266. static void passive_mcast_recv (
  267. struct totemrrp_instance *instance,
  268. unsigned int iface_no,
  269. void *context,
  270. const void *msg,
  271. unsigned int msg_len);
  272. static void passive_mcast_noflush_send (
  273. struct totemrrp_instance *instance,
  274. const void *msg,
  275. unsigned int msg_len);
  276. static void passive_mcast_flush_send (
  277. struct totemrrp_instance *instance,
  278. const void *msg,
  279. unsigned int msg_len);
  280. static void passive_monitor (
  281. struct totemrrp_instance *rrp_instance,
  282. unsigned int iface_no,
  283. int is_token_recv_count);
  284. static void passive_token_recv (
  285. struct totemrrp_instance *instance,
  286. unsigned int iface_no,
  287. void *context,
  288. const void *msg,
  289. unsigned int msg_len,
  290. unsigned int token_seqid);
  291. static void passive_token_send (
  292. struct totemrrp_instance *instance,
  293. const void *msg,
  294. unsigned int msg_len);
  295. static void passive_recv_flush (
  296. struct totemrrp_instance *instance);
  297. static void passive_send_flush (
  298. struct totemrrp_instance *instance);
  299. static void passive_iface_check (
  300. struct totemrrp_instance *instance);
  301. static void passive_processor_count_set (
  302. struct totemrrp_instance *instance,
  303. unsigned int processor_count_set);
  304. static void passive_token_target_set (
  305. struct totemrrp_instance *instance,
  306. struct totem_ip_address *token_target,
  307. unsigned int iface_no);
  308. static void passive_ring_reenable (
  309. struct totemrrp_instance *instance,
  310. unsigned int iface_no);
  311. static int passive_mcast_recv_empty (
  312. struct totemrrp_instance *instance);
  313. static int passive_member_add (
  314. struct totemrrp_instance *instance,
  315. const struct totem_ip_address *member,
  316. unsigned int iface_no);
  317. static int passive_member_remove (
  318. struct totemrrp_instance *instance,
  319. const struct totem_ip_address *member,
  320. unsigned int iface_no);
  321. /*
  322. * Active Replication Forward Definitions
  323. */
  324. static void *active_instance_initialize (
  325. struct totemrrp_instance *rrp_instance,
  326. int interface_count);
  327. static void active_mcast_recv (
  328. struct totemrrp_instance *instance,
  329. unsigned int iface_no,
  330. void *context,
  331. const void *msg,
  332. unsigned int msg_len);
  333. static void active_mcast_noflush_send (
  334. struct totemrrp_instance *instance,
  335. const void *msg,
  336. unsigned int msg_len);
  337. static void active_mcast_flush_send (
  338. struct totemrrp_instance *instance,
  339. const void *msg,
  340. unsigned int msg_len);
  341. static void active_token_recv (
  342. struct totemrrp_instance *instance,
  343. unsigned int iface_no,
  344. void *context,
  345. const void *msg,
  346. unsigned int msg_len,
  347. unsigned int token_seqid);
  348. static void active_token_send (
  349. struct totemrrp_instance *instance,
  350. const void *msg,
  351. unsigned int msg_len);
  352. static void active_recv_flush (
  353. struct totemrrp_instance *instance);
  354. static void active_send_flush (
  355. struct totemrrp_instance *instance);
  356. static void active_iface_check (
  357. struct totemrrp_instance *instance);
  358. static void active_processor_count_set (
  359. struct totemrrp_instance *instance,
  360. unsigned int processor_count_set);
  361. static void active_token_target_set (
  362. struct totemrrp_instance *instance,
  363. struct totem_ip_address *token_target,
  364. unsigned int iface_no);
  365. static void active_ring_reenable (
  366. struct totemrrp_instance *instance,
  367. unsigned int iface_no);
  368. static int active_mcast_recv_empty (
  369. struct totemrrp_instance *instance);
  370. static int active_member_add (
  371. struct totemrrp_instance *instance,
  372. const struct totem_ip_address *member,
  373. unsigned int iface_no);
  374. static int active_member_remove (
  375. struct totemrrp_instance *instance,
  376. const struct totem_ip_address *member,
  377. unsigned int iface_no);
  378. static void active_timer_expired_token_start (
  379. struct active_instance *active_instance);
  380. static void active_timer_expired_token_cancel (
  381. struct active_instance *active_instance);
  382. static void active_timer_problem_decrementer_start (
  383. struct active_instance *active_instance);
  384. static void active_timer_problem_decrementer_cancel (
  385. struct active_instance *active_instance);
  386. /*
  387. * 0-5 reserved for totemsrp.c
  388. */
  389. #define MESSAGE_TYPE_RING_TEST_ACTIVE 6
  390. #define MESSAGE_TYPE_RING_TEST_ACTIVATE 7
  391. #define ENDIAN_LOCAL 0xff22
  392. /*
  393. * Rollover handling:
  394. *
  395. * ARR_SEQNO_START_TOKEN is the starting sequence number of last seen sequence
  396. * for a token for active redundand ring. This should remain zero, unless testing
  397. * overflow in which case 07fffff00 or 0xffffff00 are good starting values.
  398. * It should be same as on defined in totemsrp.c
  399. */
  400. #define ARR_SEQNO_START_TOKEN 0x0
  401. /*
  402. * These can be used ot test different rollover points
  403. * #define ARR_SEQNO_START_MSG 0xfffffe00
  404. */
  405. /*
  406. * Threshold value when recv_count for passive rrp should be adjusted.
  407. * Set this value to some smaller for testing of adjusting proper
  408. * functionality. Also keep in mind that this value must be smaller
  409. * then rrp_problem_count_threshold
  410. */
  411. #define PASSIVE_RECV_COUNT_THRESHOLD (INT_MAX / 2)
  412. struct message_header {
  413. char type;
  414. char encapsulated;
  415. unsigned short endian_detector;
  416. int ring_number;
  417. int nodeid_activator;
  418. } __attribute__((packed));
  419. struct deliver_fn_context {
  420. struct totemrrp_instance *instance;
  421. void *context;
  422. int iface_no;
  423. };
  424. struct rrp_algo none_algo = {
  425. .name = "none",
  426. .initialize = NULL,
  427. .mcast_recv = none_mcast_recv,
  428. .mcast_noflush_send = none_mcast_noflush_send,
  429. .mcast_flush_send = none_mcast_flush_send,
  430. .token_recv = none_token_recv,
  431. .token_send = none_token_send,
  432. .recv_flush = none_recv_flush,
  433. .send_flush = none_send_flush,
  434. .iface_check = none_iface_check,
  435. .processor_count_set = none_processor_count_set,
  436. .token_target_set = none_token_target_set,
  437. .ring_reenable = none_ring_reenable,
  438. .mcast_recv_empty = none_mcast_recv_empty,
  439. .member_add = none_member_add,
  440. .member_remove = none_member_remove
  441. };
  442. struct rrp_algo passive_algo = {
  443. .name = "passive",
  444. .initialize = passive_instance_initialize,
  445. .mcast_recv = passive_mcast_recv,
  446. .mcast_noflush_send = passive_mcast_noflush_send,
  447. .mcast_flush_send = passive_mcast_flush_send,
  448. .token_recv = passive_token_recv,
  449. .token_send = passive_token_send,
  450. .recv_flush = passive_recv_flush,
  451. .send_flush = passive_send_flush,
  452. .iface_check = passive_iface_check,
  453. .processor_count_set = passive_processor_count_set,
  454. .token_target_set = passive_token_target_set,
  455. .ring_reenable = passive_ring_reenable,
  456. .mcast_recv_empty = passive_mcast_recv_empty,
  457. .member_add = passive_member_add,
  458. .member_remove = passive_member_remove
  459. };
  460. struct rrp_algo active_algo = {
  461. .name = "active",
  462. .initialize = active_instance_initialize,
  463. .mcast_recv = active_mcast_recv,
  464. .mcast_noflush_send = active_mcast_noflush_send,
  465. .mcast_flush_send = active_mcast_flush_send,
  466. .token_recv = active_token_recv,
  467. .token_send = active_token_send,
  468. .recv_flush = active_recv_flush,
  469. .send_flush = active_send_flush,
  470. .iface_check = active_iface_check,
  471. .processor_count_set = active_processor_count_set,
  472. .token_target_set = active_token_target_set,
  473. .ring_reenable = active_ring_reenable,
  474. .mcast_recv_empty = active_mcast_recv_empty,
  475. .member_add = active_member_add,
  476. .member_remove = active_member_remove
  477. };
  478. struct rrp_algo *rrp_algos[] = {
  479. &none_algo,
  480. &passive_algo,
  481. &active_algo
  482. };
  483. #define RRP_ALGOS_COUNT 3
  484. #define log_printf(level, format, args...) \
  485. do { \
  486. rrp_instance->totemrrp_log_printf ( \
  487. level, rrp_instance->totemrrp_subsys_id, \
  488. __FUNCTION__, __FILE__, __LINE__, \
  489. format, ##args); \
  490. } while (0);
  491. static void stats_set_interface_faulty(struct totemrrp_instance *rrp_instance,
  492. unsigned int iface_no, int is_faulty)
  493. {
  494. rrp_instance->stats.faulty[iface_no] = (is_faulty ? 1 : 0);
  495. }
  496. static void test_active_msg_endian_convert(const struct message_header *in, struct message_header *out)
  497. {
  498. out->type = in->type;
  499. out->encapsulated = in->encapsulated;
  500. out->endian_detector = ENDIAN_LOCAL;
  501. out->ring_number = swab32 (in->ring_number);
  502. out->nodeid_activator = swab32(in->nodeid_activator);
  503. }
  504. static void timer_function_test_ring_timeout (void *context)
  505. {
  506. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  507. struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
  508. unsigned int *faulty = NULL;
  509. int iface_no = deliver_fn_context->iface_no;
  510. struct message_header msg = {
  511. .type = MESSAGE_TYPE_RING_TEST_ACTIVE,
  512. .endian_detector = ENDIAN_LOCAL,
  513. };
  514. if (strcmp(rrp_instance->totem_config->rrp_mode, "active") == 0)
  515. faulty = ((struct active_instance *)(rrp_instance->rrp_algo_instance))->faulty;
  516. if (strcmp(rrp_instance->totem_config->rrp_mode, "passive") == 0)
  517. faulty = ((struct passive_instance *)(rrp_instance->rrp_algo_instance))->faulty;
  518. assert (faulty != NULL);
  519. if (faulty[iface_no] == 1) {
  520. msg.ring_number = iface_no;
  521. msg.nodeid_activator = rrp_instance->my_nodeid;
  522. totemnet_token_send (
  523. rrp_instance->net_handles[iface_no],
  524. &msg, sizeof (struct message_header));
  525. qb_loop_timer_add (rrp_instance->poll_handle,
  526. QB_LOOP_MED,
  527. rrp_instance->totem_config->rrp_autorecovery_check_timeout*QB_TIME_NS_IN_MSEC,
  528. (void *)deliver_fn_context,
  529. timer_function_test_ring_timeout,
  530. &rrp_instance->timer_active_test_ring_timeout[iface_no]);
  531. }
  532. }
  533. /*
  534. * None Replication Implementation
  535. */
  536. static void none_mcast_recv (
  537. struct totemrrp_instance *rrp_instance,
  538. unsigned int iface_no,
  539. void *context,
  540. const void *msg,
  541. unsigned int msg_len)
  542. {
  543. rrp_instance->totemrrp_deliver_fn (
  544. context,
  545. msg,
  546. msg_len);
  547. }
  548. static void none_mcast_flush_send (
  549. struct totemrrp_instance *instance,
  550. const void *msg,
  551. unsigned int msg_len)
  552. {
  553. totemnet_mcast_flush_send (instance->net_handles[0], msg, msg_len);
  554. }
  555. static void none_mcast_noflush_send (
  556. struct totemrrp_instance *instance,
  557. const void *msg,
  558. unsigned int msg_len)
  559. {
  560. totemnet_mcast_noflush_send (instance->net_handles[0], msg, msg_len);
  561. }
  562. static void none_token_recv (
  563. struct totemrrp_instance *rrp_instance,
  564. unsigned int iface_no,
  565. void *context,
  566. const void *msg,
  567. unsigned int msg_len,
  568. unsigned int token_seq)
  569. {
  570. rrp_instance->totemrrp_deliver_fn (
  571. context,
  572. msg,
  573. msg_len);
  574. }
  575. static void none_token_send (
  576. struct totemrrp_instance *instance,
  577. const void *msg,
  578. unsigned int msg_len)
  579. {
  580. totemnet_token_send (
  581. instance->net_handles[0],
  582. msg, msg_len);
  583. }
  584. static void none_recv_flush (struct totemrrp_instance *instance)
  585. {
  586. totemnet_recv_flush (instance->net_handles[0]);
  587. }
  588. static void none_send_flush (struct totemrrp_instance *instance)
  589. {
  590. totemnet_send_flush (instance->net_handles[0]);
  591. }
  592. static void none_iface_check (struct totemrrp_instance *instance)
  593. {
  594. totemnet_iface_check (instance->net_handles[0]);
  595. }
  596. static void none_processor_count_set (
  597. struct totemrrp_instance *instance,
  598. unsigned int processor_count)
  599. {
  600. totemnet_processor_count_set (instance->net_handles[0],
  601. processor_count);
  602. }
  603. static void none_token_target_set (
  604. struct totemrrp_instance *instance,
  605. struct totem_ip_address *token_target,
  606. unsigned int iface_no)
  607. {
  608. totemnet_token_target_set (instance->net_handles[0], token_target);
  609. }
  610. static void none_ring_reenable (
  611. struct totemrrp_instance *instance,
  612. unsigned int iface_no)
  613. {
  614. /*
  615. * No operation
  616. */
  617. }
  618. static int none_mcast_recv_empty (
  619. struct totemrrp_instance *instance)
  620. {
  621. int res;
  622. res = totemnet_recv_mcast_empty (instance->net_handles[0]);
  623. return (res);
  624. }
  625. static int none_member_add (
  626. struct totemrrp_instance *instance,
  627. const struct totem_ip_address *member,
  628. unsigned int iface_no)
  629. {
  630. int res;
  631. res = totemnet_member_add (instance->net_handles[0], member);
  632. return (res);
  633. }
  634. static int none_member_remove (
  635. struct totemrrp_instance *instance,
  636. const struct totem_ip_address *member,
  637. unsigned int iface_no)
  638. {
  639. int res;
  640. res = totemnet_member_remove (instance->net_handles[0], member);
  641. return (res);
  642. }
  643. /*
  644. * Passive Replication Implementation
  645. */
  646. void *passive_instance_initialize (
  647. struct totemrrp_instance *rrp_instance,
  648. int interface_count)
  649. {
  650. struct passive_instance *instance;
  651. int i;
  652. instance = malloc (sizeof (struct passive_instance));
  653. if (instance == 0) {
  654. goto error_exit;
  655. }
  656. memset (instance, 0, sizeof (struct passive_instance));
  657. instance->faulty = malloc (sizeof (int) * interface_count);
  658. if (instance->faulty == 0) {
  659. free (instance);
  660. instance = 0;
  661. goto error_exit;
  662. }
  663. memset (instance->faulty, 0, sizeof (int) * interface_count);
  664. for (i = 0; i < interface_count; i++) {
  665. stats_set_interface_faulty (rrp_instance, i, 0);
  666. }
  667. instance->token_recv_count = malloc (sizeof (int) * interface_count);
  668. if (instance->token_recv_count == 0) {
  669. free (instance->faulty);
  670. free (instance);
  671. instance = 0;
  672. goto error_exit;
  673. }
  674. memset (instance->token_recv_count, 0, sizeof (int) * interface_count);
  675. instance->mcast_recv_count = malloc (sizeof (int) * interface_count);
  676. if (instance->mcast_recv_count == 0) {
  677. free (instance->token_recv_count);
  678. free (instance->faulty);
  679. free (instance);
  680. instance = 0;
  681. goto error_exit;
  682. }
  683. memset (instance->mcast_recv_count, 0, sizeof (int) * interface_count);
  684. error_exit:
  685. return ((void *)instance);
  686. }
  687. static void timer_function_passive_token_expired (void *context)
  688. {
  689. struct passive_instance *passive_instance = (struct passive_instance *)context;
  690. struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
  691. rrp_instance->totemrrp_deliver_fn (
  692. passive_instance->totemrrp_context,
  693. passive_instance->token,
  694. passive_instance->token_len);
  695. }
  696. /* TODO
  697. static void timer_function_passive_problem_decrementer (void *context)
  698. {
  699. // struct passive_instance *passive_instance = (struct passive_instance *)context;
  700. // struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
  701. }
  702. */
  703. static void passive_timer_expired_token_start (
  704. struct passive_instance *passive_instance)
  705. {
  706. qb_loop_timer_add (
  707. passive_instance->rrp_instance->poll_handle,
  708. QB_LOOP_MED,
  709. passive_instance->rrp_instance->totem_config->rrp_token_expired_timeout*QB_TIME_NS_IN_MSEC,
  710. (void *)passive_instance,
  711. timer_function_passive_token_expired,
  712. &passive_instance->timer_expired_token);
  713. }
  714. static void passive_timer_expired_token_cancel (
  715. struct passive_instance *passive_instance)
  716. {
  717. qb_loop_timer_del (
  718. passive_instance->rrp_instance->poll_handle,
  719. passive_instance->timer_expired_token);
  720. }
  721. /*
  722. static void passive_timer_problem_decrementer_start (
  723. struct passive_instance *passive_instance)
  724. {
  725. qb_loop_timer_add (
  726. QB_LOOP_MED,
  727. passive_instance->rrp_instance->poll_handle,
  728. passive_instance->rrp_instance->totem_config->rrp_problem_count_timeout*QB_TIME_NS_IN_MSEC,
  729. (void *)passive_instance,
  730. timer_function_passive_problem_decrementer,
  731. &passive_instance->timer_problem_decrementer);
  732. }
  733. static void passive_timer_problem_decrementer_cancel (
  734. struct passive_instance *passive_instance)
  735. {
  736. qb_loop_timer_del (
  737. passive_instance->rrp_instance->poll_handle,
  738. passive_instance->timer_problem_decrementer);
  739. }
  740. */
  741. /*
  742. * Monitor function implementation from rrp paper.
  743. * rrp_instance is passive rrp instance, iface_no is interface with received messgae/token and
  744. * is_token_recv_count is boolean variable which donates if message is token (>1) or regular
  745. * message (= 0)
  746. */
  747. static void passive_monitor (
  748. struct totemrrp_instance *rrp_instance,
  749. unsigned int iface_no,
  750. int is_token_recv_count)
  751. {
  752. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  753. unsigned int *recv_count;
  754. unsigned int max;
  755. unsigned int i;
  756. unsigned int min_all, min_active;
  757. unsigned int threshold;
  758. /*
  759. * Monitor for failures
  760. */
  761. if (is_token_recv_count) {
  762. recv_count = passive_instance->token_recv_count;
  763. threshold = rrp_instance->totem_config->rrp_problem_count_threshold;
  764. } else {
  765. recv_count = passive_instance->mcast_recv_count;
  766. threshold = rrp_instance->totem_config->rrp_problem_count_mcast_threshold;
  767. }
  768. recv_count[iface_no] += 1;
  769. max = 0;
  770. for (i = 0; i < rrp_instance->interface_count; i++) {
  771. if (max < recv_count[i]) {
  772. max = recv_count[i];
  773. }
  774. }
  775. /*
  776. * Max is larger then threshold -> start adjusting process
  777. */
  778. if (max > PASSIVE_RECV_COUNT_THRESHOLD) {
  779. min_all = min_active = recv_count[iface_no];
  780. for (i = 0; i < rrp_instance->interface_count; i++) {
  781. if (recv_count[i] < min_all) {
  782. min_all = recv_count[i];
  783. }
  784. if (passive_instance->faulty[i] == 0 &&
  785. recv_count[i] < min_active) {
  786. min_active = recv_count[i];
  787. }
  788. }
  789. if (min_all > 0) {
  790. /*
  791. * There is one or more faulty device with recv_count > 0
  792. */
  793. for (i = 0; i < rrp_instance->interface_count; i++) {
  794. recv_count[i] -= min_all;
  795. }
  796. } else {
  797. /*
  798. * No faulty device with recv_count > 0, adjust only active
  799. * devices
  800. */
  801. for (i = 0; i < rrp_instance->interface_count; i++) {
  802. if (passive_instance->faulty[i] == 0) {
  803. recv_count[i] -= min_active;
  804. }
  805. }
  806. }
  807. /*
  808. * Find again max
  809. */
  810. max = 0;
  811. for (i = 0; i < rrp_instance->interface_count; i++) {
  812. if (max < recv_count[i]) {
  813. max = recv_count[i];
  814. }
  815. }
  816. }
  817. for (i = 0; i < rrp_instance->interface_count; i++) {
  818. if ((passive_instance->faulty[i] == 0) &&
  819. (max - recv_count[i] > threshold)) {
  820. passive_instance->faulty[i] = 1;
  821. qb_loop_timer_add (rrp_instance->poll_handle,
  822. QB_LOOP_MED,
  823. rrp_instance->totem_config->rrp_autorecovery_check_timeout*QB_TIME_NS_IN_MSEC,
  824. rrp_instance->deliver_fn_context[i],
  825. timer_function_test_ring_timeout,
  826. &rrp_instance->timer_active_test_ring_timeout[i]);
  827. stats_set_interface_faulty (rrp_instance, i, passive_instance->faulty[i]);
  828. sprintf (rrp_instance->status[i],
  829. "Marking ringid %u interface %s FAULTY",
  830. i,
  831. totemnet_iface_print (rrp_instance->net_handles[i]));
  832. log_printf (
  833. rrp_instance->totemrrp_log_level_error,
  834. "%s",
  835. rrp_instance->status[i]);
  836. }
  837. }
  838. }
  839. static void passive_mcast_recv (
  840. struct totemrrp_instance *rrp_instance,
  841. unsigned int iface_no,
  842. void *context,
  843. const void *msg,
  844. unsigned int msg_len)
  845. {
  846. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  847. rrp_instance->totemrrp_deliver_fn (
  848. context,
  849. msg,
  850. msg_len);
  851. if (rrp_instance->totemrrp_msgs_missing() == 0 &&
  852. passive_instance->timer_expired_token) {
  853. /*
  854. * Delivers the last token
  855. */
  856. rrp_instance->totemrrp_deliver_fn (
  857. passive_instance->totemrrp_context,
  858. passive_instance->token,
  859. passive_instance->token_len);
  860. passive_timer_expired_token_cancel (passive_instance);
  861. }
  862. passive_monitor (rrp_instance, iface_no, 0);
  863. }
  864. static void passive_mcast_flush_send (
  865. struct totemrrp_instance *instance,
  866. const void *msg,
  867. unsigned int msg_len)
  868. {
  869. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  870. int i = 0;
  871. do {
  872. passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
  873. i++;
  874. } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1));
  875. if (i <= instance->interface_count) {
  876. totemnet_mcast_flush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
  877. }
  878. }
  879. static void passive_mcast_noflush_send (
  880. struct totemrrp_instance *instance,
  881. const void *msg,
  882. unsigned int msg_len)
  883. {
  884. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  885. int i = 0;
  886. do {
  887. passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
  888. i++;
  889. } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1));
  890. if (i <= instance->interface_count) {
  891. totemnet_mcast_noflush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
  892. }
  893. }
  894. static void passive_token_recv (
  895. struct totemrrp_instance *rrp_instance,
  896. unsigned int iface_no,
  897. void *context,
  898. const void *msg,
  899. unsigned int msg_len,
  900. unsigned int token_seq)
  901. {
  902. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  903. passive_instance->totemrrp_context = context; // this should be in totemrrp_instance ? TODO
  904. if (rrp_instance->totemrrp_msgs_missing() == 0) {
  905. rrp_instance->totemrrp_deliver_fn (
  906. context,
  907. msg,
  908. msg_len);
  909. } else {
  910. memcpy (passive_instance->token, msg, msg_len);
  911. passive_timer_expired_token_start (passive_instance);
  912. }
  913. passive_monitor (rrp_instance, iface_no, 1);
  914. }
  915. static void passive_token_send (
  916. struct totemrrp_instance *instance,
  917. const void *msg,
  918. unsigned int msg_len)
  919. {
  920. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  921. int i = 0;
  922. do {
  923. passive_instance->token_xmit_iface = (passive_instance->token_xmit_iface + 1) % instance->interface_count;
  924. i++;
  925. } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->token_xmit_iface] == 1));
  926. if (i <= instance->interface_count) {
  927. totemnet_token_send (
  928. instance->net_handles[passive_instance->token_xmit_iface],
  929. msg, msg_len);
  930. }
  931. }
  932. static void passive_recv_flush (struct totemrrp_instance *instance)
  933. {
  934. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  935. unsigned int i;
  936. for (i = 0; i < instance->interface_count; i++) {
  937. if (rrp_algo_instance->faulty[i] == 0) {
  938. totemnet_recv_flush (instance->net_handles[i]);
  939. }
  940. }
  941. }
  942. static void passive_send_flush (struct totemrrp_instance *instance)
  943. {
  944. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  945. unsigned int i;
  946. for (i = 0; i < instance->interface_count; i++) {
  947. if (rrp_algo_instance->faulty[i] == 0) {
  948. totemnet_send_flush (instance->net_handles[i]);
  949. }
  950. }
  951. }
  952. static void passive_iface_check (struct totemrrp_instance *instance)
  953. {
  954. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  955. unsigned int i;
  956. for (i = 0; i < instance->interface_count; i++) {
  957. if (rrp_algo_instance->faulty[i] == 0) {
  958. totemnet_iface_check (instance->net_handles[i]);
  959. }
  960. }
  961. }
  962. static void passive_processor_count_set (
  963. struct totemrrp_instance *instance,
  964. unsigned int processor_count)
  965. {
  966. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  967. unsigned int i;
  968. for (i = 0; i < instance->interface_count; i++) {
  969. if (rrp_algo_instance->faulty[i] == 0) {
  970. totemnet_processor_count_set (instance->net_handles[i],
  971. processor_count);
  972. }
  973. }
  974. }
  975. static void passive_token_target_set (
  976. struct totemrrp_instance *instance,
  977. struct totem_ip_address *token_target,
  978. unsigned int iface_no)
  979. {
  980. totemnet_token_target_set (instance->net_handles[iface_no], token_target);
  981. }
  982. static int passive_mcast_recv_empty (
  983. struct totemrrp_instance *instance)
  984. {
  985. int res;
  986. int msgs_emptied = 0;
  987. int i;
  988. for (i = 0; i < instance->interface_count; i++) {
  989. res = totemnet_recv_mcast_empty (instance->net_handles[i]);
  990. if (res == -1) {
  991. return (-1);
  992. }
  993. if (res == 1) {
  994. msgs_emptied = 1;
  995. }
  996. }
  997. return (msgs_emptied);
  998. }
  999. static int passive_member_add (
  1000. struct totemrrp_instance *instance,
  1001. const struct totem_ip_address *member,
  1002. unsigned int iface_no)
  1003. {
  1004. int res;
  1005. res = totemnet_member_add (instance->net_handles[iface_no], member);
  1006. return (res);
  1007. }
  1008. static int passive_member_remove (
  1009. struct totemrrp_instance *instance,
  1010. const struct totem_ip_address *member,
  1011. unsigned int iface_no)
  1012. {
  1013. int res;
  1014. res = totemnet_member_remove (instance->net_handles[iface_no], member);
  1015. return (res);
  1016. }
  1017. static void passive_ring_reenable (
  1018. struct totemrrp_instance *instance,
  1019. unsigned int iface_no)
  1020. {
  1021. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  1022. int i;
  1023. memset (rrp_algo_instance->mcast_recv_count, 0, sizeof (unsigned int) *
  1024. instance->interface_count);
  1025. memset (rrp_algo_instance->token_recv_count, 0, sizeof (unsigned int) *
  1026. instance->interface_count);
  1027. if (iface_no == instance->interface_count) {
  1028. memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
  1029. instance->interface_count);
  1030. for (i = 0; i < instance->interface_count; i++) {
  1031. stats_set_interface_faulty (instance, i, 0);
  1032. }
  1033. } else {
  1034. rrp_algo_instance->faulty[iface_no] = 0;
  1035. stats_set_interface_faulty (instance, iface_no, 0);
  1036. }
  1037. }
  1038. /*
  1039. * Active Replication Implementation
  1040. */
  1041. void *active_instance_initialize (
  1042. struct totemrrp_instance *rrp_instance,
  1043. int interface_count)
  1044. {
  1045. struct active_instance *instance;
  1046. int i;
  1047. instance = malloc (sizeof (struct active_instance));
  1048. if (instance == 0) {
  1049. goto error_exit;
  1050. }
  1051. memset (instance, 0, sizeof (struct active_instance));
  1052. instance->faulty = malloc (sizeof (int) * interface_count);
  1053. if (instance->faulty == 0) {
  1054. free (instance);
  1055. instance = 0;
  1056. goto error_exit;
  1057. }
  1058. memset (instance->faulty, 0, sizeof (unsigned int) * interface_count);
  1059. for (i = 0; i < interface_count; i++) {
  1060. stats_set_interface_faulty (rrp_instance, i, 0);
  1061. }
  1062. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  1063. if (instance->last_token_recv == 0) {
  1064. free (instance->faulty);
  1065. free (instance);
  1066. instance = 0;
  1067. goto error_exit;
  1068. }
  1069. memset (instance->last_token_recv, 0, sizeof (unsigned int) * interface_count);
  1070. instance->counter_problems = malloc (sizeof (int) * interface_count);
  1071. if (instance->counter_problems == 0) {
  1072. free (instance->last_token_recv);
  1073. free (instance->faulty);
  1074. free (instance);
  1075. instance = 0;
  1076. goto error_exit;
  1077. }
  1078. memset (instance->counter_problems, 0, sizeof (unsigned int) * interface_count);
  1079. instance->timer_expired_token = 0;
  1080. instance->timer_problem_decrementer = 0;
  1081. instance->rrp_instance = rrp_instance;
  1082. instance->last_token_seq = ARR_SEQNO_START_TOKEN - 1;
  1083. error_exit:
  1084. return ((void *)instance);
  1085. }
  1086. static void timer_function_active_problem_decrementer (void *context)
  1087. {
  1088. struct active_instance *active_instance = (struct active_instance *)context;
  1089. struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
  1090. unsigned int problem_found = 0;
  1091. unsigned int i;
  1092. for (i = 0; i < rrp_instance->interface_count; i++) {
  1093. if (active_instance->counter_problems[i] > 0) {
  1094. problem_found = 1;
  1095. active_instance->counter_problems[i] -= 1;
  1096. if (active_instance->counter_problems[i] == 0) {
  1097. sprintf (rrp_instance->status[i],
  1098. "ring %d active with no faults", i);
  1099. } else {
  1100. sprintf (rrp_instance->status[i],
  1101. "Decrementing problem counter for iface %s to [%d of %d]",
  1102. totemnet_iface_print (rrp_instance->net_handles[i]),
  1103. active_instance->counter_problems[i],
  1104. rrp_instance->totem_config->rrp_problem_count_threshold);
  1105. }
  1106. log_printf (
  1107. rrp_instance->totemrrp_log_level_warning,
  1108. "%s",
  1109. rrp_instance->status[i]);
  1110. }
  1111. }
  1112. if (problem_found) {
  1113. active_timer_problem_decrementer_start (active_instance);
  1114. } else {
  1115. active_instance->timer_problem_decrementer = 0;
  1116. }
  1117. }
  1118. static void timer_function_active_token_expired (void *context)
  1119. {
  1120. struct active_instance *active_instance = (struct active_instance *)context;
  1121. struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
  1122. unsigned int i;
  1123. for (i = 0; i < rrp_instance->interface_count; i++) {
  1124. if (active_instance->last_token_recv[i] == 0) {
  1125. active_instance->counter_problems[i] += 1;
  1126. if (active_instance->timer_problem_decrementer == 0) {
  1127. active_timer_problem_decrementer_start (active_instance);
  1128. }
  1129. sprintf (rrp_instance->status[i],
  1130. "Incrementing problem counter for seqid %d iface %s to [%d of %d]",
  1131. active_instance->last_token_seq,
  1132. totemnet_iface_print (rrp_instance->net_handles[i]),
  1133. active_instance->counter_problems[i],
  1134. rrp_instance->totem_config->rrp_problem_count_threshold);
  1135. log_printf (
  1136. rrp_instance->totemrrp_log_level_warning,
  1137. "%s",
  1138. rrp_instance->status[i]);
  1139. }
  1140. }
  1141. for (i = 0; i < rrp_instance->interface_count; i++) {
  1142. if (active_instance->counter_problems[i] >= rrp_instance->totem_config->rrp_problem_count_threshold &&
  1143. active_instance->faulty[i] == 0) {
  1144. active_instance->faulty[i] = 1;
  1145. qb_loop_timer_add (rrp_instance->poll_handle,
  1146. QB_LOOP_MED,
  1147. rrp_instance->totem_config->rrp_autorecovery_check_timeout*QB_TIME_NS_IN_MSEC,
  1148. rrp_instance->deliver_fn_context[i],
  1149. timer_function_test_ring_timeout,
  1150. &rrp_instance->timer_active_test_ring_timeout[i]);
  1151. stats_set_interface_faulty (rrp_instance, i, active_instance->faulty[i]);
  1152. sprintf (rrp_instance->status[i],
  1153. "Marking seqid %d ringid %u interface %s FAULTY",
  1154. active_instance->last_token_seq,
  1155. i,
  1156. totemnet_iface_print (rrp_instance->net_handles[i]));
  1157. log_printf (
  1158. rrp_instance->totemrrp_log_level_error,
  1159. "%s",
  1160. rrp_instance->status[i]);
  1161. active_timer_problem_decrementer_cancel (active_instance);
  1162. }
  1163. }
  1164. rrp_instance->totemrrp_deliver_fn (
  1165. active_instance->totemrrp_context,
  1166. active_instance->token,
  1167. active_instance->token_len);
  1168. }
  1169. static void active_timer_expired_token_start (
  1170. struct active_instance *active_instance)
  1171. {
  1172. qb_loop_timer_add (
  1173. active_instance->rrp_instance->poll_handle,
  1174. QB_LOOP_MED,
  1175. active_instance->rrp_instance->totem_config->rrp_token_expired_timeout*QB_TIME_NS_IN_MSEC,
  1176. (void *)active_instance,
  1177. timer_function_active_token_expired,
  1178. &active_instance->timer_expired_token);
  1179. }
  1180. static void active_timer_expired_token_cancel (
  1181. struct active_instance *active_instance)
  1182. {
  1183. qb_loop_timer_del (
  1184. active_instance->rrp_instance->poll_handle,
  1185. active_instance->timer_expired_token);
  1186. }
  1187. static void active_timer_problem_decrementer_start (
  1188. struct active_instance *active_instance)
  1189. {
  1190. qb_loop_timer_add (
  1191. active_instance->rrp_instance->poll_handle,
  1192. QB_LOOP_MED,
  1193. active_instance->rrp_instance->totem_config->rrp_problem_count_timeout*QB_TIME_NS_IN_MSEC,
  1194. (void *)active_instance,
  1195. timer_function_active_problem_decrementer,
  1196. &active_instance->timer_problem_decrementer);
  1197. }
  1198. static void active_timer_problem_decrementer_cancel (
  1199. struct active_instance *active_instance)
  1200. {
  1201. qb_loop_timer_del (
  1202. active_instance->rrp_instance->poll_handle,
  1203. active_instance->timer_problem_decrementer);
  1204. }
  1205. /*
  1206. * active replication
  1207. */
  1208. static void active_mcast_recv (
  1209. struct totemrrp_instance *instance,
  1210. unsigned int iface_no,
  1211. void *context,
  1212. const void *msg,
  1213. unsigned int msg_len)
  1214. {
  1215. instance->totemrrp_deliver_fn (
  1216. context,
  1217. msg,
  1218. msg_len);
  1219. }
  1220. static void active_mcast_flush_send (
  1221. struct totemrrp_instance *instance,
  1222. const void *msg,
  1223. unsigned int msg_len)
  1224. {
  1225. int i;
  1226. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1227. for (i = 0; i < instance->interface_count; i++) {
  1228. if (rrp_algo_instance->faulty[i] == 0) {
  1229. totemnet_mcast_flush_send (instance->net_handles[i], msg, msg_len);
  1230. }
  1231. }
  1232. }
  1233. static void active_mcast_noflush_send (
  1234. struct totemrrp_instance *instance,
  1235. const void *msg,
  1236. unsigned int msg_len)
  1237. {
  1238. int i;
  1239. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1240. for (i = 0; i < instance->interface_count; i++) {
  1241. if (rrp_algo_instance->faulty[i] == 0) {
  1242. totemnet_mcast_noflush_send (instance->net_handles[i], msg, msg_len);
  1243. }
  1244. }
  1245. }
  1246. static void active_token_recv (
  1247. struct totemrrp_instance *rrp_instance,
  1248. unsigned int iface_no,
  1249. void *context,
  1250. const void *msg,
  1251. unsigned int msg_len,
  1252. unsigned int token_seq)
  1253. {
  1254. int i;
  1255. struct active_instance *active_instance = (struct active_instance *)rrp_instance->rrp_algo_instance;
  1256. active_instance->totemrrp_context = context;
  1257. if (sq_lt_compare (active_instance->last_token_seq, token_seq)) {
  1258. memcpy (active_instance->token, msg, msg_len);
  1259. active_instance->token_len = msg_len;
  1260. for (i = 0; i < rrp_instance->interface_count; i++) {
  1261. active_instance->last_token_recv[i] = 0;
  1262. }
  1263. active_instance->last_token_recv[iface_no] = 1;
  1264. active_timer_expired_token_start (active_instance);
  1265. }
  1266. /*
  1267. * This doesn't follow spec because the spec assumes we will know
  1268. * when token resets occur.
  1269. */
  1270. active_instance->last_token_seq = token_seq;
  1271. if (token_seq == active_instance->last_token_seq) {
  1272. active_instance->last_token_recv[iface_no] = 1;
  1273. for (i = 0; i < rrp_instance->interface_count; i++) {
  1274. if ((active_instance->last_token_recv[i] == 0) &&
  1275. active_instance->faulty[i] == 0) {
  1276. return; /* don't deliver token */
  1277. }
  1278. }
  1279. active_timer_expired_token_cancel (active_instance);
  1280. rrp_instance->totemrrp_deliver_fn (
  1281. context,
  1282. msg,
  1283. msg_len);
  1284. }
  1285. }
  1286. static void active_token_send (
  1287. struct totemrrp_instance *instance,
  1288. const void *msg,
  1289. unsigned int msg_len)
  1290. {
  1291. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1292. int i;
  1293. for (i = 0; i < instance->interface_count; i++) {
  1294. if (rrp_algo_instance->faulty[i] == 0) {
  1295. totemnet_token_send (
  1296. instance->net_handles[i],
  1297. msg, msg_len);
  1298. }
  1299. }
  1300. }
  1301. static void active_recv_flush (struct totemrrp_instance *instance)
  1302. {
  1303. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1304. unsigned int i;
  1305. for (i = 0; i < instance->interface_count; i++) {
  1306. if (rrp_algo_instance->faulty[i] == 0) {
  1307. totemnet_recv_flush (instance->net_handles[i]);
  1308. }
  1309. }
  1310. }
  1311. static void active_send_flush (struct totemrrp_instance *instance)
  1312. {
  1313. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1314. unsigned int i;
  1315. for (i = 0; i < instance->interface_count; i++) {
  1316. if (rrp_algo_instance->faulty[i] == 0) {
  1317. totemnet_send_flush (instance->net_handles[i]);
  1318. }
  1319. }
  1320. }
  1321. static int active_member_add (
  1322. struct totemrrp_instance *instance,
  1323. const struct totem_ip_address *member,
  1324. unsigned int iface_no)
  1325. {
  1326. int res;
  1327. res = totemnet_member_add (instance->net_handles[iface_no], member);
  1328. return (res);
  1329. }
  1330. static int active_member_remove (
  1331. struct totemrrp_instance *instance,
  1332. const struct totem_ip_address *member,
  1333. unsigned int iface_no)
  1334. {
  1335. int res;
  1336. res = totemnet_member_remove (instance->net_handles[iface_no], member);
  1337. return (res);
  1338. }
  1339. static void active_iface_check (struct totemrrp_instance *instance)
  1340. {
  1341. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1342. unsigned int i;
  1343. for (i = 0; i < instance->interface_count; i++) {
  1344. if (rrp_algo_instance->faulty[i] == 0) {
  1345. totemnet_iface_check (instance->net_handles[i]);
  1346. }
  1347. }
  1348. }
  1349. static void active_processor_count_set (
  1350. struct totemrrp_instance *instance,
  1351. unsigned int processor_count)
  1352. {
  1353. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1354. unsigned int i;
  1355. for (i = 0; i < instance->interface_count; i++) {
  1356. if (rrp_algo_instance->faulty[i] == 0) {
  1357. totemnet_processor_count_set (instance->net_handles[i],
  1358. processor_count);
  1359. }
  1360. }
  1361. }
  1362. static void active_token_target_set (
  1363. struct totemrrp_instance *instance,
  1364. struct totem_ip_address *token_target,
  1365. unsigned int iface_no)
  1366. {
  1367. totemnet_token_target_set (instance->net_handles[iface_no], token_target);
  1368. }
  1369. static int active_mcast_recv_empty (
  1370. struct totemrrp_instance *instance)
  1371. {
  1372. int res;
  1373. int msgs_emptied = 0;
  1374. int i;
  1375. for (i = 0; i < instance->interface_count; i++) {
  1376. res = totemnet_recv_mcast_empty (instance->net_handles[i]);
  1377. if (res == -1) {
  1378. return (-1);
  1379. }
  1380. if (res == 1) {
  1381. msgs_emptied = 1;
  1382. }
  1383. }
  1384. return (msgs_emptied);
  1385. }
  1386. static void active_ring_reenable (
  1387. struct totemrrp_instance *instance,
  1388. unsigned int iface_no)
  1389. {
  1390. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1391. int i;
  1392. if (iface_no == instance->interface_count) {
  1393. memset (rrp_algo_instance->last_token_recv, 0, sizeof (unsigned int) *
  1394. instance->interface_count);
  1395. memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
  1396. instance->interface_count);
  1397. memset (rrp_algo_instance->counter_problems, 0, sizeof (unsigned int) *
  1398. instance->interface_count);
  1399. for (i = 0; i < instance->interface_count; i++) {
  1400. stats_set_interface_faulty (instance, i, 0);
  1401. }
  1402. } else {
  1403. rrp_algo_instance->last_token_recv[iface_no] = 0;
  1404. rrp_algo_instance->faulty[iface_no] = 0;
  1405. rrp_algo_instance->counter_problems[iface_no] = 0;
  1406. stats_set_interface_faulty (instance, iface_no, 0);
  1407. }
  1408. }
  1409. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  1410. {
  1411. memset (instance, 0, sizeof (struct totemrrp_instance));
  1412. }
  1413. static int totemrrp_algorithm_set (
  1414. struct totem_config *totem_config,
  1415. struct totemrrp_instance *instance)
  1416. {
  1417. unsigned int res = -1;
  1418. unsigned int i;
  1419. for (i = 0; i < RRP_ALGOS_COUNT; i++) {
  1420. if (strcmp (totem_config->rrp_mode, rrp_algos[i]->name) == 0) {
  1421. instance->rrp_algo = rrp_algos[i];
  1422. if (rrp_algos[i]->initialize) {
  1423. instance->rrp_algo_instance = rrp_algos[i]->initialize (
  1424. instance,
  1425. totem_config->interface_count);
  1426. }
  1427. res = 0;
  1428. break;
  1429. }
  1430. }
  1431. for (i = 0; i < totem_config->interface_count; i++) {
  1432. instance->status[i] = malloc (1024);
  1433. sprintf (instance->status[i], "ring %d active with no faults", i);
  1434. }
  1435. return (res);
  1436. }
  1437. void rrp_deliver_fn (
  1438. void *context,
  1439. const void *msg,
  1440. unsigned int msg_len)
  1441. {
  1442. unsigned int token_seqid;
  1443. unsigned int token_is;
  1444. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1445. struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
  1446. const struct message_header *hdr = msg;
  1447. struct message_header tmp_msg, activate_msg;
  1448. memset(&tmp_msg, 0, sizeof(struct message_header));
  1449. memset(&activate_msg, 0, sizeof(struct message_header));
  1450. rrp_instance->totemrrp_token_seqid_get (
  1451. msg,
  1452. &token_seqid,
  1453. &token_is);
  1454. if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVE) {
  1455. log_printf (
  1456. rrp_instance->totemrrp_log_level_debug,
  1457. "received message requesting test of ring now active");
  1458. if (hdr->endian_detector != ENDIAN_LOCAL) {
  1459. test_active_msg_endian_convert(hdr, &tmp_msg);
  1460. hdr = &tmp_msg;
  1461. }
  1462. if (hdr->nodeid_activator == rrp_instance->my_nodeid) {
  1463. /*
  1464. * Send an activate message
  1465. */
  1466. activate_msg.type = MESSAGE_TYPE_RING_TEST_ACTIVATE;
  1467. activate_msg.endian_detector = ENDIAN_LOCAL;
  1468. activate_msg.ring_number = hdr->ring_number;
  1469. activate_msg.nodeid_activator = rrp_instance->my_nodeid;
  1470. totemnet_token_send (
  1471. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1472. &activate_msg, sizeof (struct message_header));
  1473. } else {
  1474. /*
  1475. * Send a ring test message
  1476. */
  1477. totemnet_token_send (
  1478. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1479. msg, msg_len);
  1480. }
  1481. } else
  1482. if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVATE) {
  1483. log_printf (
  1484. rrp_instance->totemrrp_log_level_notice,
  1485. "Automatically recovered ring %d", hdr->ring_number);
  1486. if (hdr->endian_detector != ENDIAN_LOCAL) {
  1487. test_active_msg_endian_convert(hdr, &tmp_msg);
  1488. hdr = &tmp_msg;
  1489. }
  1490. totemrrp_ring_reenable (rrp_instance, deliver_fn_context->iface_no);
  1491. if (hdr->nodeid_activator != rrp_instance->my_nodeid) {
  1492. totemnet_token_send (
  1493. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1494. msg, msg_len);
  1495. }
  1496. } else
  1497. if (token_is) {
  1498. /*
  1499. * Deliver to the token receiver for this rrp algorithm
  1500. */
  1501. rrp_instance->rrp_algo->token_recv (
  1502. rrp_instance,
  1503. deliver_fn_context->iface_no,
  1504. deliver_fn_context->context,
  1505. msg,
  1506. msg_len,
  1507. token_seqid);
  1508. } else {
  1509. /*
  1510. * Deliver to the mcast receiver for this rrp algorithm
  1511. */
  1512. rrp_instance->rrp_algo->mcast_recv (
  1513. rrp_instance,
  1514. deliver_fn_context->iface_no,
  1515. deliver_fn_context->context,
  1516. msg,
  1517. msg_len);
  1518. }
  1519. }
  1520. void rrp_iface_change_fn (
  1521. void *context,
  1522. const struct totem_ip_address *iface_addr)
  1523. {
  1524. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1525. deliver_fn_context->instance->my_nodeid = iface_addr->nodeid;
  1526. deliver_fn_context->instance->totemrrp_iface_change_fn (
  1527. deliver_fn_context->context,
  1528. iface_addr,
  1529. deliver_fn_context->iface_no);
  1530. }
  1531. int totemrrp_finalize (
  1532. void *rrp_context)
  1533. {
  1534. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1535. int i;
  1536. for (i = 0; i < instance->interface_count; i++) {
  1537. totemnet_finalize (instance->net_handles[i]);
  1538. }
  1539. free (instance->net_handles);
  1540. free (instance);
  1541. return (0);
  1542. }
  1543. static void rrp_target_set_completed (void *context)
  1544. {
  1545. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1546. deliver_fn_context->instance->totemrrp_target_set_completed (deliver_fn_context->context);
  1547. }
  1548. /*
  1549. * Totem Redundant Ring interface
  1550. * depends on poll abstraction, POSIX, IPV4
  1551. */
  1552. /*
  1553. * Create an instance
  1554. */
  1555. int totemrrp_initialize (
  1556. qb_loop_t *poll_handle,
  1557. void **rrp_context,
  1558. struct totem_config *totem_config,
  1559. totemsrp_stats_t *stats,
  1560. void *context,
  1561. void (*deliver_fn) (
  1562. void *context,
  1563. const void *msg,
  1564. unsigned int msg_len),
  1565. void (*iface_change_fn) (
  1566. void *context,
  1567. const struct totem_ip_address *iface_addr,
  1568. unsigned int iface_no),
  1569. void (*token_seqid_get) (
  1570. const void *msg,
  1571. unsigned int *seqid,
  1572. unsigned int *token_is),
  1573. unsigned int (*msgs_missing) (void),
  1574. void (*target_set_completed) (void *context))
  1575. {
  1576. struct totemrrp_instance *instance;
  1577. unsigned int res;
  1578. int i;
  1579. instance = malloc (sizeof (struct totemrrp_instance));
  1580. if (instance == 0) {
  1581. return (-1);
  1582. }
  1583. totemrrp_instance_initialize (instance);
  1584. instance->totem_config = totem_config;
  1585. stats->rrp = &instance->stats;
  1586. if (totem_config->interface_count > 1) {
  1587. instance->stats.interface_count = totem_config->interface_count;
  1588. instance->stats.faulty = calloc(instance->stats.interface_count, sizeof(uint8_t));
  1589. }
  1590. res = totemrrp_algorithm_set (
  1591. instance->totem_config,
  1592. instance);
  1593. if (res == -1) {
  1594. goto error_destroy;
  1595. }
  1596. /*
  1597. * Configure logging
  1598. */
  1599. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  1600. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  1601. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  1602. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  1603. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  1604. instance->totemrrp_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  1605. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  1606. instance->interfaces = totem_config->interfaces;
  1607. instance->poll_handle = poll_handle;
  1608. instance->totemrrp_deliver_fn = deliver_fn;
  1609. instance->totemrrp_iface_change_fn = iface_change_fn;
  1610. instance->totemrrp_token_seqid_get = token_seqid_get;
  1611. instance->totemrrp_target_set_completed = target_set_completed;
  1612. instance->totemrrp_msgs_missing = msgs_missing;
  1613. instance->interface_count = totem_config->interface_count;
  1614. instance->net_handles = malloc (sizeof (void *) * totem_config->interface_count);
  1615. instance->context = context;
  1616. instance->poll_handle = poll_handle;
  1617. for (i = 0; i < totem_config->interface_count; i++) {
  1618. struct deliver_fn_context *deliver_fn_context;
  1619. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  1620. assert (deliver_fn_context);
  1621. deliver_fn_context->instance = instance;
  1622. deliver_fn_context->context = context;
  1623. deliver_fn_context->iface_no = i;
  1624. instance->deliver_fn_context[i] = (void *)deliver_fn_context;
  1625. totemnet_initialize (
  1626. poll_handle,
  1627. &instance->net_handles[i],
  1628. totem_config,
  1629. i,
  1630. (void *)deliver_fn_context,
  1631. rrp_deliver_fn,
  1632. rrp_iface_change_fn,
  1633. rrp_target_set_completed);
  1634. totemnet_net_mtu_adjust (instance->net_handles[i], totem_config);
  1635. }
  1636. *rrp_context = instance;
  1637. return (0);
  1638. error_destroy:
  1639. free (instance);
  1640. return (res);
  1641. }
  1642. void *totemrrp_buffer_alloc (void *rrp_context)
  1643. {
  1644. struct totemrrp_instance *instance = rrp_context;
  1645. assert (instance != NULL);
  1646. return totemnet_buffer_alloc (instance->net_handles[0]);
  1647. }
  1648. void totemrrp_buffer_release (void *rrp_context, void *ptr)
  1649. {
  1650. struct totemrrp_instance *instance = rrp_context;
  1651. assert (instance != NULL);
  1652. totemnet_buffer_release (instance->net_handles[0], ptr);
  1653. }
  1654. int totemrrp_processor_count_set (
  1655. void *rrp_context,
  1656. unsigned int processor_count)
  1657. {
  1658. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1659. instance->rrp_algo->processor_count_set (instance, processor_count);
  1660. instance->processor_count = processor_count;
  1661. return (0);
  1662. }
  1663. int totemrrp_token_target_set (
  1664. void *rrp_context,
  1665. struct totem_ip_address *addr,
  1666. unsigned int iface_no)
  1667. {
  1668. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1669. instance->rrp_algo->token_target_set (instance, addr, iface_no);
  1670. return (0);
  1671. }
  1672. int totemrrp_recv_flush (void *rrp_context)
  1673. {
  1674. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1675. instance->rrp_algo->recv_flush (instance);
  1676. return (0);
  1677. }
  1678. int totemrrp_send_flush (void *rrp_context)
  1679. {
  1680. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1681. instance->rrp_algo->send_flush (instance);
  1682. return (0);
  1683. }
  1684. int totemrrp_token_send (
  1685. void *rrp_context,
  1686. const void *msg,
  1687. unsigned int msg_len)
  1688. {
  1689. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1690. instance->rrp_algo->token_send (instance, msg, msg_len);
  1691. return (0);
  1692. }
  1693. int totemrrp_mcast_flush_send (
  1694. void *rrp_context,
  1695. const void *msg,
  1696. unsigned int msg_len)
  1697. {
  1698. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1699. int res = 0;
  1700. // TODO this needs to return the result
  1701. instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
  1702. return (res);
  1703. }
  1704. int totemrrp_mcast_noflush_send (
  1705. void *rrp_context,
  1706. const void *msg,
  1707. unsigned int msg_len)
  1708. {
  1709. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1710. /*
  1711. * merge detects go out through mcast_flush_send so it is safe to
  1712. * flush these messages if we are only one processor. This avoids
  1713. * an encryption/hmac and decryption/hmac
  1714. */
  1715. if (instance->processor_count > 1) {
  1716. // TODO this needs to return the result
  1717. instance->rrp_algo->mcast_noflush_send (instance, msg, msg_len);
  1718. }
  1719. return (0);
  1720. }
  1721. int totemrrp_iface_check (void *rrp_context)
  1722. {
  1723. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1724. instance->rrp_algo->iface_check (instance);
  1725. return (0);
  1726. }
  1727. int totemrrp_ifaces_get (
  1728. void *rrp_context,
  1729. char ***status,
  1730. unsigned int *iface_count)
  1731. {
  1732. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1733. *status = instance->status;
  1734. if (iface_count) {
  1735. *iface_count = instance->interface_count;
  1736. }
  1737. return (0);
  1738. }
  1739. int totemrrp_crypto_set (
  1740. void *rrp_context,
  1741. unsigned int type)
  1742. {
  1743. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1744. int res;
  1745. res = totemnet_crypto_set(instance->net_handles[0], type);
  1746. return (res);
  1747. }
  1748. /*
  1749. * iface_no indicates the interface number [0, ..., interface_count-1] of the
  1750. * specific ring which will be reenabled. We specify iface_no == interface_count
  1751. * means reenabling all the rings.
  1752. */
  1753. int totemrrp_ring_reenable (
  1754. void *rrp_context,
  1755. unsigned int iface_no)
  1756. {
  1757. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1758. int res = 0;
  1759. unsigned int i;
  1760. instance->rrp_algo->ring_reenable (instance, iface_no);
  1761. if (iface_no == instance->interface_count) {
  1762. for (i = 0; i < instance->interface_count; i++) {
  1763. sprintf (instance->status[i], "ring %d active with no faults", i);
  1764. }
  1765. } else {
  1766. sprintf (instance->status[iface_no], "ring %d active with no faults", iface_no);
  1767. }
  1768. return (res);
  1769. }
  1770. extern int totemrrp_mcast_recv_empty (
  1771. void *rrp_context)
  1772. {
  1773. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1774. int res;
  1775. res = instance->rrp_algo->mcast_recv_empty (instance);
  1776. return (res);
  1777. }
  1778. int totemrrp_member_add (
  1779. void *rrp_context,
  1780. const struct totem_ip_address *member,
  1781. int iface_no)
  1782. {
  1783. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1784. int res;
  1785. res = instance->rrp_algo->member_add (instance, member, iface_no);
  1786. return (res);
  1787. }
  1788. int totemrrp_member_remove (
  1789. void *rrp_context,
  1790. const struct totem_ip_address *member,
  1791. int iface_no)
  1792. {
  1793. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1794. int res;
  1795. res = instance->rrp_algo->member_remove (instance, member, iface_no);
  1796. return (res);
  1797. }