4
0

ckpt.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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 <unistd.h>
  38. #include <errno.h>
  39. #include <pthread.h>
  40. #include <sys/types.h>
  41. #include <sys/uio.h>
  42. #include <sys/socket.h>
  43. #include <sys/select.h>
  44. #include <sys/un.h>
  45. #include "../include/list.h"
  46. #include "../include/ais_types.h"
  47. #include "../include/ais_ckpt.h"
  48. #include "../include/ais_msg.h"
  49. #include "util.h"
  50. struct message_overlay {
  51. struct req_header header;
  52. char data[4096];
  53. };
  54. /*
  55. * Data structure for instance data
  56. */
  57. struct ckptInstance {
  58. int fd;
  59. struct queue inq;
  60. SaCkptCallbacksT callbacks;
  61. int finalize;
  62. pthread_mutex_t mutex;
  63. };
  64. struct ckptCheckpointInstance {
  65. int fd;
  66. SaNameT checkpointName;
  67. SaUint32T maxSectionIdSize;
  68. pthread_mutex_t mutex;
  69. };
  70. struct ckptSectionIteratorInstance {
  71. int fd;
  72. struct list_head sectionIdListHead;
  73. SaUint32T maxSectionIdSize;
  74. pthread_mutex_t mutex;
  75. };
  76. void ckptHandleInstanceDestructor (void *instance);
  77. void checkpointHandleInstanceDestructor (void *instance);
  78. void ckptSectionIteratorHandleInstanceDestructor (void *instance);
  79. /*
  80. * All CKPT instances in this database
  81. */
  82. static struct saHandleDatabase ckptHandleDatabase = {
  83. .handleCount = 0,
  84. .handles = 0,
  85. .mutex = PTHREAD_MUTEX_INITIALIZER,
  86. .handleInstanceDestructor = ckptHandleInstanceDestructor
  87. };
  88. /*
  89. * All Checkpoint instances in this database
  90. */
  91. static struct saHandleDatabase checkpointHandleDatabase = {
  92. .handleCount = 0,
  93. .handles = 0,
  94. .mutex = PTHREAD_MUTEX_INITIALIZER,
  95. .handleInstanceDestructor = checkpointHandleInstanceDestructor
  96. };
  97. /*
  98. * All section iterators in this database
  99. */
  100. static struct saHandleDatabase ckptSectionIteratorHandleDatabase = {
  101. .handleCount = 0,
  102. .handles = 0,
  103. .mutex = PTHREAD_MUTEX_INITIALIZER,
  104. .handleInstanceDestructor = ckptSectionIteratorHandleInstanceDestructor
  105. };
  106. /*
  107. * Versions supported
  108. */
  109. static SaVersionT ckptVersionsSupported[] = {
  110. { 'A', 1, 1 },
  111. { 'a', 1, 1 }
  112. };
  113. static struct saVersionDatabase ckptVersionDatabase = {
  114. sizeof (ckptVersionsSupported) / sizeof (SaVersionT),
  115. ckptVersionsSupported
  116. };
  117. /*
  118. * Implementation
  119. */
  120. void ckptHandleInstanceDestructor (void *instance)
  121. {
  122. struct ckptInstance *ckptInstance = (struct ckptInstance *)instance;
  123. if (ckptInstance->fd != -1) {
  124. shutdown (ckptInstance->fd, 0);
  125. close (ckptInstance->fd);
  126. }
  127. if (ckptInstance->inq.items) {
  128. free (ckptInstance->inq.items);
  129. }
  130. }
  131. void checkpointHandleInstanceDestructor (void *instance)
  132. {
  133. struct ckptCheckpointInstance *ckptCheckpointInstance = (struct ckptCheckpointInstance *)instance;
  134. if (ckptCheckpointInstance->fd != -1) {
  135. shutdown (ckptCheckpointInstance->fd, 0);
  136. close (ckptCheckpointInstance->fd);
  137. }
  138. }
  139. void ckptSectionIteratorHandleInstanceDestructor (void *instance)
  140. {
  141. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance = (struct ckptSectionIteratorInstance *)instance;
  142. if (ckptSectionIteratorInstance->fd != -1) {
  143. shutdown (ckptSectionIteratorInstance->fd, 0);
  144. close (ckptSectionIteratorInstance->fd);
  145. }
  146. }
  147. SaErrorT
  148. saCkptInitialize (
  149. SaCkptHandleT *ckptHandle,
  150. const SaCkptCallbacksT *callbacks,
  151. const SaVersionT *version)
  152. {
  153. struct ckptInstance *ckptInstance;
  154. SaErrorT error = SA_OK;
  155. error = saVersionVerify (&ckptVersionDatabase, version);
  156. if (error != SA_OK) {
  157. goto error_no_destroy;
  158. }
  159. error = saHandleCreate (&ckptHandleDatabase, sizeof (struct ckptInstance),
  160. ckptHandle);
  161. if (error != SA_OK) {
  162. goto error_no_destroy;
  163. }
  164. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
  165. (void *)&ckptInstance);
  166. if (error != SA_OK) {
  167. goto error_destroy;
  168. }
  169. ckptInstance->fd = -1;
  170. /*
  171. * An inq is needed to store async messages while waiting for a
  172. * sync response
  173. */
  174. error = saQueueInit (&ckptInstance->inq, 512, sizeof (void *));
  175. if (error != SA_OK) {
  176. goto error_put_destroy;
  177. }
  178. error = saServiceConnect (&ckptInstance->fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  179. if (error != SA_OK) {
  180. goto error_put_destroy;
  181. }
  182. memcpy (&ckptInstance->callbacks, callbacks, sizeof (SaCkptCallbacksT));
  183. pthread_mutex_init (&ckptInstance->mutex, NULL);
  184. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  185. return (SA_OK);
  186. error_put_destroy:
  187. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  188. error_destroy:
  189. saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
  190. error_no_destroy:
  191. return (error);
  192. }
  193. SaErrorT
  194. saCkptSelectionObjectGet (
  195. const SaCkptHandleT *ckptHandle,
  196. SaSelectionObjectT *selectionObject)
  197. {
  198. struct ckptInstance *ckptInstance;
  199. SaErrorT error;
  200. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
  201. if (error != SA_OK) {
  202. return (error);
  203. }
  204. *selectionObject = ckptInstance->fd;
  205. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  206. return (SA_OK);
  207. }
  208. #ifdef COMPILE_OUT
  209. SaErrorT
  210. saCkptDispatch (
  211. const SaCkptHandleT *ckptHandle,
  212. SaDispatchFlagsT dispatchFlags)
  213. {
  214. fd_set read_fds;
  215. SaErrorT error;
  216. int dispatch_avail;
  217. struct timeval *timeout = 0;
  218. struct ckptInstance *ckptInstance;
  219. struct req_header **queue_msg;
  220. struct req_header *msg;
  221. int empty;
  222. int ignore_dispatch = 0;
  223. int cont = 1; /* always continue do loop except when set to 0 */
  224. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
  225. if (error != SA_OK) {
  226. return (error);
  227. }
  228. /*
  229. * Timeout instantly for SA_DISPATCH_ALL
  230. */
  231. if (dispatchFlags & SA_DISPATCH_ALL) {
  232. timeout = &zerousec;
  233. }
  234. do {
  235. /*
  236. * Read data directly from socket
  237. */
  238. FD_ZERO (&read_fds);
  239. FD_SET (ckptInstance->fd, &read_fds);
  240. error = saSelectRetry (ckptInstance->fd + 1, &read_fds, 0, 0, timeout);
  241. if (error != SA_OK) {
  242. goto error_exit;
  243. }
  244. dispatch_avail = FD_ISSET (ckptInstance->fd, &read_fds);
  245. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  246. break; /* exit do while cont is 1 loop */
  247. } else
  248. if (dispatch_avail == 0) {
  249. continue; /* next select */
  250. }
  251. saQueueIsEmpty(&ckptInstance->inq, &empty);
  252. if (empty == 0) {
  253. /*
  254. * Queue is not empty, read data from queue
  255. */
  256. saQueueItemGet (&ckptInstance->inq, (void **)&queue_msg);
  257. msg = *queue_msg;
  258. memcpy (&ckptInstance->message, msg, msg->size);
  259. saQueueItemRemove (&ckptInstance->inq);
  260. free (msg);
  261. } else {
  262. /*
  263. * Queue empty, read response from socket
  264. */
  265. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.header, sizeof (struct req_header), MSG_WAITALL | MSG_NOSIGNAL);
  266. if (error != SA_OK) {
  267. goto error_exit;
  268. }
  269. if (ckptInstance->message.header.size > sizeof (struct req_header)) {
  270. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.data,
  271. ckptInstance->message.header.size - sizeof (struct req_header),
  272. MSG_WAITALL | MSG_NOSIGNAL);
  273. if (error != SA_OK) {
  274. goto error_exit;
  275. }
  276. }
  277. }
  278. /*
  279. * Dispatch incoming response
  280. */
  281. switch (ckptInstance->message.header.id) {
  282. #ifdef COMPILE_OUT
  283. case MESSAGE_RES_CKPT_CHECKPOINT_ACTIVATEPOLL:
  284. /*
  285. * This is a do nothing message which the node executive sends
  286. * to activate the file handle in poll when the library has
  287. * queued a message into amfHandle->inq
  288. * The dispatch is ignored for the following two cases:
  289. * 1) setting of timeout to zero for the DISPATCH_ALL case
  290. * 2) expiration of the do loop for the DISPATCH_ONE case
  291. */
  292. ignore_dispatch = 1;
  293. break;
  294. case MESSAGE_RES_CKPT_CHECKPOINT_HEALTHCHECKCALLBACK:
  295. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&ckptInstance->message;
  296. amfInstance->callbacks.saAmfHealthcheckCallback (
  297. res_amf_healthcheckcallback->invocation,
  298. &res_amf_healthcheckcallback->compName,
  299. res_amf_healthcheckcallback->checkType);
  300. break;
  301. case MESSAGE_RES_CKPT_CHECKPOINT_READINESSSTATESETCALLBACK:
  302. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&ckptInstance->message;
  303. amfInstance->callbacks.saAmfReadinessStateSetCallback (
  304. res_amf_readinessstatesetcallback->invocation,
  305. &res_amf_readinessstatesetcallback->compName,
  306. res_amf_readinessstatesetcallback->readinessState);
  307. break;
  308. case MESSAGE_RES_CKPT_CHECKPOINT_CSISETCALLBACK:
  309. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&ckptInstance->message;
  310. amfInstance->callbacks.saAmfCSISetCallback (
  311. res_amf_csisetcallback->invocation,
  312. &res_amf_csisetcallback->compName,
  313. &res_amf_csisetcallback->csiName,
  314. res_amf_csisetcallback->csiFlags,
  315. &res_amf_csisetcallback->haState,
  316. &res_amf_csisetcallback->activeCompName,
  317. res_amf_csisetcallback->transitionDescriptor);
  318. break;
  319. case MESSAGE_RES_CKPT_CHECKPOINT_CSIREMOVECALLBACK:
  320. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&ckptInstance->message;
  321. amfInstance->callbacks.saAmfCSIRemoveCallback (
  322. res_amf_csiremovecallback->invocation,
  323. &res_amf_csiremovecallback->compName,
  324. &res_amf_csiremovecallback->csiName,
  325. &res_amf_csiremovecallback->csiFlags);
  326. break;
  327. case MESSAGE_RES_CKPT_CHECKPOINT_PROTECTIONGROUPTRACKCALLBACK:
  328. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&ckptInstance->message;
  329. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  330. res_amf_protectiongrouptrackcallback->notificationBuffer,
  331. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  332. amfInstance->callbacks.saAmfProtectionGroupTrackCallback(
  333. &res_amf_protectiongrouptrackcallback->csiName,
  334. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  335. res_amf_protectiongrouptrackcallback->numberOfItems,
  336. res_amf_protectiongrouptrackcallback->numberOfMembers,
  337. res_amf_protectiongrouptrackcallback->error);
  338. break;
  339. #endif
  340. default:
  341. /* TODO */
  342. break;
  343. }
  344. /*
  345. * Determine if more messages should be processed
  346. */
  347. switch (dispatchFlags) {
  348. case SA_DISPATCH_ONE:
  349. if (ignore_dispatch) {
  350. ignore_dispatch = 0;
  351. } else {
  352. cont = 0;
  353. }
  354. break;
  355. case SA_DISPATCH_ALL:
  356. if (ignore_dispatch) {
  357. ignore_dispatch = 0;
  358. }
  359. break;
  360. case SA_DISPATCH_BLOCKING:
  361. break;
  362. }
  363. } while (cont);
  364. error_exit:
  365. return (error);
  366. }
  367. #endif
  368. SaErrorT
  369. saCkptFinalize (
  370. const SaCkptHandleT *ckptHandle)
  371. {
  372. struct ckptInstance *ckptInstance;
  373. SaErrorT error;
  374. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
  375. (void *)&ckptInstance);
  376. if (error != SA_OK) {
  377. return (error);
  378. }
  379. pthread_mutex_lock (&ckptInstance->mutex);
  380. /*
  381. * Another thread has already started finalizing
  382. */
  383. if (ckptInstance->finalize) {
  384. pthread_mutex_unlock (&ckptInstance->mutex);
  385. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  386. return (SA_ERR_BAD_HANDLE);
  387. }
  388. ckptInstance->finalize = 1;
  389. saActivatePoll (ckptInstance->fd);
  390. pthread_mutex_unlock (&ckptInstance->mutex);
  391. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  392. saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
  393. return (SA_OK);
  394. }
  395. SaErrorT
  396. saCkptCheckpointOpen (
  397. const SaNameT *checkpointName,
  398. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  399. SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
  400. SaTimeT timeout,
  401. SaCkptCheckpointHandleT *checkpointHandle)
  402. {
  403. SaErrorT error;
  404. struct ckptCheckpointInstance *ckptCheckpointInstance;
  405. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  406. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  407. error = saHandleCreate (&checkpointHandleDatabase,
  408. sizeof (struct ckptCheckpointInstance), checkpointHandle);
  409. if (error != SA_OK) {
  410. goto error_no_destroy;
  411. }
  412. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  413. (void *)&ckptCheckpointInstance);
  414. if (error != SA_OK) {
  415. goto error_destroy;
  416. }
  417. ckptCheckpointInstance->fd = -1;
  418. ckptCheckpointInstance->maxSectionIdSize =
  419. checkpointCreationAttributes->maxSectionIdSize;
  420. error = saServiceConnect (&ckptCheckpointInstance->fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  421. if (error != SA_OK) {
  422. goto error_put_destroy;
  423. }
  424. req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
  425. req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  426. memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
  427. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
  428. memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
  429. checkpointCreationAttributes,
  430. sizeof (SaCkptCheckpointCreationAttributesT));
  431. req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
  432. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointopen,
  433. sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
  434. if (error != SA_OK) {
  435. goto error_put_destroy;
  436. }
  437. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointopen,
  438. sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
  439. if (error != SA_OK) {
  440. goto error_put_destroy;
  441. }
  442. if (res_lib_ckpt_checkpointopen.header.error != SA_OK) {
  443. error = res_lib_ckpt_checkpointopen.header.error;
  444. goto error_put_destroy;
  445. }
  446. pthread_mutex_init (&ckptCheckpointInstance->mutex, NULL);
  447. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  448. return (error);
  449. error_put_destroy:
  450. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  451. error_destroy:
  452. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  453. error_no_destroy:
  454. return (error);
  455. }
  456. SaErrorT
  457. saCkptCheckpointOpenAsync (
  458. const SaCkptHandleT *ckptHandle,
  459. SaInvocationT invocation,
  460. const SaNameT *checkpointName,
  461. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  462. SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
  463. {
  464. struct ckptInstance *ckptInstance;
  465. SaErrorT error;
  466. struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
  467. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
  468. if (error != SA_OK) {
  469. return (error);
  470. }
  471. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  472. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  473. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  474. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName, checkpointName, sizeof (SaNameT));
  475. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  476. checkpointCreationAttributes,
  477. sizeof (SaCkptCheckpointCreationAttributesT));
  478. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  479. pthread_mutex_lock (&ckptInstance->mutex);
  480. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointopenasync,
  481. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  482. pthread_mutex_unlock (&ckptInstance->mutex);
  483. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  484. return (error);
  485. }
  486. SaErrorT
  487. saCkptCheckpointClose (
  488. const SaCkptCheckpointHandleT *checkpointHandle)
  489. {
  490. SaErrorT error;
  491. struct ckptCheckpointInstance *ckptCheckpointInstance;
  492. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  493. (void *)&ckptCheckpointInstance);
  494. if (error != SA_OK) {
  495. goto error_exit;
  496. }
  497. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  498. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  499. error_exit:
  500. return (error);
  501. }
  502. SaErrorT
  503. saCkptCheckpointUnlink (
  504. const SaNameT *checkpointName)
  505. {
  506. SaErrorT error;
  507. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  508. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  509. int fd;
  510. error = saServiceConnect (&fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  511. if (error != SA_OK) {
  512. goto exit_noclose;
  513. }
  514. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  515. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  516. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  517. error = saSendRetry (fd, &req_lib_ckpt_checkpointunlink, sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  518. if (error != SA_OK) {
  519. goto exit_close;
  520. }
  521. error = saRecvRetry (fd, &res_lib_ckpt_checkpointunlink,
  522. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  523. exit_close:
  524. close (fd);
  525. return (error == SA_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  526. exit_noclose:
  527. return (error);
  528. }
  529. SaErrorT
  530. saCkptCheckpointRetentionDurationSet (
  531. const SaCkptCheckpointHandleT *checkpointHandle,
  532. SaTimeT retentionDuration)
  533. {
  534. SaErrorT error;
  535. struct ckptCheckpointInstance *ckptCheckpointInstance;
  536. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  537. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  538. (void *)&ckptCheckpointInstance);
  539. if (error != SA_OK) {
  540. goto error_exit;
  541. }
  542. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  543. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  544. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  545. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  546. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  547. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  548. error_exit:
  549. return (error);
  550. }
  551. SaErrorT
  552. saCkptActiveCheckpointSet (
  553. const SaCkptCheckpointHandleT *checkpointHandle)
  554. {
  555. SaErrorT error;
  556. struct ckptCheckpointInstance *ckptCheckpointInstance;
  557. struct req_lib_ckpt_activecheckpointset req_lib_ckpt_activecheckpointset;
  558. struct res_lib_ckpt_activecheckpointset res_lib_ckpt_activecheckpointset;
  559. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  560. (void *)&ckptCheckpointInstance);
  561. if (error != SA_OK) {
  562. goto error_exit;
  563. }
  564. req_lib_ckpt_activecheckpointset.header.size = sizeof (struct req_lib_ckpt_activecheckpointset);
  565. req_lib_ckpt_activecheckpointset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET;
  566. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  567. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activecheckpointset,
  568. sizeof (struct req_lib_ckpt_activecheckpointset), MSG_NOSIGNAL);
  569. if (error != SA_OK) {
  570. goto error_exit;
  571. }
  572. error = saRecvRetry (ckptCheckpointInstance->fd,
  573. &res_lib_ckpt_activecheckpointset,
  574. sizeof (struct res_lib_ckpt_activecheckpointset),
  575. MSG_WAITALL | MSG_NOSIGNAL);
  576. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  577. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  578. error_exit:
  579. return (error == SA_OK ? res_lib_ckpt_activecheckpointset.header.error : error);
  580. }
  581. SaErrorT
  582. saCkptCheckpointStatusGet (
  583. const SaCkptCheckpointHandleT *checkpointHandle,
  584. SaCkptCheckpointStatusT *checkpointStatus)
  585. {
  586. SaErrorT error;
  587. struct ckptCheckpointInstance *ckptCheckpointInstance;
  588. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  589. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  590. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  591. (void *)&ckptCheckpointInstance);
  592. if (error != SA_OK) {
  593. return (error);
  594. }
  595. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  596. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  597. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  598. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
  599. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  600. if (error != SA_OK) {
  601. goto error_exit;
  602. }
  603. error = saRecvRetry (ckptCheckpointInstance->fd,
  604. &res_lib_ckpt_checkpointstatusget,
  605. sizeof (struct res_lib_ckpt_checkpointstatusget),
  606. MSG_WAITALL | MSG_NOSIGNAL);
  607. if (error != SA_OK) {
  608. goto error_exit;
  609. }
  610. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  611. memcpy (checkpointStatus,
  612. &res_lib_ckpt_checkpointstatusget.checkpointStatus,
  613. sizeof (SaCkptCheckpointStatusT));
  614. error_exit:
  615. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  616. return (error);
  617. }
  618. SaErrorT
  619. saCkptSectionCreate (
  620. const SaCkptCheckpointHandleT *checkpointHandle,
  621. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  622. const void *initialData,
  623. SaUint32T initialDataSize)
  624. {
  625. SaErrorT error;
  626. struct ckptCheckpointInstance *ckptCheckpointInstance;
  627. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  628. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  629. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  630. (void *)&ckptCheckpointInstance);
  631. if (error != SA_OK) {
  632. return (error);
  633. }
  634. req_lib_ckpt_sectioncreate.header.size =
  635. sizeof (struct req_lib_ckpt_sectioncreate) +
  636. sectionCreationAttributes->sectionId->idLen +
  637. initialDataSize;
  638. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  639. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  640. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  641. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  642. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  643. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
  644. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  645. if (error != SA_OK) {
  646. goto error_exit;
  647. }
  648. /*
  649. * Write section identifier to server
  650. */
  651. error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
  652. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  653. if (error != SA_OK) {
  654. goto error_exit;
  655. }
  656. error = saSendRetry (ckptCheckpointInstance->fd, initialData,
  657. initialDataSize, MSG_NOSIGNAL);
  658. if (error != SA_OK) {
  659. goto error_exit;
  660. }
  661. error = saRecvRetry (ckptCheckpointInstance->fd,
  662. &res_lib_ckpt_sectioncreate,
  663. sizeof (struct res_lib_ckpt_sectioncreate),
  664. MSG_WAITALL | MSG_NOSIGNAL);
  665. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  666. error_exit:
  667. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  668. return (error == SA_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  669. }
  670. SaErrorT
  671. saCkptSectionDelete (
  672. const SaCkptCheckpointHandleT *checkpointHandle,
  673. const SaCkptSectionIdT *sectionId)
  674. {
  675. SaErrorT error;
  676. struct ckptCheckpointInstance *ckptCheckpointInstance;
  677. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  678. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  679. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  680. (void *)&ckptCheckpointInstance);
  681. if (error != SA_OK) {
  682. return (error);
  683. }
  684. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  685. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  686. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  687. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  688. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
  689. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  690. if (error != SA_OK) {
  691. goto error_exit;
  692. }
  693. /*
  694. * Write section identifier to server
  695. */
  696. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  697. sectionId->idLen, MSG_NOSIGNAL);
  698. if (error != SA_OK) {
  699. goto error_exit;
  700. }
  701. error = saRecvRetry (ckptCheckpointInstance->fd,
  702. &res_lib_ckpt_sectiondelete,
  703. sizeof (struct res_lib_ckpt_sectiondelete),
  704. MSG_WAITALL | MSG_NOSIGNAL);
  705. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  706. error_exit:
  707. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  708. return (error == SA_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  709. }
  710. SaErrorT
  711. saCkptSectionExpirationTimeSet (
  712. const SaCkptCheckpointHandleT *checkpointHandle,
  713. const SaCkptSectionIdT *sectionId,
  714. SaTimeT expirationTime)
  715. {
  716. SaErrorT error;
  717. struct ckptCheckpointInstance *ckptCheckpointInstance;
  718. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  719. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  720. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  721. (void *)&ckptCheckpointInstance);
  722. if (error != SA_OK) {
  723. goto error_exit;
  724. }
  725. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  726. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  727. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  728. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  729. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  730. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
  731. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  732. if (error != SA_OK) {
  733. goto error_exit;
  734. }
  735. /*
  736. * Write section identifier to server
  737. */
  738. if (sectionId->idLen) {
  739. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  740. sectionId->idLen, MSG_NOSIGNAL);
  741. if (error != SA_OK) {
  742. goto error_exit;
  743. }
  744. }
  745. error = saRecvRetry (ckptCheckpointInstance->fd,
  746. &res_lib_ckpt_sectionexpirationtimeset,
  747. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  748. MSG_WAITALL | MSG_NOSIGNAL);
  749. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  750. error_exit:
  751. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  752. return (error == SA_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  753. }
  754. SaErrorT
  755. saCkptSectionIteratorInitialize (
  756. const SaCkptCheckpointHandleT *checkpointHandle,
  757. SaCkptSectionsChosenT sectionsChosen,
  758. SaTimeT expirationTime,
  759. SaCkptSectionIteratorT *sectionIterator)
  760. {
  761. SaErrorT error;
  762. struct ckptCheckpointInstance *ckptCheckpointInstance;
  763. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  764. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  765. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  766. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  767. (void *)&ckptCheckpointInstance);
  768. if (error != SA_OK) {
  769. goto error_no_destroy;
  770. }
  771. error = saHandleCreate (&ckptSectionIteratorHandleDatabase,
  772. sizeof (struct ckptSectionIteratorInstance), sectionIterator);
  773. if (error != SA_OK) {
  774. goto error_put_checkpoint_db;
  775. }
  776. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  777. *sectionIterator,
  778. (void *)&ckptSectionIteratorInstance);
  779. if (error != SA_OK) {
  780. goto error_destroy;
  781. }
  782. ckptSectionIteratorInstance->fd = -1;
  783. pthread_mutex_init (&ckptSectionIteratorInstance->mutex, NULL);
  784. /*
  785. * Setup section id list for iterator next
  786. */
  787. list_init (&ckptSectionIteratorInstance->sectionIdListHead);
  788. ckptSectionIteratorInstance->maxSectionIdSize =
  789. ckptCheckpointInstance->maxSectionIdSize;
  790. error = saServiceConnect (&ckptSectionIteratorInstance->fd,
  791. MESSAGE_REQ_CKPT_SECTIONITERATOR_INIT);
  792. if (error != SA_OK) {
  793. goto error_put_destroy;
  794. }
  795. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  796. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  797. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  798. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  799. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  800. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  801. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  802. error = saSendRetry (ckptSectionIteratorInstance->fd,
  803. &req_lib_ckpt_sectioniteratorinitialize,
  804. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  805. MSG_NOSIGNAL);
  806. if (error != SA_OK) {
  807. goto error_put_destroy;
  808. }
  809. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  810. &res_lib_ckpt_sectioniteratorinitialize,
  811. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  812. MSG_WAITALL | MSG_NOSIGNAL);
  813. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  814. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  815. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  816. return (error == SA_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
  817. error_put_destroy:
  818. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  819. error_destroy:
  820. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  821. error_put_checkpoint_db:
  822. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  823. error_no_destroy:
  824. return (error);
  825. }
  826. struct iteratorSectionIdListEntry {
  827. struct list_head list;
  828. char data[0];
  829. };
  830. SaErrorT
  831. saCkptSectionIteratorNext (
  832. SaCkptSectionIteratorT *sectionIterator,
  833. SaCkptSectionDescriptorT *sectionDescriptor)
  834. {
  835. SaErrorT error;
  836. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  837. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  838. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  839. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  840. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  841. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  842. if (error != SA_OK) {
  843. goto error_exit;
  844. }
  845. /*
  846. * Allocate section id storage area
  847. */
  848. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  849. ckptSectionIteratorInstance->maxSectionIdSize);
  850. if (iteratorSectionIdListEntry == 0) {
  851. error = SA_ERR_NO_MEMORY;
  852. goto error_put_nounlock;
  853. }
  854. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  855. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  856. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  857. error = saSendRetry (ckptSectionIteratorInstance->fd,
  858. &req_lib_ckpt_sectioniteratornext,
  859. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  860. if (error != SA_OK) {
  861. goto error_put;
  862. }
  863. error = saRecvRetry (ckptSectionIteratorInstance->fd, &res_lib_ckpt_sectioniteratornext,
  864. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  865. if (error != SA_OK) {
  866. goto error_put;
  867. }
  868. memcpy (sectionDescriptor,
  869. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  870. sizeof (SaCkptSectionDescriptorT));
  871. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  872. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  873. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  874. sectionDescriptor->sectionId.id,
  875. res_lib_ckpt_sectioniteratornext.header.size -
  876. sizeof (struct res_lib_ckpt_sectioniteratornext),
  877. MSG_WAITALL | MSG_NOSIGNAL);
  878. }
  879. /*
  880. * Add to persistent memory list for this sectioniterator
  881. */
  882. if (error == SA_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_OK) {
  883. list_init (&iteratorSectionIdListEntry->list);
  884. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIteratorInstance->sectionIdListHead);
  885. }
  886. error_put:
  887. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  888. error_put_nounlock:
  889. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  890. error_exit:
  891. return (error == SA_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  892. }
  893. SaErrorT
  894. saCkptSectionIteratorFinalize (
  895. SaCkptSectionIteratorT *sectionIterator)
  896. {
  897. SaErrorT error;
  898. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  899. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  900. struct list_head *sectionIdIteratorList;
  901. struct list_head *sectionIdIteratorListNext;
  902. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  903. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  904. if (error != SA_OK) {
  905. goto error_noput;
  906. }
  907. /*
  908. * iterate list of section ids for this iterator to free the allocated memory
  909. * be careful to cache next pointer because free removes memory from use
  910. */
  911. for (sectionIdIteratorList = ckptSectionIteratorInstance->sectionIdListHead.next,
  912. sectionIdIteratorListNext = sectionIdIteratorList->next;
  913. sectionIdIteratorList != &ckptSectionIteratorInstance->sectionIdListHead;
  914. sectionIdIteratorList = sectionIdIteratorListNext,
  915. sectionIdIteratorListNext = sectionIdIteratorList->next) {
  916. iteratorSectionIdListEntry = list_entry (sectionIdIteratorList,
  917. struct iteratorSectionIdListEntry, list);
  918. free (iteratorSectionIdListEntry);
  919. }
  920. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  921. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  922. error_noput:
  923. return (error);
  924. }
  925. SaErrorT
  926. saCkptCheckpointWrite (
  927. const SaCkptCheckpointHandleT *checkpointHandle,
  928. const SaCkptIOVectorElementT *ioVector,
  929. SaUint32T numberOfElements,
  930. SaUint32T *erroneousVectorIndex)
  931. {
  932. SaErrorT error = SA_OK;
  933. struct ckptCheckpointInstance *ckptCheckpointInstance;
  934. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  935. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  936. int i;
  937. struct iovec iov[3];
  938. int iov_len = 0;
  939. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  940. (void *)&ckptCheckpointInstance);
  941. if (error != SA_OK) {
  942. return (error);
  943. }
  944. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  945. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  946. for (i = 0; i < numberOfElements; i++) {
  947. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  948. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  949. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  950. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  951. iov_len = 0;
  952. /* TODO check for zero length stuff */
  953. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  954. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  955. iov[1].iov_base = ioVector[i].sectionId.id;
  956. iov[1].iov_len = ioVector[i].sectionId.idLen;
  957. iov[2].iov_base = ioVector[i].dataBuffer;
  958. iov[2].iov_len = ioVector[i].dataSize;
  959. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  960. iov,
  961. 3);
  962. if (error != SA_OK) {
  963. goto error_exit;
  964. }
  965. /*
  966. * Receive response
  967. */
  968. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
  969. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  970. if (error != SA_OK) {
  971. goto error_exit;
  972. }
  973. if (res_lib_ckpt_sectionwrite.header.error == SA_ERR_TRY_AGAIN) {
  974. error = SA_ERR_TRY_AGAIN;
  975. goto error_exit;
  976. }
  977. /*
  978. * If error, report back erroneous index
  979. */
  980. if (res_lib_ckpt_sectionwrite.header.error != SA_OK) {
  981. if (erroneousVectorIndex) {
  982. *erroneousVectorIndex = i;
  983. }
  984. goto error_exit;
  985. }
  986. }
  987. error_exit:
  988. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  989. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  990. return (error == SA_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  991. }
  992. SaErrorT
  993. saCkptSectionOverwrite (
  994. const SaCkptCheckpointHandleT *checkpointHandle,
  995. const SaCkptSectionIdT *sectionId,
  996. SaUint8T *dataBuffer,
  997. SaSizeT dataSize)
  998. {
  999. SaErrorT error;
  1000. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1001. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1002. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1003. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1004. (void *)&ckptCheckpointInstance);
  1005. if (error != SA_OK) {
  1006. return (error);
  1007. }
  1008. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1009. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1010. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1011. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1012. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1013. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
  1014. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1015. if (error != SA_OK) {
  1016. goto error_exit;
  1017. }
  1018. if (sectionId->idLen) {
  1019. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  1020. sectionId->idLen, MSG_NOSIGNAL);
  1021. if (error != SA_OK) {
  1022. goto error_exit;
  1023. }
  1024. }
  1025. error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1026. if (error != SA_OK) {
  1027. goto error_exit;
  1028. }
  1029. error = saRecvRetry (ckptCheckpointInstance->fd,
  1030. &res_lib_ckpt_sectionoverwrite,
  1031. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1032. MSG_WAITALL | MSG_NOSIGNAL);
  1033. error_exit:
  1034. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1035. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1036. return (error == SA_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1037. }
  1038. SaErrorT
  1039. saCkptCheckpointRead (
  1040. const SaCkptCheckpointHandleT *checkpointHandle,
  1041. SaCkptIOVectorElementT *ioVector,
  1042. SaUint32T numberOfElements,
  1043. SaUint32T *erroneousVectorIndex)
  1044. {
  1045. SaErrorT error = SA_OK;
  1046. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1047. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1048. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1049. int dataLength;
  1050. int i;
  1051. struct iovec iov[3];
  1052. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1053. (void *)&ckptCheckpointInstance);
  1054. if (error != SA_OK) {
  1055. return (error);
  1056. }
  1057. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1058. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1059. for (i = 0; i < numberOfElements; i++) {
  1060. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1061. ioVector[i].sectionId.idLen;
  1062. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1063. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1064. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1065. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1066. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1067. iov[1].iov_base = ioVector[i].sectionId.id;
  1068. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1069. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  1070. iov,
  1071. 2);
  1072. /*
  1073. * Receive response header
  1074. */
  1075. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionread,
  1076. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1077. if (error != SA_OK) {
  1078. goto error_exit;
  1079. }
  1080. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1081. /*
  1082. * Receive checkpoint section data
  1083. */
  1084. if (dataLength > 0) {
  1085. error = saRecvRetry (ckptCheckpointInstance->fd, ioVector[i].dataBuffer,
  1086. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1087. if (error != SA_OK) {
  1088. goto error_exit;
  1089. }
  1090. }
  1091. if (res_lib_ckpt_sectionread.header.error != SA_OK) {
  1092. if (erroneousVectorIndex) {
  1093. *erroneousVectorIndex = i;
  1094. }
  1095. goto error_exit;
  1096. }
  1097. /*
  1098. * Report back bytes of data read
  1099. */
  1100. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1101. }
  1102. error_exit:
  1103. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1104. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1105. return (error == SA_OK ? res_lib_ckpt_sectionread.header.error : error);
  1106. }
  1107. SaErrorT
  1108. saCkptCheckpointSynchronize (
  1109. const SaCkptCheckpointHandleT *checkpointHandle,
  1110. SaTimeT timeout)
  1111. {
  1112. SaErrorT error;
  1113. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1114. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1115. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1116. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1117. (void *)&ckptCheckpointInstance);
  1118. if (error != SA_OK) {
  1119. return (error);
  1120. }
  1121. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1122. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1123. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1124. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointsynchronize,
  1125. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1126. if (error != SA_OK) {
  1127. goto error_exit;
  1128. }
  1129. error = saRecvRetry (ckptCheckpointInstance->fd,
  1130. &res_lib_ckpt_checkpointsynchronize,
  1131. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1132. MSG_WAITALL | MSG_NOSIGNAL);
  1133. error_exit:
  1134. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1135. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1136. return (error == SA_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1137. }
  1138. SaErrorT
  1139. saCkptCheckpointSynchronizeAsync (
  1140. const SaCkptHandleT *ckptHandle,
  1141. SaInvocationT invocation,
  1142. const SaCkptCheckpointHandleT *checkpointHandle)
  1143. {
  1144. return (SA_OK);
  1145. /* TODO not implemented in executive
  1146. struct ckptInstance *ckptInstance;
  1147. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1148. SaErrorT error;
  1149. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1150. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1151. (void *)&ckptCheckpointInstance);
  1152. if (error != SA_OK) {
  1153. return (error);
  1154. }
  1155. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1156. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1157. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1158. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1159. pthread_mutex_lock (&ckptInstance->mutex);
  1160. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1161. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1162. pthread_mutex_unlock (&ckptInstance->mutex);
  1163. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1164. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1165. return (error);
  1166. */
  1167. }