corosync  3.0.2
totempg.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 MontaVista Software, Inc.
3  * Copyright (c) 2005 OSDL.
4  * Copyright (c) 2006-2012 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 /*
39  * FRAGMENTATION AND PACKING ALGORITHM:
40  *
41  * Assemble the entire message into one buffer
42  * if full fragment
43  * store fragment into lengths list
44  * for each full fragment
45  * multicast fragment
46  * set length and fragment fields of pg mesage
47  * store remaining multicast into head of fragmentation data and set lens field
48  *
49  * If a message exceeds the maximum packet size allowed by the totem
50  * single ring protocol, the protocol could lose forward progress.
51  * Statically calculating the allowed data amount doesn't work because
52  * the amount of data allowed depends on the number of fragments in
53  * each message. In this implementation, the maximum fragment size
54  * is dynamically calculated for each fragment added to the message.
55 
56  * It is possible for a message to be two bytes short of the maximum
57  * packet size. This occurs when a message or collection of
58  * messages + the mcast header + the lens are two bytes short of the
59  * end of the packet. Since another len field consumes two bytes, the
60  * len field would consume the rest of the packet without room for data.
61  *
62  * One optimization would be to forgo the final len field and determine
63  * it from the size of the udp datagram. Then this condition would no
64  * longer occur.
65  */
66 
67 /*
68  * ASSEMBLY AND UNPACKING ALGORITHM:
69  *
70  * copy incoming packet into assembly data buffer indexed by current
71  * location of end of fragment
72  *
73  * if not fragmented
74  * deliver all messages in assembly data buffer
75  * else
76  * if msg_count > 1 and fragmented
77  * deliver all messages except last message in assembly data buffer
78  * copy last fragmented section to start of assembly data buffer
79  * else
80  * if msg_count = 1 and fragmented
81  * do nothing
82  *
83  */
84 
85 #include <config.h>
86 
87 #ifdef HAVE_ALLOCA_H
88 #include <alloca.h>
89 #endif
90 #include <sys/types.h>
91 #include <sys/socket.h>
92 #include <netinet/in.h>
93 #include <arpa/inet.h>
94 #include <sys/uio.h>
95 #include <stdio.h>
96 #include <stdlib.h>
97 #include <string.h>
98 #include <assert.h>
99 #include <pthread.h>
100 #include <errno.h>
101 #include <limits.h>
102 
103 #include <corosync/swab.h>
104 #include <qb/qblist.h>
105 #include <qb/qbloop.h>
106 #include <qb/qbipcs.h>
107 #include <corosync/totem/totempg.h>
108 #define LOGSYS_UTILS_ONLY 1
109 #include <corosync/logsys.h>
110 
111 #include "util.h"
112 #include "totemsrp.h"
113 
115  short version;
116  short type;
117 };
118 
119 #if !(defined(__i386__) || defined(__x86_64__))
120 /*
121  * Need align on architectures different then i386 or x86_64
122  */
123 #define TOTEMPG_NEED_ALIGN 1
124 #endif
125 
126 /*
127  * totempg_mcast structure
128  *
129  * header: Identify the mcast.
130  * fragmented: Set if this message continues into next message
131  * continuation: Set if this message is a continuation from last message
132  * msg_count Indicates how many packed messages are contained
133  * in the mcast.
134  * Also, the size of each packed message and the messages themselves are
135  * appended to the end of this structure when sent.
136  */
139  unsigned char fragmented;
140  unsigned char continuation;
141  unsigned short msg_count;
142  /*
143  * short msg_len[msg_count];
144  */
145  /*
146  * data for messages
147  */
148 };
149 
150 /*
151  * Maximum packet size for totem pg messages
152  */
153 #define TOTEMPG_PACKET_SIZE (totempg_totem_config->net_mtu - \
154  sizeof (struct totempg_mcast))
155 
156 /*
157  * Local variables used for packing small messages
158  */
159 static unsigned short mcast_packed_msg_lens[FRAME_SIZE_MAX];
160 
161 static int mcast_packed_msg_count = 0;
162 
163 static int totempg_reserved = 1;
164 
165 static unsigned int totempg_size_limit;
166 
167 static totem_queue_level_changed_fn totem_queue_level_changed = NULL;
168 
169 static uint32_t totempg_threaded_mode = 0;
170 
171 static void *totemsrp_context;
172 
173 /*
174  * Function and data used to log messages
175  */
176 static int totempg_log_level_security;
177 static int totempg_log_level_error;
178 static int totempg_log_level_warning;
179 static int totempg_log_level_notice;
180 static int totempg_log_level_debug;
181 static int totempg_subsys_id;
182 static void (*totempg_log_printf) (
183  int level,
184  int subsys,
185  const char *function,
186  const char *file,
187  int line,
188  const char *format, ...) __attribute__((format(printf, 6, 7)));
189 
191 
192 static totempg_stats_t totempg_stats;
193 
197 };
198 
199 struct assembly {
200  unsigned int nodeid;
201  unsigned char data[MESSAGE_SIZE_MAX+KNET_MAX_PACKET_SIZE];
202  int index;
203  unsigned char last_frag_num;
205  struct qb_list_head list;
206 };
207 
208 static void assembly_deref (struct assembly *assembly);
209 
210 static int callback_token_received_fn (enum totem_callback_token_type type,
211  const void *data);
212 
213 QB_LIST_DECLARE(assembly_list_inuse);
214 
215 /*
216  * Free list is used both for transitional and operational assemblies
217  */
218 QB_LIST_DECLARE(assembly_list_free);
219 
220 QB_LIST_DECLARE(assembly_list_inuse_trans);
221 
222 QB_LIST_DECLARE(totempg_groups_list);
223 
224 /*
225  * Staging buffer for packed messages. Messages are staged in this buffer
226  * before sending. Multiple messages may fit which cuts down on the
227  * number of mcasts sent. If a message doesn't completely fit, then
228  * the mcast header has a fragment bit set that says that there are more
229  * data to follow. fragment_size is an index into the buffer. It indicates
230  * the size of message data and where to place new message data.
231  * fragment_contuation indicates whether the first packed message in
232  * the buffer is a continuation of a previously packed fragment.
233  */
234 static unsigned char *fragmentation_data;
235 
236 static int fragment_size = 0;
237 
238 static int fragment_continuation = 0;
239 
240 static int totempg_waiting_transack = 0;
241 
243  void (*deliver_fn) (
244  unsigned int nodeid,
245  const void *msg,
246  unsigned int msg_len,
247  int endian_conversion_required);
248 
249  void (*confchg_fn) (
250  enum totem_configuration_type configuration_type,
251  const unsigned int *member_list, size_t member_list_entries,
252  const unsigned int *left_list, size_t left_list_entries,
253  const unsigned int *joined_list, size_t joined_list_entries,
254  const struct memb_ring_id *ring_id);
255 
257 
259  int32_t q_level;
260 
261  struct qb_list_head list;
262 };
263 
264 static unsigned char next_fragment = 1;
265 
266 static pthread_mutex_t totempg_mutex = PTHREAD_MUTEX_INITIALIZER;
267 
268 static pthread_mutex_t callback_token_mutex = PTHREAD_MUTEX_INITIALIZER;
269 
270 static pthread_mutex_t mcast_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
271 
272 #define log_printf(level, format, args...) \
273 do { \
274  totempg_log_printf(level, \
275  totempg_subsys_id, \
276  __FUNCTION__, __FILE__, __LINE__, \
277  format, ##args); \
278 } while (0);
279 
280 static int msg_count_send_ok (int msg_count);
281 
282 static int byte_count_send_ok (int byte_count);
283 
284 static void totempg_waiting_trans_ack_cb (int waiting_trans_ack)
285 {
286  log_printf(LOG_DEBUG, "waiting_trans_ack changed to %u", waiting_trans_ack);
287  totempg_waiting_transack = waiting_trans_ack;
288 }
289 
290 static struct assembly *assembly_ref (unsigned int nodeid)
291 {
292  struct assembly *assembly;
293  struct qb_list_head *list;
294  struct qb_list_head *active_assembly_list_inuse;
295 
296  if (totempg_waiting_transack) {
297  active_assembly_list_inuse = &assembly_list_inuse_trans;
298  } else {
299  active_assembly_list_inuse = &assembly_list_inuse;
300  }
301 
302  /*
303  * Search inuse list for node id and return assembly buffer if found
304  */
305  qb_list_for_each(list, active_assembly_list_inuse) {
306  assembly = qb_list_entry (list, struct assembly, list);
307 
308  if (nodeid == assembly->nodeid) {
309  return (assembly);
310  }
311  }
312 
313  /*
314  * Nothing found in inuse list get one from free list if available
315  */
316  if (qb_list_empty (&assembly_list_free) == 0) {
317  assembly = qb_list_first_entry (&assembly_list_free, struct assembly, list);
318  qb_list_del (&assembly->list);
319  qb_list_add (&assembly->list, active_assembly_list_inuse);
321  assembly->index = 0;
322  assembly->last_frag_num = 0;
324  return (assembly);
325  }
326 
327  /*
328  * Nothing available in inuse or free list, so allocate a new one
329  */
330  assembly = malloc (sizeof (struct assembly));
331  /*
332  * TODO handle memory allocation failure here
333  */
334  assert (assembly);
336  assembly->data[0] = 0;
337  assembly->index = 0;
338  assembly->last_frag_num = 0;
340  qb_list_init (&assembly->list);
341  qb_list_add (&assembly->list, active_assembly_list_inuse);
342 
343  return (assembly);
344 }
345 
346 static void assembly_deref (struct assembly *assembly)
347 {
348  qb_list_del (&assembly->list);
349  qb_list_add (&assembly->list, &assembly_list_free);
350 }
351 
352 static void assembly_deref_from_normal_and_trans (int nodeid)
353 {
354  int j;
355  struct qb_list_head *list, *tmp_iter;
356  struct qb_list_head *active_assembly_list_inuse;
357  struct assembly *assembly;
358 
359  for (j = 0; j < 2; j++) {
360  if (j == 0) {
361  active_assembly_list_inuse = &assembly_list_inuse;
362  } else {
363  active_assembly_list_inuse = &assembly_list_inuse_trans;
364  }
365 
366  qb_list_for_each_safe(list, tmp_iter, active_assembly_list_inuse) {
367  assembly = qb_list_entry (list, struct assembly, list);
368 
369  if (nodeid == assembly->nodeid) {
370  qb_list_del (&assembly->list);
371  qb_list_add (&assembly->list, &assembly_list_free);
372  }
373  }
374  }
375 
376 }
377 
378 static inline void app_confchg_fn (
379  enum totem_configuration_type configuration_type,
380  const unsigned int *member_list, size_t member_list_entries,
381  const unsigned int *left_list, size_t left_list_entries,
382  const unsigned int *joined_list, size_t joined_list_entries,
383  const struct memb_ring_id *ring_id)
384 {
385  int i;
386  struct totempg_group_instance *instance;
387  struct qb_list_head *list;
388 
389  /*
390  * For every leaving processor, add to free list
391  * This also has the side effect of clearing out the dataset
392  * In the leaving processor's assembly buffer.
393  */
394  for (i = 0; i < left_list_entries; i++) {
395  assembly_deref_from_normal_and_trans (left_list[i]);
396  }
397 
398  qb_list_for_each(list, &totempg_groups_list) {
399  instance = qb_list_entry (list, struct totempg_group_instance, list);
400 
401  if (instance->confchg_fn) {
402  instance->confchg_fn (
403  configuration_type,
404  member_list,
405  member_list_entries,
406  left_list,
407  left_list_entries,
408  joined_list,
409  joined_list_entries,
410  ring_id);
411  }
412  }
413 }
414 
415 static inline void group_endian_convert (
416  void *msg,
417  int msg_len)
418 {
419  unsigned short *group_len;
420  int i;
421  char *aligned_msg;
422 
423 #ifdef TOTEMPG_NEED_ALIGN
424  /*
425  * Align data structure for not i386 or x86_64
426  */
427  if ((size_t)msg % 4 != 0) {
428  aligned_msg = alloca(msg_len);
429  memcpy(aligned_msg, msg, msg_len);
430  } else {
431  aligned_msg = msg;
432  }
433 #else
434  aligned_msg = msg;
435 #endif
436 
437  group_len = (unsigned short *)aligned_msg;
438  group_len[0] = swab16(group_len[0]);
439  for (i = 1; i < group_len[0] + 1; i++) {
440  group_len[i] = swab16(group_len[i]);
441  }
442 
443  if (aligned_msg != msg) {
444  memcpy(msg, aligned_msg, msg_len);
445  }
446 }
447 
448 static inline int group_matches (
449  struct iovec *iovec,
450  unsigned int iov_len,
451  struct totempg_group *groups_b,
452  unsigned int group_b_cnt,
453  unsigned int *adjust_iovec)
454 {
455  unsigned short *group_len;
456  char *group_name;
457  int i;
458  int j;
459 #ifdef TOTEMPG_NEED_ALIGN
460  struct iovec iovec_aligned = { NULL, 0 };
461 #endif
462 
463  assert (iov_len == 1);
464 
465 #ifdef TOTEMPG_NEED_ALIGN
466  /*
467  * Align data structure for not i386 or x86_64
468  */
469  if ((size_t)iovec->iov_base % 4 != 0) {
470  iovec_aligned.iov_base = alloca(iovec->iov_len);
471  memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len);
472  iovec_aligned.iov_len = iovec->iov_len;
473  iovec = &iovec_aligned;
474  }
475 #endif
476 
477  group_len = (unsigned short *)iovec->iov_base;
478  group_name = ((char *)iovec->iov_base) +
479  sizeof (unsigned short) * (group_len[0] + 1);
480 
481 
482  /*
483  * Calculate amount to adjust the iovec by before delivering to app
484  */
485  *adjust_iovec = sizeof (unsigned short) * (group_len[0] + 1);
486  for (i = 1; i < group_len[0] + 1; i++) {
487  *adjust_iovec += group_len[i];
488  }
489 
490  /*
491  * Determine if this message should be delivered to this instance
492  */
493  for (i = 1; i < group_len[0] + 1; i++) {
494  for (j = 0; j < group_b_cnt; j++) {
495  if ((group_len[i] == groups_b[j].group_len) &&
496  (memcmp (groups_b[j].group, group_name, group_len[i]) == 0)) {
497  return (1);
498  }
499  }
500  group_name += group_len[i];
501  }
502  return (0);
503 }
504 
505 
506 static inline void app_deliver_fn (
507  unsigned int nodeid,
508  void *msg,
509  unsigned int msg_len,
510  int endian_conversion_required)
511 {
512  struct totempg_group_instance *instance;
513  struct iovec stripped_iovec;
514  unsigned int adjust_iovec;
515  struct iovec *iovec;
516  struct qb_list_head *list;
517 
518  struct iovec aligned_iovec = { NULL, 0 };
519 
520  if (endian_conversion_required) {
521  group_endian_convert (msg, msg_len);
522  }
523 
524  /*
525  * TODO: segmentation/assembly need to be redesigned to provide aligned access
526  * in all cases to avoid memory copies on non386 archs. Probably broke backwars
527  * compatibility
528  */
529 
530 #ifdef TOTEMPG_NEED_ALIGN
531  /*
532  * Align data structure for not i386 or x86_64
533  */
534  aligned_iovec.iov_base = alloca(msg_len);
535  aligned_iovec.iov_len = msg_len;
536  memcpy(aligned_iovec.iov_base, msg, msg_len);
537 #else
538  aligned_iovec.iov_base = msg;
539  aligned_iovec.iov_len = msg_len;
540 #endif
541 
542  iovec = &aligned_iovec;
543 
544  qb_list_for_each(list, &totempg_groups_list) {
545  instance = qb_list_entry (list, struct totempg_group_instance, list);
546  if (group_matches (iovec, 1, instance->groups, instance->groups_cnt, &adjust_iovec)) {
547  stripped_iovec.iov_len = iovec->iov_len - adjust_iovec;
548  stripped_iovec.iov_base = (char *)iovec->iov_base + adjust_iovec;
549 
550 #ifdef TOTEMPG_NEED_ALIGN
551  /*
552  * Align data structure for not i386 or x86_64
553  */
554  if ((char *)iovec->iov_base + adjust_iovec % 4 != 0) {
555  /*
556  * Deal with misalignment
557  */
558  stripped_iovec.iov_base =
559  alloca (stripped_iovec.iov_len);
560  memcpy (stripped_iovec.iov_base,
561  (char *)iovec->iov_base + adjust_iovec,
562  stripped_iovec.iov_len);
563  }
564 #endif
565  instance->deliver_fn (
566  nodeid,
567  stripped_iovec.iov_base,
568  stripped_iovec.iov_len,
569  endian_conversion_required);
570  }
571  }
572 }
573 
574 static void totempg_confchg_fn (
575  enum totem_configuration_type configuration_type,
576  const unsigned int *member_list, size_t member_list_entries,
577  const unsigned int *left_list, size_t left_list_entries,
578  const unsigned int *joined_list, size_t joined_list_entries,
579  const struct memb_ring_id *ring_id)
580 {
581 // TODO optimize this
582  app_confchg_fn (configuration_type,
583  member_list, member_list_entries,
584  left_list, left_list_entries,
585  joined_list, joined_list_entries,
586  ring_id);
587 }
588 
589 static void totempg_deliver_fn (
590  unsigned int nodeid,
591  const void *msg,
592  unsigned int msg_len,
593  int endian_conversion_required)
594 {
595  struct totempg_mcast *mcast;
596  unsigned short *msg_lens;
597  int i;
598  struct assembly *assembly;
599  char header[FRAME_SIZE_MAX];
600  int msg_count;
601  int continuation;
602  int start;
603  const char *data;
604  int datasize;
605  struct iovec iov_delv;
606 
607  assembly = assembly_ref (nodeid);
608  assert (assembly);
609 
610  /*
611  * Assemble the header into one block of data and
612  * assemble the packet contents into one block of data to simplify delivery
613  */
614 
615  mcast = (struct totempg_mcast *)msg;
616  if (endian_conversion_required) {
617  mcast->msg_count = swab16 (mcast->msg_count);
618  }
619 
620  msg_count = mcast->msg_count;
621  datasize = sizeof (struct totempg_mcast) +
622  msg_count * sizeof (unsigned short);
623 
624  memcpy (header, msg, datasize);
625  data = msg;
626 
627  msg_lens = (unsigned short *) (header + sizeof (struct totempg_mcast));
628  if (endian_conversion_required) {
629  for (i = 0; i < mcast->msg_count; i++) {
630  msg_lens[i] = swab16 (msg_lens[i]);
631  }
632  }
633 
634  assert((assembly->index+msg_len) < sizeof(assembly->data));
635  memcpy (&assembly->data[assembly->index], &data[datasize],
636  msg_len - datasize);
637 
638  /*
639  * If the last message in the buffer is a fragment, then we
640  * can't deliver it. We'll first deliver the full messages
641  * then adjust the assembly buffer so we can add the rest of the
642  * fragment when it arrives.
643  */
644  msg_count = mcast->fragmented ? mcast->msg_count - 1 : mcast->msg_count;
645  continuation = mcast->continuation;
646  iov_delv.iov_base = (void *)&assembly->data[0];
647  iov_delv.iov_len = assembly->index + msg_lens[0];
648 
649  /*
650  * Make sure that if this message is a continuation, that it
651  * matches the sequence number of the previous fragment.
652  * Also, if the first packed message is a continuation
653  * of a previous message, but the assembly buffer
654  * is empty, then we need to discard it since we can't
655  * assemble a complete message. Likewise, if this message isn't a
656  * continuation and the assembly buffer is empty, we have to discard
657  * the continued message.
658  */
659  start = 0;
660 
662  /* Throw away the first msg block */
663  if (mcast->fragmented == 0 || mcast->fragmented == 1) {
665 
666  assembly->index += msg_lens[0];
667  iov_delv.iov_base = (void *)&assembly->data[assembly->index];
668  iov_delv.iov_len = msg_lens[1];
669  start = 1;
670  }
671  } else
674  assembly->last_frag_num = mcast->fragmented;
675  for (i = start; i < msg_count; i++) {
676  app_deliver_fn(nodeid, iov_delv.iov_base, iov_delv.iov_len,
677  endian_conversion_required);
678  assembly->index += msg_lens[i];
679  iov_delv.iov_base = (void *)&assembly->data[assembly->index];
680  if (i < (msg_count - 1)) {
681  iov_delv.iov_len = msg_lens[i + 1];
682  }
683  }
684  } else {
685  log_printf (LOG_DEBUG, "fragmented continuation %u is not equal to assembly last_frag_num %u",
688  }
689  }
690 
691  if (mcast->fragmented == 0) {
692  /*
693  * End of messages, dereference assembly struct
694  */
695  assembly->last_frag_num = 0;
696  assembly->index = 0;
697  assembly_deref (assembly);
698  } else {
699  /*
700  * Message is fragmented, keep around assembly list
701  */
702  if (mcast->msg_count > 1) {
703  memmove (&assembly->data[0],
705  msg_lens[msg_count]);
706 
707  assembly->index = 0;
708  }
709  assembly->index += msg_lens[msg_count];
710  }
711 }
712 
713 /*
714  * Totem Process Group Abstraction
715  * depends on poll abstraction, POSIX, IPV4
716  */
717 
719 
720 int callback_token_received_fn (enum totem_callback_token_type type,
721  const void *data)
722 {
723  struct totempg_mcast mcast;
724  struct iovec iovecs[3];
725 
726  if (totempg_threaded_mode == 1) {
727  pthread_mutex_lock (&mcast_msg_mutex);
728  }
729  if (mcast_packed_msg_count == 0) {
730  if (totempg_threaded_mode == 1) {
731  pthread_mutex_unlock (&mcast_msg_mutex);
732  }
733  return (0);
734  }
735  if (totemsrp_avail(totemsrp_context) == 0) {
736  if (totempg_threaded_mode == 1) {
737  pthread_mutex_unlock (&mcast_msg_mutex);
738  }
739  return (0);
740  }
741  mcast.header.version = 0;
742  mcast.header.type = 0;
743  mcast.fragmented = 0;
744 
745  /*
746  * Was the first message in this buffer a continuation of a
747  * fragmented message?
748  */
749  mcast.continuation = fragment_continuation;
750  fragment_continuation = 0;
751 
752  mcast.msg_count = mcast_packed_msg_count;
753 
754  iovecs[0].iov_base = (void *)&mcast;
755  iovecs[0].iov_len = sizeof (struct totempg_mcast);
756  iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
757  iovecs[1].iov_len = mcast_packed_msg_count * sizeof (unsigned short);
758  iovecs[2].iov_base = (void *)&fragmentation_data[0];
759  iovecs[2].iov_len = fragment_size;
760  (void)totemsrp_mcast (totemsrp_context, iovecs, 3, 0);
761 
762  mcast_packed_msg_count = 0;
763  fragment_size = 0;
764 
765  if (totempg_threaded_mode == 1) {
766  pthread_mutex_unlock (&mcast_msg_mutex);
767  }
768  return (0);
769 }
770 
771 /*
772  * Initialize the totem process group abstraction
773  */
775  qb_loop_t *poll_handle,
776  struct totem_config *totem_config)
777 {
778  int res;
779 
781  totempg_log_level_security = totem_config->totem_logging_configuration.log_level_security;
782  totempg_log_level_error = totem_config->totem_logging_configuration.log_level_error;
783  totempg_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
784  totempg_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
785  totempg_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
788 
789  fragmentation_data = malloc (TOTEMPG_PACKET_SIZE);
790  if (fragmentation_data == 0) {
791  return (-1);
792  }
793 
795 
796  res = totemsrp_initialize (
797  poll_handle,
798  &totemsrp_context,
799  totem_config,
800  &totempg_stats,
801  totempg_deliver_fn,
802  totempg_confchg_fn,
803  totempg_waiting_trans_ack_cb);
804 
805  if (res == -1) {
806  goto error_exit;
807  }
808 
810  totemsrp_context,
813  0,
814  callback_token_received_fn,
815  0);
816 
817  totempg_size_limit = (totemsrp_avail(totemsrp_context) - 1) *
819  sizeof (struct totempg_mcast) - 16);
820 
821  qb_list_init (&totempg_groups_list);
822 
823 error_exit:
824  return (res);
825 }
826 
827 void totempg_finalize (void)
828 {
829  if (totempg_threaded_mode == 1) {
830  pthread_mutex_lock (&totempg_mutex);
831  }
832  totemsrp_finalize (totemsrp_context);
833  if (totempg_threaded_mode == 1) {
834  pthread_mutex_unlock (&totempg_mutex);
835  }
836 }
837 
838 /*
839  * Multicast a message
840  */
841 static int mcast_msg (
842  struct iovec *iovec_in,
843  unsigned int iov_len,
844  int guarantee)
845 {
846  int res = 0;
847  struct totempg_mcast mcast;
848  struct iovec iovecs[3];
849  struct iovec iovec[64];
850  int i;
851  int dest, src;
852  int max_packet_size = 0;
853  int copy_len = 0;
854  int copy_base = 0;
855  int total_size = 0;
856 
857  if (totempg_threaded_mode == 1) {
858  pthread_mutex_lock (&mcast_msg_mutex);
859  }
860  totemsrp_event_signal (totemsrp_context, TOTEM_EVENT_NEW_MSG, 1);
861 
862  /*
863  * Remove zero length iovectors from the list
864  */
865  assert (iov_len < 64);
866  for (dest = 0, src = 0; src < iov_len; src++) {
867  if (iovec_in[src].iov_len) {
868  memcpy (&iovec[dest++], &iovec_in[src],
869  sizeof (struct iovec));
870  }
871  }
872  iov_len = dest;
873 
874  max_packet_size = TOTEMPG_PACKET_SIZE -
875  (sizeof (unsigned short) * (mcast_packed_msg_count + 1));
876 
877  mcast_packed_msg_lens[mcast_packed_msg_count] = 0;
878 
879  /*
880  * Check if we would overwrite new message queue
881  */
882  for (i = 0; i < iov_len; i++) {
883  total_size += iovec[i].iov_len;
884  }
885 
886  if (byte_count_send_ok (total_size + sizeof(unsigned short) *
887  (mcast_packed_msg_count)) == 0) {
888 
889  if (totempg_threaded_mode == 1) {
890  pthread_mutex_unlock (&mcast_msg_mutex);
891  }
892  return(-1);
893  }
894 
895  mcast.header.version = 0;
896  for (i = 0; i < iov_len; ) {
897  mcast.fragmented = 0;
898  mcast.continuation = fragment_continuation;
899  copy_len = iovec[i].iov_len - copy_base;
900 
901  /*
902  * If it all fits with room left over, copy it in.
903  * We need to leave at least sizeof(short) + 1 bytes in the
904  * fragment_buffer on exit so that max_packet_size + fragment_size
905  * doesn't exceed the size of the fragment_buffer on the next call.
906  */
907  if ((iovec[i].iov_len + fragment_size) <
908  (max_packet_size - sizeof (unsigned short))) {
909 
910  memcpy (&fragmentation_data[fragment_size],
911  (char *)iovec[i].iov_base + copy_base, copy_len);
912  fragment_size += copy_len;
913  mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
914  next_fragment = 1;
915  copy_len = 0;
916  copy_base = 0;
917  i++;
918  continue;
919 
920  /*
921  * If it just fits or is too big, then send out what fits.
922  */
923  } else {
924  unsigned char *data_ptr;
925 
926  copy_len = min(copy_len, max_packet_size - fragment_size);
927  if( copy_len == max_packet_size )
928  data_ptr = (unsigned char *)iovec[i].iov_base + copy_base;
929  else {
930  data_ptr = fragmentation_data;
931  }
932 
933  memcpy (&fragmentation_data[fragment_size],
934  (unsigned char *)iovec[i].iov_base + copy_base, copy_len);
935  mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
936 
937  /*
938  * if we're not on the last iovec or the iovec is too large to
939  * fit, then indicate a fragment. This also means that the next
940  * message will have the continuation of this one.
941  */
942  if ((i < (iov_len - 1)) ||
943  ((copy_base + copy_len) < iovec[i].iov_len)) {
944  if (!next_fragment) {
945  next_fragment++;
946  }
947  fragment_continuation = next_fragment;
948  mcast.fragmented = next_fragment++;
949  assert(fragment_continuation != 0);
950  assert(mcast.fragmented != 0);
951  } else {
952  fragment_continuation = 0;
953  }
954 
955  /*
956  * assemble the message and send it
957  */
958  mcast.msg_count = ++mcast_packed_msg_count;
959  iovecs[0].iov_base = (void *)&mcast;
960  iovecs[0].iov_len = sizeof(struct totempg_mcast);
961  iovecs[1].iov_base = (void *)mcast_packed_msg_lens;
962  iovecs[1].iov_len = mcast_packed_msg_count *
963  sizeof(unsigned short);
964  iovecs[2].iov_base = (void *)data_ptr;
965  iovecs[2].iov_len = fragment_size + copy_len;
966  assert (totemsrp_avail(totemsrp_context) > 0);
967  res = totemsrp_mcast (totemsrp_context, iovecs, 3, guarantee);
968  if (res == -1) {
969  goto error_exit;
970  }
971 
972  /*
973  * Recalculate counts and indexes for the next.
974  */
975  mcast_packed_msg_lens[0] = 0;
976  mcast_packed_msg_count = 0;
977  fragment_size = 0;
978  max_packet_size = TOTEMPG_PACKET_SIZE - (sizeof(unsigned short));
979 
980  /*
981  * If the iovec all fit, go to the next iovec
982  */
983  if ((copy_base + copy_len) == iovec[i].iov_len) {
984  copy_len = 0;
985  copy_base = 0;
986  i++;
987 
988  /*
989  * Continue with the rest of the current iovec.
990  */
991  } else {
992  copy_base += copy_len;
993  }
994  }
995  }
996 
997  /*
998  * Bump only if we added message data. This may be zero if
999  * the last buffer just fit into the fragmentation_data buffer
1000  * and we were at the last iovec.
1001  */
1002  if (mcast_packed_msg_lens[mcast_packed_msg_count]) {
1003  mcast_packed_msg_count++;
1004  }
1005 
1006 error_exit:
1007  if (totempg_threaded_mode == 1) {
1008  pthread_mutex_unlock (&mcast_msg_mutex);
1009  }
1010  return (res);
1011 }
1012 
1013 /*
1014  * Determine if a message of msg_size could be queued
1015  */
1016 static int msg_count_send_ok (
1017  int msg_count)
1018 {
1019  int avail = 0;
1020 
1021  avail = totemsrp_avail (totemsrp_context);
1022  totempg_stats.msg_queue_avail = avail;
1023 
1024  return ((avail - totempg_reserved) > msg_count);
1025 }
1026 
1027 static int byte_count_send_ok (
1028  int byte_count)
1029 {
1030  unsigned int msg_count = 0;
1031  int avail = 0;
1032 
1033  avail = totemsrp_avail (totemsrp_context);
1034 
1035  msg_count = (byte_count / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
1036 
1037  return (avail >= msg_count);
1038 }
1039 
1040 static int send_reserve (
1041  int msg_size)
1042 {
1043  unsigned int msg_count = 0;
1044 
1045  msg_count = (msg_size / (totempg_totem_config->net_mtu - sizeof (struct totempg_mcast) - 16)) + 1;
1046  totempg_reserved += msg_count;
1047  totempg_stats.msg_reserved = totempg_reserved;
1048 
1049  return (msg_count);
1050 }
1051 
1052 static void send_release (
1053  int msg_count)
1054 {
1055  totempg_reserved -= msg_count;
1056  totempg_stats.msg_reserved = totempg_reserved;
1057 }
1058 
1059 #ifndef HAVE_SMALL_MEMORY_FOOTPRINT
1060 #undef MESSAGE_QUEUE_MAX
1061 #define MESSAGE_QUEUE_MAX ((4 * MESSAGE_SIZE_MAX) / totempg_totem_config->net_mtu)
1062 #endif /* HAVE_SMALL_MEMORY_FOOTPRINT */
1063 
1064 static uint32_t q_level_precent_used(void)
1065 {
1066  return (100 - (((totemsrp_avail(totemsrp_context) - totempg_reserved) * 100) / MESSAGE_QUEUE_MAX));
1067 }
1068 
1070  void **handle_out,
1072  int delete,
1073  int (*callback_fn) (enum totem_callback_token_type type, const void *),
1074  const void *data)
1075 {
1076  unsigned int res;
1077  if (totempg_threaded_mode == 1) {
1078  pthread_mutex_lock (&callback_token_mutex);
1079  }
1080  res = totemsrp_callback_token_create (totemsrp_context, handle_out, type, delete,
1081  callback_fn, data);
1082  if (totempg_threaded_mode == 1) {
1083  pthread_mutex_unlock (&callback_token_mutex);
1084  }
1085  return (res);
1086 }
1087 
1089  void *handle_out)
1090 {
1091  if (totempg_threaded_mode == 1) {
1092  pthread_mutex_lock (&callback_token_mutex);
1093  }
1094  totemsrp_callback_token_destroy (totemsrp_context, handle_out);
1095  if (totempg_threaded_mode == 1) {
1096  pthread_mutex_unlock (&callback_token_mutex);
1097  }
1098 }
1099 
1100 /*
1101  * vi: set autoindent tabstop=4 shiftwidth=4 :
1102  */
1103 
1105  void **totempg_groups_instance,
1106 
1107  void (*deliver_fn) (
1108  unsigned int nodeid,
1109  const void *msg,
1110  unsigned int msg_len,
1111  int endian_conversion_required),
1112 
1113  void (*confchg_fn) (
1114  enum totem_configuration_type configuration_type,
1115  const unsigned int *member_list, size_t member_list_entries,
1116  const unsigned int *left_list, size_t left_list_entries,
1117  const unsigned int *joined_list, size_t joined_list_entries,
1118  const struct memb_ring_id *ring_id))
1119 {
1120  struct totempg_group_instance *instance;
1121 
1122  if (totempg_threaded_mode == 1) {
1123  pthread_mutex_lock (&totempg_mutex);
1124  }
1125 
1126  instance = malloc (sizeof (struct totempg_group_instance));
1127  if (instance == NULL) {
1128  goto error_exit;
1129  }
1130 
1131  instance->deliver_fn = deliver_fn;
1132  instance->confchg_fn = confchg_fn;
1133  instance->groups = 0;
1134  instance->groups_cnt = 0;
1135  instance->q_level = QB_LOOP_MED;
1136  qb_list_init (&instance->list);
1137  qb_list_add (&instance->list, &totempg_groups_list);
1138 
1139  if (totempg_threaded_mode == 1) {
1140  pthread_mutex_unlock (&totempg_mutex);
1141  }
1142  *totempg_groups_instance = instance;
1143  return (0);
1144 
1145 error_exit:
1146  if (totempg_threaded_mode == 1) {
1147  pthread_mutex_unlock (&totempg_mutex);
1148  }
1149  return (-1);
1150 }
1151 
1153  void *totempg_groups_instance,
1154  const struct totempg_group *groups,
1155  size_t group_cnt)
1156 {
1157  struct totempg_group_instance *instance = (struct totempg_group_instance *)totempg_groups_instance;
1158  struct totempg_group *new_groups;
1159  int res = 0;
1160 
1161  if (totempg_threaded_mode == 1) {
1162  pthread_mutex_lock (&totempg_mutex);
1163  }
1164 
1165  new_groups = realloc (instance->groups,
1166  sizeof (struct totempg_group) *
1167  (instance->groups_cnt + group_cnt));
1168  if (new_groups == 0) {
1169  res = -1;
1170  goto error_exit;
1171  }
1172  memcpy (&new_groups[instance->groups_cnt],
1173  groups, group_cnt * sizeof (struct totempg_group));
1174  instance->groups = new_groups;
1175  instance->groups_cnt += group_cnt;
1176 
1177 error_exit:
1178  if (totempg_threaded_mode == 1) {
1179  pthread_mutex_unlock (&totempg_mutex);
1180  }
1181  return (res);
1182 }
1183 
1185  void *totempg_groups_instance,
1186  const struct totempg_group *groups,
1187  size_t group_cnt)
1188 {
1189  if (totempg_threaded_mode == 1) {
1190  pthread_mutex_lock (&totempg_mutex);
1191  }
1192 
1193  if (totempg_threaded_mode == 1) {
1194  pthread_mutex_unlock (&totempg_mutex);
1195  }
1196  return (0);
1197 }
1198 
1199 #define MAX_IOVECS_FROM_APP 32
1200 #define MAX_GROUPS_PER_MSG 32
1201 
1203  void *totempg_groups_instance,
1204  const struct iovec *iovec,
1205  unsigned int iov_len,
1206  int guarantee)
1207 {
1208  struct totempg_group_instance *instance = (struct totempg_group_instance *)totempg_groups_instance;
1209  unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
1210  struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
1211  int i;
1212  unsigned int res;
1213 
1214  if (totempg_threaded_mode == 1) {
1215  pthread_mutex_lock (&totempg_mutex);
1216  }
1217 
1218  /*
1219  * Build group_len structure and the iovec_mcast structure
1220  */
1221  group_len[0] = instance->groups_cnt;
1222  for (i = 0; i < instance->groups_cnt; i++) {
1223  group_len[i + 1] = instance->groups[i].group_len;
1224  iovec_mcast[i + 1].iov_len = instance->groups[i].group_len;
1225  iovec_mcast[i + 1].iov_base = (void *) instance->groups[i].group;
1226  }
1227  iovec_mcast[0].iov_len = (instance->groups_cnt + 1) * sizeof (unsigned short);
1228  iovec_mcast[0].iov_base = group_len;
1229  for (i = 0; i < iov_len; i++) {
1230  iovec_mcast[i + instance->groups_cnt + 1].iov_len = iovec[i].iov_len;
1231  iovec_mcast[i + instance->groups_cnt + 1].iov_base = iovec[i].iov_base;
1232  }
1233 
1234  res = mcast_msg (iovec_mcast, iov_len + instance->groups_cnt + 1, guarantee);
1235 
1236  if (totempg_threaded_mode == 1) {
1237  pthread_mutex_unlock (&totempg_mutex);
1238  }
1239 
1240  return (res);
1241 }
1242 
1243 static void check_q_level(
1244  void *totempg_groups_instance)
1245 {
1246  struct totempg_group_instance *instance = (struct totempg_group_instance *)totempg_groups_instance;
1247  int32_t old_level = instance->q_level;
1248  int32_t percent_used = q_level_precent_used();
1249 
1250  if (percent_used >= 75 && instance->q_level != TOTEM_Q_LEVEL_CRITICAL) {
1251  instance->q_level = TOTEM_Q_LEVEL_CRITICAL;
1252  } else if (percent_used < 30 && instance->q_level != TOTEM_Q_LEVEL_LOW) {
1253  instance->q_level = TOTEM_Q_LEVEL_LOW;
1254  } else if (percent_used > 40 && percent_used < 50 && instance->q_level != TOTEM_Q_LEVEL_GOOD) {
1255  instance->q_level = TOTEM_Q_LEVEL_GOOD;
1256  } else if (percent_used > 60 && percent_used < 70 && instance->q_level != TOTEM_Q_LEVEL_HIGH) {
1257  instance->q_level = TOTEM_Q_LEVEL_HIGH;
1258  }
1259  if (totem_queue_level_changed && old_level != instance->q_level) {
1260  totem_queue_level_changed(instance->q_level);
1261  }
1262 }
1263 
1265  void *totempg_groups_instance)
1266 {
1267  struct totempg_group_instance *instance = (struct totempg_group_instance *)totempg_groups_instance;
1268 
1269  check_q_level(instance);
1270 }
1271 
1273  void *totempg_groups_instance,
1274  const struct iovec *iovec,
1275  unsigned int iov_len)
1276 {
1277  struct totempg_group_instance *instance = (struct totempg_group_instance *)totempg_groups_instance;
1278  unsigned int size = 0;
1279  unsigned int i;
1280  unsigned int reserved = 0;
1281 
1282  if (totempg_threaded_mode == 1) {
1283  pthread_mutex_lock (&totempg_mutex);
1284  pthread_mutex_lock (&mcast_msg_mutex);
1285  }
1286 
1287  for (i = 0; i < instance->groups_cnt; i++) {
1288  size += instance->groups[i].group_len;
1289  }
1290  for (i = 0; i < iov_len; i++) {
1291  size += iovec[i].iov_len;
1292  }
1293 
1294  if (size >= totempg_size_limit) {
1295  reserved = -1;
1296  goto error_exit;
1297  }
1298 
1299  if (byte_count_send_ok (size)) {
1300  reserved = send_reserve (size);
1301  } else {
1302  reserved = 0;
1303  }
1304 
1305 error_exit:
1306  check_q_level(instance);
1307 
1308  if (totempg_threaded_mode == 1) {
1309  pthread_mutex_unlock (&mcast_msg_mutex);
1310  pthread_mutex_unlock (&totempg_mutex);
1311  }
1312  return (reserved);
1313 }
1314 
1315 
1317 {
1318  if (totempg_threaded_mode == 1) {
1319  pthread_mutex_lock (&totempg_mutex);
1320  pthread_mutex_lock (&mcast_msg_mutex);
1321  }
1322  send_release (msg_count);
1323  if (totempg_threaded_mode == 1) {
1324  pthread_mutex_unlock (&mcast_msg_mutex);
1325  pthread_mutex_unlock (&totempg_mutex);
1326  }
1327  return 0;
1328 }
1329 
1331  void *totempg_groups_instance,
1332  int guarantee,
1333  const struct totempg_group *groups,
1334  size_t groups_cnt,
1335  const struct iovec *iovec,
1336  unsigned int iov_len)
1337 {
1338  unsigned short group_len[MAX_GROUPS_PER_MSG + 1];
1339  struct iovec iovec_mcast[MAX_GROUPS_PER_MSG + 1 + MAX_IOVECS_FROM_APP];
1340  int i;
1341  unsigned int res;
1342 
1343  if (totempg_threaded_mode == 1) {
1344  pthread_mutex_lock (&totempg_mutex);
1345  }
1346 
1347  /*
1348  * Build group_len structure and the iovec_mcast structure
1349  */
1350  group_len[0] = groups_cnt;
1351  for (i = 0; i < groups_cnt; i++) {
1352  group_len[i + 1] = groups[i].group_len;
1353  iovec_mcast[i + 1].iov_len = groups[i].group_len;
1354  iovec_mcast[i + 1].iov_base = (void *) groups[i].group;
1355  }
1356  iovec_mcast[0].iov_len = (groups_cnt + 1) * sizeof (unsigned short);
1357  iovec_mcast[0].iov_base = group_len;
1358  for (i = 0; i < iov_len; i++) {
1359  iovec_mcast[i + groups_cnt + 1].iov_len = iovec[i].iov_len;
1360  iovec_mcast[i + groups_cnt + 1].iov_base = iovec[i].iov_base;
1361  }
1362 
1363  res = mcast_msg (iovec_mcast, iov_len + groups_cnt + 1, guarantee);
1364 
1365  if (totempg_threaded_mode == 1) {
1366  pthread_mutex_unlock (&totempg_mutex);
1367  }
1368  return (res);
1369 }
1370 
1371 /*
1372  * Returns -1 if error, 0 if can't send, 1 if can send the message
1373  */
1375  void *totempg_groups_instance,
1376  const struct totempg_group *groups,
1377  size_t groups_cnt,
1378  const struct iovec *iovec,
1379  unsigned int iov_len)
1380 {
1381  unsigned int size = 0;
1382  unsigned int i;
1383  unsigned int res;
1384 
1385  if (totempg_threaded_mode == 1) {
1386  pthread_mutex_lock (&totempg_mutex);
1387  }
1388 
1389  for (i = 0; i < groups_cnt; i++) {
1390  size += groups[i].group_len;
1391  }
1392  for (i = 0; i < iov_len; i++) {
1393  size += iovec[i].iov_len;
1394  }
1395 
1396  res = msg_count_send_ok (size);
1397 
1398  if (totempg_threaded_mode == 1) {
1399  pthread_mutex_unlock (&totempg_mutex);
1400  }
1401  return (res);
1402 }
1403 
1405  struct totem_ip_address *interface_addr,
1406  unsigned short ip_port,
1407  unsigned int iface_no)
1408 {
1409  int res;
1410 
1411  res = totemsrp_iface_set (
1412  totemsrp_context,
1413  interface_addr,
1414  ip_port,
1415  iface_no);
1416 
1417  return (res);
1418 }
1419 
1421  unsigned int nodeid,
1422  unsigned int *interface_id,
1423  struct totem_ip_address *interfaces,
1424  unsigned int interfaces_size,
1425  char ***status,
1426  unsigned int *iface_count)
1427 {
1428  int res;
1429 
1430  res = totemsrp_ifaces_get (
1431  totemsrp_context,
1432  nodeid,
1433  interface_id,
1434  interfaces,
1435  interfaces_size,
1436  status,
1437  iface_count);
1438 
1439  return (res);
1440 }
1441 
1443 {
1444  totemsrp_event_signal (totemsrp_context, type, value);
1445 }
1446 
1447 void* totempg_get_stats (void)
1448 {
1449  return &totempg_stats;
1450 }
1451 
1453  const char *cipher_type,
1454  const char *hash_type)
1455 {
1456  int res;
1457 
1458  res = totemsrp_crypto_set (totemsrp_context, cipher_type, hash_type);
1459 
1460  return (res);
1461 }
1462 
1463 #define ONE_IFACE_LEN 63
1464 const char *totempg_ifaces_print (unsigned int nodeid)
1465 {
1466  static char iface_string[256 * INTERFACE_MAX];
1467  char one_iface[ONE_IFACE_LEN+1];
1468  struct totem_ip_address interfaces[INTERFACE_MAX];
1469  unsigned int iface_count;
1470  unsigned int iface_ids[INTERFACE_MAX];
1471  unsigned int i;
1472  int res;
1473 
1474  iface_string[0] = '\0';
1475 
1476  res = totempg_ifaces_get (nodeid, iface_ids, interfaces, INTERFACE_MAX, NULL, &iface_count);
1477  if (res == -1) {
1478  return ("no interface found for nodeid");
1479  }
1480 
1481  res = totempg_ifaces_get (nodeid, iface_ids, interfaces, INTERFACE_MAX, NULL, &iface_count);
1482 
1483  for (i = 0; i < iface_count; i++) {
1484  if (!interfaces[i].family) {
1485  continue;
1486  }
1487  snprintf (one_iface, ONE_IFACE_LEN,
1488  "r(%d) ip(%s) ",
1489  i, totemip_print (&interfaces[i]));
1490  strcat (iface_string, one_iface);
1491  }
1492  return (iface_string);
1493 }
1494 
1495 unsigned int totempg_my_nodeid_get (void)
1496 {
1497  return (totemsrp_my_nodeid_get(totemsrp_context));
1498 }
1499 
1501 {
1502  return (totemsrp_my_family_get(totemsrp_context));
1503 }
1505  void (*totem_service_ready) (void))
1506 {
1507  totemsrp_service_ready_register (totemsrp_context, totem_service_ready);
1508 }
1509 
1511 {
1512  totem_queue_level_changed = fn;
1513 }
1514 
1516  const struct totem_ip_address *member,
1517  int ring_no)
1518 {
1519  return totemsrp_member_add (totemsrp_context, member, ring_no);
1520 }
1521 
1523  const struct totem_ip_address *member,
1524  int ring_no)
1525 {
1526  return totemsrp_member_remove (totemsrp_context, member, ring_no);
1527 }
1528 
1529 extern int totempg_reconfigure (void)
1530 {
1531  return totemsrp_reconfigure (totemsrp_context, totempg_totem_config);
1532 }
1533 
1534 extern void totempg_stats_clear (int flags)
1535 {
1537  totempg_stats.msg_reserved = 0;
1538  totempg_stats.msg_queue_avail = 0;
1539  }
1540  return totemsrp_stats_clear (totemsrp_context, flags);
1541 }
1542 
1544 {
1545  totempg_threaded_mode = 1;
1546  totemsrp_threaded_mode_enable (totemsrp_context);
1547 }
1548 
1550 {
1551  totemsrp_trans_ack (totemsrp_context);
1552 }
1553 
1555 {
1556  totemsrp_force_gather(totemsrp_context);
1557 }
totempg_callback_token_create
int totempg_callback_token_create(void **handle_out, enum totem_callback_token_type type, int delete, int(*callback_fn)(enum totem_callback_token_type type, const void *), const void *data)
Definition: totempg.c:1069
totem_logging_configuration::log_level_error
int log_level_error
Definition: totem.h:109
totempg_trans_ack
void totempg_trans_ack(void)
Definition: totempg.c:1549
totem_callback_token_type
totem_callback_token_type
The totem_callback_token_type enum.
Definition: coroapi.h:142
totemsrp_crypto_set
int totemsrp_crypto_set(void *srp_context, const char *cipher_type, const char *hash_type)
Definition: totemsrp.c:1087
totem_message_header::type
char type
Definition: totem.h:127
value
uint32_t value
Definition: exec/votequorum.c:100
totempg_initialize
int totempg_initialize(qb_loop_t *poll_handle, struct totem_config *totem_config)
Initialize the totem process groups abstraction.
Definition: totempg.c:774
totem_configuration_type
totem_configuration_type
The totem_configuration_type enum.
Definition: coroapi.h:132
totempg_stats_clear
void totempg_stats_clear(int flags)
Definition: totempg.c:1534
totempg_mcast
Definition: totempg.c:137
THROW_AWAY_INACTIVE
Definition: totempg.c:195
totempg_member_add
int totempg_member_add(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1515
totempg.h
assembly::index
int index
Definition: totempg.c:202
totempg_stats_t::msg_queue_avail
uint32_t msg_queue_avail
Definition: totemstats.h:98
THROW_AWAY_ACTIVE
Definition: totempg.c:196
totempg_mcast::msg_count
unsigned short msg_count
Definition: totempg.c:141
TOTEMPG_PACKET_SIZE
#define TOTEMPG_PACKET_SIZE
Definition: totempg.c:153
TOTEM_Q_LEVEL_LOW
Definition: totempg.h:178
totempg_groups_initialize
int totempg_groups_initialize(void **totempg_groups_instance, void(*deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required), void(*confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id))
Initialize a groups instance.
Definition: totempg.c:1104
totempg_group_instance::list
struct qb_list_head list
Definition: totempg.c:261
totempg_mcast_header::version
short version
Definition: totempg.c:115
totemsrp_finalize
void totemsrp_finalize(void *srp_context)
Definition: totemsrp.c:1026
MAX_IOVECS_FROM_APP
#define MAX_IOVECS_FROM_APP
Definition: totempg.c:1199
totem_logging_configuration::log_level_debug
int log_level_debug
Definition: totem.h:112
totemip_print
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:264
type
char type
Definition: totem.h:55
totemsrp.h
totem_logging_configuration::log_level_notice
int log_level_notice
Definition: totem.h:111
totempg_queue_level_register_callback
void totempg_queue_level_register_callback(totem_queue_level_changed_fn fn)
Definition: totempg.c:1510
totemsrp_service_ready_register
void totemsrp_service_ready_register(void *context, void(*totem_service_ready)(void))
Definition: totemsrp.c:5099
log_printf
#define log_printf(level, format, args...)
Definition: totempg.c:272
TOTEMPG_NEED_ALIGN
#define TOTEMPG_NEED_ALIGN
Definition: totempg.c:123
totempg_group::group_len
size_t group_len
Definition: totempg.h:57
totemsrp_callback_token_create
int totemsrp_callback_token_create(void *srp_context, void **handle_out, enum totem_callback_token_type type, int delete, int(*callback_fn)(enum totem_callback_token_type type, const void *), const void *data)
Definition: totemsrp.c:3457
mcast
Definition: totemsrp.c:180
totemsrp_my_family_get
int totemsrp_my_family_get(void *srp_context)
Definition: totemsrp.c:1112
MAX_GROUPS_PER_MSG
#define MAX_GROUPS_PER_MSG
Definition: totempg.c:1200
TOTEM_CALLBACK_TOKEN_RECEIVED
Definition: coroapi.h:143
totemsrp_reconfigure
int totemsrp_reconfigure(void *context, struct totem_config *totem_config)
Definition: totemsrp.c:5150
totemsrp_net_mtu_adjust
void totemsrp_net_mtu_adjust(struct totem_config *totem_config)
Definition: totemsrp.c:5095
totempg_stats_t
Definition: totemstats.h:94
totempg_mcast::fragmented
unsigned char fragmented
Definition: totempg.c:139
totempg_reconfigure
int totempg_reconfigure(void)
Definition: totempg.c:1529
FRAME_SIZE_MAX
#define FRAME_SIZE_MAX
Definition: totem.h:52
totempg_groups_join
int totempg_groups_join(void *totempg_groups_instance, const struct totempg_group *groups, size_t group_cnt)
Definition: totempg.c:1152
swab.h
totem_queue_level_changed_fn
void(* totem_queue_level_changed_fn)(enum totem_q_level level)
Definition: totempg.h:186
mcast::header
struct totem_message_header header
Definition: totemsrp.c:181
totemsrp_stats_clear
void totemsrp_stats_clear(void *context, int flags)
Definition: totemsrp.c:5159
totempg_group_instance::q_level
int32_t q_level
Definition: totempg.c:259
totemsrp_iface_set
int totemsrp_iface_set(void *context, const struct totem_ip_address *interface_addr, unsigned short ip_port, unsigned int iface_no)
Definition: totemsrp.c:5027
callback_token_received_handle
void * callback_token_received_handle
Definition: totempg.c:718
totempg_groups_mcast_joined
int totempg_groups_mcast_joined(void *totempg_groups_instance, const struct iovec *iovec, unsigned int iov_len, int guarantee)
Definition: totempg.c:1202
header
struct totem_message_header header
Definition: totemsrp.c:260
totempg_group_instance::groups
struct totempg_group * groups
Definition: totempg.c:256
totemsrp_event_signal
void totemsrp_event_signal(void *srp_context, enum totem_event_type type, int value)
Definition: totemsrp.c:2450
assembly::last_frag_num
unsigned char last_frag_num
Definition: totempg.c:203
totem_config::net_mtu
unsigned int net_mtu
Definition: totem.h:202
totempg_groups_leave
int totempg_groups_leave(void *totempg_groups_instance, const struct totempg_group *groups, size_t group_cnt)
Definition: totempg.c:1184
totempg_threaded_mode_enable
void totempg_threaded_mode_enable(void)
Definition: totempg.c:1543
INTERFACE_MAX
#define INTERFACE_MAX
Definition: coroapi.h:88
assembly::data
unsigned char data[MESSAGE_SIZE_MAX+KNET_MAX_PACKET_SIZE]
Definition: totempg.c:201
totempg_mcast_header::type
short type
Definition: totempg.c:116
totempg_my_family_get
int totempg_my_family_get(void)
Definition: totempg.c:1500
totempg_event_signal
void totempg_event_signal(enum totem_event_type type, int value)
Definition: totempg.c:1442
totempg_groups_send_ok_groups
int totempg_groups_send_ok_groups(void *totempg_groups_instance, const struct totempg_group *groups, size_t groups_cnt, const struct iovec *iovec, unsigned int iov_len)
Definition: totempg.c:1374
TOTEM_Q_LEVEL_CRITICAL
Definition: totempg.h:181
__attribute__
typedef __attribute__
totempg_groups_mcast_groups
int totempg_groups_mcast_groups(void *totempg_groups_instance, int guarantee, const struct totempg_group *groups, size_t groups_cnt, const struct iovec *iovec, unsigned int iov_len)
Definition: totempg.c:1330
totemsrp_trans_ack
void totemsrp_trans_ack(void *context)
Definition: totemsrp.c:5141
totem_logging_configuration::log_subsys_id
int log_subsys_id
Definition: totem.h:114
totempg_group_instance
Definition: totempg.c:242
totempg_member_remove
int totempg_member_remove(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1522
totemsrp_force_gather
void totemsrp_force_gather(void *context)
Definition: totemsrp.c:5169
totempg_callback_token_destroy
void totempg_callback_token_destroy(void *handle_out)
Definition: totempg.c:1088
totempg_groups_joined_release
int totempg_groups_joined_release(int msg_count)
Definition: totempg.c:1316
totempg_iface_set
int totempg_iface_set(struct totem_ip_address *interface_addr, unsigned short ip_port, unsigned int iface_no)
Definition: totempg.c:1404
totempg_ifaces_print
const char * totempg_ifaces_print(unsigned int nodeid)
Definition: totempg.c:1464
swab16
#define swab16(x)
The swab16 macro.
Definition: swab.h:39
flags
uint32_t flags
Definition: exec/votequorum.c:102
totem_config
Definition: totem.h:152
totempg_ifaces_get
int totempg_ifaces_get(unsigned int nodeid, unsigned int *interface_id, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
Definition: totempg.c:1420
totempg_group
Definition: totempg.h:55
throw_away_mode
throw_away_mode
Definition: totempg.c:194
family
unsigned short family
Definition: coroapi.h:76
totem_ip_address
The totem_ip_address struct.
Definition: coroapi.h:111
totempg_mcast_header
Definition: totempg.c:114
assembly::list
struct qb_list_head list
Definition: totempg.c:205
assembly::nodeid
unsigned int nodeid
Definition: totempg.c:200
memb_ring_id
The memb_ring_id struct.
Definition: coroapi.h:122
totempg_force_gather
void totempg_force_gather(void)
Definition: totempg.c:1554
totempg_crypto_set
int totempg_crypto_set(const char *cipher_type, const char *hash_type)
Definition: totempg.c:1452
totempg_mcast::header
struct totempg_mcast_header header
Definition: totempg.c:138
totempg_check_q_level
void totempg_check_q_level(void *totempg_groups_instance)
Definition: totempg.c:1264
totem_logging_configuration::log_level_warning
int log_level_warning
Definition: totem.h:110
totem_logging_configuration::log_level_security
void(*) in log_level_security)
Definition: totem.h:106
totem_event_type
totem_event_type
Definition: totem.h:259
totempg_totem_config
static void(*) struct totem_config totempg_totem_config)
Definition: totempg.c:190
util.h
assembly
Definition: totempg.c:199
totempg_group_instance::groups_cnt
int groups_cnt
Definition: totempg.c:258
totempg_my_nodeid_get
unsigned int totempg_my_nodeid_get(void)
Definition: totempg.c:1495
totem_message_header::version
char version
Definition: totem.h:126
nodeid
unsigned int nodeid
Definition: coroapi.h:75
MESSAGE_SIZE_MAX
#define MESSAGE_SIZE_MAX
Definition: coroapi.h:97
totempg_group_instance::confchg_fn
void(* confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id)
Definition: totempg.c:249
totemsrp_member_add
int totemsrp_member_add(void *context, const struct totem_ip_address *member, int iface_no)
Definition: totemsrp.c:5108
ring_id
struct memb_ring_id ring_id
Definition: totemsrp.c:264
totemsrp_avail
int totemsrp_avail(void *srp_context)
Return number of available messages that can be queued.
Definition: totemsrp.c:2530
totempg_groups_joined_reserve
int totempg_groups_joined_reserve(void *totempg_groups_instance, const struct iovec *iovec, unsigned int iov_len)
Definition: totempg.c:1272
assembly::throw_away_mode
enum throw_away_mode throw_away_mode
Definition: totempg.c:204
config.h
totempg_service_ready_register
void totempg_service_ready_register(void(*totem_service_ready)(void))
Definition: totempg.c:1504
totempg_group::group
const void * group
Definition: totempg.h:56
MESSAGE_QUEUE_MAX
#define MESSAGE_QUEUE_MAX
Definition: totempg.c:1061
logsys.h
TOTEM_Q_LEVEL_HIGH
Definition: totempg.h:180
totemsrp_initialize
int totemsrp_initialize(qb_loop_t *poll_handle, void **srp_context, struct totem_config *totem_config, totempg_stats_t *stats, void(*deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required), void(*confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id), void(*waiting_trans_ack_cb_fn)(int waiting_trans_ack))
Create a protocol instance.
Definition: totemsrp.c:818
TOTEM_EVENT_NEW_MSG
Definition: totem.h:261
totem_logging_configuration::log_printf
void(* log_printf)(int level, int subsys, const char *function_name, const char *file_name, int file_line, const char *format,...) __attribute__((format(printf
Definition: totem.h:99
ONE_IFACE_LEN
#define ONE_IFACE_LEN
Definition: totempg.c:1463
totempg_group_instance::deliver_fn
void(* deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required)
Definition: totempg.c:243
totempg_stats_t::msg_reserved
uint32_t msg_reserved
Definition: totemstats.h:97
QB_LIST_DECLARE
QB_LIST_DECLARE(assembly_list_inuse)
totemsrp_my_nodeid_get
unsigned int totemsrp_my_nodeid_get(void *srp_context)
Definition: totemsrp.c:1101
totemsrp_ifaces_get
int totemsrp_ifaces_get(void *srp_context, unsigned int nodeid, unsigned int *interface_id, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
Definition: totemsrp.c:1049
totemsrp_member_remove
int totemsrp_member_remove(void *context, const struct totem_ip_address *member, int iface_no)
Definition: totemsrp.c:5121
min
#define min(a, b)
Definition: exec/util.h:66
guarantee
int guarantee
Definition: totemsrp.c:266
totemsrp_threaded_mode_enable
void totemsrp_threaded_mode_enable(void *context)
Definition: totemsrp.c:5134
totemsrp_mcast
int totemsrp_mcast(void *srp_context, struct iovec *iovec, unsigned int iov_len, int guarantee)
Multicast a message.
Definition: totemsrp.c:2459
totempg_get_stats
void * totempg_get_stats(void)
Definition: totempg.c:1447
totempg_finalize
void totempg_finalize(void)
Definition: totempg.c:827
totempg_mcast::continuation
unsigned char continuation
Definition: totempg.c:140
totemsrp_callback_token_destroy
void totemsrp_callback_token_destroy(void *srp_context, void **handle_out)
Definition: totemsrp.c:3492
TOTEMPG_STATS_CLEAR_TOTEM
#define TOTEMPG_STATS_CLEAR_TOTEM
Definition: totemstats.h:115
TOTEM_Q_LEVEL_GOOD
Definition: totempg.h:179
totem_config::totem_logging_configuration
struct totem_logging_configuration totem_logging_configuration
Definition: totem.h:200