cpg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2006-2008 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 <pthread.h>
  44. #include <sys/types.h>
  45. #include <sys/socket.h>
  46. #include <errno.h>
  47. #include <corosync/corotypes.h>
  48. #include <corosync/cpg.h>
  49. #include <corosync/ipc_cpg.h>
  50. #include <corosync/mar_cpg.h>
  51. #include <corosync/coroipcc.h>
  52. struct cpg_inst {
  53. void *ipc_ctx;
  54. int finalize;
  55. cpg_callbacks_t callbacks;
  56. void *context;
  57. pthread_mutex_t response_mutex;
  58. pthread_mutex_t dispatch_mutex;
  59. };
  60. static void cpg_instance_destructor (void *instance);
  61. static struct saHandleDatabase cpg_handle_t_db = {
  62. .handleCount = 0,
  63. .handles = 0,
  64. .mutex = PTHREAD_MUTEX_INITIALIZER,
  65. .handleInstanceDestructor = cpg_instance_destructor
  66. };
  67. /*
  68. * Clean up function for a cpg instance (cpg_nitialize) handle
  69. */
  70. static void cpg_instance_destructor (void *instance)
  71. {
  72. struct cpg_inst *cpg_inst = instance;
  73. pthread_mutex_destroy (&cpg_inst->response_mutex);
  74. pthread_mutex_destroy (&cpg_inst->dispatch_mutex);
  75. }
  76. /**
  77. * @defgroup cpg_coroipcc The closed process group API
  78. * @ingroup coroipcc
  79. *
  80. * @{
  81. */
  82. cs_error_t cpg_initialize (
  83. cpg_handle_t *handle,
  84. cpg_callbacks_t *callbacks)
  85. {
  86. cs_error_t error;
  87. struct cpg_inst *cpg_inst;
  88. error = saHandleCreate (&cpg_handle_t_db, sizeof (struct cpg_inst), handle);
  89. if (error != CS_OK) {
  90. goto error_no_destroy;
  91. }
  92. error = saHandleInstanceGet (&cpg_handle_t_db, *handle, (void *)&cpg_inst);
  93. if (error != CS_OK) {
  94. goto error_destroy;
  95. }
  96. error = coroipcc_service_connect (IPC_SOCKET_NAME, CPG_SERVICE, &cpg_inst->ipc_ctx);
  97. if (error != CS_OK) {
  98. goto error_put_destroy;
  99. }
  100. memcpy (&cpg_inst->callbacks, callbacks, sizeof (cpg_callbacks_t));
  101. pthread_mutex_init (&cpg_inst->response_mutex, NULL);
  102. pthread_mutex_init (&cpg_inst->dispatch_mutex, NULL);
  103. saHandleInstancePut (&cpg_handle_t_db, *handle);
  104. return (CS_OK);
  105. error_put_destroy:
  106. saHandleInstancePut (&cpg_handle_t_db, *handle);
  107. error_destroy:
  108. saHandleDestroy (&cpg_handle_t_db, *handle);
  109. error_no_destroy:
  110. return (error);
  111. }
  112. cs_error_t cpg_finalize (
  113. cpg_handle_t handle)
  114. {
  115. struct cpg_inst *cpg_inst;
  116. cs_error_t error;
  117. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  118. if (error != CS_OK) {
  119. return (error);
  120. }
  121. pthread_mutex_lock (&cpg_inst->response_mutex);
  122. /*
  123. * Another thread has already started finalizing
  124. */
  125. if (cpg_inst->finalize) {
  126. pthread_mutex_unlock (&cpg_inst->response_mutex);
  127. saHandleInstancePut (&cpg_handle_t_db, handle);
  128. return (CPG_ERR_BAD_HANDLE);
  129. }
  130. cpg_inst->finalize = 1;
  131. coroipcc_service_disconnect (cpg_inst->ipc_ctx);
  132. pthread_mutex_unlock (&cpg_inst->response_mutex);
  133. saHandleDestroy (&cpg_handle_t_db, handle);
  134. saHandleInstancePut (&cpg_handle_t_db, handle);
  135. return (CPG_OK);
  136. }
  137. cs_error_t cpg_fd_get (
  138. cpg_handle_t handle,
  139. int *fd)
  140. {
  141. cs_error_t error;
  142. struct cpg_inst *cpg_inst;
  143. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  144. if (error != CS_OK) {
  145. return (error);
  146. }
  147. *fd = coroipcc_fd_get (cpg_inst->ipc_ctx);
  148. saHandleInstancePut (&cpg_handle_t_db, handle);
  149. return (CS_OK);
  150. }
  151. cs_error_t cpg_context_get (
  152. cpg_handle_t handle,
  153. void **context)
  154. {
  155. cs_error_t error;
  156. struct cpg_inst *cpg_inst;
  157. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  158. if (error != CS_OK) {
  159. return (error);
  160. }
  161. *context = cpg_inst->context;
  162. saHandleInstancePut (&cpg_handle_t_db, handle);
  163. return (CS_OK);
  164. }
  165. cs_error_t cpg_context_set (
  166. cpg_handle_t handle,
  167. void *context)
  168. {
  169. cs_error_t error;
  170. struct cpg_inst *cpg_inst;
  171. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  172. if (error != CS_OK) {
  173. return (error);
  174. }
  175. cpg_inst->context = context;
  176. saHandleInstancePut (&cpg_handle_t_db, handle);
  177. return (CS_OK);
  178. }
  179. struct res_overlay {
  180. mar_res_header_t header __attribute__((aligned(8)));
  181. char data[512000];
  182. };
  183. cs_error_t cpg_dispatch (
  184. cpg_handle_t handle,
  185. cs_dispatch_flags_t dispatch_types)
  186. {
  187. int timeout = -1;
  188. cs_error_t error;
  189. int cont = 1; /* always continue do loop except when set to 0 */
  190. int dispatch_avail;
  191. struct cpg_inst *cpg_inst;
  192. struct res_lib_cpg_confchg_callback *res_cpg_confchg_callback;
  193. struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback;
  194. cpg_callbacks_t callbacks;
  195. struct res_overlay dispatch_data;
  196. int ignore_dispatch = 0;
  197. struct cpg_address member_list[CPG_MEMBERS_MAX];
  198. struct cpg_address left_list[CPG_MEMBERS_MAX];
  199. struct cpg_address joined_list[CPG_MEMBERS_MAX];
  200. struct cpg_name group_name;
  201. mar_cpg_address_t *left_list_start;
  202. mar_cpg_address_t *joined_list_start;
  203. unsigned int i;
  204. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  205. if (error != CS_OK) {
  206. return (error);
  207. }
  208. /*
  209. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  210. * wait indefinately for SA_DISPATCH_BLOCKING
  211. */
  212. if (dispatch_types == CPG_DISPATCH_ALL) {
  213. timeout = 0;
  214. }
  215. do {
  216. pthread_mutex_lock (&cpg_inst->dispatch_mutex);
  217. dispatch_avail = coroipcc_dispatch_recv (cpg_inst->ipc_ctx,
  218. (void *)&dispatch_data, timeout);
  219. pthread_mutex_unlock (&cpg_inst->dispatch_mutex);
  220. if (error != CS_OK) {
  221. goto error_put;
  222. }
  223. if (dispatch_avail == 0 && dispatch_types == CPG_DISPATCH_ALL) {
  224. pthread_mutex_unlock (&cpg_inst->dispatch_mutex);
  225. break; /* exit do while cont is 1 loop */
  226. } else
  227. if (dispatch_avail == 0) {
  228. pthread_mutex_unlock (&cpg_inst->dispatch_mutex);
  229. continue; /* next poll */
  230. }
  231. if (dispatch_avail == -1) {
  232. if (cpg_inst->finalize == 1) {
  233. error = CS_OK;
  234. } else {
  235. error = CS_ERR_LIBRARY;
  236. }
  237. goto error_put;
  238. }
  239. /*
  240. * Make copy of callbacks, message data, unlock instance, and call callback
  241. * A risk of this dispatch method is that the callback routines may
  242. * operate at the same time that cpgFinalize has been called.
  243. */
  244. memcpy (&callbacks, &cpg_inst->callbacks, sizeof (cpg_callbacks_t));
  245. /*
  246. * Dispatch incoming message
  247. */
  248. switch (dispatch_data.header.id) {
  249. case MESSAGE_RES_CPG_DELIVER_CALLBACK:
  250. res_cpg_deliver_callback = (struct res_lib_cpg_deliver_callback *)&dispatch_data;
  251. marshall_from_mar_cpg_name_t (
  252. &group_name,
  253. &res_cpg_deliver_callback->group_name);
  254. callbacks.cpg_deliver_fn (handle,
  255. &group_name,
  256. res_cpg_deliver_callback->nodeid,
  257. res_cpg_deliver_callback->pid,
  258. &res_cpg_deliver_callback->message,
  259. res_cpg_deliver_callback->msglen);
  260. break;
  261. case MESSAGE_RES_CPG_CONFCHG_CALLBACK:
  262. res_cpg_confchg_callback = (struct res_lib_cpg_confchg_callback *)&dispatch_data;
  263. for (i = 0; i < res_cpg_confchg_callback->member_list_entries; i++) {
  264. marshall_from_mar_cpg_address_t (&member_list[i],
  265. &res_cpg_confchg_callback->member_list[i]);
  266. }
  267. left_list_start = res_cpg_confchg_callback->member_list +
  268. res_cpg_confchg_callback->member_list_entries;
  269. for (i = 0; i < res_cpg_confchg_callback->left_list_entries; i++) {
  270. marshall_from_mar_cpg_address_t (&left_list[i],
  271. &left_list_start[i]);
  272. }
  273. joined_list_start = res_cpg_confchg_callback->member_list +
  274. res_cpg_confchg_callback->member_list_entries +
  275. res_cpg_confchg_callback->left_list_entries;
  276. for (i = 0; i < res_cpg_confchg_callback->joined_list_entries; i++) {
  277. marshall_from_mar_cpg_address_t (&joined_list[i],
  278. &joined_list_start[i]);
  279. }
  280. marshall_from_mar_cpg_name_t (
  281. &group_name,
  282. &res_cpg_confchg_callback->group_name);
  283. callbacks.cpg_confchg_fn (handle,
  284. &group_name,
  285. member_list,
  286. res_cpg_confchg_callback->member_list_entries,
  287. left_list,
  288. res_cpg_confchg_callback->left_list_entries,
  289. joined_list,
  290. res_cpg_confchg_callback->joined_list_entries);
  291. break;
  292. default:
  293. error = CS_ERR_LIBRARY;
  294. goto error_put;
  295. break;
  296. }
  297. /*
  298. * Determine if more messages should be processed
  299. * */
  300. switch (dispatch_types) {
  301. case CPG_DISPATCH_ONE:
  302. if (ignore_dispatch) {
  303. ignore_dispatch = 0;
  304. } else {
  305. cont = 0;
  306. }
  307. break;
  308. case CPG_DISPATCH_ALL:
  309. if (ignore_dispatch) {
  310. ignore_dispatch = 0;
  311. }
  312. break;
  313. case CPG_DISPATCH_BLOCKING:
  314. break;
  315. }
  316. } while (cont);
  317. error_put:
  318. saHandleInstancePut (&cpg_handle_t_db, handle);
  319. return (error);
  320. }
  321. cs_error_t cpg_join (
  322. cpg_handle_t handle,
  323. struct cpg_name *group)
  324. {
  325. cs_error_t error;
  326. struct cpg_inst *cpg_inst;
  327. struct iovec iov[2];
  328. struct req_lib_cpg_join req_lib_cpg_join;
  329. struct res_lib_cpg_join res_lib_cpg_join;
  330. struct req_lib_cpg_trackstart req_lib_cpg_trackstart;
  331. struct res_lib_cpg_trackstart res_lib_cpg_trackstart;
  332. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  333. if (error != CS_OK) {
  334. return (error);
  335. }
  336. pthread_mutex_lock (&cpg_inst->response_mutex);
  337. /* Automatically add a tracker */
  338. req_lib_cpg_trackstart.header.size = sizeof (struct req_lib_cpg_trackstart);
  339. req_lib_cpg_trackstart.header.id = MESSAGE_REQ_CPG_TRACKSTART;
  340. marshall_to_mar_cpg_name_t (&req_lib_cpg_trackstart.group_name,
  341. group);
  342. iov[0].iov_base = &req_lib_cpg_trackstart;
  343. iov[0].iov_len = sizeof (struct req_lib_cpg_trackstart);
  344. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, iov, 1,
  345. &res_lib_cpg_trackstart, sizeof (struct res_lib_cpg_trackstart));
  346. if (error != CS_OK) {
  347. pthread_mutex_unlock (&cpg_inst->response_mutex);
  348. goto error_exit;
  349. }
  350. /* Now join */
  351. req_lib_cpg_join.header.size = sizeof (struct req_lib_cpg_join);
  352. req_lib_cpg_join.header.id = MESSAGE_REQ_CPG_JOIN;
  353. req_lib_cpg_join.pid = getpid();
  354. marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
  355. group);
  356. iov[0].iov_base = &req_lib_cpg_join;
  357. iov[0].iov_len = sizeof (struct req_lib_cpg_join);
  358. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, iov, 1,
  359. &res_lib_cpg_join, sizeof (struct res_lib_cpg_join));
  360. pthread_mutex_unlock (&cpg_inst->response_mutex);
  361. if (error != CS_OK) {
  362. goto error_exit;
  363. }
  364. error = res_lib_cpg_join.header.error;
  365. error_exit:
  366. saHandleInstancePut (&cpg_handle_t_db, handle);
  367. return (error);
  368. }
  369. cs_error_t cpg_leave (
  370. cpg_handle_t handle,
  371. struct cpg_name *group)
  372. {
  373. cs_error_t error;
  374. struct cpg_inst *cpg_inst;
  375. struct iovec iov[2];
  376. struct req_lib_cpg_leave req_lib_cpg_leave;
  377. struct res_lib_cpg_leave res_lib_cpg_leave;
  378. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  379. if (error != CS_OK) {
  380. return (error);
  381. }
  382. req_lib_cpg_leave.header.size = sizeof (struct req_lib_cpg_leave);
  383. req_lib_cpg_leave.header.id = MESSAGE_REQ_CPG_LEAVE;
  384. req_lib_cpg_leave.pid = getpid();
  385. marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
  386. group);
  387. iov[0].iov_base = &req_lib_cpg_leave;
  388. iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
  389. pthread_mutex_lock (&cpg_inst->response_mutex);
  390. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, iov, 1,
  391. &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave));
  392. pthread_mutex_unlock (&cpg_inst->response_mutex);
  393. if (error != CS_OK) {
  394. goto error_exit;
  395. }
  396. error = res_lib_cpg_leave.header.error;
  397. error_exit:
  398. saHandleInstancePut (&cpg_handle_t_db, handle);
  399. return (error);
  400. }
  401. cs_error_t cpg_mcast_joined (
  402. cpg_handle_t handle,
  403. cpg_guarantee_t guarantee,
  404. struct iovec *iovec,
  405. int iov_len)
  406. {
  407. int i;
  408. cs_error_t error;
  409. struct cpg_inst *cpg_inst;
  410. struct iovec iov[64];
  411. struct req_lib_cpg_mcast req_lib_cpg_mcast;
  412. struct res_lib_cpg_mcast res_lib_cpg_mcast;
  413. int msg_len = 0;
  414. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  415. if (error != CS_OK) {
  416. return (error);
  417. }
  418. for (i = 0; i < iov_len; i++ ) {
  419. msg_len += iovec[i].iov_len;
  420. }
  421. req_lib_cpg_mcast.header.size = sizeof (struct req_lib_cpg_mcast) +
  422. msg_len;
  423. req_lib_cpg_mcast.header.id = MESSAGE_REQ_CPG_MCAST;
  424. req_lib_cpg_mcast.guarantee = guarantee;
  425. req_lib_cpg_mcast.msglen = msg_len;
  426. iov[0].iov_base = &req_lib_cpg_mcast;
  427. iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
  428. memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
  429. pthread_mutex_lock (&cpg_inst->response_mutex);
  430. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, iov,
  431. iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast));
  432. pthread_mutex_unlock (&cpg_inst->response_mutex);
  433. if (error != CS_OK) {
  434. goto error_exit;
  435. }
  436. error = res_lib_cpg_mcast.header.error;
  437. error_exit:
  438. saHandleInstancePut (&cpg_handle_t_db, handle);
  439. return (error);
  440. }
  441. cs_error_t cpg_membership_get (
  442. cpg_handle_t handle,
  443. struct cpg_name *group_name,
  444. struct cpg_address *member_list,
  445. int *member_list_entries)
  446. {
  447. cs_error_t error;
  448. struct cpg_inst *cpg_inst;
  449. struct iovec iov;
  450. struct req_lib_cpg_membership req_lib_cpg_membership_get;
  451. struct res_lib_cpg_confchg_callback res_lib_cpg_membership_get;
  452. unsigned int i;
  453. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  454. if (error != CS_OK) {
  455. return (error);
  456. }
  457. req_lib_cpg_membership_get.header.size = sizeof (mar_req_header_t);
  458. req_lib_cpg_membership_get.header.id = MESSAGE_REQ_CPG_MEMBERSHIP;
  459. iov.iov_base = &req_lib_cpg_membership_get;
  460. iov.iov_len = sizeof (mar_req_header_t);
  461. pthread_mutex_lock (&cpg_inst->response_mutex);
  462. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, &iov, 1,
  463. &res_lib_cpg_membership_get, sizeof (mar_res_header_t));
  464. pthread_mutex_unlock (&cpg_inst->response_mutex);
  465. if (error != CS_OK) {
  466. goto error_exit;
  467. }
  468. error = res_lib_cpg_membership_get.header.error;
  469. /*
  470. * Copy results to caller
  471. */
  472. *member_list_entries = res_lib_cpg_membership_get.member_list_entries;
  473. if (member_list) {
  474. for (i = 0; i < res_lib_cpg_membership_get.member_list_entries; i++) {
  475. marshall_from_mar_cpg_address_t (&member_list[i],
  476. &res_lib_cpg_membership_get.member_list[i]);
  477. }
  478. }
  479. error_exit:
  480. saHandleInstancePut (&cpg_handle_t_db, handle);
  481. return (error);
  482. }
  483. cs_error_t cpg_local_get (
  484. cpg_handle_t handle,
  485. unsigned int *local_nodeid)
  486. {
  487. cs_error_t error;
  488. struct cpg_inst *cpg_inst;
  489. struct iovec iov;
  490. struct req_lib_cpg_local_get req_lib_cpg_local_get;
  491. struct res_lib_cpg_local_get res_lib_cpg_local_get;
  492. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  493. if (error != CS_OK) {
  494. return (error);
  495. }
  496. req_lib_cpg_local_get.header.size = sizeof (mar_req_header_t);
  497. req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET;
  498. iov.iov_base = &req_lib_cpg_local_get;
  499. iov.iov_len = sizeof (struct req_lib_cpg_local_get);
  500. pthread_mutex_lock (&cpg_inst->response_mutex);
  501. error = coroipcc_msg_send_reply_receive (cpg_inst->ipc_ctx, &iov, 1,
  502. &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get));
  503. pthread_mutex_unlock (&cpg_inst->response_mutex);
  504. if (error != CS_OK) {
  505. goto error_exit;
  506. }
  507. error = res_lib_cpg_local_get.header.error;
  508. *local_nodeid = res_lib_cpg_local_get.local_nodeid;
  509. error_exit:
  510. saHandleInstancePut (&cpg_handle_t_db, handle);
  511. return (error);
  512. }
  513. cs_error_t cpg_flow_control_state_get (
  514. cpg_handle_t handle,
  515. cpg_flow_control_state_t *flow_control_state)
  516. {
  517. cs_error_t error;
  518. struct cpg_inst *cpg_inst;
  519. error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst);
  520. if (error != CS_OK) {
  521. return (error);
  522. }
  523. *flow_control_state = coroipcc_dispatch_flow_control_get (cpg_inst->ipc_ctx);
  524. saHandleInstancePut (&cpg_handle_t_db, handle);
  525. return (error);
  526. }
  527. /** @} */