totempg.c 36 KB

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