ckpt.c 57 KB

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