ckpt.c 57 KB

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