totemrrp.c 54 KB

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