clm.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <stdlib.h>
  38. #include <unistd.h>
  39. #include <assert.h>
  40. #include <errno.h>
  41. #include <pthread.h>
  42. #include <sys/types.h>
  43. #include <sys/socket.h>
  44. #include <sys/select.h>
  45. #include <sys/un.h>
  46. #include "../include/swab.h"
  47. #include "../exec/totem.h"
  48. #include "../include/saAis.h"
  49. #include "../include/saClm.h"
  50. #include "../include/ipc_gen.h"
  51. #include "../include/ipc_clm.h"
  52. #include "../include/mar_gen.h"
  53. #include "../include/mar_clm.h"
  54. #include "util.h"
  55. struct res_overlay {
  56. mar_res_header_t header;
  57. char data[512000];
  58. };
  59. struct clmInstance {
  60. int response_fd;
  61. int dispatch_fd;
  62. SaClmCallbacksT callbacks;
  63. int finalize;
  64. pthread_mutex_t response_mutex;
  65. pthread_mutex_t dispatch_mutex;
  66. };
  67. static void clmHandleInstanceDestructor (void *);
  68. static struct saHandleDatabase clmHandleDatabase = {
  69. .handleCount = 0,
  70. .handles = 0,
  71. .mutex = PTHREAD_MUTEX_INITIALIZER,
  72. .handleInstanceDestructor = clmHandleInstanceDestructor
  73. };
  74. /*
  75. * Versions supported
  76. */
  77. static SaVersionT clmVersionsSupported[] = {
  78. { 'B', 1, 1 }
  79. };
  80. static struct saVersionDatabase clmVersionDatabase = {
  81. sizeof (clmVersionsSupported) / sizeof (SaVersionT),
  82. clmVersionsSupported
  83. };
  84. void clmHandleInstanceDestructor (void *instance)
  85. {
  86. struct clmInstance *clmInstance = instance;
  87. pthread_mutex_destroy (&clmInstance->response_mutex);
  88. pthread_mutex_destroy (&clmInstance->dispatch_mutex);
  89. }
  90. /**
  91. * @defgroup saClm SAF AIS Cluster Membership API
  92. * @ingroup saf
  93. *
  94. * @{
  95. */
  96. /**
  97. * This function initializes the Cluster Membership Service for the invoking
  98. * process and registers the various callback functions. This function must
  99. * be invoked prior to the invocation of any other Cluster Membership Service
  100. * functionality. The handle clmHandle is returned as the reference to this
  101. * association between the process and the Cluster Membership Service. The
  102. * process uses this handle in subsequent communication with the Cluster
  103. * Membership Service.
  104. *
  105. * @param clmHandle A pointer to the handle designating this particular
  106. * initialization of the Cluster Membership Service that is to be
  107. * returned by the Cluster Membership Service.
  108. * @param clmCallbacks If clmCallbacks is set to NULL, no callback is
  109. * registered; otherise, it is a pointer to an SaClmCallbacksT structure,
  110. * containing the callback functions of the process that the Cluster
  111. * Membership Service may invoke. Only non-NULL callback functions
  112. * in this structure will be registered.
  113. * @param version The version requested from the application is passed into
  114. * this parameter and the version supported is returned.
  115. *
  116. * @returns SA_AIS_OK if the function completed successfully.
  117. * @returns SA_AIS_ERR_LIBRARY if an unexpected problem occurred in
  118. * the library.
  119. * @returns SA_AIS_ERR_TRY_AGAIN if the service cannot be provided at this
  120. * time.
  121. * @returns SA_AIS_ERR_INVALID_PARAM if a parameter is not set correctly.
  122. * @returns SA_AIS_ERR_NO_MEMORY if the Cluster Membership Service is out
  123. * of memory and cannot provide the service.
  124. * @returns SA_AIS_ERR_VERSION if the version parameter is not compatible with
  125. * the version of the Cluster Membership Service implementation.
  126. */
  127. SaAisErrorT
  128. saClmInitialize (
  129. SaClmHandleT *clmHandle,
  130. const SaClmCallbacksT *clmCallbacks,
  131. SaVersionT *version)
  132. {
  133. struct clmInstance *clmInstance;
  134. SaAisErrorT error = SA_AIS_OK;
  135. if (clmHandle == NULL) {
  136. return (SA_AIS_ERR_INVALID_PARAM);
  137. }
  138. if (version == NULL) {
  139. return (SA_AIS_ERR_INVALID_PARAM);
  140. }
  141. error = saVersionVerify (&clmVersionDatabase, version);
  142. if (error != SA_AIS_OK) {
  143. goto error_no_destroy;
  144. }
  145. error = saHandleCreate (&clmHandleDatabase, sizeof (struct clmInstance),
  146. clmHandle);
  147. if (error != SA_AIS_OK) {
  148. goto error_no_destroy;
  149. }
  150. error = saHandleInstanceGet (&clmHandleDatabase, *clmHandle,
  151. (void *)&clmInstance);
  152. if (error != SA_AIS_OK) {
  153. goto error_destroy;
  154. }
  155. clmInstance->response_fd = -1;
  156. clmInstance->dispatch_fd = -1;
  157. error = saServiceConnect (&clmInstance->response_fd,
  158. &clmInstance->dispatch_fd, CLM_SERVICE);
  159. if (error != SA_AIS_OK) {
  160. goto error_put_destroy;
  161. }
  162. if (clmCallbacks) {
  163. memcpy (&clmInstance->callbacks, clmCallbacks, sizeof (SaClmCallbacksT));
  164. } else {
  165. memset (&clmInstance->callbacks, 0, sizeof (SaClmCallbacksT));
  166. }
  167. pthread_mutex_init (&clmInstance->response_mutex, NULL);
  168. pthread_mutex_init (&clmInstance->dispatch_mutex, NULL);
  169. saHandleInstancePut (&clmHandleDatabase, *clmHandle);
  170. return (SA_AIS_OK);
  171. error_put_destroy:
  172. saHandleInstancePut (&clmHandleDatabase, *clmHandle);
  173. error_destroy:
  174. saHandleDestroy (&clmHandleDatabase, *clmHandle);
  175. error_no_destroy:
  176. return (error);
  177. }
  178. /**
  179. * This function returns the operating system handle, selectionObject,
  180. * assocated with the handle clmHandle. The invoking process can use this
  181. * handle to detect pending callbacks, instead of repeatedly invoking
  182. * saClmDispatch() for this purpose.
  183. *
  184. * In a POSIX environment, the operating system handle is a file descriptor
  185. * that is used with the poll() or select() system calls to detect pending
  186. * callbacks.
  187. *
  188. * The selectionObject returned by saClmSelectionObjectGet() is valid until
  189. * saClmFinalize() is invoked on the same handle clmHandle.
  190. *
  191. * @param clmHandle The handle, obtained through the saClmInitialize function,
  192. * designating this particular initialization of the Cluster Membership
  193. * @param selectionObject A pointer to the operating system handle that the
  194. * invoking process can use to detect pending callbacks.
  195. *
  196. * @returns SA_AIS_OK if the function completed successfully.
  197. * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is
  198. * corrupted, uninitialized, or has already been finalized.
  199. */
  200. SaAisErrorT
  201. saClmSelectionObjectGet (
  202. SaClmHandleT clmHandle,
  203. SaSelectionObjectT *selectionObject)
  204. {
  205. struct clmInstance *clmInstance;
  206. SaAisErrorT error;
  207. if (selectionObject == NULL) {
  208. return (SA_AIS_ERR_INVALID_PARAM);
  209. }
  210. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  211. (void *)&clmInstance);
  212. if (error != SA_AIS_OK) {
  213. return (error);
  214. }
  215. *selectionObject = clmInstance->dispatch_fd;
  216. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  217. return (SA_AIS_OK);
  218. }
  219. /**
  220. * This function invokes, in the context of the calling thread, pending callbacks for
  221. * the handle clmhandle in a way that is specified by the dispatchFlags parameter.
  222. *
  223. * @param clmHandle The handle, obtained through the saClmInitialize() function,
  224. * designating the particular initialization of the Cluster Membership Service.
  225. * @param dispatchFlags Flags that specify the callback exection behavior of
  226. * saClmDispatch, which have the values SA_DISPATCH_ONE, SA_DISPATCH_ALL, or
  227. * SA_DISPATCH_BLOCKING.
  228. * @returns SA_AIS_OK if the function completed successfully.
  229. * @returns SA_AIS_ERR_TRY_AGAIN if the service cannot be provided at this time. The
  230. * process may retry later.
  231. * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is
  232. * corrupted, uninitialized, or has already been finalized.
  233. * @returns SA_AIS_ERR_INVALID_PARAM if the dispatchFlags parameter is valid.
  234. */
  235. SaAisErrorT
  236. saClmDispatch (
  237. SaClmHandleT clmHandle,
  238. SaDispatchFlagsT dispatchFlags)
  239. {
  240. struct pollfd ufds;
  241. int timeout = -1;
  242. SaAisErrorT error;
  243. int cont = 1; /* always continue do loop except when set to 0 */
  244. int dispatch_avail;
  245. struct clmInstance *clmInstance;
  246. struct res_lib_clm_clustertrack *res_lib_clm_clustertrack;
  247. struct res_clm_nodegetcallback *res_clm_nodegetcallback;
  248. SaClmCallbacksT callbacks;
  249. struct res_overlay dispatch_data;
  250. SaClmClusterNotificationBufferT notificationBuffer;
  251. SaClmClusterNotificationT notification[PROCESSOR_COUNT_MAX];
  252. SaClmClusterNodeT clusterNode;
  253. int items_to_copy;
  254. unsigned int i;
  255. if (dispatchFlags != SA_DISPATCH_ONE &&
  256. dispatchFlags != SA_DISPATCH_ALL &&
  257. dispatchFlags != SA_DISPATCH_BLOCKING) {
  258. return (SA_AIS_ERR_INVALID_PARAM);
  259. }
  260. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  261. (void *)&clmInstance);
  262. if (error != SA_AIS_OK) {
  263. return (error);
  264. }
  265. /*
  266. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  267. * wait indefinately for SA_DISPATCH_BLOCKING
  268. */
  269. if (dispatchFlags == SA_DISPATCH_ALL) {
  270. timeout = 0;
  271. }
  272. do {
  273. ufds.fd = clmInstance->dispatch_fd;
  274. ufds.events = POLLIN;
  275. ufds.revents = 0;
  276. pthread_mutex_lock (&clmInstance->dispatch_mutex);
  277. error = saPollRetry (&ufds, 1, timeout);
  278. if (error != SA_AIS_OK) {
  279. goto error_unlock;
  280. }
  281. /*
  282. * Handle has been finalized in another thread
  283. */
  284. if (clmInstance->finalize == 1) {
  285. error = SA_AIS_OK;
  286. goto error_unlock;
  287. }
  288. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  289. error = SA_AIS_ERR_BAD_HANDLE;
  290. goto error_unlock;
  291. }
  292. dispatch_avail = ufds.revents & POLLIN;
  293. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  294. pthread_mutex_unlock (&clmInstance->dispatch_mutex);
  295. break; /* exit do while cont is 1 loop */
  296. } else
  297. if (dispatch_avail == 0) {
  298. pthread_mutex_unlock (&clmInstance->dispatch_mutex);
  299. continue; /* next poll */
  300. }
  301. if (ufds.revents & POLLIN) {
  302. error = saRecvRetry (clmInstance->dispatch_fd, &dispatch_data.header,
  303. sizeof (mar_res_header_t));
  304. if (error != SA_AIS_OK) {
  305. goto error_unlock;
  306. }
  307. if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
  308. error = saRecvRetry (clmInstance->dispatch_fd, &dispatch_data.data,
  309. dispatch_data.header.size - sizeof (mar_res_header_t));
  310. if (error != SA_AIS_OK) {
  311. goto error_unlock;
  312. }
  313. }
  314. } else {
  315. pthread_mutex_unlock (&clmInstance->dispatch_mutex);
  316. continue;
  317. }
  318. /*
  319. * Make copy of callbacks, message data, unlock instance, and call callback
  320. * A risk of this dispatch method is that the callback routines may
  321. * operate at the same time that clmFinalize has been called in another thread.
  322. */
  323. memcpy (&callbacks, &clmInstance->callbacks, sizeof (SaClmCallbacksT));
  324. pthread_mutex_unlock (&clmInstance->dispatch_mutex);
  325. /*
  326. * Dispatch incoming message
  327. */
  328. switch (dispatch_data.header.id) {
  329. case MESSAGE_RES_CLM_TRACKCALLBACK:
  330. if (callbacks.saClmClusterTrackCallback == NULL) {
  331. continue;
  332. }
  333. res_lib_clm_clustertrack = (struct res_lib_clm_clustertrack *)&dispatch_data;
  334. error = SA_AIS_OK;
  335. notificationBuffer.notification = notification;
  336. notificationBuffer.viewNumber = res_lib_clm_clustertrack->view;
  337. notificationBuffer.notification = notification;
  338. notificationBuffer.numberOfItems =
  339. res_lib_clm_clustertrack->number_of_items;
  340. items_to_copy = notificationBuffer.numberOfItems
  341. < res_lib_clm_clustertrack->number_of_items ?
  342. notificationBuffer.numberOfItems :
  343. res_lib_clm_clustertrack->number_of_items;
  344. for (i = 0; i < items_to_copy; i++) {
  345. marshall_from_mar_clm_cluster_notification_t (
  346. &notificationBuffer.notification[i],
  347. &res_lib_clm_clustertrack->notification[i]);
  348. }
  349. callbacks.saClmClusterTrackCallback (
  350. (const SaClmClusterNotificationBufferT *)&notificationBuffer,
  351. res_lib_clm_clustertrack->number_of_items, error);
  352. break;
  353. case MESSAGE_RES_CLM_NODEGETCALLBACK:
  354. if (callbacks.saClmClusterNodeGetCallback == NULL) {
  355. continue;
  356. }
  357. res_clm_nodegetcallback = (struct res_clm_nodegetcallback *)&dispatch_data;
  358. marshall_from_mar_clm_cluster_node_t (
  359. &clusterNode,
  360. &res_clm_nodegetcallback->cluster_node);
  361. callbacks.saClmClusterNodeGetCallback (
  362. res_clm_nodegetcallback->invocation,
  363. &clusterNode,
  364. res_clm_nodegetcallback->header.error);
  365. break;
  366. default:
  367. error = SA_AIS_ERR_LIBRARY;
  368. goto error_put;
  369. break;
  370. }
  371. /*
  372. * Determine if more messages should be processed
  373. * */
  374. switch (dispatchFlags) {
  375. case SA_DISPATCH_ONE:
  376. cont = 0;
  377. break;
  378. case SA_DISPATCH_ALL:
  379. break;
  380. case SA_DISPATCH_BLOCKING:
  381. break;
  382. }
  383. } while (cont);
  384. goto error_put;
  385. error_unlock:
  386. pthread_mutex_unlock (&clmInstance->dispatch_mutex);
  387. error_put:
  388. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  389. return (error);
  390. }
  391. /**
  392. * The saClmFinalize function closes the assocation, represented by the clmHandle
  393. * parameter, between the invoking process and the Cluster Membership Service. The
  394. * process must have invoked saClmInitialize before it invokes this function. A
  395. * process must invoke this function once for each handle it acquired by invoking
  396. * saClmInitialize().
  397. *
  398. * If the saClmFinalize() function returns successfully, the saClmFinalize() function
  399. * releases all resources acquired when saClmInitialize(0 was called. Moreover, it
  400. * stops any tracking associated with the particular handle. Furthermore, it cancels
  401. * all pending callbacks related to the particular handle. Note that because the
  402. * callback invocation is asynchronous, it is still possible that some callback calls
  403. * are processed after this call returns successfully.
  404. *
  405. * After saClmFinalize() is invoked, the selection object is no longer valid.
  406. *
  407. * @param clmHandle The handle, obtained through the saClmInitialize() function,
  408. * designating this particular initialization of the Cluster Membership Service.
  409. *
  410. * @returns SA_AIS_OK if the function completed successfully.
  411. * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is
  412. * corrupted, uninitialized, or has already been finalized.
  413. */
  414. SaAisErrorT
  415. saClmFinalize (
  416. SaClmHandleT clmHandle)
  417. {
  418. struct clmInstance *clmInstance;
  419. SaAisErrorT error;
  420. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  421. (void *)&clmInstance);
  422. if (error != SA_AIS_OK) {
  423. return (error);
  424. }
  425. pthread_mutex_lock (&clmInstance->response_mutex);
  426. /*
  427. * Another thread has already started finalizing
  428. */
  429. if (clmInstance->finalize) {
  430. pthread_mutex_unlock (&clmInstance->response_mutex);
  431. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  432. return (SA_AIS_ERR_BAD_HANDLE);
  433. }
  434. clmInstance->finalize = 1;
  435. pthread_mutex_unlock (&clmInstance->response_mutex);
  436. saHandleDestroy (&clmHandleDatabase, clmHandle);
  437. if (clmInstance->response_fd != -1) {
  438. shutdown (clmInstance->response_fd, 0);
  439. close (clmInstance->response_fd);
  440. }
  441. if (clmInstance->dispatch_fd != -1) {
  442. shutdown (clmInstance->dispatch_fd, 0);
  443. close (clmInstance->dispatch_fd);
  444. }
  445. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  446. return (error);
  447. }
  448. SaAisErrorT
  449. saClmClusterTrack (
  450. SaClmHandleT clmHandle,
  451. SaUint8T trackFlags,
  452. SaClmClusterNotificationBufferT *notificationBuffer)
  453. {
  454. struct req_lib_clm_clustertrack req_lib_clm_clustertrack;
  455. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  456. struct clmInstance *clmInstance;
  457. SaAisErrorT error = SA_AIS_OK;
  458. int items_to_copy;
  459. unsigned int i;
  460. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  461. (void *)&clmInstance);
  462. if (error != SA_AIS_OK) {
  463. return (error);
  464. }
  465. if ((trackFlags & SA_TRACK_CHANGES) && (trackFlags & SA_TRACK_CHANGES_ONLY)) {
  466. error = SA_AIS_ERR_BAD_FLAGS;
  467. goto error_nounlock;
  468. }
  469. if (trackFlags & ~(SA_TRACK_CURRENT | SA_TRACK_CHANGES | SA_TRACK_CHANGES_ONLY)) {
  470. error = SA_AIS_ERR_BAD_FLAGS;
  471. goto error_nounlock;
  472. }
  473. if ((notificationBuffer != NULL) &&
  474. (notificationBuffer->notification != NULL) &&
  475. (notificationBuffer->numberOfItems == 0)) {
  476. error = SA_AIS_ERR_INVALID_PARAM;
  477. goto error_nounlock;
  478. }
  479. req_lib_clm_clustertrack.header.size = sizeof (struct req_lib_clm_clustertrack);
  480. req_lib_clm_clustertrack.header.id = MESSAGE_REQ_CLM_TRACKSTART;
  481. req_lib_clm_clustertrack.track_flags = trackFlags;
  482. req_lib_clm_clustertrack.return_in_callback = 0;
  483. if ((trackFlags & SA_TRACK_CURRENT) && (notificationBuffer == NULL)) {
  484. req_lib_clm_clustertrack.return_in_callback = 1;
  485. }
  486. pthread_mutex_lock (&clmInstance->response_mutex);
  487. if ((clmInstance->callbacks.saClmClusterTrackCallback == 0) &&
  488. ((notificationBuffer == NULL) ||
  489. (trackFlags & (SA_TRACK_CHANGES | SA_TRACK_CHANGES_ONLY)))) {
  490. error = SA_AIS_ERR_INIT;
  491. goto error_exit;
  492. }
  493. error = saSendReceiveReply (clmInstance->response_fd,
  494. &req_lib_clm_clustertrack,
  495. sizeof (struct req_lib_clm_clustertrack),
  496. &res_lib_clm_clustertrack,
  497. sizeof (struct res_lib_clm_clustertrack));
  498. if ((trackFlags & SA_TRACK_CURRENT) && (notificationBuffer != NULL)) {
  499. if (notificationBuffer->notification == 0) {
  500. notificationBuffer->viewNumber = res_lib_clm_clustertrack.view;
  501. notificationBuffer->notification =
  502. malloc (res_lib_clm_clustertrack.number_of_items *
  503. sizeof (SaClmClusterNotificationT));
  504. notificationBuffer->numberOfItems =
  505. res_lib_clm_clustertrack.number_of_items;
  506. }
  507. items_to_copy = notificationBuffer->numberOfItems <
  508. res_lib_clm_clustertrack.number_of_items ?
  509. notificationBuffer->numberOfItems :
  510. res_lib_clm_clustertrack.number_of_items;
  511. for (i = 0; i < items_to_copy; i++) {
  512. marshall_from_mar_clm_cluster_notification_t (
  513. &notificationBuffer->notification[i],
  514. &res_lib_clm_clustertrack.notification[i]);
  515. }
  516. notificationBuffer->viewNumber = res_lib_clm_clustertrack.view;
  517. notificationBuffer->numberOfItems = items_to_copy;
  518. }
  519. error_exit:
  520. pthread_mutex_unlock (&clmInstance->response_mutex);
  521. error_nounlock:
  522. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  523. return (error == SA_AIS_OK ? res_lib_clm_clustertrack.header.error : error);
  524. }
  525. SaAisErrorT
  526. saClmClusterTrackStop (
  527. SaClmHandleT clmHandle)
  528. {
  529. struct clmInstance *clmInstance;
  530. struct req_lib_clm_trackstop req_lib_clm_trackstop;
  531. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  532. SaAisErrorT error = SA_AIS_OK;
  533. req_lib_clm_trackstop.header.size = sizeof (struct req_lib_clm_trackstop);
  534. req_lib_clm_trackstop.header.id = MESSAGE_REQ_CLM_TRACKSTOP;
  535. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  536. (void *)&clmInstance);
  537. if (error != SA_AIS_OK) {
  538. return (error);
  539. }
  540. pthread_mutex_lock (&clmInstance->response_mutex);
  541. error = saSendReceiveReply (clmInstance->response_fd,
  542. &req_lib_clm_trackstop,
  543. sizeof (struct req_lib_clm_trackstop),
  544. &res_lib_clm_trackstop,
  545. sizeof (struct res_lib_clm_trackstop));
  546. pthread_mutex_unlock (&clmInstance->response_mutex);
  547. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  548. return (error == SA_AIS_OK ? res_lib_clm_trackstop.header.error : error);
  549. }
  550. SaAisErrorT
  551. saClmClusterNodeGet (
  552. SaClmHandleT clmHandle,
  553. SaClmNodeIdT nodeId,
  554. SaTimeT timeout,
  555. SaClmClusterNodeT *clusterNode)
  556. {
  557. struct clmInstance *clmInstance;
  558. struct req_lib_clm_nodeget req_lib_clm_nodeget;
  559. struct res_clm_nodeget res_clm_nodeget;
  560. SaAisErrorT error = SA_AIS_OK;
  561. if (clusterNode == NULL) {
  562. return (SA_AIS_ERR_INVALID_PARAM);
  563. }
  564. if (timeout == 0) {
  565. return (SA_AIS_ERR_TIMEOUT);
  566. }
  567. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  568. (void *)&clmInstance);
  569. if (error != SA_AIS_OK) {
  570. return (error);
  571. }
  572. pthread_mutex_lock (&clmInstance->response_mutex);
  573. /*
  574. * Send request message
  575. */
  576. req_lib_clm_nodeget.header.size = sizeof (struct req_lib_clm_nodeget);
  577. req_lib_clm_nodeget.header.id = MESSAGE_REQ_CLM_NODEGET;
  578. req_lib_clm_nodeget.node_id = nodeId;
  579. error = saSendReceiveReply (clmInstance->response_fd, &req_lib_clm_nodeget,
  580. sizeof (struct req_lib_clm_nodeget), &res_clm_nodeget, sizeof (res_clm_nodeget));
  581. if (error != SA_AIS_OK) {
  582. goto error_exit;
  583. }
  584. error = res_clm_nodeget.header.error;
  585. marshall_from_mar_clm_cluster_node_t (clusterNode,
  586. &res_clm_nodeget.cluster_node);
  587. error_exit:
  588. pthread_mutex_unlock (&clmInstance->response_mutex);
  589. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  590. return (error);
  591. }
  592. SaAisErrorT
  593. saClmClusterNodeGetAsync (
  594. SaClmHandleT clmHandle,
  595. SaInvocationT invocation,
  596. SaClmNodeIdT nodeId)
  597. {
  598. struct clmInstance *clmInstance;
  599. struct req_lib_clm_nodegetasync req_lib_clm_nodegetasync;
  600. struct res_clm_nodegetasync res_clm_nodegetasync;
  601. SaAisErrorT error = SA_AIS_OK;
  602. req_lib_clm_nodegetasync.header.size = sizeof (struct req_lib_clm_nodegetasync);
  603. req_lib_clm_nodegetasync.header.id = MESSAGE_REQ_CLM_NODEGETASYNC;
  604. req_lib_clm_nodegetasync.invocation = invocation;
  605. req_lib_clm_nodegetasync.node_id = nodeId;
  606. error = saHandleInstanceGet (&clmHandleDatabase, clmHandle,
  607. (void *)&clmInstance);
  608. if (error != SA_AIS_OK) {
  609. return (error);
  610. }
  611. pthread_mutex_lock (&clmInstance->response_mutex);
  612. if (clmInstance->callbacks.saClmClusterNodeGetCallback == NULL) {
  613. error = SA_AIS_ERR_INIT;
  614. goto error_exit;
  615. }
  616. error = saSendReceiveReply (clmInstance->response_fd, &req_lib_clm_nodegetasync,
  617. sizeof (struct req_lib_clm_nodegetasync),
  618. &res_clm_nodegetasync, sizeof (struct res_clm_nodegetasync));
  619. if (error != SA_AIS_OK) {
  620. goto error_exit;
  621. }
  622. error = res_clm_nodegetasync.header.error;
  623. error_exit:
  624. pthread_mutex_unlock (&clmInstance->response_mutex);
  625. saHandleInstancePut (&clmHandleDatabase, clmHandle);
  626. return (error);
  627. }
  628. /** @} */