totemmrp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/ioctl.h>
  42. #include <sys/param.h>
  43. #include <netinet/in.h>
  44. #include <arpa/inet.h>
  45. #include <unistd.h>
  46. #include <fcntl.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <errno.h>
  50. #include <signal.h>
  51. #include <sched.h>
  52. #include <time.h>
  53. #include <sys/time.h>
  54. #include <sys/poll.h>
  55. #include "totem.h"
  56. #include "totemsrp.h"
  57. #include "aispoll.h"
  58. totemsrp_handle totemsrp_handle_in;
  59. void (*pg_deliver_fn) (
  60. unsigned int nodeid,
  61. struct iovec *iovec,
  62. int iov_len,
  63. int endian_conversion_required) = 0;
  64. void (*pg_confchg_fn) (
  65. enum totem_configuration_type configuration_type,
  66. unsigned int *member_list, int member_list_entries,
  67. unsigned int *left_list, int left_list_entries,
  68. unsigned int *joined_list, int joined_list_entries,
  69. struct memb_ring_id *ring_id) = 0;
  70. void totemmrp_deliver_fn (
  71. unsigned int nodeid,
  72. struct iovec *iovec,
  73. int iov_len,
  74. int endian_conversion_required)
  75. {
  76. pg_deliver_fn (nodeid, iovec, iov_len, endian_conversion_required);
  77. }
  78. void totemmrp_confchg_fn (
  79. enum totem_configuration_type configuration_type,
  80. unsigned int *member_list, int member_list_entries,
  81. unsigned int *left_list, int left_list_entries,
  82. unsigned int *joined_list, int joined_list_entries,
  83. struct memb_ring_id *ring_id)
  84. {
  85. pg_confchg_fn (configuration_type,
  86. member_list, member_list_entries,
  87. left_list, left_list_entries,
  88. joined_list, joined_list_entries,
  89. ring_id);
  90. }
  91. /*
  92. * Initialize the totem multiple ring protocol
  93. */
  94. int totemmrp_initialize (
  95. poll_handle poll_handle,
  96. struct totem_config *totem_config,
  97. void (*deliver_fn) (
  98. unsigned int nodeid,
  99. struct iovec *iovec,
  100. int iov_len,
  101. int endian_conversion_required),
  102. void (*confchg_fn) (
  103. enum totem_configuration_type configuration_type,
  104. unsigned int *member_list, int member_list_entries,
  105. unsigned int *left_list, int left_list_entries,
  106. unsigned int *joined_list, int joined_list_entries,
  107. struct memb_ring_id *ring_id))
  108. {
  109. int result;
  110. pg_deliver_fn = deliver_fn;
  111. pg_confchg_fn = confchg_fn;
  112. result = totemsrp_initialize (
  113. poll_handle,
  114. &totemsrp_handle_in,
  115. totem_config,
  116. totemmrp_deliver_fn,
  117. totemmrp_confchg_fn);
  118. return (result);
  119. }
  120. void totemmrp_finalize (void)
  121. {
  122. totemsrp_finalize (totemsrp_handle_in);
  123. }
  124. /*
  125. * Multicast a message
  126. */
  127. int totemmrp_mcast (
  128. struct iovec *iovec,
  129. int iov_len,
  130. int priority)
  131. {
  132. return totemsrp_mcast (totemsrp_handle_in, iovec, iov_len, priority);
  133. }
  134. /*
  135. * Return number of available messages that can be queued
  136. */
  137. int totemmrp_avail (void)
  138. {
  139. return (totemsrp_avail (totemsrp_handle_in));
  140. }
  141. int totemmrp_callback_token_create (
  142. void **handle_out,
  143. enum totem_callback_token_type type,
  144. int delete,
  145. int (*callback_fn) (enum totem_callback_token_type type, void *),
  146. void *data)
  147. {
  148. return totemsrp_callback_token_create (totemsrp_handle_in, handle_out, type, delete, callback_fn, data);
  149. }
  150. void totemmrp_callback_token_destroy (
  151. void *handle_out)
  152. {
  153. totemsrp_callback_token_destroy (totemsrp_handle_in, handle_out);
  154. }
  155. void totemmrp_new_msg_signal (void) {
  156. totemsrp_new_msg_signal (totemsrp_handle_in);
  157. }
  158. int totemmrp_ifaces_get (
  159. unsigned int nodeid,
  160. struct totem_ip_address *interfaces,
  161. char ***status,
  162. unsigned int *iface_count)
  163. {
  164. int res;
  165. res = totemsrp_ifaces_get (
  166. totemsrp_handle_in,
  167. nodeid,
  168. interfaces,
  169. status,
  170. iface_count);
  171. return (res);
  172. }
  173. extern int totemmrp_ring_reenable (void)
  174. {
  175. int res;
  176. res = totemsrp_ring_reenable (
  177. totemsrp_handle_in);
  178. return (res);
  179. }