ckpt.c 54 KB

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