totemrrp.c 57 KB

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