lck.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@redhat.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 <assert.h>
  38. #include <unistd.h>
  39. #include <errno.h>
  40. #include <pthread.h>
  41. #include <sys/types.h>
  42. #include <sys/uio.h>
  43. #include <sys/socket.h>
  44. #include <sys/select.h>
  45. #include <sys/un.h>
  46. #include <saAis.h>
  47. #include <list.h>
  48. #include <saLck.h>
  49. #include <ipc_gen.h>
  50. #include <ipc_lck.h>
  51. #include <ais_util.h>
  52. struct message_overlay {
  53. mar_res_header_t header __attribute__((aligned(8)));
  54. char data[4096];
  55. };
  56. /*
  57. * Data structure for instance data
  58. */
  59. struct lckInstance {
  60. int response_fd;
  61. int dispatch_fd;
  62. SaLckCallbacksT callbacks;
  63. int finalize;
  64. SaLckHandleT lckHandle;
  65. struct list_head resource_list;
  66. pthread_mutex_t response_mutex;
  67. pthread_mutex_t dispatch_mutex;
  68. };
  69. struct lckResourceInstance {
  70. int response_fd;
  71. SaLckHandleT lckHandle;
  72. SaLckResourceHandleT lckResourceHandle;
  73. SaLckResourceOpenFlagsT resourceOpenFlags;
  74. SaNameT lockResourceName;
  75. struct list_head list;
  76. mar_message_source_t source;
  77. pthread_mutex_t *response_mutex;
  78. };
  79. struct lckLockIdInstance {
  80. int response_fd;
  81. SaLckResourceHandleT lckResourceHandle;
  82. struct list_head list;
  83. void *resource_lock;
  84. pthread_mutex_t *response_mutex;
  85. };
  86. void lckHandleInstanceDestructor (void *instance);
  87. void lckResourceHandleInstanceDestructor (void *instance);
  88. void lckResourceHandleLockIdInstanceDestructor (void *instance);
  89. /*
  90. * All LCK instances in this database
  91. */
  92. static struct saHandleDatabase lckHandleDatabase = {
  93. .handleCount = 0,
  94. .handles = 0,
  95. .mutex = PTHREAD_MUTEX_INITIALIZER,
  96. .handleInstanceDestructor = lckHandleInstanceDestructor
  97. };
  98. /*
  99. * All Resource instances in this database
  100. */
  101. static struct saHandleDatabase lckResourceHandleDatabase = {
  102. .handleCount = 0,
  103. .handles = 0,
  104. .mutex = PTHREAD_MUTEX_INITIALIZER,
  105. .handleInstanceDestructor = lckResourceHandleInstanceDestructor
  106. };
  107. /*
  108. * All Resource Lock Identifier instances in this database
  109. */
  110. static struct saHandleDatabase lckLockIdHandleDatabase = {
  111. .handleCount = 0,
  112. .handles = 0,
  113. .mutex = PTHREAD_MUTEX_INITIALIZER,
  114. .handleInstanceDestructor = lckResourceHandleLockIdInstanceDestructor
  115. };
  116. /*
  117. * Versions supported
  118. */
  119. static SaVersionT lckVersionsSupported[] = {
  120. { 'B', 1, 1 }
  121. };
  122. static struct saVersionDatabase lckVersionDatabase = {
  123. sizeof (lckVersionsSupported) / sizeof (SaVersionT),
  124. lckVersionsSupported
  125. };
  126. /*
  127. * Implementation
  128. */
  129. void lckHandleInstanceDestructor (void *instance)
  130. {
  131. struct lckInstance *lckInstance = instance;
  132. pthread_mutex_destroy (&lckInstance->response_mutex);
  133. pthread_mutex_destroy (&lckInstance->dispatch_mutex);
  134. }
  135. void lckResourceHandleInstanceDestructor (void *instance)
  136. {
  137. }
  138. void lckResourceHandleLockIdInstanceDestructor (void *instance)
  139. {
  140. }
  141. #ifdef NOT_DONE
  142. static void lckSectionIterationInstanceFinalize (struct lckSectionIterationInstance *lckSectionIterationInstance)
  143. {
  144. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  145. struct list_head *sectionIdIterationList;
  146. struct list_head *sectionIdIterationListNext;
  147. /*
  148. * iterate list of section ids for this iterator to free the allocated memory
  149. * be careful to cache next pointer because free removes memory from use
  150. */
  151. for (sectionIdIterationList = lckSectionIterationInstance->sectionIdListHead.next,
  152. sectionIdIterationListNext = sectionIdIterationList->next;
  153. sectionIdIterationList != &lckSectionIterationInstance->sectionIdListHead;
  154. sectionIdIterationList = sectionIdIterationListNext,
  155. sectionIdIterationListNext = sectionIdIterationList->next) {
  156. iteratorSectionIdListEntry = list_entry (sectionIdIterationList,
  157. struct iteratorSectionIdListEntry, list);
  158. free (iteratorSectionIdListEntry);
  159. }
  160. list_del (&lckSectionIterationInstance->list);
  161. saHandleDestroy (&lckSectionIterationHandleDatabase,
  162. lckSectionIterationInstance->sectionIterationHandle);
  163. }
  164. static void lckResourceInstanceFinalize (struct lckResourceInstance *lckResourceInstance)
  165. {
  166. struct lckSectionIterationInstance *sectionIterationInstance;
  167. struct list_head *sectionIterationList;
  168. struct list_head *sectionIterationListNext;
  169. for (sectionIterationList = lckResourceInstance->section_iteration_list_head.next,
  170. sectionIterationListNext = sectionIterationList->next;
  171. sectionIterationList != &lckResourceInstance->section_iteration_list_head;
  172. sectionIterationList = sectionIterationListNext,
  173. sectionIterationListNext = sectionIterationList->next) {
  174. sectionIterationInstance = list_entry (sectionIterationList,
  175. struct lckSectionIterationInstance, list);
  176. lckSectionIterationInstanceFinalize (sectionIterationInstance);
  177. }
  178. list_del (&lckResourceInstance->list);
  179. saHandleDestroy (&lckResourceHandleDatabase, lckResourceInstance->lckResourceHandle);
  180. }
  181. static void lckInstanceFinalize (struct lckInstance *lckInstance)
  182. {
  183. struct lckResourceInstance *lckResourceInstance;
  184. struct list_head *resourceInstanceList;
  185. struct list_head *resourceInstanceListNext;
  186. for (resourceInstanceList = lckInstance->resource_list.next,
  187. resourceInstanceListNext = resourceInstanceList->next;
  188. resourceInstanceList != &lckInstance->resource_list;
  189. resourceInstanceList = resourceInstanceListNext,
  190. resourceInstanceListNext = resourceInstanceList->next) {
  191. lckResourceInstance = list_entry (resourceInstanceList,
  192. struct lckResourceInstance, list);
  193. lckResourceInstanceFinalize (lckResourceInstance);
  194. }
  195. saHandleDestroy (&lckHandleDatabase, lckInstance->lckHandle);
  196. }
  197. #endif
  198. SaAisErrorT
  199. saLckInitialize (
  200. SaLckHandleT *lckHandle,
  201. const SaLckCallbacksT *callbacks,
  202. SaVersionT *version)
  203. {
  204. struct lckInstance *lckInstance;
  205. SaAisErrorT error = SA_AIS_OK;
  206. if (lckHandle == NULL) {
  207. return (SA_AIS_ERR_INVALID_PARAM);
  208. }
  209. error = saVersionVerify (&lckVersionDatabase, version);
  210. if (error != SA_AIS_OK) {
  211. goto error_no_destroy;
  212. }
  213. error = saHandleCreate (&lckHandleDatabase, sizeof (struct lckInstance),
  214. lckHandle);
  215. if (error != SA_AIS_OK) {
  216. goto error_no_destroy;
  217. }
  218. error = saHandleInstanceGet (&lckHandleDatabase, *lckHandle,
  219. (void *)&lckInstance);
  220. if (error != SA_AIS_OK) {
  221. goto error_destroy;
  222. }
  223. lckInstance->response_fd = -1;
  224. error = saServiceConnect (&lckInstance->response_fd,
  225. &lckInstance->dispatch_fd, LCK_SERVICE);
  226. if (error != SA_AIS_OK) {
  227. goto error_put_destroy;
  228. }
  229. if (callbacks) {
  230. memcpy (&lckInstance->callbacks, callbacks, sizeof (SaLckCallbacksT));
  231. } else {
  232. memset (&lckInstance->callbacks, 0, sizeof (SaLckCallbacksT));
  233. }
  234. list_init (&lckInstance->resource_list);
  235. lckInstance->lckHandle = *lckHandle;
  236. pthread_mutex_init (&lckInstance->response_mutex, NULL);
  237. saHandleInstancePut (&lckHandleDatabase, *lckHandle);
  238. return (SA_AIS_OK);
  239. error_put_destroy:
  240. saHandleInstancePut (&lckHandleDatabase, *lckHandle);
  241. error_destroy:
  242. saHandleDestroy (&lckHandleDatabase, *lckHandle);
  243. error_no_destroy:
  244. return (error);
  245. }
  246. SaAisErrorT
  247. saLckSelectionObjectGet (
  248. const SaLckHandleT lckHandle,
  249. SaSelectionObjectT *selectionObject)
  250. {
  251. struct lckInstance *lckInstance;
  252. SaAisErrorT error;
  253. if (selectionObject == NULL) {
  254. return (SA_AIS_ERR_INVALID_PARAM);
  255. }
  256. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, (void *)&lckInstance);
  257. if (error != SA_AIS_OK) {
  258. return (error);
  259. }
  260. *selectionObject = lckInstance->dispatch_fd;
  261. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  262. return (SA_AIS_OK);
  263. }
  264. SaAisErrorT
  265. saLckOptionCheck (
  266. SaLckHandleT lckHandle,
  267. SaLckOptionsT *lckOptions)
  268. {
  269. return (SA_AIS_OK);
  270. }
  271. SaAisErrorT
  272. saLckDispatch (
  273. const SaLckHandleT lckHandle,
  274. SaDispatchFlagsT dispatchFlags)
  275. {
  276. struct pollfd ufds;
  277. int poll_fd;
  278. int timeout = 1;
  279. SaLckCallbacksT callbacks;
  280. SaAisErrorT error;
  281. int dispatch_avail;
  282. struct lckInstance *lckInstance;
  283. struct lckResourceInstance *lckResourceInstance;
  284. struct lckLockIdInstance *lckLockIdInstance;
  285. int cont = 1; /* always continue do loop except when set to 0 */
  286. struct message_overlay dispatch_data;
  287. struct res_lib_lck_lockwaitercallback *res_lib_lck_lockwaitercallback;
  288. struct res_lib_lck_resourceopenasync *res_lib_lck_resourceopenasync = NULL;
  289. struct res_lib_lck_resourcelockasync *res_lib_lck_resourcelockasync = NULL;
  290. struct res_lib_lck_resourceunlockasync *res_lib_lck_resourceunlockasync;
  291. if (dispatchFlags != SA_DISPATCH_ONE &&
  292. dispatchFlags != SA_DISPATCH_ALL &&
  293. dispatchFlags != SA_DISPATCH_BLOCKING) {
  294. return (SA_AIS_ERR_INVALID_PARAM);
  295. }
  296. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  297. (void *)&lckInstance);
  298. if (error != SA_AIS_OK) {
  299. goto error_exit;
  300. }
  301. /*
  302. * Timeout instantly for SA_DISPATCH_ALL
  303. */
  304. if (dispatchFlags == SA_DISPATCH_ALL) {
  305. timeout = 0;
  306. }
  307. do {
  308. /*
  309. * Read data directly from socket
  310. */
  311. poll_fd = lckInstance->dispatch_fd;
  312. ufds.fd = poll_fd;
  313. ufds.events = POLLIN;
  314. ufds.revents = 0;
  315. error = saPollRetry(&ufds, 1, timeout);
  316. if (error != SA_AIS_OK) {
  317. goto error_put;
  318. }
  319. pthread_mutex_lock(&lckInstance->dispatch_mutex);
  320. if (lckInstance->finalize == 1) {
  321. error = SA_AIS_OK;
  322. goto error_unlock;
  323. }
  324. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  325. error = SA_AIS_ERR_BAD_HANDLE;
  326. goto error_unlock;
  327. }
  328. dispatch_avail = (ufds.revents & POLLIN);
  329. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  330. pthread_mutex_unlock(&lckInstance->dispatch_mutex);
  331. break; /* exit do while cont is 1 loop */
  332. } else
  333. if (dispatch_avail == 0) {
  334. pthread_mutex_unlock(&lckInstance->dispatch_mutex);
  335. continue;
  336. }
  337. memset(&dispatch_data,0, sizeof(struct message_overlay));
  338. error = saRecvRetry (lckInstance->dispatch_fd, &dispatch_data.header, sizeof (mar_res_header_t));
  339. if (error != SA_AIS_OK) {
  340. goto error_unlock;
  341. }
  342. if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
  343. error = saRecvRetry (lckInstance->dispatch_fd, &dispatch_data.data,
  344. dispatch_data.header.size - sizeof (mar_res_header_t));
  345. if (error != SA_AIS_OK) {
  346. goto error_unlock;
  347. }
  348. }
  349. /*
  350. * Make copy of callbacks, message data, unlock instance,
  351. * and call callback. A risk of this dispatch method is that
  352. * the callback routines may operate at the same time that
  353. * LckFinalize has been called in another thread.
  354. */
  355. memcpy(&callbacks,&lckInstance->callbacks, sizeof(lckInstance->callbacks));
  356. pthread_mutex_unlock(&lckInstance->dispatch_mutex);
  357. /*
  358. * Dispatch incoming response
  359. */
  360. switch (dispatch_data.header.id) {
  361. case MESSAGE_RES_LCK_LOCKWAITERCALLBACK:
  362. if (callbacks.saLckResourceOpenCallback == NULL) {
  363. continue;
  364. }
  365. res_lib_lck_lockwaitercallback = (struct res_lib_lck_lockwaitercallback *)&dispatch_data;
  366. callbacks.saLckLockWaiterCallback (
  367. res_lib_lck_lockwaitercallback->waiter_signal,
  368. res_lib_lck_lockwaitercallback->lock_id,
  369. res_lib_lck_lockwaitercallback->mode_held,
  370. res_lib_lck_lockwaitercallback->mode_requested);
  371. break;
  372. case MESSAGE_RES_LCK_RESOURCEOPENASYNC:
  373. if (callbacks.saLckLockWaiterCallback == NULL) {
  374. continue;
  375. }
  376. res_lib_lck_resourceopenasync = (struct res_lib_lck_resourceopenasync *)&dispatch_data;
  377. /*
  378. * This instance get/listadd/put required so that close
  379. * later has the proper list of resources
  380. */
  381. if (res_lib_lck_resourceopenasync->header.error == SA_AIS_OK) {
  382. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  383. res_lib_lck_resourceopenasync->resourceHandle,
  384. (void *)&lckResourceInstance);
  385. assert (error == SA_AIS_OK); /* should only be valid handles here */
  386. /*
  387. * open succeeded without error
  388. */
  389. callbacks.saLckResourceOpenCallback(
  390. res_lib_lck_resourceopenasync->invocation,
  391. res_lib_lck_resourceopenasync->resourceHandle,
  392. res_lib_lck_resourceopenasync->header.error);
  393. memcpy (&lckResourceInstance->source,
  394. &res_lib_lck_resourceopenasync->source,
  395. sizeof (mar_message_source_t));
  396. saHandleInstancePut (&lckResourceHandleDatabase,
  397. res_lib_lck_resourceopenasync->resourceHandle);
  398. } else {
  399. /*
  400. * open failed with error
  401. */
  402. callbacks.saLckResourceOpenCallback(
  403. res_lib_lck_resourceopenasync->invocation,
  404. -1,
  405. res_lib_lck_resourceopenasync->header.error);
  406. }
  407. break;
  408. case MESSAGE_RES_LCK_RESOURCELOCKASYNC:
  409. DPRINT (("grant\n"));
  410. if (callbacks.saLckLockGrantCallback == NULL) {
  411. continue;
  412. }
  413. res_lib_lck_resourcelockasync = (struct res_lib_lck_resourcelockasync *)&dispatch_data;
  414. /*
  415. * This instance get/listadd/put required so that close
  416. * later has the proper list of resources
  417. */
  418. if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) {
  419. error = saHandleInstanceGet (&lckLockIdHandleDatabase,
  420. res_lib_lck_resourcelockasync->lockId,
  421. (void *)&lckLockIdInstance);
  422. assert (error == SA_AIS_OK); /* should only be valid handles here */
  423. /*
  424. * open succeeded without error
  425. */
  426. lckLockIdInstance->resource_lock = res_lib_lck_resourcelockasync->resource_lock;
  427. callbacks.saLckLockGrantCallback(
  428. res_lib_lck_resourcelockasync->invocation,
  429. res_lib_lck_resourcelockasync->lockStatus,
  430. res_lib_lck_resourcelockasync->header.error);
  431. saHandleInstancePut (&lckLockIdHandleDatabase,
  432. res_lib_lck_resourcelockasync->lockId);
  433. } else {
  434. /*
  435. * open failed with error
  436. */
  437. callbacks.saLckLockGrantCallback (
  438. res_lib_lck_resourceopenasync->invocation,
  439. -1,
  440. res_lib_lck_resourceopenasync->header.error);
  441. }
  442. break;
  443. case MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC:
  444. if (callbacks.saLckResourceUnlockCallback == NULL) {
  445. continue;
  446. }
  447. res_lib_lck_resourceunlockasync = (struct res_lib_lck_resourceunlockasync *)&dispatch_data;
  448. callbacks.saLckResourceUnlockCallback (
  449. res_lib_lck_resourceunlockasync->invocation,
  450. res_lib_lck_resourceunlockasync->header.error);
  451. if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) {
  452. error = saHandleInstanceGet (&lckLockIdHandleDatabase,
  453. res_lib_lck_resourceunlockasync->lockId,
  454. (void *)&lckLockIdInstance);
  455. if (error == SA_AIS_OK) {
  456. saHandleInstancePut (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId);
  457. saHandleDestroy (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId);
  458. }
  459. }
  460. break;
  461. #ifdef NOT_DONE_YET
  462. case MESSAGE_RES_LCK_RESOURCESYNCHRONIZEASYNC:
  463. if (callbacks.saLckResourceSynchronizeCallback == NULL) {
  464. continue;
  465. }
  466. res_lib_lck_resourcesynchronizeasync = (struct res_lib_lck_resourcesynchronizeasync *) &dispatch_data;
  467. callbacks.saLckResourceSynchronizeCallback(
  468. res_lib_lck_resourcesynchronizeasync->invocation,
  469. res_lib_lck_resourcesynchronizeasync->header.error);
  470. break;
  471. #endif
  472. default:
  473. /* TODO */
  474. break;
  475. }
  476. /*
  477. * Determine if more messages should be processed
  478. */
  479. switch (dispatchFlags) {
  480. case SA_DISPATCH_ONE:
  481. cont = 0;
  482. break;
  483. case SA_DISPATCH_ALL:
  484. break;
  485. case SA_DISPATCH_BLOCKING:
  486. break;
  487. }
  488. } while (cont);
  489. error_unlock:
  490. pthread_mutex_unlock(&lckInstance->dispatch_mutex);
  491. error_put:
  492. saHandleInstancePut(&lckHandleDatabase, lckHandle);
  493. error_exit:
  494. return (error);
  495. }
  496. SaAisErrorT
  497. saLckFinalize (
  498. const SaLckHandleT lckHandle)
  499. {
  500. struct lckInstance *lckInstance;
  501. SaAisErrorT error;
  502. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  503. (void *)&lckInstance);
  504. if (error != SA_AIS_OK) {
  505. return (error);
  506. }
  507. pthread_mutex_lock (&lckInstance->response_mutex);
  508. /*
  509. * Another thread has already started finalizing
  510. */
  511. if (lckInstance->finalize) {
  512. pthread_mutex_unlock (&lckInstance->response_mutex);
  513. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  514. return (SA_AIS_ERR_BAD_HANDLE);
  515. }
  516. lckInstance->finalize = 1;
  517. pthread_mutex_unlock (&lckInstance->response_mutex);
  518. // TODO lckInstanceFinalize (lckInstance);
  519. if (lckInstance->response_fd != -1) {
  520. shutdown (lckInstance->response_fd, 0);
  521. close (lckInstance->response_fd);
  522. }
  523. if (lckInstance->dispatch_fd != -1) {
  524. shutdown (lckInstance->dispatch_fd, 0);
  525. close (lckInstance->dispatch_fd);
  526. }
  527. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  528. return (SA_AIS_OK);
  529. }
  530. SaAisErrorT
  531. saLckResourceOpen (
  532. SaLckHandleT lckHandle,
  533. const SaNameT *lockResourceName,
  534. SaLckResourceOpenFlagsT resourceOpenFlags,
  535. SaTimeT timeout,
  536. SaLckResourceHandleT *lckResourceHandle)
  537. {
  538. SaAisErrorT error;
  539. struct lckResourceInstance *lckResourceInstance;
  540. struct lckInstance *lckInstance;
  541. struct req_lib_lck_resourceopen req_lib_lck_resourceopen;
  542. struct res_lib_lck_resourceopen res_lib_lck_resourceopen;
  543. if (lckResourceHandle == NULL) {
  544. return (SA_AIS_ERR_INVALID_PARAM);
  545. }
  546. if (lockResourceName == NULL) {
  547. return (SA_AIS_ERR_INVALID_PARAM);
  548. }
  549. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  550. (void *)&lckInstance);
  551. if (error != SA_AIS_OK) {
  552. goto error_exit;
  553. }
  554. error = saHandleCreate (&lckResourceHandleDatabase,
  555. sizeof (struct lckResourceInstance), lckResourceHandle);
  556. if (error != SA_AIS_OK) {
  557. goto error_put_lck;
  558. }
  559. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  560. *lckResourceHandle, (void *)&lckResourceInstance);
  561. if (error != SA_AIS_OK) {
  562. goto error_destroy;
  563. }
  564. lckResourceInstance->response_fd = lckInstance->response_fd;
  565. lckResourceInstance->lckHandle = lckHandle;
  566. lckResourceInstance->lckResourceHandle = *lckResourceHandle;
  567. lckResourceInstance->response_mutex = &lckInstance->response_mutex;
  568. req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen);
  569. req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPEN;
  570. marshall_to_mar_name_t (&req_lib_lck_resourceopen.lockResourceName, (SaNameT *)lockResourceName);
  571. memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof(SaNameT));
  572. req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags;
  573. req_lib_lck_resourceopen.resourceHandle = *lckResourceHandle;
  574. req_lib_lck_resourceopen.async_call = 0;
  575. pthread_mutex_lock (&lckInstance->response_mutex);
  576. error = saSendReceiveReply (lckResourceInstance->response_fd,
  577. &req_lib_lck_resourceopen,
  578. sizeof (struct req_lib_lck_resourceopen),
  579. &res_lib_lck_resourceopen,
  580. sizeof (struct res_lib_lck_resourceopen));
  581. pthread_mutex_unlock (&lckInstance->response_mutex);
  582. if (res_lib_lck_resourceopen.header.error != SA_AIS_OK) {
  583. error = res_lib_lck_resourceopen.header.error;
  584. goto error_put_destroy;
  585. }
  586. memcpy (&lckResourceInstance->source,
  587. &res_lib_lck_resourceopen.source,
  588. sizeof (mar_message_source_t));
  589. saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle);
  590. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  591. list_init (&lckResourceInstance->list);
  592. list_add (&lckResourceInstance->list, &lckInstance->resource_list);
  593. return (error);
  594. error_put_destroy:
  595. saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle);
  596. error_destroy:
  597. saHandleDestroy (&lckResourceHandleDatabase, *lckResourceHandle);
  598. error_put_lck:
  599. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  600. error_exit:
  601. return (error);
  602. }
  603. SaAisErrorT
  604. saLckResourceOpenAsync (
  605. SaLckHandleT lckHandle,
  606. SaInvocationT invocation,
  607. const SaNameT *lockResourceName,
  608. SaLckResourceOpenFlagsT resourceOpenFlags)
  609. {
  610. struct lckResourceInstance *lckResourceInstance;
  611. struct lckInstance *lckInstance;
  612. SaLckResourceHandleT lckResourceHandle;
  613. SaAisErrorT error;
  614. struct req_lib_lck_resourceopen req_lib_lck_resourceopen;
  615. struct res_lib_lck_resourceopenasync res_lib_lck_resourceopenasync;
  616. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  617. (void *)&lckInstance);
  618. if (error != SA_AIS_OK) {
  619. goto error_exit;
  620. }
  621. if (lckInstance->callbacks.saLckResourceOpenCallback == NULL) {
  622. error = SA_AIS_ERR_INIT;
  623. goto error_put_lck;
  624. }
  625. error = saHandleCreate (&lckResourceHandleDatabase,
  626. sizeof (struct lckResourceInstance), &lckResourceHandle);
  627. if (error != SA_AIS_OK) {
  628. goto error_put_lck;
  629. }
  630. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  631. (void *)&lckResourceInstance);
  632. if (error != SA_AIS_OK) {
  633. goto error_destroy;
  634. }
  635. lckResourceInstance->response_fd = lckInstance->response_fd;
  636. lckResourceInstance->response_mutex = &lckInstance->response_mutex;
  637. lckResourceInstance->lckHandle = lckHandle;
  638. lckResourceInstance->lckResourceHandle = lckResourceHandle;
  639. lckResourceInstance->resourceOpenFlags = resourceOpenFlags;
  640. marshall_to_mar_name_t (&req_lib_lck_resourceopen.lockResourceName,
  641. (SaNameT *)lockResourceName);
  642. memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof (SaNameT));
  643. req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen);
  644. req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPENASYNC;
  645. req_lib_lck_resourceopen.invocation = invocation;
  646. req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags;
  647. req_lib_lck_resourceopen.resourceHandle = lckResourceHandle;
  648. req_lib_lck_resourceopen.async_call = 1;
  649. pthread_mutex_lock (&lckInstance->response_mutex);
  650. error = saSendReceiveReply (lckResourceInstance->response_fd,
  651. &req_lib_lck_resourceopen,
  652. sizeof (struct req_lib_lck_resourceopen),
  653. &res_lib_lck_resourceopenasync,
  654. sizeof (struct res_lib_lck_resourceopenasync));
  655. pthread_mutex_unlock (&lckInstance->response_mutex);
  656. if (error == SA_AIS_OK) {
  657. saHandleInstancePut (&lckResourceHandleDatabase,
  658. lckResourceHandle);
  659. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  660. return (res_lib_lck_resourceopenasync.header.error);
  661. }
  662. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  663. error_destroy:
  664. saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle);
  665. error_put_lck:
  666. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  667. error_exit:
  668. return (error);
  669. }
  670. SaAisErrorT
  671. saLckResourceClose (
  672. SaLckResourceHandleT lckResourceHandle)
  673. {
  674. struct req_lib_lck_resourceclose req_lib_lck_resourceclose;
  675. struct res_lib_lck_resourceclose res_lib_lck_resourceclose;
  676. SaAisErrorT error;
  677. struct lckResourceInstance *lckResourceInstance;
  678. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  679. (void *)&lckResourceInstance);
  680. if (error != SA_AIS_OK) {
  681. return (error);
  682. }
  683. req_lib_lck_resourceclose.header.size = sizeof (struct req_lib_lck_resourceclose);
  684. req_lib_lck_resourceclose.header.id = MESSAGE_REQ_LCK_RESOURCECLOSE;
  685. marshall_to_mar_name_t (&req_lib_lck_resourceclose.lockResourceName,
  686. &lckResourceInstance->lockResourceName);
  687. req_lib_lck_resourceclose.resourceHandle = lckResourceHandle;
  688. pthread_mutex_lock (lckResourceInstance->response_mutex);
  689. error = saSendReceiveReply (lckResourceInstance->response_fd,
  690. &req_lib_lck_resourceclose,
  691. sizeof (struct req_lib_lck_resourceclose),
  692. &res_lib_lck_resourceclose,
  693. sizeof (struct res_lib_lck_resourceclose));
  694. pthread_mutex_unlock (lckResourceInstance->response_mutex);
  695. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  696. saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle);
  697. return (error == SA_AIS_OK ? res_lib_lck_resourceclose.header.error : error);
  698. }
  699. SaAisErrorT
  700. saLckResourceLock (
  701. SaLckResourceHandleT lckResourceHandle,
  702. SaLckLockIdT *lockId,
  703. SaLckLockModeT lockMode,
  704. SaLckLockFlagsT lockFlags,
  705. SaLckWaiterSignalT waiterSignal,
  706. SaTimeT timeout,
  707. SaLckLockStatusT *lockStatus)
  708. {
  709. struct req_lib_lck_resourcelock req_lib_lck_resourcelock;
  710. struct res_lib_lck_resourcelock res_lib_lck_resourcelock;
  711. SaAisErrorT error;
  712. struct lckResourceInstance *lckResourceInstance;
  713. struct lckLockIdInstance *lckLockIdInstance;
  714. int lock_fd;
  715. int dummy_fd;
  716. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  717. (void *)&lckResourceInstance);
  718. if (error != SA_AIS_OK) {
  719. return (error);
  720. }
  721. error = saHandleCreate (&lckLockIdHandleDatabase,
  722. sizeof (struct lckLockIdInstance), lockId);
  723. if (error != SA_AIS_OK) {
  724. goto error_put_lck;
  725. }
  726. error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId,
  727. (void *)&lckLockIdInstance);
  728. if (error != SA_AIS_OK) {
  729. goto error_destroy;
  730. }
  731. error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE);
  732. if (error != SA_AIS_OK) { // TODO error handling
  733. goto error_destroy;
  734. }
  735. lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex;
  736. lckLockIdInstance->response_fd = lckResourceInstance->response_fd;
  737. lckLockIdInstance->lckResourceHandle = lckResourceHandle;
  738. req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock);
  739. req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCK;
  740. marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName,
  741. &lckResourceInstance->lockResourceName);
  742. req_lib_lck_resourcelock.lockMode = lockMode;
  743. req_lib_lck_resourcelock.lockFlags = lockFlags;
  744. req_lib_lck_resourcelock.waiterSignal = waiterSignal;
  745. req_lib_lck_resourcelock.lockId = *lockId;
  746. req_lib_lck_resourcelock.async_call = 0;
  747. req_lib_lck_resourcelock.invocation = 0;
  748. req_lib_lck_resourcelock.resourceHandle = lckResourceHandle;
  749. memcpy (&req_lib_lck_resourcelock.source,
  750. &lckResourceInstance->source,
  751. sizeof (mar_message_source_t));
  752. /*
  753. * no mutex needed here since its a new connection
  754. */
  755. error = saSendReceiveReply (lock_fd,
  756. &req_lib_lck_resourcelock,
  757. sizeof (struct req_lib_lck_resourcelock),
  758. &res_lib_lck_resourcelock,
  759. sizeof (struct res_lib_lck_resourcelock));
  760. close (lock_fd);
  761. close (dummy_fd);
  762. if (error == SA_AIS_OK) {
  763. lckLockIdInstance->resource_lock = res_lib_lck_resourcelock.resource_lock;
  764. *lockStatus = res_lib_lck_resourcelock.lockStatus;
  765. return (res_lib_lck_resourcelock.header.error);
  766. }
  767. /*
  768. * Error
  769. */
  770. saHandleInstancePut (&lckLockIdHandleDatabase, *lockId);
  771. error_destroy:
  772. saHandleDestroy (&lckLockIdHandleDatabase, *lockId);
  773. error_put_lck:
  774. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  775. return (error);
  776. }
  777. SaAisErrorT
  778. saLckResourceLockAsync (
  779. SaLckResourceHandleT lckResourceHandle,
  780. SaInvocationT invocation,
  781. SaLckLockIdT *lockId,
  782. SaLckLockModeT lockMode,
  783. SaLckLockFlagsT lockFlags,
  784. SaLckWaiterSignalT waiterSignal)
  785. {
  786. struct req_lib_lck_resourcelock req_lib_lck_resourcelock;
  787. struct res_lib_lck_resourcelockasync res_lib_lck_resourcelockasync;
  788. SaAisErrorT error;
  789. struct lckResourceInstance *lckResourceInstance;
  790. struct lckLockIdInstance *lckLockIdInstance;
  791. int lock_fd;
  792. int dummy_fd;
  793. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  794. (void *)&lckResourceInstance);
  795. if (error != SA_AIS_OK) {
  796. return (error);
  797. }
  798. error = saHandleCreate (&lckLockIdHandleDatabase,
  799. sizeof (struct lckLockIdInstance), lockId);
  800. if (error != SA_AIS_OK) {
  801. goto error_put_lck;
  802. }
  803. error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId,
  804. (void *)&lckLockIdInstance);
  805. if (error != SA_AIS_OK) {
  806. goto error_destroy;
  807. }
  808. error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE);
  809. if (error != SA_AIS_OK) { // TODO error handling
  810. goto error_destroy;
  811. }
  812. lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex;
  813. lckLockIdInstance->response_fd = lckResourceInstance->response_fd;
  814. lckLockIdInstance->lckResourceHandle = lckResourceHandle;
  815. req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock);
  816. req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCKASYNC;
  817. marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName,
  818. &lckResourceInstance->lockResourceName);
  819. req_lib_lck_resourcelock.lockMode = lockMode;
  820. req_lib_lck_resourcelock.lockFlags = lockFlags;
  821. req_lib_lck_resourcelock.waiterSignal = waiterSignal;
  822. req_lib_lck_resourcelock.lockId = *lockId;
  823. req_lib_lck_resourcelock.async_call = 1;
  824. req_lib_lck_resourcelock.invocation = invocation;
  825. req_lib_lck_resourcelock.resourceHandle = lckResourceHandle;
  826. memcpy (&req_lib_lck_resourcelock.source,
  827. &lckResourceInstance->source,
  828. sizeof (mar_message_source_t));
  829. /*
  830. * no mutex needed here since its a new connection
  831. */
  832. error = saSendReceiveReply (lock_fd,
  833. &req_lib_lck_resourcelock,
  834. sizeof (struct req_lib_lck_resourcelock),
  835. &res_lib_lck_resourcelockasync,
  836. sizeof (struct res_lib_lck_resourcelock));
  837. close (lock_fd);
  838. close (dummy_fd);
  839. if (error == SA_AIS_OK) {
  840. return (res_lib_lck_resourcelockasync.header.error);
  841. }
  842. /*
  843. * Error
  844. */
  845. saHandleInstancePut (&lckLockIdHandleDatabase, *lockId);
  846. error_destroy:
  847. saHandleDestroy (&lckLockIdHandleDatabase, *lockId);
  848. error_put_lck:
  849. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  850. return (error);
  851. }
  852. SaAisErrorT
  853. saLckResourceUnlock (
  854. SaLckLockIdT lockId,
  855. SaTimeT timeout)
  856. {
  857. struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock;
  858. struct res_lib_lck_resourceunlock res_lib_lck_resourceunlock;
  859. SaAisErrorT error;
  860. struct lckLockIdInstance *lckLockIdInstance;
  861. struct lckResourceInstance *lckResourceInstance;
  862. error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId,
  863. (void *)&lckLockIdInstance);
  864. if (error != SA_AIS_OK) {
  865. return (error);
  866. }
  867. /*
  868. * Retrieve resource name
  869. */
  870. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  871. lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance);
  872. if (error != SA_AIS_OK) {
  873. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  874. return (error);
  875. }
  876. marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName,
  877. &lckResourceInstance->lockResourceName);
  878. saHandleInstancePut (&lckResourceHandleDatabase,
  879. lckLockIdInstance->lckResourceHandle);
  880. req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock);
  881. req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCK;
  882. req_lib_lck_resourceunlock.lockId = lockId;
  883. req_lib_lck_resourceunlock.timeout = timeout;
  884. req_lib_lck_resourceunlock.invocation = -1;
  885. req_lib_lck_resourceunlock.async_call = 0;
  886. req_lib_lck_resourceunlock.resource_lock = lckLockIdInstance->resource_lock;
  887. pthread_mutex_lock (lckLockIdInstance->response_mutex);
  888. error = saSendReceiveReply (lckLockIdInstance->response_fd,
  889. &req_lib_lck_resourceunlock,
  890. sizeof (struct req_lib_lck_resourceunlock),
  891. &res_lib_lck_resourceunlock,
  892. sizeof (struct res_lib_lck_resourceunlock));
  893. pthread_mutex_unlock (lckLockIdInstance->response_mutex);
  894. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  895. saHandleDestroy (&lckLockIdHandleDatabase, lockId);
  896. return (error == SA_AIS_OK ? res_lib_lck_resourceunlock.header.error : error);
  897. }
  898. SaAisErrorT
  899. saLckResourceUnlockAsync (
  900. SaInvocationT invocation,
  901. SaLckLockIdT lockId)
  902. {
  903. struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock;
  904. struct res_lib_lck_resourceunlockasync res_lib_lck_resourceunlockasync;
  905. SaAisErrorT error;
  906. struct lckLockIdInstance *lckLockIdInstance;
  907. struct lckResourceInstance *lckResourceInstance;
  908. error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId,
  909. (void *)&lckLockIdInstance);
  910. if (error != SA_AIS_OK) {
  911. return (error);
  912. }
  913. /*
  914. * Retrieve resource name
  915. */
  916. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  917. lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance);
  918. if (error != SA_AIS_OK) {
  919. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  920. return (error);
  921. }
  922. marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName,
  923. &lckResourceInstance->lockResourceName);
  924. saHandleInstancePut (&lckResourceHandleDatabase,
  925. lckLockIdInstance->lckResourceHandle);
  926. /*
  927. * Build and send request
  928. */
  929. req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock);
  930. req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCKASYNC;
  931. req_lib_lck_resourceunlock.invocation = invocation;
  932. req_lib_lck_resourceunlock.lockId = lockId;
  933. req_lib_lck_resourceunlock.async_call = 1;
  934. pthread_mutex_lock (lckLockIdInstance->response_mutex);
  935. error = saSendReceiveReply (lckLockIdInstance->response_fd,
  936. &req_lib_lck_resourceunlock,
  937. sizeof (struct req_lib_lck_resourceunlock),
  938. &res_lib_lck_resourceunlockasync,
  939. sizeof (struct res_lib_lck_resourceunlockasync));
  940. pthread_mutex_unlock (lckLockIdInstance->response_mutex);
  941. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  942. return (error == SA_AIS_OK ? res_lib_lck_resourceunlockasync.header.error : error);
  943. }
  944. SaAisErrorT
  945. saLckLockPurge (
  946. SaLckResourceHandleT lckResourceHandle)
  947. {
  948. struct req_lib_lck_lockpurge req_lib_lck_lockpurge;
  949. struct res_lib_lck_lockpurge res_lib_lck_lockpurge;
  950. SaAisErrorT error;
  951. struct lckResourceInstance *lckResourceInstance;
  952. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  953. (void *)&lckResourceInstance);
  954. if (error != SA_AIS_OK) {
  955. return (error);
  956. }
  957. req_lib_lck_lockpurge.header.size = sizeof (struct req_lib_lck_lockpurge);
  958. req_lib_lck_lockpurge.header.id = MESSAGE_REQ_LCK_LOCKPURGE;
  959. marshall_to_mar_name_t (&req_lib_lck_lockpurge.lockResourceName,
  960. &lckResourceInstance->lockResourceName);
  961. pthread_mutex_lock (lckResourceInstance->response_mutex);
  962. error = saSendReceiveReply (lckResourceInstance->response_fd,
  963. &req_lib_lck_lockpurge,
  964. sizeof (struct req_lib_lck_lockpurge),
  965. &res_lib_lck_lockpurge,
  966. sizeof (struct res_lib_lck_lockpurge));
  967. pthread_mutex_unlock (lckResourceInstance->response_mutex);
  968. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  969. return (error == SA_AIS_OK ? res_lib_lck_lockpurge.header.error : error);
  970. }