ckpt.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  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. error == SA_AIS_OK ? res_lib_ckpt_checkpointclose.header.error : error;
  685. if (error == SA_AIS_OK) {
  686. ckptCheckpointInstanceFinalize (ckptCheckpointInstance);
  687. }
  688. exit_put:
  689. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  690. error_exit:
  691. return (error);
  692. }
  693. SaAisErrorT
  694. saCkptCheckpointUnlink (
  695. SaCkptHandleT ckptHandle,
  696. const SaNameT *checkpointName)
  697. {
  698. SaAisErrorT error;
  699. struct ckptInstance *ckptInstance;
  700. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  701. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  702. if (checkpointName == NULL) {
  703. return (SA_AIS_ERR_INVALID_PARAM);
  704. }
  705. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  706. if (error != SA_AIS_OK) {
  707. goto exit_noclose;
  708. }
  709. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  710. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  711. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  712. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointunlink,
  713. sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  714. if (error != SA_AIS_OK) {
  715. goto exit_put;
  716. }
  717. error = saRecvRetry (ckptInstance->response_fd, &res_lib_ckpt_checkpointunlink,
  718. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  719. exit_put:
  720. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  721. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  722. exit_noclose:
  723. return (error);
  724. }
  725. SaAisErrorT
  726. saCkptCheckpointRetentionDurationSet (
  727. SaCkptCheckpointHandleT checkpointHandle,
  728. SaTimeT retentionDuration)
  729. {
  730. SaAisErrorT error;
  731. struct ckptCheckpointInstance *ckptCheckpointInstance;
  732. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  733. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  734. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  735. (void *)&ckptCheckpointInstance);
  736. if (error != SA_AIS_OK) {
  737. goto error_exit_noput;
  738. }
  739. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  740. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  741. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  742. memcpy (&req_lib_ckpt_checkpointretentiondurationset.checkpointName,
  743. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  744. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  745. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  746. if (error != SA_AIS_OK) {
  747. goto error_exit;
  748. }
  749. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  750. &res_lib_ckpt_checkpointretentiondurationset,
  751. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  752. MSG_WAITALL | MSG_NOSIGNAL);
  753. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  754. error_exit:
  755. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  756. error_exit_noput:
  757. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  758. }
  759. SaAisErrorT
  760. saCkptActiveReplicaSet (
  761. SaCkptCheckpointHandleT checkpointHandle)
  762. {
  763. SaAisErrorT error;
  764. struct ckptCheckpointInstance *ckptCheckpointInstance;
  765. struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset;
  766. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  767. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  768. (void *)&ckptCheckpointInstance);
  769. if (error != SA_AIS_OK) {
  770. goto error_noput;
  771. }
  772. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  773. error = SA_AIS_ERR_ACCESS;
  774. goto error_put;
  775. }
  776. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  777. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_ACTIVEREPLICASET;
  778. memcpy (&req_lib_ckpt_activereplicaset.checkpointName,
  779. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  780. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  781. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset,
  782. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  783. if (error != SA_AIS_OK) {
  784. goto error_put;
  785. }
  786. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  787. &res_lib_ckpt_activereplicaset,
  788. sizeof (struct res_lib_ckpt_activereplicaset),
  789. MSG_WAITALL | MSG_NOSIGNAL);
  790. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  791. error_put:
  792. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  793. error_noput:
  794. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  795. }
  796. SaAisErrorT
  797. saCkptCheckpointStatusGet (
  798. SaCkptCheckpointHandleT checkpointHandle,
  799. SaCkptCheckpointDescriptorT *checkpointStatus)
  800. {
  801. SaAisErrorT error;
  802. struct ckptCheckpointInstance *ckptCheckpointInstance;
  803. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  804. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  805. if (checkpointStatus == NULL) {
  806. return (SA_AIS_ERR_INVALID_PARAM);
  807. }
  808. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  809. (void *)&ckptCheckpointInstance);
  810. if (error != SA_AIS_OK) {
  811. return (error);
  812. }
  813. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  814. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  815. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  816. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  817. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  818. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget,
  819. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  820. if (error != SA_AIS_OK) {
  821. goto error_exit;
  822. }
  823. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  824. &res_lib_ckpt_checkpointstatusget,
  825. sizeof (struct res_lib_ckpt_checkpointstatusget),
  826. MSG_WAITALL | MSG_NOSIGNAL);
  827. if (error != SA_AIS_OK) {
  828. goto error_exit;
  829. }
  830. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  831. memcpy (checkpointStatus,
  832. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  833. sizeof (SaCkptCheckpointDescriptorT));
  834. error_exit:
  835. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  836. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointstatusget.header.error : error);
  837. }
  838. SaAisErrorT
  839. saCkptSectionCreate (
  840. SaCkptCheckpointHandleT checkpointHandle,
  841. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  842. const void *initialData,
  843. SaUint32T initialDataSize)
  844. {
  845. SaAisErrorT error;
  846. struct ckptCheckpointInstance *ckptCheckpointInstance;
  847. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  848. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  849. if (sectionCreationAttributes == NULL) {
  850. return (SA_AIS_ERR_INVALID_PARAM);
  851. }
  852. if (initialData == NULL) {
  853. return (SA_AIS_ERR_INVALID_PARAM);
  854. }
  855. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  856. (void *)&ckptCheckpointInstance);
  857. if (error != SA_AIS_OK) {
  858. return (error);
  859. }
  860. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  861. error = SA_AIS_ERR_ACCESS;
  862. goto error_exit;
  863. }
  864. req_lib_ckpt_sectioncreate.header.size =
  865. sizeof (struct req_lib_ckpt_sectioncreate) +
  866. sectionCreationAttributes->sectionId->idLen +
  867. initialDataSize;
  868. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  869. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  870. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  871. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  872. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  873. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  874. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  875. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate,
  876. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  877. if (error != SA_AIS_OK) {
  878. goto error_exit;
  879. }
  880. /*
  881. * Write section identifier to server
  882. */
  883. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id,
  884. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  885. if (error != SA_AIS_OK) {
  886. goto error_exit;
  887. }
  888. error = saSendRetry (ckptCheckpointInstance->response_fd, initialData,
  889. initialDataSize, MSG_NOSIGNAL);
  890. if (error != SA_AIS_OK) {
  891. goto error_exit;
  892. }
  893. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  894. &res_lib_ckpt_sectioncreate,
  895. sizeof (struct res_lib_ckpt_sectioncreate),
  896. MSG_WAITALL | MSG_NOSIGNAL);
  897. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  898. error_exit:
  899. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  900. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  901. }
  902. SaAisErrorT
  903. saCkptSectionDelete (
  904. SaCkptCheckpointHandleT checkpointHandle,
  905. const SaCkptSectionIdT *sectionId)
  906. {
  907. SaAisErrorT error;
  908. struct ckptCheckpointInstance *ckptCheckpointInstance;
  909. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  910. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  911. if (sectionId == NULL) {
  912. return (SA_AIS_ERR_INVALID_PARAM);
  913. }
  914. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  915. (void *)&ckptCheckpointInstance);
  916. if (error != SA_AIS_OK) {
  917. return (error);
  918. }
  919. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  920. error = SA_AIS_ERR_ACCESS;
  921. goto error_put;
  922. }
  923. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  924. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  925. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  926. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  927. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  928. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  929. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete,
  930. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  931. if (error != SA_AIS_OK) {
  932. goto error_exit;
  933. }
  934. /*
  935. * Write section identifier to server
  936. */
  937. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  938. sectionId->idLen, MSG_NOSIGNAL);
  939. if (error != SA_AIS_OK) {
  940. goto error_exit;
  941. }
  942. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  943. &res_lib_ckpt_sectiondelete,
  944. sizeof (struct res_lib_ckpt_sectiondelete),
  945. MSG_WAITALL | MSG_NOSIGNAL);
  946. error_exit:
  947. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  948. error_put:
  949. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  950. return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  951. }
  952. SaAisErrorT
  953. saCkptSectionExpirationTimeSet (
  954. SaCkptCheckpointHandleT checkpointHandle,
  955. const SaCkptSectionIdT *sectionId,
  956. SaTimeT expirationTime)
  957. {
  958. SaAisErrorT error;
  959. struct ckptCheckpointInstance *ckptCheckpointInstance;
  960. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  961. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  962. if (sectionId == NULL) {
  963. return (SA_AIS_ERR_INVALID_PARAM);
  964. }
  965. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  966. (void *)&ckptCheckpointInstance);
  967. if (error != SA_AIS_OK) {
  968. return (error);
  969. }
  970. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  971. error = SA_AIS_ERR_ACCESS;
  972. goto error_put;
  973. }
  974. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  975. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  976. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  977. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  978. memcpy (&req_lib_ckpt_sectionexpirationtimeset.checkpointName,
  979. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  980. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  981. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset,
  982. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  983. if (error != SA_AIS_OK) {
  984. goto error_exit;
  985. }
  986. /*
  987. * Write section identifier to server
  988. */
  989. if (sectionId->idLen) {
  990. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  991. sectionId->idLen, MSG_NOSIGNAL);
  992. if (error != SA_AIS_OK) {
  993. goto error_exit;
  994. }
  995. }
  996. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  997. &res_lib_ckpt_sectionexpirationtimeset,
  998. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  999. MSG_WAITALL | MSG_NOSIGNAL);
  1000. error_exit:
  1001. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1002. error_put:
  1003. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1004. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  1005. }
  1006. SaAisErrorT
  1007. saCkptSectionIterationInitialize (
  1008. SaCkptCheckpointHandleT checkpointHandle,
  1009. SaCkptSectionsChosenT sectionsChosen,
  1010. SaTimeT expirationTime,
  1011. SaCkptSectionIterationHandleT *sectionIterationHandle)
  1012. {
  1013. SaAisErrorT error;
  1014. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1015. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1016. struct req_lib_ckpt_sectioniterationinitialize req_lib_ckpt_sectioniterationinitialize;
  1017. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  1018. if (sectionIterationHandle == NULL) {
  1019. return (SA_AIS_ERR_INVALID_PARAM);
  1020. }
  1021. if (sectionsChosen != SA_CKPT_SECTIONS_FOREVER &&
  1022. sectionsChosen != SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME &&
  1023. sectionsChosen != SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME &&
  1024. sectionsChosen != SA_CKPT_SECTIONS_CORRUPTED &&
  1025. sectionsChosen != SA_CKPT_SECTIONS_ANY) {
  1026. return (SA_AIS_ERR_INVALID_PARAM);
  1027. }
  1028. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1029. (void *)&ckptCheckpointInstance);
  1030. if (error != SA_AIS_OK) {
  1031. goto error_no_destroy;
  1032. }
  1033. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  1034. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  1035. if (error != SA_AIS_OK) {
  1036. goto error_put_checkpoint_db;
  1037. }
  1038. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1039. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1040. if (error != SA_AIS_OK) {
  1041. goto error_destroy;
  1042. }
  1043. ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd;
  1044. ckptSectionIterationInstance->sectionIterationHandle = *sectionIterationHandle;
  1045. memcpy (&ckptSectionIterationInstance->checkpointName,
  1046. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1047. list_init (&ckptSectionIterationInstance->list);
  1048. list_add (&ckptSectionIterationInstance->list,
  1049. &ckptCheckpointInstance->section_iteration_list_head);
  1050. pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL);
  1051. /*
  1052. * Setup section id list for iterator next
  1053. */
  1054. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  1055. req_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniterationinitialize);
  1056. req_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1057. req_lib_ckpt_sectioniterationinitialize.sectionsChosen = sectionsChosen;
  1058. req_lib_ckpt_sectioniterationinitialize.expirationTime = expirationTime;
  1059. memcpy (&req_lib_ckpt_sectioniterationinitialize.checkpointName,
  1060. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1061. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1062. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1063. &req_lib_ckpt_sectioniterationinitialize,
  1064. sizeof (struct req_lib_ckpt_sectioniterationinitialize),
  1065. MSG_NOSIGNAL);
  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. MSG_WAITALL | MSG_NOSIGNAL);
  1073. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1074. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1075. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationinitialize.header.error : error);
  1076. error_put_destroy:
  1077. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1078. error_destroy:
  1079. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1080. error_put_checkpoint_db:
  1081. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1082. error_no_destroy:
  1083. return (error);
  1084. }
  1085. SaAisErrorT
  1086. saCkptSectionIterationNext (
  1087. SaCkptSectionIterationHandleT sectionIterationHandle,
  1088. SaCkptSectionDescriptorT *sectionDescriptor)
  1089. {
  1090. SaAisErrorT error;
  1091. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1092. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  1093. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1094. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  1095. if (sectionDescriptor == NULL) {
  1096. return (SA_AIS_ERR_INVALID_PARAM);
  1097. }
  1098. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1099. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1100. if (error != SA_AIS_OK) {
  1101. goto error_exit;
  1102. }
  1103. /*
  1104. * Allocate section id storage area
  1105. */
  1106. /*
  1107. * TODO max section id size is 500
  1108. */
  1109. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) + 500);
  1110. if (iteratorSectionIdListEntry == 0) {
  1111. error = SA_AIS_ERR_NO_MEMORY;
  1112. goto error_put_nounlock;
  1113. }
  1114. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  1115. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1116. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1117. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1118. &req_lib_ckpt_sectioniteratornext,
  1119. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  1120. if (error != SA_AIS_OK) {
  1121. goto error_put;
  1122. }
  1123. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniteratornext,
  1124. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  1125. if (error != SA_AIS_OK) {
  1126. goto error_put;
  1127. }
  1128. memcpy (sectionDescriptor,
  1129. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1130. sizeof (SaCkptSectionDescriptorT));
  1131. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  1132. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  1133. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1134. sectionDescriptor->sectionId.id,
  1135. res_lib_ckpt_sectioniteratornext.header.size -
  1136. sizeof (struct res_lib_ckpt_sectioniteratornext),
  1137. MSG_WAITALL | MSG_NOSIGNAL);
  1138. }
  1139. /*
  1140. * Add to persistent memory list for this sectioniterator
  1141. */
  1142. if (error == SA_AIS_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_AIS_OK) {
  1143. list_init (&iteratorSectionIdListEntry->list);
  1144. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  1145. }
  1146. error_put:
  1147. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1148. error_put_nounlock:
  1149. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1150. error_exit:
  1151. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  1152. }
  1153. SaAisErrorT
  1154. saCkptSectionIterationFinalize (
  1155. SaCkptSectionIterationHandleT sectionIterationHandle)
  1156. {
  1157. SaAisErrorT error;
  1158. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1159. struct req_lib_ckpt_sectioniterationfinalize req_lib_ckpt_sectioniterationfinalize;
  1160. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  1161. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1162. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1163. if (error != SA_AIS_OK) {
  1164. goto error_exit;
  1165. }
  1166. req_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct req_lib_ckpt_sectioniterationfinalize);
  1167. req_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  1168. memcpy (&req_lib_ckpt_sectioniterationfinalize.checkpointName,
  1169. &ckptSectionIterationInstance->checkpointName, sizeof (SaNameT));
  1170. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1171. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1172. &req_lib_ckpt_sectioniterationfinalize,
  1173. sizeof (struct req_lib_ckpt_sectioniterationfinalize), MSG_NOSIGNAL);
  1174. if (error != SA_AIS_OK) {
  1175. goto error_put;
  1176. }
  1177. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniterationfinalize,
  1178. sizeof (struct res_lib_ckpt_sectioniterationfinalize), MSG_WAITALL | MSG_NOSIGNAL);
  1179. if (error != SA_AIS_OK) {
  1180. goto error_put;
  1181. }
  1182. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1183. ckptSectionIterationInstanceFinalize (ckptSectionIterationInstance);
  1184. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1185. return (error);
  1186. error_put:
  1187. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1188. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1189. error_exit:
  1190. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationfinalize.header.error : error);
  1191. }
  1192. SaAisErrorT
  1193. saCkptCheckpointWrite (
  1194. SaCkptCheckpointHandleT checkpointHandle,
  1195. const SaCkptIOVectorElementT *ioVector,
  1196. SaUint32T numberOfElements,
  1197. SaUint32T *erroneousVectorIndex)
  1198. {
  1199. SaAisErrorT error = SA_AIS_OK;
  1200. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1201. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  1202. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1203. int i;
  1204. struct iovec iov[3];
  1205. int iov_len = 0;
  1206. if (ioVector == NULL) {
  1207. return (SA_AIS_ERR_INVALID_PARAM);
  1208. }
  1209. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1210. (void *)&ckptCheckpointInstance);
  1211. if (error != SA_AIS_OK) {
  1212. return (error);
  1213. }
  1214. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1215. error = SA_AIS_ERR_ACCESS;
  1216. goto error_put;
  1217. }
  1218. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  1219. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1220. for (i = 0; i < numberOfElements; i++) {
  1221. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  1222. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  1223. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  1224. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  1225. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  1226. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1227. iov_len = 0;
  1228. /* TODO check for zero length stuff */
  1229. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  1230. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  1231. iov[1].iov_base = ioVector[i].sectionId.id;
  1232. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1233. iov[2].iov_base = ioVector[i].dataBuffer;
  1234. iov[2].iov_len = ioVector[i].dataSize;
  1235. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1236. iov,
  1237. 3);
  1238. if (error != SA_AIS_OK) {
  1239. goto error_exit;
  1240. }
  1241. /*
  1242. * Receive response
  1243. */
  1244. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite,
  1245. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1246. if (error != SA_AIS_OK) {
  1247. goto error_exit;
  1248. }
  1249. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1250. error = SA_AIS_ERR_TRY_AGAIN;
  1251. goto error_exit;
  1252. }
  1253. /*
  1254. * If error, report back erroneous index
  1255. */
  1256. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1257. if (erroneousVectorIndex) {
  1258. *erroneousVectorIndex = i;
  1259. }
  1260. goto error_exit;
  1261. }
  1262. }
  1263. error_exit:
  1264. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1265. error_put:
  1266. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1267. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1268. }
  1269. SaAisErrorT
  1270. saCkptSectionOverwrite (
  1271. SaCkptCheckpointHandleT checkpointHandle,
  1272. const SaCkptSectionIdT *sectionId,
  1273. const void *dataBuffer,
  1274. SaSizeT dataSize)
  1275. {
  1276. SaAisErrorT error;
  1277. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1278. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1279. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1280. if (dataBuffer == NULL) {
  1281. return (SA_ERR_INVALID_PARAM);
  1282. }
  1283. if (sectionId == NULL) {
  1284. return (SA_ERR_INVALID_PARAM);
  1285. }
  1286. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1287. (void *)&ckptCheckpointInstance);
  1288. if (error != SA_AIS_OK) {
  1289. return (error);
  1290. }
  1291. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1292. return (SA_AIS_ERR_ACCESS);
  1293. }
  1294. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1295. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1296. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1297. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1298. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1299. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1300. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1301. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite,
  1302. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1303. if (error != SA_AIS_OK) {
  1304. goto error_exit;
  1305. }
  1306. if (sectionId->idLen) {
  1307. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  1308. sectionId->idLen, MSG_NOSIGNAL);
  1309. if (error != SA_AIS_OK) {
  1310. goto error_exit;
  1311. }
  1312. }
  1313. error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1314. if (error != SA_AIS_OK) {
  1315. goto error_exit;
  1316. }
  1317. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1318. &res_lib_ckpt_sectionoverwrite,
  1319. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1320. MSG_WAITALL | MSG_NOSIGNAL);
  1321. error_exit:
  1322. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1323. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1324. return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1325. }
  1326. SaAisErrorT
  1327. saCkptCheckpointRead (
  1328. SaCkptCheckpointHandleT checkpointHandle,
  1329. SaCkptIOVectorElementT *ioVector,
  1330. SaUint32T numberOfElements,
  1331. SaUint32T *erroneousVectorIndex)
  1332. {
  1333. SaAisErrorT error = SA_AIS_OK;
  1334. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1335. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1336. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1337. int dataLength;
  1338. int i;
  1339. struct iovec iov[3];
  1340. if (ioVector == NULL) {
  1341. return (SA_AIS_ERR_INVALID_PARAM);
  1342. }
  1343. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1344. (void *)&ckptCheckpointInstance);
  1345. if (error != SA_AIS_OK) {
  1346. return (error);
  1347. }
  1348. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1349. return (SA_AIS_ERR_ACCESS);
  1350. }
  1351. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1352. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1353. for (i = 0; i < numberOfElements; i++) {
  1354. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1355. ioVector[i].sectionId.idLen;
  1356. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1357. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1358. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1359. memcpy (&req_lib_ckpt_sectionread.checkpointName,
  1360. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1361. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1362. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1363. iov[1].iov_base = ioVector[i].sectionId.id;
  1364. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1365. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1366. iov,
  1367. 2);
  1368. /*
  1369. * Receive response header
  1370. */
  1371. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionread,
  1372. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1373. if (error != SA_AIS_OK) {
  1374. goto error_exit;
  1375. }
  1376. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1377. /*
  1378. * Receive checkpoint section data
  1379. */
  1380. if (ioVector[i].dataBuffer == 0) {
  1381. ioVector[i].dataBuffer =
  1382. malloc (dataLength);
  1383. if (ioVector[i].dataBuffer == NULL) {
  1384. error = SA_AIS_ERR_NO_MEMORY;
  1385. goto error_exit;
  1386. }
  1387. }
  1388. if (dataLength > 0) {
  1389. error = saRecvRetry (ckptCheckpointInstance->response_fd, ioVector[i].dataBuffer,
  1390. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1391. if (error != SA_AIS_OK) {
  1392. goto error_exit;
  1393. }
  1394. }
  1395. if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) {
  1396. goto error_exit;
  1397. }
  1398. /*
  1399. * Report back bytes of data read
  1400. */
  1401. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1402. }
  1403. error_exit:
  1404. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1405. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1406. if (error != SA_AIS_OK && erroneousVectorIndex) {
  1407. *erroneousVectorIndex = i;
  1408. }
  1409. return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error);
  1410. }
  1411. SaAisErrorT
  1412. saCkptCheckpointSynchronize (
  1413. SaCkptCheckpointHandleT checkpointHandle,
  1414. SaTimeT timeout)
  1415. {
  1416. SaAisErrorT error;
  1417. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1418. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1419. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1420. if (timeout == 0) {
  1421. return (SA_AIS_ERR_TIMEOUT);
  1422. }
  1423. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1424. (void *)&ckptCheckpointInstance);
  1425. if (error != SA_AIS_OK) {
  1426. return (error);
  1427. }
  1428. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1429. error = SA_AIS_ERR_ACCESS;
  1430. goto error_put;
  1431. }
  1432. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1433. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1434. memcpy (&req_lib_ckpt_checkpointsynchronize.checkpointName,
  1435. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1436. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1437. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronize,
  1438. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1439. if (error != SA_AIS_OK) {
  1440. goto error_exit;
  1441. }
  1442. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1443. &res_lib_ckpt_checkpointsynchronize,
  1444. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1445. MSG_WAITALL | MSG_NOSIGNAL);
  1446. error_exit:
  1447. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1448. error_put:
  1449. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1450. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1451. }
  1452. SaAisErrorT
  1453. saCkptCheckpointSynchronizeAsync (
  1454. SaCkptCheckpointHandleT checkpointHandle,
  1455. SaInvocationT invocation)
  1456. {
  1457. SaAisErrorT error;
  1458. struct ckptInstance *ckptInstance;
  1459. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1460. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1461. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  1462. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1463. (void *)&ckptCheckpointInstance);
  1464. if (error != SA_AIS_OK) {
  1465. return (error);
  1466. }
  1467. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1468. error = SA_AIS_ERR_ACCESS;
  1469. goto error_put;
  1470. }
  1471. error = saHandleInstanceGet (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle,
  1472. (void *)&ckptInstance);
  1473. if (error != SA_AIS_OK) {
  1474. goto error_put;
  1475. }
  1476. if (ckptInstance->callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  1477. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1478. error = SA_AIS_ERR_INIT;
  1479. goto error_put;
  1480. }
  1481. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1482. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1483. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1484. memcpy (&req_lib_ckpt_checkpointsynchronizeasync.checkpointName,
  1485. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1486. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1487. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1488. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1489. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1490. if (error != SA_AIS_OK) {
  1491. goto error_exit;
  1492. }
  1493. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1494. &res_lib_ckpt_checkpointsynchronizeasync,
  1495. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync),
  1496. MSG_WAITALL | MSG_NOSIGNAL);
  1497. error_exit:
  1498. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1499. error_put:
  1500. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1501. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronizeasync.header.error : error);
  1502. return (SA_AIS_OK);
  1503. }