ckpt.c 54 KB

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