ckpt.c 44 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 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. free (msg);
  261. } else {
  262. /*
  263. * Queue empty, read response from socket
  264. */
  265. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.header, sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  266. if (error != SA_OK) {
  267. goto error_exit;
  268. }
  269. if (ckptInstance->message.header.size > sizeof (struct message_header)) {
  270. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.data,
  271. ckptInstance->message.header.size - sizeof (struct message_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.magic = MESSAGE_MAGIC;
  425. req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
  426. req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  427. memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
  428. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
  429. memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
  430. checkpointCreationAttributes,
  431. sizeof (SaCkptCheckpointCreationAttributesT));
  432. req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
  433. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointopen,
  434. sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
  435. if (error != SA_OK) {
  436. goto error_put_destroy;
  437. }
  438. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointopen,
  439. sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
  440. if (error != SA_OK) {
  441. goto error_put_destroy;
  442. }
  443. if (res_lib_ckpt_checkpointopen.error != SA_OK) {
  444. error = res_lib_ckpt_checkpointopen.error;
  445. goto error_put_destroy;
  446. }
  447. pthread_mutex_init (&ckptCheckpointInstance->mutex, NULL);
  448. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  449. return (error);
  450. error_put_destroy:
  451. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  452. error_destroy:
  453. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  454. error_no_destroy:
  455. return (error);
  456. }
  457. SaErrorT
  458. saCkptCheckpointOpenAsync (
  459. const SaCkptHandleT *ckptHandle,
  460. SaInvocationT invocation,
  461. const SaNameT *checkpointName,
  462. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  463. SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
  464. {
  465. struct ckptInstance *ckptInstance;
  466. SaErrorT error;
  467. struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
  468. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, (void *)&ckptInstance);
  469. if (error != SA_OK) {
  470. return (error);
  471. }
  472. req_lib_ckpt_checkpointopenasync.header.magic = MESSAGE_MAGIC;
  473. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  474. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  475. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  476. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName, checkpointName, sizeof (SaNameT));
  477. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  478. checkpointCreationAttributes,
  479. sizeof (SaCkptCheckpointCreationAttributesT));
  480. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  481. pthread_mutex_lock (&ckptInstance->mutex);
  482. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointopenasync,
  483. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  484. pthread_mutex_unlock (&ckptInstance->mutex);
  485. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  486. return (error);
  487. }
  488. SaErrorT
  489. saCkptCheckpointClose (
  490. const SaCkptCheckpointHandleT *checkpointHandle)
  491. {
  492. SaErrorT error;
  493. struct ckptCheckpointInstance *ckptCheckpointInstance;
  494. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  495. (void *)&ckptCheckpointInstance);
  496. if (error != SA_OK) {
  497. goto error_exit;
  498. }
  499. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  500. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  501. error_exit:
  502. return (error);
  503. }
  504. SaErrorT
  505. saCkptCheckpointUnlink (
  506. const SaNameT *checkpointName)
  507. {
  508. SaErrorT error;
  509. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  510. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  511. int fd;
  512. error = saServiceConnect (&fd, MESSAGE_REQ_CKPT_CHECKPOINT_INIT);
  513. if (error != SA_OK) {
  514. goto exit_noclose;
  515. }
  516. req_lib_ckpt_checkpointunlink.header.magic = MESSAGE_MAGIC;
  517. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  518. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  519. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  520. error = saSendRetry (fd, &req_lib_ckpt_checkpointunlink, sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  521. if (error != SA_OK) {
  522. goto exit_close;
  523. }
  524. error = saRecvRetry (fd, &res_lib_ckpt_checkpointunlink,
  525. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  526. exit_close:
  527. close (fd);
  528. return (error == SA_OK ? res_lib_ckpt_checkpointunlink.error : error);
  529. exit_noclose:
  530. return (error);
  531. }
  532. SaErrorT
  533. saCkptCheckpointRetentionDurationSet (
  534. const SaCkptCheckpointHandleT *checkpointHandle,
  535. SaTimeT retentionDuration)
  536. {
  537. SaErrorT error;
  538. struct ckptCheckpointInstance *ckptCheckpointInstance;
  539. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  540. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  541. (void *)&ckptCheckpointInstance);
  542. if (error != SA_OK) {
  543. goto error_exit;
  544. }
  545. req_lib_ckpt_checkpointretentiondurationset.header.magic = MESSAGE_MAGIC;
  546. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  547. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  548. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  549. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  550. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  551. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  552. error_exit:
  553. return (error);
  554. }
  555. SaErrorT
  556. saCkptActiveCheckpointSet (
  557. const SaCkptCheckpointHandleT *checkpointHandle)
  558. {
  559. SaErrorT error;
  560. struct ckptCheckpointInstance *ckptCheckpointInstance;
  561. struct req_lib_ckpt_activecheckpointset req_lib_ckpt_activecheckpointset;
  562. struct res_lib_ckpt_activecheckpointset res_lib_ckpt_activecheckpointset;
  563. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  564. (void *)&ckptCheckpointInstance);
  565. if (error != SA_OK) {
  566. goto error_exit;
  567. }
  568. req_lib_ckpt_activecheckpointset.header.magic = MESSAGE_MAGIC;
  569. req_lib_ckpt_activecheckpointset.header.size = sizeof (struct req_lib_ckpt_activecheckpointset);
  570. req_lib_ckpt_activecheckpointset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET;
  571. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  572. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activecheckpointset,
  573. sizeof (struct req_lib_ckpt_activecheckpointset), MSG_NOSIGNAL);
  574. if (error != SA_OK) {
  575. goto error_exit;
  576. }
  577. error = saRecvRetry (ckptCheckpointInstance->fd,
  578. &res_lib_ckpt_activecheckpointset,
  579. sizeof (struct res_lib_ckpt_activecheckpointset),
  580. MSG_WAITALL | MSG_NOSIGNAL);
  581. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  582. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  583. error_exit:
  584. return (error == SA_OK ? res_lib_ckpt_activecheckpointset.error : error);
  585. }
  586. SaErrorT
  587. saCkptCheckpointStatusGet (
  588. const SaCkptCheckpointHandleT *checkpointHandle,
  589. SaCkptCheckpointStatusT *checkpointStatus)
  590. {
  591. SaErrorT error;
  592. struct ckptCheckpointInstance *ckptCheckpointInstance;
  593. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  594. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  595. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  596. (void *)&ckptCheckpointInstance);
  597. if (error != SA_OK) {
  598. return (error);
  599. }
  600. req_lib_ckpt_checkpointstatusget.header.magic = MESSAGE_MAGIC;
  601. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  602. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  603. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  604. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
  605. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  606. if (error != SA_OK) {
  607. goto error_exit;
  608. }
  609. error = saRecvRetry (ckptCheckpointInstance->fd,
  610. &res_lib_ckpt_checkpointstatusget,
  611. sizeof (struct res_lib_ckpt_checkpointstatusget),
  612. MSG_WAITALL | MSG_NOSIGNAL);
  613. if (error != SA_OK) {
  614. goto error_exit;
  615. }
  616. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  617. memcpy (checkpointStatus,
  618. &res_lib_ckpt_checkpointstatusget.checkpointStatus,
  619. sizeof (SaCkptCheckpointStatusT));
  620. error_exit:
  621. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  622. return (error);
  623. }
  624. SaErrorT
  625. saCkptSectionCreate (
  626. const SaCkptCheckpointHandleT *checkpointHandle,
  627. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  628. const void *initialData,
  629. SaUint32T initialDataSize)
  630. {
  631. SaErrorT error;
  632. struct ckptCheckpointInstance *ckptCheckpointInstance;
  633. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  634. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  635. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  636. (void *)&ckptCheckpointInstance);
  637. if (error != SA_OK) {
  638. return (error);
  639. }
  640. req_lib_ckpt_sectioncreate.header.magic = MESSAGE_MAGIC;
  641. req_lib_ckpt_sectioncreate.header.size =
  642. sizeof (struct req_lib_ckpt_sectioncreate) +
  643. sectionCreationAttributes->sectionId->idLen +
  644. initialDataSize;
  645. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  646. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  647. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  648. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  649. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  650. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
  651. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  652. if (error != SA_OK) {
  653. goto error_exit;
  654. }
  655. /*
  656. * Write section identifier to server
  657. */
  658. error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
  659. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  660. if (error != SA_OK) {
  661. goto error_exit;
  662. }
  663. error = saSendRetry (ckptCheckpointInstance->fd, initialData,
  664. initialDataSize, MSG_NOSIGNAL);
  665. if (error != SA_OK) {
  666. goto error_exit;
  667. }
  668. error = saRecvRetry (ckptCheckpointInstance->fd,
  669. &res_lib_ckpt_sectioncreate,
  670. sizeof (struct res_lib_ckpt_sectioncreate),
  671. MSG_WAITALL | MSG_NOSIGNAL);
  672. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  673. error_exit:
  674. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  675. return (error == SA_OK ? res_lib_ckpt_sectioncreate.error : error);
  676. }
  677. SaErrorT
  678. saCkptSectionDelete (
  679. const SaCkptCheckpointHandleT *checkpointHandle,
  680. const SaCkptSectionIdT *sectionId)
  681. {
  682. SaErrorT error;
  683. struct ckptCheckpointInstance *ckptCheckpointInstance;
  684. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  685. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  686. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  687. (void *)&ckptCheckpointInstance);
  688. if (error != SA_OK) {
  689. return (error);
  690. }
  691. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  692. req_lib_ckpt_sectiondelete.header.magic = MESSAGE_MAGIC;
  693. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  694. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  695. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  696. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
  697. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  698. if (error != SA_OK) {
  699. goto error_exit;
  700. }
  701. /*
  702. * Write section identifier to server
  703. */
  704. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  705. sectionId->idLen, MSG_NOSIGNAL);
  706. if (error != SA_OK) {
  707. goto error_exit;
  708. }
  709. error = saRecvRetry (ckptCheckpointInstance->fd,
  710. &res_lib_ckpt_sectiondelete,
  711. sizeof (struct res_lib_ckpt_sectiondelete),
  712. MSG_WAITALL | MSG_NOSIGNAL);
  713. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  714. error_exit:
  715. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  716. return (error == SA_OK ? res_lib_ckpt_sectiondelete.error : error);
  717. }
  718. SaErrorT
  719. saCkptSectionExpirationTimeSet (
  720. const SaCkptCheckpointHandleT *checkpointHandle,
  721. const SaCkptSectionIdT *sectionId,
  722. SaTimeT expirationTime)
  723. {
  724. SaErrorT error;
  725. struct ckptCheckpointInstance *ckptCheckpointInstance;
  726. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  727. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  728. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  729. (void *)&ckptCheckpointInstance);
  730. if (error != SA_OK) {
  731. goto error_exit;
  732. }
  733. req_lib_ckpt_sectionexpirationtimeset.header.magic = MESSAGE_MAGIC;
  734. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  735. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  736. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  737. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  738. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  739. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
  740. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  741. if (error != SA_OK) {
  742. goto error_exit;
  743. }
  744. /*
  745. * Write section identifier to server
  746. */
  747. if (sectionId->idLen) {
  748. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  749. sectionId->idLen, MSG_NOSIGNAL);
  750. if (error != SA_OK) {
  751. goto error_exit;
  752. }
  753. }
  754. error = saRecvRetry (ckptCheckpointInstance->fd,
  755. &res_lib_ckpt_sectionexpirationtimeset,
  756. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  757. MSG_WAITALL | MSG_NOSIGNAL);
  758. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  759. error_exit:
  760. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  761. return (error == SA_OK ? res_lib_ckpt_sectionexpirationtimeset.error : error);
  762. }
  763. SaErrorT
  764. saCkptSectionIteratorInitialize (
  765. const SaCkptCheckpointHandleT *checkpointHandle,
  766. SaCkptSectionsChosenT sectionsChosen,
  767. SaTimeT expirationTime,
  768. SaCkptSectionIteratorT *sectionIterator)
  769. {
  770. SaErrorT error;
  771. struct ckptCheckpointInstance *ckptCheckpointInstance;
  772. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  773. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  774. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  775. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  776. (void *)&ckptCheckpointInstance);
  777. if (error != SA_OK) {
  778. goto error_no_destroy;
  779. }
  780. error = saHandleCreate (&ckptSectionIteratorHandleDatabase,
  781. sizeof (struct ckptSectionIteratorInstance), sectionIterator);
  782. if (error != SA_OK) {
  783. goto error_put_checkpoint_db;
  784. }
  785. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  786. *sectionIterator,
  787. (void *)&ckptSectionIteratorInstance);
  788. if (error != SA_OK) {
  789. goto error_destroy;
  790. }
  791. ckptSectionIteratorInstance->fd = -1;
  792. pthread_mutex_init (&ckptSectionIteratorInstance->mutex, NULL);
  793. /*
  794. * Setup section id list for iterator next
  795. */
  796. list_init (&ckptSectionIteratorInstance->sectionIdListHead);
  797. ckptSectionIteratorInstance->maxSectionIdSize =
  798. ckptCheckpointInstance->maxSectionIdSize;
  799. error = saServiceConnect (&ckptSectionIteratorInstance->fd,
  800. MESSAGE_REQ_CKPT_SECTIONITERATOR_INIT);
  801. if (error != SA_OK) {
  802. goto error_put_destroy;
  803. }
  804. req_lib_ckpt_sectioniteratorinitialize.header.magic = MESSAGE_MAGIC;
  805. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  806. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  807. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  808. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  809. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  810. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  811. pthread_mutex_lock (&ckptSectionIteratorInstance->mutex);
  812. error = saSendRetry (ckptSectionIteratorInstance->fd,
  813. &req_lib_ckpt_sectioniteratorinitialize,
  814. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  815. MSG_NOSIGNAL);
  816. if (error != SA_OK) {
  817. goto error_put_destroy;
  818. }
  819. error = saRecvRetry (ckptSectionIteratorInstance->fd,
  820. &res_lib_ckpt_sectioniteratorinitialize,
  821. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  822. MSG_WAITALL | MSG_NOSIGNAL);
  823. pthread_mutex_unlock (&ckptSectionIteratorInstance->mutex);
  824. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  825. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  826. return (error == SA_OK ? res_lib_ckpt_sectioniteratorinitialize.error : error);
  827. error_put_destroy:
  828. saHandleInstancePut (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  829. error_destroy:
  830. saHandleDestroy (&ckptSectionIteratorHandleDatabase, *sectionIterator);
  831. error_put_checkpoint_db:
  832. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  833. error_no_destroy:
  834. return (error);
  835. }
  836. struct iteratorSectionIdListEntry {
  837. struct list_head list;
  838. char data[0];
  839. };
  840. SaErrorT
  841. saCkptSectionIteratorNext (
  842. SaCkptSectionIteratorT *sectionIterator,
  843. SaCkptSectionDescriptorT *sectionDescriptor)
  844. {
  845. SaErrorT error;
  846. struct ckptSectionIteratorInstance *ckptSectionIteratorInstance;
  847. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  848. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  849. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  850. error = saHandleInstanceGet (&ckptSectionIteratorHandleDatabase,
  851. *sectionIterator, (void *)&ckptSectionIteratorInstance);
  852. if (error != SA_OK) {
  853. goto error_exit;
  854. }
  855. /*
  856. * Allocate section id storage area
  857. */
  858. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  859. ckptSectionIteratorInstance->maxSectionIdSize);
  860. if (iteratorSectionIdListEntry == 0) {
  861. error = SA_ERR_NO_MEMORY;
  862. goto error_put_nounlock;
  863. }
  864. req_lib_ckpt_sectioniteratornext.header.magic = MESSAGE_MAGIC;
  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.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.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.magic = MESSAGE_MAGIC;
  956. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  957. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  958. for (i = 0; i < numberOfElements; i++) {
  959. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  960. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  961. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  962. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  963. iov_len = 0;
  964. /* TODO check for zero length stuff */
  965. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  966. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  967. iov[1].iov_base = ioVector[i].sectionId.id;
  968. iov[1].iov_len = ioVector[i].sectionId.idLen;
  969. iov[2].iov_base = ioVector[i].dataBuffer;
  970. iov[2].iov_len = ioVector[i].dataSize;
  971. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  972. iov,
  973. 3);
  974. if (error != SA_OK) {
  975. goto error_exit;
  976. }
  977. /*
  978. * Receive response
  979. */
  980. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
  981. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  982. if (error != SA_OK) {
  983. goto error_exit;
  984. }
  985. /*
  986. * If error, report back erroneous index
  987. */
  988. if (res_lib_ckpt_sectionwrite.error != SA_OK) {
  989. if (erroneousVectorIndex) {
  990. *erroneousVectorIndex = i;
  991. }
  992. goto error_exit;
  993. }
  994. }
  995. error_exit:
  996. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  997. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  998. return (error == SA_OK ? res_lib_ckpt_sectionwrite.error : error);
  999. }
  1000. SaErrorT
  1001. saCkptSectionOverwrite (
  1002. const SaCkptCheckpointHandleT *checkpointHandle,
  1003. const SaCkptSectionIdT *sectionId,
  1004. SaUint8T *dataBuffer,
  1005. SaSizeT dataSize)
  1006. {
  1007. SaErrorT error;
  1008. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1009. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1010. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1011. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1012. (void *)&ckptCheckpointInstance);
  1013. if (error != SA_OK) {
  1014. return (error);
  1015. }
  1016. req_lib_ckpt_sectionoverwrite.header.magic = MESSAGE_MAGIC;
  1017. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1018. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1019. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1020. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1021. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1022. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
  1023. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1024. if (error != SA_OK) {
  1025. goto error_exit;
  1026. }
  1027. if (sectionId->idLen) {
  1028. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  1029. sectionId->idLen, MSG_NOSIGNAL);
  1030. if (error != SA_OK) {
  1031. goto error_exit;
  1032. }
  1033. }
  1034. error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1035. if (error != SA_OK) {
  1036. goto error_exit;
  1037. }
  1038. error = saRecvRetry (ckptCheckpointInstance->fd,
  1039. &res_lib_ckpt_sectionoverwrite,
  1040. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1041. MSG_WAITALL | MSG_NOSIGNAL);
  1042. error_exit:
  1043. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1044. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1045. return (error == SA_OK ? res_lib_ckpt_sectionoverwrite.error : error);
  1046. }
  1047. SaErrorT
  1048. saCkptCheckpointRead (
  1049. const SaCkptCheckpointHandleT *checkpointHandle,
  1050. SaCkptIOVectorElementT *ioVector,
  1051. SaUint32T numberOfElements,
  1052. SaUint32T *erroneousVectorIndex)
  1053. {
  1054. SaErrorT error = SA_OK;
  1055. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1056. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1057. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1058. int dataLength;
  1059. int i;
  1060. struct iovec iov[3];
  1061. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1062. (void *)&ckptCheckpointInstance);
  1063. if (error != SA_OK) {
  1064. return (error);
  1065. }
  1066. req_lib_ckpt_sectionread.header.magic = MESSAGE_MAGIC;
  1067. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1068. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1069. for (i = 0; i < numberOfElements; i++) {
  1070. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1071. ioVector[i].sectionId.idLen;
  1072. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1073. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1074. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1075. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1076. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1077. iov[1].iov_base = ioVector[i].sectionId.id;
  1078. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1079. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  1080. iov,
  1081. 2);
  1082. /*
  1083. * Receive response header
  1084. */
  1085. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionread,
  1086. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1087. if (error != SA_OK) {
  1088. goto error_exit;
  1089. }
  1090. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1091. /*
  1092. * Receive checkpoint section data
  1093. */
  1094. if (dataLength > 0) {
  1095. error = saRecvRetry (ckptCheckpointInstance->fd, ioVector[i].dataBuffer,
  1096. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1097. if (error != SA_OK) {
  1098. goto error_exit;
  1099. }
  1100. }
  1101. if (res_lib_ckpt_sectionread.error != SA_OK) {
  1102. if (erroneousVectorIndex) {
  1103. *erroneousVectorIndex = i;
  1104. }
  1105. goto error_exit;
  1106. }
  1107. /*
  1108. * Report back bytes of data read
  1109. */
  1110. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1111. }
  1112. error_exit:
  1113. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1114. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1115. return (error == SA_OK ? res_lib_ckpt_sectionread.error : error);
  1116. }
  1117. SaErrorT
  1118. saCkptCheckpointSynchronize (
  1119. const SaCkptCheckpointHandleT *checkpointHandle,
  1120. SaTimeT timeout)
  1121. {
  1122. SaErrorT error;
  1123. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1124. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1125. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1126. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  1127. (void *)&ckptCheckpointInstance);
  1128. if (error != SA_OK) {
  1129. return (error);
  1130. }
  1131. req_lib_ckpt_checkpointsynchronize.header.magic = MESSAGE_MAGIC;
  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.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.magic = MESSAGE_MAGIC;
  1167. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1168. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1169. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1170. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1171. pthread_mutex_lock (&ckptInstance->mutex);
  1172. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1173. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1174. pthread_mutex_unlock (&ckptInstance->mutex);
  1175. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1176. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1177. return (error);
  1178. */
  1179. }