4
0

totemmrp.c 5.4 KB

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