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 message_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 message_header **queue_msg;
  220. struct message_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. } else {
  261. /*
  262. * Queue empty, read response from socket
  263. */
  264. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.header, sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  265. if (error != SA_OK) {
  266. goto error_exit;
  267. }
  268. if (ckptInstance->message.header.size > sizeof (struct message_header)) {
  269. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.data,
  270. ckptInstance->message.header.size - sizeof (struct message_header),
  271. MSG_WAITALL | MSG_NOSIGNAL);
  272. if (error != SA_OK) {
  273. goto error_exit;
  274. }
  275. }
  276. }
  277. /*
  278. * Dispatch incoming response
  279. */
  280. switch (ckptInstance->message.header.id) {
  281. #ifdef COMPILE_OUT
  282. case MESSAGE_RES_CKPT_CHECKPOINT_ACTIVATEPOLL:
  283. /*
  284. * This is a do nothing message which the node executive sends
  285. * to activate the file handle in poll when the library has
  286. * queued a message into amfHandle->inq
  287. * The dispatch is ignored for the following two cases:
  288. * 1) setting of timeout to zero for the DISPATCH_ALL case
  289. * 2) expiration of the do loop for the DISPATCH_ONE case
  290. */
  291. ignore_dispatch = 1;
  292. break;
  293. case MESSAGE_RES_CKPT_CHECKPOINT_HEALTHCHECKCALLBACK:
  294. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&ckptInstance->message;
  295. amfInstance->callbacks.saAmfHealthcheckCallback (
  296. res_amf_healthcheckcallback->invocation,
  297. &res_amf_healthcheckcallback->compName,
  298. res_amf_healthcheckcallback->checkType);
  299. break;
  300. case MESSAGE_RES_CKPT_CHECKPOINT_READINESSSTATESETCALLBACK:
  301. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&ckptInstance->message;
  302. amfInstance->callbacks.saAmfReadinessStateSetCallback (
  303. res_amf_readinessstatesetcallback->invocation,
  304. &res_amf_readinessstatesetcallback->compName,
  305. res_amf_readinessstatesetcallback->readinessState);
  306. break;
  307. case MESSAGE_RES_CKPT_CHECKPOINT_CSISETCALLBACK:
  308. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&ckptInstance->message;
  309. amfInstance->callbacks.saAmfCSISetCallback (
  310. res_amf_csisetcallback->invocation,
  311. &res_amf_csisetcallback->compName,
  312. &res_amf_csisetcallback->csiName,
  313. res_amf_csisetcallback->csiFlags,
  314. &res_amf_csisetcallback->haState,
  315. &res_amf_csisetcallback->activeCompName,
  316. res_amf_csisetcallback->transitionDescriptor);
  317. break;
  318. case MESSAGE_RES_CKPT_CHECKPOINT_CSIREMOVECALLBACK:
  319. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&ckptInstance->message;
  320. amfInstance->callbacks.saAmfCSIRemoveCallback (
  321. res_amf_csiremovecallback->invocation,
  322. &res_amf_csiremovecallback->compName,
  323. &res_amf_csiremovecallback->csiName,
  324. &res_amf_csiremovecallback->csiFlags);
  325. break;
  326. case MESSAGE_RES_CKPT_CHECKPOINT_PROTECTIONGROUPTRACKCALLBACK:
  327. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&ckptInstance->message;
  328. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  329. res_amf_protectiongrouptrackcallback->notificationBuffer,
  330. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  331. amfInstance->callbacks.saAmfProtectionGroupTrackCallback(
  332. &res_amf_protectiongrouptrackcallback->csiName,
  333. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  334. res_amf_protectiongrouptrackcallback->numberOfItems,
  335. res_amf_protectiongrouptrackcallback->numberOfMembers,
  336. res_amf_protectiongrouptrackcallback->error);
  337. break;
  338. #endif
  339. default:
  340. /* TODO */
  341. break;
  342. }
  343. /*
  344. * Determine if more messages should be processed
  345. */
  346. switch (dispatchFlags) {
  347. case SA_DISPATCH_ONE:
  348. if (ignore_dispatch) {
  349. ignore_dispatch = 0;
  350. } else {
  351. cont = 0;
  352. }
  353. break;
  354. case SA_DISPATCH_ALL:
  355. if (ignore_dispatch) {
  356. ignore_dispatch = 0;
  357. }
  358. break;
  359. case SA_DISPATCH_BLOCKING:
  360. break;
  361. }
  362. } while (cont);
  363. error_exit:
  364. return (error);
  365. }
  366. #endif
  367. SaErrorT
  368. saCkptFinalize (
  369. const SaCkptHandleT *ckptHandle)
  370. {
  371. struct ckptInstance *ckptInstance;
  372. SaErrorT error;
  373. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
  374. (void *)&ckptInstance);
  375. if (error != SA_OK) {
  376. return (error);
  377. }
  378. pthread_mutex_lock (&ckptInstance->mutex);
  379. /*
  380. * Another thread has already started finalizing
  381. */
  382. if (ckptInstance->finalize) {
  383. pthread_mutex_unlock (&ckptInstance->mutex);
  384. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  385. return (SA_ERR_BAD_HANDLE);
  386. }
  387. ckptInstance->finalize = 1;
  388. saActivatePoll (ckptInstance->fd);
  389. pthread_mutex_unlock (&ckptInstance->mutex);
  390. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  391. saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
  392. return (SA_OK);
  393. }
  394. SaErrorT
  395. saCkptCheckpointOpen (
  396. const SaNameT *checkpointName,
  397. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  398. SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
  399. SaTimeT timeout,
  400. SaCkptCheckpointHandleT *checkpointHandle)
  401. {
  402. SaErrorT error;
  403. struct ckptCheckpointInstance *ckptCheckpointInstance;
  404. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  405. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  406. error = saHandleCreate (&checkpointHandleDatabase,
  407. sizeof (struct ckptCheckpointInstance), checkpointHandle);
  408. if (error != SA_OK) {
  409. goto error_no_destroy;
  410. }
  411. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  412. (void *)&ckptCheckpointInstance);
  413. if (error != SA_OK) {
  414. goto error_destroy;
  415. }
  416. ckptCheckpointInstance->fd = -1;
  417. ckptCheckpointInstance->maxSectionIdSize =
  418. checkpointCreationAttributes->maxSectionIdSize;
  419. error = saServiceConnect (&ckptCheckpointInstance->fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  420. if (error != SA_OK) {
  421. goto error_put_destroy;
  422. }
  423. req_lib_ckpt_checkpointopen.header.magic = MESSAGE_MAGIC;
  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.error != SA_OK) {
  443. error = res_lib_ckpt_checkpointopen.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.magic = MESSAGE_MAGIC;
  472. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  473. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  474. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  475. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName, checkpointName, sizeof (SaNameT));
  476. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  477. checkpointCreationAttributes,
  478. sizeof (SaCkptCheckpointCreationAttributesT));
  479. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  480. pthread_mutex_lock (&ckptInstance->mutex);
  481. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointopenasync,
  482. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  483. pthread_mutex_unlock (&ckptInstance->mutex);
  484. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  485. return (error);
  486. }
  487. SaErrorT
  488. saCkptCheckpointClose (
  489. const SaCkptCheckpointHandleT *checkpointHandle)
  490. {
  491. SaErrorT error;
  492. struct ckptCheckpointInstance *ckptCheckpointInstance;
  493. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  494. (void *)&ckptCheckpointInstance);
  495. if (error != SA_OK) {
  496. goto error_exit;
  497. }
  498. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  499. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  500. error_exit:
  501. return (error);
  502. }
  503. SaErrorT
  504. saCkptCheckpointUnlink (
  505. const SaNameT *checkpointName)
  506. {
  507. SaErrorT error;
  508. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  509. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  510. int fd;
  511. error = saServiceConnect (&fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  512. if (error != SA_OK) {
  513. goto exit_noclose;
  514. }
  515. req_lib_ckpt_checkpointunlink.header.magic = MESSAGE_MAGIC;
  516. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  517. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  518. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  519. error = saSendRetry (fd, &req_lib_ckpt_checkpointunlink, sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  520. if (error != SA_OK) {
  521. goto exit_close;
  522. }
  523. error = saRecvQueue (fd, &res_lib_ckpt_checkpointunlink,
  524. 0, MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK);
  525. exit_close:
  526. close (fd);
  527. return (error == SA_OK ? res_lib_ckpt_checkpointunlink.error : error);
  528. exit_noclose:
  529. return (error);
  530. }
  531. SaErrorT
  532. saCkptCheckpointRetentionDurationSet (
  533. const SaCkptCheckpointHandleT *checkpointHandle,
  534. SaTimeT retentionDuration)
  535. {
  536. SaErrorT error;
  537. struct ckptCheckpointInstance *ckptCheckpointInstance;
  538. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  539. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  540. (void *)&ckptCheckpointInstance);
  541. if (error != SA_OK) {
  542. goto error_exit;
  543. }
  544. req_lib_ckpt_checkpointretentiondurationset.header.magic = MESSAGE_MAGIC;
  545. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  546. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  547. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  548. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  549. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  550. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  551. error_exit:
  552. return (error);
  553. }
  554. SaErrorT
  555. saCkptActiveCheckpointSet (
  556. const SaCkptCheckpointHandleT *checkpointHandle)
  557. {
  558. SaErrorT error;
  559. struct ckptCheckpointInstance *ckptCheckpointInstance;
  560. struct req_lib_ckpt_activecheckpointset req_lib_ckpt_activecheckpointset;
  561. struct res_lib_ckpt_activecheckpointset res_lib_ckpt_activecheckpointset;
  562. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  563. (void *)&ckptCheckpointInstance);
  564. if (error != SA_OK) {
  565. goto error_exit;
  566. }
  567. req_lib_ckpt_activecheckpointset.header.magic = MESSAGE_MAGIC;
  568. req_lib_ckpt_activecheckpointset.header.size = sizeof (struct req_lib_ckpt_activecheckpointset);
  569. req_lib_ckpt_activecheckpointset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET;
  570. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  571. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activecheckpointset,
  572. sizeof (struct req_lib_ckpt_activecheckpointset), MSG_NOSIGNAL);
  573. if (error != SA_OK) {
  574. goto error_exit;
  575. }
  576. error = saRecvQueue (ckptCheckpointInstance->fd,
  577. &res_lib_ckpt_activecheckpointset, 0,
  578. MESSAGE_RES_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET);
  579. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  580. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  581. error_exit:
  582. return (error == SA_OK ? res_lib_ckpt_activecheckpointset.error : error);
  583. }
  584. SaErrorT
  585. saCkptCheckpointStatusGet (
  586. const SaCkptCheckpointHandleT *checkpointHandle,
  587. SaCkptCheckpointStatusT *checkpointStatus)
  588. {
  589. SaErrorT error;
  590. struct ckptCheckpointInstance *ckptCheckpointInstance;
  591. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  592. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  593. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  594. (void *)&ckptCheckpointInstance);
  595. if (error != SA_OK) {
  596. return (error);
  597. }
  598. req_lib_ckpt_checkpointstatusget.header.magic = MESSAGE_MAGIC;
  599. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  600. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  601. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  602. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
  603. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  604. if (error != SA_OK) {
  605. goto error_exit;
  606. }
  607. error = saRecvQueue (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointstatusget,
  608. 0, MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET);
  609. if (error != SA_OK) {
  610. goto error_exit;
  611. }
  612. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  613. memcpy (checkpointStatus,
  614. &res_lib_ckpt_checkpointstatusget.checkpointStatus,
  615. sizeof (SaCkptCheckpointStatusT));
  616. error_exit:
  617. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  618. return (error);
  619. }
  620. SaErrorT
  621. saCkptSectionCreate (
  622. const SaCkptCheckpointHandleT *checkpointHandle,
  623. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  624. const void *initialData,
  625. SaUint32T initialDataSize)
  626. {
  627. SaErrorT error;
  628. struct ckptCheckpointInstance *ckptCheckpointInstance;
  629. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  630. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  631. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  632. (void *)&ckptCheckpointInstance);
  633. if (error != SA_OK) {
  634. return (error);
  635. }
  636. req_lib_ckpt_sectioncreate.header.magic = MESSAGE_MAGIC;
  637. req_lib_ckpt_sectioncreate.header.size =
  638. sizeof (struct req_lib_ckpt_sectioncreate) +
  639. sectionCreationAttributes->sectionId->idLen +
  640. initialDataSize;
  641. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  642. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  643. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  644. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  645. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  646. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
  647. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  648. if (error != SA_OK) {
  649. goto error_exit;
  650. }
  651. /*
  652. * Write section identifier to server
  653. */
  654. error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
  655. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  656. if (error != SA_OK) {
  657. goto error_exit;
  658. }
  659. error = saSendRetry (ckptCheckpointInstance->fd, initialData,
  660. initialDataSize, MSG_NOSIGNAL);
  661. if (error != SA_OK) {
  662. goto error_exit;
  663. }
  664. error = saRecvQueue (ckptCheckpointInstance->fd,
  665. &res_lib_ckpt_sectioncreate, 0,
  666. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE);
  667. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  668. error_exit:
  669. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  670. return (error == SA_OK ? res_lib_ckpt_sectioncreate.error : error);
  671. }
  672. SaErrorT
  673. saCkptSectionDelete (
  674. const SaCkptCheckpointHandleT *checkpointHandle,
  675. const SaCkptSectionIdT *sectionId)
  676. {
  677. SaErrorT error;
  678. struct ckptCheckpointInstance *ckptCheckpointInstance;
  679. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  680. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  681. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  682. (void *)&ckptCheckpointInstance);
  683. if (error != SA_OK) {
  684. return (error);
  685. }
  686. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  687. req_lib_ckpt_sectiondelete.header.magic = MESSAGE_MAGIC;
  688. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  689. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  690. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  691. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
  692. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  693. if (error != SA_OK) {
  694. goto error_exit;
  695. }
  696. /*
  697. * Write section identifier to server
  698. */
  699. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  700. sectionId->idLen, MSG_NOSIGNAL);
  701. if (error != SA_OK) {
  702. goto error_exit;
  703. }
  704. error = saRecvQueue (ckptCheckpointInstance->fd,
  705. &res_lib_ckpt_sectiondelete, 0,
  706. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE);
  707. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  708. error_exit:
  709. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  710. return (error == SA_OK ? res_lib_ckpt_sectiondelete.error : error);
  711. }
  712. SaErrorT
  713. saCkptSectionExpirationTimeSet (
  714. const SaCkptCheckpointHandleT *checkpointHandle,
  715. const SaCkptSectionIdT *sectionId,
  716. SaTimeT expirationTime)
  717. {
  718. SaErrorT error;
  719. struct ckptCheckpointInstance *ckptCheckpointInstance;
  720. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  721. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  722. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  723. (void *)&ckptCheckpointInstance);
  724. if (error != SA_OK) {
  725. goto error_exit;
  726. }
  727. req_lib_ckpt_sectionexpirationtimeset.header.magic = MESSAGE_MAGIC;
  728. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  729. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  730. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  731. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  732. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  733. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
  734. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  735. if (error != SA_OK) {
  736. goto error_exit;
  737. }
  738. /*
  739. * Write section identifier to server
  740. */
  741. if (sectionId->idLen) {
  742. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  743. sectionId->idLen, MSG_NOSIGNAL);
  744. if (error != SA_OK) {
  745. goto error_exit;
  746. }
  747. }
  748. error = saRecvQueue (ckptCheckpointInstance->fd,
  749. &res_lib_ckpt_sectionexpirationtimeset,
  750. 0, MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET);
  751. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  752. error_exit:
  753. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  754. return (error == SA_OK ? res_lib_ckpt_sectionexpirationtimeset.error : error);
  755. }
  756. SaErrorT
  757. saCkptSectionIteratorInitialize (
  758. const SaCkptCheckpointHandleT *checkpointHandle,
  759. SaCkptSectionsChosenT sectionsChosen,
  760. SaTimeT expirationTime,
  761. SaCkptSectionIteratorT *sectionIterator)
  762. {
  763. SaErrorT error;
  764. struct ckptCheckpointInstance *ckptCheckpointInstance;
  765. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  766. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  767. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  768. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  769. (void *)&ckptCheckpointInstance);
  770. if (error != SA_OK) {
  771. goto error_no_destroy;
  772. }
  773. error = saHandleCreate (&ckptSectionIteratorHandleDatabase,
  774. sizeof (struct ckptSectionIteratorInstance), sectionIterator);
  775. if (error != SA_OK) {
  776. goto error_put_checkpoint_db;
  777. }
  778. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  779. *sectionIterator,
  780. (void *)&ckptSectionIteratorInstance);
  781. if (error != SA_OK) {
  782. goto error_destroy;
  783. }
  784. ckptSectionIteratorInstance->fd = -1;
  785. pthread_mutex_init (&ckptSectionIteratorInstance->mutex, NULL);
  786. /*
  787. * Setup section id list for iterator next
  788. */
  789. list_init (&ckptSectionIteratorInstance->sectionIdListHead);
  790. ckptSectionIteratorInstance->maxSectionIdSize =
  791. ckptCheckpointInstance->maxSectionIdSize;
  792. error = saServiceConnect (&ckptSectionIteratorInstance->fd,
  793. MESSAGE_REQ_CKPT_SECTIONITERATOR_INIT);
  794. if (error != SA_OK) {
  795. goto error_put_destroy;
  796. }
  797. req_lib_ckpt_sectioniteratorinitialize.header.magic = MESSAGE_MAGIC;
  798. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  799. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  800. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  801. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  802. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  803. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  804. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  805. error = saSendRetry (ckptSectionIteratorInstance->fd,
  806. &req_lib_ckpt_sectioniteratorinitialize,
  807. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  808. MSG_NOSIGNAL);
  809. if (error != SA_OK) {
  810. goto error_put_destroy;
  811. }
  812. error = saRecvQueue (ckptSectionIteratorInstance->fd,
  813. &res_lib_ckpt_sectioniteratorinitialize, 0,
  814. MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE);
  815. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  816. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  817. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  818. return (error == SA_OK ? res_lib_ckpt_sectioniteratorinitialize.error : error);
  819. error_put_destroy:
  820. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  821. error_destroy:
  822. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  823. error_put_checkpoint_db:
  824. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  825. error_no_destroy:
  826. return (error);
  827. }
  828. struct iteratorSectionIdListEntry {
  829. struct list_head list;
  830. char data[0];
  831. };
  832. SaErrorT
  833. saCkptSectionIteratorNext (
  834. SaCkptSectionIteratorT *sectionIterator,
  835. SaCkptSectionDescriptorT *sectionDescriptor)
  836. {
  837. SaErrorT error;
  838. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  839. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  840. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  841. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  842. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  843. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  844. if (error != SA_OK) {
  845. goto error_exit;
  846. }
  847. /*
  848. * Allocate section id storage area
  849. */
  850. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  851. ckptSectionIteratorInstance->maxSectionIdSize);
  852. if (iteratorSectionIdListEntry == 0) {
  853. error = SA_ERR_NO_MEMORY;
  854. goto error_put_nounlock;
  855. }
  856. req_lib_ckpt_sectioniteratornext.header.magic = MESSAGE_MAGIC;
  857. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  858. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  859. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  860. error = saSendRetry (ckptSectionIteratorInstance->fd,
  861. &req_lib_ckpt_sectioniteratornext,
  862. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  863. if (error != SA_OK) {
  864. goto error_put;
  865. }
  866. error = saRecvRetry (ckptSectionIteratorInstance->fd, &res_lib_ckpt_sectioniteratornext,
  867. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  868. if (error != SA_OK) {
  869. goto error_put;
  870. }
  871. memcpy (sectionDescriptor,
  872. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  873. sizeof (SaCkptSectionDescriptorT));
  874. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  875. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  876. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  877. sectionDescriptor->sectionId.id,
  878. res_lib_ckpt_sectioniteratornext.header.size -
  879. sizeof (struct res_lib_ckpt_sectioniteratornext),
  880. MSG_WAITALL | MSG_NOSIGNAL);
  881. }
  882. /*
  883. * Add to persistent memory list for this sectioniterator
  884. */
  885. if (error == SA_OK && res_lib_ckpt_sectioniteratornext.error == SA_OK) {
  886. list_init (&iteratorSectionIdListEntry->list);
  887. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIteratorInstance->sectionIdListHead);
  888. }
  889. error_put:
  890. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  891. error_put_nounlock:
  892. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  893. error_exit:
  894. return (error == SA_OK ? res_lib_ckpt_sectioniteratornext.error : error);
  895. }
  896. SaErrorT
  897. saCkptSectionIteratorFinalize (
  898. SaCkptSectionIteratorT *sectionIterator)
  899. {
  900. SaErrorT error;
  901. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  902. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  903. struct list_head *sectionIdIteratorList;
  904. struct list_head *sectionIdIteratorListNext;
  905. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  906. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  907. if (error != SA_OK) {
  908. goto error_noput;
  909. }
  910. /*
  911. * iterate list of section ids for this iterator to free the allocated memory
  912. * be careful to cache next pointer because free removes memory from use
  913. */
  914. for (sectionIdIteratorList = ckptSectionIteratorInstance->sectionIdListHead.next,
  915. sectionIdIteratorListNext = sectionIdIteratorList->next;
  916. sectionIdIteratorList != &ckptSectionIteratorInstance->sectionIdListHead;
  917. sectionIdIteratorList = sectionIdIteratorListNext,
  918. sectionIdIteratorListNext = sectionIdIteratorList->next) {
  919. iteratorSectionIdListEntry = list_entry (sectionIdIteratorList,
  920. struct iteratorSectionIdListEntry, list);
  921. free (iteratorSectionIdListEntry);
  922. }
  923. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  924. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  925. error_noput:
  926. return (error);
  927. }
  928. SaErrorT
  929. saCkptCheckpointWrite (
  930. const SaCkptCheckpointHandleT *checkpointHandle,
  931. const SaCkptIOVectorElementT *ioVector,
  932. SaUint32T numberOfElements,
  933. SaUint32T *erroneousVectorIndex)
  934. {
  935. SaErrorT error = SA_OK;
  936. struct ckptCheckpointInstance *ckptCheckpointInstance;
  937. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  938. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  939. int i;
  940. struct iovec iov[3];
  941. int iov_len = 0;
  942. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  943. (void *)&ckptCheckpointInstance);
  944. if (error != SA_OK) {
  945. return (error);
  946. }
  947. req_lib_ckpt_sectionwrite.header.magic = MESSAGE_MAGIC;
  948. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  949. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  950. for (i = 0; i < numberOfElements; i++) {
  951. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  952. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  953. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  954. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  955. iov_len = 0;
  956. /* TODO check for zero length stuff */
  957. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  958. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  959. iov[1].iov_base = ioVector[i].sectionId.id;
  960. iov[1].iov_len = ioVector[i].sectionId.idLen;
  961. iov[2].iov_base = ioVector[i].dataBuffer;
  962. iov[2].iov_len = ioVector[i].dataSize;
  963. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  964. iov,
  965. 3);
  966. if (error != SA_OK) {
  967. goto error_exit;
  968. }
  969. /*
  970. * Receive response
  971. */
  972. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
  973. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  974. if (error != SA_OK) {
  975. goto error_exit;
  976. }
  977. /*
  978. * If error, report back erroneous index
  979. */
  980. if (res_lib_ckpt_sectionwrite.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.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.magic = MESSAGE_MAGIC;
  1009. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1010. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1011. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1012. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1013. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1014. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
  1015. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1016. if (error != SA_OK) {
  1017. goto error_exit;
  1018. }
  1019. if (sectionId->idLen) {
  1020. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  1021. sectionId->idLen, MSG_NOSIGNAL);
  1022. if (error != SA_OK) {
  1023. goto error_exit;
  1024. }
  1025. }
  1026. error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1027. if (error != SA_OK) {
  1028. goto error_exit;
  1029. }
  1030. error = saRecvQueue (ckptCheckpointInstance->fd,
  1031. &res_lib_ckpt_sectionoverwrite, 0, MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE);
  1032. error_exit:
  1033. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1034. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1035. return (error == SA_OK ? res_lib_ckpt_sectionoverwrite.error : error);
  1036. }
  1037. SaErrorT
  1038. saCkptCheckpointRead (
  1039. const SaCkptCheckpointHandleT *checkpointHandle,
  1040. SaCkptIOVectorElementT *ioVector,
  1041. SaUint32T numberOfElements,
  1042. SaUint32T *erroneousVectorIndex)
  1043. {
  1044. SaErrorT error = SA_OK;
  1045. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1046. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1047. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1048. int dataLength;
  1049. int i;
  1050. struct iovec iov[3];
  1051. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1052. (void *)&ckptCheckpointInstance);
  1053. if (error != SA_OK) {
  1054. return (error);
  1055. }
  1056. req_lib_ckpt_sectionread.header.magic = MESSAGE_MAGIC;
  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.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.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.magic = MESSAGE_MAGIC;
  1122. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1123. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1124. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1125. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointsynchronize,
  1126. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1127. if (error != SA_OK) {
  1128. goto error_exit;
  1129. }
  1130. error = saRecvQueue (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointsynchronize,
  1131. 0, MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE);
  1132. error_exit:
  1133. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1134. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1135. return (error == SA_OK ? res_lib_ckpt_checkpointsynchronize.error : error);
  1136. }
  1137. SaErrorT
  1138. saCkptCheckpointSynchronizeAsync (
  1139. const SaCkptHandleT *ckptHandle,
  1140. SaInvocationT invocation,
  1141. const SaCkptCheckpointHandleT *checkpointHandle)
  1142. {
  1143. return (SA_OK);
  1144. /* TODO not implemented in executive
  1145. struct ckptInstance *ckptInstance;
  1146. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1147. SaErrorT error;
  1148. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1149. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1150. (void *)&ckptCheckpointInstance);
  1151. if (error != SA_OK) {
  1152. return (error);
  1153. }
  1154. req_lib_ckpt_checkpointsynchronizeasync.header.magic = MESSAGE_MAGIC;
  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. }