totempg.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /*
  2. * Copyright (c) 2003-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2005 OSDL.
  4. * Copyright (c) 2006-2009 Red Hat, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@redhat.com)
  9. * Author: Mark Haverkamp (markh@osdl.org)
  10. *
  11. * This software licensed under BSD license, the text of which follows:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * - Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  22. * contributors may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. * THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /*
  38. * FRAGMENTATION AND PACKING ALGORITHM:
  39. *
  40. * Assemble the entire message into one buffer
  41. * if full fragment
  42. * store fragment into lengths list
  43. * for each full fragment
  44. * multicast fragment
  45. * set length and fragment fields of pg mesage
  46. * store remaining multicast into head of fragmentation data and set lens field
  47. *
  48. * If a message exceeds the maximum packet size allowed by the totem
  49. * single ring protocol, the protocol could lose forward progress.
  50. * Statically calculating the allowed data amount doesn't work because
  51. * the amount of data allowed depends on the number of fragments in
  52. * each message. In this implementation, the maximum fragment size
  53. * is dynamically calculated for each fragment added to the message.
  54. * It is possible for a message to be two bytes short of the maximum
  55. * packet size. This occurs when a message or collection of
  56. * messages + the mcast header + the lens are two bytes short of the
  57. * end of the packet. Since another len field consumes two bytes, the
  58. * len field would consume the rest of the packet without room for data.
  59. *
  60. * One optimization would be to forgo the final len field and determine
  61. * it from the size of the udp datagram. Then this condition would no
  62. * longer occur.
  63. */
  64. /*
  65. * ASSEMBLY AND UNPACKING ALGORITHM:
  66. *
  67. * copy incoming packet into assembly data buffer indexed by current
  68. * location of end of fragment
  69. *
  70. * if not fragmented
  71. * deliver all messages in assembly data buffer
  72. * else
  73. * if msg_count > 1 and fragmented
  74. * deliver all messages except last message in assembly data buffer
  75. * copy last fragmented section to start of assembly data buffer
  76. * else
  77. * if msg_count = 1 and fragmented
  78. * do nothing
  79. *
  80. */
  81. #include <config.h>
  82. #ifdef HAVE_ALLOCA_H
  83. #include <alloca.h>
  84. #endif
  85. #include <netinet/in.h>
  86. #include <sys/uio.h>
  87. #include <stdio.h>
  88. #include <stdlib.h>
  89. #include <string.h>
  90. #include <assert.h>
  91. #include <pthread.h>
  92. #include <errno.h>
  93. #include <limits.h>
  94. #include <corosync/swab.h>
  95. #include <corosync/hdb.h>
  96. #include <corosync/list.h>
  97. #include <corosync/totem/coropoll.h>
  98. #include <corosync/totem/totempg.h>
  99. #define LOGSYS_UTILS_ONLY 1
  100. #include <corosync/engine/logsys.h>
  101. #include "totemmrp.h"
  102. #include "totemsrp.h"
  103. #define min(a,b) ((a) < (b)) ? a : b
  104. struct totempg_mcast_header {
  105. short version;
  106. short type;
  107. };
  108. /*
  109. * totempg_mcast structure
  110. *
  111. * header: Identify the mcast.
  112. * fragmented: Set if this message continues into next message
  113. * continuation: Set if this message is a continuation from last message
  114. * msg_count Indicates how many packed messages are contained
  115. * in the mcast.
  116. * Also, the size of each packed message and the messages themselves are
  117. * appended to the end of this structure when sent.
  118. */
  119. struct totempg_mcast {
  120. struct totempg_mcast_header header;
  121. unsigned char fragmented;
  122. unsigned char continuation;
  123. unsigned short msg_count;
  124. /*
  125. * short msg_len[msg_count];
  126. */
  127. /*
  128. * data for messages
  129. */
  130. };
  131. /*
  132. * Maximum packet size for totem pg messages
  133. */
  134. #define TOTEMPG_PACKET_SIZE (totempg_totem_config->net_mtu - \
  135. sizeof (struct totempg_mcast))
  136. /*
  137. * Local variables used for packing small messages
  138. */
  139. static unsigned short mcast_packed_msg_lens[FRAME_SIZE_MAX];
  140. static int mcast_packed_msg_count = 0;
  141. static int totempg_reserved = 1;
  142. static unsigned int totempg_size_limit;
  143. /*
  144. * Function and data used to log messages
  145. */
  146. static int totempg_log_level_security;
  147. static int totempg_log_level_error;
  148. static int totempg_log_level_warning;
  149. static int totempg_log_level_notice;
  150. static int totempg_log_level_debug;
  151. static int totempg_subsys_id;
  152. static void (*totempg_log_printf) (
  153. unsigned int rec_ident,
  154. const char *function,
  155. const char *file,
  156. int line,
  157. const char *format, ...) __attribute__((format(printf, 5, 6)));
  158. struct totem_config *totempg_totem_config;
  159. static totempg_stats_t totempg_stats;
  160. enum throw_away_mode {
  161. THROW_AWAY_INACTIVE,
  162. THROW_AWAY_ACTIVE
  163. };
  164. struct assembly {
  165. unsigned int nodeid;
  166. unsigned char data[MESSAGE_SIZE_MAX];
  167. int index;
  168. unsigned char last_frag_num;
  169. enum throw_away_mode throw_away_mode;
  170. struct list_head list;
  171. };
  172. static void assembly_deref (struct assembly *assembly);
  173. static int callback_token_received_fn (enum totem_callback_token_type type,
  174. const void *data);
  175. DECLARE_LIST_INIT(assembly_list_inuse);
  176. DECLARE_LIST_INIT(assembly_list_free);
  177. /*
  178. * Staging buffer for packed messages. Messages are staged in this buffer
  179. * before sending. Multiple messages may fit which cuts down on the
  180. * number of mcasts sent. If a message doesn't completely fit, then
  181. * the mcast header has a fragment bit set that says that there are more
  182. * data to follow. fragment_size is an index into the buffer. It indicates
  183. * the size of message data and where to place new message data.
  184. * fragment_contuation indicates whether the first packed message in
  185. * the buffer is a continuation of a previously packed fragment.
  186. */
  187. static unsigned char *fragmentation_data;
  188. static int fragment_size = 0;
  189. static int fragment_continuation = 0;
  190. static struct iovec iov_delv;
  191. static unsigned int totempg_max_handle = 0;
  192. struct totempg_group_instance {
  193. void (*deliver_fn) (
  194. unsigned int nodeid,
  195. const void *msg,
  196. unsigned int msg_len,
  197. int endian_conversion_required);
  198. void (*confchg_fn) (
  199. enum totem_configuration_type configuration_type,
  200. const unsigned int *member_list, size_t member_list_entries,
  201. const unsigned int *left_list, size_t left_list_entries,
  202. const unsigned int *joined_list, size_t joined_list_entries,
  203. const struct memb_ring_id *ring_id);
  204. struct totempg_group *groups;
  205. int groups_cnt;
  206. };
  207. DECLARE_HDB_DATABASE (totempg_groups_instance_database,NULL);
  208. static unsigned char next_fragment = 1;
  209. static pthread_mutex_t totempg_mutex = PTHREAD_MUTEX_INITIALIZER;
  210. static pthread_mutex_t callback_token_mutex = PTHREAD_MUTEX_INITIALIZER;
  211. static pthread_mutex_t mcast_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
  212. #define log_printf(level, format, args...) \
  213. do { \
  214. totempg_log_printf ( \
  215. LOGSYS_ENCODE_RECID(level, \
  216. totempg_subsys_id, \
  217. LOGSYS_RECID_LOG), \
  218. __FUNCTION__, __FILE__, __LINE__, \
  219. format, ##args); \
  220. } while (0);
  221. static int msg_count_send_ok (int msg_count);
  222. static int byte_count_send_ok (int byte_count);
  223. static struct assembly *assembly_ref (unsigned int nodeid)
  224. {
  225. struct assembly *assembly;
  226. struct list_head *list;
  227. /*
  228. * Search inuse list for node id and return assembly buffer if found
  229. */
  230. for (list = assembly_list_inuse.next;
  231. list != &assembly_list_inuse;
  232. list = list->next) {
  233. assembly = list_entry (list, struct assembly, list);
  234. if (nodeid == assembly->nodeid) {
  235. return (assembly);
  236. }
  237. }
  238. /*
  239. * Nothing found in inuse list get one from free list if available
  240. */
  241. if (list_empty (&assembly_list_free) == 0) {
  242. assembly = list_entry (assembly_list_free.next, struct assembly, list);
  243. list_del (&assembly->list);
  244. list_add (&assembly->list, &assembly_list_inuse);
  245. assembly->nodeid = nodeid;
  246. assembly->index = 0;
  247. assembly->last_frag_num = 0;
  248. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  249. return (assembly);
  250. }
  251. /*
  252. * Nothing available in inuse or free list, so allocate a new one
  253. */
  254. assembly = malloc (sizeof (struct assembly));
  255. /*
  256. * TODO handle memory allocation failure here
  257. */
  258. assert (assembly);
  259. assembly->nodeid = nodeid;
  260. assembly->data[0] = 0;
  261. assembly->index = 0;
  262. assembly->last_frag_num = 0;
  263. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  264. list_init (&assembly->list);
  265. list_add (&assembly->list, &assembly_list_inuse);
  266. return (assembly);
  267. }
  268. static void assembly_deref (struct assembly *assembly)
  269. {
  270. list_del (&assembly->list);
  271. list_add (&assembly->list, &assembly_list_free);
  272. }
  273. static inline void app_confchg_fn (
  274. enum totem_configuration_type configuration_type,
  275. const unsigned int *member_list, size_t member_list_entries,
  276. const unsigned int *left_list, size_t left_list_entries,
  277. const unsigned int *joined_list, size_t joined_list_entries,
  278. const struct memb_ring_id *ring_id)
  279. {
  280. int i;
  281. struct totempg_group_instance *instance;
  282. struct assembly *assembly;
  283. unsigned int res;
  284. /*
  285. * For every leaving processor, add to free list
  286. * This also has the side effect of clearing out the dataset
  287. * In the leaving processor's assembly buffer.
  288. */
  289. for (i = 0; i < left_list_entries; i++) {
  290. assembly = assembly_ref (left_list[i]);
  291. list_del (&assembly->list);
  292. list_add (&assembly->list, &assembly_list_free);
  293. }
  294. for (i = 0; i <= totempg_max_handle; i++) {
  295. res = hdb_handle_get (&totempg_groups_instance_database,
  296. hdb_nocheck_convert (i), (void *)&instance);
  297. if (res == 0) {
  298. if (instance->confchg_fn) {
  299. instance->confchg_fn (
  300. configuration_type,
  301. member_list,
  302. member_list_entries,
  303. left_list,
  304. left_list_entries,
  305. joined_list,
  306. joined_list_entries,
  307. ring_id);
  308. }
  309. hdb_handle_put (&totempg_groups_instance_database,
  310. hdb_nocheck_convert (i));
  311. }
  312. }
  313. }
  314. static inline void group_endian_convert (
  315. void *msg,
  316. int msg_len)
  317. {
  318. unsigned short *group_len;
  319. int i;
  320. char *aligned_msg;
  321. /*
  322. * Align data structure for sparc and ia64
  323. */
  324. if ((size_t)msg % 4 != 0) {
  325. aligned_msg = alloca(msg_len);
  326. memcpy(aligned_msg, msg, msg_len);
  327. } else {
  328. aligned_msg = msg;
  329. }
  330. group_len = (unsigned short *)aligned_msg;
  331. group_len[0] = swab16(group_len[0]);
  332. for (i = 1; i < group_len[0] + 1; i++) {
  333. group_len[i] = swab16(group_len[i]);
  334. }
  335. if (aligned_msg != msg) {
  336. memcpy(msg, aligned_msg, msg_len);
  337. }
  338. }
  339. static inline int group_matches (
  340. struct iovec *iovec,
  341. unsigned int iov_len,
  342. struct totempg_group *groups_b,
  343. unsigned int group_b_cnt,
  344. unsigned int *adjust_iovec)
  345. {
  346. unsigned short *group_len;
  347. char *group_name;
  348. int i;
  349. int j;
  350. struct iovec iovec_aligned = { NULL, 0 };
  351. assert (iov_len == 1);
  352. /*
  353. * Align data structure for sparc and ia64
  354. */
  355. if ((size_t)iovec->iov_base % 4 != 0) {
  356. iovec_aligned.iov_base = alloca(iovec->iov_len);
  357. memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len);
  358. iovec_aligned.iov_len = iovec->iov_len;
  359. iovec = &iovec_aligned;
  360. }
  361. group_len = (unsigned short *)iovec->iov_base;
  362. group_name = ((char *)iovec->iov_base) +
  363. sizeof (unsigned short) * (group_len[0] + 1);
  364. /*
  365. * Calculate amount to adjust the iovec by before delivering to app
  366. */
  367. *adjust_iovec = sizeof (unsigned short) * (group_len[0] + 1);
  368. for (i = 1; i < group_len[0] + 1; i++) {
  369. *adjust_iovec += group_len[i];
  370. }
  371. /*
  372. * Determine if this message should be delivered to this instance
  373. */
  374. for (i = 1; i < group_len[0] + 1; i++) {
  375. for (j = 0; j < group_b_cnt; j++) {
  376. if ((group_len[i] == groups_b[j].group_len) &&
  377. (memcmp (groups_b[j].group, group_name, group_len[i]) == 0)) {
  378. return (1);
  379. }
  380. }
  381. group_name += group_len[i];
  382. }
  383. return (0);
  384. }
  385. static inline void app_deliver_fn (
  386. unsigned int nodeid,
  387. void *msg,
  388. unsigned int msg_len,
  389. int endian_conversion_required)
  390. {
  391. int i;
  392. struct totempg_group_instance *instance;
  393. struct iovec stripped_iovec;
  394. unsigned int adjust_iovec;
  395. unsigned int res;
  396. struct iovec *iovec;
  397. struct iovec aligned_iovec = { NULL, 0 };
  398. if (endian_conversion_required) {
  399. group_endian_convert (msg, msg_len);
  400. }
  401. /*
  402. * TODO This function needs to be rewritten for proper alignment to avoid 3+ memory copies
  403. */
  404. /*
  405. * Align data structure for sparc and ia64
  406. */
  407. aligned_iovec.iov_base = alloca(msg_len);
  408. aligned_iovec.iov_len = msg_len;
  409. memcpy(aligned_iovec.iov_base, msg, msg_len);
  410. iovec = &aligned_iovec;
  411. for (i = 0; i <= totempg_max_handle; i++) {
  412. res = hdb_handle_get (&totempg_groups_instance_database,
  413. hdb_nocheck_convert (i), (void *)&instance);
  414. if (res == 0) {
  415. if (group_matches (iovec, 1, instance->groups, instance->groups_cnt, &adjust_iovec)) {
  416. stripped_iovec.iov_len = iovec->iov_len - adjust_iovec;
  417. stripped_iovec.iov_base = (char *)iovec->iov_base + adjust_iovec;
  418. /*
  419. * Align data structure for sparc and ia64
  420. */
  421. if ((char *)iovec->iov_base + adjust_iovec % 4 != 0) {
  422. /*
  423. * Deal with misalignment
  424. */
  425. stripped_iovec.iov_base =
  426. alloca (stripped_iovec.iov_len);
  427. memcpy (stripped_iovec.iov_base,
  428. (char *)iovec->iov_base + adjust_iovec,
  429. stripped_iovec.iov_len);
  430. }
  431. instance->deliver_fn (
  432. nodeid,
  433. stripped_iovec.iov_base,
  434. stripped_iovec.iov_len,
  435. endian_conversion_required);
  436. }
  437. hdb_handle_put (&totempg_groups_instance_database, hdb_nocheck_convert(i));
  438. }
  439. }
  440. }
  441. static void totempg_confchg_fn (
  442. enum totem_configuration_type configuration_type,
  443. const unsigned int *member_list, size_t member_list_entries,
  444. const unsigned int *left_list, size_t left_list_entries,
  445. const unsigned int *joined_list, size_t joined_list_entries,
  446. const struct memb_ring_id *ring_id)
  447. {
  448. // TODO optimize this
  449. app_confchg_fn (configuration_type,
  450. member_list, member_list_entries,
  451. left_list, left_list_entries,
  452. joined_list, joined_list_entries,
  453. ring_id);
  454. }
  455. static void totempg_deliver_fn (
  456. unsigned int nodeid,
  457. const void *msg,
  458. unsigned int msg_len,
  459. int endian_conversion_required)
  460. {
  461. struct totempg_mcast *mcast;
  462. unsigned short *msg_lens;
  463. int i;
  464. struct assembly *assembly;
  465. char header[FRAME_SIZE_MAX];
  466. int msg_count;
  467. int continuation;
  468. int start;
  469. const char *data;
  470. int datasize;
  471. assembly = assembly_ref (nodeid);
  472. assert (assembly);
  473. /*
  474. * Assemble the header into one block of data and
  475. * assemble the packet contents into one block of data to simplify delivery
  476. */
  477. mcast = (struct totempg_mcast *)msg;
  478. if (endian_conversion_required) {
  479. mcast->msg_count = swab16 (mcast->msg_count);
  480. }
  481. msg_count = mcast->msg_count;
  482. datasize = sizeof (struct totempg_mcast) +
  483. msg_count * sizeof (unsigned short);
  484. memcpy (header, msg, datasize);
  485. data = msg;
  486. msg_lens = (unsigned short *) (header + sizeof (struct totempg_mcast));
  487. if (endian_conversion_required) {
  488. for (i = 0; i < mcast->msg_count; i++) {
  489. msg_lens[i] = swab16 (msg_lens[i]);
  490. }
  491. }
  492. memcpy (&assembly->data[assembly->index], &data[datasize],
  493. msg_len - datasize);
  494. /*
  495. * If the last message in the buffer is a fragment, then we
  496. * can't deliver it. We'll first deliver the full messages
  497. * then adjust the assembly buffer so we can add the rest of the
  498. * fragment when it arrives.
  499. */
  500. msg_count = mcast->fragmented ? mcast->msg_count - 1 : mcast->msg_count;
  501. continuation = mcast->continuation;
  502. iov_delv.iov_base = (void *)&assembly->data[0];
  503. iov_delv.iov_len = assembly->index + msg_lens[0];
  504. /*
  505. * Make sure that if this message is a continuation, that it
  506. * matches the sequence number of the previous fragment.
  507. * Also, if the first packed message is a continuation
  508. * of a previous message, but the assembly buffer
  509. * is empty, then we need to discard it since we can't
  510. * assemble a complete message. Likewise, if this message isn't a
  511. * continuation and the assembly buffer is empty, we have to discard
  512. * the continued message.
  513. */
  514. start = 0;
  515. if (assembly->throw_away_mode == THROW_AWAY_ACTIVE) {
  516. /* Throw away the first msg block */
  517. if (mcast->fragmented == 0 || mcast->fragmented == 1) {
  518. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  519. assembly->index += msg_lens[0];
  520. iov_delv.iov_base = (void *)&assembly->data[assembly->index];
  521. iov_delv.iov_len = msg_lens[1];
  522. start = 1;
  523. }
  524. } else
  525. if (assembly->throw_away_mode == THROW_AWAY_INACTIVE) {
  526. if (continuation == assembly->last_frag_num) {
  527. assembly->last_frag_num = mcast->fragmented;
  528. for (i = start; i < msg_count; i++) {
  529. app_deliver_fn(nodeid, iov_delv.iov_base, iov_delv.iov_len,
  530. endian_conversion_required);
  531. assembly->index += msg_lens[i];
  532. iov_delv.iov_base = (void *)&assembly->data[assembly->index];
  533. if (i < (msg_count - 1)) {
  534. iov_delv.iov_len = msg_lens[i + 1];
  535. }
  536. }
  537. } else {
  538. assembly->throw_away_mode = THROW_AWAY_ACTIVE;
  539. }
  540. }
  541. if (mcast->fragmented == 0) {
  542. /*
  543. * End of messages, dereference assembly struct
  544. */
  545. assembly->last_frag_num = 0;
  546. assembly->index = 0;
  547. assembly_deref (assembly);
  548. } else {
  549. /*
  550. * Message is fragmented, keep around assembly list
  551. */
  552. if (mcast->msg_count > 1) {
  553. memmove (&assembly->data[0],
  554. &assembly->data[assembly->index],
  555. msg_lens[msg_count]);
  556. assembly->index = 0;
  557. }
  558. assembly->index += msg_lens[msg_count];
  559. }
  560. }
  561. /*
  562. * Totem Process Group Abstraction
  563. * depends on poll abstraction, POSIX, IPV4
  564. */
  565. void *callback_token_received_handle;
  566. int callback_token_received_fn (enum totem_callback_token_type type,
  567. const void *data)
  568. {
  569. struct totempg_mcast mcast;
  570. struct iovec iovecs[3];
  571. pthread_mutex_lock (&mcast_msg_mutex);
  572. if (mcast_packed_msg_count == 0) {
  573. pthread_mutex_unlock (&mcast_msg_mutex);
  574. return (0);
  575. }
  576. if (totemmrp_avail() == 0) {
  577. pthread_mutex_unlock (&mcast_msg_mutex);
  578. return (0);
  579. }
  580. mcast.header.version = 0;
  581. mcast.fragmented = 0;
  582. /*
  583. * Was the first message in this buffer a continuation of a
  584. * fragmented message?
  585. */
  586. mcast.continuation = fragment_continuation;
  587. fragment_continuation = 0;
  588. mcast.msg_count = mcast_packed_msg_count;
  589. iovecs[0].iov_base = (void *)&mcast;
  590. iovecs[0].iov_len = sizeof (struct totempg_mcast);
  591. iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
  592. iovecs[1].iov_len = mcast_packed_msg_count * sizeof (unsigned short);
  593. iovecs[2].iov_base = (void *)&fragmentation_data[0];
  594. iovecs[2].iov_len = fragment_size;
  595. (void)totemmrp_mcast (iovecs, 3, 0);
  596. mcast_packed_msg_count = 0;
  597. fragment_size = 0;
  598. pthread_mutex_unlock (&mcast_msg_mutex);
  599. return (0);
  600. }
  601. /*
  602. * Initialize the totem process group abstraction
  603. */
  604. int totempg_initialize (
  605. hdb_handle_t poll_handle,
  606. struct totem_config *totem_config)
  607. {
  608. int res;
  609. totempg_totem_config = totem_config;
  610. totempg_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  611. totempg_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  612. totempg_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  613. totempg_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  614. totempg_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  615. totempg_log_printf = totem_config->totem_logging_configuration.log_printf;
  616. totempg_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  617. fragmentation_data = malloc (TOTEMPG_PACKET_SIZE);
  618. if (fragmentation_data == 0) {
  619. return (-1);
  620. }
  621. totemsrp_net_mtu_adjust (totem_config);
  622. res = totemmrp_initialize (
  623. poll_handle,
  624. totem_config,
  625. &totempg_stats,
  626. totempg_deliver_fn,
  627. totempg_confchg_fn);
  628. totemmrp_callback_token_create (
  629. &callback_token_received_handle,
  630. TOTEM_CALLBACK_TOKEN_RECEIVED,
  631. 0,
  632. callback_token_received_fn,
  633. 0);
  634. totempg_size_limit = (totemmrp_avail() - 1) *
  635. (totempg_totem_config->net_mtu -
  636. sizeof (struct totempg_mcast) - 16);
  637. return (res);
  638. }
  639. void totempg_finalize (void)
  640. {
  641. pthread_mutex_lock (&totempg_mutex);
  642. totemmrp_finalize ();
  643. pthread_mutex_unlock (&totempg_mutex);
  644. }
  645. /*
  646. * Multicast a message
  647. */
  648. static int mcast_msg (
  649. struct iovec *iovec_in,
  650. unsigned int iov_len,
  651. int guarantee)
  652. {
  653. int res = 0;
  654. struct totempg_mcast mcast;
  655. struct iovec iovecs[3];
  656. struct iovec iovec[64];
  657. int i;
  658. int dest, src;
  659. int max_packet_size = 0;
  660. int copy_len = 0;
  661. int copy_base = 0;
  662. int total_size = 0;
  663. pthread_mutex_lock (&mcast_msg_mutex);
  664. totemmrp_event_signal (TOTEM_EVENT_NEW_MSG, 1);
  665. /*
  666. * Remove zero length iovectors from the list
  667. */
  668. assert (iov_len < 64);
  669. for (dest = 0, src = 0; src < iov_len; src++) {
  670. if (iovec_in[src].iov_len) {
  671. memcpy (&iovec[dest++], &iovec_in[src],
  672. sizeof (struct iovec));
  673. }
  674. }
  675. iov_len = dest;
  676. max_packet_size = TOTEMPG_PACKET_SIZE -
  677. (sizeof (unsigned short) * (mcast_packed_msg_count + 1));
  678. mcast_packed_msg_lens[mcast_packed_msg_count] = 0;
  679. /*
  680. * Check if we would overwrite new message queue
  681. */
  682. for (i = 0; i < iov_len; i++) {
  683. total_size += iovec[i].iov_len;
  684. }
  685. if (byte_count_send_ok (total_size + sizeof(unsigned short) *
  686. (mcast_packed_msg_count)) == 0) {
  687. pthread_mutex_unlock (&mcast_msg_mutex);
  688. return(-1);
  689. }
  690. mcast.header.version = 0;
  691. for (i = 0; i < iov_len; ) {
  692. mcast.fragmented = 0;
  693. mcast.continuation = fragment_continuation;
  694. copy_len = iovec[i].iov_len - copy_base;
  695. /*
  696. * If it all fits with room left over, copy it in.
  697. * We need to leave at least sizeof(short) + 1 bytes in the
  698. * fragment_buffer on exit so that max_packet_size + fragment_size
  699. * doesn't exceed the size of the fragment_buffer on the next call.
  700. */
  701. if ((copy_len + fragment_size) <
  702. (max_packet_size - sizeof (unsigned short))) {
  703. memcpy (&fragmentation_data[fragment_size],
  704. (char *)iovec[i].iov_base + copy_base, copy_len);
  705. fragment_size += copy_len;
  706. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  707. next_fragment = 1;
  708. copy_len = 0;
  709. copy_base = 0;
  710. i++;
  711. continue;
  712. /*
  713. * If it just fits or is too big, then send out what fits.
  714. */
  715. } else {
  716. unsigned char *data_ptr;
  717. copy_len = min(copy_len, max_packet_size - fragment_size);
  718. if( copy_len == max_packet_size )
  719. data_ptr = (unsigned char *)iovec[i].iov_base + copy_base;
  720. else {
  721. data_ptr = fragmentation_data;
  722. memcpy (&fragmentation_data[fragment_size],
  723. (unsigned char *)iovec[i].iov_base + copy_base, copy_len);
  724. }
  725. memcpy (&fragmentation_data[fragment_size],
  726. (unsigned char *)iovec[i].iov_base + copy_base, copy_len);
  727. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  728. /*
  729. * if we're not on the last iovec or the iovec is too large to
  730. * fit, then indicate a fragment. This also means that the next
  731. * message will have the continuation of this one.
  732. */
  733. if ((i < (iov_len - 1)) ||
  734. ((copy_base + copy_len) < iovec[i].iov_len)) {
  735. if (!next_fragment) {
  736. next_fragment++;
  737. }
  738. fragment_continuation = next_fragment;
  739. mcast.fragmented = next_fragment++;
  740. assert(fragment_continuation != 0);
  741. assert(mcast.fragmented != 0);
  742. } else {
  743. fragment_continuation = 0;
  744. }
  745. /*
  746. * assemble the message and send it
  747. */
  748. mcast.msg_count = ++mcast_packed_msg_count;
  749. iovecs[0].iov_base = (void *)&mcast;
  750. iovecs[0].iov_len = sizeof(struct totempg_mcast);
  751. iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
  752. iovecs[1].iov_len = mcast_packed_msg_count *
  753. sizeof(unsigned short);
  754. iovecs[2].iov_base = (void *)data_ptr;
  755. iovecs[2].iov_len = max_packet_size;
  756. assert (totemmrp_avail() > 0);
  757. res = totemmrp_mcast (iovecs, 3, guarantee);
  758. if (res == -1) {
  759. goto error_exit;
  760. }
  761. /*
  762. * Recalculate counts and indexes for the next.
  763. */
  764. mcast_packed_msg_lens[0] = 0;
  765. mcast_packed_msg_count = 0;
  766. fragment_size = 0;
  767. max_packet_size = TOTEMPG_PACKET_SIZE - (sizeof(unsigned short));
  768. /*
  769. * If the iovec all fit, go to the next iovec
  770. */
  771. if ((copy_base + copy_len) == iovec[i].iov_len) {
  772. copy_len = 0;
  773. copy_base = 0;
  774. i++;
  775. /*
  776. * Continue with the rest of the current iovec.
  777. */
  778. } else {
  779. copy_base += copy_len;
  780. }
  781. }
  782. }
  783. /*
  784. * Bump only if we added message data. This may be zero if
  785. * the last buffer just fit into the fragmentation_data buffer
  786. * and we were at the last iovec.
  787. */
  788. if (mcast_packed_msg_lens[mcast_packed_msg_count]) {
  789. mcast_packed_msg_count++;
  790. }
  791. error_exit:
  792. pthread_mutex_unlock (&mcast_msg_mutex);
  793. return (res);
  794. }
  795. /*
  796. * Determine if a message of msg_size could be queued
  797. */
  798. static int msg_count_send_ok (
  799. int msg_count)
  800. {
  801. int avail = 0;
  802. avail = totemmrp_avail ();
  803. return ((avail - totempg_reserved) > msg_count);
  804. }
  805. static int byte_count_send_ok (
  806. int byte_count)
  807. {
  808. unsigned int msg_count = 0;
  809. int avail = 0;
  810. avail = totemmrp_avail ();
  811. msg_count = (byte_count / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  812. return (avail >= msg_count);
  813. }
  814. static int send_reserve (
  815. int msg_size)
  816. {
  817. unsigned int msg_count = 0;
  818. msg_count = (msg_size / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  819. totempg_reserved += msg_count;
  820. return (msg_count);
  821. }
  822. static void send_release (
  823. int msg_count)
  824. {
  825. totempg_reserved -= msg_count;
  826. }
  827. int totempg_callback_token_create (
  828. void **handle_out,
  829. enum totem_callback_token_type type,
  830. int delete,
  831. int (*callback_fn) (enum totem_callback_token_type type, const void *),
  832. const void *data)
  833. {
  834. unsigned int res;
  835. pthread_mutex_lock (&callback_token_mutex);
  836. res = totemmrp_callback_token_create (handle_out, type, delete,
  837. callback_fn, data);
  838. pthread_mutex_unlock (&callback_token_mutex);
  839. return (res);
  840. }
  841. void totempg_callback_token_destroy (
  842. void *handle_out)
  843. {
  844. pthread_mutex_lock (&callback_token_mutex);
  845. totemmrp_callback_token_destroy (handle_out);
  846. pthread_mutex_unlock (&callback_token_mutex);
  847. }
  848. /*
  849. * vi: set autoindent tabstop=4 shiftwidth=4 :
  850. */
  851. int totempg_groups_initialize (
  852. hdb_handle_t *handle,
  853. void (*deliver_fn) (
  854. unsigned int nodeid,
  855. const void *msg,
  856. unsigned int msg_len,
  857. int endian_conversion_required),
  858. void (*confchg_fn) (
  859. enum totem_configuration_type configuration_type,
  860. const unsigned int *member_list, size_t member_list_entries,
  861. const unsigned int *left_list, size_t left_list_entries,
  862. const unsigned int *joined_list, size_t joined_list_entries,
  863. const struct memb_ring_id *ring_id))
  864. {
  865. struct totempg_group_instance *instance;
  866. unsigned int res;
  867. pthread_mutex_lock (&totempg_mutex);
  868. res = hdb_handle_create (&totempg_groups_instance_database,
  869. sizeof (struct totempg_group_instance), handle);
  870. if (res != 0) {
  871. goto error_exit;
  872. }
  873. if (*handle > totempg_max_handle) {
  874. totempg_max_handle = *handle;
  875. }
  876. res = hdb_handle_get (&totempg_groups_instance_database, *handle,
  877. (void *)&instance);
  878. if (res != 0) {
  879. goto error_destroy;
  880. }
  881. instance->deliver_fn = deliver_fn;
  882. instance->confchg_fn = confchg_fn;
  883. instance->groups = 0;
  884. instance->groups_cnt = 0;
  885. hdb_handle_put (&totempg_groups_instance_database, *handle);
  886. pthread_mutex_unlock (&totempg_mutex);
  887. return (0);
  888. error_destroy:
  889. hdb_handle_destroy (&totempg_groups_instance_database, *handle);
  890. error_exit:
  891. pthread_mutex_unlock (&totempg_mutex);
  892. return (-1);
  893. }
  894. int totempg_groups_join (
  895. hdb_handle_t handle,
  896. const struct totempg_group *groups,
  897. size_t group_cnt)
  898. {
  899. struct totempg_group_instance *instance;
  900. struct totempg_group *new_groups;
  901. unsigned int res;
  902. pthread_mutex_lock (&totempg_mutex);
  903. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  904. (void *)&instance);
  905. if (res != 0) {
  906. goto error_exit;
  907. }
  908. new_groups = realloc (instance->groups,
  909. sizeof (struct totempg_group) *
  910. (instance->groups_cnt + group_cnt));
  911. if (new_groups == 0) {
  912. res = ENOMEM;
  913. goto error_exit;
  914. }
  915. memcpy (&new_groups[instance->groups_cnt],
  916. groups, group_cnt * sizeof (struct totempg_group));
  917. instance->groups = new_groups;
  918. instance->groups_cnt += group_cnt;
  919. hdb_handle_put (&totempg_groups_instance_database, handle);
  920. error_exit:
  921. pthread_mutex_unlock (&totempg_mutex);
  922. return (res);
  923. }
  924. int totempg_groups_leave (
  925. hdb_handle_t handle,
  926. const struct totempg_group *groups,
  927. size_t group_cnt)
  928. {
  929. struct totempg_group_instance *instance;
  930. unsigned int res;
  931. pthread_mutex_lock (&totempg_mutex);
  932. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  933. (void *)&instance);
  934. if (res != 0) {
  935. goto error_exit;
  936. }
  937. hdb_handle_put (&totempg_groups_instance_database, handle);
  938. error_exit:
  939. pthread_mutex_unlock (&totempg_mutex);
  940. return (res);
  941. }
  942. #define MAX_IOVECS_FROM_APP 32
  943. #define MAX_GROUPS_PER_MSG 32
  944. int totempg_groups_mcast_joined (
  945. hdb_handle_t handle,
  946. const struct iovec *iovec,
  947. unsigned int iov_len,
  948. int guarantee)
  949. {
  950. struct totempg_group_instance *instance;
  951. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  952. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  953. int i;
  954. unsigned int res;
  955. pthread_mutex_lock (&totempg_mutex);
  956. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  957. (void *)&instance);
  958. if (res != 0) {
  959. goto error_exit;
  960. }
  961. /*
  962. * Build group_len structure and the iovec_mcast structure
  963. */
  964. group_len[0] = instance->groups_cnt;
  965. for (i = 0; i < instance->groups_cnt; i++) {
  966. group_len[i + 1] = instance->groups[i].group_len;
  967. iovec_mcast[i + 1].iov_len = instance->groups[i].group_len;
  968. iovec_mcast[i + 1].iov_base = (void *) instance->groups[i].group;
  969. }
  970. iovec_mcast[0].iov_len = (instance->groups_cnt + 1) * sizeof (unsigned short);
  971. iovec_mcast[0].iov_base = group_len;
  972. for (i = 0; i < iov_len; i++) {
  973. iovec_mcast[i + instance->groups_cnt + 1].iov_len = iovec[i].iov_len;
  974. iovec_mcast[i + instance->groups_cnt + 1].iov_base = iovec[i].iov_base;
  975. }
  976. res = mcast_msg (iovec_mcast, iov_len + instance->groups_cnt + 1, guarantee);
  977. hdb_handle_put (&totempg_groups_instance_database, handle);
  978. error_exit:
  979. pthread_mutex_unlock (&totempg_mutex);
  980. return (res);
  981. }
  982. int totempg_groups_joined_reserve (
  983. hdb_handle_t handle,
  984. const struct iovec *iovec,
  985. unsigned int iov_len)
  986. {
  987. struct totempg_group_instance *instance;
  988. unsigned int size = 0;
  989. unsigned int i;
  990. unsigned int res;
  991. unsigned int reserved = 0;
  992. pthread_mutex_lock (&totempg_mutex);
  993. pthread_mutex_lock (&mcast_msg_mutex);
  994. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  995. (void *)&instance);
  996. if (res != 0) {
  997. goto error_exit;
  998. }
  999. for (i = 0; i < instance->groups_cnt; i++) {
  1000. size += instance->groups[i].group_len;
  1001. }
  1002. for (i = 0; i < iov_len; i++) {
  1003. size += iovec[i].iov_len;
  1004. }
  1005. if (size >= totempg_size_limit) {
  1006. reserved = -1;
  1007. goto error_put;
  1008. }
  1009. reserved = send_reserve (size);
  1010. if (msg_count_send_ok (reserved) == 0) {
  1011. send_release (reserved);
  1012. reserved = 0;
  1013. }
  1014. error_put:
  1015. hdb_handle_put (&totempg_groups_instance_database, handle);
  1016. error_exit:
  1017. pthread_mutex_unlock (&mcast_msg_mutex);
  1018. pthread_mutex_unlock (&totempg_mutex);
  1019. return (reserved);
  1020. }
  1021. int totempg_groups_joined_release (int msg_count)
  1022. {
  1023. pthread_mutex_lock (&totempg_mutex);
  1024. pthread_mutex_lock (&mcast_msg_mutex);
  1025. send_release (msg_count);
  1026. pthread_mutex_unlock (&mcast_msg_mutex);
  1027. pthread_mutex_unlock (&totempg_mutex);
  1028. return 0;
  1029. }
  1030. int totempg_groups_mcast_groups (
  1031. hdb_handle_t handle,
  1032. int guarantee,
  1033. const struct totempg_group *groups,
  1034. size_t groups_cnt,
  1035. const struct iovec *iovec,
  1036. unsigned int iov_len)
  1037. {
  1038. struct totempg_group_instance *instance;
  1039. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  1040. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  1041. int i;
  1042. unsigned int res;
  1043. pthread_mutex_lock (&totempg_mutex);
  1044. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1045. (void *)&instance);
  1046. if (res != 0) {
  1047. goto error_exit;
  1048. }
  1049. /*
  1050. * Build group_len structure and the iovec_mcast structure
  1051. */
  1052. group_len[0] = groups_cnt;
  1053. for (i = 0; i < groups_cnt; i++) {
  1054. group_len[i + 1] = groups[i].group_len;
  1055. iovec_mcast[i + 1].iov_len = groups[i].group_len;
  1056. iovec_mcast[i + 1].iov_base = (void *) groups[i].group;
  1057. }
  1058. iovec_mcast[0].iov_len = (groups_cnt + 1) * sizeof (unsigned short);
  1059. iovec_mcast[0].iov_base = group_len;
  1060. for (i = 0; i < iov_len; i++) {
  1061. iovec_mcast[i + groups_cnt + 1].iov_len = iovec[i].iov_len;
  1062. iovec_mcast[i + groups_cnt + 1].iov_base = iovec[i].iov_base;
  1063. }
  1064. res = mcast_msg (iovec_mcast, iov_len + groups_cnt + 1, guarantee);
  1065. hdb_handle_put (&totempg_groups_instance_database, handle);
  1066. error_exit:
  1067. pthread_mutex_unlock (&totempg_mutex);
  1068. return (res);
  1069. }
  1070. /*
  1071. * Returns -1 if error, 0 if can't send, 1 if can send the message
  1072. */
  1073. int totempg_groups_send_ok_groups (
  1074. hdb_handle_t handle,
  1075. const struct totempg_group *groups,
  1076. size_t groups_cnt,
  1077. const struct iovec *iovec,
  1078. unsigned int iov_len)
  1079. {
  1080. struct totempg_group_instance *instance;
  1081. unsigned int size = 0;
  1082. unsigned int i;
  1083. unsigned int res;
  1084. pthread_mutex_lock (&totempg_mutex);
  1085. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1086. (void *)&instance);
  1087. if (res != 0) {
  1088. goto error_exit;
  1089. }
  1090. for (i = 0; i < groups_cnt; i++) {
  1091. size += groups[i].group_len;
  1092. }
  1093. for (i = 0; i < iov_len; i++) {
  1094. size += iovec[i].iov_len;
  1095. }
  1096. res = msg_count_send_ok (size);
  1097. hdb_handle_put (&totempg_groups_instance_database, handle);
  1098. error_exit:
  1099. pthread_mutex_unlock (&totempg_mutex);
  1100. return (res);
  1101. }
  1102. int totempg_ifaces_get (
  1103. unsigned int nodeid,
  1104. struct totem_ip_address *interfaces,
  1105. char ***status,
  1106. unsigned int *iface_count)
  1107. {
  1108. int res;
  1109. res = totemmrp_ifaces_get (
  1110. nodeid,
  1111. interfaces,
  1112. status,
  1113. iface_count);
  1114. return (res);
  1115. }
  1116. void totempg_event_signal (enum totem_event_type type, int value)
  1117. {
  1118. totemmrp_event_signal (type, value);
  1119. }
  1120. void* totempg_get_stats (void)
  1121. {
  1122. return &totempg_stats;
  1123. }
  1124. int totempg_crypto_set (
  1125. unsigned int type)
  1126. {
  1127. int res;
  1128. res = totemmrp_crypto_set (
  1129. type);
  1130. return (res);
  1131. }
  1132. int totempg_ring_reenable (void)
  1133. {
  1134. int res;
  1135. res = totemmrp_ring_reenable ();
  1136. return (res);
  1137. }
  1138. const char *totempg_ifaces_print (unsigned int nodeid)
  1139. {
  1140. static char iface_string[256 * INTERFACE_MAX];
  1141. char one_iface[64];
  1142. struct totem_ip_address interfaces[INTERFACE_MAX];
  1143. char **status;
  1144. unsigned int iface_count;
  1145. unsigned int i;
  1146. int res;
  1147. iface_string[0] = '\0';
  1148. res = totempg_ifaces_get (nodeid, interfaces, &status, &iface_count);
  1149. if (res == -1) {
  1150. return ("no interface found for nodeid");
  1151. }
  1152. for (i = 0; i < iface_count; i++) {
  1153. sprintf (one_iface, "r(%d) ip(%s) ",
  1154. i, totemip_print (&interfaces[i]));
  1155. strcat (iface_string, one_iface);
  1156. }
  1157. return (iface_string);
  1158. }
  1159. unsigned int totempg_my_nodeid_get (void)
  1160. {
  1161. return (totemmrp_my_nodeid_get());
  1162. }
  1163. int totempg_my_family_get (void)
  1164. {
  1165. return (totemmrp_my_family_get());
  1166. }
  1167. extern void totempg_service_ready_register (
  1168. void (*totem_service_ready) (void))
  1169. {
  1170. totemmrp_service_ready_register (totem_service_ready);
  1171. }
  1172. extern int totempg_member_add (
  1173. const struct totem_ip_address *member,
  1174. int ring_no);
  1175. extern int totempg_member_remove (
  1176. const struct totem_ip_address *member,
  1177. int ring_no);