cpg.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. int ignore_dispatch = 0;
  213. struct cpg_address member_list[CPG_MEMBERS_MAX];
  214. struct cpg_address left_list[CPG_MEMBERS_MAX];
  215. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  216. struct cpg_name group_name;
  217. mar_cpg_address_t *left_list_start;
  218. mar_cpg_address_t *joined_list_start;
  219. unsigned int i;
  220. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  221. if (error != CS_OK) {
  222. return (error);
  223. }
  224. /*
  225. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  226. * wait indefinately for SA_DISPATCH_BLOCKING
  227. */
  228. if (dispatch_types == CPG_DISPATCH_ALL) {
  229. timeout = 0;
  230. }
  231. do {
  232. error = coroipcc_dispatch_get (
  233. cpg_inst->handle,
  234. (void **)&dispatch_data,
  235. timeout);
  236. if (error == CS_ERR_BAD_HANDLE) {
  237. error = CS_OK;
  238. goto error_put;
  239. }
  240. if (error == CS_ERR_TRY_AGAIN) {
  241. error = CS_OK;
  242. if (dispatch_types == CPG_DISPATCH_ALL) {
  243. break; /* exit do while cont is 1 loop */
  244. } else {
  245. continue; /* next poll */
  246. }
  247. }
  248. if (error != CS_OK) {
  249. goto error_put;
  250. }
  251. /*
  252. * Make copy of callbacks, message data, unlock instance, and call callback
  253. * A risk of this dispatch method is that the callback routines may
  254. * operate at the same time that cpgFinalize has been called.
  255. */
  256. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  257. /*
  258. * Dispatch incoming message
  259. */
  260. switch (dispatch_data->id) {
  261. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  262. if (callbacks.cpg_deliver_fn == NULL) {
  263. continue;
  264. }
  265. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  266. marshall_from_mar_cpg_name_t (
  267. &group_name,
  268. &res_cpg_deliver_callback->group_name);
  269. callbacks.cpg_deliver_fn (handle,
  270. &group_name,
  271. res_cpg_deliver_callback->nodeid,
  272. res_cpg_deliver_callback->pid,
  273. &res_cpg_deliver_callback->message,
  274. res_cpg_deliver_callback->msglen);
  275. break;
  276. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  277. if (callbacks.cpg_confchg_fn == NULL) {
  278. continue;
  279. }
  280. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  281. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  282. marshall_from_mar_cpg_address_t (&member_list[i],
  283. &res_cpg_confchg_callback->member_list[i]);
  284. }
  285. left_list_start = res_cpg_confchg_callback->member_list +
  286. res_cpg_confchg_callback->member_list_entries;
  287. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  288. marshall_from_mar_cpg_address_t (&left_list[i],
  289. &left_list_start[i]);
  290. }
  291. joined_list_start = res_cpg_confchg_callback->member_list +
  292. res_cpg_confchg_callback->member_list_entries +
  293. res_cpg_confchg_callback->left_list_entries;
  294. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  295. marshall_from_mar_cpg_address_t (&joined_list[i],
  296. &joined_list_start[i]);
  297. }
  298. marshall_from_mar_cpg_name_t (
  299. &group_name,
  300. &res_cpg_confchg_callback->group_name);
  301. callbacks.cpg_confchg_fn (handle,
  302. &group_name,
  303. member_list,
  304. res_cpg_confchg_callback->member_list_entries,
  305. left_list,
  306. res_cpg_confchg_callback->left_list_entries,
  307. joined_list,
  308. res_cpg_confchg_callback->joined_list_entries);
  309. break;
  310. default:
  311. coroipcc_dispatch_put (cpg_inst->handle);
  312. error = CS_ERR_LIBRARY;
  313. goto error_put;
  314. break;
  315. }
  316. coroipcc_dispatch_put (cpg_inst->handle);
  317. /*
  318. * Determine if more messages should be processed
  319. * */
  320. switch (dispatch_types) {
  321. case CPG_DISPATCH_ONE:
  322. if (ignore_dispatch) {
  323. ignore_dispatch = 0;
  324. } else {
  325. cont = 0;
  326. }
  327. break;
  328. case CPG_DISPATCH_ALL:
  329. if (ignore_dispatch) {
  330. ignore_dispatch = 0;
  331. }
  332. break;
  333. case CPG_DISPATCH_BLOCKING:
  334. break;
  335. }
  336. } while (cont);
  337. error_put:
  338. hdb_handle_put (&cpg_handle_t_db, handle);
  339. return (error);
  340. }
  341. cs_error_t cpg_join (
  342. cpg_handle_t handle,
  343. const struct cpg_name *group)
  344. {
  345. cs_error_t error;
  346. struct cpg_inst *cpg_inst;
  347. struct iovec iov[2];
  348. struct req_lib_cpg_join req_lib_cpg_join;
  349. struct res_lib_cpg_join res_lib_cpg_join;
  350. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  351. if (error != CS_OK) {
  352. return (error);
  353. }
  354. /* Now join */
  355. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  356. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  357. req_lib_cpg_join.pid = getpid();
  358. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  359. group);
  360. iov[0].iov_base = (void *)&req_lib_cpg_join;
  361. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  362. do {
  363. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  364. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  365. if (error != CS_OK) {
  366. goto error_exit;
  367. }
  368. } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY);
  369. error = res_lib_cpg_join.header.error;
  370. error_exit:
  371. hdb_handle_put (&cpg_handle_t_db, handle);
  372. return (error);
  373. }
  374. cs_error_t cpg_leave (
  375. cpg_handle_t handle,
  376. const struct cpg_name *group)
  377. {
  378. cs_error_t error;
  379. struct cpg_inst *cpg_inst;
  380. struct iovec iov[2];
  381. struct req_lib_cpg_leave req_lib_cpg_leave;
  382. struct res_lib_cpg_leave res_lib_cpg_leave;
  383. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  384. if (error != CS_OK) {
  385. return (error);
  386. }
  387. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  388. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  389. req_lib_cpg_leave.pid = getpid();
  390. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  391. group);
  392. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  393. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  394. do {
  395. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  396. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  397. if (error != CS_OK) {
  398. goto error_exit;
  399. }
  400. } while (res_lib_cpg_leave.header.error == CPG_ERR_BUSY);
  401. error = res_lib_cpg_leave.header.error;
  402. error_exit:
  403. hdb_handle_put (&cpg_handle_t_db, handle);
  404. return (error);
  405. }
  406. cs_error_t cpg_membership_get (
  407. cpg_handle_t handle,
  408. struct cpg_name *group_name,
  409. struct cpg_address *member_list,
  410. int *member_list_entries)
  411. {
  412. cs_error_t error;
  413. struct cpg_inst *cpg_inst;
  414. struct iovec iov;
  415. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  416. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  417. unsigned int i;
  418. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  419. if (error != CS_OK) {
  420. return (error);
  421. }
  422. req_lib_cpg_membership_get.header.size = sizeof (coroipc_request_header_t);
  423. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  424. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  425. iov.iov_len = sizeof (coroipc_request_header_t);
  426. do {
  427. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  428. &res_lib_cpg_membership_get, sizeof (coroipc_response_header_t));
  429. if (error != CS_OK) {
  430. goto error_exit;
  431. }
  432. } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY);
  433. error = res_lib_cpg_membership_get.header.error;
  434. /*
  435. * Copy results to caller
  436. */
  437. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  438. if (member_list) {
  439. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  440. marshall_from_mar_cpg_address_t (&member_list[i],
  441. &res_lib_cpg_membership_get.member_list[i]);
  442. }
  443. }
  444. error_exit:
  445. hdb_handle_put (&cpg_handle_t_db, handle);
  446. return (error);
  447. }
  448. cs_error_t cpg_local_get (
  449. cpg_handle_t handle,
  450. unsigned int *local_nodeid)
  451. {
  452. cs_error_t error;
  453. struct cpg_inst *cpg_inst;
  454. struct iovec iov;
  455. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  456. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  457. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  458. if (error != CS_OK) {
  459. return (error);
  460. }
  461. req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t);
  462. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  463. iov.iov_base = (void *)&req_lib_cpg_local_get;
  464. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  465. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  466. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  467. if (error != CS_OK) {
  468. goto error_exit;
  469. }
  470. error = res_lib_cpg_local_get.header.error;
  471. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  472. error_exit:
  473. hdb_handle_put (&cpg_handle_t_db, handle);
  474. return (error);
  475. }
  476. cs_error_t cpg_flow_control_state_get (
  477. cpg_handle_t handle,
  478. cpg_flow_control_state_t *flow_control_state)
  479. {
  480. cs_error_t error;
  481. struct cpg_inst *cpg_inst;
  482. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  483. if (error != CS_OK) {
  484. return (error);
  485. }
  486. error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state);
  487. hdb_handle_put (&cpg_handle_t_db, handle);
  488. return (error);
  489. }
  490. cs_error_t cpg_zcb_alloc (
  491. cpg_handle_t handle,
  492. size_t size,
  493. void **buffer)
  494. {
  495. cs_error_t error;
  496. struct cpg_inst *cpg_inst;
  497. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  498. if (error != CS_OK) {
  499. return (error);
  500. }
  501. error = coroipcc_zcb_alloc (cpg_inst->handle,
  502. buffer,
  503. size,
  504. sizeof (struct req_lib_cpg_mcast));
  505. hdb_handle_put (&cpg_handle_t_db, handle);
  506. *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast);
  507. return (error);
  508. }
  509. cs_error_t cpg_zcb_free (
  510. cpg_handle_t handle,
  511. void *buffer)
  512. {
  513. cs_error_t error;
  514. struct cpg_inst *cpg_inst;
  515. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  516. if (error != CS_OK) {
  517. return (error);
  518. }
  519. coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast));
  520. hdb_handle_put (&cpg_handle_t_db, handle);
  521. return (error);
  522. }
  523. cs_error_t cpg_zcb_mcast_joined (
  524. cpg_handle_t handle,
  525. cpg_guarantee_t guarantee,
  526. void *msg,
  527. size_t msg_len)
  528. {
  529. cs_error_t error;
  530. struct cpg_inst *cpg_inst;
  531. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  532. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  533. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  534. if (error != CS_OK) {
  535. return (error);
  536. }
  537. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast));
  538. req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) +
  539. msg_len;
  540. req_lib_cpg_mcast->header.id = MESSAGE_REQ_CPG_MCAST;
  541. req_lib_cpg_mcast->guarantee = guarantee;
  542. req_lib_cpg_mcast->msglen = msg_len;
  543. error = coroipcc_zcb_msg_send_reply_receive (
  544. cpg_inst->handle,
  545. req_lib_cpg_mcast,
  546. &res_lib_cpg_mcast,
  547. sizeof (res_lib_cpg_mcast));
  548. if (error != CS_OK) {
  549. goto error_exit;
  550. }
  551. error = res_lib_cpg_mcast.header.error;
  552. error_exit:
  553. hdb_handle_put (&cpg_handle_t_db, handle);
  554. return (error);
  555. }
  556. cs_error_t cpg_mcast_joined (
  557. cpg_handle_t handle,
  558. cpg_guarantee_t guarantee,
  559. const struct iovec *iovec,
  560. unsigned int iov_len)
  561. {
  562. int i;
  563. cs_error_t error;
  564. struct cpg_inst *cpg_inst;
  565. struct iovec iov[64];
  566. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  567. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  568. size_t msg_len = 0;
  569. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  570. if (error != CS_OK) {
  571. return (error);
  572. }
  573. for (i = 0; i < iov_len; i++ ) {
  574. msg_len += iovec[i].iov_len;
  575. }
  576. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  577. msg_len;
  578. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  579. req_lib_cpg_mcast.guarantee = guarantee;
  580. req_lib_cpg_mcast.msglen = msg_len;
  581. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  582. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  583. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  584. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov,
  585. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  586. if (error != CS_OK) {
  587. goto error_exit;
  588. }
  589. error = res_lib_cpg_mcast.header.error;
  590. error_exit:
  591. hdb_handle_put (&cpg_handle_t_db, handle);
  592. return (error);
  593. }
  594. cs_error_t cpg_iteration_initialize(
  595. cpg_handle_t handle,
  596. cpg_iteration_type_t iteration_type,
  597. const struct cpg_name *group,
  598. cpg_iteration_handle_t *cpg_iteration_handle)
  599. {
  600. cs_error_t error;
  601. struct iovec iov;
  602. struct cpg_inst *cpg_inst;
  603. struct cpg_iteration_instance_t *cpg_iteration_instance;
  604. struct req_lib_cpg_iterationinitialize req_lib_cpg_iterationinitialize;
  605. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  606. if (cpg_iteration_handle == NULL) {
  607. return (CS_ERR_INVALID_PARAM);
  608. }
  609. if ((iteration_type == CPG_ITERATION_ONE_GROUP && group == NULL) ||
  610. (iteration_type != CPG_ITERATION_ONE_GROUP && group != NULL)) {
  611. return (CS_ERR_INVALID_PARAM);
  612. }
  613. if (iteration_type != CPG_ITERATION_NAME_ONLY && iteration_type != CPG_ITERATION_ONE_GROUP &&
  614. iteration_type != CPG_ITERATION_ALL) {
  615. return (CS_ERR_INVALID_PARAM);
  616. }
  617. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  618. if (error != CS_OK) {
  619. return (error);
  620. }
  621. error = hdb_error_to_cs (hdb_handle_create (&cpg_iteration_handle_t_db,
  622. sizeof (struct cpg_iteration_instance_t), cpg_iteration_handle));
  623. if (error != CS_OK) {
  624. goto error_put_cpg_db;
  625. }
  626. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, *cpg_iteration_handle,
  627. (void *)&cpg_iteration_instance));
  628. if (error != CS_OK) {
  629. goto error_destroy;
  630. }
  631. cpg_iteration_instance->conn_handle = cpg_inst->handle;
  632. list_init (&cpg_iteration_instance->list);
  633. req_lib_cpg_iterationinitialize.header.size = sizeof (struct req_lib_cpg_iterationinitialize);
  634. req_lib_cpg_iterationinitialize.header.id = MESSAGE_REQ_CPG_ITERATIONINITIALIZE;
  635. req_lib_cpg_iterationinitialize.iteration_type = iteration_type;
  636. if (group) {
  637. marshall_to_mar_cpg_name_t (&req_lib_cpg_iterationinitialize.group_name, group);
  638. }
  639. iov.iov_base = (void *)&req_lib_cpg_iterationinitialize;
  640. iov.iov_len = sizeof (struct req_lib_cpg_iterationinitialize);
  641. error = coroipcc_msg_send_reply_receive (cpg_inst->handle,
  642. &iov,
  643. 1,
  644. &res_lib_cpg_iterationinitialize,
  645. sizeof (struct res_lib_cpg_iterationinitialize));
  646. if (error != CS_OK) {
  647. goto error_put_destroy;
  648. }
  649. cpg_iteration_instance->executive_iteration_handle =
  650. res_lib_cpg_iterationinitialize.iteration_handle;
  651. cpg_iteration_instance->cpg_iteration_handle = *cpg_iteration_handle;
  652. list_add (&cpg_iteration_instance->list, &cpg_inst->iteration_list_head);
  653. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  654. hdb_handle_put (&cpg_handle_t_db, handle);
  655. return (res_lib_cpg_iterationinitialize.header.error);
  656. error_put_destroy:
  657. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  658. error_destroy:
  659. hdb_handle_destroy (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  660. error_put_cpg_db:
  661. hdb_handle_put (&cpg_handle_t_db, handle);
  662. return (error);
  663. }
  664. cs_error_t cpg_iteration_next(
  665. cpg_iteration_handle_t handle,
  666. struct cpg_iteration_description_t *description)
  667. {
  668. cs_error_t error;
  669. struct cpg_iteration_instance_t *cpg_iteration_instance;
  670. struct req_lib_cpg_iterationnext req_lib_cpg_iterationnext;
  671. struct res_lib_cpg_iterationnext *res_lib_cpg_iterationnext;
  672. struct iovec iov;
  673. void *return_address;
  674. if (description == NULL) {
  675. return CS_ERR_INVALID_PARAM;
  676. }
  677. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  678. (void *)&cpg_iteration_instance));
  679. if (error != CS_OK) {
  680. goto error_exit;
  681. }
  682. req_lib_cpg_iterationnext.header.size = sizeof (struct req_lib_cpg_iterationnext);
  683. req_lib_cpg_iterationnext.header.id = MESSAGE_REQ_CPG_ITERATIONNEXT;
  684. req_lib_cpg_iterationnext.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  685. iov.iov_base = (void *)&req_lib_cpg_iterationnext;
  686. iov.iov_len = sizeof (struct req_lib_cpg_iterationnext);
  687. error = coroipcc_msg_send_reply_receive_in_buf_get (cpg_iteration_instance->conn_handle,
  688. &iov,
  689. 1,
  690. &return_address);
  691. res_lib_cpg_iterationnext = return_address;
  692. if (error != CS_OK) {
  693. goto error_put;
  694. }
  695. marshall_from_mar_cpg_iteration_description_t(
  696. description,
  697. &res_lib_cpg_iterationnext->description);
  698. error = res_lib_cpg_iterationnext->header.error;
  699. coroipcc_msg_send_reply_receive_in_buf_put(
  700. cpg_iteration_instance->conn_handle);
  701. error_put:
  702. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  703. error_exit:
  704. return (error);
  705. }
  706. cs_error_t cpg_iteration_finalize (
  707. cpg_iteration_handle_t handle)
  708. {
  709. cs_error_t error;
  710. struct iovec iov;
  711. struct cpg_iteration_instance_t *cpg_iteration_instance;
  712. struct req_lib_cpg_iterationfinalize req_lib_cpg_iterationfinalize;
  713. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  714. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  715. (void *)&cpg_iteration_instance));
  716. if (error != CS_OK) {
  717. goto error_exit;
  718. }
  719. req_lib_cpg_iterationfinalize.header.size = sizeof (struct req_lib_cpg_iterationfinalize);
  720. req_lib_cpg_iterationfinalize.header.id = MESSAGE_REQ_CPG_ITERATIONFINALIZE;
  721. req_lib_cpg_iterationfinalize.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  722. iov.iov_base = (void *)&req_lib_cpg_iterationfinalize;
  723. iov.iov_len = sizeof (struct req_lib_cpg_iterationfinalize);
  724. error = coroipcc_msg_send_reply_receive (cpg_iteration_instance->conn_handle,
  725. &iov,
  726. 1,
  727. &res_lib_cpg_iterationfinalize,
  728. sizeof (struct req_lib_cpg_iterationfinalize));
  729. if (error != CS_OK) {
  730. goto error_put;
  731. }
  732. cpg_iteration_instance_finalize (cpg_iteration_instance);
  733. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->cpg_iteration_handle);
  734. return (res_lib_cpg_iterationfinalize.header.error);
  735. error_put:
  736. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  737. error_exit:
  738. return (error);
  739. }
  740. /** @} */