ckpt.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  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), MSG_WAITALL | MSG_NOSIGNAL);
  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. MSG_WAITALL | MSG_NOSIGNAL);
  337. if (error != SA_AIS_OK) {
  338. goto error_unlock;
  339. }
  340. }
  341. /*
  342. * Make copy of callbacks, message data, unlock instance,
  343. * and call callback. A risk of this dispatch method is that
  344. * the callback routines may operate at the same time that
  345. * CkptFinalize has been called in another thread.
  346. */
  347. memcpy(&callbacks,&ckptInstance->callbacks, sizeof(ckptInstance->callbacks));
  348. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  349. /*
  350. * Dispatch incoming response
  351. */
  352. switch (dispatch_data.header.id) {
  353. case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC:
  354. if (callbacks.saCkptCheckpointOpenCallback == NULL) {
  355. continue;
  356. }
  357. res_lib_ckpt_checkpointopenasync = (struct res_lib_ckpt_checkpointopenasync *) &dispatch_data;
  358. /*
  359. * This instance get/listadd/put required so that close
  360. * later has the proper list of checkpoints
  361. */
  362. if (res_lib_ckpt_checkpointopenasync->header.error == SA_AIS_OK) {
  363. error = saHandleInstanceGet (&checkpointHandleDatabase,
  364. res_lib_ckpt_checkpointopenasync->checkpointHandle,
  365. (void *)&ckptCheckpointInstance);
  366. assert (error == SA_AIS_OK); /* should only be valid handles here */
  367. /*
  368. * open succeeded without error
  369. */
  370. list_init (&ckptCheckpointInstance->list);
  371. list_init (&ckptCheckpointInstance->section_iteration_list_head);
  372. list_add (&ckptCheckpointInstance->list,
  373. &ckptInstance->checkpoint_list);
  374. callbacks.saCkptCheckpointOpenCallback(
  375. res_lib_ckpt_checkpointopenasync->invocation,
  376. res_lib_ckpt_checkpointopenasync->checkpointHandle,
  377. res_lib_ckpt_checkpointopenasync->header.error);
  378. saHandleInstancePut (&checkpointHandleDatabase,
  379. res_lib_ckpt_checkpointopenasync->checkpointHandle);
  380. } else {
  381. /*
  382. * open failed with error
  383. */
  384. callbacks.saCkptCheckpointOpenCallback(
  385. res_lib_ckpt_checkpointopenasync->invocation,
  386. -1,
  387. res_lib_ckpt_checkpointopenasync->header.error);
  388. }
  389. break;
  390. case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC:
  391. if (callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  392. continue;
  393. }
  394. res_lib_ckpt_checkpointsynchronizeasync = (struct res_lib_ckpt_checkpointsynchronizeasync *) &dispatch_data;
  395. callbacks.saCkptCheckpointSynchronizeCallback(
  396. res_lib_ckpt_checkpointsynchronizeasync->invocation,
  397. res_lib_ckpt_checkpointsynchronizeasync->header.error);
  398. break;
  399. default:
  400. /* TODO */
  401. break;
  402. }
  403. /*
  404. * Determine if more messages should be processed
  405. */
  406. switch (dispatchFlags) {
  407. case SA_DISPATCH_ONE:
  408. cont = 0;
  409. break;
  410. case SA_DISPATCH_ALL:
  411. break;
  412. case SA_DISPATCH_BLOCKING:
  413. break;
  414. }
  415. } while (cont);
  416. error_unlock:
  417. pthread_mutex_unlock(&ckptInstance->dispatch_mutex);
  418. error_put:
  419. saHandleInstancePut(&ckptHandleDatabase, ckptHandle);
  420. error_exit:
  421. return (error);
  422. }
  423. SaAisErrorT
  424. saCkptFinalize (
  425. const SaCkptHandleT ckptHandle)
  426. {
  427. struct ckptInstance *ckptInstance;
  428. SaAisErrorT error;
  429. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  430. (void *)&ckptInstance);
  431. if (error != SA_AIS_OK) {
  432. return (error);
  433. }
  434. pthread_mutex_lock (&ckptInstance->response_mutex);
  435. /*
  436. * Another thread has already started finalizing
  437. */
  438. if (ckptInstance->finalize) {
  439. pthread_mutex_unlock (&ckptInstance->response_mutex);
  440. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  441. return (SA_AIS_ERR_BAD_HANDLE);
  442. }
  443. ckptInstance->finalize = 1;
  444. pthread_mutex_unlock (&ckptInstance->response_mutex);
  445. ckptInstanceFinalize (ckptInstance);
  446. if (ckptInstance->response_fd != -1) {
  447. shutdown (ckptInstance->response_fd, 0);
  448. close (ckptInstance->response_fd);
  449. }
  450. if (ckptInstance->dispatch_fd != -1) {
  451. shutdown (ckptInstance->dispatch_fd, 0);
  452. close (ckptInstance->dispatch_fd);
  453. }
  454. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  455. return (SA_AIS_OK);
  456. }
  457. SaAisErrorT
  458. saCkptCheckpointOpen (
  459. SaCkptHandleT ckptHandle,
  460. const SaNameT *checkpointName,
  461. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  462. SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
  463. SaTimeT timeout,
  464. SaCkptCheckpointHandleT *checkpointHandle)
  465. {
  466. SaAisErrorT error;
  467. struct ckptCheckpointInstance *ckptCheckpointInstance;
  468. struct ckptInstance *ckptInstance;
  469. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  470. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  471. if (checkpointHandle == NULL) {
  472. return (SA_AIS_ERR_INVALID_PARAM);
  473. }
  474. if (checkpointName == NULL) {
  475. return (SA_AIS_ERR_INVALID_PARAM);
  476. }
  477. if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) &&
  478. checkpointCreationAttributes == NULL) {
  479. return (SA_AIS_ERR_INVALID_PARAM);
  480. }
  481. if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) &&
  482. checkpointCreationAttributes != NULL) {
  483. return (SA_AIS_ERR_INVALID_PARAM);
  484. }
  485. if (checkpointCreationAttributes &&
  486. (checkpointCreationAttributes->checkpointSize >
  487. (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) {
  488. return (SA_AIS_ERR_INVALID_PARAM);
  489. }
  490. if (checkpointOpenFlags & ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) {
  491. return (SA_AIS_ERR_BAD_FLAGS);
  492. }
  493. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  494. (void *)&ckptInstance);
  495. if (error != SA_AIS_OK) {
  496. goto error_exit;
  497. }
  498. error = saHandleCreate (&checkpointHandleDatabase,
  499. sizeof (struct ckptCheckpointInstance), checkpointHandle);
  500. if (error != SA_AIS_OK) {
  501. goto error_put_ckpt;
  502. }
  503. error = saHandleInstanceGet (&checkpointHandleDatabase,
  504. *checkpointHandle, (void *)&ckptCheckpointInstance);
  505. if (error != SA_AIS_OK) {
  506. goto error_destroy;
  507. }
  508. ckptCheckpointInstance->response_fd = ckptInstance->response_fd;
  509. ckptCheckpointInstance->ckptHandle = ckptHandle;
  510. ckptCheckpointInstance->checkpointHandle = *checkpointHandle;
  511. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  512. list_init (&ckptCheckpointInstance->section_iteration_list_head);
  513. req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
  514. req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  515. memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
  516. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
  517. req_lib_ckpt_checkpointopen.checkpointCreationAttributesSet = 0;
  518. if (checkpointCreationAttributes) {
  519. memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
  520. checkpointCreationAttributes,
  521. sizeof (SaCkptCheckpointCreationAttributesT));
  522. req_lib_ckpt_checkpointopen.checkpointCreationAttributesSet = 1;
  523. }
  524. req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
  525. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointopen,
  526. sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
  527. if (error != SA_AIS_OK) {
  528. goto error_put_destroy;
  529. }
  530. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointopen,
  531. sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
  532. if (error != SA_AIS_OK) {
  533. goto error_put_destroy;
  534. }
  535. if (res_lib_ckpt_checkpointopen.header.error != SA_AIS_OK) {
  536. error = res_lib_ckpt_checkpointopen.header.error;
  537. goto error_put_destroy;
  538. }
  539. pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL);
  540. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  541. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  542. list_init (&ckptCheckpointInstance->list);
  543. list_add (&ckptCheckpointInstance->list, &ckptInstance->checkpoint_list);
  544. return (error);
  545. error_put_destroy:
  546. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  547. error_destroy:
  548. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  549. error_put_ckpt:
  550. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  551. error_exit:
  552. return (error);
  553. }
  554. SaAisErrorT
  555. saCkptCheckpointOpenAsync (
  556. const SaCkptHandleT ckptHandle,
  557. SaInvocationT invocation,
  558. const SaNameT *checkpointName,
  559. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  560. SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
  561. {
  562. struct ckptCheckpointInstance *ckptCheckpointInstance;
  563. struct ckptInstance *ckptInstance;
  564. SaCkptCheckpointHandleT checkpointHandle;
  565. SaAisErrorT error;
  566. struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
  567. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  568. SaAisErrorT failWithError = SA_AIS_OK;
  569. if (checkpointName == NULL) {
  570. failWithError = SA_AIS_ERR_INVALID_PARAM;
  571. } else
  572. if (checkpointOpenFlags &
  573. ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) {
  574. failWithError = SA_AIS_ERR_BAD_FLAGS;
  575. } else
  576. if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) &&
  577. checkpointCreationAttributes == NULL) {
  578. failWithError = SA_AIS_ERR_INVALID_PARAM;
  579. } else
  580. if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) &&
  581. checkpointCreationAttributes != NULL) {
  582. failWithError = SA_AIS_ERR_INVALID_PARAM;
  583. } else
  584. if (checkpointCreationAttributes &&
  585. (checkpointCreationAttributes->checkpointSize >
  586. (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) {
  587. failWithError = SA_AIS_ERR_INVALID_PARAM;
  588. }
  589. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  590. (void *)&ckptInstance);
  591. if (error != SA_AIS_OK) {
  592. goto error_exit;
  593. }
  594. if (ckptInstance->callbacks.saCkptCheckpointOpenCallback == NULL) {
  595. error = SA_AIS_ERR_INIT;
  596. goto error_put_ckpt;
  597. }
  598. error = saHandleCreate (&checkpointHandleDatabase,
  599. sizeof (struct ckptCheckpointInstance), &checkpointHandle);
  600. if (error != SA_AIS_OK) {
  601. goto error_put_ckpt;
  602. }
  603. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  604. (void *)&ckptCheckpointInstance);
  605. if (error != SA_AIS_OK) {
  606. goto error_destroy;
  607. }
  608. ckptCheckpointInstance->response_fd = ckptInstance->response_fd;
  609. ckptCheckpointInstance->ckptHandle = ckptHandle;
  610. ckptCheckpointInstance->checkpointHandle = checkpointHandle;
  611. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  612. if (failWithError == SA_AIS_OK) {
  613. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName,
  614. sizeof (SaNameT));
  615. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName,
  616. checkpointName, sizeof (SaNameT));
  617. }
  618. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  619. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  620. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  621. req_lib_ckpt_checkpointopenasync.fail_with_error = failWithError;
  622. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 0;
  623. if (checkpointCreationAttributes) {
  624. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  625. checkpointCreationAttributes,
  626. sizeof (SaCkptCheckpointCreationAttributesT));
  627. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 1;
  628. }
  629. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  630. req_lib_ckpt_checkpointopenasync.checkpointHandle = checkpointHandle;
  631. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointopenasync,
  632. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  633. if (error != SA_AIS_OK) {
  634. goto error_put_destroy;
  635. }
  636. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  637. &res_lib_ckpt_checkpointopenasync,
  638. sizeof (struct res_lib_ckpt_checkpointopenasync),
  639. MSG_WAITALL | MSG_NOSIGNAL);
  640. if (error != SA_AIS_OK) {
  641. goto error_put_destroy;
  642. }
  643. if (res_lib_ckpt_checkpointopenasync.header.error != SA_AIS_OK) {
  644. error = res_lib_ckpt_checkpointopenasync.header.error;
  645. goto error_put_destroy;
  646. }
  647. pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL);
  648. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  649. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  650. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointopenasync.header.error : error);
  651. error_put_destroy:
  652. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  653. error_destroy:
  654. saHandleDestroy (&checkpointHandleDatabase, checkpointHandle);
  655. error_put_ckpt:
  656. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  657. error_exit:
  658. return (error);
  659. }
  660. SaAisErrorT
  661. saCkptCheckpointClose (
  662. SaCkptCheckpointHandleT checkpointHandle)
  663. {
  664. struct req_lib_ckpt_checkpointclose req_lib_ckpt_checkpointclose;
  665. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  666. SaAisErrorT error;
  667. struct ckptCheckpointInstance *ckptCheckpointInstance;
  668. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  669. (void *)&ckptCheckpointInstance);
  670. if (error != SA_AIS_OK) {
  671. goto error_exit;
  672. }
  673. req_lib_ckpt_checkpointclose.header.size = sizeof (struct req_lib_ckpt_checkpointclose);
  674. req_lib_ckpt_checkpointclose.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  675. memcpy (&req_lib_ckpt_checkpointclose.checkpointName,
  676. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  677. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointclose,
  678. sizeof (struct req_lib_ckpt_checkpointclose), MSG_NOSIGNAL);
  679. if (error != SA_AIS_OK) {
  680. goto exit_put;
  681. }
  682. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointclose,
  683. sizeof (struct res_lib_ckpt_checkpointclose), MSG_WAITALL | MSG_NOSIGNAL);
  684. if (error == SA_AIS_OK) {
  685. error = res_lib_ckpt_checkpointclose.header.error;
  686. }
  687. if (error == SA_AIS_OK) {
  688. ckptCheckpointInstanceFinalize (ckptCheckpointInstance);
  689. }
  690. exit_put:
  691. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  692. error_exit:
  693. return (error);
  694. }
  695. SaAisErrorT
  696. saCkptCheckpointUnlink (
  697. SaCkptHandleT ckptHandle,
  698. const SaNameT *checkpointName)
  699. {
  700. SaAisErrorT error;
  701. struct ckptInstance *ckptInstance;
  702. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  703. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  704. if (checkpointName == NULL) {
  705. return (SA_AIS_ERR_INVALID_PARAM);
  706. }
  707. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  708. if (error != SA_AIS_OK) {
  709. goto exit_noclose;
  710. }
  711. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  712. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  713. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  714. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointunlink,
  715. sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  716. if (error != SA_AIS_OK) {
  717. goto exit_put;
  718. }
  719. error = saRecvRetry (ckptInstance->response_fd, &res_lib_ckpt_checkpointunlink,
  720. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  721. exit_put:
  722. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  723. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  724. exit_noclose:
  725. return (error);
  726. }
  727. SaAisErrorT
  728. saCkptCheckpointRetentionDurationSet (
  729. SaCkptCheckpointHandleT checkpointHandle,
  730. SaTimeT retentionDuration)
  731. {
  732. SaAisErrorT error;
  733. struct ckptCheckpointInstance *ckptCheckpointInstance;
  734. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  735. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  736. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  737. (void *)&ckptCheckpointInstance);
  738. if (error != SA_AIS_OK) {
  739. goto error_exit_noput;
  740. }
  741. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  742. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  743. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  744. memcpy (&req_lib_ckpt_checkpointretentiondurationset.checkpointName,
  745. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  746. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  747. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  748. if (error != SA_AIS_OK) {
  749. goto error_exit;
  750. }
  751. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  752. &res_lib_ckpt_checkpointretentiondurationset,
  753. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  754. MSG_WAITALL | MSG_NOSIGNAL);
  755. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  756. error_exit:
  757. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  758. error_exit_noput:
  759. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  760. }
  761. SaAisErrorT
  762. saCkptActiveReplicaSet (
  763. SaCkptCheckpointHandleT checkpointHandle)
  764. {
  765. SaAisErrorT error;
  766. struct ckptCheckpointInstance *ckptCheckpointInstance;
  767. struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset;
  768. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  769. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  770. (void *)&ckptCheckpointInstance);
  771. if (error != SA_AIS_OK) {
  772. goto error_noput;
  773. }
  774. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  775. error = SA_AIS_ERR_ACCESS;
  776. goto error_put;
  777. }
  778. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  779. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_ACTIVEREPLICASET;
  780. memcpy (&req_lib_ckpt_activereplicaset.checkpointName,
  781. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  782. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  783. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset,
  784. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  785. if (error != SA_AIS_OK) {
  786. goto error_put;
  787. }
  788. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  789. &res_lib_ckpt_activereplicaset,
  790. sizeof (struct res_lib_ckpt_activereplicaset),
  791. MSG_WAITALL | MSG_NOSIGNAL);
  792. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  793. error_put:
  794. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  795. error_noput:
  796. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  797. }
  798. SaAisErrorT
  799. saCkptCheckpointStatusGet (
  800. SaCkptCheckpointHandleT checkpointHandle,
  801. SaCkptCheckpointDescriptorT *checkpointStatus)
  802. {
  803. SaAisErrorT error;
  804. struct ckptCheckpointInstance *ckptCheckpointInstance;
  805. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  806. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  807. if (checkpointStatus == NULL) {
  808. return (SA_AIS_ERR_INVALID_PARAM);
  809. }
  810. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  811. (void *)&ckptCheckpointInstance);
  812. if (error != SA_AIS_OK) {
  813. return (error);
  814. }
  815. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  816. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  817. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  818. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  819. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  820. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget,
  821. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  822. if (error != SA_AIS_OK) {
  823. goto error_exit;
  824. }
  825. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  826. &res_lib_ckpt_checkpointstatusget,
  827. sizeof (struct res_lib_ckpt_checkpointstatusget),
  828. MSG_WAITALL | MSG_NOSIGNAL);
  829. if (error != SA_AIS_OK) {
  830. goto error_exit;
  831. }
  832. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  833. memcpy (checkpointStatus,
  834. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  835. sizeof (SaCkptCheckpointDescriptorT));
  836. error_exit:
  837. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  838. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointstatusget.header.error : error);
  839. }
  840. SaAisErrorT
  841. saCkptSectionCreate (
  842. SaCkptCheckpointHandleT checkpointHandle,
  843. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  844. const void *initialData,
  845. SaUint32T initialDataSize)
  846. {
  847. SaAisErrorT error;
  848. struct ckptCheckpointInstance *ckptCheckpointInstance;
  849. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  850. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  851. if (sectionCreationAttributes == NULL) {
  852. return (SA_AIS_ERR_INVALID_PARAM);
  853. }
  854. if (initialData == NULL) {
  855. return (SA_AIS_ERR_INVALID_PARAM);
  856. }
  857. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  858. (void *)&ckptCheckpointInstance);
  859. if (error != SA_AIS_OK) {
  860. return (error);
  861. }
  862. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  863. error = SA_AIS_ERR_ACCESS;
  864. goto error_exit;
  865. }
  866. req_lib_ckpt_sectioncreate.header.size =
  867. sizeof (struct req_lib_ckpt_sectioncreate) +
  868. sectionCreationAttributes->sectionId->idLen +
  869. initialDataSize;
  870. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  871. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  872. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  873. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  874. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  875. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  876. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  877. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate,
  878. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  879. if (error != SA_AIS_OK) {
  880. goto error_exit;
  881. }
  882. /*
  883. * Write section identifier to server
  884. */
  885. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id,
  886. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  887. if (error != SA_AIS_OK) {
  888. goto error_exit;
  889. }
  890. error = saSendRetry (ckptCheckpointInstance->response_fd, initialData,
  891. initialDataSize, MSG_NOSIGNAL);
  892. if (error != SA_AIS_OK) {
  893. goto error_exit;
  894. }
  895. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  896. &res_lib_ckpt_sectioncreate,
  897. sizeof (struct res_lib_ckpt_sectioncreate),
  898. MSG_WAITALL | MSG_NOSIGNAL);
  899. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  900. error_exit:
  901. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  902. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  903. }
  904. SaAisErrorT
  905. saCkptSectionDelete (
  906. SaCkptCheckpointHandleT checkpointHandle,
  907. const SaCkptSectionIdT *sectionId)
  908. {
  909. SaAisErrorT error;
  910. struct ckptCheckpointInstance *ckptCheckpointInstance;
  911. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  912. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  913. if (sectionId == NULL) {
  914. return (SA_AIS_ERR_INVALID_PARAM);
  915. }
  916. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  917. (void *)&ckptCheckpointInstance);
  918. if (error != SA_AIS_OK) {
  919. return (error);
  920. }
  921. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  922. error = SA_AIS_ERR_ACCESS;
  923. goto error_put;
  924. }
  925. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  926. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  927. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  928. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  929. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  930. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  931. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete,
  932. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  933. if (error != SA_AIS_OK) {
  934. goto error_exit;
  935. }
  936. /*
  937. * Write section identifier to server
  938. */
  939. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  940. sectionId->idLen, MSG_NOSIGNAL);
  941. if (error != SA_AIS_OK) {
  942. goto error_exit;
  943. }
  944. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  945. &res_lib_ckpt_sectiondelete,
  946. sizeof (struct res_lib_ckpt_sectiondelete),
  947. MSG_WAITALL | MSG_NOSIGNAL);
  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), MSG_NOSIGNAL);
  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, MSG_NOSIGNAL);
  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. MSG_WAITALL | MSG_NOSIGNAL);
  1002. error_exit:
  1003. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1004. error_put:
  1005. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1006. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  1007. }
  1008. SaAisErrorT
  1009. saCkptSectionIterationInitialize (
  1010. SaCkptCheckpointHandleT checkpointHandle,
  1011. SaCkptSectionsChosenT sectionsChosen,
  1012. SaTimeT expirationTime,
  1013. SaCkptSectionIterationHandleT *sectionIterationHandle)
  1014. {
  1015. SaAisErrorT error;
  1016. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1017. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1018. struct req_lib_ckpt_sectioniterationinitialize req_lib_ckpt_sectioniterationinitialize;
  1019. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  1020. if (sectionIterationHandle == NULL) {
  1021. return (SA_AIS_ERR_INVALID_PARAM);
  1022. }
  1023. if (sectionsChosen != SA_CKPT_SECTIONS_FOREVER &&
  1024. sectionsChosen != SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME &&
  1025. sectionsChosen != SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME &&
  1026. sectionsChosen != SA_CKPT_SECTIONS_CORRUPTED &&
  1027. sectionsChosen != SA_CKPT_SECTIONS_ANY) {
  1028. return (SA_AIS_ERR_INVALID_PARAM);
  1029. }
  1030. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1031. (void *)&ckptCheckpointInstance);
  1032. if (error != SA_AIS_OK) {
  1033. goto error_no_destroy;
  1034. }
  1035. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  1036. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  1037. if (error != SA_AIS_OK) {
  1038. goto error_put_checkpoint_db;
  1039. }
  1040. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1041. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1042. if (error != SA_AIS_OK) {
  1043. goto error_destroy;
  1044. }
  1045. ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd;
  1046. ckptSectionIterationInstance->sectionIterationHandle = *sectionIterationHandle;
  1047. memcpy (&ckptSectionIterationInstance->checkpointName,
  1048. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1049. list_init (&ckptSectionIterationInstance->list);
  1050. list_add (&ckptSectionIterationInstance->list,
  1051. &ckptCheckpointInstance->section_iteration_list_head);
  1052. pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL);
  1053. /*
  1054. * Setup section id list for iterator next
  1055. */
  1056. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  1057. req_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniterationinitialize);
  1058. req_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1059. req_lib_ckpt_sectioniterationinitialize.sectionsChosen = sectionsChosen;
  1060. req_lib_ckpt_sectioniterationinitialize.expirationTime = expirationTime;
  1061. memcpy (&req_lib_ckpt_sectioniterationinitialize.checkpointName,
  1062. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1063. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1064. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1065. &req_lib_ckpt_sectioniterationinitialize,
  1066. sizeof (struct req_lib_ckpt_sectioniterationinitialize),
  1067. MSG_NOSIGNAL);
  1068. if (error != SA_AIS_OK) {
  1069. goto error_put_destroy;
  1070. }
  1071. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1072. &res_lib_ckpt_sectioniterationinitialize,
  1073. sizeof (struct res_lib_ckpt_sectioniterationinitialize),
  1074. MSG_WAITALL | MSG_NOSIGNAL);
  1075. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1076. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1077. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationinitialize.header.error : error);
  1078. error_put_destroy:
  1079. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1080. error_destroy:
  1081. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1082. error_put_checkpoint_db:
  1083. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1084. error_no_destroy:
  1085. return (error);
  1086. }
  1087. SaAisErrorT
  1088. saCkptSectionIterationNext (
  1089. SaCkptSectionIterationHandleT sectionIterationHandle,
  1090. SaCkptSectionDescriptorT *sectionDescriptor)
  1091. {
  1092. SaAisErrorT error;
  1093. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1094. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  1095. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1096. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  1097. if (sectionDescriptor == NULL) {
  1098. return (SA_AIS_ERR_INVALID_PARAM);
  1099. }
  1100. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1101. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1102. if (error != SA_AIS_OK) {
  1103. goto error_exit;
  1104. }
  1105. /*
  1106. * Allocate section id storage area
  1107. */
  1108. /*
  1109. * TODO max section id size is 500
  1110. */
  1111. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) + 500);
  1112. if (iteratorSectionIdListEntry == 0) {
  1113. error = SA_AIS_ERR_NO_MEMORY;
  1114. goto error_put_nounlock;
  1115. }
  1116. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  1117. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1118. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1119. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1120. &req_lib_ckpt_sectioniteratornext,
  1121. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  1122. if (error != SA_AIS_OK) {
  1123. goto error_put_unlock;
  1124. }
  1125. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniteratornext,
  1126. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  1127. if (error != SA_AIS_OK) {
  1128. goto error_put_unlock;
  1129. }
  1130. memcpy (sectionDescriptor,
  1131. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1132. sizeof (SaCkptSectionDescriptorT));
  1133. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  1134. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  1135. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1136. sectionDescriptor->sectionId.id,
  1137. res_lib_ckpt_sectioniteratornext.header.size -
  1138. sizeof (struct res_lib_ckpt_sectioniteratornext),
  1139. MSG_WAITALL | MSG_NOSIGNAL);
  1140. }
  1141. error = (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  1142. /*
  1143. * Add to persistent memory list for this sectioniterator
  1144. */
  1145. if (error == SA_AIS_OK) {
  1146. list_init (&iteratorSectionIdListEntry->list);
  1147. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  1148. }
  1149. error_put_unlock:
  1150. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1151. error_put_nounlock:
  1152. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1153. error_exit:
  1154. if (error != SA_AIS_OK) {
  1155. free (iteratorSectionIdListEntry);
  1156. }
  1157. return (error);
  1158. }
  1159. SaAisErrorT
  1160. saCkptSectionIterationFinalize (
  1161. SaCkptSectionIterationHandleT sectionIterationHandle)
  1162. {
  1163. SaAisErrorT error;
  1164. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1165. struct req_lib_ckpt_sectioniterationfinalize req_lib_ckpt_sectioniterationfinalize;
  1166. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  1167. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1168. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1169. if (error != SA_AIS_OK) {
  1170. goto error_exit;
  1171. }
  1172. req_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct req_lib_ckpt_sectioniterationfinalize);
  1173. req_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  1174. memcpy (&req_lib_ckpt_sectioniterationfinalize.checkpointName,
  1175. &ckptSectionIterationInstance->checkpointName, sizeof (SaNameT));
  1176. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1177. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1178. &req_lib_ckpt_sectioniterationfinalize,
  1179. sizeof (struct req_lib_ckpt_sectioniterationfinalize), MSG_NOSIGNAL);
  1180. if (error != SA_AIS_OK) {
  1181. goto error_put;
  1182. }
  1183. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniterationfinalize,
  1184. sizeof (struct res_lib_ckpt_sectioniterationfinalize), MSG_WAITALL | MSG_NOSIGNAL);
  1185. if (error != SA_AIS_OK) {
  1186. goto error_put;
  1187. }
  1188. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1189. ckptSectionIterationInstanceFinalize (ckptSectionIterationInstance);
  1190. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1191. return (error);
  1192. error_put:
  1193. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1194. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1195. error_exit:
  1196. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationfinalize.header.error : error);
  1197. }
  1198. SaAisErrorT
  1199. saCkptCheckpointWrite (
  1200. SaCkptCheckpointHandleT checkpointHandle,
  1201. const SaCkptIOVectorElementT *ioVector,
  1202. SaUint32T numberOfElements,
  1203. SaUint32T *erroneousVectorIndex)
  1204. {
  1205. SaAisErrorT error = SA_AIS_OK;
  1206. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1207. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  1208. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1209. int i;
  1210. struct iovec iov[3];
  1211. int iov_len = 0;
  1212. if (ioVector == NULL) {
  1213. return (SA_AIS_ERR_INVALID_PARAM);
  1214. }
  1215. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1216. (void *)&ckptCheckpointInstance);
  1217. if (error != SA_AIS_OK) {
  1218. return (error);
  1219. }
  1220. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1221. error = SA_AIS_ERR_ACCESS;
  1222. goto error_put;
  1223. }
  1224. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  1225. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1226. for (i = 0; i < numberOfElements; i++) {
  1227. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  1228. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  1229. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  1230. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  1231. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  1232. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1233. iov_len = 0;
  1234. /* TODO check for zero length stuff */
  1235. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  1236. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  1237. iov[1].iov_base = ioVector[i].sectionId.id;
  1238. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1239. iov[2].iov_base = ioVector[i].dataBuffer;
  1240. iov[2].iov_len = ioVector[i].dataSize;
  1241. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1242. iov,
  1243. 3);
  1244. if (error != SA_AIS_OK) {
  1245. goto error_exit;
  1246. }
  1247. /*
  1248. * Receive response
  1249. */
  1250. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite,
  1251. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1252. if (error != SA_AIS_OK) {
  1253. goto error_exit;
  1254. }
  1255. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1256. error = SA_AIS_ERR_TRY_AGAIN;
  1257. goto error_exit;
  1258. }
  1259. /*
  1260. * If error, report back erroneous index
  1261. */
  1262. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1263. if (erroneousVectorIndex) {
  1264. *erroneousVectorIndex = i;
  1265. }
  1266. goto error_exit;
  1267. }
  1268. }
  1269. error_exit:
  1270. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1271. error_put:
  1272. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1273. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1274. }
  1275. SaAisErrorT
  1276. saCkptSectionOverwrite (
  1277. SaCkptCheckpointHandleT checkpointHandle,
  1278. const SaCkptSectionIdT *sectionId,
  1279. const void *dataBuffer,
  1280. SaSizeT dataSize)
  1281. {
  1282. SaAisErrorT error;
  1283. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1284. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1285. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1286. if (dataBuffer == NULL) {
  1287. return (SA_AIS_ERR_INVALID_PARAM);
  1288. }
  1289. if (sectionId == NULL) {
  1290. return (SA_AIS_ERR_INVALID_PARAM);
  1291. }
  1292. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1293. (void *)&ckptCheckpointInstance);
  1294. if (error != SA_AIS_OK) {
  1295. return (error);
  1296. }
  1297. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1298. return (SA_AIS_ERR_ACCESS);
  1299. }
  1300. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1301. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1302. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1303. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1304. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1305. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1306. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1307. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite,
  1308. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1309. if (error != SA_AIS_OK) {
  1310. goto error_exit;
  1311. }
  1312. if (sectionId->idLen) {
  1313. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  1314. sectionId->idLen, MSG_NOSIGNAL);
  1315. if (error != SA_AIS_OK) {
  1316. goto error_exit;
  1317. }
  1318. }
  1319. error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1320. if (error != SA_AIS_OK) {
  1321. goto error_exit;
  1322. }
  1323. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1324. &res_lib_ckpt_sectionoverwrite,
  1325. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1326. MSG_WAITALL | MSG_NOSIGNAL);
  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), MSG_WAITALL | MSG_NOSIGNAL);
  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, MSG_WAITALL | MSG_NOSIGNAL);
  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), MSG_NOSIGNAL);
  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. MSG_WAITALL | MSG_NOSIGNAL);
  1452. error_exit:
  1453. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1454. error_put:
  1455. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1456. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1457. }
  1458. SaAisErrorT
  1459. saCkptCheckpointSynchronizeAsync (
  1460. SaCkptCheckpointHandleT checkpointHandle,
  1461. SaInvocationT invocation)
  1462. {
  1463. SaAisErrorT error;
  1464. struct ckptInstance *ckptInstance;
  1465. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1466. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1467. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  1468. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1469. (void *)&ckptCheckpointInstance);
  1470. if (error != SA_AIS_OK) {
  1471. return (error);
  1472. }
  1473. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1474. error = SA_AIS_ERR_ACCESS;
  1475. goto error_put;
  1476. }
  1477. error = saHandleInstanceGet (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle,
  1478. (void *)&ckptInstance);
  1479. if (error != SA_AIS_OK) {
  1480. goto error_put;
  1481. }
  1482. if (ckptInstance->callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  1483. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1484. error = SA_AIS_ERR_INIT;
  1485. goto error_put;
  1486. }
  1487. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1488. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1489. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1490. memcpy (&req_lib_ckpt_checkpointsynchronizeasync.checkpointName,
  1491. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1492. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1493. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1494. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1495. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1496. if (error != SA_AIS_OK) {
  1497. goto error_exit;
  1498. }
  1499. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1500. &res_lib_ckpt_checkpointsynchronizeasync,
  1501. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync),
  1502. MSG_WAITALL | MSG_NOSIGNAL);
  1503. error_exit:
  1504. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1505. error_put:
  1506. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1507. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronizeasync.header.error : error);
  1508. return (SA_AIS_OK);
  1509. }