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_OK) {
  208. goto error_put;
  209. }
  210. if (dispatch_data == NULL) {
  211. if (dispatch_types == CPG_DISPATCH_ALL) {
  212. break; /* exit do while cont is 1 loop */
  213. } else {
  214. continue; /* next poll */
  215. }
  216. }
  217. /*
  218. * Make copy of callbacks, message data, unlock instance, and call callback
  219. * A risk of this dispatch method is that the callback routines may
  220. * operate at the same time that cpgFinalize has been called.
  221. */
  222. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  223. /*
  224. * Dispatch incoming message
  225. */
  226. switch (dispatch_data->id) {
  227. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  228. if (callbacks.cpg_deliver_fn == NULL) {
  229. continue;
  230. }
  231. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  232. marshall_from_mar_cpg_name_t (
  233. &group_name,
  234. &res_cpg_deliver_callback->group_name);
  235. callbacks.cpg_deliver_fn (handle,
  236. &group_name,
  237. res_cpg_deliver_callback->nodeid,
  238. res_cpg_deliver_callback->pid,
  239. &res_cpg_deliver_callback->message,
  240. res_cpg_deliver_callback->msglen);
  241. break;
  242. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  243. if (callbacks.cpg_confchg_fn == NULL) {
  244. continue;
  245. }
  246. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  247. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  248. marshall_from_mar_cpg_address_t (&member_list[i],
  249. &res_cpg_confchg_callback->member_list[i]);
  250. }
  251. left_list_start = res_cpg_confchg_callback->member_list +
  252. res_cpg_confchg_callback->member_list_entries;
  253. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  254. marshall_from_mar_cpg_address_t (&left_list[i],
  255. &left_list_start[i]);
  256. }
  257. joined_list_start = res_cpg_confchg_callback->member_list +
  258. res_cpg_confchg_callback->member_list_entries +
  259. res_cpg_confchg_callback->left_list_entries;
  260. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  261. marshall_from_mar_cpg_address_t (&joined_list[i],
  262. &joined_list_start[i]);
  263. }
  264. marshall_from_mar_cpg_name_t (
  265. &group_name,
  266. &res_cpg_confchg_callback->group_name);
  267. callbacks.cpg_confchg_fn (handle,
  268. &group_name,
  269. member_list,
  270. res_cpg_confchg_callback->member_list_entries,
  271. left_list,
  272. res_cpg_confchg_callback->left_list_entries,
  273. joined_list,
  274. res_cpg_confchg_callback->joined_list_entries);
  275. break;
  276. default:
  277. coroipcc_dispatch_put (cpg_inst->handle);
  278. error = CS_ERR_LIBRARY;
  279. goto error_put;
  280. break;
  281. }
  282. coroipcc_dispatch_put (cpg_inst->handle);
  283. /*
  284. * Determine if more messages should be processed
  285. * */
  286. switch (dispatch_types) {
  287. case CPG_DISPATCH_ONE:
  288. if (ignore_dispatch) {
  289. ignore_dispatch = 0;
  290. } else {
  291. cont = 0;
  292. }
  293. break;
  294. case CPG_DISPATCH_ALL:
  295. if (ignore_dispatch) {
  296. ignore_dispatch = 0;
  297. }
  298. break;
  299. case CPG_DISPATCH_BLOCKING:
  300. break;
  301. }
  302. } while (cont);
  303. error_put:
  304. hdb_handle_put (&cpg_handle_t_db, handle);
  305. return (error);
  306. }
  307. cs_error_t cpg_join (
  308. cpg_handle_t handle,
  309. const struct cpg_name *group)
  310. {
  311. cs_error_t error;
  312. struct cpg_inst *cpg_inst;
  313. struct iovec iov[2];
  314. struct req_lib_cpg_join req_lib_cpg_join;
  315. struct res_lib_cpg_join res_lib_cpg_join;
  316. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  317. if (error != CS_OK) {
  318. return (error);
  319. }
  320. /* Now join */
  321. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  322. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  323. req_lib_cpg_join.pid = getpid();
  324. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  325. group);
  326. iov[0].iov_base = (void *)&req_lib_cpg_join;
  327. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  328. do {
  329. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  330. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  331. if (error != CS_OK) {
  332. goto error_exit;
  333. }
  334. } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY);
  335. error = res_lib_cpg_join.header.error;
  336. error_exit:
  337. hdb_handle_put (&cpg_handle_t_db, handle);
  338. return (error);
  339. }
  340. cs_error_t cpg_leave (
  341. cpg_handle_t handle,
  342. const struct cpg_name *group)
  343. {
  344. cs_error_t error;
  345. struct cpg_inst *cpg_inst;
  346. struct iovec iov[2];
  347. struct req_lib_cpg_leave req_lib_cpg_leave;
  348. struct res_lib_cpg_leave res_lib_cpg_leave;
  349. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  350. if (error != CS_OK) {
  351. return (error);
  352. }
  353. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  354. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  355. req_lib_cpg_leave.pid = getpid();
  356. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  357. group);
  358. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  359. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  360. do {
  361. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  362. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  363. if (error != CS_OK) {
  364. goto error_exit;
  365. }
  366. } while (res_lib_cpg_leave.header.error == CPG_ERR_BUSY);
  367. error = res_lib_cpg_leave.header.error;
  368. error_exit:
  369. hdb_handle_put (&cpg_handle_t_db, handle);
  370. return (error);
  371. }
  372. cs_error_t cpg_membership_get (
  373. cpg_handle_t handle,
  374. struct cpg_name *group_name,
  375. struct cpg_address *member_list,
  376. int *member_list_entries)
  377. {
  378. cs_error_t error;
  379. struct cpg_inst *cpg_inst;
  380. struct iovec iov;
  381. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  382. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  383. unsigned int i;
  384. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  385. if (error != CS_OK) {
  386. return (error);
  387. }
  388. req_lib_cpg_membership_get.header.size = sizeof (coroipc_request_header_t);
  389. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  390. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  391. iov.iov_len = sizeof (coroipc_request_header_t);
  392. do {
  393. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  394. &res_lib_cpg_membership_get, sizeof (coroipc_response_header_t));
  395. if (error != CS_OK) {
  396. goto error_exit;
  397. }
  398. } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY);
  399. error = res_lib_cpg_membership_get.header.error;
  400. /*
  401. * Copy results to caller
  402. */
  403. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  404. if (member_list) {
  405. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  406. marshall_from_mar_cpg_address_t (&member_list[i],
  407. &res_lib_cpg_membership_get.member_list[i]);
  408. }
  409. }
  410. error_exit:
  411. hdb_handle_put (&cpg_handle_t_db, handle);
  412. return (error);
  413. }
  414. cs_error_t cpg_local_get (
  415. cpg_handle_t handle,
  416. unsigned int *local_nodeid)
  417. {
  418. cs_error_t error;
  419. struct cpg_inst *cpg_inst;
  420. struct iovec iov;
  421. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  422. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  423. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  424. if (error != CS_OK) {
  425. return (error);
  426. }
  427. req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t);
  428. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  429. iov.iov_base = (void *)&req_lib_cpg_local_get;
  430. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  431. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  432. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  433. if (error != CS_OK) {
  434. goto error_exit;
  435. }
  436. error = res_lib_cpg_local_get.header.error;
  437. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  438. error_exit:
  439. hdb_handle_put (&cpg_handle_t_db, handle);
  440. return (error);
  441. }
  442. cs_error_t cpg_flow_control_state_get (
  443. cpg_handle_t handle,
  444. cpg_flow_control_state_t *flow_control_state)
  445. {
  446. cs_error_t error;
  447. struct cpg_inst *cpg_inst;
  448. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  449. if (error != CS_OK) {
  450. return (error);
  451. }
  452. error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state);
  453. hdb_handle_put (&cpg_handle_t_db, handle);
  454. return (error);
  455. }
  456. cs_error_t cpg_zcb_alloc (
  457. cpg_handle_t handle,
  458. size_t size,
  459. void **buffer)
  460. {
  461. cs_error_t error;
  462. struct cpg_inst *cpg_inst;
  463. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  464. if (error != CS_OK) {
  465. return (error);
  466. }
  467. error = coroipcc_zcb_alloc (cpg_inst->handle,
  468. buffer,
  469. size,
  470. sizeof (struct req_lib_cpg_mcast));
  471. hdb_handle_put (&cpg_handle_t_db, handle);
  472. *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast);
  473. return (error);
  474. }
  475. cs_error_t cpg_zcb_free (
  476. cpg_handle_t handle,
  477. void *buffer)
  478. {
  479. cs_error_t error;
  480. struct cpg_inst *cpg_inst;
  481. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  482. if (error != CS_OK) {
  483. return (error);
  484. }
  485. coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast));
  486. hdb_handle_put (&cpg_handle_t_db, handle);
  487. return (error);
  488. }
  489. cs_error_t cpg_zcb_mcast_joined (
  490. cpg_handle_t handle,
  491. cpg_guarantee_t guarantee,
  492. void *msg,
  493. size_t msg_len)
  494. {
  495. cs_error_t error;
  496. struct cpg_inst *cpg_inst;
  497. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  498. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  499. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  500. if (error != CS_OK) {
  501. return (error);
  502. }
  503. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast));
  504. req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) +
  505. msg_len;
  506. req_lib_cpg_mcast->header.id = MESSAGE_REQ_CPG_MCAST;
  507. req_lib_cpg_mcast->guarantee = guarantee;
  508. req_lib_cpg_mcast->msglen = msg_len;
  509. error = coroipcc_zcb_msg_send_reply_receive (
  510. cpg_inst->handle,
  511. req_lib_cpg_mcast,
  512. &res_lib_cpg_mcast,
  513. sizeof (res_lib_cpg_mcast));
  514. if (error != CS_OK) {
  515. goto error_exit;
  516. }
  517. error = res_lib_cpg_mcast.header.error;
  518. error_exit:
  519. hdb_handle_put (&cpg_handle_t_db, handle);
  520. return (error);
  521. }
  522. cs_error_t cpg_mcast_joined (
  523. cpg_handle_t handle,
  524. cpg_guarantee_t guarantee,
  525. const struct iovec *iovec,
  526. unsigned int iov_len)
  527. {
  528. int i;
  529. cs_error_t error;
  530. struct cpg_inst *cpg_inst;
  531. struct iovec iov[64];
  532. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  533. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  534. size_t msg_len = 0;
  535. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  536. if (error != CS_OK) {
  537. return (error);
  538. }
  539. for (i = 0; i < iov_len; i++ ) {
  540. msg_len += iovec[i].iov_len;
  541. }
  542. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  543. msg_len;
  544. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  545. req_lib_cpg_mcast.guarantee = guarantee;
  546. req_lib_cpg_mcast.msglen = msg_len;
  547. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  548. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  549. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  550. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov,
  551. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  552. if (error != CS_OK) {
  553. goto error_exit;
  554. }
  555. error = res_lib_cpg_mcast.header.error;
  556. error_exit:
  557. hdb_handle_put (&cpg_handle_t_db, handle);
  558. return (error);
  559. }
  560. /** @} */