clm.c 22 KB

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