cpg.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2006-2009 Red Hat, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Christine Caulfield (ccaulfi@redhat.com)
  9. * Author: Jan Friesse (jfriesse@redhat.com)
  10. *
  11. * This software licensed under BSD license, the text of which follows:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * - Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  22. * contributors may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. * THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /*
  38. * Provides a closed process group API using the coroipcc executive
  39. */
  40. #include <config.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <unistd.h>
  44. #include <sys/types.h>
  45. #include <sys/socket.h>
  46. #include <errno.h>
  47. #include <corosync/corotypes.h>
  48. #include <corosync/coroipc_types.h>
  49. #include <corosync/coroipcc.h>
  50. #include <corosync/corodefs.h>
  51. #include <corosync/hdb.h>
  52. #include <corosync/list.h>
  53. #include <corosync/cpg.h>
  54. #include <corosync/ipc_cpg.h>
  55. #include "util.h"
  56. struct cpg_inst {
  57. hdb_handle_t handle;
  58. int finalize;
  59. cpg_callbacks_t callbacks;
  60. void *context;
  61. struct list_head iteration_list_head;
  62. };
  63. DECLARE_HDB_DATABASE(cpg_handle_t_db,NULL);
  64. struct cpg_iteration_instance_t {
  65. cpg_iteration_handle_t cpg_iteration_handle;
  66. hdb_handle_t conn_handle;
  67. hdb_handle_t executive_iteration_handle;
  68. struct list_head list;
  69. };
  70. DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
  71. /*
  72. * Internal (not visible by API) functions
  73. */
  74. static void cpg_iteration_instance_finalize (struct cpg_iteration_instance_t *cpg_iteration_instance)
  75. {
  76. list_del (&cpg_iteration_instance->list);
  77. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->cpg_iteration_handle);
  78. }
  79. static void cpg_inst_finalize (struct cpg_inst *cpg_inst, hdb_handle_t handle)
  80. {
  81. struct list_head *iter, *iter_next;
  82. struct cpg_iteration_instance_t *cpg_iteration_instance;
  83. /*
  84. * Traverse thru iteration instances and delete them
  85. */
  86. for (iter = cpg_inst->iteration_list_head.next; iter != &cpg_inst->iteration_list_head;iter = iter_next) {
  87. iter_next = iter->next;
  88. cpg_iteration_instance = list_entry (iter, struct cpg_iteration_instance_t, list);
  89. cpg_iteration_instance_finalize (cpg_iteration_instance);
  90. }
  91. hdb_handle_destroy (&cpg_handle_t_db, handle);
  92. }
  93. /**
  94. * @defgroup cpg_coroipcc The closed process group API
  95. * @ingroup coroipcc
  96. *
  97. * @{
  98. */
  99. cs_error_t cpg_initialize (
  100. cpg_handle_t *handle,
  101. cpg_callbacks_t *callbacks)
  102. {
  103. cs_error_t error;
  104. struct cpg_inst *cpg_inst;
  105. error = hdb_error_to_cs (hdb_handle_create (&cpg_handle_t_db, sizeof (struct cpg_inst), handle));
  106. if (error != CS_OK) {
  107. goto error_no_destroy;
  108. }
  109. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, *handle, (void *)&cpg_inst));
  110. if (error != CS_OK) {
  111. goto error_destroy;
  112. }
  113. error = coroipcc_service_connect (
  114. COROSYNC_SOCKET_NAME,
  115. CPG_SERVICE,
  116. IPC_REQUEST_SIZE,
  117. IPC_RESPONSE_SIZE,
  118. IPC_DISPATCH_SIZE,
  119. &cpg_inst->handle);
  120. if (error != CS_OK) {
  121. goto error_put_destroy;
  122. }
  123. if (callbacks) {
  124. memcpy (&cpg_inst->callbacks, callbacks, sizeof (cpg_callbacks_t));
  125. }
  126. list_init(&cpg_inst->iteration_list_head);
  127. hdb_handle_put (&cpg_handle_t_db, *handle);
  128. return (CS_OK);
  129. error_put_destroy:
  130. hdb_handle_put (&cpg_handle_t_db, *handle);
  131. error_destroy:
  132. hdb_handle_destroy (&cpg_handle_t_db, *handle);
  133. error_no_destroy:
  134. return (error);
  135. }
  136. cs_error_t cpg_finalize (
  137. cpg_handle_t handle)
  138. {
  139. struct cpg_inst *cpg_inst;
  140. cs_error_t error;
  141. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  142. if (error != CS_OK) {
  143. return (error);
  144. }
  145. /*
  146. * Another thread has already started finalizing
  147. */
  148. if (cpg_inst->finalize) {
  149. hdb_handle_put (&cpg_handle_t_db, handle);
  150. return (CPG_ERR_BAD_HANDLE);
  151. }
  152. cpg_inst->finalize = 1;
  153. coroipcc_service_disconnect (cpg_inst->handle);
  154. cpg_inst_finalize (cpg_inst, handle);
  155. hdb_handle_put (&cpg_handle_t_db, handle);
  156. return (CPG_OK);
  157. }
  158. cs_error_t cpg_fd_get (
  159. cpg_handle_t handle,
  160. int *fd)
  161. {
  162. cs_error_t error;
  163. struct cpg_inst *cpg_inst;
  164. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  165. if (error != CS_OK) {
  166. return (error);
  167. }
  168. error = coroipcc_fd_get (cpg_inst->handle, fd);
  169. hdb_handle_put (&cpg_handle_t_db, handle);
  170. return (error);
  171. }
  172. cs_error_t cpg_context_get (
  173. cpg_handle_t handle,
  174. void **context)
  175. {
  176. cs_error_t error;
  177. struct cpg_inst *cpg_inst;
  178. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  179. if (error != CS_OK) {
  180. return (error);
  181. }
  182. *context = cpg_inst->context;
  183. hdb_handle_put (&cpg_handle_t_db, handle);
  184. return (CS_OK);
  185. }
  186. cs_error_t cpg_context_set (
  187. cpg_handle_t handle,
  188. void *context)
  189. {
  190. cs_error_t error;
  191. struct cpg_inst *cpg_inst;
  192. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  193. if (error != CS_OK) {
  194. return (error);
  195. }
  196. cpg_inst->context = context;
  197. hdb_handle_put (&cpg_handle_t_db, handle);
  198. return (CS_OK);
  199. }
  200. cs_error_t cpg_dispatch (
  201. cpg_handle_t handle,
  202. cs_dispatch_flags_t dispatch_types)
  203. {
  204. int timeout = -1;
  205. cs_error_t error;
  206. int cont = 1; /* always continue do loop except when set to 0 */
  207. struct cpg_inst *cpg_inst;
  208. struct res_lib_cpg_confchg_callback *res_cpg_confchg_callback;
  209. struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback;
  210. cpg_callbacks_t callbacks;
  211. coroipc_response_header_t *dispatch_data;
  212. struct cpg_address member_list[CPG_MEMBERS_MAX];
  213. struct cpg_address left_list[CPG_MEMBERS_MAX];
  214. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  215. struct cpg_name group_name;
  216. mar_cpg_address_t *left_list_start;
  217. mar_cpg_address_t *joined_list_start;
  218. unsigned int i;
  219. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  220. if (error != CS_OK) {
  221. return (error);
  222. }
  223. /*
  224. * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
  225. * wait indefinately for CS_DISPATCH_BLOCKING
  226. */
  227. if (dispatch_types == CPG_DISPATCH_ALL) {
  228. timeout = 0;
  229. }
  230. do {
  231. error = coroipcc_dispatch_get (
  232. cpg_inst->handle,
  233. (void **)&dispatch_data,
  234. timeout);
  235. if (error == CS_ERR_BAD_HANDLE) {
  236. error = CS_OK;
  237. goto error_put;
  238. }
  239. if (error == CS_ERR_TRY_AGAIN) {
  240. error = CS_OK;
  241. if (dispatch_types == CPG_DISPATCH_ALL) {
  242. break; /* exit do while cont is 1 loop */
  243. } else {
  244. continue; /* next poll */
  245. }
  246. }
  247. if (error != CS_OK) {
  248. goto error_put;
  249. }
  250. /*
  251. * Make copy of callbacks, message data, unlock instance, and call callback
  252. * A risk of this dispatch method is that the callback routines may
  253. * operate at the same time that cpgFinalize has been called.
  254. */
  255. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  256. /*
  257. * Dispatch incoming message
  258. */
  259. switch (dispatch_data->id) {
  260. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  261. if (callbacks.cpg_deliver_fn == NULL) {
  262. continue;
  263. }
  264. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  265. marshall_from_mar_cpg_name_t (
  266. &group_name,
  267. &res_cpg_deliver_callback->group_name);
  268. callbacks.cpg_deliver_fn (handle,
  269. &group_name,
  270. res_cpg_deliver_callback->nodeid,
  271. res_cpg_deliver_callback->pid,
  272. &res_cpg_deliver_callback->message,
  273. res_cpg_deliver_callback->msglen);
  274. break;
  275. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  276. if (callbacks.cpg_confchg_fn == NULL) {
  277. continue;
  278. }
  279. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  280. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  281. marshall_from_mar_cpg_address_t (&member_list[i],
  282. &res_cpg_confchg_callback->member_list[i]);
  283. }
  284. left_list_start = res_cpg_confchg_callback->member_list +
  285. res_cpg_confchg_callback->member_list_entries;
  286. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  287. marshall_from_mar_cpg_address_t (&left_list[i],
  288. &left_list_start[i]);
  289. }
  290. joined_list_start = res_cpg_confchg_callback->member_list +
  291. res_cpg_confchg_callback->member_list_entries +
  292. res_cpg_confchg_callback->left_list_entries;
  293. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  294. marshall_from_mar_cpg_address_t (&joined_list[i],
  295. &joined_list_start[i]);
  296. }
  297. marshall_from_mar_cpg_name_t (
  298. &group_name,
  299. &res_cpg_confchg_callback->group_name);
  300. callbacks.cpg_confchg_fn (handle,
  301. &group_name,
  302. member_list,
  303. res_cpg_confchg_callback->member_list_entries,
  304. left_list,
  305. res_cpg_confchg_callback->left_list_entries,
  306. joined_list,
  307. res_cpg_confchg_callback->joined_list_entries);
  308. break;
  309. default:
  310. coroipcc_dispatch_put (cpg_inst->handle);
  311. error = CS_ERR_LIBRARY;
  312. goto error_put;
  313. break;
  314. }
  315. coroipcc_dispatch_put (cpg_inst->handle);
  316. /*
  317. * Determine if more messages should be processed
  318. */
  319. if (dispatch_types == CS_DISPATCH_ONE) {
  320. cont = 0;
  321. }
  322. } while (cont);
  323. error_put:
  324. hdb_handle_put (&cpg_handle_t_db, handle);
  325. return (error);
  326. }
  327. cs_error_t cpg_join (
  328. cpg_handle_t handle,
  329. const struct cpg_name *group)
  330. {
  331. cs_error_t error;
  332. struct cpg_inst *cpg_inst;
  333. struct iovec iov[2];
  334. struct req_lib_cpg_join req_lib_cpg_join;
  335. struct res_lib_cpg_join res_lib_cpg_join;
  336. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  337. if (error != CS_OK) {
  338. return (error);
  339. }
  340. /* Now join */
  341. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  342. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  343. req_lib_cpg_join.pid = getpid();
  344. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  345. group);
  346. iov[0].iov_base = (void *)&req_lib_cpg_join;
  347. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  348. do {
  349. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  350. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  351. if (error != CS_OK) {
  352. goto error_exit;
  353. }
  354. } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY);
  355. error = res_lib_cpg_join.header.error;
  356. error_exit:
  357. hdb_handle_put (&cpg_handle_t_db, handle);
  358. return (error);
  359. }
  360. cs_error_t cpg_leave (
  361. cpg_handle_t handle,
  362. const struct cpg_name *group)
  363. {
  364. cs_error_t error;
  365. struct cpg_inst *cpg_inst;
  366. struct iovec iov[2];
  367. struct req_lib_cpg_leave req_lib_cpg_leave;
  368. struct res_lib_cpg_leave res_lib_cpg_leave;
  369. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  370. if (error != CS_OK) {
  371. return (error);
  372. }
  373. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  374. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  375. req_lib_cpg_leave.pid = getpid();
  376. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  377. group);
  378. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  379. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  380. do {
  381. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  382. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  383. if (error != CS_OK) {
  384. goto error_exit;
  385. }
  386. } while (res_lib_cpg_leave.header.error == CPG_ERR_BUSY);
  387. error = res_lib_cpg_leave.header.error;
  388. error_exit:
  389. hdb_handle_put (&cpg_handle_t_db, handle);
  390. return (error);
  391. }
  392. cs_error_t cpg_membership_get (
  393. cpg_handle_t handle,
  394. struct cpg_name *group_name,
  395. struct cpg_address *member_list,
  396. int *member_list_entries)
  397. {
  398. cs_error_t error;
  399. struct cpg_inst *cpg_inst;
  400. struct iovec iov;
  401. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  402. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  403. unsigned int i;
  404. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  405. if (error != CS_OK) {
  406. return (error);
  407. }
  408. req_lib_cpg_membership_get.header.size = sizeof (coroipc_request_header_t);
  409. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  410. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  411. iov.iov_len = sizeof (coroipc_request_header_t);
  412. do {
  413. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  414. &res_lib_cpg_membership_get, sizeof (coroipc_response_header_t));
  415. if (error != CS_OK) {
  416. goto error_exit;
  417. }
  418. } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY);
  419. error = res_lib_cpg_membership_get.header.error;
  420. /*
  421. * Copy results to caller
  422. */
  423. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  424. if (member_list) {
  425. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  426. marshall_from_mar_cpg_address_t (&member_list[i],
  427. &res_lib_cpg_membership_get.member_list[i]);
  428. }
  429. }
  430. error_exit:
  431. hdb_handle_put (&cpg_handle_t_db, handle);
  432. return (error);
  433. }
  434. cs_error_t cpg_local_get (
  435. cpg_handle_t handle,
  436. unsigned int *local_nodeid)
  437. {
  438. cs_error_t error;
  439. struct cpg_inst *cpg_inst;
  440. struct iovec iov;
  441. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  442. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  443. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  444. if (error != CS_OK) {
  445. return (error);
  446. }
  447. req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t);
  448. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  449. iov.iov_base = (void *)&req_lib_cpg_local_get;
  450. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  451. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  452. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  453. if (error != CS_OK) {
  454. goto error_exit;
  455. }
  456. error = res_lib_cpg_local_get.header.error;
  457. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  458. error_exit:
  459. hdb_handle_put (&cpg_handle_t_db, handle);
  460. return (error);
  461. }
  462. cs_error_t cpg_flow_control_state_get (
  463. cpg_handle_t handle,
  464. cpg_flow_control_state_t *flow_control_state)
  465. {
  466. cs_error_t error;
  467. struct cpg_inst *cpg_inst;
  468. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  469. if (error != CS_OK) {
  470. return (error);
  471. }
  472. error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state);
  473. hdb_handle_put (&cpg_handle_t_db, handle);
  474. return (error);
  475. }
  476. cs_error_t cpg_zcb_alloc (
  477. cpg_handle_t handle,
  478. size_t size,
  479. void **buffer)
  480. {
  481. cs_error_t error;
  482. struct cpg_inst *cpg_inst;
  483. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  484. if (error != CS_OK) {
  485. return (error);
  486. }
  487. error = coroipcc_zcb_alloc (cpg_inst->handle,
  488. buffer,
  489. size,
  490. sizeof (struct req_lib_cpg_mcast));
  491. hdb_handle_put (&cpg_handle_t_db, handle);
  492. *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast);
  493. return (error);
  494. }
  495. cs_error_t cpg_zcb_free (
  496. cpg_handle_t handle,
  497. void *buffer)
  498. {
  499. cs_error_t error;
  500. struct cpg_inst *cpg_inst;
  501. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  502. if (error != CS_OK) {
  503. return (error);
  504. }
  505. coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast));
  506. hdb_handle_put (&cpg_handle_t_db, handle);
  507. return (error);
  508. }
  509. cs_error_t cpg_zcb_mcast_joined (
  510. cpg_handle_t handle,
  511. cpg_guarantee_t guarantee,
  512. void *msg,
  513. size_t msg_len)
  514. {
  515. cs_error_t error;
  516. struct cpg_inst *cpg_inst;
  517. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  518. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  519. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  520. if (error != CS_OK) {
  521. return (error);
  522. }
  523. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast));
  524. req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) +
  525. msg_len;
  526. req_lib_cpg_mcast->header.id = MESSAGE_REQ_CPG_MCAST;
  527. req_lib_cpg_mcast->guarantee = guarantee;
  528. req_lib_cpg_mcast->msglen = msg_len;
  529. error = coroipcc_zcb_msg_send_reply_receive (
  530. cpg_inst->handle,
  531. req_lib_cpg_mcast,
  532. &res_lib_cpg_mcast,
  533. sizeof (res_lib_cpg_mcast));
  534. if (error != CS_OK) {
  535. goto error_exit;
  536. }
  537. error = res_lib_cpg_mcast.header.error;
  538. error_exit:
  539. hdb_handle_put (&cpg_handle_t_db, handle);
  540. return (error);
  541. }
  542. cs_error_t cpg_mcast_joined (
  543. cpg_handle_t handle,
  544. cpg_guarantee_t guarantee,
  545. const struct iovec *iovec,
  546. unsigned int iov_len)
  547. {
  548. int i;
  549. cs_error_t error;
  550. struct cpg_inst *cpg_inst;
  551. struct iovec iov[64];
  552. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  553. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  554. size_t msg_len = 0;
  555. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  556. if (error != CS_OK) {
  557. return (error);
  558. }
  559. for (i = 0; i < iov_len; i++ ) {
  560. msg_len += iovec[i].iov_len;
  561. }
  562. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  563. msg_len;
  564. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  565. req_lib_cpg_mcast.guarantee = guarantee;
  566. req_lib_cpg_mcast.msglen = msg_len;
  567. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  568. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  569. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  570. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov,
  571. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  572. if (error != CS_OK) {
  573. goto error_exit;
  574. }
  575. error = res_lib_cpg_mcast.header.error;
  576. error_exit:
  577. hdb_handle_put (&cpg_handle_t_db, handle);
  578. return (error);
  579. }
  580. cs_error_t cpg_iteration_initialize(
  581. cpg_handle_t handle,
  582. cpg_iteration_type_t iteration_type,
  583. const struct cpg_name *group,
  584. cpg_iteration_handle_t *cpg_iteration_handle)
  585. {
  586. cs_error_t error;
  587. struct iovec iov;
  588. struct cpg_inst *cpg_inst;
  589. struct cpg_iteration_instance_t *cpg_iteration_instance;
  590. struct req_lib_cpg_iterationinitialize req_lib_cpg_iterationinitialize;
  591. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  592. if (cpg_iteration_handle == NULL) {
  593. return (CS_ERR_INVALID_PARAM);
  594. }
  595. if ((iteration_type == CPG_ITERATION_ONE_GROUP && group == NULL) ||
  596. (iteration_type != CPG_ITERATION_ONE_GROUP && group != NULL)) {
  597. return (CS_ERR_INVALID_PARAM);
  598. }
  599. if (iteration_type != CPG_ITERATION_NAME_ONLY && iteration_type != CPG_ITERATION_ONE_GROUP &&
  600. iteration_type != CPG_ITERATION_ALL) {
  601. return (CS_ERR_INVALID_PARAM);
  602. }
  603. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  604. if (error != CS_OK) {
  605. return (error);
  606. }
  607. error = hdb_error_to_cs (hdb_handle_create (&cpg_iteration_handle_t_db,
  608. sizeof (struct cpg_iteration_instance_t), cpg_iteration_handle));
  609. if (error != CS_OK) {
  610. goto error_put_cpg_db;
  611. }
  612. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, *cpg_iteration_handle,
  613. (void *)&cpg_iteration_instance));
  614. if (error != CS_OK) {
  615. goto error_destroy;
  616. }
  617. cpg_iteration_instance->conn_handle = cpg_inst->handle;
  618. list_init (&cpg_iteration_instance->list);
  619. req_lib_cpg_iterationinitialize.header.size = sizeof (struct req_lib_cpg_iterationinitialize);
  620. req_lib_cpg_iterationinitialize.header.id = MESSAGE_REQ_CPG_ITERATIONINITIALIZE;
  621. req_lib_cpg_iterationinitialize.iteration_type = iteration_type;
  622. if (group) {
  623. marshall_to_mar_cpg_name_t (&req_lib_cpg_iterationinitialize.group_name, group);
  624. }
  625. iov.iov_base = (void *)&req_lib_cpg_iterationinitialize;
  626. iov.iov_len = sizeof (struct req_lib_cpg_iterationinitialize);
  627. error = coroipcc_msg_send_reply_receive (cpg_inst->handle,
  628. &iov,
  629. 1,
  630. &res_lib_cpg_iterationinitialize,
  631. sizeof (struct res_lib_cpg_iterationinitialize));
  632. if (error != CS_OK) {
  633. goto error_put_destroy;
  634. }
  635. cpg_iteration_instance->executive_iteration_handle =
  636. res_lib_cpg_iterationinitialize.iteration_handle;
  637. cpg_iteration_instance->cpg_iteration_handle = *cpg_iteration_handle;
  638. list_add (&cpg_iteration_instance->list, &cpg_inst->iteration_list_head);
  639. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  640. hdb_handle_put (&cpg_handle_t_db, handle);
  641. return (res_lib_cpg_iterationinitialize.header.error);
  642. error_put_destroy:
  643. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  644. error_destroy:
  645. hdb_handle_destroy (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  646. error_put_cpg_db:
  647. hdb_handle_put (&cpg_handle_t_db, handle);
  648. return (error);
  649. }
  650. cs_error_t cpg_iteration_next(
  651. cpg_iteration_handle_t handle,
  652. struct cpg_iteration_description_t *description)
  653. {
  654. cs_error_t error;
  655. struct cpg_iteration_instance_t *cpg_iteration_instance;
  656. struct req_lib_cpg_iterationnext req_lib_cpg_iterationnext;
  657. struct res_lib_cpg_iterationnext *res_lib_cpg_iterationnext;
  658. struct iovec iov;
  659. void *return_address;
  660. if (description == NULL) {
  661. return CS_ERR_INVALID_PARAM;
  662. }
  663. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  664. (void *)&cpg_iteration_instance));
  665. if (error != CS_OK) {
  666. goto error_exit;
  667. }
  668. req_lib_cpg_iterationnext.header.size = sizeof (struct req_lib_cpg_iterationnext);
  669. req_lib_cpg_iterationnext.header.id = MESSAGE_REQ_CPG_ITERATIONNEXT;
  670. req_lib_cpg_iterationnext.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  671. iov.iov_base = (void *)&req_lib_cpg_iterationnext;
  672. iov.iov_len = sizeof (struct req_lib_cpg_iterationnext);
  673. error = coroipcc_msg_send_reply_receive_in_buf_get (cpg_iteration_instance->conn_handle,
  674. &iov,
  675. 1,
  676. &return_address);
  677. res_lib_cpg_iterationnext = return_address;
  678. if (error != CS_OK) {
  679. goto error_put;
  680. }
  681. marshall_from_mar_cpg_iteration_description_t(
  682. description,
  683. &res_lib_cpg_iterationnext->description);
  684. error = res_lib_cpg_iterationnext->header.error;
  685. coroipcc_msg_send_reply_receive_in_buf_put(
  686. cpg_iteration_instance->conn_handle);
  687. error_put:
  688. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  689. error_exit:
  690. return (error);
  691. }
  692. cs_error_t cpg_iteration_finalize (
  693. cpg_iteration_handle_t handle)
  694. {
  695. cs_error_t error;
  696. struct iovec iov;
  697. struct cpg_iteration_instance_t *cpg_iteration_instance;
  698. struct req_lib_cpg_iterationfinalize req_lib_cpg_iterationfinalize;
  699. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  700. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  701. (void *)&cpg_iteration_instance));
  702. if (error != CS_OK) {
  703. goto error_exit;
  704. }
  705. req_lib_cpg_iterationfinalize.header.size = sizeof (struct req_lib_cpg_iterationfinalize);
  706. req_lib_cpg_iterationfinalize.header.id = MESSAGE_REQ_CPG_ITERATIONFINALIZE;
  707. req_lib_cpg_iterationfinalize.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  708. iov.iov_base = (void *)&req_lib_cpg_iterationfinalize;
  709. iov.iov_len = sizeof (struct req_lib_cpg_iterationfinalize);
  710. error = coroipcc_msg_send_reply_receive (cpg_iteration_instance->conn_handle,
  711. &iov,
  712. 1,
  713. &res_lib_cpg_iterationfinalize,
  714. sizeof (struct req_lib_cpg_iterationfinalize));
  715. if (error != CS_OK) {
  716. goto error_put;
  717. }
  718. cpg_iteration_instance_finalize (cpg_iteration_instance);
  719. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->cpg_iteration_handle);
  720. return (res_lib_cpg_iterationfinalize.header.error);
  721. error_put:
  722. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  723. error_exit:
  724. return (error);
  725. }
  726. /** @} */