ckpt.c 58 KB

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