ckpt.c 55 KB

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