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