totemrrp.c 54 KB

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