ckpt.c 57 KB

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