ckpt.c 57 KB

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