totemrrp.c 54 KB

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