ckpt.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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. }
  533. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  534. (void *)&ckptInstance);
  535. if (error != SA_AIS_OK) {
  536. goto error_exit;
  537. }
  538. if (ckptInstance->callbacks.saCkptCheckpointOpenCallback == NULL) {
  539. error = SA_AIS_ERR_INIT;
  540. goto error_put_ckpt;
  541. }
  542. error = saHandleCreate (&checkpointHandleDatabase,
  543. sizeof (struct ckptCheckpointInstance), &checkpointHandle);
  544. if (error != SA_AIS_OK) {
  545. goto error_put_ckpt;
  546. }
  547. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  548. (void *)&ckptCheckpointInstance);
  549. if (error != SA_AIS_OK) {
  550. goto error_destroy;
  551. }
  552. ckptCheckpointInstance->response_fd = ckptInstance->response_fd;
  553. ckptCheckpointInstance->ckptHandle = ckptHandle;
  554. ckptCheckpointInstance->checkpointHandle = checkpointHandle;
  555. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  556. if (failWithError == SA_AIS_OK) {
  557. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName,
  558. sizeof (SaNameT));
  559. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName,
  560. checkpointName, sizeof (SaNameT));
  561. }
  562. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  563. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  564. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  565. req_lib_ckpt_checkpointopenasync.fail_with_error = failWithError;
  566. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 0;
  567. if (checkpointCreationAttributes) {
  568. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  569. checkpointCreationAttributes,
  570. sizeof (SaCkptCheckpointCreationAttributesT));
  571. req_lib_ckpt_checkpointopenasync.checkpointCreationAttributesSet = 1;
  572. }
  573. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  574. req_lib_ckpt_checkpointopenasync.checkpointHandle = checkpointHandle;
  575. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointopenasync,
  576. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  577. if (error != SA_AIS_OK) {
  578. goto error_put_destroy;
  579. }
  580. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  581. &res_lib_ckpt_checkpointopenasync,
  582. sizeof (struct res_lib_ckpt_checkpointopenasync),
  583. MSG_WAITALL | MSG_NOSIGNAL);
  584. if (error != SA_AIS_OK) {
  585. goto error_put_destroy;
  586. }
  587. if (res_lib_ckpt_checkpointopenasync.header.error != SA_AIS_OK) {
  588. error = res_lib_ckpt_checkpointopenasync.header.error;
  589. goto error_put_destroy;
  590. }
  591. pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL);
  592. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  593. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  594. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointopenasync.header.error : error);
  595. error_put_destroy:
  596. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  597. error_destroy:
  598. saHandleDestroy (&checkpointHandleDatabase, checkpointHandle);
  599. error_put_ckpt:
  600. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  601. error_exit:
  602. return (error);
  603. }
  604. SaAisErrorT
  605. saCkptCheckpointClose (
  606. SaCkptCheckpointHandleT checkpointHandle)
  607. {
  608. struct req_lib_ckpt_checkpointclose req_lib_ckpt_checkpointclose;
  609. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  610. SaAisErrorT error;
  611. struct ckptCheckpointInstance *ckptCheckpointInstance;
  612. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  613. (void *)&ckptCheckpointInstance);
  614. if (error != SA_AIS_OK) {
  615. goto error_exit;
  616. }
  617. req_lib_ckpt_checkpointclose.header.size = sizeof (struct req_lib_ckpt_checkpointclose);
  618. req_lib_ckpt_checkpointclose.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  619. memcpy (&req_lib_ckpt_checkpointclose.checkpointName,
  620. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  621. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointclose,
  622. sizeof (struct req_lib_ckpt_checkpointclose), MSG_NOSIGNAL);
  623. if (error != SA_AIS_OK) {
  624. goto exit_put;
  625. }
  626. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointclose,
  627. sizeof (struct res_lib_ckpt_checkpointclose), MSG_WAITALL | MSG_NOSIGNAL);
  628. list_del (&ckptCheckpointInstance->list);
  629. saHandleDestroy (&checkpointHandleDatabase, checkpointHandle);
  630. exit_put:
  631. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  632. error_exit:
  633. return (error);
  634. }
  635. SaAisErrorT
  636. saCkptCheckpointUnlink (
  637. SaCkptHandleT ckptHandle,
  638. const SaNameT *checkpointName)
  639. {
  640. SaAisErrorT error;
  641. struct ckptInstance *ckptInstance;
  642. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  643. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  644. if (checkpointName == NULL) {
  645. return (SA_AIS_ERR_INVALID_PARAM);
  646. }
  647. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  648. if (error != SA_AIS_OK) {
  649. goto exit_noclose;
  650. }
  651. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  652. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  653. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  654. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointunlink,
  655. sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  656. if (error != SA_AIS_OK) {
  657. goto exit_put;
  658. }
  659. error = saRecvRetry (ckptInstance->response_fd, &res_lib_ckpt_checkpointunlink,
  660. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  661. exit_put:
  662. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  663. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  664. exit_noclose:
  665. return (error);
  666. }
  667. SaAisErrorT
  668. saCkptCheckpointRetentionDurationSet (
  669. SaCkptCheckpointHandleT checkpointHandle,
  670. SaTimeT retentionDuration)
  671. {
  672. SaAisErrorT error;
  673. struct ckptCheckpointInstance *ckptCheckpointInstance;
  674. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  675. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  676. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  677. (void *)&ckptCheckpointInstance);
  678. if (error != SA_AIS_OK) {
  679. goto error_exit_noput;
  680. }
  681. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  682. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  683. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  684. memcpy (&req_lib_ckpt_checkpointretentiondurationset.checkpointName,
  685. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  686. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  687. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  688. if (error != SA_AIS_OK) {
  689. goto error_exit;
  690. }
  691. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  692. &res_lib_ckpt_checkpointretentiondurationset,
  693. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  694. MSG_WAITALL | MSG_NOSIGNAL);
  695. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  696. error_exit:
  697. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  698. error_exit_noput:
  699. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  700. }
  701. SaAisErrorT
  702. saCkptActiveReplicaSet (
  703. SaCkptCheckpointHandleT checkpointHandle)
  704. {
  705. SaAisErrorT error;
  706. struct ckptCheckpointInstance *ckptCheckpointInstance;
  707. struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset;
  708. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  709. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  710. (void *)&ckptCheckpointInstance);
  711. if (error != SA_AIS_OK) {
  712. goto error_noput;
  713. }
  714. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  715. error = SA_AIS_ERR_ACCESS;
  716. goto error_put;
  717. }
  718. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  719. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_ACTIVEREPLICASET;
  720. memcpy (&req_lib_ckpt_activereplicaset.checkpointName,
  721. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  722. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  723. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset,
  724. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  725. if (error != SA_AIS_OK) {
  726. goto error_put;
  727. }
  728. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  729. &res_lib_ckpt_activereplicaset,
  730. sizeof (struct res_lib_ckpt_activereplicaset),
  731. MSG_WAITALL | MSG_NOSIGNAL);
  732. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  733. error_put:
  734. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  735. error_noput:
  736. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  737. }
  738. SaAisErrorT
  739. saCkptCheckpointStatusGet (
  740. SaCkptCheckpointHandleT checkpointHandle,
  741. SaCkptCheckpointDescriptorT *checkpointStatus)
  742. {
  743. SaAisErrorT error;
  744. struct ckptCheckpointInstance *ckptCheckpointInstance;
  745. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  746. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  747. if (checkpointStatus == NULL) {
  748. return (SA_AIS_ERR_INVALID_PARAM);
  749. }
  750. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  751. (void *)&ckptCheckpointInstance);
  752. if (error != SA_AIS_OK) {
  753. return (error);
  754. }
  755. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  756. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  757. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  758. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  759. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  760. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget,
  761. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  762. if (error != SA_AIS_OK) {
  763. goto error_exit;
  764. }
  765. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  766. &res_lib_ckpt_checkpointstatusget,
  767. sizeof (struct res_lib_ckpt_checkpointstatusget),
  768. MSG_WAITALL | MSG_NOSIGNAL);
  769. if (error != SA_AIS_OK) {
  770. goto error_exit;
  771. }
  772. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  773. memcpy (checkpointStatus,
  774. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  775. sizeof (SaCkptCheckpointDescriptorT));
  776. error_exit:
  777. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  778. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointstatusget.header.error : error);
  779. }
  780. SaAisErrorT
  781. saCkptSectionCreate (
  782. SaCkptCheckpointHandleT checkpointHandle,
  783. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  784. const void *initialData,
  785. SaUint32T initialDataSize)
  786. {
  787. SaAisErrorT error;
  788. struct ckptCheckpointInstance *ckptCheckpointInstance;
  789. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  790. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  791. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  792. (void *)&ckptCheckpointInstance);
  793. if (error != SA_AIS_OK) {
  794. return (error);
  795. }
  796. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  797. error = SA_AIS_ERR_ACCESS;
  798. goto error_exit;
  799. }
  800. req_lib_ckpt_sectioncreate.header.size =
  801. sizeof (struct req_lib_ckpt_sectioncreate) +
  802. sectionCreationAttributes->sectionId->idLen +
  803. initialDataSize;
  804. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  805. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  806. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  807. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  808. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  809. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  810. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  811. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate,
  812. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  813. if (error != SA_AIS_OK) {
  814. goto error_exit;
  815. }
  816. /*
  817. * Write section identifier to server
  818. */
  819. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id,
  820. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  821. if (error != SA_AIS_OK) {
  822. goto error_exit;
  823. }
  824. error = saSendRetry (ckptCheckpointInstance->response_fd, initialData,
  825. initialDataSize, MSG_NOSIGNAL);
  826. if (error != SA_AIS_OK) {
  827. goto error_exit;
  828. }
  829. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  830. &res_lib_ckpt_sectioncreate,
  831. sizeof (struct res_lib_ckpt_sectioncreate),
  832. MSG_WAITALL | MSG_NOSIGNAL);
  833. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  834. error_exit:
  835. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  836. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  837. }
  838. SaAisErrorT
  839. saCkptSectionDelete (
  840. SaCkptCheckpointHandleT checkpointHandle,
  841. const SaCkptSectionIdT *sectionId)
  842. {
  843. SaAisErrorT error;
  844. struct ckptCheckpointInstance *ckptCheckpointInstance;
  845. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  846. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  847. if (sectionId == NULL) {
  848. return (SA_AIS_ERR_INVALID_PARAM);
  849. }
  850. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  851. (void *)&ckptCheckpointInstance);
  852. if (error != SA_AIS_OK) {
  853. return (error);
  854. }
  855. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  856. error = SA_AIS_ERR_ACCESS;
  857. goto error_put;
  858. }
  859. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  860. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  861. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  862. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  863. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  864. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  865. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete,
  866. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  867. if (error != SA_AIS_OK) {
  868. goto error_exit;
  869. }
  870. /*
  871. * Write section identifier to server
  872. */
  873. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  874. sectionId->idLen, MSG_NOSIGNAL);
  875. if (error != SA_AIS_OK) {
  876. goto error_exit;
  877. }
  878. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  879. &res_lib_ckpt_sectiondelete,
  880. sizeof (struct res_lib_ckpt_sectiondelete),
  881. MSG_WAITALL | MSG_NOSIGNAL);
  882. error_exit:
  883. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  884. error_put:
  885. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  886. return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  887. }
  888. SaAisErrorT
  889. saCkptSectionExpirationTimeSet (
  890. SaCkptCheckpointHandleT checkpointHandle,
  891. const SaCkptSectionIdT *sectionId,
  892. SaTimeT expirationTime)
  893. {
  894. SaAisErrorT error;
  895. struct ckptCheckpointInstance *ckptCheckpointInstance;
  896. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  897. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  898. if (sectionId == NULL) {
  899. return (SA_AIS_ERR_INVALID_PARAM);
  900. }
  901. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  902. (void *)&ckptCheckpointInstance);
  903. if (error != SA_AIS_OK) {
  904. return (error);
  905. }
  906. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  907. error = SA_AIS_ERR_ACCESS;
  908. goto error_put;
  909. }
  910. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  911. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  912. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  913. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  914. memcpy (&req_lib_ckpt_sectionexpirationtimeset.checkpointName,
  915. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  916. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  917. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset,
  918. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  919. if (error != SA_AIS_OK) {
  920. goto error_exit;
  921. }
  922. /*
  923. * Write section identifier to server
  924. */
  925. if (sectionId->idLen) {
  926. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  927. sectionId->idLen, MSG_NOSIGNAL);
  928. if (error != SA_AIS_OK) {
  929. goto error_exit;
  930. }
  931. }
  932. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  933. &res_lib_ckpt_sectionexpirationtimeset,
  934. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  935. MSG_WAITALL | MSG_NOSIGNAL);
  936. error_exit:
  937. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  938. error_put:
  939. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  940. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  941. }
  942. SaAisErrorT
  943. saCkptSectionIterationInitialize (
  944. SaCkptCheckpointHandleT checkpointHandle,
  945. SaCkptSectionsChosenT sectionsChosen,
  946. SaTimeT expirationTime,
  947. SaCkptSectionIterationHandleT *sectionIterationHandle)
  948. {
  949. SaAisErrorT error;
  950. struct ckptCheckpointInstance *ckptCheckpointInstance;
  951. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  952. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  953. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  954. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  955. (void *)&ckptCheckpointInstance);
  956. if (error != SA_AIS_OK) {
  957. goto error_no_destroy;
  958. }
  959. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  960. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  961. if (error != SA_AIS_OK) {
  962. goto error_put_checkpoint_db;
  963. }
  964. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  965. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  966. if (error != SA_AIS_OK) {
  967. goto error_destroy;
  968. }
  969. ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd;
  970. ckptSectionIterationInstance->checkpointHandle = checkpointHandle;
  971. pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL);
  972. /*
  973. * Setup section id list for iterator next
  974. */
  975. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  976. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  977. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  978. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  979. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  980. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  981. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  982. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  983. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  984. &req_lib_ckpt_sectioniteratorinitialize,
  985. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  986. MSG_NOSIGNAL);
  987. if (error != SA_AIS_OK) {
  988. goto error_put_destroy;
  989. }
  990. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  991. &res_lib_ckpt_sectioniteratorinitialize,
  992. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  993. MSG_WAITALL | MSG_NOSIGNAL);
  994. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  995. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  996. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
  997. error_put_destroy:
  998. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  999. error_destroy:
  1000. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  1001. error_put_checkpoint_db:
  1002. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1003. error_no_destroy:
  1004. return (error);
  1005. }
  1006. struct iteratorSectionIdListEntry {
  1007. struct list_head list;
  1008. char data[0];
  1009. };
  1010. SaAisErrorT
  1011. saCkptSectionIterationNext (
  1012. SaCkptSectionIterationHandleT sectionIterationHandle,
  1013. SaCkptSectionDescriptorT *sectionDescriptor)
  1014. {
  1015. SaAisErrorT error;
  1016. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1017. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  1018. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1019. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  1020. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1021. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1022. if (error != SA_AIS_OK) {
  1023. goto error_exit;
  1024. }
  1025. /*
  1026. * Allocate section id storage area
  1027. */
  1028. /*
  1029. * TODO max section id size is 500
  1030. */
  1031. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) + 500);
  1032. if (iteratorSectionIdListEntry == 0) {
  1033. error = SA_AIS_ERR_NO_MEMORY;
  1034. goto error_put_nounlock;
  1035. }
  1036. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  1037. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1038. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  1039. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  1040. &req_lib_ckpt_sectioniteratornext,
  1041. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  1042. if (error != SA_AIS_OK) {
  1043. goto error_put;
  1044. }
  1045. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniteratornext,
  1046. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  1047. if (error != SA_AIS_OK) {
  1048. goto error_put;
  1049. }
  1050. memcpy (sectionDescriptor,
  1051. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1052. sizeof (SaCkptSectionDescriptorT));
  1053. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  1054. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  1055. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  1056. sectionDescriptor->sectionId.id,
  1057. res_lib_ckpt_sectioniteratornext.header.size -
  1058. sizeof (struct res_lib_ckpt_sectioniteratornext),
  1059. MSG_WAITALL | MSG_NOSIGNAL);
  1060. }
  1061. /*
  1062. * Add to persistent memory list for this sectioniterator
  1063. */
  1064. if (error == SA_AIS_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_AIS_OK) {
  1065. list_init (&iteratorSectionIdListEntry->list);
  1066. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  1067. }
  1068. error_put:
  1069. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  1070. error_put_nounlock:
  1071. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1072. error_exit:
  1073. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  1074. }
  1075. SaAisErrorT
  1076. saCkptSectionIterationFinalize (
  1077. SaCkptSectionIterationHandleT sectionIterationHandle)
  1078. {
  1079. SaAisErrorT error;
  1080. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  1081. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  1082. struct list_head *sectionIdIterationList;
  1083. struct list_head *sectionIdIterationListNext;
  1084. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  1085. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  1086. if (error != SA_AIS_OK) {
  1087. goto error_noput;
  1088. }
  1089. /*
  1090. * iterate list of section ids for this iterator to free the allocated memory
  1091. * be careful to cache next pointer because free removes memory from use
  1092. */
  1093. for (sectionIdIterationList = ckptSectionIterationInstance->sectionIdListHead.next,
  1094. sectionIdIterationListNext = sectionIdIterationList->next;
  1095. sectionIdIterationList != &ckptSectionIterationInstance->sectionIdListHead;
  1096. sectionIdIterationList = sectionIdIterationListNext,
  1097. sectionIdIterationListNext = sectionIdIterationList->next) {
  1098. iteratorSectionIdListEntry = list_entry (sectionIdIterationList,
  1099. struct iteratorSectionIdListEntry, list);
  1100. free (iteratorSectionIdListEntry);
  1101. }
  1102. saHandleInstancePut (&checkpointHandleDatabase,
  1103. ckptSectionIterationInstance->checkpointHandle);
  1104. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1105. saHandleDestroy (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  1106. error_noput:
  1107. return (error);
  1108. }
  1109. SaAisErrorT
  1110. saCkptCheckpointWrite (
  1111. SaCkptCheckpointHandleT checkpointHandle,
  1112. const SaCkptIOVectorElementT *ioVector,
  1113. SaUint32T numberOfElements,
  1114. SaUint32T *erroneousVectorIndex)
  1115. {
  1116. SaAisErrorT error = SA_AIS_OK;
  1117. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1118. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  1119. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1120. int i;
  1121. struct iovec iov[3];
  1122. int iov_len = 0;
  1123. if (ioVector == NULL) {
  1124. return (SA_AIS_ERR_INVALID_PARAM);
  1125. }
  1126. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1127. (void *)&ckptCheckpointInstance);
  1128. if (error != SA_AIS_OK) {
  1129. return (error);
  1130. }
  1131. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1132. error = SA_AIS_ERR_ACCESS;
  1133. goto error_put;
  1134. }
  1135. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  1136. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1137. for (i = 0; i < numberOfElements; i++) {
  1138. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  1139. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  1140. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  1141. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  1142. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  1143. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1144. iov_len = 0;
  1145. /* TODO check for zero length stuff */
  1146. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  1147. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  1148. iov[1].iov_base = ioVector[i].sectionId.id;
  1149. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1150. iov[2].iov_base = ioVector[i].dataBuffer;
  1151. iov[2].iov_len = ioVector[i].dataSize;
  1152. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1153. iov,
  1154. 3);
  1155. if (error != SA_AIS_OK) {
  1156. goto error_exit;
  1157. }
  1158. /*
  1159. * Receive response
  1160. */
  1161. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite,
  1162. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1163. if (error != SA_AIS_OK) {
  1164. goto error_exit;
  1165. }
  1166. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1167. error = SA_AIS_ERR_TRY_AGAIN;
  1168. goto error_exit;
  1169. }
  1170. /*
  1171. * If error, report back erroneous index
  1172. */
  1173. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1174. if (erroneousVectorIndex) {
  1175. *erroneousVectorIndex = i;
  1176. }
  1177. goto error_exit;
  1178. }
  1179. }
  1180. error_exit:
  1181. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1182. error_put:
  1183. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1184. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1185. }
  1186. SaAisErrorT
  1187. saCkptSectionOverwrite (
  1188. SaCkptCheckpointHandleT checkpointHandle,
  1189. const SaCkptSectionIdT *sectionId,
  1190. const void *dataBuffer,
  1191. SaSizeT dataSize)
  1192. {
  1193. SaAisErrorT error;
  1194. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1195. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1196. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1197. if (dataBuffer == NULL) {
  1198. return (SA_ERR_INVALID_PARAM);
  1199. }
  1200. if (sectionId == NULL) {
  1201. return (SA_ERR_INVALID_PARAM);
  1202. }
  1203. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1204. (void *)&ckptCheckpointInstance);
  1205. if (error != SA_AIS_OK) {
  1206. return (error);
  1207. }
  1208. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1209. return (SA_AIS_ERR_ACCESS);
  1210. }
  1211. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1212. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1213. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1214. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1215. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1216. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1217. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1218. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite,
  1219. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1220. if (error != SA_AIS_OK) {
  1221. goto error_exit;
  1222. }
  1223. if (sectionId->idLen) {
  1224. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  1225. sectionId->idLen, MSG_NOSIGNAL);
  1226. if (error != SA_AIS_OK) {
  1227. goto error_exit;
  1228. }
  1229. }
  1230. error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1231. if (error != SA_AIS_OK) {
  1232. goto error_exit;
  1233. }
  1234. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1235. &res_lib_ckpt_sectionoverwrite,
  1236. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1237. MSG_WAITALL | MSG_NOSIGNAL);
  1238. error_exit:
  1239. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1240. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1241. return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1242. }
  1243. SaAisErrorT
  1244. saCkptCheckpointRead (
  1245. SaCkptCheckpointHandleT checkpointHandle,
  1246. SaCkptIOVectorElementT *ioVector,
  1247. SaUint32T numberOfElements,
  1248. SaUint32T *erroneousVectorIndex)
  1249. {
  1250. SaAisErrorT error = SA_AIS_OK;
  1251. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1252. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1253. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1254. int dataLength;
  1255. int i;
  1256. struct iovec iov[3];
  1257. if (ioVector == NULL) {
  1258. return (SA_AIS_ERR_INVALID_PARAM);
  1259. }
  1260. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1261. (void *)&ckptCheckpointInstance);
  1262. if (error != SA_AIS_OK) {
  1263. return (error);
  1264. }
  1265. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1266. return (SA_AIS_ERR_ACCESS);
  1267. }
  1268. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1269. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1270. for (i = 0; i < numberOfElements; i++) {
  1271. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1272. ioVector[i].sectionId.idLen;
  1273. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1274. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1275. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1276. memcpy (&req_lib_ckpt_sectionread.checkpointName,
  1277. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1278. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1279. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1280. iov[1].iov_base = ioVector[i].sectionId.id;
  1281. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1282. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1283. iov,
  1284. 2);
  1285. /*
  1286. * Receive response header
  1287. */
  1288. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionread,
  1289. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1290. if (error != SA_AIS_OK) {
  1291. goto error_exit;
  1292. }
  1293. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1294. /*
  1295. * Receive checkpoint section data
  1296. */
  1297. if (ioVector[i].dataBuffer == 0) {
  1298. ioVector[i].dataBuffer =
  1299. malloc (dataLength);
  1300. if (ioVector[i].dataBuffer == NULL) {
  1301. error = SA_AIS_ERR_NO_MEMORY;
  1302. goto error_exit;
  1303. }
  1304. }
  1305. if (dataLength > 0) {
  1306. error = saRecvRetry (ckptCheckpointInstance->response_fd, ioVector[i].dataBuffer,
  1307. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1308. if (error != SA_AIS_OK) {
  1309. goto error_exit;
  1310. }
  1311. }
  1312. if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) {
  1313. goto error_exit;
  1314. }
  1315. /*
  1316. * Report back bytes of data read
  1317. */
  1318. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1319. }
  1320. error_exit:
  1321. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1322. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1323. if (error != SA_AIS_OK && erroneousVectorIndex) {
  1324. *erroneousVectorIndex = i;
  1325. }
  1326. return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error);
  1327. }
  1328. SaAisErrorT
  1329. saCkptCheckpointSynchronize (
  1330. SaCkptCheckpointHandleT checkpointHandle,
  1331. SaTimeT timeout)
  1332. {
  1333. SaAisErrorT error;
  1334. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1335. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1336. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1337. if (timeout == 0) {
  1338. return (SA_AIS_ERR_TIMEOUT);
  1339. }
  1340. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1341. (void *)&ckptCheckpointInstance);
  1342. if (error != SA_AIS_OK) {
  1343. return (error);
  1344. }
  1345. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1346. error = SA_AIS_ERR_ACCESS;
  1347. goto error_put;
  1348. }
  1349. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1350. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1351. memcpy (&req_lib_ckpt_checkpointsynchronize.checkpointName,
  1352. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1353. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1354. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronize,
  1355. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1356. if (error != SA_AIS_OK) {
  1357. goto error_exit;
  1358. }
  1359. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1360. &res_lib_ckpt_checkpointsynchronize,
  1361. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1362. MSG_WAITALL | MSG_NOSIGNAL);
  1363. error_exit:
  1364. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1365. error_put:
  1366. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1367. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1368. }
  1369. SaAisErrorT
  1370. saCkptCheckpointSynchronizeAsync (
  1371. SaCkptCheckpointHandleT checkpointHandle,
  1372. SaInvocationT invocation)
  1373. {
  1374. SaAisErrorT error;
  1375. struct ckptInstance *ckptInstance;
  1376. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1377. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1378. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  1379. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1380. (void *)&ckptCheckpointInstance);
  1381. if (error != SA_AIS_OK) {
  1382. return (error);
  1383. }
  1384. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1385. error = SA_AIS_ERR_ACCESS;
  1386. goto error_put;
  1387. }
  1388. error = saHandleInstanceGet (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle,
  1389. (void *)&ckptInstance);
  1390. if (error != SA_AIS_OK) {
  1391. goto error_put;
  1392. }
  1393. if (ckptInstance->callbacks.saCkptCheckpointSynchronizeCallback == NULL) {
  1394. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1395. error = SA_AIS_ERR_INIT;
  1396. goto error_put;
  1397. }
  1398. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  1399. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1400. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1401. memcpy (&req_lib_ckpt_checkpointsynchronizeasync.checkpointName,
  1402. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1403. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1404. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1405. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1406. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1407. if (error != SA_AIS_OK) {
  1408. goto error_exit;
  1409. }
  1410. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1411. &res_lib_ckpt_checkpointsynchronizeasync,
  1412. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync),
  1413. MSG_WAITALL | MSG_NOSIGNAL);
  1414. error_exit:
  1415. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1416. error_put:
  1417. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1418. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronizeasync.header.error : error);
  1419. return (SA_AIS_OK);
  1420. }