totemmrp.c 5.9 KB

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