4
0

totempg.c 36 KB

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