lck.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /*
  2. * Copyright (c) 2005 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 <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 "../include/saAis.h"
  47. #include "../include/list.h"
  48. #include "../include/saLck.h"
  49. #include "../include/ipc_gen.h"
  50. #include "../include/ipc_lck.h"
  51. #include "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. saHandleInstancePut (&lckResourceHandleDatabase,
  394. res_lib_lck_resourceopenasync->resourceHandle);
  395. } else {
  396. /*
  397. * open failed with error
  398. */
  399. callbacks.saLckResourceOpenCallback(
  400. res_lib_lck_resourceopenasync->invocation,
  401. -1,
  402. res_lib_lck_resourceopenasync->header.error);
  403. }
  404. break;
  405. case MESSAGE_RES_LCK_RESOURCELOCKASYNC:
  406. DPRINT (("grant\n"));
  407. if (callbacks.saLckLockGrantCallback == NULL) {
  408. continue;
  409. }
  410. res_lib_lck_resourcelockasync = (struct res_lib_lck_resourcelockasync *)&dispatch_data;
  411. /*
  412. * This instance get/listadd/put required so that close
  413. * later has the proper list of resources
  414. */
  415. if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) {
  416. error = saHandleInstanceGet (&lckLockIdHandleDatabase,
  417. res_lib_lck_resourcelockasync->lockId,
  418. (void *)&lckLockIdInstance);
  419. assert (error == SA_AIS_OK); /* should only be valid handles here */
  420. /*
  421. * open succeeded without error
  422. */
  423. lckLockIdInstance->resource_lock = res_lib_lck_resourcelockasync->resource_lock;
  424. callbacks.saLckLockGrantCallback(
  425. res_lib_lck_resourcelockasync->invocation,
  426. res_lib_lck_resourcelockasync->lockStatus,
  427. res_lib_lck_resourcelockasync->header.error);
  428. saHandleInstancePut (&lckLockIdHandleDatabase,
  429. res_lib_lck_resourcelockasync->lockId);
  430. } else {
  431. /*
  432. * open failed with error
  433. */
  434. callbacks.saLckLockGrantCallback (
  435. res_lib_lck_resourceopenasync->invocation,
  436. -1,
  437. res_lib_lck_resourceopenasync->header.error);
  438. }
  439. break;
  440. case MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC:
  441. if (callbacks.saLckResourceUnlockCallback == NULL) {
  442. continue;
  443. }
  444. res_lib_lck_resourceunlockasync = (struct res_lib_lck_resourceunlockasync *)&dispatch_data;
  445. callbacks.saLckResourceUnlockCallback (
  446. res_lib_lck_resourceunlockasync->invocation,
  447. res_lib_lck_resourceunlockasync->header.error);
  448. if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) {
  449. error = saHandleInstanceGet (&lckLockIdHandleDatabase,
  450. res_lib_lck_resourceunlockasync->lockId,
  451. (void *)&lckLockIdInstance);
  452. if (error == SA_AIS_OK) {
  453. saHandleInstancePut (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId);
  454. saHandleDestroy (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId);
  455. }
  456. }
  457. break;
  458. #ifdef NOT_DONE_YET
  459. case MESSAGE_RES_LCK_RESOURCESYNCHRONIZEASYNC:
  460. if (callbacks.saLckResourceSynchronizeCallback == NULL) {
  461. continue;
  462. }
  463. res_lib_lck_resourcesynchronizeasync = (struct res_lib_lck_resourcesynchronizeasync *) &dispatch_data;
  464. callbacks.saLckResourceSynchronizeCallback(
  465. res_lib_lck_resourcesynchronizeasync->invocation,
  466. res_lib_lck_resourcesynchronizeasync->header.error);
  467. break;
  468. #endif
  469. default:
  470. /* TODO */
  471. break;
  472. }
  473. /*
  474. * Determine if more messages should be processed
  475. */
  476. switch (dispatchFlags) {
  477. case SA_DISPATCH_ONE:
  478. cont = 0;
  479. break;
  480. case SA_DISPATCH_ALL:
  481. break;
  482. case SA_DISPATCH_BLOCKING:
  483. break;
  484. }
  485. } while (cont);
  486. error_unlock:
  487. pthread_mutex_unlock(&lckInstance->dispatch_mutex);
  488. error_put:
  489. saHandleInstancePut(&lckHandleDatabase, lckHandle);
  490. error_exit:
  491. return (error);
  492. }
  493. SaAisErrorT
  494. saLckFinalize (
  495. const SaLckHandleT lckHandle)
  496. {
  497. struct lckInstance *lckInstance;
  498. SaAisErrorT error;
  499. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  500. (void *)&lckInstance);
  501. if (error != SA_AIS_OK) {
  502. return (error);
  503. }
  504. pthread_mutex_lock (&lckInstance->response_mutex);
  505. /*
  506. * Another thread has already started finalizing
  507. */
  508. if (lckInstance->finalize) {
  509. pthread_mutex_unlock (&lckInstance->response_mutex);
  510. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  511. return (SA_AIS_ERR_BAD_HANDLE);
  512. }
  513. lckInstance->finalize = 1;
  514. pthread_mutex_unlock (&lckInstance->response_mutex);
  515. // TODO lckInstanceFinalize (lckInstance);
  516. if (lckInstance->response_fd != -1) {
  517. shutdown (lckInstance->response_fd, 0);
  518. close (lckInstance->response_fd);
  519. }
  520. if (lckInstance->dispatch_fd != -1) {
  521. shutdown (lckInstance->dispatch_fd, 0);
  522. close (lckInstance->dispatch_fd);
  523. }
  524. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  525. return (SA_AIS_OK);
  526. }
  527. SaAisErrorT
  528. saLckResourceOpen (
  529. SaLckHandleT lckHandle,
  530. const SaNameT *lockResourceName,
  531. SaLckResourceOpenFlagsT resourceOpenFlags,
  532. SaTimeT timeout,
  533. SaLckResourceHandleT *lckResourceHandle)
  534. {
  535. SaAisErrorT error;
  536. struct lckResourceInstance *lckResourceInstance;
  537. struct lckInstance *lckInstance;
  538. struct req_lib_lck_resourceopen req_lib_lck_resourceopen;
  539. struct res_lib_lck_resourceopen res_lib_lck_resourceopen;
  540. if (lckResourceHandle == NULL) {
  541. return (SA_AIS_ERR_INVALID_PARAM);
  542. }
  543. if (lockResourceName == NULL) {
  544. return (SA_AIS_ERR_INVALID_PARAM);
  545. }
  546. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  547. (void *)&lckInstance);
  548. if (error != SA_AIS_OK) {
  549. goto error_exit;
  550. }
  551. error = saHandleCreate (&lckResourceHandleDatabase,
  552. sizeof (struct lckResourceInstance), lckResourceHandle);
  553. if (error != SA_AIS_OK) {
  554. goto error_put_lck;
  555. }
  556. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  557. *lckResourceHandle, (void *)&lckResourceInstance);
  558. if (error != SA_AIS_OK) {
  559. goto error_destroy;
  560. }
  561. lckResourceInstance->response_fd = lckInstance->response_fd;
  562. lckResourceInstance->lckHandle = lckHandle;
  563. lckResourceInstance->lckResourceHandle = *lckResourceHandle;
  564. lckResourceInstance->response_mutex = &lckInstance->response_mutex;
  565. req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen);
  566. req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPEN;
  567. marshall_to_mar_name_t (&req_lib_lck_resourceopen.lockResourceName, (SaNameT *)lockResourceName);
  568. memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof(SaNameT));
  569. req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags;
  570. req_lib_lck_resourceopen.resourceHandle = *lckResourceHandle;
  571. req_lib_lck_resourceopen.async_call = 0;
  572. pthread_mutex_lock (&lckInstance->response_mutex);
  573. error = saSendReceiveReply (lckResourceInstance->response_fd,
  574. &req_lib_lck_resourceopen,
  575. sizeof (struct req_lib_lck_resourceopen),
  576. &res_lib_lck_resourceopen,
  577. sizeof (struct res_lib_lck_resourceopen));
  578. pthread_mutex_unlock (&lckInstance->response_mutex);
  579. if (res_lib_lck_resourceopen.header.error != SA_AIS_OK) {
  580. error = res_lib_lck_resourceopen.header.error;
  581. goto error_put_destroy;
  582. }
  583. memcpy (&lckResourceInstance->source,
  584. &res_lib_lck_resourceopen.source,
  585. sizeof (mar_message_source_t));
  586. saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle);
  587. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  588. list_init (&lckResourceInstance->list);
  589. list_add (&lckResourceInstance->list, &lckInstance->resource_list);
  590. return (error);
  591. error_put_destroy:
  592. saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle);
  593. error_destroy:
  594. saHandleDestroy (&lckResourceHandleDatabase, *lckResourceHandle);
  595. error_put_lck:
  596. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  597. error_exit:
  598. return (error);
  599. }
  600. SaAisErrorT
  601. saLckResourceOpenAsync (
  602. SaLckHandleT lckHandle,
  603. SaInvocationT invocation,
  604. const SaNameT *lockResourceName,
  605. SaLckResourceOpenFlagsT resourceOpenFlags)
  606. {
  607. struct lckResourceInstance *lckResourceInstance;
  608. struct lckInstance *lckInstance;
  609. SaLckResourceHandleT lckResourceHandle;
  610. SaAisErrorT error;
  611. struct req_lib_lck_resourceopen req_lib_lck_resourceopen;
  612. struct res_lib_lck_resourceopenasync res_lib_lck_resourceopenasync;
  613. error = saHandleInstanceGet (&lckHandleDatabase, lckHandle,
  614. (void *)&lckInstance);
  615. if (error != SA_AIS_OK) {
  616. goto error_exit;
  617. }
  618. if (lckInstance->callbacks.saLckResourceOpenCallback == NULL) {
  619. error = SA_AIS_ERR_INIT;
  620. goto error_put_lck;
  621. }
  622. error = saHandleCreate (&lckResourceHandleDatabase,
  623. sizeof (struct lckResourceInstance), &lckResourceHandle);
  624. if (error != SA_AIS_OK) {
  625. goto error_put_lck;
  626. }
  627. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  628. (void *)&lckResourceInstance);
  629. if (error != SA_AIS_OK) {
  630. goto error_destroy;
  631. }
  632. lckResourceInstance->response_fd = lckInstance->response_fd;
  633. lckResourceInstance->response_mutex = &lckInstance->response_mutex;
  634. lckResourceInstance->lckHandle = lckHandle;
  635. lckResourceInstance->lckResourceHandle = lckResourceHandle;
  636. lckResourceInstance->resourceOpenFlags = resourceOpenFlags;
  637. memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof (SaNameT));
  638. req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen);
  639. req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPENASYNC;
  640. req_lib_lck_resourceopen.invocation = invocation;
  641. req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags;
  642. req_lib_lck_resourceopen.resourceHandle = lckResourceHandle;
  643. req_lib_lck_resourceopen.async_call = 1;
  644. pthread_mutex_lock (&lckInstance->response_mutex);
  645. error = saSendReceiveReply (lckResourceInstance->response_fd,
  646. &req_lib_lck_resourceopen,
  647. sizeof (struct req_lib_lck_resourceopen),
  648. &res_lib_lck_resourceopenasync,
  649. sizeof (struct res_lib_lck_resourceopenasync));
  650. pthread_mutex_unlock (&lckInstance->response_mutex);
  651. if (error == SA_AIS_OK) {
  652. saHandleInstancePut (&lckResourceHandleDatabase,
  653. lckResourceHandle);
  654. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  655. return (res_lib_lck_resourceopenasync.header.error);
  656. }
  657. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  658. error_destroy:
  659. saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle);
  660. error_put_lck:
  661. saHandleInstancePut (&lckHandleDatabase, lckHandle);
  662. error_exit:
  663. return (error);
  664. }
  665. SaAisErrorT
  666. saLckResourceClose (
  667. SaLckResourceHandleT lckResourceHandle)
  668. {
  669. struct req_lib_lck_resourceclose req_lib_lck_resourceclose;
  670. struct res_lib_lck_resourceclose res_lib_lck_resourceclose;
  671. SaAisErrorT error;
  672. struct lckResourceInstance *lckResourceInstance;
  673. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  674. (void *)&lckResourceInstance);
  675. if (error != SA_AIS_OK) {
  676. return (error);
  677. }
  678. req_lib_lck_resourceclose.header.size = sizeof (struct req_lib_lck_resourceclose);
  679. req_lib_lck_resourceclose.header.id = MESSAGE_REQ_LCK_RESOURCECLOSE;
  680. marshall_to_mar_name_t (&req_lib_lck_resourceclose.lockResourceName,
  681. &lckResourceInstance->lockResourceName);
  682. req_lib_lck_resourceclose.resourceHandle = lckResourceHandle;
  683. pthread_mutex_lock (lckResourceInstance->response_mutex);
  684. error = saSendReceiveReply (lckResourceInstance->response_fd,
  685. &req_lib_lck_resourceclose,
  686. sizeof (struct req_lib_lck_resourceclose),
  687. &res_lib_lck_resourceclose,
  688. sizeof (struct res_lib_lck_resourceclose));
  689. pthread_mutex_unlock (lckResourceInstance->response_mutex);
  690. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  691. saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle);
  692. return (error == SA_AIS_OK ? res_lib_lck_resourceclose.header.error : error);
  693. }
  694. SaAisErrorT
  695. saLckResourceLock (
  696. SaLckResourceHandleT lckResourceHandle,
  697. SaLckLockIdT *lockId,
  698. SaLckLockModeT lockMode,
  699. SaLckLockFlagsT lockFlags,
  700. SaLckWaiterSignalT waiterSignal,
  701. SaTimeT timeout,
  702. SaLckLockStatusT *lockStatus)
  703. {
  704. struct req_lib_lck_resourcelock req_lib_lck_resourcelock;
  705. struct res_lib_lck_resourcelock res_lib_lck_resourcelock;
  706. SaAisErrorT error;
  707. struct lckResourceInstance *lckResourceInstance;
  708. struct lckLockIdInstance *lckLockIdInstance;
  709. int lock_fd;
  710. int dummy_fd;
  711. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  712. (void *)&lckResourceInstance);
  713. if (error != SA_AIS_OK) {
  714. return (error);
  715. }
  716. error = saHandleCreate (&lckLockIdHandleDatabase,
  717. sizeof (struct lckLockIdInstance), lockId);
  718. if (error != SA_AIS_OK) {
  719. goto error_put_lck;
  720. }
  721. error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId,
  722. (void *)&lckLockIdInstance);
  723. if (error != SA_AIS_OK) {
  724. goto error_destroy;
  725. }
  726. error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE);
  727. if (error != SA_AIS_OK) { // TODO error handling
  728. goto error_destroy;
  729. }
  730. lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex;
  731. lckLockIdInstance->response_fd = lckResourceInstance->response_fd;
  732. lckLockIdInstance->lckResourceHandle = lckResourceHandle;
  733. req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock);
  734. req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCK;
  735. marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName,
  736. &lckResourceInstance->lockResourceName);
  737. req_lib_lck_resourcelock.lockMode = lockMode;
  738. req_lib_lck_resourcelock.lockFlags = lockFlags;
  739. req_lib_lck_resourcelock.waiterSignal = waiterSignal;
  740. req_lib_lck_resourcelock.lockId = *lockId;
  741. req_lib_lck_resourcelock.async_call = 0;
  742. req_lib_lck_resourcelock.invocation = 0;
  743. req_lib_lck_resourcelock.resourceHandle = lckResourceHandle;
  744. memcpy (&req_lib_lck_resourcelock.source,
  745. &lckResourceInstance->source,
  746. sizeof (mar_message_source_t));
  747. /*
  748. * no mutex needed here since its a new connection
  749. */
  750. error = saSendReceiveReply (lock_fd,
  751. &req_lib_lck_resourcelock,
  752. sizeof (struct req_lib_lck_resourcelock),
  753. &res_lib_lck_resourcelock,
  754. sizeof (struct res_lib_lck_resourcelock));
  755. close (lock_fd);
  756. close (dummy_fd);
  757. if (error == SA_AIS_OK) {
  758. lckLockIdInstance->resource_lock = res_lib_lck_resourcelock.resource_lock;
  759. *lockStatus = res_lib_lck_resourcelock.lockStatus;
  760. return (res_lib_lck_resourcelock.header.error);
  761. }
  762. /*
  763. * Error
  764. */
  765. saHandleInstancePut (&lckLockIdHandleDatabase, *lockId);
  766. error_destroy:
  767. saHandleDestroy (&lckLockIdHandleDatabase, *lockId);
  768. error_put_lck:
  769. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  770. return (error);
  771. }
  772. SaAisErrorT
  773. saLckResourceLockAsync (
  774. SaLckResourceHandleT lckResourceHandle,
  775. SaInvocationT invocation,
  776. SaLckLockIdT *lockId,
  777. SaLckLockModeT lockMode,
  778. SaLckLockFlagsT lockFlags,
  779. SaLckWaiterSignalT waiterSignal)
  780. {
  781. struct req_lib_lck_resourcelock req_lib_lck_resourcelock;
  782. struct res_lib_lck_resourcelockasync res_lib_lck_resourcelockasync;
  783. SaAisErrorT error;
  784. struct lckResourceInstance *lckResourceInstance;
  785. struct lckLockIdInstance *lckLockIdInstance;
  786. int lock_fd;
  787. int dummy_fd;
  788. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  789. (void *)&lckResourceInstance);
  790. if (error != SA_AIS_OK) {
  791. return (error);
  792. }
  793. error = saHandleCreate (&lckLockIdHandleDatabase,
  794. sizeof (struct lckLockIdInstance), lockId);
  795. if (error != SA_AIS_OK) {
  796. goto error_put_lck;
  797. }
  798. error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId,
  799. (void *)&lckLockIdInstance);
  800. if (error != SA_AIS_OK) {
  801. goto error_destroy;
  802. }
  803. error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE);
  804. if (error != SA_AIS_OK) { // TODO error handling
  805. goto error_destroy;
  806. }
  807. lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex;
  808. lckLockIdInstance->response_fd = lckResourceInstance->response_fd;
  809. lckLockIdInstance->lckResourceHandle = lckResourceHandle;
  810. req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock);
  811. req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCKASYNC;
  812. marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName,
  813. &lckResourceInstance->lockResourceName);
  814. req_lib_lck_resourcelock.lockMode = lockMode;
  815. req_lib_lck_resourcelock.lockFlags = lockFlags;
  816. req_lib_lck_resourcelock.waiterSignal = waiterSignal;
  817. req_lib_lck_resourcelock.lockId = *lockId;
  818. req_lib_lck_resourcelock.async_call = 1;
  819. req_lib_lck_resourcelock.invocation = invocation;
  820. req_lib_lck_resourcelock.resourceHandle = lckResourceHandle;
  821. memcpy (&req_lib_lck_resourcelock.source,
  822. &lckResourceInstance->source,
  823. sizeof (mar_message_source_t));
  824. /*
  825. * no mutex needed here since its a new connection
  826. */
  827. error = saSendReceiveReply (lock_fd,
  828. &req_lib_lck_resourcelock,
  829. sizeof (struct req_lib_lck_resourcelock),
  830. &res_lib_lck_resourcelockasync,
  831. sizeof (struct res_lib_lck_resourcelock));
  832. close (lock_fd);
  833. close (dummy_fd);
  834. if (error == SA_AIS_OK) {
  835. return (res_lib_lck_resourcelockasync.header.error);
  836. }
  837. /*
  838. * Error
  839. */
  840. saHandleInstancePut (&lckLockIdHandleDatabase, *lockId);
  841. error_destroy:
  842. saHandleDestroy (&lckLockIdHandleDatabase, *lockId);
  843. error_put_lck:
  844. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  845. return (error);
  846. }
  847. SaAisErrorT
  848. saLckResourceUnlock (
  849. SaLckLockIdT lockId,
  850. SaTimeT timeout)
  851. {
  852. struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock;
  853. struct res_lib_lck_resourceunlock res_lib_lck_resourceunlock;
  854. SaAisErrorT error;
  855. struct lckLockIdInstance *lckLockIdInstance;
  856. struct lckResourceInstance *lckResourceInstance;
  857. error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId,
  858. (void *)&lckLockIdInstance);
  859. if (error != SA_AIS_OK) {
  860. return (error);
  861. }
  862. /*
  863. * Retrieve resource name
  864. */
  865. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  866. lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance);
  867. if (error != SA_AIS_OK) {
  868. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  869. return (error);
  870. }
  871. marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName,
  872. &lckResourceInstance->lockResourceName);
  873. saHandleInstancePut (&lckResourceHandleDatabase,
  874. lckLockIdInstance->lckResourceHandle);
  875. req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock);
  876. req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCK;
  877. req_lib_lck_resourceunlock.lockId = lockId;
  878. req_lib_lck_resourceunlock.timeout = timeout;
  879. req_lib_lck_resourceunlock.invocation = -1;
  880. req_lib_lck_resourceunlock.async_call = 0;
  881. req_lib_lck_resourceunlock.resource_lock = lckLockIdInstance->resource_lock;
  882. pthread_mutex_lock (lckLockIdInstance->response_mutex);
  883. error = saSendReceiveReply (lckLockIdInstance->response_fd,
  884. &req_lib_lck_resourceunlock,
  885. sizeof (struct req_lib_lck_resourceunlock),
  886. &res_lib_lck_resourceunlock,
  887. sizeof (struct res_lib_lck_resourceunlock));
  888. pthread_mutex_unlock (lckLockIdInstance->response_mutex);
  889. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  890. saHandleDestroy (&lckLockIdHandleDatabase, lockId);
  891. return (error == SA_AIS_OK ? res_lib_lck_resourceunlock.header.error : error);
  892. }
  893. SaAisErrorT
  894. saLckResourceUnlockAsync (
  895. SaInvocationT invocation,
  896. SaLckLockIdT lockId)
  897. {
  898. struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock;
  899. struct res_lib_lck_resourceunlockasync res_lib_lck_resourceunlockasync;
  900. SaAisErrorT error;
  901. struct lckLockIdInstance *lckLockIdInstance;
  902. struct lckResourceInstance *lckResourceInstance;
  903. error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId,
  904. (void *)&lckLockIdInstance);
  905. if (error != SA_AIS_OK) {
  906. return (error);
  907. }
  908. /*
  909. * Retrieve resource name
  910. */
  911. error = saHandleInstanceGet (&lckResourceHandleDatabase,
  912. lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance);
  913. if (error != SA_AIS_OK) {
  914. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  915. return (error);
  916. }
  917. marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName,
  918. &lckResourceInstance->lockResourceName);
  919. saHandleInstancePut (&lckResourceHandleDatabase,
  920. lckLockIdInstance->lckResourceHandle);
  921. /*
  922. * Build and send request
  923. */
  924. req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock);
  925. req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCKASYNC;
  926. req_lib_lck_resourceunlock.invocation = invocation;
  927. req_lib_lck_resourceunlock.lockId = lockId;
  928. req_lib_lck_resourceunlock.async_call = 1;
  929. pthread_mutex_lock (lckLockIdInstance->response_mutex);
  930. error = saSendReceiveReply (lckLockIdInstance->response_fd,
  931. &req_lib_lck_resourceunlock,
  932. sizeof (struct req_lib_lck_resourceunlock),
  933. &res_lib_lck_resourceunlockasync,
  934. sizeof (struct res_lib_lck_resourceunlockasync));
  935. pthread_mutex_unlock (lckLockIdInstance->response_mutex);
  936. saHandleInstancePut (&lckLockIdHandleDatabase, lockId);
  937. return (error == SA_AIS_OK ? res_lib_lck_resourceunlockasync.header.error : error);
  938. }
  939. SaAisErrorT
  940. saLckLockPurge (
  941. SaLckResourceHandleT lckResourceHandle)
  942. {
  943. struct req_lib_lck_lockpurge req_lib_lck_lockpurge;
  944. struct res_lib_lck_lockpurge res_lib_lck_lockpurge;
  945. SaAisErrorT error;
  946. struct lckResourceInstance *lckResourceInstance;
  947. error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle,
  948. (void *)&lckResourceInstance);
  949. if (error != SA_AIS_OK) {
  950. return (error);
  951. }
  952. req_lib_lck_lockpurge.header.size = sizeof (struct req_lib_lck_lockpurge);
  953. req_lib_lck_lockpurge.header.id = MESSAGE_REQ_LCK_LOCKPURGE;
  954. marshall_to_mar_name_t (&req_lib_lck_lockpurge.lockResourceName,
  955. &lckResourceInstance->lockResourceName);
  956. pthread_mutex_lock (lckResourceInstance->response_mutex);
  957. error = saSendReceiveReply (lckResourceInstance->response_fd,
  958. &req_lib_lck_lockpurge,
  959. sizeof (struct req_lib_lck_lockpurge),
  960. &res_lib_lck_lockpurge,
  961. sizeof (struct res_lib_lck_lockpurge));
  962. pthread_mutex_unlock (lckResourceInstance->response_mutex);
  963. saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle);
  964. return (error == SA_AIS_OK ? res_lib_lck_lockpurge.header.error : error);
  965. }