ckpt.c 58 KB

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