totemmrp.c 6.1 KB

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