totemmrp.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 <qb/qbloop.h>
  57. #include "totemmrp.h"
  58. #include "totemsrp.h"
  59. void *totemsrp_context;
  60. void totemmrp_deliver_fn (
  61. unsigned int nodeid,
  62. const void *msg,
  63. unsigned int msg_len,
  64. int endian_conversion_required);
  65. void totemmrp_confchg_fn (
  66. enum totem_configuration_type configuration_type,
  67. const unsigned int *member_list, size_t member_list_entries,
  68. const unsigned int *left_list, size_t left_list_entries,
  69. const unsigned int *joined_list, size_t joined_list_entries,
  70. const struct memb_ring_id *ring_id);
  71. void (*pg_deliver_fn) (
  72. unsigned int nodeid,
  73. const void *msg,
  74. unsigned int msg_len,
  75. int endian_conversion_required) = 0;
  76. void (*pg_confchg_fn) (
  77. enum totem_configuration_type configuration_type,
  78. const unsigned int *member_list, size_t member_list_entries,
  79. const unsigned int *left_list, size_t left_list_entries,
  80. const unsigned int *joined_list, size_t joined_list_entries,
  81. const struct memb_ring_id *ring_id) = 0;
  82. void totemmrp_deliver_fn (
  83. unsigned int nodeid,
  84. const void *msg,
  85. unsigned int msg_len,
  86. int endian_conversion_required)
  87. {
  88. pg_deliver_fn (nodeid, msg, msg_len, endian_conversion_required);
  89. }
  90. void totemmrp_confchg_fn (
  91. enum totem_configuration_type configuration_type,
  92. const unsigned int *member_list, size_t member_list_entries,
  93. const unsigned int *left_list, size_t left_list_entries,
  94. const unsigned int *joined_list, size_t joined_list_entries,
  95. const struct memb_ring_id *ring_id)
  96. {
  97. pg_confchg_fn (configuration_type,
  98. member_list, member_list_entries,
  99. left_list, left_list_entries,
  100. joined_list, joined_list_entries,
  101. ring_id);
  102. }
  103. /*
  104. * Initialize the totem multiple ring protocol
  105. */
  106. int totemmrp_initialize (
  107. qb_loop_t *poll_handle,
  108. struct totem_config *totem_config,
  109. totempg_stats_t *stats,
  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. void (*waiting_trans_ack_cb_fn) (
  122. int waiting_trans_ack))
  123. {
  124. int result;
  125. pg_deliver_fn = deliver_fn;
  126. pg_confchg_fn = confchg_fn;
  127. stats->mrp = calloc (sizeof(totemmrp_stats_t), 1);
  128. result = totemsrp_initialize (
  129. poll_handle,
  130. &totemsrp_context,
  131. totem_config,
  132. stats->mrp,
  133. totemmrp_deliver_fn,
  134. totemmrp_confchg_fn,
  135. waiting_trans_ack_cb_fn);
  136. return (result);
  137. }
  138. void totemmrp_finalize (void)
  139. {
  140. totemsrp_finalize (totemsrp_context);
  141. }
  142. /*
  143. * Multicast a message
  144. */
  145. int totemmrp_mcast (
  146. struct iovec *iovec,
  147. unsigned int iov_len,
  148. int priority)
  149. {
  150. return totemsrp_mcast (totemsrp_context, iovec, iov_len, priority);
  151. }
  152. /*
  153. * Return number of available messages that can be queued
  154. */
  155. int totemmrp_avail (void)
  156. {
  157. return (totemsrp_avail (totemsrp_context));
  158. }
  159. int totemmrp_callback_token_create (
  160. void **handle_out,
  161. enum totem_callback_token_type type,
  162. int delete,
  163. int (*callback_fn) (enum totem_callback_token_type type, const void *),
  164. const void *data)
  165. {
  166. return totemsrp_callback_token_create (totemsrp_context, handle_out, type, delete, callback_fn, data);
  167. }
  168. void totemmrp_callback_token_destroy (
  169. void *handle_out)
  170. {
  171. totemsrp_callback_token_destroy (totemsrp_context, handle_out);
  172. }
  173. void totemmrp_event_signal (enum totem_event_type type, int value)
  174. {
  175. totemsrp_event_signal (totemsrp_context, type, value);
  176. }
  177. int totemmrp_ifaces_get (
  178. unsigned int nodeid,
  179. struct totem_ip_address *interfaces,
  180. unsigned int interfaces_size,
  181. char ***status,
  182. unsigned int *iface_count)
  183. {
  184. int res;
  185. res = totemsrp_ifaces_get (
  186. totemsrp_context,
  187. nodeid,
  188. interfaces,
  189. interfaces_size,
  190. status,
  191. iface_count);
  192. return (res);
  193. }
  194. int totemmrp_crypto_set (
  195. const char *cipher_type,
  196. const char *hash_type)
  197. {
  198. return totemsrp_crypto_set (totemsrp_context,
  199. cipher_type,
  200. hash_type);
  201. }
  202. unsigned int totemmrp_my_nodeid_get (void)
  203. {
  204. return (totemsrp_my_nodeid_get (totemsrp_context));
  205. }
  206. int totemmrp_my_family_get (void)
  207. {
  208. return (totemsrp_my_family_get (totemsrp_context));
  209. }
  210. extern int totemmrp_ring_reenable (void)
  211. {
  212. int res;
  213. res = totemsrp_ring_reenable (
  214. totemsrp_context);
  215. return (res);
  216. }
  217. extern void totemmrp_service_ready_register (
  218. void (*totem_service_ready) (void))
  219. {
  220. totemsrp_service_ready_register (
  221. totemsrp_context,
  222. totem_service_ready);
  223. }
  224. int totemmrp_member_add (
  225. const struct totem_ip_address *member,
  226. int ring_no)
  227. {
  228. int res;
  229. res = totemsrp_member_add (totemsrp_context, member, ring_no);
  230. return (res);
  231. }
  232. int totemmrp_member_remove (
  233. const struct totem_ip_address *member,
  234. int ring_no)
  235. {
  236. int res;
  237. res = totemsrp_member_remove (totemsrp_context, member, ring_no);
  238. return (res);
  239. }
  240. void totemmrp_threaded_mode_enable (void)
  241. {
  242. totemsrp_threaded_mode_enable (totemsrp_context);
  243. }
  244. void totemmrp_trans_ack (void)
  245. {
  246. totemsrp_trans_ack (totemsrp_context);
  247. }