totemrrp.c 54 KB

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