totemrrp.c 54 KB

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