clm.c 22 KB

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