ckpt.c 57 KB

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