cpg.c 17 KB

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