ckpt.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  538. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  539. (void *)&ckptCheckpointInstance);
  540. if (error != SA_OK) {
  541. goto error_exit_noput;
  542. }
  543. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  544. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  545. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  546. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  547. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  548. if (error != SA_OK) {
  549. goto error_exit;
  550. }
  551. error = saRecvRetry (ckptCheckpointInstance->fd,
  552. &res_lib_ckpt_checkpointretentiondurationset,
  553. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  554. MSG_WAITALL | MSG_NOSIGNAL);
  555. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  556. error_exit:
  557. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  558. error_exit_noput:
  559. return (error == SA_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  560. }
  561. SaErrorT
  562. saCkptActiveCheckpointSet (
  563. const SaCkptCheckpointHandleT *checkpointHandle)
  564. {
  565. SaErrorT error;
  566. struct ckptCheckpointInstance *ckptCheckpointInstance;
  567. struct req_lib_ckpt_activecheckpointset req_lib_ckpt_activecheckpointset;
  568. struct res_lib_ckpt_activecheckpointset res_lib_ckpt_activecheckpointset;
  569. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  570. (void *)&ckptCheckpointInstance);
  571. if (error != SA_OK) {
  572. goto error_exit;
  573. }
  574. req_lib_ckpt_activecheckpointset.header.size = sizeof (struct req_lib_ckpt_activecheckpointset);
  575. req_lib_ckpt_activecheckpointset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET;
  576. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  577. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activecheckpointset,
  578. sizeof (struct req_lib_ckpt_activecheckpointset), MSG_NOSIGNAL);
  579. if (error != SA_OK) {
  580. goto error_exit;
  581. }
  582. error = saRecvRetry (ckptCheckpointInstance->fd,
  583. &res_lib_ckpt_activecheckpointset,
  584. sizeof (struct res_lib_ckpt_activecheckpointset),
  585. MSG_WAITALL | MSG_NOSIGNAL);
  586. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  587. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  588. error_exit:
  589. return (error == SA_OK ? res_lib_ckpt_activecheckpointset.header.error : error);
  590. }
  591. SaErrorT
  592. saCkptCheckpointStatusGet (
  593. const SaCkptCheckpointHandleT *checkpointHandle,
  594. SaCkptCheckpointStatusT *checkpointStatus)
  595. {
  596. SaErrorT error;
  597. struct ckptCheckpointInstance *ckptCheckpointInstance;
  598. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  599. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  600. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  601. (void *)&ckptCheckpointInstance);
  602. if (error != SA_OK) {
  603. return (error);
  604. }
  605. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  606. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  607. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  608. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
  609. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  610. if (error != SA_OK) {
  611. goto error_exit;
  612. }
  613. error = saRecvRetry (ckptCheckpointInstance->fd,
  614. &res_lib_ckpt_checkpointstatusget,
  615. sizeof (struct res_lib_ckpt_checkpointstatusget),
  616. MSG_WAITALL | MSG_NOSIGNAL);
  617. if (error != SA_OK) {
  618. goto error_exit;
  619. }
  620. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  621. memcpy (checkpointStatus,
  622. &res_lib_ckpt_checkpointstatusget.checkpointStatus,
  623. sizeof (SaCkptCheckpointStatusT));
  624. error_exit:
  625. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  626. return (error);
  627. }
  628. SaErrorT
  629. saCkptSectionCreate (
  630. const SaCkptCheckpointHandleT *checkpointHandle,
  631. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  632. const void *initialData,
  633. SaUint32T initialDataSize)
  634. {
  635. SaErrorT error;
  636. struct ckptCheckpointInstance *ckptCheckpointInstance;
  637. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  638. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  639. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  640. (void *)&ckptCheckpointInstance);
  641. if (error != SA_OK) {
  642. return (error);
  643. }
  644. req_lib_ckpt_sectioncreate.header.size =
  645. sizeof (struct req_lib_ckpt_sectioncreate) +
  646. sectionCreationAttributes->sectionId->idLen +
  647. initialDataSize;
  648. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  649. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  650. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  651. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  652. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  653. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
  654. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  655. if (error != SA_OK) {
  656. goto error_exit;
  657. }
  658. /*
  659. * Write section identifier to server
  660. */
  661. error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
  662. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  663. if (error != SA_OK) {
  664. goto error_exit;
  665. }
  666. error = saSendRetry (ckptCheckpointInstance->fd, initialData,
  667. initialDataSize, MSG_NOSIGNAL);
  668. if (error != SA_OK) {
  669. goto error_exit;
  670. }
  671. error = saRecvRetry (ckptCheckpointInstance->fd,
  672. &res_lib_ckpt_sectioncreate,
  673. sizeof (struct res_lib_ckpt_sectioncreate),
  674. MSG_WAITALL | MSG_NOSIGNAL);
  675. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  676. error_exit:
  677. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  678. return (error == SA_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  679. }
  680. SaErrorT
  681. saCkptSectionDelete (
  682. const SaCkptCheckpointHandleT *checkpointHandle,
  683. const SaCkptSectionIdT *sectionId)
  684. {
  685. SaErrorT error;
  686. struct ckptCheckpointInstance *ckptCheckpointInstance;
  687. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  688. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  689. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  690. (void *)&ckptCheckpointInstance);
  691. if (error != SA_OK) {
  692. return (error);
  693. }
  694. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  695. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  696. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  697. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  698. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
  699. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  700. if (error != SA_OK) {
  701. goto error_exit;
  702. }
  703. /*
  704. * Write section identifier to server
  705. */
  706. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  707. sectionId->idLen, MSG_NOSIGNAL);
  708. if (error != SA_OK) {
  709. goto error_exit;
  710. }
  711. error = saRecvRetry (ckptCheckpointInstance->fd,
  712. &res_lib_ckpt_sectiondelete,
  713. sizeof (struct res_lib_ckpt_sectiondelete),
  714. MSG_WAITALL | MSG_NOSIGNAL);
  715. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  716. error_exit:
  717. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  718. return (error == SA_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  719. }
  720. SaErrorT
  721. saCkptSectionExpirationTimeSet (
  722. const SaCkptCheckpointHandleT *checkpointHandle,
  723. const SaCkptSectionIdT *sectionId,
  724. SaTimeT expirationTime)
  725. {
  726. SaErrorT error;
  727. struct ckptCheckpointInstance *ckptCheckpointInstance;
  728. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  729. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  730. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  731. (void *)&ckptCheckpointInstance);
  732. if (error != SA_OK) {
  733. goto error_exit_noput;
  734. }
  735. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  736. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  737. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  738. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  739. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  740. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
  741. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  742. if (error != SA_OK) {
  743. goto error_exit;
  744. }
  745. /*
  746. * Write section identifier to server
  747. */
  748. if (sectionId->idLen) {
  749. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  750. sectionId->idLen, MSG_NOSIGNAL);
  751. if (error != SA_OK) {
  752. goto error_exit;
  753. }
  754. }
  755. error = saRecvRetry (ckptCheckpointInstance->fd,
  756. &res_lib_ckpt_sectionexpirationtimeset,
  757. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  758. MSG_WAITALL | MSG_NOSIGNAL);
  759. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  760. error_exit:
  761. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  762. error_exit_noput:
  763. return (error == SA_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  764. }
  765. SaErrorT
  766. saCkptSectionIteratorInitialize (
  767. const SaCkptCheckpointHandleT *checkpointHandle,
  768. SaCkptSectionsChosenT sectionsChosen,
  769. SaTimeT expirationTime,
  770. SaCkptSectionIteratorT *sectionIterator)
  771. {
  772. SaErrorT error;
  773. struct ckptCheckpointInstance *ckptCheckpointInstance;
  774. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  775. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  776. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  777. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  778. (void *)&ckptCheckpointInstance);
  779. if (error != SA_OK) {
  780. goto error_no_destroy;
  781. }
  782. error = saHandleCreate (&ckptSectionIteratorHandleDatabase,
  783. sizeof (struct ckptSectionIteratorInstance), sectionIterator);
  784. if (error != SA_OK) {
  785. goto error_put_checkpoint_db;
  786. }
  787. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  788. *sectionIterator,
  789. (void *)&ckptSectionIteratorInstance);
  790. if (error != SA_OK) {
  791. goto error_destroy;
  792. }
  793. ckptSectionIteratorInstance->fd = -1;
  794. pthread_mutex_init (&ckptSectionIteratorInstance->mutex, NULL);
  795. /*
  796. * Setup section id list for iterator next
  797. */
  798. list_init (&ckptSectionIteratorInstance->sectionIdListHead);
  799. ckptSectionIteratorInstance->maxSectionIdSize =
  800. ckptCheckpointInstance->maxSectionIdSize;
  801. error = saServiceConnect (&ckptSectionIteratorInstance->fd,
  802. MESSAGE_REQ_CKPT_SECTIONITERATOR_INIT);
  803. if (error != SA_OK) {
  804. goto error_put_destroy;
  805. }
  806. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  807. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  808. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  809. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  810. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  811. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  812. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  813. error = saSendRetry (ckptSectionIteratorInstance->fd,
  814. &req_lib_ckpt_sectioniteratorinitialize,
  815. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  816. MSG_NOSIGNAL);
  817. if (error != SA_OK) {
  818. goto error_put_destroy;
  819. }
  820. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  821. &res_lib_ckpt_sectioniteratorinitialize,
  822. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  823. MSG_WAITALL | MSG_NOSIGNAL);
  824. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  825. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  826. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  827. return (error == SA_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
  828. error_put_destroy:
  829. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  830. error_destroy:
  831. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  832. error_put_checkpoint_db:
  833. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  834. error_no_destroy:
  835. return (error);
  836. }
  837. struct iteratorSectionIdListEntry {
  838. struct list_head list;
  839. char data[0];
  840. };
  841. SaErrorT
  842. saCkptSectionIteratorNext (
  843. SaCkptSectionIteratorT *sectionIterator,
  844. SaCkptSectionDescriptorT *sectionDescriptor)
  845. {
  846. SaErrorT error;
  847. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  848. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  849. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  850. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  851. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  852. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  853. if (error != SA_OK) {
  854. goto error_exit;
  855. }
  856. /*
  857. * Allocate section id storage area
  858. */
  859. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  860. ckptSectionIteratorInstance->maxSectionIdSize);
  861. if (iteratorSectionIdListEntry == 0) {
  862. error = SA_ERR_NO_MEMORY;
  863. goto error_put_nounlock;
  864. }
  865. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  866. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  867. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  868. error = saSendRetry (ckptSectionIteratorInstance->fd,
  869. &req_lib_ckpt_sectioniteratornext,
  870. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  871. if (error != SA_OK) {
  872. goto error_put;
  873. }
  874. error = saRecvRetry (ckptSectionIteratorInstance->fd, &res_lib_ckpt_sectioniteratornext,
  875. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  876. if (error != SA_OK) {
  877. goto error_put;
  878. }
  879. memcpy (sectionDescriptor,
  880. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  881. sizeof (SaCkptSectionDescriptorT));
  882. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  883. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  884. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  885. sectionDescriptor->sectionId.id,
  886. res_lib_ckpt_sectioniteratornext.header.size -
  887. sizeof (struct res_lib_ckpt_sectioniteratornext),
  888. MSG_WAITALL | MSG_NOSIGNAL);
  889. }
  890. /*
  891. * Add to persistent memory list for this sectioniterator
  892. */
  893. if (error == SA_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_OK) {
  894. list_init (&iteratorSectionIdListEntry->list);
  895. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIteratorInstance->sectionIdListHead);
  896. }
  897. error_put:
  898. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  899. error_put_nounlock:
  900. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  901. error_exit:
  902. return (error == SA_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  903. }
  904. SaErrorT
  905. saCkptSectionIteratorFinalize (
  906. SaCkptSectionIteratorT *sectionIterator)
  907. {
  908. SaErrorT error;
  909. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  910. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  911. struct list_head *sectionIdIteratorList;
  912. struct list_head *sectionIdIteratorListNext;
  913. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  914. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  915. if (error != SA_OK) {
  916. goto error_noput;
  917. }
  918. /*
  919. * iterate list of section ids for this iterator to free the allocated memory
  920. * be careful to cache next pointer because free removes memory from use
  921. */
  922. for (sectionIdIteratorList = ckptSectionIteratorInstance->sectionIdListHead.next,
  923. sectionIdIteratorListNext = sectionIdIteratorList->next;
  924. sectionIdIteratorList != &ckptSectionIteratorInstance->sectionIdListHead;
  925. sectionIdIteratorList = sectionIdIteratorListNext,
  926. sectionIdIteratorListNext = sectionIdIteratorList->next) {
  927. iteratorSectionIdListEntry = list_entry (sectionIdIteratorList,
  928. struct iteratorSectionIdListEntry, list);
  929. free (iteratorSectionIdListEntry);
  930. }
  931. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  932. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  933. error_noput:
  934. return (error);
  935. }
  936. SaErrorT
  937. saCkptCheckpointWrite (
  938. const SaCkptCheckpointHandleT *checkpointHandle,
  939. const SaCkptIOVectorElementT *ioVector,
  940. SaUint32T numberOfElements,
  941. SaUint32T *erroneousVectorIndex)
  942. {
  943. SaErrorT error = SA_OK;
  944. struct ckptCheckpointInstance *ckptCheckpointInstance;
  945. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  946. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  947. int i;
  948. struct iovec iov[3];
  949. int iov_len = 0;
  950. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  951. (void *)&ckptCheckpointInstance);
  952. if (error != SA_OK) {
  953. return (error);
  954. }
  955. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  956. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  957. for (i = 0; i < numberOfElements; i++) {
  958. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  959. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  960. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  961. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  962. iov_len = 0;
  963. /* TODO check for zero length stuff */
  964. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  965. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  966. iov[1].iov_base = ioVector[i].sectionId.id;
  967. iov[1].iov_len = ioVector[i].sectionId.idLen;
  968. iov[2].iov_base = ioVector[i].dataBuffer;
  969. iov[2].iov_len = ioVector[i].dataSize;
  970. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  971. iov,
  972. 3);
  973. if (error != SA_OK) {
  974. goto error_exit;
  975. }
  976. /*
  977. * Receive response
  978. */
  979. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
  980. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  981. if (error != SA_OK) {
  982. goto error_exit;
  983. }
  984. if (res_lib_ckpt_sectionwrite.header.error == SA_ERR_TRY_AGAIN) {
  985. error = SA_ERR_TRY_AGAIN;
  986. goto error_exit;
  987. }
  988. /*
  989. * If error, report back erroneous index
  990. */
  991. if (res_lib_ckpt_sectionwrite.header.error != SA_OK) {
  992. if (erroneousVectorIndex) {
  993. *erroneousVectorIndex = i;
  994. }
  995. goto error_exit;
  996. }
  997. }
  998. error_exit:
  999. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1000. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1001. return (error == SA_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1002. }
  1003. SaErrorT
  1004. saCkptSectionOverwrite (
  1005. const SaCkptCheckpointHandleT *checkpointHandle,
  1006. const SaCkptSectionIdT *sectionId,
  1007. SaUint8T *dataBuffer,
  1008. SaSizeT dataSize)
  1009. {
  1010. SaErrorT error;
  1011. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1012. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1013. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1014. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1015. (void *)&ckptCheckpointInstance);
  1016. if (error != SA_OK) {
  1017. return (error);
  1018. }
  1019. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1020. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1021. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1022. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1023. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1024. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
  1025. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1026. if (error != SA_OK) {
  1027. goto error_exit;
  1028. }
  1029. if (sectionId->idLen) {
  1030. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  1031. sectionId->idLen, MSG_NOSIGNAL);
  1032. if (error != SA_OK) {
  1033. goto error_exit;
  1034. }
  1035. }
  1036. error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1037. if (error != SA_OK) {
  1038. goto error_exit;
  1039. }
  1040. error = saRecvRetry (ckptCheckpointInstance->fd,
  1041. &res_lib_ckpt_sectionoverwrite,
  1042. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1043. MSG_WAITALL | MSG_NOSIGNAL);
  1044. error_exit:
  1045. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1046. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1047. return (error == SA_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1048. }
  1049. SaErrorT
  1050. saCkptCheckpointRead (
  1051. const SaCkptCheckpointHandleT *checkpointHandle,
  1052. SaCkptIOVectorElementT *ioVector,
  1053. SaUint32T numberOfElements,
  1054. SaUint32T *erroneousVectorIndex)
  1055. {
  1056. SaErrorT error = SA_OK;
  1057. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1058. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1059. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1060. int dataLength;
  1061. int i;
  1062. struct iovec iov[3];
  1063. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1064. (void *)&ckptCheckpointInstance);
  1065. if (error != SA_OK) {
  1066. return (error);
  1067. }
  1068. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1069. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1070. for (i = 0; i < numberOfElements; i++) {
  1071. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1072. ioVector[i].sectionId.idLen;
  1073. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1074. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1075. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1076. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1077. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1078. iov[1].iov_base = ioVector[i].sectionId.id;
  1079. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1080. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  1081. iov,
  1082. 2);
  1083. /*
  1084. * Receive response header
  1085. */
  1086. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionread,
  1087. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1088. if (error != SA_OK) {
  1089. goto error_exit;
  1090. }
  1091. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1092. /*
  1093. * Receive checkpoint section data
  1094. */
  1095. if (dataLength > 0) {
  1096. error = saRecvRetry (ckptCheckpointInstance->fd, ioVector[i].dataBuffer,
  1097. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1098. if (error != SA_OK) {
  1099. goto error_exit;
  1100. }
  1101. }
  1102. if (res_lib_ckpt_sectionread.header.error != SA_OK) {
  1103. if (erroneousVectorIndex) {
  1104. *erroneousVectorIndex = i;
  1105. }
  1106. goto error_exit;
  1107. }
  1108. /*
  1109. * Report back bytes of data read
  1110. */
  1111. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1112. }
  1113. error_exit:
  1114. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1115. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1116. return (error == SA_OK ? res_lib_ckpt_sectionread.header.error : error);
  1117. }
  1118. SaErrorT
  1119. saCkptCheckpointSynchronize (
  1120. const SaCkptCheckpointHandleT *checkpointHandle,
  1121. SaTimeT timeout)
  1122. {
  1123. SaErrorT error;
  1124. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1125. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1126. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1127. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1128. (void *)&ckptCheckpointInstance);
  1129. if (error != SA_OK) {
  1130. return (error);
  1131. }
  1132. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1133. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1134. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1135. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointsynchronize,
  1136. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1137. if (error != SA_OK) {
  1138. goto error_exit;
  1139. }
  1140. error = saRecvRetry (ckptCheckpointInstance->fd,
  1141. &res_lib_ckpt_checkpointsynchronize,
  1142. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1143. MSG_WAITALL | MSG_NOSIGNAL);
  1144. error_exit:
  1145. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1146. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1147. return (error == SA_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1148. }
  1149. SaErrorT
  1150. saCkptCheckpointSynchronizeAsync (
  1151. const SaCkptHandleT *ckptHandle,
  1152. SaInvocationT invocation,
  1153. const SaCkptCheckpointHandleT *checkpointHandle)
  1154. {
  1155. return (SA_OK);
  1156. /* TODO not implemented in executive
  1157. struct ckptInstance *ckptInstance;
  1158. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1159. SaErrorT error;
  1160. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1161. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1162. (void *)&ckptCheckpointInstance);
  1163. if (error != SA_OK) {
  1164. return (error);
  1165. }
  1166. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1167. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1168. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1169. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1170. pthread_mutex_lock (&ckptInstance->mutex);
  1171. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1172. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1173. pthread_mutex_unlock (&ckptInstance->mutex);
  1174. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1175. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1176. return (error);
  1177. */
  1178. }