totemmrp.c 6.3 KB

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