totempg.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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. int res;
  572. pthread_mutex_lock (&mcast_msg_mutex);
  573. if (mcast_packed_msg_count == 0) {
  574. pthread_mutex_unlock (&mcast_msg_mutex);
  575. return (0);
  576. }
  577. if (totemmrp_avail() == 0) {
  578. pthread_mutex_unlock (&mcast_msg_mutex);
  579. return (0);
  580. }
  581. mcast.header.version = 0;
  582. mcast.fragmented = 0;
  583. /*
  584. * Was the first message in this buffer a continuation of a
  585. * fragmented message?
  586. */
  587. mcast.continuation = fragment_continuation;
  588. fragment_continuation = 0;
  589. mcast.msg_count = mcast_packed_msg_count;
  590. iovecs[0].iov_base = (void *)&mcast;
  591. iovecs[0].iov_len = sizeof (struct totempg_mcast);
  592. iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
  593. iovecs[1].iov_len = mcast_packed_msg_count * sizeof (unsigned short);
  594. iovecs[2].iov_base = (void *)&fragmentation_data[0];
  595. iovecs[2].iov_len = fragment_size;
  596. res = totemmrp_mcast (iovecs, 3, 0);
  597. mcast_packed_msg_count = 0;
  598. fragment_size = 0;
  599. pthread_mutex_unlock (&mcast_msg_mutex);
  600. return (0);
  601. }
  602. /*
  603. * Initialize the totem process group abstraction
  604. */
  605. int totempg_initialize (
  606. hdb_handle_t poll_handle,
  607. struct totem_config *totem_config)
  608. {
  609. int res;
  610. totempg_totem_config = totem_config;
  611. totempg_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  612. totempg_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  613. totempg_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  614. totempg_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  615. totempg_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  616. totempg_log_printf = totem_config->totem_logging_configuration.log_printf;
  617. totempg_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  618. fragmentation_data = malloc (TOTEMPG_PACKET_SIZE);
  619. if (fragmentation_data == 0) {
  620. return (-1);
  621. }
  622. totemsrp_net_mtu_adjust (totem_config);
  623. res = totemmrp_initialize (
  624. poll_handle,
  625. totem_config,
  626. &totempg_stats,
  627. totempg_deliver_fn,
  628. totempg_confchg_fn);
  629. totemmrp_callback_token_create (
  630. &callback_token_received_handle,
  631. TOTEM_CALLBACK_TOKEN_RECEIVED,
  632. 0,
  633. callback_token_received_fn,
  634. 0);
  635. totempg_size_limit = (totemmrp_avail() - 1) *
  636. (totempg_totem_config->net_mtu -
  637. sizeof (struct totempg_mcast) - 16);
  638. return (res);
  639. }
  640. void totempg_finalize (void)
  641. {
  642. pthread_mutex_lock (&totempg_mutex);
  643. totemmrp_finalize ();
  644. pthread_mutex_unlock (&totempg_mutex);
  645. }
  646. /*
  647. * Multicast a message
  648. */
  649. static int mcast_msg (
  650. struct iovec *iovec_in,
  651. unsigned int iov_len,
  652. int guarantee)
  653. {
  654. int res = 0;
  655. struct totempg_mcast mcast;
  656. unsigned int extra_iovec;
  657. struct iovec iovecs[4];
  658. struct iovec iovec[64];
  659. int i;
  660. int dest, src;
  661. int max_packet_size = 0;
  662. int copy_len = 0;
  663. int copy_base = 0;
  664. int total_size = 0;
  665. int iov2_size = 0;
  666. pthread_mutex_lock (&mcast_msg_mutex);
  667. totemmrp_new_msg_signal ();
  668. /*
  669. * Remove zero length iovectors from the list
  670. */
  671. assert (iov_len < 64);
  672. for (dest = 0, src = 0; src < iov_len; src++) {
  673. if (iovec_in[src].iov_len) {
  674. memcpy (&iovec[dest++], &iovec_in[src],
  675. sizeof (struct iovec));
  676. }
  677. }
  678. iov_len = dest;
  679. max_packet_size = TOTEMPG_PACKET_SIZE -
  680. (sizeof (unsigned short) * (mcast_packed_msg_count + 1));
  681. mcast_packed_msg_lens[mcast_packed_msg_count] = 0;
  682. /*
  683. * Check if we would overwrite new message queue
  684. */
  685. for (i = 0; i < iov_len; i++) {
  686. total_size += iovec[i].iov_len;
  687. }
  688. if (byte_count_send_ok (total_size + sizeof(unsigned short) *
  689. (mcast_packed_msg_count)) == 0) {
  690. pthread_mutex_unlock (&mcast_msg_mutex);
  691. return(-1);
  692. }
  693. mcast.header.version = 0;
  694. for (i = 0; i < iov_len; ) {
  695. mcast.fragmented = 0;
  696. mcast.continuation = fragment_continuation;
  697. copy_len = iovec[i].iov_len - copy_base;
  698. /*
  699. * If it all fits with room left over, copy it in.
  700. * We need to leave at least sizeof(short) + 1 bytes in the
  701. * fragment_buffer on exit so that max_packet_size + fragment_size
  702. * doesn't exceed the size of the fragment_buffer on the next call.
  703. */
  704. if ((copy_len + fragment_size) <
  705. (max_packet_size - sizeof (unsigned short))) {
  706. memcpy (&fragmentation_data[fragment_size],
  707. (char *)iovec[i].iov_base + copy_base, copy_len);
  708. fragment_size += copy_len;
  709. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  710. next_fragment = 1;
  711. copy_len = 0;
  712. copy_base = 0;
  713. i++;
  714. continue;
  715. /*
  716. * If it just fits or is too big, then send out what fits.
  717. */
  718. } else {
  719. unsigned char *data_ptr;
  720. copy_len = min(copy_len, max_packet_size - fragment_size);
  721. if (copy_len == max_packet_size) {
  722. data_ptr = (unsigned char *)iovec[i].iov_base + copy_base;
  723. extra_iovec = 0;
  724. iov2_size = max_packet_size;
  725. } else {
  726. extra_iovec = 1;
  727. data_ptr = fragmentation_data;
  728. iovecs[3].iov_base = (((char *)iovec[i].iov_base) + copy_base);
  729. iovecs[3].iov_len = copy_len;
  730. iov2_size = max_packet_size - copy_len;
  731. }
  732. mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
  733. /*
  734. * if we're not on the last iovec or the iovec is too large to
  735. * fit, then indicate a fragment. This also means that the next
  736. * message will have the continuation of this one.
  737. */
  738. if ((i < (iov_len - 1)) ||
  739. ((copy_base + copy_len) < iovec[i].iov_len)) {
  740. if (!next_fragment) {
  741. next_fragment++;
  742. }
  743. fragment_continuation = next_fragment;
  744. mcast.fragmented = next_fragment++;
  745. assert(fragment_continuation != 0);
  746. assert(mcast.fragmented != 0);
  747. } else {
  748. fragment_continuation = 0;
  749. }
  750. /*
  751. * assemble the message and send it
  752. */
  753. mcast.msg_count = ++mcast_packed_msg_count;
  754. iovecs[0].iov_base = (void *)&mcast;
  755. iovecs[0].iov_len = sizeof(struct totempg_mcast);
  756. iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
  757. iovecs[1].iov_len = mcast_packed_msg_count *
  758. sizeof(unsigned short);
  759. iovecs[2].iov_base = (void *)data_ptr;
  760. iovecs[2].iov_len = iov2_size;
  761. assert (totemmrp_avail() > 0);
  762. res = totemmrp_mcast (iovecs, 3 + extra_iovec, guarantee);
  763. if (res == -1) {
  764. goto error_exit;
  765. }
  766. /*
  767. * Recalculate counts and indexes for the next.
  768. */
  769. mcast_packed_msg_lens[0] = 0;
  770. mcast_packed_msg_count = 0;
  771. fragment_size = 0;
  772. max_packet_size = TOTEMPG_PACKET_SIZE - (sizeof(unsigned short));
  773. /*
  774. * If the iovec all fit, go to the next iovec
  775. */
  776. if ((copy_base + copy_len) == iovec[i].iov_len) {
  777. copy_len = 0;
  778. copy_base = 0;
  779. i++;
  780. /*
  781. * Continue with the rest of the current iovec.
  782. */
  783. } else {
  784. copy_base += copy_len;
  785. }
  786. }
  787. }
  788. /*
  789. * Bump only if we added message data. This may be zero if
  790. * the last buffer just fit into the fragmentation_data buffer
  791. * and we were at the last iovec.
  792. */
  793. if (mcast_packed_msg_lens[mcast_packed_msg_count]) {
  794. mcast_packed_msg_count++;
  795. }
  796. error_exit:
  797. pthread_mutex_unlock (&mcast_msg_mutex);
  798. return (res);
  799. }
  800. /*
  801. * Determine if a message of msg_size could be queued
  802. */
  803. static int msg_count_send_ok (
  804. int msg_count)
  805. {
  806. int avail = 0;
  807. avail = totemmrp_avail ();
  808. return ((avail - totempg_reserved) > msg_count);
  809. }
  810. static int byte_count_send_ok (
  811. int byte_count)
  812. {
  813. unsigned int msg_count = 0;
  814. int avail = 0;
  815. avail = totemmrp_avail ();
  816. msg_count = (byte_count / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  817. return (avail >= msg_count);
  818. }
  819. static int send_reserve (
  820. int msg_size)
  821. {
  822. unsigned int msg_count = 0;
  823. msg_count = (msg_size / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
  824. totempg_reserved += msg_count;
  825. return (msg_count);
  826. }
  827. static void send_release (
  828. int msg_count)
  829. {
  830. totempg_reserved -= msg_count;
  831. }
  832. int totempg_callback_token_create (
  833. void **handle_out,
  834. enum totem_callback_token_type type,
  835. int delete,
  836. int (*callback_fn) (enum totem_callback_token_type type, const void *),
  837. const void *data)
  838. {
  839. unsigned int res;
  840. pthread_mutex_lock (&callback_token_mutex);
  841. res = totemmrp_callback_token_create (handle_out, type, delete,
  842. callback_fn, data);
  843. pthread_mutex_unlock (&callback_token_mutex);
  844. return (res);
  845. }
  846. void totempg_callback_token_destroy (
  847. void *handle_out)
  848. {
  849. pthread_mutex_lock (&callback_token_mutex);
  850. totemmrp_callback_token_destroy (handle_out);
  851. pthread_mutex_unlock (&callback_token_mutex);
  852. }
  853. /*
  854. * vi: set autoindent tabstop=4 shiftwidth=4 :
  855. */
  856. int totempg_groups_initialize (
  857. hdb_handle_t *handle,
  858. void (*deliver_fn) (
  859. unsigned int nodeid,
  860. const void *msg,
  861. unsigned int msg_len,
  862. int endian_conversion_required),
  863. void (*confchg_fn) (
  864. enum totem_configuration_type configuration_type,
  865. const unsigned int *member_list, size_t member_list_entries,
  866. const unsigned int *left_list, size_t left_list_entries,
  867. const unsigned int *joined_list, size_t joined_list_entries,
  868. const struct memb_ring_id *ring_id))
  869. {
  870. struct totempg_group_instance *instance;
  871. unsigned int res;
  872. pthread_mutex_lock (&totempg_mutex);
  873. res = hdb_handle_create (&totempg_groups_instance_database,
  874. sizeof (struct totempg_group_instance), handle);
  875. if (res != 0) {
  876. goto error_exit;
  877. }
  878. if (*handle > totempg_max_handle) {
  879. totempg_max_handle = *handle;
  880. }
  881. res = hdb_handle_get (&totempg_groups_instance_database, *handle,
  882. (void *)&instance);
  883. if (res != 0) {
  884. goto error_destroy;
  885. }
  886. instance->deliver_fn = deliver_fn;
  887. instance->confchg_fn = confchg_fn;
  888. instance->groups = 0;
  889. instance->groups_cnt = 0;
  890. hdb_handle_put (&totempg_groups_instance_database, *handle);
  891. pthread_mutex_unlock (&totempg_mutex);
  892. return (0);
  893. error_destroy:
  894. hdb_handle_destroy (&totempg_groups_instance_database, *handle);
  895. error_exit:
  896. pthread_mutex_unlock (&totempg_mutex);
  897. return (-1);
  898. }
  899. int totempg_groups_join (
  900. hdb_handle_t handle,
  901. const struct totempg_group *groups,
  902. size_t group_cnt)
  903. {
  904. struct totempg_group_instance *instance;
  905. struct totempg_group *new_groups;
  906. unsigned int res;
  907. pthread_mutex_lock (&totempg_mutex);
  908. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  909. (void *)&instance);
  910. if (res != 0) {
  911. goto error_exit;
  912. }
  913. new_groups = realloc (instance->groups,
  914. sizeof (struct totempg_group) *
  915. (instance->groups_cnt + group_cnt));
  916. if (new_groups == 0) {
  917. res = ENOMEM;
  918. goto error_exit;
  919. }
  920. memcpy (&new_groups[instance->groups_cnt],
  921. groups, group_cnt * sizeof (struct totempg_group));
  922. instance->groups = new_groups;
  923. instance->groups_cnt += group_cnt;
  924. hdb_handle_put (&totempg_groups_instance_database, handle);
  925. error_exit:
  926. pthread_mutex_unlock (&totempg_mutex);
  927. return (res);
  928. }
  929. int totempg_groups_leave (
  930. hdb_handle_t handle,
  931. const struct totempg_group *groups,
  932. size_t group_cnt)
  933. {
  934. struct totempg_group_instance *instance;
  935. unsigned int res;
  936. pthread_mutex_lock (&totempg_mutex);
  937. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  938. (void *)&instance);
  939. if (res != 0) {
  940. goto error_exit;
  941. }
  942. hdb_handle_put (&totempg_groups_instance_database, handle);
  943. error_exit:
  944. pthread_mutex_unlock (&totempg_mutex);
  945. return (res);
  946. }
  947. #define MAX_IOVECS_FROM_APP 32
  948. #define MAX_GROUPS_PER_MSG 32
  949. int totempg_groups_mcast_joined (
  950. hdb_handle_t handle,
  951. const struct iovec *iovec,
  952. unsigned int iov_len,
  953. int guarantee)
  954. {
  955. struct totempg_group_instance *instance;
  956. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  957. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  958. int i;
  959. unsigned int res;
  960. pthread_mutex_lock (&totempg_mutex);
  961. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  962. (void *)&instance);
  963. if (res != 0) {
  964. goto error_exit;
  965. }
  966. /*
  967. * Build group_len structure and the iovec_mcast structure
  968. */
  969. group_len[0] = instance->groups_cnt;
  970. for (i = 0; i < instance->groups_cnt; i++) {
  971. group_len[i + 1] = instance->groups[i].group_len;
  972. iovec_mcast[i + 1].iov_len = instance->groups[i].group_len;
  973. iovec_mcast[i + 1].iov_base = (void *) instance->groups[i].group;
  974. }
  975. iovec_mcast[0].iov_len = (instance->groups_cnt + 1) * sizeof (unsigned short);
  976. iovec_mcast[0].iov_base = group_len;
  977. for (i = 0; i < iov_len; i++) {
  978. iovec_mcast[i + instance->groups_cnt + 1].iov_len = iovec[i].iov_len;
  979. iovec_mcast[i + instance->groups_cnt + 1].iov_base = iovec[i].iov_base;
  980. }
  981. res = mcast_msg (iovec_mcast, iov_len + instance->groups_cnt + 1, guarantee);
  982. hdb_handle_put (&totempg_groups_instance_database, handle);
  983. error_exit:
  984. pthread_mutex_unlock (&totempg_mutex);
  985. return (res);
  986. }
  987. int totempg_groups_joined_reserve (
  988. hdb_handle_t handle,
  989. const struct iovec *iovec,
  990. unsigned int iov_len)
  991. {
  992. struct totempg_group_instance *instance;
  993. unsigned int size = 0;
  994. unsigned int i;
  995. unsigned int res;
  996. unsigned int reserved = 0;
  997. pthread_mutex_lock (&totempg_mutex);
  998. pthread_mutex_lock (&mcast_msg_mutex);
  999. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1000. (void *)&instance);
  1001. if (res != 0) {
  1002. goto error_exit;
  1003. }
  1004. for (i = 0; i < instance->groups_cnt; i++) {
  1005. size += instance->groups[i].group_len;
  1006. }
  1007. for (i = 0; i < iov_len; i++) {
  1008. size += iovec[i].iov_len;
  1009. }
  1010. if (size >= totempg_size_limit) {
  1011. reserved = -1;
  1012. goto error_put;
  1013. }
  1014. reserved = send_reserve (size);
  1015. if (msg_count_send_ok (reserved) == 0) {
  1016. send_release (reserved);
  1017. reserved = 0;
  1018. }
  1019. error_put:
  1020. hdb_handle_put (&totempg_groups_instance_database, handle);
  1021. error_exit:
  1022. pthread_mutex_unlock (&mcast_msg_mutex);
  1023. pthread_mutex_unlock (&totempg_mutex);
  1024. return (reserved);
  1025. }
  1026. int totempg_groups_joined_release (int msg_count)
  1027. {
  1028. pthread_mutex_lock (&totempg_mutex);
  1029. pthread_mutex_lock (&mcast_msg_mutex);
  1030. send_release (msg_count);
  1031. pthread_mutex_unlock (&mcast_msg_mutex);
  1032. pthread_mutex_unlock (&totempg_mutex);
  1033. return 0;
  1034. }
  1035. int totempg_groups_mcast_groups (
  1036. hdb_handle_t handle,
  1037. int guarantee,
  1038. const struct totempg_group *groups,
  1039. size_t groups_cnt,
  1040. const struct iovec *iovec,
  1041. unsigned int iov_len)
  1042. {
  1043. struct totempg_group_instance *instance;
  1044. unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
  1045. struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
  1046. int i;
  1047. unsigned int res;
  1048. pthread_mutex_lock (&totempg_mutex);
  1049. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1050. (void *)&instance);
  1051. if (res != 0) {
  1052. goto error_exit;
  1053. }
  1054. /*
  1055. * Build group_len structure and the iovec_mcast structure
  1056. */
  1057. group_len[0] = groups_cnt;
  1058. for (i = 0; i < groups_cnt; i++) {
  1059. group_len[i + 1] = groups[i].group_len;
  1060. iovec_mcast[i + 1].iov_len = groups[i].group_len;
  1061. iovec_mcast[i + 1].iov_base = (void *) groups[i].group;
  1062. }
  1063. iovec_mcast[0].iov_len = (groups_cnt + 1) * sizeof (unsigned short);
  1064. iovec_mcast[0].iov_base = group_len;
  1065. for (i = 0; i < iov_len; i++) {
  1066. iovec_mcast[i + groups_cnt + 1].iov_len = iovec[i].iov_len;
  1067. iovec_mcast[i + groups_cnt + 1].iov_base = iovec[i].iov_base;
  1068. }
  1069. res = mcast_msg (iovec_mcast, iov_len + groups_cnt + 1, guarantee);
  1070. hdb_handle_put (&totempg_groups_instance_database, handle);
  1071. error_exit:
  1072. pthread_mutex_unlock (&totempg_mutex);
  1073. return (res);
  1074. }
  1075. /*
  1076. * Returns -1 if error, 0 if can't send, 1 if can send the message
  1077. */
  1078. int totempg_groups_send_ok_groups (
  1079. hdb_handle_t handle,
  1080. const struct totempg_group *groups,
  1081. size_t groups_cnt,
  1082. const struct iovec *iovec,
  1083. unsigned int iov_len)
  1084. {
  1085. struct totempg_group_instance *instance;
  1086. unsigned int size = 0;
  1087. unsigned int i;
  1088. unsigned int res;
  1089. pthread_mutex_lock (&totempg_mutex);
  1090. res = hdb_handle_get (&totempg_groups_instance_database, handle,
  1091. (void *)&instance);
  1092. if (res != 0) {
  1093. goto error_exit;
  1094. }
  1095. for (i = 0; i < groups_cnt; i++) {
  1096. size += groups[i].group_len;
  1097. }
  1098. for (i = 0; i < iov_len; i++) {
  1099. size += iovec[i].iov_len;
  1100. }
  1101. res = msg_count_send_ok (size);
  1102. hdb_handle_put (&totempg_groups_instance_database, handle);
  1103. error_exit:
  1104. pthread_mutex_unlock (&totempg_mutex);
  1105. return (res);
  1106. }
  1107. int totempg_ifaces_get (
  1108. unsigned int nodeid,
  1109. struct totem_ip_address *interfaces,
  1110. char ***status,
  1111. unsigned int *iface_count)
  1112. {
  1113. int res;
  1114. res = totemmrp_ifaces_get (
  1115. nodeid,
  1116. interfaces,
  1117. status,
  1118. iface_count);
  1119. return (res);
  1120. }
  1121. void* totempg_get_stats (void)
  1122. {
  1123. return &totempg_stats;
  1124. }
  1125. int totempg_crypto_set (
  1126. unsigned int type)
  1127. {
  1128. int res;
  1129. res = totemmrp_crypto_set (
  1130. type);
  1131. return (res);
  1132. }
  1133. int totempg_ring_reenable (void)
  1134. {
  1135. int res;
  1136. res = totemmrp_ring_reenable ();
  1137. return (res);
  1138. }
  1139. const char *totempg_ifaces_print (unsigned int nodeid)
  1140. {
  1141. static char iface_string[256 * INTERFACE_MAX];
  1142. char one_iface[64];
  1143. struct totem_ip_address interfaces[INTERFACE_MAX];
  1144. char **status;
  1145. unsigned int iface_count;
  1146. unsigned int i;
  1147. int res;
  1148. iface_string[0] = '\0';
  1149. res = totempg_ifaces_get (nodeid, interfaces, &status, &iface_count);
  1150. if (res == -1) {
  1151. return ("no interface found for nodeid");
  1152. }
  1153. for (i = 0; i < iface_count; i++) {
  1154. sprintf (one_iface, "r(%d) ip(%s) ",
  1155. i, totemip_print (&interfaces[i]));
  1156. strcat (iface_string, one_iface);
  1157. }
  1158. return (iface_string);
  1159. }
  1160. unsigned int totempg_my_nodeid_get (void)
  1161. {
  1162. return (totemmrp_my_nodeid_get());
  1163. }
  1164. int totempg_my_family_get (void)
  1165. {
  1166. return (totemmrp_my_family_get());
  1167. }
  1168. extern void totempg_service_ready_register (
  1169. void (*totem_service_ready) (void))
  1170. {
  1171. totemmrp_service_ready_register (totem_service_ready);
  1172. }