totemrrp.c 53 KB

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