ckpt.c 59 KB

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