cpg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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: Patrick Caulfield (pcaulfie@redhat.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /*
  37. * Provides a closed process group API using the coroipcc executive
  38. */
  39. #include <config.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <unistd.h>
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <errno.h>
  46. #include <corosync/corotypes.h>
  47. #include <corosync/coroipc_types.h>
  48. #include <corosync/coroipcc.h>
  49. #include <corosync/corodefs.h>
  50. #include <corosync/hdb.h>
  51. #include <corosync/cpg.h>
  52. #include <corosync/ipc_cpg.h>
  53. #include "util.h"
  54. struct cpg_inst {
  55. hdb_handle_t handle;
  56. int finalize;
  57. cpg_callbacks_t callbacks;
  58. void *context;
  59. };
  60. DECLARE_HDB_DATABASE(cpg_handle_t_db,NULL);
  61. /**
  62. * @defgroup cpg_coroipcc The closed process group API
  63. * @ingroup coroipcc
  64. *
  65. * @{
  66. */
  67. cs_error_t cpg_initialize (
  68. cpg_handle_t *handle,
  69. cpg_callbacks_t *callbacks)
  70. {
  71. cs_error_t error;
  72. struct cpg_inst *cpg_inst;
  73. error = hdb_error_to_cs (hdb_handle_create (&cpg_handle_t_db, sizeof (struct cpg_inst), handle));
  74. if (error != CS_OK) {
  75. goto error_no_destroy;
  76. }
  77. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, *handle, (void *)&cpg_inst));
  78. if (error != CS_OK) {
  79. goto error_destroy;
  80. }
  81. error = coroipcc_service_connect (
  82. COROSYNC_SOCKET_NAME,
  83. CPG_SERVICE,
  84. IPC_REQUEST_SIZE,
  85. IPC_RESPONSE_SIZE,
  86. IPC_DISPATCH_SIZE,
  87. &cpg_inst->handle);
  88. if (error != CS_OK) {
  89. goto error_put_destroy;
  90. }
  91. if (callbacks) {
  92. memcpy (&cpg_inst->callbacks, callbacks, sizeof (cpg_callbacks_t));
  93. }
  94. hdb_handle_put (&cpg_handle_t_db, *handle);
  95. return (CS_OK);
  96. error_put_destroy:
  97. hdb_handle_put (&cpg_handle_t_db, *handle);
  98. error_destroy:
  99. hdb_handle_destroy (&cpg_handle_t_db, *handle);
  100. error_no_destroy:
  101. return (error);
  102. }
  103. cs_error_t cpg_finalize (
  104. cpg_handle_t handle)
  105. {
  106. struct cpg_inst *cpg_inst;
  107. cs_error_t error;
  108. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  109. if (error != CS_OK) {
  110. return (error);
  111. }
  112. /*
  113. * Another thread has already started finalizing
  114. */
  115. if (cpg_inst->finalize) {
  116. hdb_handle_put (&cpg_handle_t_db, handle);
  117. return (CPG_ERR_BAD_HANDLE);
  118. }
  119. cpg_inst->finalize = 1;
  120. coroipcc_service_disconnect (cpg_inst->handle);
  121. hdb_handle_destroy (&cpg_handle_t_db, handle);
  122. hdb_handle_put (&cpg_handle_t_db, handle);
  123. return (CPG_OK);
  124. }
  125. cs_error_t cpg_fd_get (
  126. cpg_handle_t handle,
  127. int *fd)
  128. {
  129. cs_error_t error;
  130. struct cpg_inst *cpg_inst;
  131. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  132. if (error != CS_OK) {
  133. return (error);
  134. }
  135. error = coroipcc_fd_get (cpg_inst->handle, fd);
  136. hdb_handle_put (&cpg_handle_t_db, handle);
  137. return (error);
  138. }
  139. cs_error_t cpg_context_get (
  140. cpg_handle_t handle,
  141. void **context)
  142. {
  143. cs_error_t error;
  144. struct cpg_inst *cpg_inst;
  145. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  146. if (error != CS_OK) {
  147. return (error);
  148. }
  149. *context = cpg_inst->context;
  150. hdb_handle_put (&cpg_handle_t_db, handle);
  151. return (CS_OK);
  152. }
  153. cs_error_t cpg_context_set (
  154. cpg_handle_t handle,
  155. void *context)
  156. {
  157. cs_error_t error;
  158. struct cpg_inst *cpg_inst;
  159. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  160. if (error != CS_OK) {
  161. return (error);
  162. }
  163. cpg_inst->context = context;
  164. hdb_handle_put (&cpg_handle_t_db, handle);
  165. return (CS_OK);
  166. }
  167. cs_error_t cpg_dispatch (
  168. cpg_handle_t handle,
  169. cs_dispatch_flags_t dispatch_types)
  170. {
  171. int timeout = -1;
  172. cs_error_t error;
  173. int cont = 1; /* always continue do loop except when set to 0 */
  174. struct cpg_inst *cpg_inst;
  175. struct res_lib_cpg_confchg_callback *res_cpg_confchg_callback;
  176. struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback;
  177. cpg_callbacks_t callbacks;
  178. coroipc_response_header_t *dispatch_data;
  179. int ignore_dispatch = 0;
  180. struct cpg_address member_list[CPG_MEMBERS_MAX];
  181. struct cpg_address left_list[CPG_MEMBERS_MAX];
  182. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  183. struct cpg_name group_name;
  184. mar_cpg_address_t *left_list_start;
  185. mar_cpg_address_t *joined_list_start;
  186. unsigned int i;
  187. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  188. if (error != CS_OK) {
  189. return (error);
  190. }
  191. /*
  192. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  193. * wait indefinately for SA_DISPATCH_BLOCKING
  194. */
  195. if (dispatch_types == CPG_DISPATCH_ALL) {
  196. timeout = 0;
  197. }
  198. do {
  199. error = coroipcc_dispatch_get (
  200. cpg_inst->handle,
  201. (void **)&dispatch_data,
  202. timeout);
  203. if (error == CS_ERR_BAD_HANDLE) {
  204. error = CS_OK;
  205. goto error_put;
  206. }
  207. if (error == CS_ERR_TRY_AGAIN) {
  208. error = CS_OK;
  209. if (dispatch_types == CPG_DISPATCH_ALL) {
  210. break; /* exit do while cont is 1 loop */
  211. } else {
  212. continue; /* next poll */
  213. }
  214. }
  215. if (error != CS_OK) {
  216. goto error_put;
  217. }
  218. /*
  219. * Make copy of callbacks, message data, unlock instance, and call callback
  220. * A risk of this dispatch method is that the callback routines may
  221. * operate at the same time that cpgFinalize has been called.
  222. */
  223. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  224. /*
  225. * Dispatch incoming message
  226. */
  227. switch (dispatch_data->id) {
  228. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  229. if (callbacks.cpg_deliver_fn == NULL) {
  230. continue;
  231. }
  232. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  233. marshall_from_mar_cpg_name_t (
  234. &group_name,
  235. &res_cpg_deliver_callback->group_name);
  236. callbacks.cpg_deliver_fn (handle,
  237. &group_name,
  238. res_cpg_deliver_callback->nodeid,
  239. res_cpg_deliver_callback->pid,
  240. &res_cpg_deliver_callback->message,
  241. res_cpg_deliver_callback->msglen);
  242. break;
  243. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  244. if (callbacks.cpg_confchg_fn == NULL) {
  245. continue;
  246. }
  247. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  248. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  249. marshall_from_mar_cpg_address_t (&member_list[i],
  250. &res_cpg_confchg_callback->member_list[i]);
  251. }
  252. left_list_start = res_cpg_confchg_callback->member_list +
  253. res_cpg_confchg_callback->member_list_entries;
  254. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  255. marshall_from_mar_cpg_address_t (&left_list[i],
  256. &left_list_start[i]);
  257. }
  258. joined_list_start = res_cpg_confchg_callback->member_list +
  259. res_cpg_confchg_callback->member_list_entries +
  260. res_cpg_confchg_callback->left_list_entries;
  261. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  262. marshall_from_mar_cpg_address_t (&joined_list[i],
  263. &joined_list_start[i]);
  264. }
  265. marshall_from_mar_cpg_name_t (
  266. &group_name,
  267. &res_cpg_confchg_callback->group_name);
  268. callbacks.cpg_confchg_fn (handle,
  269. &group_name,
  270. member_list,
  271. res_cpg_confchg_callback->member_list_entries,
  272. left_list,
  273. res_cpg_confchg_callback->left_list_entries,
  274. joined_list,
  275. res_cpg_confchg_callback->joined_list_entries);
  276. break;
  277. default:
  278. coroipcc_dispatch_put (cpg_inst->handle);
  279. error = CS_ERR_LIBRARY;
  280. goto error_put;
  281. break;
  282. }
  283. coroipcc_dispatch_put (cpg_inst->handle);
  284. /*
  285. * Determine if more messages should be processed
  286. * */
  287. switch (dispatch_types) {
  288. case CPG_DISPATCH_ONE:
  289. if (ignore_dispatch) {
  290. ignore_dispatch = 0;
  291. } else {
  292. cont = 0;
  293. }
  294. break;
  295. case CPG_DISPATCH_ALL:
  296. if (ignore_dispatch) {
  297. ignore_dispatch = 0;
  298. }
  299. break;
  300. case CPG_DISPATCH_BLOCKING:
  301. break;
  302. }
  303. } while (cont);
  304. error_put:
  305. hdb_handle_put (&cpg_handle_t_db, handle);
  306. return (error);
  307. }
  308. cs_error_t cpg_join (
  309. cpg_handle_t handle,
  310. const struct cpg_name *group)
  311. {
  312. cs_error_t error;
  313. struct cpg_inst *cpg_inst;
  314. struct iovec iov[2];
  315. struct req_lib_cpg_join req_lib_cpg_join;
  316. struct res_lib_cpg_join res_lib_cpg_join;
  317. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  318. if (error != CS_OK) {
  319. return (error);
  320. }
  321. /* Now join */
  322. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  323. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  324. req_lib_cpg_join.pid = getpid();
  325. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  326. group);
  327. iov[0].iov_base = (void *)&req_lib_cpg_join;
  328. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  329. do {
  330. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  331. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  332. if (error != CS_OK) {
  333. goto error_exit;
  334. }
  335. } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY);
  336. error = res_lib_cpg_join.header.error;
  337. error_exit:
  338. hdb_handle_put (&cpg_handle_t_db, handle);
  339. return (error);
  340. }
  341. cs_error_t cpg_leave (
  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_leave req_lib_cpg_leave;
  349. struct res_lib_cpg_leave res_lib_cpg_leave;
  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. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  355. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  356. req_lib_cpg_leave.pid = getpid();
  357. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  358. group);
  359. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  360. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  361. do {
  362. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  363. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  364. if (error != CS_OK) {
  365. goto error_exit;
  366. }
  367. } while (res_lib_cpg_leave.header.error == CPG_ERR_BUSY);
  368. error = res_lib_cpg_leave.header.error;
  369. error_exit:
  370. hdb_handle_put (&cpg_handle_t_db, handle);
  371. return (error);
  372. }
  373. cs_error_t cpg_membership_get (
  374. cpg_handle_t handle,
  375. struct cpg_name *group_name,
  376. struct cpg_address *member_list,
  377. int *member_list_entries)
  378. {
  379. cs_error_t error;
  380. struct cpg_inst *cpg_inst;
  381. struct iovec iov;
  382. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  383. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  384. unsigned int i;
  385. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  386. if (error != CS_OK) {
  387. return (error);
  388. }
  389. req_lib_cpg_membership_get.header.size = sizeof (coroipc_request_header_t);
  390. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  391. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  392. iov.iov_len = sizeof (coroipc_request_header_t);
  393. do {
  394. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  395. &res_lib_cpg_membership_get, sizeof (coroipc_response_header_t));
  396. if (error != CS_OK) {
  397. goto error_exit;
  398. }
  399. } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY);
  400. error = res_lib_cpg_membership_get.header.error;
  401. /*
  402. * Copy results to caller
  403. */
  404. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  405. if (member_list) {
  406. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  407. marshall_from_mar_cpg_address_t (&member_list[i],
  408. &res_lib_cpg_membership_get.member_list[i]);
  409. }
  410. }
  411. error_exit:
  412. hdb_handle_put (&cpg_handle_t_db, handle);
  413. return (error);
  414. }
  415. cs_error_t cpg_local_get (
  416. cpg_handle_t handle,
  417. unsigned int *local_nodeid)
  418. {
  419. cs_error_t error;
  420. struct cpg_inst *cpg_inst;
  421. struct iovec iov;
  422. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  423. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  424. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  425. if (error != CS_OK) {
  426. return (error);
  427. }
  428. req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t);
  429. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  430. iov.iov_base = (void *)&req_lib_cpg_local_get;
  431. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  432. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  433. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  434. if (error != CS_OK) {
  435. goto error_exit;
  436. }
  437. error = res_lib_cpg_local_get.header.error;
  438. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  439. error_exit:
  440. hdb_handle_put (&cpg_handle_t_db, handle);
  441. return (error);
  442. }
  443. cs_error_t cpg_flow_control_state_get (
  444. cpg_handle_t handle,
  445. cpg_flow_control_state_t *flow_control_state)
  446. {
  447. cs_error_t error;
  448. struct cpg_inst *cpg_inst;
  449. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  450. if (error != CS_OK) {
  451. return (error);
  452. }
  453. error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state);
  454. hdb_handle_put (&cpg_handle_t_db, handle);
  455. return (error);
  456. }
  457. cs_error_t cpg_zcb_alloc (
  458. cpg_handle_t handle,
  459. size_t size,
  460. void **buffer)
  461. {
  462. cs_error_t error;
  463. struct cpg_inst *cpg_inst;
  464. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  465. if (error != CS_OK) {
  466. return (error);
  467. }
  468. error = coroipcc_zcb_alloc (cpg_inst->handle,
  469. buffer,
  470. size,
  471. sizeof (struct req_lib_cpg_mcast));
  472. hdb_handle_put (&cpg_handle_t_db, handle);
  473. *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast);
  474. return (error);
  475. }
  476. cs_error_t cpg_zcb_free (
  477. cpg_handle_t handle,
  478. void *buffer)
  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. coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast));
  487. hdb_handle_put (&cpg_handle_t_db, handle);
  488. return (error);
  489. }
  490. cs_error_t cpg_zcb_mcast_joined (
  491. cpg_handle_t handle,
  492. cpg_guarantee_t guarantee,
  493. void *msg,
  494. size_t msg_len)
  495. {
  496. cs_error_t error;
  497. struct cpg_inst *cpg_inst;
  498. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  499. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  500. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  501. if (error != CS_OK) {
  502. return (error);
  503. }
  504. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast));
  505. req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) +
  506. msg_len;
  507. req_lib_cpg_mcast->header.id = MESSAGE_REQ_CPG_MCAST;
  508. req_lib_cpg_mcast->guarantee = guarantee;
  509. req_lib_cpg_mcast->msglen = msg_len;
  510. error = coroipcc_zcb_msg_send_reply_receive (
  511. cpg_inst->handle,
  512. req_lib_cpg_mcast,
  513. &res_lib_cpg_mcast,
  514. sizeof (res_lib_cpg_mcast));
  515. if (error != CS_OK) {
  516. goto error_exit;
  517. }
  518. error = res_lib_cpg_mcast.header.error;
  519. error_exit:
  520. hdb_handle_put (&cpg_handle_t_db, handle);
  521. return (error);
  522. }
  523. cs_error_t cpg_mcast_joined (
  524. cpg_handle_t handle,
  525. cpg_guarantee_t guarantee,
  526. const struct iovec *iovec,
  527. unsigned int iov_len)
  528. {
  529. int i;
  530. cs_error_t error;
  531. struct cpg_inst *cpg_inst;
  532. struct iovec iov[64];
  533. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  534. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  535. size_t msg_len = 0;
  536. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  537. if (error != CS_OK) {
  538. return (error);
  539. }
  540. for (i = 0; i < iov_len; i++ ) {
  541. msg_len += iovec[i].iov_len;
  542. }
  543. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  544. msg_len;
  545. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  546. req_lib_cpg_mcast.guarantee = guarantee;
  547. req_lib_cpg_mcast.msglen = msg_len;
  548. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  549. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  550. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  551. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov,
  552. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  553. if (error != CS_OK) {
  554. goto error_exit;
  555. }
  556. error = res_lib_cpg_mcast.header.error;
  557. error_exit:
  558. hdb_handle_put (&cpg_handle_t_db, handle);
  559. return (error);
  560. }
  561. /** @} */