cpg.c 18 KB

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