totempg.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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 = 0;
  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. enum throw_away_mode {
  160. THROW_AWAY_INACTIVE,
  161. THROW_AWAY_ACTIVE
  162. };
  163. struct assembly {
  164. unsigned int nodeid;
  165. unsigned char data[MESSAGE_SIZE_MAX];
  166. int index;
  167. unsigned char last_frag_num;
  168. enum throw_away_mode throw_away_mode;
  169. struct list_head list;
  170. };
  171. static void assembly_deref (struct assembly *assembly);
  172. static int callback_token_received_fn (enum totem_callback_token_type type,
  173. const void *data);
  174. DECLARE_LIST_INIT(assembly_list_inuse);
  175. DECLARE_LIST_INIT(assembly_list_free);
  176. /*
  177. * Staging buffer for packed messages. Messages are staged in this buffer
  178. * before sending. Multiple messages may fit which cuts down on the
  179. * number of mcasts sent. If a message doesn't completely fit, then
  180. * the mcast header has a fragment bit set that says that there are more
  181. * data to follow. fragment_size is an index into the buffer. It indicates
  182. * the size of message data and where to place new message data.
  183. * fragment_contuation indicates whether the first packed message in
  184. * the buffer is a continuation of a previously packed fragment.
  185. */
  186. static unsigned char *fragmentation_data;
  187. static int fragment_size = 0;
  188. static int fragment_continuation = 0;
  189. static struct iovec iov_delv;
  190. static unsigned int totempg_max_handle = 0;
  191. struct totempg_group_instance {
  192. void (*deliver_fn) (
  193. unsigned int nodeid,
  194. const void *msg,
  195. unsigned int msg_len,
  196. int endian_conversion_required);
  197. void (*confchg_fn) (
  198. enum totem_configuration_type configuration_type,
  199. const unsigned int *member_list, size_t member_list_entries,
  200. const unsigned int *left_list, size_t left_list_entries,
  201. const unsigned int *joined_list, size_t joined_list_entries,
  202. const struct memb_ring_id *ring_id);
  203. struct totempg_group *groups;
  204. int groups_cnt;
  205. };
  206. DECLARE_HDB_DATABASE (totempg_groups_instance_database,NULL);
  207. static unsigned char next_fragment = 1;
  208. static pthread_mutex_t totempg_mutex = PTHREAD_MUTEX_INITIALIZER;
  209. static pthread_mutex_t callback_token_mutex = PTHREAD_MUTEX_INITIALIZER;
  210. static pthread_mutex_t mcast_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
  211. #define log_printf(level, format, args...) \
  212. do { \
  213. totempg_log_printf ( \
  214. LOGSYS_ENCODE_RECID(level, \
  215. totempg_subsys_id, \
  216. LOGSYS_RECID_LOG), \
  217. __FUNCTION__, __FILE__, __LINE__, \
  218. format, ##args); \
  219. } while (0);
  220. static int msg_count_send_ok (int msg_count);
  221. static int byte_count_send_ok (int byte_count);
  222. static struct assembly *assembly_ref (unsigned int nodeid)
  223. {
  224. struct assembly *assembly;
  225. struct list_head *list;
  226. /*
  227. * Search inuse list for node id and return assembly buffer if found
  228. */
  229. for (list = assembly_list_inuse.next;
  230. list != &assembly_list_inuse;
  231. list = list->next) {
  232. assembly = list_entry (list, struct assembly, list);
  233. if (nodeid == assembly->nodeid) {
  234. return (assembly);
  235. }
  236. }
  237. /*
  238. * Nothing found in inuse list get one from free list if available
  239. */
  240. if (list_empty (&assembly_list_free) == 0) {
  241. assembly = list_entry (assembly_list_free.next, struct assembly, list);
  242. list_del (&assembly->list);
  243. list_add (&assembly->list, &assembly_list_inuse);
  244. assembly->nodeid = nodeid;
  245. assembly->index = 0;
  246. assembly->last_frag_num = 0;
  247. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  248. return (assembly);
  249. }
  250. /*
  251. * Nothing available in inuse or free list, so allocate a new one
  252. */
  253. assembly = malloc (sizeof (struct assembly));
  254. /*
  255. * TODO handle memory allocation failure here
  256. */
  257. assert (assembly);
  258. assembly->nodeid = nodeid;
  259. assembly->data[0] = 0;
  260. assembly->index = 0;
  261. assembly->last_frag_num = 0;
  262. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  263. list_init (&assembly->list);
  264. list_add (&assembly->list, &assembly_list_inuse);
  265. return (assembly);
  266. }
  267. static void assembly_deref (struct assembly *assembly)
  268. {
  269. list_del (&assembly->list);
  270. list_add (&assembly->list, &assembly_list_free);
  271. }
  272. static inline void app_confchg_fn (
  273. enum totem_configuration_type configuration_type,
  274. const unsigned int *member_list, size_t member_list_entries,
  275. const unsigned int *left_list, size_t left_list_entries,
  276. const unsigned int *joined_list, size_t joined_list_entries,
  277. const struct memb_ring_id *ring_id)
  278. {
  279. int i;
  280. struct totempg_group_instance *instance;
  281. struct assembly *assembly;
  282. unsigned int res;
  283. /*
  284. * For every leaving processor, add to free list
  285. * This also has the side effect of clearing out the dataset
  286. * In the leaving processor's assembly buffer.
  287. */
  288. for (i = 0; i < left_list_entries; i++) {
  289. assembly = assembly_ref (left_list[i]);
  290. list_del (&assembly->list);
  291. list_add (&assembly->list, &assembly_list_free);
  292. }
  293. for (i = 0; i <= totempg_max_handle; i++) {
  294. res = hdb_handle_get (&totempg_groups_instance_database,
  295. hdb_nocheck_convert (i), (void *)&instance);
  296. if (res == 0) {
  297. if (instance->confchg_fn) {
  298. instance->confchg_fn (
  299. configuration_type,
  300. member_list,
  301. member_list_entries,
  302. left_list,
  303. left_list_entries,
  304. joined_list,
  305. joined_list_entries,
  306. ring_id);
  307. }
  308. hdb_handle_put (&totempg_groups_instance_database,
  309. hdb_nocheck_convert (i));
  310. }
  311. }
  312. }
  313. static inline void group_endian_convert (
  314. void *msg,
  315. int msg_len)
  316. {
  317. unsigned short *group_len;
  318. int i;
  319. char *aligned_msg;
  320. /*
  321. * Align data structure for sparc and ia64
  322. */
  323. if ((size_t)msg % 4 != 0) {
  324. aligned_msg = alloca(msg_len);
  325. memcpy(aligned_msg, msg, msg_len);
  326. } else {
  327. aligned_msg = msg;
  328. }
  329. group_len = (unsigned short *)aligned_msg;
  330. group_len[0] = swab16(group_len[0]);
  331. for (i = 1; i < group_len[0] + 1; i++) {
  332. group_len[i] = swab16(group_len[i]);
  333. }
  334. if (aligned_msg != msg) {
  335. memcpy(msg, aligned_msg, msg_len);
  336. }
  337. }
  338. static inline int group_matches (
  339. struct iovec *iovec,
  340. unsigned int iov_len,
  341. struct totempg_group *groups_b,
  342. unsigned int group_b_cnt,
  343. unsigned int *adjust_iovec)
  344. {
  345. unsigned short *group_len;
  346. char *group_name;
  347. int i;
  348. int j;
  349. struct iovec iovec_aligned = { NULL, 0 };
  350. assert (iov_len == 1);
  351. /*
  352. * Align data structure for sparc and ia64
  353. */
  354. if ((size_t)iovec->iov_base % 4 != 0) {
  355. iovec_aligned.iov_base = alloca(iovec->iov_len);
  356. memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len);
  357. iovec_aligned.iov_len = iovec->iov_len;
  358. iovec = &iovec_aligned;
  359. }
  360. group_len = (unsigned short *)iovec->iov_base;
  361. group_name = ((char *)iovec->iov_base) +
  362. sizeof (unsigned short) * (group_len[0] + 1);
  363. /*
  364. * Calculate amount to adjust the iovec by before delivering to app
  365. */
  366. *adjust_iovec = sizeof (unsigned short) * (group_len[0] + 1);
  367. for (i = 1; i < group_len[0] + 1; i++) {
  368. *adjust_iovec += group_len[i];
  369. }
  370. /*
  371. * Determine if this message should be delivered to this instance
  372. */
  373. for (i = 1; i < group_len[0] + 1; i++) {
  374. for (j = 0; j < group_b_cnt; j++) {
  375. if ((group_len[i] == groups_b[j].group_len) &&
  376. (memcmp (groups_b[j].group, group_name, group_len[i]) == 0)) {
  377. return (1);
  378. }
  379. }
  380. group_name += group_len[i];
  381. }
  382. return (0);
  383. }
  384. static inline void app_deliver_fn (
  385. unsigned int nodeid,
  386. void *msg,
  387. unsigned int msg_len,
  388. int endian_conversion_required)
  389. {
  390. int i;
  391. struct totempg_group_instance *instance;
  392. struct iovec stripped_iovec;
  393. unsigned int adjust_iovec;
  394. unsigned int res;
  395. struct iovec *iovec;
  396. struct iovec aligned_iovec = { NULL, 0 };
  397. if (endian_conversion_required) {
  398. group_endian_convert (msg, msg_len);
  399. }
  400. /*
  401. * TODO This function needs to be rewritten for proper alignment to avoid 3+ memory copies
  402. */
  403. /*
  404. * Align data structure for sparc and ia64
  405. */
  406. aligned_iovec.iov_base = alloca(msg_len);
  407. aligned_iovec.iov_len = msg_len;
  408. memcpy(aligned_iovec.iov_base, msg, msg_len);
  409. iovec = &aligned_iovec;
  410. for (i = 0; i <= totempg_max_handle; i++) {
  411. res = hdb_handle_get (&totempg_groups_instance_database,
  412. hdb_nocheck_convert (i), (void *)&instance);
  413. if (res == 0) {
  414. if (group_matches (iovec, 1, instance->groups, instance->groups_cnt, &adjust_iovec)) {
  415. stripped_iovec.iov_len = iovec->iov_len - adjust_iovec;
  416. stripped_iovec.iov_base = (char *)iovec->iov_base + adjust_iovec;
  417. /*
  418. * Align data structure for sparc and ia64
  419. */
  420. if ((char *)iovec->iov_base + adjust_iovec % 4 != 0) {
  421. /*
  422. * Deal with misalignment
  423. */
  424. stripped_iovec.iov_base =
  425. alloca (stripped_iovec.iov_len);
  426. memcpy (stripped_iovec.iov_base,
  427. (char *)iovec->iov_base + adjust_iovec,
  428. stripped_iovec.iov_len);
  429. }
  430. instance->deliver_fn (
  431. nodeid,
  432. stripped_iovec.iov_base,
  433. stripped_iovec.iov_len,
  434. endian_conversion_required);
  435. }
  436. hdb_handle_put (&totempg_groups_instance_database, hdb_nocheck_convert(i));
  437. }
  438. }
  439. }
  440. static void totempg_confchg_fn (
  441. enum totem_configuration_type configuration_type,
  442. const unsigned int *member_list, size_t member_list_entries,
  443. const unsigned int *left_list, size_t left_list_entries,
  444. const unsigned int *joined_list, size_t joined_list_entries,
  445. const struct memb_ring_id *ring_id)
  446. {
  447. // TODO optimize this
  448. app_confchg_fn (configuration_type,
  449. member_list, member_list_entries,
  450. left_list, left_list_entries,
  451. joined_list, joined_list_entries,
  452. ring_id);
  453. }
  454. static void totempg_deliver_fn (
  455. unsigned int nodeid,
  456. const void *msg,
  457. unsigned int msg_len,
  458. int endian_conversion_required)
  459. {
  460. struct totempg_mcast *mcast;
  461. unsigned short *msg_lens;
  462. int i;
  463. struct assembly *assembly;
  464. char header[FRAME_SIZE_MAX];
  465. int msg_count;
  466. int continuation;
  467. int start;
  468. const char *data;
  469. int datasize;
  470. assembly = assembly_ref (nodeid);
  471. assert (assembly);
  472. /*
  473. * Assemble the header into one block of data and
  474. * assemble the packet contents into one block of data to simplify delivery
  475. */
  476. mcast = (struct totempg_mcast *)msg;
  477. if (endian_conversion_required) {
  478. mcast->msg_count = swab16 (mcast->msg_count);
  479. }
  480. msg_count = mcast->msg_count;
  481. datasize = sizeof (struct totempg_mcast) +
  482. msg_count * sizeof (unsigned short);
  483. memcpy (header, msg, datasize);
  484. data = msg;
  485. msg_lens = (unsigned short *) (header + sizeof (struct totempg_mcast));
  486. if (endian_conversion_required) {
  487. for (i = 0; i < mcast->msg_count; i++) {
  488. msg_lens[i] = swab16 (msg_lens[i]);
  489. }
  490. }
  491. memcpy (&assembly->data[assembly->index], &data[datasize],
  492. msg_len - datasize);
  493. /*
  494. * If the last message in the buffer is a fragment, then we
  495. * can't deliver it. We'll first deliver the full messages
  496. * then adjust the assembly buffer so we can add the rest of the
  497. * fragment when it arrives.
  498. */
  499. msg_count = mcast->fragmented ? mcast->msg_count - 1 : mcast->msg_count;
  500. continuation = mcast->continuation;
  501. iov_delv.iov_base = (void *)&assembly->data[0];
  502. iov_delv.iov_len = assembly->index + msg_lens[0];
  503. /*
  504. * Make sure that if this message is a continuation, that it
  505. * matches the sequence number of the previous fragment.
  506. * Also, if the first packed message is a continuation
  507. * of a previous message, but the assembly buffer
  508. * is empty, then we need to discard it since we can't
  509. * assemble a complete message. Likewise, if this message isn't a
  510. * continuation and the assembly buffer is empty, we have to discard
  511. * the continued message.
  512. */
  513. start = 0;
  514. if (assembly->throw_away_mode == THROW_AWAY_ACTIVE) {
  515. /* Throw away the first msg block */
  516. if (mcast->fragmented == 0 || mcast->fragmented == 1) {
  517. assembly->throw_away_mode = THROW_AWAY_INACTIVE;
  518. assembly->index += msg_lens[0];
  519. iov_delv.iov_base = (void *)&assembly->data[assembly->index];
  520. iov_delv.iov_len = msg_lens[1];
  521. start = 1;
  522. }
  523. } else
  524. if (assembly->throw_away_mode == THROW_AWAY_INACTIVE) {
  525. if (continuation == assembly->last_frag_num) {
  526. assembly->last_frag_num = mcast->fragmented;
  527. for (i = start; i < msg_count; i++) {
  528. app_deliver_fn(nodeid, iov_delv.iov_base, iov_delv.iov_len,
  529. endian_conversion_required);
  530. assembly->index += msg_lens[i];
  531. iov_delv.iov_base = (void *)&assembly->data[assembly->index];
  532. if (i < (msg_count - 1)) {
  533. iov_delv.iov_len = msg_lens[i + 1];
  534. }
  535. }
  536. } else {
  537. assembly->throw_away_mode = THROW_AWAY_ACTIVE;
  538. }
  539. }
  540. if (mcast->fragmented == 0) {
  541. /*
  542. * End of messages, dereference assembly struct
  543. */
  544. assembly->last_frag_num = 0;
  545. assembly->index = 0;
  546. assembly_deref (assembly);
  547. } else {
  548. /*
  549. * Message is fragmented, keep around assembly list
  550. */
  551. if (mcast->msg_count > 1) {
  552. memmove (&assembly->data[0],
  553. &assembly->data[assembly->index],
  554. msg_lens[msg_count]);
  555. assembly->index = 0;
  556. }
  557. assembly->index += msg_lens[msg_count];
  558. }
  559. }
  560. /*
  561. * Totem Process Group Abstraction
  562. * depends on poll abstraction, POSIX, IPV4
  563. */
  564. void *callback_token_received_handle;
  565. int callback_token_received_fn (enum totem_callback_token_type type,
  566. const void *data)
  567. {
  568. struct totempg_mcast mcast;
  569. struct iovec iovecs[3];
  570. int res;
  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. res = 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_deliver_fn,
  626. totempg_confchg_fn);
  627. totemmrp_callback_token_create (
  628. &callback_token_received_handle,
  629. TOTEM_CALLBACK_TOKEN_RECEIVED,
  630. 0,
  631. callback_token_received_fn,
  632. 0);
  633. totempg_size_limit = (totemmrp_avail() - 1) *
  634. (totempg_totem_config->net_mtu -
  635. sizeof (struct totempg_mcast) - 16);
  636. return (res);
  637. }
  638. void totempg_finalize (void)
  639. {
  640. pthread_mutex_lock (&totempg_mutex);
  641. totemmrp_finalize ();
  642. pthread_mutex_unlock (&totempg_mutex);
  643. }
  644. /*
  645. * Multicast a message
  646. */
  647. static int mcast_msg (
  648. struct iovec *iovec_in,
  649. unsigned int iov_len,
  650. int guarantee)
  651. {
  652. int res = 0;
  653. struct totempg_mcast mcast;
  654. struct iovec iovecs[3];
  655. struct iovec iovec[64];
  656. int i;
  657. int dest, src;
  658. int max_packet_size = 0;
  659. int copy_len = 0;
  660. int copy_base = 0;
  661. int total_size = 0;
  662. pthread_mutex_lock (&mcast_msg_mutex);
  663. totemmrp_new_msg_signal ();
  664. /*
  665. * Remove zero length iovectors from the list
  666. */
  667. assert (iov_len < 64);
  668. for (dest = 0, src = 0; src < iov_len; src++) {
  669. if (iovec_in[src].iov_len) {
  670. memcpy (&iovec[dest++], &iovec_in[src],
  671. sizeof (struct iovec));
  672. }
  673. }
  674. iov_len = dest;
  675. max_packet_size = TOTEMPG_PACKET_SIZE -
  676. (sizeof (unsigned short) * (mcast_packed_msg_count + 1));
  677. mcast_packed_msg_lens[mcast_packed_msg_count] = 0;
  678. /*
  679. * Check if we would overwrite new message queue
  680. */
  681. for (i = 0; i < iov_len; i++) {
  682. total_size += iovec[i].iov_len;
  683. }
  684. if (byte_count_send_ok (total_size + sizeof(unsigned short) *
  685. (mcast_packed_msg_count)) == 0) {
  686. pthread_mutex_unlock (&mcast_msg_mutex);
  687. return(-1);
  688. }
  689. mcast.header.version = 0;
  690. for (i = 0; i < iov_len; ) {
  691. mcast.fragmented = 0;
  692. mcast.continuation = fragment_continuation;
  693. copy_len = iovec[i].iov_len - copy_base;
  694. /*
  695. * If it all fits with room left over, copy it in.
  696. * We need to leave at least sizeof(short) + 1 bytes in the
  697. * fragment_buffer on exit so that max_packet_size + fragment_size
  698. * doesn't exceed the size of the fragment_buffer on the next call.
  699. */
  700. if ((copy_len + fragment_size) <
  701. (max_packet_size - sizeof (unsigned short))) {
  702. memcpy (&fragmentation_data[fragment_size],
  703. (char *)iovec[i].iov_base + copy_base, copy_len);
  704. fragment_size += copy_len;
  705. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  706. next_fragment = 1;
  707. copy_len = 0;
  708. copy_base = 0;
  709. i++;
  710. continue;
  711. /*
  712. * If it just fits or is too big, then send out what fits.
  713. */
  714. } else {
  715. unsigned char *data_ptr;
  716. copy_len = min(copy_len, max_packet_size - fragment_size);
  717. if( copy_len == max_packet_size )
  718. data_ptr = (unsigned char *)iovec[i].iov_base + copy_base;
  719. else {
  720. data_ptr = fragmentation_data;
  721. memcpy (&fragmentation_data[fragment_size],
  722. (unsigned char *)iovec[i].iov_base + copy_base, copy_len);
  723. }
  724. memcpy (&fragmentation_data[fragment_size],
  725. (unsigned char *)iovec[i].iov_base + copy_base, copy_len);
  726. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  727. /*
  728. * if we're not on the last iovec or the iovec is too large to
  729. * fit, then indicate a fragment. This also means that the next
  730. * message will have the continuation of this one.
  731. */
  732. if ((i < (iov_len - 1)) ||
  733. ((copy_base + copy_len) < iovec[i].iov_len)) {
  734. if (!next_fragment) {
  735. next_fragment++;
  736. }
  737. fragment_continuation = next_fragment;
  738. mcast.fragmented = next_fragment++;
  739. assert(fragment_continuation != 0);
  740. assert(mcast.fragmented != 0);
  741. } else {
  742. fragment_continuation = 0;
  743. }
  744. /*
  745. * assemble the message and send it
  746. */
  747. mcast.msg_count = ++mcast_packed_msg_count;
  748. iovecs[0].iov_base = (void *)&mcast;
  749. iovecs[0].iov_len = sizeof(struct totempg_mcast);
  750. iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
  751. iovecs[1].iov_len = mcast_packed_msg_count *
  752. sizeof(unsigned short);
  753. iovecs[2].iov_base = (void *)data_ptr;
  754. iovecs[2].iov_len = max_packet_size;
  755. assert (totemmrp_avail() > 0);
  756. res = totemmrp_mcast (iovecs, 3, guarantee);
  757. if (res == -1) {
  758. goto error_exit;
  759. }
  760. /*
  761. * Recalculate counts and indexes for the next.
  762. */
  763. mcast_packed_msg_lens[0] = 0;
  764. mcast_packed_msg_count = 0;
  765. fragment_size = 0;
  766. max_packet_size = TOTEMPG_PACKET_SIZE - (sizeof(unsigned short));
  767. /*
  768. * If the iovec all fit, go to the next iovec
  769. */
  770. if ((copy_base + copy_len) == iovec[i].iov_len) {
  771. copy_len = 0;
  772. copy_base = 0;
  773. i++;
  774. /*
  775. * Continue with the rest of the current iovec.
  776. */
  777. } else {
  778. copy_base += copy_len;
  779. }
  780. }
  781. }
  782. /*
  783. * Bump only if we added message data. This may be zero if
  784. * the last buffer just fit into the fragmentation_data buffer
  785. * and we were at the last iovec.
  786. */
  787. if (mcast_packed_msg_lens[mcast_packed_msg_count]) {
  788. mcast_packed_msg_count++;
  789. }
  790. error_exit:
  791. pthread_mutex_unlock (&mcast_msg_mutex);
  792. return (res);
  793. }
  794. /*
  795. * Determine if a message of msg_size could be queued
  796. */
  797. static int msg_count_send_ok (
  798. int msg_count)
  799. {
  800. int avail = 0;
  801. avail = totemmrp_avail ();
  802. return (avail > msg_count);
  803. }
  804. static int byte_count_send_ok (
  805. int byte_count)
  806. {
  807. unsigned int msg_count = 0;
  808. int avail = 0;
  809. avail = totemmrp_avail ();
  810. msg_count = (byte_count / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  811. return (avail >= msg_count);
  812. }
  813. static int send_reserve (
  814. int msg_size)
  815. {
  816. unsigned int msg_count = 0;
  817. msg_count = (msg_size / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  818. totempg_reserved += msg_count;
  819. return (msg_count);
  820. }
  821. static void send_release (
  822. int msg_count)
  823. {
  824. totempg_reserved -= msg_count;
  825. }
  826. int totempg_callback_token_create (
  827. void **handle_out,
  828. enum totem_callback_token_type type,
  829. int delete,
  830. int (*callback_fn) (enum totem_callback_token_type type, const void *),
  831. const void *data)
  832. {
  833. unsigned int res;
  834. pthread_mutex_lock (&callback_token_mutex);
  835. res = totemmrp_callback_token_create (handle_out, type, delete,
  836. callback_fn, data);
  837. pthread_mutex_unlock (&callback_token_mutex);
  838. return (res);
  839. }
  840. void totempg_callback_token_destroy (
  841. void *handle_out)
  842. {
  843. pthread_mutex_lock (&callback_token_mutex);
  844. totemmrp_callback_token_destroy (handle_out);
  845. pthread_mutex_unlock (&callback_token_mutex);
  846. }
  847. /*
  848. * vi: set autoindent tabstop=4 shiftwidth=4 :
  849. */
  850. int totempg_groups_initialize (
  851. hdb_handle_t *handle,
  852. void (*deliver_fn) (
  853. unsigned int nodeid,
  854. const void *msg,
  855. unsigned int msg_len,
  856. int endian_conversion_required),
  857. void (*confchg_fn) (
  858. enum totem_configuration_type configuration_type,
  859. const unsigned int *member_list, size_t member_list_entries,
  860. const unsigned int *left_list, size_t left_list_entries,
  861. const unsigned int *joined_list, size_t joined_list_entries,
  862. const struct memb_ring_id *ring_id))
  863. {
  864. struct totempg_group_instance *instance;
  865. unsigned int res;
  866. pthread_mutex_lock (&totempg_mutex);
  867. res = hdb_handle_create (&totempg_groups_instance_database,
  868. sizeof (struct totempg_group_instance), handle);
  869. if (res != 0) {
  870. goto error_exit;
  871. }
  872. if (*handle > totempg_max_handle) {
  873. totempg_max_handle = *handle;
  874. }
  875. res = hdb_handle_get (&totempg_groups_instance_database, *handle,
  876. (void *)&instance);
  877. if (res != 0) {
  878. goto error_destroy;
  879. }
  880. instance->deliver_fn = deliver_fn;
  881. instance->confchg_fn = confchg_fn;
  882. instance->groups = 0;
  883. instance->groups_cnt = 0;
  884. hdb_handle_put (&totempg_groups_instance_database, *handle);
  885. pthread_mutex_unlock (&totempg_mutex);
  886. return (0);
  887. error_destroy:
  888. hdb_handle_destroy (&totempg_groups_instance_database, *handle);
  889. error_exit:
  890. pthread_mutex_unlock (&totempg_mutex);
  891. return (-1);
  892. }
  893. int totempg_groups_join (
  894. hdb_handle_t handle,
  895. const struct totempg_group *groups,
  896. size_t group_cnt)
  897. {
  898. struct totempg_group_instance *instance;
  899. struct totempg_group *new_groups;
  900. unsigned int res;
  901. pthread_mutex_lock (&totempg_mutex);
  902. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  903. (void *)&instance);
  904. if (res != 0) {
  905. goto error_exit;
  906. }
  907. new_groups = realloc (instance->groups,
  908. sizeof (struct totempg_group) *
  909. (instance->groups_cnt + group_cnt));
  910. if (new_groups == 0) {
  911. res = ENOMEM;
  912. goto error_exit;
  913. }
  914. memcpy (&new_groups[instance->groups_cnt],
  915. groups, group_cnt * sizeof (struct totempg_group));
  916. instance->groups = new_groups;
  917. instance->groups_cnt += group_cnt;
  918. hdb_handle_put (&totempg_groups_instance_database, handle);
  919. error_exit:
  920. pthread_mutex_unlock (&totempg_mutex);
  921. return (res);
  922. }
  923. int totempg_groups_leave (
  924. hdb_handle_t handle,
  925. const struct totempg_group *groups,
  926. size_t group_cnt)
  927. {
  928. struct totempg_group_instance *instance;
  929. unsigned int res;
  930. pthread_mutex_lock (&totempg_mutex);
  931. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  932. (void *)&instance);
  933. if (res != 0) {
  934. goto error_exit;
  935. }
  936. hdb_handle_put (&totempg_groups_instance_database, handle);
  937. error_exit:
  938. pthread_mutex_unlock (&totempg_mutex);
  939. return (res);
  940. }
  941. #define MAX_IOVECS_FROM_APP 32
  942. #define MAX_GROUPS_PER_MSG 32
  943. int totempg_groups_mcast_joined (
  944. hdb_handle_t handle,
  945. const struct iovec *iovec,
  946. unsigned int iov_len,
  947. int guarantee)
  948. {
  949. struct totempg_group_instance *instance;
  950. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  951. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  952. int i;
  953. unsigned int res;
  954. pthread_mutex_lock (&totempg_mutex);
  955. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  956. (void *)&instance);
  957. if (res != 0) {
  958. goto error_exit;
  959. }
  960. /*
  961. * Build group_len structure and the iovec_mcast structure
  962. */
  963. group_len[0] = instance->groups_cnt;
  964. for (i = 0; i < instance->groups_cnt; i++) {
  965. group_len[i + 1] = instance->groups[i].group_len;
  966. iovec_mcast[i + 1].iov_len = instance->groups[i].group_len;
  967. iovec_mcast[i + 1].iov_base = (void *) instance->groups[i].group;
  968. }
  969. iovec_mcast[0].iov_len = (instance->groups_cnt + 1) * sizeof (unsigned short);
  970. iovec_mcast[0].iov_base = group_len;
  971. for (i = 0; i < iov_len; i++) {
  972. iovec_mcast[i + instance->groups_cnt + 1].iov_len = iovec[i].iov_len;
  973. iovec_mcast[i + instance->groups_cnt + 1].iov_base = iovec[i].iov_base;
  974. }
  975. res = mcast_msg (iovec_mcast, iov_len + instance->groups_cnt + 1, guarantee);
  976. hdb_handle_put (&totempg_groups_instance_database, handle);
  977. error_exit:
  978. pthread_mutex_unlock (&totempg_mutex);
  979. return (res);
  980. }
  981. int totempg_groups_joined_reserve (
  982. hdb_handle_t handle,
  983. const struct iovec *iovec,
  984. unsigned int iov_len)
  985. {
  986. struct totempg_group_instance *instance;
  987. unsigned int size = 0;
  988. unsigned int i;
  989. unsigned int res;
  990. unsigned int reserved = 0;
  991. pthread_mutex_lock (&totempg_mutex);
  992. pthread_mutex_lock (&mcast_msg_mutex);
  993. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  994. (void *)&instance);
  995. if (res != 0) {
  996. goto error_exit;
  997. }
  998. for (i = 0; i < instance->groups_cnt; i++) {
  999. size += instance->groups[i].group_len;
  1000. }
  1001. for (i = 0; i < iov_len; i++) {
  1002. size += iovec[i].iov_len;
  1003. }
  1004. if (size >= totempg_size_limit) {
  1005. reserved = -1;
  1006. goto error_put;
  1007. }
  1008. reserved = send_reserve (size);
  1009. if (msg_count_send_ok (reserved) == 0) {
  1010. send_release (reserved);
  1011. reserved = 0;
  1012. }
  1013. error_put:
  1014. hdb_handle_put (&totempg_groups_instance_database, handle);
  1015. error_exit:
  1016. pthread_mutex_unlock (&mcast_msg_mutex);
  1017. pthread_mutex_unlock (&totempg_mutex);
  1018. return (reserved);
  1019. }
  1020. int totempg_groups_joined_release (int msg_count)
  1021. {
  1022. pthread_mutex_lock (&totempg_mutex);
  1023. pthread_mutex_lock (&mcast_msg_mutex);
  1024. send_release (msg_count);
  1025. pthread_mutex_unlock (&mcast_msg_mutex);
  1026. pthread_mutex_unlock (&totempg_mutex);
  1027. return 0;
  1028. }
  1029. int totempg_groups_mcast_groups (
  1030. hdb_handle_t handle,
  1031. int guarantee,
  1032. const struct totempg_group *groups,
  1033. size_t groups_cnt,
  1034. const struct iovec *iovec,
  1035. unsigned int iov_len)
  1036. {
  1037. struct totempg_group_instance *instance;
  1038. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  1039. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  1040. int i;
  1041. unsigned int res;
  1042. pthread_mutex_lock (&totempg_mutex);
  1043. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1044. (void *)&instance);
  1045. if (res != 0) {
  1046. goto error_exit;
  1047. }
  1048. /*
  1049. * Build group_len structure and the iovec_mcast structure
  1050. */
  1051. group_len[0] = groups_cnt;
  1052. for (i = 0; i < groups_cnt; i++) {
  1053. group_len[i + 1] = groups[i].group_len;
  1054. iovec_mcast[i + 1].iov_len = groups[i].group_len;
  1055. iovec_mcast[i + 1].iov_base = (void *) groups[i].group;
  1056. }
  1057. iovec_mcast[0].iov_len = (groups_cnt + 1) * sizeof (unsigned short);
  1058. iovec_mcast[0].iov_base = group_len;
  1059. for (i = 0; i < iov_len; i++) {
  1060. iovec_mcast[i + groups_cnt + 1].iov_len = iovec[i].iov_len;
  1061. iovec_mcast[i + groups_cnt + 1].iov_base = iovec[i].iov_base;
  1062. }
  1063. res = mcast_msg (iovec_mcast, iov_len + groups_cnt + 1, guarantee);
  1064. hdb_handle_put (&totempg_groups_instance_database, handle);
  1065. error_exit:
  1066. pthread_mutex_unlock (&totempg_mutex);
  1067. return (res);
  1068. }
  1069. /*
  1070. * Returns -1 if error, 0 if can't send, 1 if can send the message
  1071. */
  1072. int totempg_groups_send_ok_groups (
  1073. hdb_handle_t handle,
  1074. const struct totempg_group *groups,
  1075. size_t groups_cnt,
  1076. const struct iovec *iovec,
  1077. unsigned int iov_len)
  1078. {
  1079. struct totempg_group_instance *instance;
  1080. unsigned int size = 0;
  1081. unsigned int i;
  1082. unsigned int res;
  1083. pthread_mutex_lock (&totempg_mutex);
  1084. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1085. (void *)&instance);
  1086. if (res != 0) {
  1087. goto error_exit;
  1088. }
  1089. for (i = 0; i < groups_cnt; i++) {
  1090. size += groups[i].group_len;
  1091. }
  1092. for (i = 0; i < iov_len; i++) {
  1093. size += iovec[i].iov_len;
  1094. }
  1095. res = msg_count_send_ok (size);
  1096. hdb_handle_put (&totempg_groups_instance_database, handle);
  1097. error_exit:
  1098. pthread_mutex_unlock (&totempg_mutex);
  1099. return (res);
  1100. }
  1101. int totempg_ifaces_get (
  1102. unsigned int nodeid,
  1103. struct totem_ip_address *interfaces,
  1104. char ***status,
  1105. unsigned int *iface_count)
  1106. {
  1107. int res;
  1108. res = totemmrp_ifaces_get (
  1109. nodeid,
  1110. interfaces,
  1111. status,
  1112. iface_count);
  1113. return (res);
  1114. }
  1115. int totempg_crypto_set (
  1116. unsigned int type)
  1117. {
  1118. int res;
  1119. res = totemmrp_crypto_set (
  1120. type);
  1121. return (res);
  1122. }
  1123. int totempg_ring_reenable (void)
  1124. {
  1125. int res;
  1126. res = totemmrp_ring_reenable ();
  1127. return (res);
  1128. }
  1129. const char *totempg_ifaces_print (unsigned int nodeid)
  1130. {
  1131. static char iface_string[256 * INTERFACE_MAX];
  1132. char one_iface[64];
  1133. struct totem_ip_address interfaces[INTERFACE_MAX];
  1134. char **status;
  1135. unsigned int iface_count;
  1136. unsigned int i;
  1137. int res;
  1138. iface_string[0] = '\0';
  1139. res = totempg_ifaces_get (nodeid, interfaces, &status, &iface_count);
  1140. if (res == -1) {
  1141. return ("no interface found for nodeid");
  1142. }
  1143. for (i = 0; i < iface_count; i++) {
  1144. sprintf (one_iface, "r(%d) ip(%s) ",
  1145. i, totemip_print (&interfaces[i]));
  1146. strcat (iface_string, one_iface);
  1147. }
  1148. return (iface_string);
  1149. }
  1150. unsigned int totempg_my_nodeid_get (void)
  1151. {
  1152. return (totemmrp_my_nodeid_get());
  1153. }
  1154. int totempg_my_family_get (void)
  1155. {
  1156. return (totemmrp_my_family_get());
  1157. }
  1158. extern void totempg_service_ready_register (
  1159. void (*totem_service_ready) (void))
  1160. {
  1161. totemmrp_service_ready_register (totem_service_ready);
  1162. }