totemnet.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. hdb_handle_t *handle,
  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. hdb_handle_t handle,
  55. int processor_count);
  56. int (*token_send) (
  57. hdb_handle_t handle,
  58. const void *msg,
  59. unsigned int msg_len);
  60. int (*mcast_flush_send) (
  61. hdb_handle_t handle,
  62. const void *msg,
  63. unsigned int msg_len);
  64. int (*mcast_noflush_send) (
  65. hdb_handle_t handle,
  66. const void *msg,
  67. unsigned int msg_len);
  68. int (*recv_flush) (hdb_handle_t handle);
  69. int (*send_flush) (hdb_handle_t handle);
  70. int (*iface_check) (hdb_handle_t handle);
  71. int (*finalize) (hdb_handle_t handle);
  72. void (*net_mtu_adjust) (hdb_handle_t handle, struct totem_config *totem_config);
  73. const char *(*iface_print) (hdb_handle_t handle);
  74. int (*iface_get) (
  75. hdb_handle_t handle,
  76. struct totem_ip_address *addr);
  77. int (*token_target_set) (
  78. hdb_handle_t handle,
  79. const struct totem_ip_address *token_target);
  80. int (*crypto_set) (
  81. hdb_handle_t handle,
  82. unsigned int type);
  83. int (*recv_mcast_empty) (
  84. hdb_handle_t handle);
  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. hdb_handle_t transport_handle;
  126. struct transport *transport;
  127. };
  128. DECLARE_HDB_DATABASE (totemnet_instance_database,NULL);
  129. static void totemnet_instance_initialize (struct totemnet_instance *instance)
  130. {
  131. instance->transport = &transport_entries[0];
  132. }
  133. int totemnet_crypto_set (hdb_handle_t handle,
  134. unsigned int type)
  135. {
  136. struct totemnet_instance *instance;
  137. int res = 0;
  138. res = hdb_handle_get (&totemnet_instance_database, handle,
  139. (void *)&instance);
  140. if (res != 0) {
  141. res = ENOENT;
  142. goto error_exit;
  143. }
  144. res = instance->transport->crypto_set (instance->transport_handle, type);
  145. hdb_handle_put (&totemnet_instance_database, handle);
  146. error_exit:
  147. return res;
  148. }
  149. int totemnet_finalize (
  150. hdb_handle_t handle)
  151. {
  152. struct totemnet_instance *instance;
  153. int res = 0;
  154. res = hdb_handle_get (&totemnet_instance_database, handle,
  155. (void *)&instance);
  156. if (res != 0) {
  157. res = ENOENT;
  158. goto error_exit;
  159. }
  160. res = instance->transport->finalize (instance->transport_handle);
  161. hdb_handle_put (&totemnet_instance_database, handle);
  162. error_exit:
  163. return (res);
  164. }
  165. int totemnet_initialize (
  166. hdb_handle_t poll_handle,
  167. hdb_handle_t *handle,
  168. struct totem_config *totem_config,
  169. int interface_no,
  170. void *context,
  171. void (*deliver_fn) (
  172. void *context,
  173. const void *msg,
  174. unsigned int msg_len),
  175. void (*iface_change_fn) (
  176. void *context,
  177. const struct totem_ip_address *iface_address))
  178. {
  179. struct totemnet_instance *instance;
  180. unsigned int res;
  181. res = hdb_handle_create (&totemnet_instance_database,
  182. sizeof (struct totemnet_instance), handle);
  183. if (res != 0) {
  184. goto error_exit;
  185. }
  186. res = hdb_handle_get (&totemnet_instance_database, *handle,
  187. (void *)&instance);
  188. if (res != 0) {
  189. goto error_destroy;
  190. }
  191. totemnet_instance_initialize (instance);
  192. res = instance->transport->initialize (poll_handle, &instance->transport_handle, totem_config,
  193. interface_no, context, deliver_fn, iface_change_fn);
  194. error_exit:
  195. hdb_handle_put (&totemnet_instance_database, *handle);
  196. return (0);
  197. error_destroy:
  198. hdb_handle_destroy (&totemnet_instance_database, *handle);
  199. return (-1);
  200. }
  201. int totemnet_processor_count_set (
  202. hdb_handle_t handle,
  203. int processor_count)
  204. {
  205. struct totemnet_instance *instance;
  206. int res = 0;
  207. res = hdb_handle_get (&totemnet_instance_database, handle,
  208. (void *)&instance);
  209. if (res != 0) {
  210. res = ENOENT;
  211. goto error_exit;
  212. }
  213. res = instance->transport->processor_count_set (handle, processor_count);
  214. hdb_handle_put (&totemnet_instance_database, instance->transport_handle);
  215. error_exit:
  216. return (res);
  217. }
  218. int totemnet_recv_flush (hdb_handle_t handle)
  219. {
  220. struct totemnet_instance *instance;
  221. int res = 0;
  222. res = hdb_handle_get (&totemnet_instance_database, handle,
  223. (void *)&instance);
  224. if (res != 0) {
  225. res = ENOENT;
  226. goto error_exit;
  227. }
  228. res = instance->transport->recv_flush (instance->transport_handle);
  229. hdb_handle_put (&totemnet_instance_database, handle);
  230. error_exit:
  231. return (res);
  232. }
  233. int totemnet_send_flush (hdb_handle_t handle)
  234. {
  235. struct totemnet_instance *instance;
  236. int res = 0;
  237. res = hdb_handle_get (&totemnet_instance_database, handle,
  238. (void *)&instance);
  239. if (res != 0) {
  240. res = ENOENT;
  241. goto error_exit;
  242. }
  243. res = instance->transport->send_flush (instance->transport_handle);
  244. hdb_handle_put (&totemnet_instance_database, handle);
  245. error_exit:
  246. return (res);
  247. }
  248. int totemnet_token_send (
  249. hdb_handle_t handle,
  250. const void *msg,
  251. unsigned int msg_len)
  252. {
  253. struct totemnet_instance *instance;
  254. int res = 0;
  255. res = hdb_handle_get (&totemnet_instance_database, handle,
  256. (void *)&instance);
  257. if (res != 0) {
  258. res = ENOENT;
  259. goto error_exit;
  260. }
  261. res = instance->transport->token_send (instance->transport_handle, msg, msg_len);
  262. hdb_handle_put (&totemnet_instance_database, handle);
  263. error_exit:
  264. return (res);
  265. }
  266. int totemnet_mcast_flush_send (
  267. hdb_handle_t handle,
  268. const void *msg,
  269. unsigned int msg_len)
  270. {
  271. struct totemnet_instance *instance;
  272. int res = 0;
  273. res = hdb_handle_get (&totemnet_instance_database, handle,
  274. (void *)&instance);
  275. if (res != 0) {
  276. res = ENOENT;
  277. goto error_exit;
  278. }
  279. res = instance->transport->mcast_flush_send (instance->transport_handle, msg, msg_len);
  280. hdb_handle_put (&totemnet_instance_database, handle);
  281. error_exit:
  282. return (res);
  283. }
  284. int totemnet_mcast_noflush_send (
  285. hdb_handle_t handle,
  286. const void *msg,
  287. unsigned int msg_len)
  288. {
  289. struct totemnet_instance *instance;
  290. int res = 0;
  291. res = hdb_handle_get (&totemnet_instance_database, handle,
  292. (void *)&instance);
  293. if (res != 0) {
  294. res = ENOENT;
  295. goto error_exit;
  296. }
  297. res = instance->transport->mcast_noflush_send (instance->transport_handle, msg, msg_len);
  298. hdb_handle_put (&totemnet_instance_database, handle);
  299. error_exit:
  300. return (res);
  301. }
  302. extern int totemnet_iface_check (hdb_handle_t handle)
  303. {
  304. struct totemnet_instance *instance;
  305. int res = 0;
  306. res = hdb_handle_get (&totemnet_instance_database, handle,
  307. (void *)&instance);
  308. if (res != 0) {
  309. res = ENOENT;
  310. goto error_exit;
  311. }
  312. res = instance->transport->iface_check (instance->transport_handle);
  313. hdb_handle_put (&totemnet_instance_database, handle);
  314. error_exit:
  315. return (res);
  316. }
  317. extern int totemnet_net_mtu_adjust (hdb_handle_t handle, struct totem_config *totem_config)
  318. {
  319. struct totemnet_instance *instance;
  320. int res = 0;
  321. res = hdb_handle_get (&totemnet_instance_database, handle,
  322. (void *)&instance);
  323. if (res != 0) {
  324. res = ENOENT;
  325. goto error_exit;
  326. }
  327. instance->transport->net_mtu_adjust (instance->transport_handle, totem_config);
  328. hdb_handle_put (&totemnet_instance_database, handle);
  329. error_exit:
  330. return (res);
  331. }
  332. const char *totemnet_iface_print (hdb_handle_t handle) {
  333. struct totemnet_instance *instance;
  334. int res = 0;
  335. const char *ret_char;
  336. res = hdb_handle_get (&totemnet_instance_database, handle,
  337. (void *)&instance);
  338. if (res != 0) {
  339. ret_char = "Invalid totemnet handle";
  340. goto error_exit;
  341. }
  342. ret_char = instance->transport->iface_print (instance->transport_handle);
  343. hdb_handle_put (&totemnet_instance_database, handle);
  344. error_exit:
  345. return (ret_char);
  346. }
  347. int totemnet_iface_get (
  348. hdb_handle_t handle,
  349. struct totem_ip_address *addr)
  350. {
  351. struct totemnet_instance *instance;
  352. unsigned int res;
  353. res = hdb_handle_get (&totemnet_instance_database, handle,
  354. (void *)&instance);
  355. if (res != 0) {
  356. goto error_exit;
  357. }
  358. res = instance->transport->iface_get (instance->transport_handle, addr);
  359. hdb_handle_put (&totemnet_instance_database, handle);
  360. error_exit:
  361. return (res);
  362. }
  363. int totemnet_token_target_set (
  364. hdb_handle_t handle,
  365. const struct totem_ip_address *token_target)
  366. {
  367. struct totemnet_instance *instance;
  368. unsigned int res;
  369. res = hdb_handle_get (&totemnet_instance_database, handle,
  370. (void *)&instance);
  371. if (res != 0) {
  372. goto error_exit;
  373. }
  374. res = instance->transport->token_target_set (instance->transport_handle, token_target);
  375. hdb_handle_put (&totemnet_instance_database, handle);
  376. error_exit:
  377. return (res);
  378. }
  379. extern int totemnet_recv_mcast_empty (
  380. hdb_handle_t handle)
  381. {
  382. struct totemnet_instance *instance;
  383. unsigned int res = 0;
  384. res = hdb_handle_get (&totemnet_instance_database, handle,
  385. (void *)&instance);
  386. if (res != 0) {
  387. goto error_exit;
  388. }
  389. res = instance->transport->recv_mcast_empty (instance->transport_handle);
  390. hdb_handle_put (&totemnet_instance_database, handle);
  391. error_exit:
  392. return (res);
  393. }