cpg.c 18 KB

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