ckpt.c 56 KB

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