4
0

totemrrp.c 55 KB

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