ckpt.c 57 KB

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