cpg.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2006-2015 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 <stdio.h>
  43. #include <string.h>
  44. #include <unistd.h>
  45. #include <sys/types.h>
  46. #include <sys/socket.h>
  47. #include <sys/mman.h>
  48. #include <sys/uio.h>
  49. #include <sys/stat.h>
  50. #include <errno.h>
  51. #include <limits.h>
  52. #include <qb/qblist.h>
  53. #include <qb/qbdefs.h>
  54. #include <qb/qbipcc.h>
  55. #include <qb/qblog.h>
  56. #include <corosync/hdb.h>
  57. #include <corosync/corotypes.h>
  58. #include <corosync/corodefs.h>
  59. #include <corosync/cpg.h>
  60. #include <corosync/ipc_cpg.h>
  61. #include "util.h"
  62. #ifndef MAP_ANONYMOUS
  63. #define MAP_ANONYMOUS MAP_ANON
  64. #endif
  65. /*
  66. * Maximum number of times to retry a send when transmitting
  67. * a large message fragment
  68. */
  69. #define MAX_RETRIES 100
  70. struct cpg_assembly_data
  71. {
  72. struct qb_list_head list;
  73. uint32_t nodeid;
  74. uint32_t pid;
  75. char *assembly_buf;
  76. uint32_t assembly_buf_ptr;
  77. };
  78. struct cpg_inst {
  79. qb_ipcc_connection_t *c;
  80. int finalize;
  81. void *context;
  82. union {
  83. cpg_model_data_t model_data;
  84. cpg_model_v1_data_t model_v1_data;
  85. };
  86. struct qb_list_head iteration_list_head;
  87. uint32_t max_msg_size;
  88. struct qb_list_head assembly_list_head;
  89. };
  90. static void cpg_inst_free (void *inst);
  91. DECLARE_HDB_DATABASE(cpg_handle_t_db, cpg_inst_free);
  92. struct cpg_iteration_instance_t {
  93. cpg_iteration_handle_t cpg_iteration_handle;
  94. qb_ipcc_connection_t *conn;
  95. hdb_handle_t executive_iteration_handle;
  96. struct qb_list_head list;
  97. };
  98. DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
  99. /*
  100. * Internal (not visible by API) functions
  101. */
  102. static cs_error_t
  103. coroipcc_msg_send_reply_receive (
  104. qb_ipcc_connection_t *c,
  105. const struct iovec *iov,
  106. unsigned int iov_len,
  107. void *res_msg,
  108. size_t res_len)
  109. {
  110. return qb_to_cs_error(qb_ipcc_sendv_recv(c, iov, iov_len, res_msg, res_len,
  111. CS_IPC_TIMEOUT_MS));
  112. }
  113. static void cpg_iteration_instance_finalize (struct cpg_iteration_instance_t *cpg_iteration_instance)
  114. {
  115. qb_list_del (&cpg_iteration_instance->list);
  116. hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->cpg_iteration_handle);
  117. }
  118. static void cpg_inst_free (void *inst)
  119. {
  120. struct cpg_inst *cpg_inst = (struct cpg_inst *)inst;
  121. qb_ipcc_disconnect(cpg_inst->c);
  122. }
  123. static void cpg_inst_finalize (struct cpg_inst *cpg_inst, hdb_handle_t handle)
  124. {
  125. struct qb_list_head *iter, *tmp_iter;
  126. struct cpg_iteration_instance_t *cpg_iteration_instance;
  127. /*
  128. * Traverse thru iteration instances and delete them
  129. */
  130. qb_list_for_each_safe(iter, tmp_iter, &(cpg_inst->iteration_list_head)) {
  131. cpg_iteration_instance = qb_list_entry (iter, struct cpg_iteration_instance_t, list);
  132. cpg_iteration_instance_finalize (cpg_iteration_instance);
  133. }
  134. hdb_handle_destroy (&cpg_handle_t_db, handle);
  135. }
  136. /**
  137. * @defgroup cpg_coroipcc The closed process group API
  138. * @ingroup coroipcc
  139. *
  140. * @{
  141. */
  142. cs_error_t cpg_initialize (
  143. cpg_handle_t *handle,
  144. cpg_callbacks_t *callbacks)
  145. {
  146. cpg_model_v1_data_t model_v1_data;
  147. memset (&model_v1_data, 0, sizeof (cpg_model_v1_data_t));
  148. if (callbacks) {
  149. model_v1_data.cpg_deliver_fn = callbacks->cpg_deliver_fn;
  150. model_v1_data.cpg_confchg_fn = callbacks->cpg_confchg_fn;
  151. }
  152. return (cpg_model_initialize (handle, CPG_MODEL_V1, (cpg_model_data_t *)&model_v1_data, NULL));
  153. }
  154. cs_error_t cpg_model_initialize (
  155. cpg_handle_t *handle,
  156. cpg_model_t model,
  157. cpg_model_data_t *model_data,
  158. void *context)
  159. {
  160. cs_error_t error;
  161. struct cpg_inst *cpg_inst;
  162. if (model != CPG_MODEL_V1) {
  163. error = CS_ERR_INVALID_PARAM;
  164. goto error_no_destroy;
  165. }
  166. error = hdb_error_to_cs (hdb_handle_create (&cpg_handle_t_db, sizeof (struct cpg_inst), handle));
  167. if (error != CS_OK) {
  168. goto error_no_destroy;
  169. }
  170. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, *handle, (void *)&cpg_inst));
  171. if (error != CS_OK) {
  172. goto error_destroy;
  173. }
  174. cpg_inst->c = qb_ipcc_connect ("cpg", IPC_REQUEST_SIZE);
  175. if (cpg_inst->c == NULL) {
  176. error = qb_to_cs_error(-errno);
  177. goto error_put_destroy;
  178. }
  179. if (model_data != NULL) {
  180. switch (model) {
  181. case CPG_MODEL_V1:
  182. memcpy (&cpg_inst->model_v1_data, model_data, sizeof (cpg_model_v1_data_t));
  183. if ((cpg_inst->model_v1_data.flags & ~(CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF)) != 0) {
  184. error = CS_ERR_INVALID_PARAM;
  185. goto error_destroy;
  186. }
  187. break;
  188. }
  189. }
  190. /* Allow space for corosync internal headers */
  191. cpg_inst->max_msg_size = IPC_REQUEST_SIZE - 1024;
  192. cpg_inst->model_data.model = model;
  193. cpg_inst->context = context;
  194. qb_list_init(&cpg_inst->iteration_list_head);
  195. qb_list_init(&cpg_inst->assembly_list_head);
  196. hdb_handle_put (&cpg_handle_t_db, *handle);
  197. return (CS_OK);
  198. error_put_destroy:
  199. hdb_handle_put (&cpg_handle_t_db, *handle);
  200. error_destroy:
  201. hdb_handle_destroy (&cpg_handle_t_db, *handle);
  202. error_no_destroy:
  203. return (error);
  204. }
  205. cs_error_t cpg_finalize (
  206. cpg_handle_t handle)
  207. {
  208. struct cpg_inst *cpg_inst;
  209. struct iovec iov;
  210. struct req_lib_cpg_finalize req_lib_cpg_finalize;
  211. struct res_lib_cpg_finalize res_lib_cpg_finalize;
  212. cs_error_t error;
  213. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  214. if (error != CS_OK) {
  215. return (error);
  216. }
  217. /*
  218. * Another thread has already started finalizing
  219. */
  220. if (cpg_inst->finalize) {
  221. hdb_handle_put (&cpg_handle_t_db, handle);
  222. return (CS_ERR_BAD_HANDLE);
  223. }
  224. cpg_inst->finalize = 1;
  225. /*
  226. * Send service request
  227. */
  228. req_lib_cpg_finalize.header.size = sizeof (struct req_lib_cpg_finalize);
  229. req_lib_cpg_finalize.header.id = MESSAGE_REQ_CPG_FINALIZE;
  230. iov.iov_base = (void *)&req_lib_cpg_finalize;
  231. iov.iov_len = sizeof (struct req_lib_cpg_finalize);
  232. error = coroipcc_msg_send_reply_receive (cpg_inst->c,
  233. &iov,
  234. 1,
  235. &res_lib_cpg_finalize,
  236. sizeof (struct res_lib_cpg_finalize));
  237. cpg_inst_finalize (cpg_inst, handle);
  238. hdb_handle_put (&cpg_handle_t_db, handle);
  239. return (error);
  240. }
  241. cs_error_t cpg_fd_get (
  242. cpg_handle_t handle,
  243. int *fd)
  244. {
  245. cs_error_t error;
  246. struct cpg_inst *cpg_inst;
  247. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  248. if (error != CS_OK) {
  249. return (error);
  250. }
  251. error = qb_to_cs_error (qb_ipcc_fd_get (cpg_inst->c, fd));
  252. hdb_handle_put (&cpg_handle_t_db, handle);
  253. return (error);
  254. }
  255. cs_error_t cpg_max_atomic_msgsize_get (
  256. cpg_handle_t handle,
  257. uint32_t *size)
  258. {
  259. cs_error_t error;
  260. struct cpg_inst *cpg_inst;
  261. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  262. if (error != CS_OK) {
  263. return (error);
  264. }
  265. *size = cpg_inst->max_msg_size;
  266. hdb_handle_put (&cpg_handle_t_db, handle);
  267. return (error);
  268. }
  269. cs_error_t cpg_context_get (
  270. cpg_handle_t handle,
  271. void **context)
  272. {
  273. cs_error_t error;
  274. struct cpg_inst *cpg_inst;
  275. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  276. if (error != CS_OK) {
  277. return (error);
  278. }
  279. *context = cpg_inst->context;
  280. hdb_handle_put (&cpg_handle_t_db, handle);
  281. return (CS_OK);
  282. }
  283. cs_error_t cpg_context_set (
  284. cpg_handle_t handle,
  285. void *context)
  286. {
  287. cs_error_t error;
  288. struct cpg_inst *cpg_inst;
  289. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  290. if (error != CS_OK) {
  291. return (error);
  292. }
  293. cpg_inst->context = context;
  294. hdb_handle_put (&cpg_handle_t_db, handle);
  295. return (CS_OK);
  296. }
  297. cs_error_t cpg_dispatch (
  298. cpg_handle_t handle,
  299. cs_dispatch_flags_t dispatch_types)
  300. {
  301. int timeout = -1;
  302. cs_error_t error;
  303. int cont = 1; /* always continue do loop except when set to 0 */
  304. struct cpg_inst *cpg_inst;
  305. struct res_lib_cpg_confchg_callback *res_cpg_confchg_callback;
  306. struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback;
  307. struct res_lib_cpg_partial_deliver_callback *res_cpg_partial_deliver_callback;
  308. struct res_lib_cpg_totem_confchg_callback *res_cpg_totem_confchg_callback;
  309. struct cpg_inst cpg_inst_copy;
  310. struct qb_ipc_response_header *dispatch_data;
  311. struct cpg_address member_list[CPG_MEMBERS_MAX];
  312. struct cpg_address left_list[CPG_MEMBERS_MAX];
  313. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  314. struct cpg_name group_name;
  315. struct cpg_assembly_data *assembly_data;
  316. struct qb_list_head *iter, *tmp_iter;
  317. mar_cpg_address_t *left_list_start;
  318. mar_cpg_address_t *joined_list_start;
  319. unsigned int i;
  320. struct cpg_ring_id ring_id;
  321. uint32_t totem_member_list[CPG_MEMBERS_MAX];
  322. int32_t errno_res;
  323. char dispatch_buf[IPC_DISPATCH_SIZE];
  324. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  325. if (error != CS_OK) {
  326. return (error);
  327. }
  328. /*
  329. * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  330. * wait indefinitely for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  331. */
  332. if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  333. timeout = 0;
  334. }
  335. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  336. do {
  337. errno_res = qb_ipcc_event_recv (
  338. cpg_inst->c,
  339. dispatch_buf,
  340. IPC_DISPATCH_SIZE,
  341. timeout);
  342. error = qb_to_cs_error (errno_res);
  343. if (error == CS_ERR_BAD_HANDLE) {
  344. error = CS_OK;
  345. goto error_put;
  346. }
  347. if (error == CS_ERR_TRY_AGAIN) {
  348. if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  349. /*
  350. * Don't mask error
  351. */
  352. goto error_put;
  353. }
  354. error = CS_OK;
  355. if (dispatch_types == CS_DISPATCH_ALL) {
  356. break; /* exit do while cont is 1 loop */
  357. } else {
  358. continue; /* next poll */
  359. }
  360. }
  361. if (error != CS_OK) {
  362. goto error_put;
  363. }
  364. /*
  365. * Make copy of callbacks, message data, unlock instance, and call callback
  366. * A risk of this dispatch method is that the callback routines may
  367. * operate at the same time that cpgFinalize has been called.
  368. */
  369. memcpy (&cpg_inst_copy, cpg_inst, sizeof (struct cpg_inst));
  370. switch (cpg_inst_copy.model_data.model) {
  371. case CPG_MODEL_V1:
  372. /*
  373. * Dispatch incoming message
  374. */
  375. switch (dispatch_data->id) {
  376. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  377. if (cpg_inst_copy.model_v1_data.cpg_deliver_fn == NULL) {
  378. break;
  379. }
  380. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)dispatch_data;
  381. marshall_from_mar_cpg_name_t (
  382. &group_name,
  383. &res_cpg_deliver_callback->group_name);
  384. cpg_inst_copy.model_v1_data.cpg_deliver_fn (handle,
  385. &group_name,
  386. res_cpg_deliver_callback->nodeid,
  387. res_cpg_deliver_callback->pid,
  388. &res_cpg_deliver_callback->message,
  389. res_cpg_deliver_callback->msglen);
  390. break;
  391. case MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK:
  392. res_cpg_partial_deliver_callback = (struct res_lib_cpg_partial_deliver_callback *)dispatch_data;
  393. marshall_from_mar_cpg_name_t (
  394. &group_name,
  395. &res_cpg_partial_deliver_callback->group_name);
  396. /*
  397. * Search for assembly data for current messages (nodeid, pid) pair in list of assemblies
  398. */
  399. assembly_data = NULL;
  400. qb_list_for_each(iter, &(cpg_inst->assembly_list_head)) {
  401. struct cpg_assembly_data *current_assembly_data = qb_list_entry (iter, struct cpg_assembly_data, list);
  402. if (current_assembly_data->nodeid == res_cpg_partial_deliver_callback->nodeid && current_assembly_data->pid == res_cpg_partial_deliver_callback->pid) {
  403. assembly_data = current_assembly_data;
  404. break;
  405. }
  406. }
  407. if (res_cpg_partial_deliver_callback->type == LIBCPG_PARTIAL_FIRST) {
  408. /*
  409. * As this is LIBCPG_PARTIAL_FIRST packet, check that there is no ongoing assembly.
  410. * Otherwise the sending of packet must have been interrupted and error should have
  411. * been reported to sending client. Therefore here last assembly will be dropped.
  412. */
  413. if (assembly_data) {
  414. qb_list_del (&assembly_data->list);
  415. free(assembly_data->assembly_buf);
  416. free(assembly_data);
  417. // coverity[UNUSED_VALUE:SUPPRESS] defensive programming
  418. assembly_data = NULL;
  419. }
  420. assembly_data = malloc(sizeof(struct cpg_assembly_data));
  421. if (!assembly_data) {
  422. error = CS_ERR_NO_MEMORY;
  423. goto error_put;
  424. }
  425. assembly_data->nodeid = res_cpg_partial_deliver_callback->nodeid;
  426. assembly_data->pid = res_cpg_partial_deliver_callback->pid;
  427. assembly_data->assembly_buf = malloc(res_cpg_partial_deliver_callback->msglen);
  428. if (!assembly_data->assembly_buf) {
  429. free(assembly_data);
  430. error = CS_ERR_NO_MEMORY;
  431. goto error_put;
  432. }
  433. assembly_data->assembly_buf_ptr = 0;
  434. qb_list_init (&assembly_data->list);
  435. qb_list_add (&assembly_data->list, &cpg_inst->assembly_list_head);
  436. }
  437. if (assembly_data) {
  438. memcpy(assembly_data->assembly_buf + assembly_data->assembly_buf_ptr,
  439. res_cpg_partial_deliver_callback->message, res_cpg_partial_deliver_callback->fraglen);
  440. assembly_data->assembly_buf_ptr += res_cpg_partial_deliver_callback->fraglen;
  441. if (res_cpg_partial_deliver_callback->type == LIBCPG_PARTIAL_LAST) {
  442. if (cpg_inst_copy.model_v1_data.cpg_deliver_fn != NULL) {
  443. cpg_inst_copy.model_v1_data.cpg_deliver_fn (handle,
  444. &group_name,
  445. res_cpg_partial_deliver_callback->nodeid,
  446. res_cpg_partial_deliver_callback->pid,
  447. assembly_data->assembly_buf,
  448. res_cpg_partial_deliver_callback->msglen);
  449. }
  450. qb_list_del (&assembly_data->list);
  451. free(assembly_data->assembly_buf);
  452. free(assembly_data);
  453. }
  454. }
  455. break;
  456. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  457. if (cpg_inst_copy.model_v1_data.cpg_confchg_fn == NULL) {
  458. break;
  459. }
  460. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)dispatch_data;
  461. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  462. marshall_from_mar_cpg_address_t (&member_list[i],
  463. &res_cpg_confchg_callback->member_list[i]);
  464. }
  465. left_list_start = res_cpg_confchg_callback->member_list +
  466. res_cpg_confchg_callback->member_list_entries;
  467. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  468. marshall_from_mar_cpg_address_t (&left_list[i],
  469. &left_list_start[i]);
  470. }
  471. joined_list_start = res_cpg_confchg_callback->member_list +
  472. res_cpg_confchg_callback->member_list_entries +
  473. res_cpg_confchg_callback->left_list_entries;
  474. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  475. marshall_from_mar_cpg_address_t (&joined_list[i],
  476. &joined_list_start[i]);
  477. }
  478. marshall_from_mar_cpg_name_t (
  479. &group_name,
  480. &res_cpg_confchg_callback->group_name);
  481. cpg_inst_copy.model_v1_data.cpg_confchg_fn (handle,
  482. &group_name,
  483. member_list,
  484. res_cpg_confchg_callback->member_list_entries,
  485. left_list,
  486. res_cpg_confchg_callback->left_list_entries,
  487. joined_list,
  488. res_cpg_confchg_callback->joined_list_entries);
  489. /*
  490. * If member left while his partial packet was being assembled, assembly data must be removed from list
  491. */
  492. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  493. qb_list_for_each_safe(iter, tmp_iter, &(cpg_inst->assembly_list_head)) {
  494. struct cpg_assembly_data *current_assembly_data = qb_list_entry (iter, struct cpg_assembly_data, list);
  495. if (current_assembly_data->nodeid != left_list[i].nodeid || current_assembly_data->pid != left_list[i].pid)
  496. continue;
  497. qb_list_del (&current_assembly_data->list);
  498. free(current_assembly_data->assembly_buf);
  499. free(current_assembly_data);
  500. }
  501. }
  502. break;
  503. case MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK:
  504. if (cpg_inst_copy.model_v1_data.cpg_totem_confchg_fn == NULL) {
  505. break;
  506. }
  507. res_cpg_totem_confchg_callback = (struct res_lib_cpg_totem_confchg_callback *)dispatch_data;
  508. marshall_from_mar_cpg_ring_id_t (&ring_id, &res_cpg_totem_confchg_callback->ring_id);
  509. for (i = 0; i < res_cpg_totem_confchg_callback->member_list_entries; i++) {
  510. totem_member_list[i] = res_cpg_totem_confchg_callback->member_list[i];
  511. }
  512. cpg_inst_copy.model_v1_data.cpg_totem_confchg_fn (handle,
  513. ring_id,
  514. res_cpg_totem_confchg_callback->member_list_entries,
  515. totem_member_list);
  516. break;
  517. default:
  518. error = CS_ERR_LIBRARY;
  519. goto error_put;
  520. break;
  521. } /* - switch (dispatch_data->id) */
  522. break; /* case CPG_MODEL_V1 */
  523. } /* - switch (cpg_inst_copy.model_data.model) */
  524. if (cpg_inst_copy.finalize || cpg_inst->finalize) {
  525. /*
  526. * If the finalize has been called then get out of the dispatch.
  527. */
  528. cpg_inst->finalize = 1;
  529. error = CS_ERR_BAD_HANDLE;
  530. goto error_put;
  531. }
  532. /*
  533. * Determine if more messages should be processed
  534. */
  535. if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  536. cont = 0;
  537. }
  538. } while (cont);
  539. error_put:
  540. hdb_handle_put (&cpg_handle_t_db, handle);
  541. return (error);
  542. }
  543. cs_error_t cpg_join (
  544. cpg_handle_t handle,
  545. const struct cpg_name *group)
  546. {
  547. cs_error_t error;
  548. struct cpg_inst *cpg_inst;
  549. struct iovec iov[2];
  550. struct req_lib_cpg_join req_lib_cpg_join;
  551. struct res_lib_cpg_join response;
  552. if (group->length > CPG_MAX_NAME_LENGTH) {
  553. return (CS_ERR_NAME_TOO_LONG);
  554. }
  555. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  556. if (error != CS_OK) {
  557. return (error);
  558. }
  559. /* Now join */
  560. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  561. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  562. req_lib_cpg_join.pid = getpid();
  563. req_lib_cpg_join.flags = 0;
  564. switch (cpg_inst->model_data.model) {
  565. case CPG_MODEL_V1:
  566. req_lib_cpg_join.flags = cpg_inst->model_v1_data.flags;
  567. break;
  568. }
  569. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  570. group);
  571. iov[0].iov_base = (void *)&req_lib_cpg_join;
  572. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  573. do {
  574. error = coroipcc_msg_send_reply_receive (cpg_inst->c, iov, 1,
  575. &response, sizeof (struct res_lib_cpg_join));
  576. if (error != CS_OK) {
  577. goto error_exit;
  578. }
  579. } while (response.header.error == CS_ERR_BUSY);
  580. error = response.header.error;
  581. error_exit:
  582. hdb_handle_put (&cpg_handle_t_db, handle);
  583. return (error);
  584. }
  585. cs_error_t cpg_leave (
  586. cpg_handle_t handle,
  587. const struct cpg_name *group)
  588. {
  589. cs_error_t error;
  590. struct cpg_inst *cpg_inst;
  591. struct iovec iov[2];
  592. struct req_lib_cpg_leave req_lib_cpg_leave;
  593. struct res_lib_cpg_leave res_lib_cpg_leave;
  594. if (group->length > CPG_MAX_NAME_LENGTH) {
  595. return (CS_ERR_NAME_TOO_LONG);
  596. }
  597. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  598. if (error != CS_OK) {
  599. return (error);
  600. }
  601. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  602. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  603. req_lib_cpg_leave.pid = getpid();
  604. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  605. group);
  606. iov[0].iov_base = (void *)&req_lib_cpg_leave;
  607. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  608. do {
  609. error = coroipcc_msg_send_reply_receive (cpg_inst->c, iov, 1,
  610. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  611. if (error != CS_OK) {
  612. goto error_exit;
  613. }
  614. } while (res_lib_cpg_leave.header.error == CS_ERR_BUSY);
  615. error = res_lib_cpg_leave.header.error;
  616. error_exit:
  617. hdb_handle_put (&cpg_handle_t_db, handle);
  618. return (error);
  619. }
  620. cs_error_t cpg_membership_get (
  621. cpg_handle_t handle,
  622. struct cpg_name *group_name,
  623. struct cpg_address *member_list,
  624. int *member_list_entries)
  625. {
  626. cs_error_t error;
  627. struct cpg_inst *cpg_inst;
  628. struct iovec iov;
  629. struct req_lib_cpg_membership_get req_lib_cpg_membership_get;
  630. struct res_lib_cpg_membership_get res_lib_cpg_membership_get;
  631. unsigned int i;
  632. if (group_name->length > CPG_MAX_NAME_LENGTH) {
  633. return (CS_ERR_NAME_TOO_LONG);
  634. }
  635. if (member_list == NULL) {
  636. return (CS_ERR_INVALID_PARAM);
  637. }
  638. if (member_list_entries == NULL) {
  639. return (CS_ERR_INVALID_PARAM);
  640. }
  641. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  642. if (error != CS_OK) {
  643. return (error);
  644. }
  645. req_lib_cpg_membership_get.header.size = sizeof (struct req_lib_cpg_membership_get);
  646. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  647. marshall_to_mar_cpg_name_t (&req_lib_cpg_membership_get.group_name,
  648. group_name);
  649. iov.iov_base = (void *)&req_lib_cpg_membership_get;
  650. iov.iov_len = sizeof (struct req_lib_cpg_membership_get);
  651. error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1,
  652. &res_lib_cpg_membership_get, sizeof (res_lib_cpg_membership_get));
  653. if (error != CS_OK) {
  654. goto error_exit;
  655. }
  656. error = res_lib_cpg_membership_get.header.error;
  657. /*
  658. * Copy results to caller
  659. */
  660. *member_list_entries = res_lib_cpg_membership_get.member_count;
  661. if (member_list) {
  662. for (i = 0; i < res_lib_cpg_membership_get.member_count; i++) {
  663. marshall_from_mar_cpg_address_t (&member_list[i],
  664. &res_lib_cpg_membership_get.member_list[i]);
  665. }
  666. }
  667. error_exit:
  668. hdb_handle_put (&cpg_handle_t_db, handle);
  669. return (error);
  670. }
  671. cs_error_t cpg_local_get (
  672. cpg_handle_t handle,
  673. unsigned int *local_nodeid)
  674. {
  675. cs_error_t error;
  676. struct cpg_inst *cpg_inst;
  677. struct iovec iov;
  678. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  679. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  680. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  681. if (error != CS_OK) {
  682. return (error);
  683. }
  684. req_lib_cpg_local_get.header.size = sizeof (struct qb_ipc_request_header);
  685. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  686. iov.iov_base = (void *)&req_lib_cpg_local_get;
  687. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  688. error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1,
  689. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  690. if (error != CS_OK) {
  691. goto error_exit;
  692. }
  693. error = res_lib_cpg_local_get.header.error;
  694. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  695. error_exit:
  696. hdb_handle_put (&cpg_handle_t_db, handle);
  697. return (error);
  698. }
  699. cs_error_t cpg_flow_control_state_get (
  700. cpg_handle_t handle,
  701. cpg_flow_control_state_t *flow_control_state)
  702. {
  703. cs_error_t error;
  704. struct cpg_inst *cpg_inst;
  705. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  706. if (error != CS_OK) {
  707. return (error);
  708. }
  709. *flow_control_state = CPG_FLOW_CONTROL_DISABLED;
  710. error = CS_OK;
  711. hdb_handle_put (&cpg_handle_t_db, handle);
  712. return (error);
  713. }
  714. /*
  715. * Dummy-ish function that just allocates some memory for the user
  716. */
  717. cs_error_t cpg_zcb_alloc (
  718. cpg_handle_t handle,
  719. size_t size,
  720. void **buffer)
  721. {
  722. int error = CS_OK;
  723. *buffer = malloc(size);
  724. if (*buffer == NULL) {
  725. error = CS_ERR_NO_MEMORY;
  726. }
  727. return (error);
  728. }
  729. cs_error_t cpg_zcb_free (
  730. cpg_handle_t handle,
  731. void *buffer)
  732. {
  733. free(buffer);
  734. return (CS_OK);
  735. }
  736. cs_error_t cpg_zcb_mcast_joined (
  737. cpg_handle_t handle,
  738. cpg_guarantee_t guarantee,
  739. void *msg,
  740. size_t msg_len)
  741. {
  742. struct iovec iov[1];
  743. iov[0].iov_base = msg;
  744. iov[0].iov_len = msg_len;
  745. return cpg_mcast_joined(handle, guarantee, iov, 1);
  746. }
  747. static cs_error_t send_fragments (
  748. struct cpg_inst *cpg_inst,
  749. cpg_guarantee_t guarantee,
  750. size_t msg_len,
  751. const struct iovec *iovec,
  752. unsigned int iov_len)
  753. {
  754. int i;
  755. cs_error_t error = CS_OK;
  756. struct iovec iov[2];
  757. struct req_lib_cpg_partial_mcast req_lib_cpg_mcast;
  758. struct res_lib_cpg_partial_send res_lib_cpg_partial_send;
  759. size_t sent = 0;
  760. size_t iov_sent = 0;
  761. int retry_count;
  762. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_PARTIAL_MCAST;
  763. req_lib_cpg_mcast.guarantee = guarantee;
  764. req_lib_cpg_mcast.msglen = msg_len;
  765. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  766. iov[0].iov_len = sizeof (struct req_lib_cpg_partial_mcast);
  767. i=0;
  768. iov_sent = 0 ;
  769. qb_ipcc_fc_enable_max_set(cpg_inst->c, 2);
  770. while (error == CS_OK && sent < msg_len) {
  771. retry_count = 0;
  772. if ( (iovec[i].iov_len - iov_sent) > cpg_inst->max_msg_size) {
  773. iov[1].iov_len = cpg_inst->max_msg_size;
  774. }
  775. else {
  776. iov[1].iov_len = iovec[i].iov_len - iov_sent;
  777. }
  778. if (sent == 0) {
  779. req_lib_cpg_mcast.type = LIBCPG_PARTIAL_FIRST;
  780. }
  781. else if ((sent + iov[1].iov_len) == msg_len) {
  782. req_lib_cpg_mcast.type = LIBCPG_PARTIAL_LAST;
  783. }
  784. else {
  785. req_lib_cpg_mcast.type = LIBCPG_PARTIAL_CONTINUED;
  786. }
  787. req_lib_cpg_mcast.fraglen = iov[1].iov_len;
  788. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_partial_mcast) + iov[1].iov_len;
  789. iov[1].iov_base = (char *)iovec[i].iov_base + iov_sent;
  790. resend:
  791. error = coroipcc_msg_send_reply_receive (cpg_inst->c, iov, 2,
  792. &res_lib_cpg_partial_send,
  793. sizeof (res_lib_cpg_partial_send));
  794. if (error == CS_ERR_TRY_AGAIN) {
  795. fprintf(stderr, "sleep. counter=%d\n", retry_count);
  796. if (++retry_count > MAX_RETRIES) {
  797. goto error_exit;
  798. }
  799. usleep(10000);
  800. goto resend;
  801. }
  802. iov_sent += iov[1].iov_len;
  803. sent += iov[1].iov_len;
  804. /* Next iovec */
  805. if (iov_sent >= iovec[i].iov_len) {
  806. i++;
  807. iov_sent = 0;
  808. }
  809. error = res_lib_cpg_partial_send.header.error;
  810. }
  811. error_exit:
  812. qb_ipcc_fc_enable_max_set(cpg_inst->c, 1);
  813. return error;
  814. }
  815. cs_error_t cpg_mcast_joined (
  816. cpg_handle_t handle,
  817. cpg_guarantee_t guarantee,
  818. const struct iovec *iovec,
  819. unsigned int iov_len)
  820. {
  821. int i;
  822. cs_error_t error;
  823. struct cpg_inst *cpg_inst;
  824. struct iovec iov[64];
  825. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  826. size_t msg_len = 0;
  827. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  828. if (error != CS_OK) {
  829. return (error);
  830. }
  831. for (i = 0; i < iov_len; i++ ) {
  832. msg_len += iovec[i].iov_len;
  833. }
  834. if (msg_len > cpg_inst->max_msg_size) {
  835. error = send_fragments(cpg_inst, guarantee, msg_len, iovec, iov_len);
  836. goto error_exit;
  837. }
  838. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  839. msg_len;
  840. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  841. req_lib_cpg_mcast.guarantee = guarantee;
  842. req_lib_cpg_mcast.msglen = msg_len;
  843. iov[0].iov_base = (void *)&req_lib_cpg_mcast;
  844. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  845. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  846. qb_ipcc_fc_enable_max_set(cpg_inst->c, 2);
  847. error = qb_to_cs_error(qb_ipcc_sendv(cpg_inst->c, iov, iov_len + 1));
  848. qb_ipcc_fc_enable_max_set(cpg_inst->c, 1);
  849. error_exit:
  850. hdb_handle_put (&cpg_handle_t_db, handle);
  851. return (error);
  852. }
  853. cs_error_t cpg_iteration_initialize(
  854. cpg_handle_t handle,
  855. cpg_iteration_type_t iteration_type,
  856. const struct cpg_name *group,
  857. cpg_iteration_handle_t *cpg_iteration_handle)
  858. {
  859. cs_error_t error;
  860. struct iovec iov;
  861. struct cpg_inst *cpg_inst;
  862. struct cpg_iteration_instance_t *cpg_iteration_instance;
  863. struct req_lib_cpg_iterationinitialize req_lib_cpg_iterationinitialize;
  864. struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
  865. if (group && group->length > CPG_MAX_NAME_LENGTH) {
  866. return (CS_ERR_NAME_TOO_LONG);
  867. }
  868. if (cpg_iteration_handle == NULL) {
  869. return (CS_ERR_INVALID_PARAM);
  870. }
  871. if ((iteration_type == CPG_ITERATION_ONE_GROUP && group == NULL) ||
  872. (iteration_type != CPG_ITERATION_ONE_GROUP && group != NULL)) {
  873. return (CS_ERR_INVALID_PARAM);
  874. }
  875. if (iteration_type != CPG_ITERATION_NAME_ONLY && iteration_type != CPG_ITERATION_ONE_GROUP &&
  876. iteration_type != CPG_ITERATION_ALL) {
  877. return (CS_ERR_INVALID_PARAM);
  878. }
  879. error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
  880. if (error != CS_OK) {
  881. return (error);
  882. }
  883. error = hdb_error_to_cs (hdb_handle_create (&cpg_iteration_handle_t_db,
  884. sizeof (struct cpg_iteration_instance_t), cpg_iteration_handle));
  885. if (error != CS_OK) {
  886. goto error_put_cpg_db;
  887. }
  888. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, *cpg_iteration_handle,
  889. (void *)&cpg_iteration_instance));
  890. if (error != CS_OK) {
  891. goto error_destroy;
  892. }
  893. cpg_iteration_instance->conn = cpg_inst->c;
  894. qb_list_init (&cpg_iteration_instance->list);
  895. req_lib_cpg_iterationinitialize.header.size = sizeof (struct req_lib_cpg_iterationinitialize);
  896. req_lib_cpg_iterationinitialize.header.id = MESSAGE_REQ_CPG_ITERATIONINITIALIZE;
  897. req_lib_cpg_iterationinitialize.iteration_type = iteration_type;
  898. if (group) {
  899. marshall_to_mar_cpg_name_t (&req_lib_cpg_iterationinitialize.group_name, group);
  900. }
  901. iov.iov_base = (void *)&req_lib_cpg_iterationinitialize;
  902. iov.iov_len = sizeof (struct req_lib_cpg_iterationinitialize);
  903. error = coroipcc_msg_send_reply_receive (cpg_inst->c,
  904. &iov,
  905. 1,
  906. &res_lib_cpg_iterationinitialize,
  907. sizeof (struct res_lib_cpg_iterationinitialize));
  908. if (error != CS_OK) {
  909. goto error_put_destroy;
  910. }
  911. cpg_iteration_instance->executive_iteration_handle =
  912. res_lib_cpg_iterationinitialize.iteration_handle;
  913. cpg_iteration_instance->cpg_iteration_handle = *cpg_iteration_handle;
  914. qb_list_add (&cpg_iteration_instance->list, &cpg_inst->iteration_list_head);
  915. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  916. hdb_handle_put (&cpg_handle_t_db, handle);
  917. return (res_lib_cpg_iterationinitialize.header.error);
  918. error_put_destroy:
  919. hdb_handle_put (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  920. error_destroy:
  921. hdb_handle_destroy (&cpg_iteration_handle_t_db, *cpg_iteration_handle);
  922. error_put_cpg_db:
  923. hdb_handle_put (&cpg_handle_t_db, handle);
  924. return (error);
  925. }
  926. cs_error_t cpg_iteration_next(
  927. cpg_iteration_handle_t handle,
  928. struct cpg_iteration_description_t *description)
  929. {
  930. cs_error_t error;
  931. struct cpg_iteration_instance_t *cpg_iteration_instance;
  932. struct req_lib_cpg_iterationnext req_lib_cpg_iterationnext;
  933. struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext;
  934. if (description == NULL) {
  935. return CS_ERR_INVALID_PARAM;
  936. }
  937. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  938. (void *)&cpg_iteration_instance));
  939. if (error != CS_OK) {
  940. goto error_exit;
  941. }
  942. req_lib_cpg_iterationnext.header.size = sizeof (struct req_lib_cpg_iterationnext);
  943. req_lib_cpg_iterationnext.header.id = MESSAGE_REQ_CPG_ITERATIONNEXT;
  944. req_lib_cpg_iterationnext.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  945. error = qb_to_cs_error (qb_ipcc_send (cpg_iteration_instance->conn,
  946. &req_lib_cpg_iterationnext,
  947. req_lib_cpg_iterationnext.header.size));
  948. if (error != CS_OK) {
  949. goto error_put;
  950. }
  951. error = qb_to_cs_error (qb_ipcc_recv (cpg_iteration_instance->conn,
  952. &res_lib_cpg_iterationnext,
  953. sizeof(struct res_lib_cpg_iterationnext), -1));
  954. if (error != CS_OK) {
  955. goto error_put;
  956. }
  957. marshall_from_mar_cpg_iteration_description_t(
  958. description,
  959. &res_lib_cpg_iterationnext.description);
  960. error = res_lib_cpg_iterationnext.header.error;
  961. error_put:
  962. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  963. error_exit:
  964. return (error);
  965. }
  966. cs_error_t cpg_iteration_finalize (
  967. cpg_iteration_handle_t handle)
  968. {
  969. cs_error_t error;
  970. struct iovec iov;
  971. struct cpg_iteration_instance_t *cpg_iteration_instance;
  972. struct req_lib_cpg_iterationfinalize req_lib_cpg_iterationfinalize;
  973. struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
  974. error = hdb_error_to_cs (hdb_handle_get (&cpg_iteration_handle_t_db, handle,
  975. (void *)&cpg_iteration_instance));
  976. if (error != CS_OK) {
  977. goto error_exit;
  978. }
  979. req_lib_cpg_iterationfinalize.header.size = sizeof (struct req_lib_cpg_iterationfinalize);
  980. req_lib_cpg_iterationfinalize.header.id = MESSAGE_REQ_CPG_ITERATIONFINALIZE;
  981. req_lib_cpg_iterationfinalize.iteration_handle = cpg_iteration_instance->executive_iteration_handle;
  982. iov.iov_base = (void *)&req_lib_cpg_iterationfinalize;
  983. iov.iov_len = sizeof (struct req_lib_cpg_iterationfinalize);
  984. error = coroipcc_msg_send_reply_receive (cpg_iteration_instance->conn,
  985. &iov,
  986. 1,
  987. &res_lib_cpg_iterationfinalize,
  988. sizeof (struct req_lib_cpg_iterationfinalize));
  989. if (error != CS_OK) {
  990. goto error_put;
  991. }
  992. cpg_iteration_instance_finalize (cpg_iteration_instance);
  993. hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->cpg_iteration_handle);
  994. return (res_lib_cpg_iterationfinalize.header.error);
  995. error_put:
  996. hdb_handle_put (&cpg_iteration_handle_t_db, handle);
  997. error_exit:
  998. return (error);
  999. }
  1000. /** @} */