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