totemnet.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <totemiba.h>
  36. #include <totemudp.h>
  37. #include <totemnet.h>
  38. struct transport {
  39. const char *name;
  40. int (*initialize) (
  41. hdb_handle_t poll_handle,
  42. void **transport_instance,
  43. struct totem_config *totem_config,
  44. int interface_no,
  45. void *context,
  46. void (*deliver_fn) (
  47. void *context,
  48. const void *msg,
  49. unsigned int msg_len),
  50. void (*iface_change_fn) (
  51. void *context,
  52. const struct totem_ip_address *iface_address));
  53. int (*processor_count_set) (
  54. void *transport_context,
  55. int processor_count);
  56. int (*token_send) (
  57. void *transport_context,
  58. const void *msg,
  59. unsigned int msg_len);
  60. int (*mcast_flush_send) (
  61. void *transport_context,
  62. const void *msg,
  63. unsigned int msg_len);
  64. int (*mcast_noflush_send) (
  65. void *transport_context,
  66. const void *msg,
  67. unsigned int msg_len);
  68. int (*recv_flush) (void *transport_context);
  69. int (*send_flush) (void *transport_context);
  70. int (*iface_check) (void *transport_context);
  71. int (*finalize) (void *transport_context);
  72. void (*net_mtu_adjust) (void *transport_context, struct totem_config *totem_config);
  73. const char *(*iface_print) (void *transport_context);
  74. int (*iface_get) (
  75. void *transport_context,
  76. struct totem_ip_address *addr);
  77. int (*token_target_set) (
  78. void *transport_context,
  79. const struct totem_ip_address *token_target);
  80. int (*crypto_set) (
  81. void *transport_context,
  82. unsigned int type);
  83. int (*recv_mcast_empty) (
  84. void *transport_context);
  85. };
  86. struct transport transport_entries[] = {
  87. {
  88. .name = "UDP/IP",
  89. .initialize = totemudp_initialize,
  90. .processor_count_set = totemudp_processor_count_set,
  91. .token_send = totemudp_token_send,
  92. .mcast_flush_send = totemudp_mcast_flush_send,
  93. .mcast_noflush_send = totemudp_mcast_noflush_send,
  94. .recv_flush = totemudp_recv_flush,
  95. .send_flush = totemudp_send_flush,
  96. .iface_check = totemudp_iface_check,
  97. .finalize = totemudp_finalize,
  98. .net_mtu_adjust = totemudp_net_mtu_adjust,
  99. .iface_print = totemudp_iface_print,
  100. .iface_get = totemudp_iface_get,
  101. .token_target_set = totemudp_token_target_set,
  102. .crypto_set = totemudp_crypto_set,
  103. .recv_mcast_empty = totemudp_recv_mcast_empty
  104. },
  105. {
  106. .name = "Infiniband/IP",
  107. .initialize = totemiba_initialize,
  108. .processor_count_set = totemiba_processor_count_set,
  109. .token_send = totemiba_token_send,
  110. .mcast_flush_send = totemiba_mcast_flush_send,
  111. .mcast_noflush_send = totemiba_mcast_noflush_send,
  112. .recv_flush = totemiba_recv_flush,
  113. .send_flush = totemiba_send_flush,
  114. .iface_check = totemiba_iface_check,
  115. .finalize = totemiba_finalize,
  116. .net_mtu_adjust = totemiba_net_mtu_adjust,
  117. .iface_print = totemiba_iface_print,
  118. .iface_get = totemiba_iface_get,
  119. .token_target_set = totemiba_token_target_set,
  120. .crypto_set = totemiba_crypto_set,
  121. .recv_mcast_empty = totemiba_recv_mcast_empty
  122. }
  123. };
  124. struct totemnet_instance {
  125. void *transport_context;
  126. struct transport *transport;
  127. };
  128. static void totemnet_instance_initialize (struct totemnet_instance *instance)
  129. {
  130. instance->transport = &transport_entries[0];
  131. }
  132. int totemnet_crypto_set (
  133. void *net_context,
  134. unsigned int type)
  135. {
  136. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  137. int res = 0;
  138. res = instance->transport->crypto_set (instance->transport_context, type);
  139. return res;
  140. }
  141. int totemnet_finalize (
  142. void *net_context)
  143. {
  144. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  145. int res = 0;
  146. res = instance->transport->finalize (instance->transport_context);
  147. return (res);
  148. }
  149. int totemnet_initialize (
  150. hdb_handle_t poll_handle,
  151. void **net_context,
  152. struct totem_config *totem_config,
  153. int interface_no,
  154. void *context,
  155. void (*deliver_fn) (
  156. void *context,
  157. const void *msg,
  158. unsigned int msg_len),
  159. void (*iface_change_fn) (
  160. void *context,
  161. const struct totem_ip_address *iface_address))
  162. {
  163. struct totemnet_instance *instance;
  164. unsigned int res;
  165. instance = malloc (sizeof (struct totemnet_instance));
  166. if (instance == NULL) {
  167. return (-1);
  168. }
  169. totemnet_instance_initialize (instance);
  170. res = instance->transport->initialize (poll_handle,
  171. &instance->transport_context, totem_config,
  172. interface_no, context, deliver_fn, iface_change_fn);
  173. if (res == -1) {
  174. goto error_destroy;
  175. }
  176. *net_context = instance;
  177. return (0);
  178. error_destroy:
  179. free (instance);
  180. return (-1);
  181. }
  182. int totemnet_processor_count_set (
  183. void *net_context,
  184. int processor_count)
  185. {
  186. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  187. int res = 0;
  188. res = instance->transport->processor_count_set (instance->transport_context, processor_count);
  189. return (res);
  190. }
  191. int totemnet_recv_flush (void *net_context)
  192. {
  193. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  194. int res = 0;
  195. res = instance->transport->recv_flush (instance->transport_context);
  196. return (res);
  197. }
  198. int totemnet_send_flush (void *net_context)
  199. {
  200. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  201. int res = 0;
  202. res = instance->transport->send_flush (instance->transport_context);
  203. return (res);
  204. }
  205. int totemnet_token_send (
  206. void *net_context,
  207. const void *msg,
  208. unsigned int msg_len)
  209. {
  210. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  211. int res = 0;
  212. res = instance->transport->token_send (instance->transport_context, msg, msg_len);
  213. return (res);
  214. }
  215. int totemnet_mcast_flush_send (
  216. void *net_context,
  217. const void *msg,
  218. unsigned int msg_len)
  219. {
  220. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  221. int res = 0;
  222. res = instance->transport->mcast_flush_send (instance->transport_context, msg, msg_len);
  223. return (res);
  224. }
  225. int totemnet_mcast_noflush_send (
  226. void *net_context,
  227. const void *msg,
  228. unsigned int msg_len)
  229. {
  230. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  231. int res = 0;
  232. res = instance->transport->mcast_noflush_send (instance->transport_context, msg, msg_len);
  233. return (res);
  234. }
  235. extern int totemnet_iface_check (void *net_context)
  236. {
  237. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  238. int res = 0;
  239. res = instance->transport->iface_check (instance->transport_context);
  240. return (res);
  241. }
  242. extern int totemnet_net_mtu_adjust (void *net_context, struct totem_config *totem_config)
  243. {
  244. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  245. int res = 0;
  246. instance->transport->net_mtu_adjust (instance->transport_context, totem_config);
  247. return (res);
  248. }
  249. const char *totemnet_iface_print (void *net_context) {
  250. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  251. const char *ret_char;
  252. ret_char = instance->transport->iface_print (instance->transport_context);
  253. return (ret_char);
  254. }
  255. int totemnet_iface_get (
  256. void *net_context,
  257. struct totem_ip_address *addr)
  258. {
  259. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  260. unsigned int res;
  261. res = instance->transport->iface_get (instance->transport_context, addr);
  262. return (res);
  263. }
  264. int totemnet_token_target_set (
  265. void *net_context,
  266. const struct totem_ip_address *token_target)
  267. {
  268. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  269. unsigned int res;
  270. res = instance->transport->token_target_set (instance->transport_context, token_target);
  271. return (res);
  272. }
  273. extern int totemnet_recv_mcast_empty (
  274. void *net_context)
  275. {
  276. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  277. unsigned int res;
  278. res = instance->transport->recv_mcast_empty (instance->transport_context);
  279. return (res);
  280. }