totemmrp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 in_addr 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 in_addr *member_list, int member_list_entries,
  70. struct in_addr *left_list, int left_list_entries,
  71. struct in_addr *joined_list, int joined_list_entries,
  72. struct memb_ring_id *ring_id) = 0;
  73. void totemmrp_deliver_fn (
  74. struct in_addr 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 in_addr *member_list, int member_list_entries,
  84. struct in_addr *left_list, int left_list_entries,
  85. struct in_addr *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. totemsrp_handle *totemsrp_handle,
  100. struct totem_config *totem_config,
  101. void (*deliver_fn) (
  102. struct in_addr source_addr,
  103. struct iovec *iovec,
  104. int iov_len,
  105. int endian_conversion_required),
  106. void (*confchg_fn) (
  107. enum totem_configuration_type configuration_type,
  108. struct in_addr *member_list, int member_list_entries,
  109. struct in_addr *left_list, int left_list_entries,
  110. struct in_addr *joined_list, int joined_list_entries,
  111. struct memb_ring_id *ring_id))
  112. {
  113. int result;
  114. pg_deliver_fn = deliver_fn;
  115. pg_confchg_fn = confchg_fn;
  116. result = totemsrp_initialize (
  117. poll_handle,
  118. &totemsrp_handle_in,
  119. totem_config,
  120. totemmrp_deliver_fn,
  121. totemmrp_confchg_fn);
  122. *totemsrp_handle = totemsrp_handle_in;
  123. return (result);
  124. }
  125. void totemmrp_finalize (void)
  126. {
  127. totemsrp_finalize (totemsrp_handle_in);
  128. }
  129. /*
  130. * Multicast a message
  131. */
  132. int totemmrp_mcast (
  133. struct iovec *iovec,
  134. int iov_len,
  135. int priority)
  136. {
  137. return totemsrp_mcast (totemsrp_handle_in, iovec, iov_len, priority);
  138. }
  139. /*
  140. * Return number of available messages that can be queued
  141. */
  142. int totemmrp_avail (void)
  143. {
  144. return (totemsrp_avail (totemsrp_handle_in));
  145. }
  146. int totemmrp_callback_token_create (
  147. void **handle_out,
  148. enum totem_callback_token_type type,
  149. int delete,
  150. int (*callback_fn) (enum totem_callback_token_type type, void *),
  151. void *data)
  152. {
  153. return totemsrp_callback_token_create (totemsrp_handle_in, handle_out, type, delete, callback_fn, data);
  154. }
  155. void totemmrp_callback_token_destroy (
  156. void **handle_out)
  157. {
  158. totemsrp_callback_token_destroy (totemsrp_handle_in, handle_out);
  159. }
  160. void totemmrp_new_msg_signal (void) {
  161. totemsrp_new_msg_signal (totemsrp_handle_in);
  162. }