ckpt.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  1. /*
  2. * Copyright (c) 2002-2004 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/saCkpt.h"
  49. #include "../include/ipc_gen.h"
  50. #include "../include/ipc_ckpt.h"
  51. #include "util.h"
  52. struct message_overlay {
  53. struct res_header header;
  54. char data[4096];
  55. };
  56. /*
  57. * Data structure for instance data
  58. */
  59. struct ckptInstance {
  60. int response_fd;
  61. int dispatch_fd;
  62. SaCkptCallbacksT callbacks;
  63. int finalize;
  64. SaCkptHandleT ckptHandle;
  65. pthread_mutex_t response_mutex;
  66. pthread_mutex_t dispatch_mutex;
  67. struct list_head checkpoint_list;
  68. };
  69. struct ckptCheckpointInstance {
  70. int response_fd;
  71. SaCkptHandleT ckptHandle;
  72. SaCkptCheckpointHandleT checkpointHandle;
  73. SaCkptCheckpointOpenFlagsT checkpointOpenFlags;
  74. SaNameT checkpointName;
  75. pthread_mutex_t response_mutex;
  76. struct list_head list;
  77. struct list_head section_iteration_list_head;
  78. };
  79. struct ckptSectionIterationInstance {
  80. int response_fd;
  81. SaCkptSectionIterationHandleT sectionIterationHandle;
  82. SaNameT checkpointName;
  83. struct list_head sectionIdListHead;
  84. pthread_mutex_t response_mutex;
  85. struct list_head list;
  86. };
  87. void ckptHandleInstanceDestructor (void *instance);
  88. void checkpointHandleInstanceDestructor (void *instance);
  89. void ckptSectionIterationHandleInstanceDestructor (void *instance);
  90. /*
  91. * All CKPT instances in this database
  92. */
  93. static struct saHandleDatabase ckptHandleDatabase = {
  94. .handleCount = 0,
  95. .handles = 0,
  96. .mutex = PTHREAD_MUTEX_INITIALIZER,
  97. .handleInstanceDestructor = ckptHandleInstanceDestructor
  98. };
  99. /*
  100. * All Checkpoint instances in this database
  101. */
  102. static struct saHandleDatabase checkpointHandleDatabase = {
  103. .handleCount = 0,
  104. .handles = 0,
  105. .mutex = PTHREAD_MUTEX_INITIALIZER,
  106. .handleInstanceDestructor = checkpointHandleInstanceDestructor
  107. };
  108. /*
  109. * All section iterators in this database
  110. */
  111. static struct saHandleDatabase ckptSectionIterationHandleDatabase = {
  112. .handleCount = 0,
  113. .handles = 0,
  114. .mutex = PTHREAD_MUTEX_INITIALIZER,
  115. .handleInstanceDestructor = ckptSectionIterationHandleInstanceDestructor
  116. };
  117. /*
  118. * Versions supported
  119. */
  120. static SaVersionT ckptVersionsSupported[] = {
  121. { 'B', 1, 1 }
  122. };
  123. static struct saVersionDatabase ckptVersionDatabase = {
  124. sizeof (ckptVersionsSupported) / sizeof (SaVersionT),
  125. ckptVersionsSupported
  126. };
  127. struct iteratorSectionIdListEntry {
  128. struct list_head list;
  129. unsigned char data[0];
  130. };
  131. /*
  132. * Implementation
  133. */
  134. void ckptHandleInstanceDestructor (void *instance)
  135. {
  136. }
  137. void checkpointHandleInstanceDestructor (void *instance)
  138. {
  139. return;
  140. }
  141. void ckptSectionIterationHandleInstanceDestructor (void *instance)
  142. {
  143. }
  144. static void ckptSectionIterationInstanceFinalize (struct ckptSectionIterationInstance *ckptSectionIterationInstance)
  145. {
  146. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  147. struct list_head *sectionIdIterationList;
  148. struct list_head *sectionIdIterationListNext;
  149. /*
  150. * iterate list of section ids for this iterator to free the allocated memory
  151. * be careful to cache next pointer because free removes memory from use
  152. */
  153. for (sectionIdIterationList = ckptSectionIterationInstance->sectionIdListHead.next,
  154. sectionIdIterationListNext = sectionIdIterationList->next;
  155. sectionIdIterationList != &ckptSectionIterationInstance->sectionIdListHead;
  156. sectionIdIterationList = sectionIdIterationListNext,
  157. sectionIdIterationListNext = sectionIdIterationList->next) {
  158. iteratorSectionIdListEntry = list_entry (sectionIdIterationList,
  159. struct iteratorSectionIdListEntry, list);
  160. free (iteratorSectionIdListEntry);
  161. }
  162. list_del (&ckptSectionIterationInstance->list);
  163. saHandleDestroy (&ckptSectionIterationHandleDatabase,
  164. ckptSectionIterationInstance->sectionIterationHandle);
  165. }
  166. static void ckptCheckpointInstanceFinalize (struct ckptCheckpointInstance *ckptCheckpointInstance)
  167. {
  168. struct ckptSectionIterationInstance *sectionIterationInstance;
  169. struct list_head *sectionIterationList;
  170. struct list_head *sectionIterationListNext;
  171. for (sectionIterationList = ckptCheckpointInstance->section_iteration_list_head.next,
  172. sectionIterationListNext = sectionIterationList->next;
  173. sectionIterationList != &ckptCheckpointInstance->section_iteration_list_head;
  174. sectionIterationList = sectionIterationListNext,
  175. sectionIterationListNext = sectionIterationList->next) {
  176. sectionIterationInstance = list_entry (sectionIterationList,
  177. struct ckptSectionIterationInstance, list);
  178. ckptSectionIterationInstanceFinalize (sectionIterationInstance);
  179. }
  180. list_del (&ckptCheckpointInstance->list);
  181. saHandleDestroy (&checkpointHandleDatabase, ckptCheckpointInstance->checkpointHandle);
  182. }
  183. static void ckptInstanceFinalize (struct ckptInstance *ckptInstance)
  184. {
  185. struct ckptCheckpointInstance *ckptCheckpointInstance;
  186. struct list_head *checkpointInstanceList;
  187. struct list_head *checkpointInstanceListNext;
  188. for (checkpointInstanceList = ckptInstance->checkpoint_list.next,
  189. checkpointInstanceListNext = checkpointInstanceList->next;
  190. checkpointInstanceList != &ckptInstance->checkpoint_list;
  191. checkpointInstanceList = checkpointInstanceListNext,
  192. checkpointInstanceListNext = checkpointInstanceList->next) {
  193. ckptCheckpointInstance = list_entry (checkpointInstanceList,
  194. struct ckptCheckpointInstance, list);
  195. ckptCheckpointInstanceFinalize (ckptCheckpointInstance);
  196. }
  197. saHandleDestroy (&ckptHandleDatabase, ckptInstance->ckptHandle);
  198. }
  199. SaAisErrorT
  200. saCkptInitialize (
  201. SaCkptHandleT *ckptHandle,
  202. const SaCkptCallbacksT *callbacks,
  203. SaVersionT *version)
  204. {
  205. struct ckptInstance *ckptInstance;
  206. SaAisErrorT error = SA_AIS_OK;
  207. if (ckptHandle == NULL) {
  208. return (SA_AIS_ERR_INVALID_PARAM);
  209. }
  210. error = saVersionVerify (&ckptVersionDatabase, version);
  211. if (error != SA_AIS_OK) {
  212. goto error_no_destroy;
  213. }
  214. error = saHandleCreate (&ckptHandleDatabase, sizeof (struct ckptInstance),
  215. ckptHandle);
  216. if (error != SA_AIS_OK) {
  217. goto error_no_destroy;
  218. }
  219. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
  220. (void *)&ckptInstance);
  221. if (error != SA_AIS_OK) {
  222. goto error_destroy;
  223. }
  224. ckptInstance->response_fd = -1;
  225. error = saServiceConnectTwo (&ckptInstance->response_fd,
  226. &ckptInstance->dispatch_fd, CKPT_SERVICE);
  227. if (error != SA_AIS_OK) {
  228. goto error_put_destroy;
  229. }
  230. if (callbacks) {
  231. memcpy (&ckptInstance->callbacks, callbacks, sizeof (SaCkptCallbacksT));
  232. } else {
  233. memset (&ckptInstance->callbacks, 0, sizeof (SaCkptCallbacksT));
  234. }
  235. list_init (&ckptInstance->checkpoint_list);
  236. ckptInstance->ckptHandle = *ckptHandle;
  237. pthread_mutex_init (&ckptInstance->response_mutex, NULL);
  238. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  239. return (SA_AIS_OK);
  240. error_put_destroy:
  241. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  242. error_destroy:
  243. saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
  244. error_no_destroy:
  245. return (error);
  246. }
  247. SaAisErrorT
  248. saCkptSelectionObjectGet (
  249. const SaCkptHandleT ckptHandle,
  250. SaSelectionObjectT *selectionObject)
  251. {
  252. struct ckptInstance *ckptInstance;
  253. SaAisErrorT error;
  254. if (selectionObject == NULL) {
  255. return (SA_AIS_ERR_INVALID_PARAM);
  256. }
  257. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  258. if (error != SA_AIS_OK) {
  259. return (error);
  260. }
  261. *selectionObject = ckptInstance->dispatch_fd;
  262. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  263. return (SA_AIS_OK);
  264. }
  265. SaAisErrorT
  266. saCkptDispatch (
  267. const SaCkptHandleT ckptHandle,
  268. SaDispatchFlagsT dispatchFlags)
  269. {
  270. struct pollfd ufds;
  271. int poll_fd;
  272. int timeout = 1;
  273. SaCkptCallbacksT callbacks;
  274. SaAisErrorT error;
  275. int dispatch_avail;
  276. struct ckptInstance *ckptInstance;
  277. int cont = 1; /* always continue do loop except when set to 0 */
  278. struct message_overlay dispatch_data;
  279. struct res_lib_ckpt_checkpointopenasync *res_lib_ckpt_checkpointopenasync;
  280. struct res_lib_ckpt_checkpointsynchronizeasync *res_lib_ckpt_checkpointsynchronizeasync;
  281. struct ckptCheckpointInstance *ckptCheckpointInstance;
  282. if (dispatchFlags != SA_DISPATCH_ONE &&
  283. dispatchFlags != SA_DISPATCH_ALL &&
  284. dispatchFlags != SA_DISPATCH_BLOCKING) {
  285. return (SA_AIS_ERR_INVALID_PARAM);
  286. }
  287. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  288. (void *)&ckptInstance);
  289. if (error != SA_AIS_OK) {
  290. goto error_exit;
  291. }
  292. /*
  293. * Timeout instantly for SA_DISPATCH_ALL
  294. */
  295. if (dispatchFlags == SA_DISPATCH_ALL) {
  296. timeout = 0;
  297. }
  298. do {
  299. /*
  300. * Read data directly from socket
  301. */
  302. poll_fd = ckptInstance->dispatch_fd;
  303. ufds.fd = poll_fd;
  304. ufds.events = POLLIN;
  305. ufds.revents = 0;
  306. error = saPollRetry(&ufds, 1, timeout);
  307. if (error != SA_AIS_OK) {
  308. goto error_put;
  309. }
  310. pthread_mutex_lock(&ckptInstance->dispatch_mutex);
  311. if (ckptInstance->finalize == 1) {
  312. error = SA_AIS_OK;
  313. goto error_unlock;
  314. }
  315. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  316. error = SA_AIS_ERR_BAD_HANDLE;
  317. goto error_unlock;
  318. }
  319. dispatch_avail = (ufds.revents & POLLIN);
  320. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  321. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  322. break; /* exit do while cont is 1 loop */
  323. } else
  324. if (dispatch_avail == 0) {
  325. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  326. continue;
  327. }
  328. memset(&dispatch_data,0, sizeof(struct message_overlay));
  329. error = saRecvRetry (ckptInstance->dispatch_fd, &dispatch_data.header, sizeof (struct res_header), MSG_WAITALL | MSG_NOSIGNAL);
  330. if (error != SA_AIS_OK) {
  331. goto error_unlock;
  332. }
  333. if (dispatch_data.header.size > sizeof (struct res_header)) {
  334. error = saRecvRetry (ckptInstance->dispatch_fd, &dispatch_data.data,
  335. dispatch_data.header.size - sizeof (struct res_header),
  336. MSG_WAITALL | MSG_NOSIGNAL);
  337. if (error != SA_AIS_OK) {
  338. goto error_unlock;
  339. }
  340. }
  341. /*
  342. * Make copy of callbacks, message data, unlock instance,
  343. * and call callback. A risk of this dispatch method is that
  344. * the callback routines may operate at the same time that
  345. * CkptFinalize has been called in another thread.
  346. */
  347. memcpy(&callbacks,&ckptInstance->callbacks, sizeof(ckptInstance->callbacks));
  348. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  349. /*
  350. * Dispatch incoming response
  351. */
  352. switch (dispatch_data.header.id) {
  353. case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC:
  354. if (callbacks.saCkptCheckpointOpenCallback == NULL) {
  355. continue;
  356. }
  357. res_lib_ckpt_checkpointopenasync = (struct res_lib_ckpt_checkpointopenasync *) &dispatch_data;
  358. /*
  359. * This instance get/listadd/put required so that close
  360. * later has the proper list of checkpoints
  361. */
  362. if (res_lib_ckpt_checkpointopenasync->header.error == SA_AIS_OK) {
  363. error = saHandleInstanceGet (&checkpointHandleDatabase,
  364. res_lib_ckpt_checkpointopenasync->checkpointHandle,
  365. (void *)&ckptCheckpointInstance);
  366. assert (error == SA_AIS_OK); /* should only be valid handles here */
  367. /*
  368. * open succeeded without error
  369. */
  370. list_init (&ckptCheckpointInstance->list);
  371. list_init (&ckptCheckpointInstance->section_iteration_list_head);
  372. list_add (&ckptCheckpointInstance->list,
  373. &ckptInstance->checkpoint_list);
  374. callbacks.saCkptCheckpointOpenCallback(
  375. res_lib_ckpt_checkpointopenasync->invocation,
  376. res_lib_ckpt_checkpointopenasync->checkpointHandle,
  377. res_lib_ckpt_checkpointopenasync->header.error);
  378. saHandleInstancePut (&checkpointHandleDatabase,
  379. res_lib_ckpt_checkpointopenasync->checkpointHandle);
  380. } else {
  381. /*
  382. * open failed with error
  383. */
  384. callbacks.saCkptCheckpointOpenCallback(
  385. res_lib_ckpt_checkpointopenasync->invocation,
  386. -1,
  387. res_lib_ckpt_checkpointopenasync->header.error);
  388. }
  389. break;
  390. case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC:
  391. if (callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  392. continue;
  393. }
  394. res_lib_ckpt_checkpointsynchronizeasync = (struct res_lib_ckpt_checkpointsynchronizeasync *) &dispatch_data;
  395. callbacks.saCkptCheckpointSynchronizeCallback(
  396. res_lib_ckpt_checkpointsynchronizeasync->invocation,
  397. res_lib_ckpt_checkpointsynchronizeasync->header.error);
  398. break;
  399. default:
  400. /* TODO */
  401. break;
  402. }
  403. /*
  404. * Determine if more messages should be processed
  405. */
  406. switch (dispatchFlags) {
  407. case SA_DISPATCH_ONE:
  408. cont = 0;
  409. break;
  410. case SA_DISPATCH_ALL:
  411. break;
  412. case SA_DISPATCH_BLOCKING:
  413. break;
  414. }
  415. } while (cont);
  416. error_unlock:
  417. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  418. error_put:
  419. saHandleInstancePut(&ckptHandleDatabase, ckptHandle);
  420. error_exit:
  421. return (error);
  422. }
  423. SaAisErrorT
  424. saCkptFinalize (
  425. const SaCkptHandleT ckptHandle)
  426. {
  427. struct ckptInstance *ckptInstance;
  428. SaAisErrorT error;
  429. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  430. (void *)&ckptInstance);
  431. if (error != SA_AIS_OK) {
  432. return (error);
  433. }
  434. pthread_mutex_lock (&ckptInstance->response_mutex);
  435. /*
  436. * Another thread has already started finalizing
  437. */
  438. if (ckptInstance->finalize) {
  439. pthread_mutex_unlock (&ckptInstance->response_mutex);
  440. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  441. return (SA_AIS_ERR_BAD_HANDLE);
  442. }
  443. ckptInstance->finalize = 1;
  444. pthread_mutex_unlock (&ckptInstance->response_mutex);
  445. ckptInstanceFinalize (ckptInstance);
  446. if (ckptInstance->response_fd != -1) {
  447. shutdown (ckptInstance->response_fd, 0);
  448. close (ckptInstance->response_fd);
  449. }
  450. if (ckptInstance->dispatch_fd != -1) {
  451. shutdown (ckptInstance->dispatch_fd, 0);
  452. close (ckptInstance->dispatch_fd);
  453. }
  454. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  455. return (SA_AIS_OK);
  456. }
  457. SaAisErrorT
  458. saCkptCheckpointOpen (
  459. SaCkptHandleT ckptHandle,
  460. const SaNameT *checkpointName,
  461. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  462. SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
  463. SaTimeT timeout,
  464. SaCkptCheckpointHandleT *checkpointHandle)
  465. {
  466. SaAisErrorT error;
  467. struct ckptCheckpointInstance *ckptCheckpointInstance;
  468. struct ckptInstance *ckptInstance;
  469. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  470. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  471. if (checkpointHandle == NULL) {
  472. return (SA_AIS_ERR_INVALID_PARAM);
  473. }
  474. if (checkpointName == NULL) {
  475. return (SA_AIS_ERR_INVALID_PARAM);
  476. }
  477. if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) &&
  478. checkpointCreationAttributes == NULL) {
  479. return (SA_AIS_ERR_INVALID_PARAM);
  480. }
  481. if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) &&
  482. checkpointCreationAttributes != NULL) {
  483. return (SA_AIS_ERR_INVALID_PARAM);
  484. }
  485. if (checkpointCreationAttributes &&
  486. (checkpointCreationAttributes->checkpointSize >
  487. (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) {
  488. return (SA_AIS_ERR_INVALID_PARAM);
  489. }
  490. if (checkpointOpenFlags & ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) {
  491. return (SA_AIS_ERR_BAD_FLAGS);
  492. }
  493. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  494. (void *)&ckptInstance);
  495. if (error != SA_AIS_OK) {
  496. goto error_exit;
  497. }
  498. error = saHandleCreate (&checkpointHandleDatabase,
  499. sizeof (struct ckptCheckpointInstance), checkpointHandle);
  500. if (error != SA_AIS_OK) {
  501. goto error_put_ckpt;
  502. }
  503. error = saHandleInstanceGet (&checkpointHandleDatabase,
  504. *checkpointHandle, (void *)&ckptCheckpointInstance);
  505. if (error != SA_AIS_OK) {
  506. goto error_destroy;
  507. }
  508. ckptCheckpointInstance->response_fd = ckptInstance->response_fd;
  509. ckptCheckpointInstance->ckptHandle = ckptHandle;
  510. ckptCheckpointInstance->checkpointHandle = *checkpointHandle;
  511. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  512. list_init (&ckptCheckpointInstance->section_iteration_list_head);
  513. req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
  514. req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  515. memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
  516. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
  517. req_lib_ckpt_checkpointopen.checkpointCreationAttributesSet = 0;
  518. if (checkpointCreationAttributes) {
  519. memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
  520. checkpointCreationAttributes,
  521. sizeof (SaCkptCheckpointCreationAttributesT));
  522. req_lib_ckpt_checkpointopen.checkpointCreationAttributesSet = 1;
  523. }
  524. req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
  525. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointopen,
  526. sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
  527. if (error != SA_AIS_OK) {
  528. goto error_put_destroy;
  529. }
  530. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointopen,
  531. sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
  532. if (error != SA_AIS_OK) {
  533. goto error_put_destroy;
  534. }
  535. if (res_lib_ckpt_checkpointopen.header.error != SA_AIS_OK) {
  536. error = res_lib_ckpt_checkpointopen.header.error;
  537. goto error_put_destroy;
  538. }
  539. pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL);
  540. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  541. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  542. list_init (&ckptCheckpointInstance->list);
  543. list_add (&ckptCheckpointInstance->list, &ckptInstance->checkpoint_list);
  544. return (error);
  545. error_put_destroy:
  546. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  547. error_destroy:
  548. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  549. error_put_ckpt:
  550. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  551. error_exit:
  552. return (error);
  553. }
  554. SaAisErrorT
  555. saCkptCheckpointOpenAsync (
  556. const SaCkptHandleT ckptHandle,
  557. SaInvocationT invocation,
  558. const SaNameT *checkpointName,
  559. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  560. SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
  561. {
  562. struct ckptCheckpointInstance *ckptCheckpointInstance;
  563. struct ckptInstance *ckptInstance;
  564. SaCkptCheckpointHandleT checkpointHandle;
  565. SaAisErrorT error;
  566. struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
  567. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  568. SaAisErrorT failWithError = SA_AIS_OK;
  569. if (checkpointName == NULL) {
  570. failWithError = SA_AIS_ERR_INVALID_PARAM;
  571. } else
  572. if (checkpointOpenFlags &
  573. ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) {
  574. failWithError = SA_AIS_ERR_BAD_FLAGS;
  575. } else
  576. if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) &&
  577. checkpointCreationAttributes == NULL) {
  578. failWithError = SA_AIS_ERR_INVALID_PARAM;
  579. } else
  580. if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) &&
  581. checkpointCreationAttributes != NULL) {
  582. failWithError = SA_AIS_ERR_INVALID_PARAM;
  583. } else
  584. if (checkpointCreationAttributes &&
  585. (checkpointCreationAttributes->checkpointSize >
  586. (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) {
  587. failWithError = SA_AIS_ERR_INVALID_PARAM;
  588. }
  589. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  590. (void *)&ckptInstance);
  591. if (error != SA_AIS_OK) {
  592. goto error_exit;
  593. }
  594. if (ckptInstance->callbacks.saCkptCheckpointOpenCallback == NULL) {
  595. error = SA_AIS_ERR_INIT;
  596. goto error_put_ckpt;
  597. }
  598. error = saHandleCreate (&checkpointHandleDatabase,
  599. sizeof (struct ckptCheckpointInstance), &checkpointHandle);
  600. if (error != SA_AIS_OK) {
  601. goto error_put_ckpt;
  602. }
  603. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  604. (void *)&ckptCheckpointInstance);
  605. if (error != SA_AIS_OK) {
  606. goto error_destroy;
  607. }
  608. ckptCheckpointInstance->response_fd = ckptInstance->response_fd;
  609. ckptCheckpointInstance->ckptHandle = ckptHandle;
  610. ckptCheckpointInstance->checkpointHandle = checkpointHandle;
  611. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  612. if (failWithError == SA_AIS_OK) {
  613. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName,
  614. sizeof (SaNameT));
  615. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName,
  616. checkpointName, sizeof (SaNameT));
  617. }
  618. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  619. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  620. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  621. req_lib_ckpt_checkpointopenasync.fail_with_error = failWithError;
  622. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 0;
  623. if (checkpointCreationAttributes) {
  624. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  625. checkpointCreationAttributes,
  626. sizeof (SaCkptCheckpointCreationAttributesT));
  627. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 1;
  628. }
  629. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  630. req_lib_ckpt_checkpointopenasync.checkpointHandle = checkpointHandle;
  631. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointopenasync,
  632. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  633. if (error != SA_AIS_OK) {
  634. goto error_put_destroy;
  635. }
  636. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  637. &res_lib_ckpt_checkpointopenasync,
  638. sizeof (struct res_lib_ckpt_checkpointopenasync),
  639. MSG_WAITALL | MSG_NOSIGNAL);
  640. if (error != SA_AIS_OK) {
  641. goto error_put_destroy;
  642. }
  643. if (res_lib_ckpt_checkpointopenasync.header.error != SA_AIS_OK) {
  644. error = res_lib_ckpt_checkpointopenasync.header.error;
  645. goto error_put_destroy;
  646. }
  647. pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL);
  648. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  649. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  650. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointopenasync.header.error : error);
  651. error_put_destroy:
  652. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  653. error_destroy:
  654. saHandleDestroy (&checkpointHandleDatabase, checkpointHandle);
  655. error_put_ckpt:
  656. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  657. error_exit:
  658. return (error);
  659. }
  660. SaAisErrorT
  661. saCkptCheckpointClose (
  662. SaCkptCheckpointHandleT checkpointHandle)
  663. {
  664. struct req_lib_ckpt_checkpointclose req_lib_ckpt_checkpointclose;
  665. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  666. SaAisErrorT error;
  667. struct ckptCheckpointInstance *ckptCheckpointInstance;
  668. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  669. (void *)&ckptCheckpointInstance);
  670. if (error != SA_AIS_OK) {
  671. goto error_exit;
  672. }
  673. req_lib_ckpt_checkpointclose.header.size = sizeof (struct req_lib_ckpt_checkpointclose);
  674. req_lib_ckpt_checkpointclose.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  675. memcpy (&req_lib_ckpt_checkpointclose.checkpointName,
  676. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  677. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointclose,
  678. sizeof (struct req_lib_ckpt_checkpointclose), MSG_NOSIGNAL);
  679. if (error != SA_AIS_OK) {
  680. goto exit_put;
  681. }
  682. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointclose,
  683. sizeof (struct res_lib_ckpt_checkpointclose), MSG_WAITALL | MSG_NOSIGNAL);
  684. if (error == SA_AIS_OK) {
  685. error = res_lib_ckpt_checkpointclose.header.error;
  686. }
  687. if (error == SA_AIS_OK) {
  688. ckptCheckpointInstanceFinalize (ckptCheckpointInstance);
  689. }
  690. exit_put:
  691. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  692. error_exit:
  693. return (error);
  694. }
  695. SaAisErrorT
  696. saCkptCheckpointUnlink (
  697. SaCkptHandleT ckptHandle,
  698. const SaNameT *checkpointName)
  699. {
  700. SaAisErrorT error;
  701. struct ckptInstance *ckptInstance;
  702. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  703. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  704. if (checkpointName == NULL) {
  705. return (SA_AIS_ERR_INVALID_PARAM);
  706. }
  707. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  708. if (error != SA_AIS_OK) {
  709. goto exit_noclose;
  710. }
  711. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  712. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  713. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  714. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointunlink,
  715. sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  716. if (error != SA_AIS_OK) {
  717. goto exit_put;
  718. }
  719. error = saRecvRetry (ckptInstance->response_fd, &res_lib_ckpt_checkpointunlink,
  720. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  721. exit_put:
  722. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  723. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  724. exit_noclose:
  725. return (error);
  726. }
  727. SaAisErrorT
  728. saCkptCheckpointRetentionDurationSet (
  729. SaCkptCheckpointHandleT checkpointHandle,
  730. SaTimeT retentionDuration)
  731. {
  732. SaAisErrorT error;
  733. struct ckptCheckpointInstance *ckptCheckpointInstance;
  734. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  735. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  736. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  737. (void *)&ckptCheckpointInstance);
  738. if (error != SA_AIS_OK) {
  739. goto error_exit_noput;
  740. }
  741. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  742. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  743. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  744. memcpy (&req_lib_ckpt_checkpointretentiondurationset.checkpointName,
  745. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  746. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  747. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  748. if (error != SA_AIS_OK) {
  749. goto error_exit;
  750. }
  751. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  752. &res_lib_ckpt_checkpointretentiondurationset,
  753. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  754. MSG_WAITALL | MSG_NOSIGNAL);
  755. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  756. error_exit:
  757. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  758. error_exit_noput:
  759. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  760. }
  761. SaAisErrorT
  762. saCkptActiveReplicaSet (
  763. SaCkptCheckpointHandleT checkpointHandle)
  764. {
  765. SaAisErrorT error;
  766. struct ckptCheckpointInstance *ckptCheckpointInstance;
  767. struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset;
  768. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  769. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  770. (void *)&ckptCheckpointInstance);
  771. if (error != SA_AIS_OK) {
  772. goto error_noput;
  773. }
  774. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  775. error = SA_AIS_ERR_ACCESS;
  776. goto error_put;
  777. }
  778. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  779. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_ACTIVEREPLICASET;
  780. memcpy (&req_lib_ckpt_activereplicaset.checkpointName,
  781. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  782. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  783. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset,
  784. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  785. if (error != SA_AIS_OK) {
  786. goto error_put;
  787. }
  788. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  789. &res_lib_ckpt_activereplicaset,
  790. sizeof (struct res_lib_ckpt_activereplicaset),
  791. MSG_WAITALL | MSG_NOSIGNAL);
  792. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  793. error_put:
  794. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  795. error_noput:
  796. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  797. }
  798. SaAisErrorT
  799. saCkptCheckpointStatusGet (
  800. SaCkptCheckpointHandleT checkpointHandle,
  801. SaCkptCheckpointDescriptorT *checkpointStatus)
  802. {
  803. SaAisErrorT error;
  804. struct ckptCheckpointInstance *ckptCheckpointInstance;
  805. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  806. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  807. if (checkpointStatus == NULL) {
  808. return (SA_AIS_ERR_INVALID_PARAM);
  809. }
  810. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  811. (void *)&ckptCheckpointInstance);
  812. if (error != SA_AIS_OK) {
  813. return (error);
  814. }
  815. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  816. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  817. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  818. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  819. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  820. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget,
  821. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  822. if (error != SA_AIS_OK) {
  823. goto error_exit;
  824. }
  825. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  826. &res_lib_ckpt_checkpointstatusget,
  827. sizeof (struct res_lib_ckpt_checkpointstatusget),
  828. MSG_WAITALL | MSG_NOSIGNAL);
  829. if (error != SA_AIS_OK) {
  830. goto error_exit;
  831. }
  832. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  833. memcpy (checkpointStatus,
  834. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  835. sizeof (SaCkptCheckpointDescriptorT));
  836. error_exit:
  837. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  838. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointstatusget.header.error : error);
  839. }
  840. SaAisErrorT
  841. saCkptSectionCreate (
  842. SaCkptCheckpointHandleT checkpointHandle,
  843. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  844. const void *initialData,
  845. SaUint32T initialDataSize)
  846. {
  847. SaAisErrorT error;
  848. struct ckptCheckpointInstance *ckptCheckpointInstance;
  849. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  850. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  851. if (sectionCreationAttributes == NULL) {
  852. return (SA_AIS_ERR_INVALID_PARAM);
  853. }
  854. if (initialData == NULL) {
  855. return (SA_AIS_ERR_INVALID_PARAM);
  856. }
  857. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  858. (void *)&ckptCheckpointInstance);
  859. if (error != SA_AIS_OK) {
  860. return (error);
  861. }
  862. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  863. error = SA_AIS_ERR_ACCESS;
  864. goto error_exit;
  865. }
  866. req_lib_ckpt_sectioncreate.header.size =
  867. sizeof (struct req_lib_ckpt_sectioncreate) +
  868. sectionCreationAttributes->sectionId->idLen +
  869. initialDataSize;
  870. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  871. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  872. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  873. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  874. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  875. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  876. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  877. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate,
  878. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  879. if (error != SA_AIS_OK) {
  880. goto error_exit;
  881. }
  882. /*
  883. * Write section identifier to server
  884. */
  885. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id,
  886. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  887. if (error != SA_AIS_OK) {
  888. goto error_exit;
  889. }
  890. error = saSendRetry (ckptCheckpointInstance->response_fd, initialData,
  891. initialDataSize, MSG_NOSIGNAL);
  892. if (error != SA_AIS_OK) {
  893. goto error_exit;
  894. }
  895. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  896. &res_lib_ckpt_sectioncreate,
  897. sizeof (struct res_lib_ckpt_sectioncreate),
  898. MSG_WAITALL | MSG_NOSIGNAL);
  899. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  900. error_exit:
  901. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  902. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  903. }
  904. SaAisErrorT
  905. saCkptSectionDelete (
  906. SaCkptCheckpointHandleT checkpointHandle,
  907. const SaCkptSectionIdT *sectionId)
  908. {
  909. SaAisErrorT error;
  910. struct ckptCheckpointInstance *ckptCheckpointInstance;
  911. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  912. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  913. if (sectionId == NULL) {
  914. return (SA_AIS_ERR_INVALID_PARAM);
  915. }
  916. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  917. (void *)&ckptCheckpointInstance);
  918. if (error != SA_AIS_OK) {
  919. return (error);
  920. }
  921. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  922. error = SA_AIS_ERR_ACCESS;
  923. goto error_put;
  924. }
  925. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  926. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  927. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  928. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  929. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  930. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  931. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete,
  932. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  933. if (error != SA_AIS_OK) {
  934. goto error_exit;
  935. }
  936. /*
  937. * Write section identifier to server
  938. */
  939. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  940. sectionId->idLen, MSG_NOSIGNAL);
  941. if (error != SA_AIS_OK) {
  942. goto error_exit;
  943. }
  944. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  945. &res_lib_ckpt_sectiondelete,
  946. sizeof (struct res_lib_ckpt_sectiondelete),
  947. MSG_WAITALL | MSG_NOSIGNAL);
  948. error_exit:
  949. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  950. error_put:
  951. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  952. return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  953. }
  954. SaAisErrorT
  955. saCkptSectionExpirationTimeSet (
  956. SaCkptCheckpointHandleT checkpointHandle,
  957. const SaCkptSectionIdT *sectionId,
  958. SaTimeT expirationTime)
  959. {
  960. SaAisErrorT error;
  961. struct ckptCheckpointInstance *ckptCheckpointInstance;
  962. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  963. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  964. if (sectionId == NULL) {
  965. return (SA_AIS_ERR_INVALID_PARAM);
  966. }
  967. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  968. (void *)&ckptCheckpointInstance);
  969. if (error != SA_AIS_OK) {
  970. return (error);
  971. }
  972. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  973. error = SA_AIS_ERR_ACCESS;
  974. goto error_put;
  975. }
  976. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  977. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  978. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  979. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  980. memcpy (&req_lib_ckpt_sectionexpirationtimeset.checkpointName,
  981. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  982. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  983. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset,
  984. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  985. if (error != SA_AIS_OK) {
  986. goto error_exit;
  987. }
  988. /*
  989. * Write section identifier to server
  990. */
  991. if (sectionId->idLen) {
  992. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  993. sectionId->idLen, MSG_NOSIGNAL);
  994. if (error != SA_AIS_OK) {
  995. goto error_exit;
  996. }
  997. }
  998. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  999. &res_lib_ckpt_sectionexpirationtimeset,
  1000. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  1001. MSG_WAITALL | MSG_NOSIGNAL);
  1002. error_exit:
  1003. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1004. error_put:
  1005. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1006. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  1007. }
  1008. SaAisErrorT
  1009. saCkptSectionIterationInitialize (
  1010. SaCkptCheckpointHandleT checkpointHandle,
  1011. SaCkptSectionsChosenT sectionsChosen,
  1012. SaTimeT expirationTime,
  1013. SaCkptSectionIterationHandleT *sectionIterationHandle)
  1014. {
  1015. SaAisErrorT error;
  1016. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1017. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1018. struct req_lib_ckpt_sectioniterationinitialize req_lib_ckpt_sectioniterationinitialize;
  1019. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  1020. if (sectionIterationHandle == NULL) {
  1021. return (SA_AIS_ERR_INVALID_PARAM);
  1022. }
  1023. if (sectionsChosen != SA_CKPT_SECTIONS_FOREVER &&
  1024. sectionsChosen != SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME &&
  1025. sectionsChosen != SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME &&
  1026. sectionsChosen != SA_CKPT_SECTIONS_CORRUPTED &&
  1027. sectionsChosen != SA_CKPT_SECTIONS_ANY) {
  1028. return (SA_AIS_ERR_INVALID_PARAM);
  1029. }
  1030. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1031. (void *)&ckptCheckpointInstance);
  1032. if (error != SA_AIS_OK) {
  1033. goto error_no_destroy;
  1034. }
  1035. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  1036. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  1037. if (error != SA_AIS_OK) {
  1038. goto error_put_checkpoint_db;
  1039. }
  1040. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1041. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1042. if (error != SA_AIS_OK) {
  1043. goto error_destroy;
  1044. }
  1045. ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd;
  1046. ckptSectionIterationInstance->sectionIterationHandle = *sectionIterationHandle;
  1047. memcpy (&ckptSectionIterationInstance->checkpointName,
  1048. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1049. list_init (&ckptSectionIterationInstance->list);
  1050. list_add (&ckptSectionIterationInstance->list,
  1051. &ckptCheckpointInstance->section_iteration_list_head);
  1052. pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL);
  1053. /*
  1054. * Setup section id list for iterator next
  1055. */
  1056. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  1057. req_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniterationinitialize);
  1058. req_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1059. req_lib_ckpt_sectioniterationinitialize.sectionsChosen = sectionsChosen;
  1060. req_lib_ckpt_sectioniterationinitialize.expirationTime = expirationTime;
  1061. memcpy (&req_lib_ckpt_sectioniterationinitialize.checkpointName,
  1062. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1063. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1064. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1065. &req_lib_ckpt_sectioniterationinitialize,
  1066. sizeof (struct req_lib_ckpt_sectioniterationinitialize),
  1067. MSG_NOSIGNAL);
  1068. if (error != SA_AIS_OK) {
  1069. goto error_put_destroy;
  1070. }
  1071. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1072. &res_lib_ckpt_sectioniterationinitialize,
  1073. sizeof (struct res_lib_ckpt_sectioniterationinitialize),
  1074. MSG_WAITALL | MSG_NOSIGNAL);
  1075. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1076. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1077. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationinitialize.header.error : error);
  1078. error_put_destroy:
  1079. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1080. error_destroy:
  1081. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1082. error_put_checkpoint_db:
  1083. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1084. error_no_destroy:
  1085. return (error);
  1086. }
  1087. SaAisErrorT
  1088. saCkptSectionIterationNext (
  1089. SaCkptSectionIterationHandleT sectionIterationHandle,
  1090. SaCkptSectionDescriptorT *sectionDescriptor)
  1091. {
  1092. SaAisErrorT error;
  1093. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1094. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  1095. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1096. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  1097. if (sectionDescriptor == NULL) {
  1098. return (SA_AIS_ERR_INVALID_PARAM);
  1099. }
  1100. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1101. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1102. if (error != SA_AIS_OK) {
  1103. goto error_exit;
  1104. }
  1105. /*
  1106. * Allocate section id storage area
  1107. */
  1108. /*
  1109. * TODO max section id size is 500
  1110. */
  1111. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) + 500);
  1112. if (iteratorSectionIdListEntry == 0) {
  1113. error = SA_AIS_ERR_NO_MEMORY;
  1114. goto error_put_nounlock;
  1115. }
  1116. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  1117. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1118. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1119. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1120. &req_lib_ckpt_sectioniteratornext,
  1121. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  1122. if (error != SA_AIS_OK) {
  1123. goto error_put;
  1124. }
  1125. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniteratornext,
  1126. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  1127. if (error != SA_AIS_OK) {
  1128. goto error_put;
  1129. }
  1130. memcpy (sectionDescriptor,
  1131. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1132. sizeof (SaCkptSectionDescriptorT));
  1133. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  1134. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  1135. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1136. sectionDescriptor->sectionId.id,
  1137. res_lib_ckpt_sectioniteratornext.header.size -
  1138. sizeof (struct res_lib_ckpt_sectioniteratornext),
  1139. MSG_WAITALL | MSG_NOSIGNAL);
  1140. }
  1141. /*
  1142. * Add to persistent memory list for this sectioniterator
  1143. */
  1144. if (error == SA_AIS_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_AIS_OK) {
  1145. list_init (&iteratorSectionIdListEntry->list);
  1146. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  1147. }
  1148. error_put:
  1149. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1150. error_put_nounlock:
  1151. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1152. error_exit:
  1153. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  1154. }
  1155. SaAisErrorT
  1156. saCkptSectionIterationFinalize (
  1157. SaCkptSectionIterationHandleT sectionIterationHandle)
  1158. {
  1159. SaAisErrorT error;
  1160. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1161. struct req_lib_ckpt_sectioniterationfinalize req_lib_ckpt_sectioniterationfinalize;
  1162. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  1163. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1164. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1165. if (error != SA_AIS_OK) {
  1166. goto error_exit;
  1167. }
  1168. req_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct req_lib_ckpt_sectioniterationfinalize);
  1169. req_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  1170. memcpy (&req_lib_ckpt_sectioniterationfinalize.checkpointName,
  1171. &ckptSectionIterationInstance->checkpointName, sizeof (SaNameT));
  1172. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1173. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1174. &req_lib_ckpt_sectioniterationfinalize,
  1175. sizeof (struct req_lib_ckpt_sectioniterationfinalize), MSG_NOSIGNAL);
  1176. if (error != SA_AIS_OK) {
  1177. goto error_put;
  1178. }
  1179. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniterationfinalize,
  1180. sizeof (struct res_lib_ckpt_sectioniterationfinalize), MSG_WAITALL | MSG_NOSIGNAL);
  1181. if (error != SA_AIS_OK) {
  1182. goto error_put;
  1183. }
  1184. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1185. ckptSectionIterationInstanceFinalize (ckptSectionIterationInstance);
  1186. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1187. return (error);
  1188. error_put:
  1189. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1190. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1191. error_exit:
  1192. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationfinalize.header.error : error);
  1193. }
  1194. SaAisErrorT
  1195. saCkptCheckpointWrite (
  1196. SaCkptCheckpointHandleT checkpointHandle,
  1197. const SaCkptIOVectorElementT *ioVector,
  1198. SaUint32T numberOfElements,
  1199. SaUint32T *erroneousVectorIndex)
  1200. {
  1201. SaAisErrorT error = SA_AIS_OK;
  1202. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1203. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  1204. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1205. int i;
  1206. struct iovec iov[3];
  1207. int iov_len = 0;
  1208. if (ioVector == NULL) {
  1209. return (SA_AIS_ERR_INVALID_PARAM);
  1210. }
  1211. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1212. (void *)&ckptCheckpointInstance);
  1213. if (error != SA_AIS_OK) {
  1214. return (error);
  1215. }
  1216. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1217. error = SA_AIS_ERR_ACCESS;
  1218. goto error_put;
  1219. }
  1220. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  1221. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1222. for (i = 0; i < numberOfElements; i++) {
  1223. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  1224. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  1225. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  1226. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  1227. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  1228. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1229. iov_len = 0;
  1230. /* TODO check for zero length stuff */
  1231. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  1232. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  1233. iov[1].iov_base = ioVector[i].sectionId.id;
  1234. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1235. iov[2].iov_base = ioVector[i].dataBuffer;
  1236. iov[2].iov_len = ioVector[i].dataSize;
  1237. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1238. iov,
  1239. 3);
  1240. if (error != SA_AIS_OK) {
  1241. goto error_exit;
  1242. }
  1243. /*
  1244. * Receive response
  1245. */
  1246. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite,
  1247. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1248. if (error != SA_AIS_OK) {
  1249. goto error_exit;
  1250. }
  1251. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1252. error = SA_AIS_ERR_TRY_AGAIN;
  1253. goto error_exit;
  1254. }
  1255. /*
  1256. * If error, report back erroneous index
  1257. */
  1258. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1259. if (erroneousVectorIndex) {
  1260. *erroneousVectorIndex = i;
  1261. }
  1262. goto error_exit;
  1263. }
  1264. }
  1265. error_exit:
  1266. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1267. error_put:
  1268. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1269. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1270. }
  1271. SaAisErrorT
  1272. saCkptSectionOverwrite (
  1273. SaCkptCheckpointHandleT checkpointHandle,
  1274. const SaCkptSectionIdT *sectionId,
  1275. const void *dataBuffer,
  1276. SaSizeT dataSize)
  1277. {
  1278. SaAisErrorT error;
  1279. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1280. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1281. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1282. if (dataBuffer == NULL) {
  1283. return (SA_ERR_INVALID_PARAM);
  1284. }
  1285. if (sectionId == NULL) {
  1286. return (SA_ERR_INVALID_PARAM);
  1287. }
  1288. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1289. (void *)&ckptCheckpointInstance);
  1290. if (error != SA_AIS_OK) {
  1291. return (error);
  1292. }
  1293. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1294. return (SA_AIS_ERR_ACCESS);
  1295. }
  1296. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1297. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1298. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1299. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1300. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1301. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1302. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1303. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite,
  1304. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1305. if (error != SA_AIS_OK) {
  1306. goto error_exit;
  1307. }
  1308. if (sectionId->idLen) {
  1309. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  1310. sectionId->idLen, MSG_NOSIGNAL);
  1311. if (error != SA_AIS_OK) {
  1312. goto error_exit;
  1313. }
  1314. }
  1315. error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1316. if (error != SA_AIS_OK) {
  1317. goto error_exit;
  1318. }
  1319. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1320. &res_lib_ckpt_sectionoverwrite,
  1321. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1322. MSG_WAITALL | MSG_NOSIGNAL);
  1323. error_exit:
  1324. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1325. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1326. return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1327. }
  1328. SaAisErrorT
  1329. saCkptCheckpointRead (
  1330. SaCkptCheckpointHandleT checkpointHandle,
  1331. SaCkptIOVectorElementT *ioVector,
  1332. SaUint32T numberOfElements,
  1333. SaUint32T *erroneousVectorIndex)
  1334. {
  1335. SaAisErrorT error = SA_AIS_OK;
  1336. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1337. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1338. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1339. int dataLength;
  1340. int i;
  1341. struct iovec iov[3];
  1342. if (ioVector == NULL) {
  1343. return (SA_AIS_ERR_INVALID_PARAM);
  1344. }
  1345. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1346. (void *)&ckptCheckpointInstance);
  1347. if (error != SA_AIS_OK) {
  1348. return (error);
  1349. }
  1350. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1351. return (SA_AIS_ERR_ACCESS);
  1352. }
  1353. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1354. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1355. for (i = 0; i < numberOfElements; i++) {
  1356. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1357. ioVector[i].sectionId.idLen;
  1358. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1359. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1360. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1361. memcpy (&req_lib_ckpt_sectionread.checkpointName,
  1362. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1363. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1364. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1365. iov[1].iov_base = ioVector[i].sectionId.id;
  1366. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1367. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1368. iov,
  1369. 2);
  1370. /*
  1371. * Receive response header
  1372. */
  1373. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionread,
  1374. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1375. if (error != SA_AIS_OK) {
  1376. goto error_exit;
  1377. }
  1378. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1379. /*
  1380. * Receive checkpoint section data
  1381. */
  1382. if (ioVector[i].dataBuffer == 0) {
  1383. ioVector[i].dataBuffer =
  1384. malloc (dataLength);
  1385. if (ioVector[i].dataBuffer == NULL) {
  1386. error = SA_AIS_ERR_NO_MEMORY;
  1387. goto error_exit;
  1388. }
  1389. }
  1390. if (dataLength > 0) {
  1391. error = saRecvRetry (ckptCheckpointInstance->response_fd, ioVector[i].dataBuffer,
  1392. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1393. if (error != SA_AIS_OK) {
  1394. goto error_exit;
  1395. }
  1396. }
  1397. if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) {
  1398. goto error_exit;
  1399. }
  1400. /*
  1401. * Report back bytes of data read
  1402. */
  1403. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1404. }
  1405. error_exit:
  1406. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1407. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1408. if (error != SA_AIS_OK && erroneousVectorIndex) {
  1409. *erroneousVectorIndex = i;
  1410. }
  1411. return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error);
  1412. }
  1413. SaAisErrorT
  1414. saCkptCheckpointSynchronize (
  1415. SaCkptCheckpointHandleT checkpointHandle,
  1416. SaTimeT timeout)
  1417. {
  1418. SaAisErrorT error;
  1419. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1420. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1421. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1422. if (timeout == 0) {
  1423. return (SA_AIS_ERR_TIMEOUT);
  1424. }
  1425. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1426. (void *)&ckptCheckpointInstance);
  1427. if (error != SA_AIS_OK) {
  1428. return (error);
  1429. }
  1430. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1431. error = SA_AIS_ERR_ACCESS;
  1432. goto error_put;
  1433. }
  1434. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1435. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1436. memcpy (&req_lib_ckpt_checkpointsynchronize.checkpointName,
  1437. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1438. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1439. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronize,
  1440. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1441. if (error != SA_AIS_OK) {
  1442. goto error_exit;
  1443. }
  1444. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1445. &res_lib_ckpt_checkpointsynchronize,
  1446. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1447. MSG_WAITALL | MSG_NOSIGNAL);
  1448. error_exit:
  1449. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1450. error_put:
  1451. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1452. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1453. }
  1454. SaAisErrorT
  1455. saCkptCheckpointSynchronizeAsync (
  1456. SaCkptCheckpointHandleT checkpointHandle,
  1457. SaInvocationT invocation)
  1458. {
  1459. SaAisErrorT error;
  1460. struct ckptInstance *ckptInstance;
  1461. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1462. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1463. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  1464. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1465. (void *)&ckptCheckpointInstance);
  1466. if (error != SA_AIS_OK) {
  1467. return (error);
  1468. }
  1469. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1470. error = SA_AIS_ERR_ACCESS;
  1471. goto error_put;
  1472. }
  1473. error = saHandleInstanceGet (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle,
  1474. (void *)&ckptInstance);
  1475. if (error != SA_AIS_OK) {
  1476. goto error_put;
  1477. }
  1478. if (ckptInstance->callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  1479. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1480. error = SA_AIS_ERR_INIT;
  1481. goto error_put;
  1482. }
  1483. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1484. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1485. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1486. memcpy (&req_lib_ckpt_checkpointsynchronizeasync.checkpointName,
  1487. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1488. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1489. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1490. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1491. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1492. if (error != SA_AIS_OK) {
  1493. goto error_exit;
  1494. }
  1495. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1496. &res_lib_ckpt_checkpointsynchronizeasync,
  1497. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync),
  1498. MSG_WAITALL | MSG_NOSIGNAL);
  1499. error_exit:
  1500. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1501. error_put:
  1502. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1503. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronizeasync.header.error : error);
  1504. return (SA_AIS_OK);
  1505. }