ckpt.c 58 KB

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