clm.c 22 KB

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