cpg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. memcpy (&cpg_inst->callbacks, callbacks, sizeof (cpg_callbacks_t));
  92. hdb_handle_put (&cpg_handle_t_db, *handle);
  93. return (CS_OK);
  94. error_put_destroy:
  95. hdb_handle_put (&cpg_handle_t_db, *handle);
  96. error_destroy:
  97. hdb_handle_destroy (&cpg_handle_t_db, *handle);
  98. error_no_destroy:
  99. return (error);
  100. }
  101. cs_error_t cpg_finalize (
  102. cpg_handle_t handle)
  103. {
  104. struct cpg_inst *cpg_inst;
  105. cs_error_t error;
  106. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  107. if (error != CS_OK) {
  108. return (error);
  109. }
  110. /*
  111. * Another thread has already started finalizing
  112. */
  113. if (cpg_inst->finalize) {
  114. hdb_handle_put (&cpg_handle_t_db, handle);
  115. return (CPG_ERR_BAD_HANDLE);
  116. }
  117. cpg_inst->finalize = 1;
  118. coroipcc_service_disconnect (cpg_inst->handle);
  119. hdb_handle_destroy (&cpg_handle_t_db, handle);
  120. hdb_handle_put (&cpg_handle_t_db, handle);
  121. return (CPG_OK);
  122. }
  123. cs_error_t cpg_fd_get (
  124. cpg_handle_t handle,
  125. int *fd)
  126. {
  127. cs_error_t error;
  128. struct cpg_inst *cpg_inst;
  129. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  130. if (error != CS_OK) {
  131. return (error);
  132. }
  133. error = coroipcc_fd_get (cpg_inst->handle, fd);
  134. hdb_handle_put (&cpg_handle_t_db, handle);
  135. return (error);
  136. }
  137. cs_error_t cpg_context_get (
  138. cpg_handle_t handle,
  139. void **context)
  140. {
  141. cs_error_t error;
  142. struct cpg_inst *cpg_inst;
  143. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  144. if (error != CS_OK) {
  145. return (error);
  146. }
  147. *context = cpg_inst->context;
  148. hdb_handle_put (&cpg_handle_t_db, handle);
  149. return (CS_OK);
  150. }
  151. cs_error_t cpg_context_set (
  152. cpg_handle_t handle,
  153. void *context)
  154. {
  155. cs_error_t error;
  156. struct cpg_inst *cpg_inst;
  157. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  158. if (error != CS_OK) {
  159. return (error);
  160. }
  161. cpg_inst->context = context;
  162. hdb_handle_put (&cpg_handle_t_db, handle);
  163. return (CS_OK);
  164. }
  165. cs_error_t cpg_dispatch (
  166. cpg_handle_t handle,
  167. cs_dispatch_flags_t dispatch_types)
  168. {
  169. int timeout = -1;
  170. cs_error_t error;
  171. int cont = 1; /* always continue do loop except when set to 0 */
  172. struct cpg_inst *cpg_inst;
  173. struct res_lib_cpg_confchg_callback *res_cpg_confchg_callback;
  174. struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback;
  175. cpg_callbacks_t callbacks;
  176. coroipc_response_header_t *dispatch_data;
  177. int ignore_dispatch = 0;
  178. struct cpg_address member_list[CPG_MEMBERS_MAX];
  179. struct cpg_address left_list[CPG_MEMBERS_MAX];
  180. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  181. struct cpg_name group_name;
  182. mar_cpg_address_t *left_list_start;
  183. mar_cpg_address_t *joined_list_start;
  184. unsigned int i;
  185. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  186. if (error != CS_OK) {
  187. return (error);
  188. }
  189. /*
  190. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  191. * wait indefinately for SA_DISPATCH_BLOCKING
  192. */
  193. if (dispatch_types == CPG_DISPATCH_ALL) {
  194. timeout = 0;
  195. }
  196. do {
  197. error = coroipcc_dispatch_get (
  198. cpg_inst->handle,
  199. (void **)&dispatch_data,
  200. timeout);
  201. if (error == CS_ERR_BAD_HANDLE) {
  202. error = CS_OK;
  203. goto error_put;
  204. }
  205. if (error != CS_OK) {
  206. goto error_put;
  207. }
  208. if (dispatch_data == NULL) {
  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. /*
  216. * Make copy of callbacks, message data, unlock instance, and call callback
  217. * A risk of this dispatch method is that the callback routines may
  218. * operate at the same time that cpgFinalize has been called.
  219. */
  220. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  221. /*
  222. * Dispatch incoming message
  223. */
  224. switch (dispatch_data->id) {
  225. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  226. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  227. marshall_from_mar_cpg_name_t (
  228. &group_name,
  229. &res_cpg_deliver_callback->group_name);
  230. callbacks.cpg_deliver_fn (handle,
  231. &group_name,
  232. res_cpg_deliver_callback->nodeid,
  233. res_cpg_deliver_callback->pid,
  234. &res_cpg_deliver_callback->message,
  235. res_cpg_deliver_callback->msglen);
  236. break;
  237. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  238. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  239. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  240. marshall_from_mar_cpg_address_t (&member_list[i],
  241. &res_cpg_confchg_callback->member_list[i]);
  242. }
  243. left_list_start = res_cpg_confchg_callback->member_list +
  244. res_cpg_confchg_callback->member_list_entries;
  245. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  246. marshall_from_mar_cpg_address_t (&left_list[i],
  247. &left_list_start[i]);
  248. }
  249. joined_list_start = res_cpg_confchg_callback->member_list +
  250. res_cpg_confchg_callback->member_list_entries +
  251. res_cpg_confchg_callback->left_list_entries;
  252. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  253. marshall_from_mar_cpg_address_t (&joined_list[i],
  254. &joined_list_start[i]);
  255. }
  256. marshall_from_mar_cpg_name_t (
  257. &group_name,
  258. &res_cpg_confchg_callback->group_name);
  259. callbacks.cpg_confchg_fn (handle,
  260. &group_name,
  261. member_list,
  262. res_cpg_confchg_callback->member_list_entries,
  263. left_list,
  264. res_cpg_confchg_callback->left_list_entries,
  265. joined_list,
  266. res_cpg_confchg_callback->joined_list_entries);
  267. break;
  268. default:
  269. coroipcc_dispatch_put (cpg_inst->handle);
  270. error = CS_ERR_LIBRARY;
  271. goto error_put;
  272. break;
  273. }
  274. coroipcc_dispatch_put (cpg_inst->handle);
  275. /*
  276. * Determine if more messages should be processed
  277. * */
  278. switch (dispatch_types) {
  279. case CPG_DISPATCH_ONE:
  280. if (ignore_dispatch) {
  281. ignore_dispatch = 0;
  282. } else {
  283. cont = 0;
  284. }
  285. break;
  286. case CPG_DISPATCH_ALL:
  287. if (ignore_dispatch) {
  288. ignore_dispatch = 0;
  289. }
  290. break;
  291. case CPG_DISPATCH_BLOCKING:
  292. break;
  293. }
  294. } while (cont);
  295. error_put:
  296. hdb_handle_put (&cpg_handle_t_db, handle);
  297. return (error);
  298. }
  299. cs_error_t cpg_join (
  300. cpg_handle_t handle,
  301. const struct cpg_name *group)
  302. {
  303. cs_error_t error;
  304. struct cpg_inst *cpg_inst;
  305. struct iovec iov[2];
  306. struct req_lib_cpg_join req_lib_cpg_join;
  307. struct res_lib_cpg_join res_lib_cpg_join;
  308. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  309. if (error != CS_OK) {
  310. return (error);
  311. }
  312. /* Now join */
  313. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  314. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  315. req_lib_cpg_join.pid = getpid();
  316. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  317. group);
  318. iov[0].iov_base = (void *)&req_lib_cpg_join;
  319. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  320. do {
  321. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  322. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  323. if (error != CS_OK) {
  324. goto error_exit;
  325. }
  326. } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY);
  327. error = res_lib_cpg_join.header.error;
  328. error_exit:
  329. hdb_handle_put (&cpg_handle_t_db, handle);
  330. return (error);
  331. }
  332. cs_error_t cpg_leave (
  333. cpg_handle_t handle,
  334. const struct cpg_name *group)
  335. {
  336. cs_error_t error;
  337. struct cpg_inst *cpg_inst;
  338. struct iovec iov[2];
  339. struct req_lib_cpg_leave req_lib_cpg_leave;
  340. struct res_lib_cpg_leave res_lib_cpg_leave;
  341. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  342. if (error != CS_OK) {
  343. return (error);
  344. }
  345. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  346. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  347. req_lib_cpg_leave.pid = getpid();
  348. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  349. group);
  350. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  351. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  352. do {
  353. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1,
  354. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  355. if (error != CS_OK) {
  356. goto error_exit;
  357. }
  358. } while (res_lib_cpg_leave.header.error == CPG_ERR_BUSY);
  359. error = res_lib_cpg_leave.header.error;
  360. error_exit:
  361. hdb_handle_put (&cpg_handle_t_db, handle);
  362. return (error);
  363. }
  364. cs_error_t cpg_membership_get (
  365. cpg_handle_t handle,
  366. struct cpg_name *group_name,
  367. struct cpg_address *member_list,
  368. int *member_list_entries)
  369. {
  370. cs_error_t error;
  371. struct cpg_inst *cpg_inst;
  372. struct iovec iov;
  373. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  374. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  375. unsigned int i;
  376. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  377. if (error != CS_OK) {
  378. return (error);
  379. }
  380. req_lib_cpg_membership_get.header.size = sizeof (coroipc_request_header_t);
  381. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  382. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  383. iov.iov_len = sizeof (coroipc_request_header_t);
  384. do {
  385. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  386. &res_lib_cpg_membership_get, sizeof (coroipc_response_header_t));
  387. if (error != CS_OK) {
  388. goto error_exit;
  389. }
  390. } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY);
  391. error = res_lib_cpg_membership_get.header.error;
  392. /*
  393. * Copy results to caller
  394. */
  395. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  396. if (member_list) {
  397. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  398. marshall_from_mar_cpg_address_t (&member_list[i],
  399. &res_lib_cpg_membership_get.member_list[i]);
  400. }
  401. }
  402. error_exit:
  403. hdb_handle_put (&cpg_handle_t_db, handle);
  404. return (error);
  405. }
  406. cs_error_t cpg_local_get (
  407. cpg_handle_t handle,
  408. unsigned int *local_nodeid)
  409. {
  410. cs_error_t error;
  411. struct cpg_inst *cpg_inst;
  412. struct iovec iov;
  413. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  414. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  415. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  416. if (error != CS_OK) {
  417. return (error);
  418. }
  419. req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t);
  420. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  421. iov.iov_base = (void *)&req_lib_cpg_local_get;
  422. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  423. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1,
  424. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  425. if (error != CS_OK) {
  426. goto error_exit;
  427. }
  428. error = res_lib_cpg_local_get.header.error;
  429. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  430. error_exit:
  431. hdb_handle_put (&cpg_handle_t_db, handle);
  432. return (error);
  433. }
  434. cs_error_t cpg_flow_control_state_get (
  435. cpg_handle_t handle,
  436. cpg_flow_control_state_t *flow_control_state)
  437. {
  438. cs_error_t error;
  439. struct cpg_inst *cpg_inst;
  440. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  441. if (error != CS_OK) {
  442. return (error);
  443. }
  444. error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state);
  445. hdb_handle_put (&cpg_handle_t_db, handle);
  446. return (error);
  447. }
  448. cs_error_t cpg_zcb_alloc (
  449. cpg_handle_t handle,
  450. size_t size,
  451. void **buffer)
  452. {
  453. cs_error_t error;
  454. struct cpg_inst *cpg_inst;
  455. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  456. if (error != CS_OK) {
  457. return (error);
  458. }
  459. error = coroipcc_zcb_alloc (cpg_inst->handle,
  460. buffer,
  461. size,
  462. sizeof (struct req_lib_cpg_mcast));
  463. hdb_handle_put (&cpg_handle_t_db, handle);
  464. *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast);
  465. return (error);
  466. }
  467. cs_error_t cpg_zcb_free (
  468. cpg_handle_t handle,
  469. void *buffer)
  470. {
  471. cs_error_t error;
  472. struct cpg_inst *cpg_inst;
  473. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  474. if (error != CS_OK) {
  475. return (error);
  476. }
  477. coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast));
  478. hdb_handle_put (&cpg_handle_t_db, handle);
  479. return (error);
  480. }
  481. cs_error_t cpg_zcb_mcast_joined (
  482. cpg_handle_t handle,
  483. cpg_guarantee_t guarantee,
  484. void *msg,
  485. size_t msg_len)
  486. {
  487. cs_error_t error;
  488. struct cpg_inst *cpg_inst;
  489. struct req_lib_cpg_mcast *req_lib_cpg_mcast;
  490. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  491. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  492. if (error != CS_OK) {
  493. return (error);
  494. }
  495. req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast));
  496. req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) +
  497. msg_len;
  498. req_lib_cpg_mcast->header.id = MESSAGE_REQ_CPG_MCAST;
  499. req_lib_cpg_mcast->guarantee = guarantee;
  500. req_lib_cpg_mcast->msglen = msg_len;
  501. error = coroipcc_zcb_msg_send_reply_receive (
  502. cpg_inst->handle,
  503. req_lib_cpg_mcast,
  504. &res_lib_cpg_mcast,
  505. sizeof (res_lib_cpg_mcast));
  506. if (error != CS_OK) {
  507. goto error_exit;
  508. }
  509. error = res_lib_cpg_mcast.header.error;
  510. error_exit:
  511. hdb_handle_put (&cpg_handle_t_db, handle);
  512. return (error);
  513. }
  514. cs_error_t cpg_mcast_joined (
  515. cpg_handle_t handle,
  516. cpg_guarantee_t guarantee,
  517. const struct iovec *iovec,
  518. unsigned int iov_len)
  519. {
  520. int i;
  521. cs_error_t error;
  522. struct cpg_inst *cpg_inst;
  523. struct iovec iov[64];
  524. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  525. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  526. size_t msg_len = 0;
  527. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  528. if (error != CS_OK) {
  529. return (error);
  530. }
  531. for (i = 0; i < iov_len; i++ ) {
  532. msg_len += iovec[i].iov_len;
  533. }
  534. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  535. msg_len;
  536. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  537. req_lib_cpg_mcast.guarantee = guarantee;
  538. req_lib_cpg_mcast.msglen = msg_len;
  539. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  540. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  541. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  542. error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov,
  543. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  544. if (error != CS_OK) {
  545. goto error_exit;
  546. }
  547. error = res_lib_cpg_mcast.header.error;
  548. error_exit:
  549. hdb_handle_put (&cpg_handle_t_db, handle);
  550. return (error);
  551. }
  552. /** @} */