totemnet.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. void (*target_set_completed) (
  54. void *context));
  55. int (*processor_count_set) (
  56. void *transport_context,
  57. int processor_count);
  58. int (*token_send) (
  59. void *transport_context,
  60. const void *msg,
  61. unsigned int msg_len);
  62. int (*mcast_flush_send) (
  63. void *transport_context,
  64. const void *msg,
  65. unsigned int msg_len);
  66. int (*mcast_noflush_send) (
  67. void *transport_context,
  68. const void *msg,
  69. unsigned int msg_len);
  70. int (*recv_flush) (void *transport_context);
  71. int (*send_flush) (void *transport_context);
  72. int (*iface_check) (void *transport_context);
  73. int (*finalize) (void *transport_context);
  74. void (*net_mtu_adjust) (void *transport_context, struct totem_config *totem_config);
  75. const char *(*iface_print) (void *transport_context);
  76. int (*iface_get) (
  77. void *transport_context,
  78. struct totem_ip_address *addr);
  79. int (*token_target_set) (
  80. void *transport_context,
  81. const struct totem_ip_address *token_target);
  82. int (*crypto_set) (
  83. void *transport_context,
  84. unsigned int type);
  85. int (*recv_mcast_empty) (
  86. void *transport_context);
  87. };
  88. struct transport transport_entries[] = {
  89. {
  90. .name = "UDP/IP",
  91. .initialize = totemudp_initialize,
  92. .processor_count_set = totemudp_processor_count_set,
  93. .token_send = totemudp_token_send,
  94. .mcast_flush_send = totemudp_mcast_flush_send,
  95. .mcast_noflush_send = totemudp_mcast_noflush_send,
  96. .recv_flush = totemudp_recv_flush,
  97. .send_flush = totemudp_send_flush,
  98. .iface_check = totemudp_iface_check,
  99. .finalize = totemudp_finalize,
  100. .net_mtu_adjust = totemudp_net_mtu_adjust,
  101. .iface_print = totemudp_iface_print,
  102. .iface_get = totemudp_iface_get,
  103. .token_target_set = totemudp_token_target_set,
  104. .crypto_set = totemudp_crypto_set,
  105. .recv_mcast_empty = totemudp_recv_mcast_empty
  106. },
  107. {
  108. .name = "Infiniband/IP",
  109. .initialize = totemiba_initialize,
  110. .processor_count_set = totemiba_processor_count_set,
  111. .token_send = totemiba_token_send,
  112. .mcast_flush_send = totemiba_mcast_flush_send,
  113. .mcast_noflush_send = totemiba_mcast_noflush_send,
  114. .recv_flush = totemiba_recv_flush,
  115. .send_flush = totemiba_send_flush,
  116. .iface_check = totemiba_iface_check,
  117. .finalize = totemiba_finalize,
  118. .net_mtu_adjust = totemiba_net_mtu_adjust,
  119. .iface_print = totemiba_iface_print,
  120. .iface_get = totemiba_iface_get,
  121. .token_target_set = totemiba_token_target_set,
  122. .crypto_set = totemiba_crypto_set,
  123. .recv_mcast_empty = totemiba_recv_mcast_empty
  124. }
  125. };
  126. struct totemnet_instance {
  127. void *transport_context;
  128. struct transport *transport;
  129. };
  130. static void totemnet_instance_initialize (struct totemnet_instance *instance)
  131. {
  132. instance->transport = &transport_entries[0];
  133. }
  134. int totemnet_crypto_set (
  135. void *net_context,
  136. unsigned int type)
  137. {
  138. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  139. int res = 0;
  140. res = instance->transport->crypto_set (instance->transport_context, type);
  141. return res;
  142. }
  143. int totemnet_finalize (
  144. void *net_context)
  145. {
  146. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  147. int res = 0;
  148. res = instance->transport->finalize (instance->transport_context);
  149. return (res);
  150. }
  151. int totemnet_initialize (
  152. hdb_handle_t poll_handle,
  153. void **net_context,
  154. struct totem_config *totem_config,
  155. int interface_no,
  156. void *context,
  157. void (*deliver_fn) (
  158. void *context,
  159. const void *msg,
  160. unsigned int msg_len),
  161. void (*iface_change_fn) (
  162. void *context,
  163. const struct totem_ip_address *iface_address),
  164. void (*target_set_completed) (
  165. void *context))
  166. {
  167. struct totemnet_instance *instance;
  168. unsigned int res;
  169. instance = malloc (sizeof (struct totemnet_instance));
  170. if (instance == NULL) {
  171. return (-1);
  172. }
  173. totemnet_instance_initialize (instance);
  174. res = instance->transport->initialize (poll_handle,
  175. &instance->transport_context, totem_config,
  176. interface_no, context, deliver_fn, iface_change_fn, target_set_completed);
  177. if (res == -1) {
  178. goto error_destroy;
  179. }
  180. *net_context = instance;
  181. return (0);
  182. error_destroy:
  183. free (instance);
  184. return (-1);
  185. }
  186. int totemnet_processor_count_set (
  187. void *net_context,
  188. int processor_count)
  189. {
  190. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  191. int res = 0;
  192. res = instance->transport->processor_count_set (instance->transport_context, processor_count);
  193. return (res);
  194. }
  195. int totemnet_recv_flush (void *net_context)
  196. {
  197. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  198. int res = 0;
  199. res = instance->transport->recv_flush (instance->transport_context);
  200. return (res);
  201. }
  202. int totemnet_send_flush (void *net_context)
  203. {
  204. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  205. int res = 0;
  206. res = instance->transport->send_flush (instance->transport_context);
  207. return (res);
  208. }
  209. int totemnet_token_send (
  210. void *net_context,
  211. const void *msg,
  212. unsigned int msg_len)
  213. {
  214. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  215. int res = 0;
  216. res = instance->transport->token_send (instance->transport_context, msg, msg_len);
  217. return (res);
  218. }
  219. int totemnet_mcast_flush_send (
  220. void *net_context,
  221. const void *msg,
  222. unsigned int msg_len)
  223. {
  224. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  225. int res = 0;
  226. res = instance->transport->mcast_flush_send (instance->transport_context, msg, msg_len);
  227. return (res);
  228. }
  229. int totemnet_mcast_noflush_send (
  230. void *net_context,
  231. const void *msg,
  232. unsigned int msg_len)
  233. {
  234. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  235. int res = 0;
  236. res = instance->transport->mcast_noflush_send (instance->transport_context, msg, msg_len);
  237. return (res);
  238. }
  239. extern int totemnet_iface_check (void *net_context)
  240. {
  241. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  242. int res = 0;
  243. res = instance->transport->iface_check (instance->transport_context);
  244. return (res);
  245. }
  246. extern int totemnet_net_mtu_adjust (void *net_context, struct totem_config *totem_config)
  247. {
  248. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  249. int res = 0;
  250. instance->transport->net_mtu_adjust (instance->transport_context, totem_config);
  251. return (res);
  252. }
  253. const char *totemnet_iface_print (void *net_context) {
  254. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  255. const char *ret_char;
  256. ret_char = instance->transport->iface_print (instance->transport_context);
  257. return (ret_char);
  258. }
  259. int totemnet_iface_get (
  260. void *net_context,
  261. struct totem_ip_address *addr)
  262. {
  263. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  264. unsigned int res;
  265. res = instance->transport->iface_get (instance->transport_context, addr);
  266. return (res);
  267. }
  268. int totemnet_token_target_set (
  269. void *net_context,
  270. const struct totem_ip_address *token_target)
  271. {
  272. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  273. unsigned int res;
  274. res = instance->transport->token_target_set (instance->transport_context, token_target);
  275. return (res);
  276. }
  277. extern int totemnet_recv_mcast_empty (
  278. void *net_context)
  279. {
  280. struct totemnet_instance *instance = (struct totemnet_instance *)net_context;
  281. unsigned int res;
  282. res = instance->transport->recv_mcast_empty (instance->transport_context);
  283. return (res);
  284. }