totemmrp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <assert.h>
  35. #include <sys/mman.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <sys/socket.h>
  39. #include <netdb.h>
  40. #include <sys/un.h>
  41. #include <sys/sysinfo.h>
  42. #include <sys/ioctl.h>
  43. #include <sys/param.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <linux/if.h>
  47. #include <linux/sockios.h>
  48. #include <unistd.h>
  49. #include <fcntl.h>
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52. #include <errno.h>
  53. #include <signal.h>
  54. #include <sched.h>
  55. #include <time.h>
  56. #include <sys/time.h>
  57. #include <sys/poll.h>
  58. #include "totem.h"
  59. #include "totemsrp.h"
  60. #include "aispoll.h"
  61. totemsrp_handle totemsrp_handle_in;
  62. void (*pg_deliver_fn) (
  63. struct totem_ip_address *source_addr,
  64. struct iovec *iovec,
  65. int iov_len,
  66. int endian_conversion_required) = 0;
  67. void (*pg_confchg_fn) (
  68. enum totem_configuration_type configuration_type,
  69. struct totem_ip_address *member_list, int member_list_entries,
  70. struct totem_ip_address *left_list, int left_list_entries,
  71. struct totem_ip_address *joined_list, int joined_list_entries,
  72. struct memb_ring_id *ring_id) = 0;
  73. void totemmrp_deliver_fn (
  74. struct totem_ip_address *source_addr,
  75. struct iovec *iovec,
  76. int iov_len,
  77. int endian_conversion_required)
  78. {
  79. pg_deliver_fn (source_addr, iovec, iov_len, endian_conversion_required);
  80. }
  81. void totemmrp_confchg_fn (
  82. enum totem_configuration_type configuration_type,
  83. struct totem_ip_address *member_list, int member_list_entries,
  84. struct totem_ip_address *left_list, int left_list_entries,
  85. struct totem_ip_address *joined_list, int joined_list_entries,
  86. struct memb_ring_id *ring_id)
  87. {
  88. pg_confchg_fn (configuration_type,
  89. member_list, member_list_entries,
  90. left_list, left_list_entries,
  91. joined_list, joined_list_entries,
  92. ring_id);
  93. }
  94. /*
  95. * Initialize the totem multiple ring protocol
  96. */
  97. int totemmrp_initialize (
  98. poll_handle poll_handle,
  99. struct totem_config *totem_config,
  100. void (*deliver_fn) (
  101. struct totem_ip_address *source_addr,
  102. struct iovec *iovec,
  103. int iov_len,
  104. int endian_conversion_required),
  105. void (*confchg_fn) (
  106. enum totem_configuration_type configuration_type,
  107. struct totem_ip_address *member_list, int member_list_entries,
  108. struct totem_ip_address *left_list, int left_list_entries,
  109. struct totem_ip_address *joined_list, int joined_list_entries,
  110. struct memb_ring_id *ring_id))
  111. {
  112. int result;
  113. pg_deliver_fn = deliver_fn;
  114. pg_confchg_fn = confchg_fn;
  115. result = totemsrp_initialize (
  116. poll_handle,
  117. &totemsrp_handle_in,
  118. totem_config,
  119. totemmrp_deliver_fn,
  120. totemmrp_confchg_fn);
  121. return (result);
  122. }
  123. void totemmrp_finalize (void)
  124. {
  125. totemsrp_finalize (totemsrp_handle_in);
  126. }
  127. /*
  128. * Multicast a message
  129. */
  130. int totemmrp_mcast (
  131. struct iovec *iovec,
  132. int iov_len,
  133. int priority)
  134. {
  135. return totemsrp_mcast (totemsrp_handle_in, iovec, iov_len, priority);
  136. }
  137. /*
  138. * Return number of available messages that can be queued
  139. */
  140. int totemmrp_avail (void)
  141. {
  142. return (totemsrp_avail (totemsrp_handle_in));
  143. }
  144. int totemmrp_callback_token_create (
  145. void **handle_out,
  146. enum totem_callback_token_type type,
  147. int delete,
  148. int (*callback_fn) (enum totem_callback_token_type type, void *),
  149. void *data)
  150. {
  151. return totemsrp_callback_token_create (totemsrp_handle_in, handle_out, type, delete, callback_fn, data);
  152. }
  153. void totemmrp_callback_token_destroy (
  154. void *handle_out)
  155. {
  156. totemsrp_callback_token_destroy (totemsrp_handle_in, handle_out);
  157. }
  158. void totemmrp_new_msg_signal (void) {
  159. totemsrp_new_msg_signal (totemsrp_handle_in);
  160. }