ckpt.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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 <unistd.h>
  38. #include <errno.h>
  39. #include <pthread.h>
  40. #include <sys/types.h>
  41. #include <sys/uio.h>
  42. #include <sys/socket.h>
  43. #include <sys/select.h>
  44. #include <sys/un.h>
  45. #include "util.h"
  46. #include "../include/list.h"
  47. #include "../include/saCkpt.h"
  48. #include "../include/ipc_gen.h"
  49. #include "../include/ipc_ckpt.h"
  50. struct message_overlay {
  51. struct req_header header;
  52. char data[4096];
  53. };
  54. /*
  55. * Data structure for instance data
  56. */
  57. struct ckptInstance {
  58. int fd;
  59. struct queue inq;
  60. SaCkptCallbacksT callbacks;
  61. int finalize;
  62. pthread_mutex_t mutex;
  63. };
  64. struct ckptCheckpointInstance {
  65. int fd;
  66. SaCkptHandleT ckptHandle;
  67. SaCkptCheckpointOpenFlagsT checkpointOpenFlags;
  68. SaNameT checkpointName;
  69. SaUint32T maxSectionIdSize;
  70. pthread_mutex_t mutex;
  71. };
  72. struct ckptSectionIterationInstance {
  73. int fd;
  74. SaCkptCheckpointHandleT checkpointHandle;
  75. struct list_head sectionIdListHead;
  76. SaUint32T maxSectionIdSize;
  77. pthread_mutex_t mutex;
  78. };
  79. void ckptHandleInstanceDestructor (void *instance);
  80. void checkpointHandleInstanceDestructor (void *instance);
  81. void ckptSectionIterationHandleInstanceDestructor (void *instance);
  82. /*
  83. * All CKPT instances in this database
  84. */
  85. static struct saHandleDatabase ckptHandleDatabase = {
  86. .handleCount = 0,
  87. .handles = 0,
  88. .mutex = PTHREAD_MUTEX_INITIALIZER,
  89. .handleInstanceDestructor = ckptHandleInstanceDestructor
  90. };
  91. /*
  92. * All Checkpoint instances in this database
  93. */
  94. static struct saHandleDatabase checkpointHandleDatabase = {
  95. .handleCount = 0,
  96. .handles = 0,
  97. .mutex = PTHREAD_MUTEX_INITIALIZER,
  98. .handleInstanceDestructor = checkpointHandleInstanceDestructor
  99. };
  100. /*
  101. * All section iterators in this database
  102. */
  103. static struct saHandleDatabase ckptSectionIterationHandleDatabase = {
  104. .handleCount = 0,
  105. .handles = 0,
  106. .mutex = PTHREAD_MUTEX_INITIALIZER,
  107. .handleInstanceDestructor = ckptSectionIterationHandleInstanceDestructor
  108. };
  109. /*
  110. * Versions supported
  111. */
  112. static SaVersionT ckptVersionsSupported[] = {
  113. { 'B', 1, 1 },
  114. { 'b', 1, 1 }
  115. };
  116. static struct saVersionDatabase ckptVersionDatabase = {
  117. sizeof (ckptVersionsSupported) / sizeof (SaVersionT),
  118. ckptVersionsSupported
  119. };
  120. /*
  121. * Implementation
  122. */
  123. void ckptHandleInstanceDestructor (void *instance)
  124. {
  125. struct ckptInstance *ckptInstance = (struct ckptInstance *)instance;
  126. if (ckptInstance->fd != -1) {
  127. shutdown (ckptInstance->fd, 0);
  128. close (ckptInstance->fd);
  129. }
  130. if (ckptInstance->inq.items) {
  131. free (ckptInstance->inq.items);
  132. }
  133. }
  134. void checkpointHandleInstanceDestructor (void *instance)
  135. {
  136. return;
  137. }
  138. void ckptSectionIterationHandleInstanceDestructor (void *instance)
  139. {
  140. struct ckptSectionIterationInstance *ckptSectionIterationInstance = (struct ckptSectionIterationInstance *)instance;
  141. if (ckptSectionIterationInstance->fd != -1) {
  142. shutdown (ckptSectionIterationInstance->fd, 0);
  143. close (ckptSectionIterationInstance->fd);
  144. }
  145. }
  146. SaAisErrorT
  147. saCkptInitialize (
  148. SaCkptHandleT *ckptHandle,
  149. const SaCkptCallbacksT *callbacks,
  150. SaVersionT *version)
  151. {
  152. struct ckptInstance *ckptInstance;
  153. SaAisErrorT error = SA_AIS_OK;
  154. error = saVersionVerify (&ckptVersionDatabase, version);
  155. if (error != SA_AIS_OK) {
  156. goto error_no_destroy;
  157. }
  158. error = saHandleCreate (&ckptHandleDatabase, sizeof (struct ckptInstance),
  159. ckptHandle);
  160. if (error != SA_AIS_OK) {
  161. goto error_no_destroy;
  162. }
  163. error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle,
  164. (void *)&ckptInstance);
  165. if (error != SA_AIS_OK) {
  166. goto error_destroy;
  167. }
  168. ckptInstance->fd = -1;
  169. /*
  170. * An inq is needed to store async messages while waiting for a
  171. * sync response
  172. */
  173. error = saQueueInit (&ckptInstance->inq, 512, sizeof (void *));
  174. if (error != SA_AIS_OK) {
  175. goto error_put_destroy;
  176. }
  177. error = saServiceConnect (&ckptInstance->fd, MESSAGE_REQ_CKPT_INIT);
  178. if (error != SA_AIS_OK) {
  179. goto error_put_destroy;
  180. }
  181. memcpy (&ckptInstance->callbacks, callbacks, sizeof (SaCkptCallbacksT));
  182. pthread_mutex_init (&ckptInstance->mutex, NULL);
  183. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  184. return (SA_AIS_OK);
  185. error_put_destroy:
  186. saHandleInstancePut (&ckptHandleDatabase, *ckptHandle);
  187. error_destroy:
  188. saHandleDestroy (&ckptHandleDatabase, *ckptHandle);
  189. error_no_destroy:
  190. return (error);
  191. }
  192. SaAisErrorT
  193. saCkptSelectionObjectGet (
  194. const SaCkptHandleT ckptHandle,
  195. SaSelectionObjectT *selectionObject)
  196. {
  197. struct ckptInstance *ckptInstance;
  198. SaAisErrorT error;
  199. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  200. if (error != SA_AIS_OK) {
  201. return (error);
  202. }
  203. *selectionObject = ckptInstance->fd;
  204. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  205. return (SA_AIS_OK);
  206. }
  207. #ifdef COMPILE_OUT
  208. SaAisErrorT
  209. saCkptDispatch (
  210. const SaCkptHandleT ckptHandle,
  211. SaDispatchFlagsT dispatchFlags)
  212. {
  213. fd_set read_fds;
  214. SaAisErrorT error;
  215. int dispatch_avail;
  216. struct timeval *timeout = 0;
  217. struct ckptInstance *ckptInstance;
  218. struct req_header **queue_msg;
  219. struct req_header *msg;
  220. int empty;
  221. int ignore_dispatch = 0;
  222. int cont = 1; /* always continue do loop except when set to 0 */
  223. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  224. if (error != SA_AIS_OK) {
  225. return (error);
  226. }
  227. /*
  228. * Timeout instantly for SA_DISPATCH_ALL
  229. */
  230. if (dispatchFlags & SA_DISPATCH_ALL) {
  231. timeout = &zerousec;
  232. }
  233. do {
  234. /*
  235. * Read data directly from socket
  236. */
  237. FD_ZERO (&read_fds);
  238. FD_SET (ckptInstance->fd, &read_fds);
  239. error = saSelectRetry (ckptInstance->fd + 1, &read_fds, 0, 0, timeout);
  240. if (error != SA_AIS_OK) {
  241. goto error_exit;
  242. }
  243. dispatch_avail = FD_ISSET (ckptInstance->fd, &read_fds);
  244. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  245. break; /* exit do while cont is 1 loop */
  246. } else
  247. if (dispatch_avail == 0) {
  248. continue; /* next select */
  249. }
  250. saQueueIsEmpty(&ckptInstance->inq, &empty);
  251. if (empty == 0) {
  252. /*
  253. * Queue is not empty, read data from queue
  254. */
  255. saQueueItemGet (&ckptInstance->inq, (void **)&queue_msg);
  256. msg = *queue_msg;
  257. memcpy (&ckptInstance->message, msg, msg->size);
  258. saQueueItemRemove (&ckptInstance->inq);
  259. free (msg);
  260. } else {
  261. /*
  262. * Queue empty, read response from socket
  263. */
  264. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.header, sizeof (struct req_header), MSG_WAITALL | MSG_NOSIGNAL);
  265. if (error != SA_AIS_OK) {
  266. goto error_exit;
  267. }
  268. if (ckptInstance->message.header.size > sizeof (struct req_header)) {
  269. error = saRecvRetry (ckptInstance->fd, &ckptInstance->message.data,
  270. ckptInstance->message.header.size - sizeof (struct req_header),
  271. MSG_WAITALL | MSG_NOSIGNAL);
  272. if (error != SA_AIS_OK) {
  273. goto error_exit;
  274. }
  275. }
  276. }
  277. /*
  278. * Dispatch incoming response
  279. */
  280. switch (ckptInstance->message.header.id) {
  281. #ifdef COMPILE_OUT
  282. case MESSAGE_RES_CKPT_CHECKPOINT_ACTIVATEPOLL:
  283. /*
  284. * This is a do nothing message which the node executive sends
  285. * to activate the file handle in poll when the library has
  286. * queued a message into amfHandle->inq
  287. * The dispatch is ignored for the following two cases:
  288. * 1) setting of timeout to zero for the DISPATCH_ALL case
  289. * 2) expiration of the do loop for the DISPATCH_ONE case
  290. */
  291. ignore_dispatch = 1;
  292. break;
  293. case MESSAGE_RES_CKPT_CHECKPOINT_HEALTHCHECKCALLBACK:
  294. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&ckptInstance->message;
  295. amfInstance->callbacks.saAmfHealthcheckCallback (
  296. res_amf_healthcheckcallback->invocation,
  297. &res_amf_healthcheckcallback->compName,
  298. res_amf_healthcheckcallback->checkType);
  299. break;
  300. case MESSAGE_RES_CKPT_CHECKPOINT_READINESSSTATESETCALLBACK:
  301. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&ckptInstance->message;
  302. amfInstance->callbacks.saAmfReadinessStateSetCallback (
  303. res_amf_readinessstatesetcallback->invocation,
  304. &res_amf_readinessstatesetcallback->compName,
  305. res_amf_readinessstatesetcallback->readinessState);
  306. break;
  307. case MESSAGE_RES_CKPT_CHECKPOINT_CSISETCALLBACK:
  308. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&ckptInstance->message;
  309. amfInstance->callbacks.saAmfCSISetCallback (
  310. res_amf_csisetcallback->invocation,
  311. &res_amf_csisetcallback->compName,
  312. &res_amf_csisetcallback->csiName,
  313. res_amf_csisetcallback->csiFlags,
  314. &res_amf_csisetcallback->haState,
  315. &res_amf_csisetcallback->activeCompName,
  316. res_amf_csisetcallback->transitionDescriptor);
  317. break;
  318. case MESSAGE_RES_CKPT_CHECKPOINT_CSIREMOVECALLBACK:
  319. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&ckptInstance->message;
  320. amfInstance->callbacks.saAmfCSIRemoveCallback (
  321. res_amf_csiremovecallback->invocation,
  322. &res_amf_csiremovecallback->compName,
  323. &res_amf_csiremovecallback->csiName,
  324. &res_amf_csiremovecallback->csiFlags);
  325. break;
  326. case MESSAGE_RES_CKPT_CHECKPOINT_PROTECTIONGROUPTRACKCALLBACK:
  327. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&ckptInstance->message;
  328. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  329. res_amf_protectiongrouptrackcallback->notificationBuffer,
  330. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  331. amfInstance->callbacks.saAmfProtectionGroupTrackCallback(
  332. &res_amf_protectiongrouptrackcallback->csiName,
  333. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  334. res_amf_protectiongrouptrackcallback->numberOfItems,
  335. res_amf_protectiongrouptrackcallback->numberOfMembers,
  336. res_amf_protectiongrouptrackcallback->error);
  337. break;
  338. #endif
  339. default:
  340. /* TODO */
  341. break;
  342. }
  343. /*
  344. * Determine if more messages should be processed
  345. */
  346. switch (dispatchFlags) {
  347. case SA_DISPATCH_ONE:
  348. if (ignore_dispatch) {
  349. ignore_dispatch = 0;
  350. } else {
  351. cont = 0;
  352. }
  353. break;
  354. case SA_DISPATCH_ALL:
  355. if (ignore_dispatch) {
  356. ignore_dispatch = 0;
  357. }
  358. break;
  359. case SA_DISPATCH_BLOCKING:
  360. break;
  361. }
  362. } while (cont);
  363. error_exit:
  364. return (error);
  365. }
  366. #endif
  367. SaAisErrorT
  368. saCkptFinalize (
  369. const SaCkptHandleT ckptHandle)
  370. {
  371. struct ckptInstance *ckptInstance;
  372. SaAisErrorT error;
  373. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  374. (void *)&ckptInstance);
  375. if (error != SA_AIS_OK) {
  376. return (error);
  377. }
  378. pthread_mutex_lock (&ckptInstance->mutex);
  379. /*
  380. * Another thread has already started finalizing
  381. */
  382. if (ckptInstance->finalize) {
  383. pthread_mutex_unlock (&ckptInstance->mutex);
  384. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  385. return (SA_AIS_ERR_BAD_HANDLE);
  386. }
  387. ckptInstance->finalize = 1;
  388. saActivatePoll (ckptInstance->fd);
  389. pthread_mutex_unlock (&ckptInstance->mutex);
  390. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  391. saHandleDestroy (&ckptHandleDatabase, ckptHandle);
  392. return (SA_AIS_OK);
  393. }
  394. SaAisErrorT
  395. saCkptCheckpointOpen (
  396. SaCkptHandleT ckptHandle,
  397. const SaNameT *checkpointName,
  398. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  399. SaCkptCheckpointOpenFlagsT checkpointOpenFlags,
  400. SaTimeT timeout,
  401. SaCkptCheckpointHandleT *checkpointHandle)
  402. {
  403. SaAisErrorT error;
  404. struct ckptCheckpointInstance *ckptCheckpointInstance;
  405. struct ckptInstance *ckptInstance;
  406. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  407. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  408. error = saHandleCreate (&checkpointHandleDatabase,
  409. sizeof (struct ckptCheckpointInstance), checkpointHandle);
  410. if (error != SA_AIS_OK) {
  411. goto error_no_destroy;
  412. }
  413. error = saHandleInstanceGet (&checkpointHandleDatabase, *checkpointHandle,
  414. (void *)&ckptCheckpointInstance);
  415. if (error != SA_AIS_OK) {
  416. goto error_destroy;
  417. }
  418. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle,
  419. (void *)&ckptInstance);
  420. if (error != SA_AIS_OK) {
  421. goto error_put_destroy;
  422. }
  423. ckptCheckpointInstance->fd = ckptInstance->fd;
  424. ckptCheckpointInstance->maxSectionIdSize =
  425. checkpointCreationAttributes->maxSectionIdSize;
  426. ckptCheckpointInstance->ckptHandle = ckptHandle;
  427. ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags;
  428. req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen);
  429. req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  430. memcpy (&req_lib_ckpt_checkpointopen.checkpointName, checkpointName, sizeof (SaNameT));
  431. memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT));
  432. memcpy (&req_lib_ckpt_checkpointopen.checkpointCreationAttributes,
  433. checkpointCreationAttributes,
  434. sizeof (SaCkptCheckpointCreationAttributesT));
  435. req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags;
  436. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointopen,
  437. sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL);
  438. if (error != SA_AIS_OK) {
  439. goto error_put_ckpt_destroy;
  440. }
  441. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointopen,
  442. sizeof (struct res_lib_ckpt_checkpointopen), MSG_WAITALL | MSG_NOSIGNAL);
  443. if (error != SA_AIS_OK) {
  444. goto error_put_ckpt_destroy;
  445. }
  446. if (res_lib_ckpt_checkpointopen.header.error != SA_AIS_OK) {
  447. error = res_lib_ckpt_checkpointopen.header.error;
  448. goto error_put_ckpt_destroy;
  449. }
  450. pthread_mutex_init (&ckptCheckpointInstance->mutex, NULL);
  451. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  452. return (error);
  453. error_put_ckpt_destroy:
  454. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  455. error_put_destroy:
  456. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  457. error_destroy:
  458. saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle);
  459. error_no_destroy:
  460. return (error);
  461. }
  462. SaAisErrorT
  463. saCkptCheckpointOpenAsync (
  464. const SaCkptHandleT ckptHandle,
  465. SaInvocationT invocation,
  466. const SaNameT *checkpointName,
  467. const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes,
  468. SaCkptCheckpointOpenFlagsT checkpointOpenFlags)
  469. {
  470. struct ckptInstance *ckptInstance;
  471. SaAisErrorT error;
  472. struct req_lib_ckpt_checkpointopenasync req_lib_ckpt_checkpointopenasync;
  473. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  474. if (error != SA_AIS_OK) {
  475. return (error);
  476. }
  477. req_lib_ckpt_checkpointopenasync.header.size = sizeof (struct req_lib_ckpt_checkpointopenasync);
  478. req_lib_ckpt_checkpointopenasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  479. req_lib_ckpt_checkpointopenasync.invocation = invocation;
  480. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointName, checkpointName, sizeof (SaNameT));
  481. memcpy (&req_lib_ckpt_checkpointopenasync.checkpointCreationAttributes,
  482. checkpointCreationAttributes,
  483. sizeof (SaCkptCheckpointCreationAttributesT));
  484. req_lib_ckpt_checkpointopenasync.checkpointOpenFlags = checkpointOpenFlags;
  485. pthread_mutex_lock (&ckptInstance->mutex);
  486. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointopenasync,
  487. sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL);
  488. pthread_mutex_unlock (&ckptInstance->mutex);
  489. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  490. return (error);
  491. }
  492. SaAisErrorT
  493. saCkptCheckpointClose (
  494. SaCkptCheckpointHandleT checkpointHandle)
  495. {
  496. struct req_lib_ckpt_checkpointclose req_lib_ckpt_checkpointclose;
  497. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  498. SaAisErrorT error;
  499. struct ckptCheckpointInstance *ckptCheckpointInstance;
  500. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  501. (void *)&ckptCheckpointInstance);
  502. if (error != SA_AIS_OK) {
  503. goto error_exit;
  504. }
  505. req_lib_ckpt_checkpointclose.header.size = sizeof (struct req_lib_ckpt_checkpointclose);
  506. req_lib_ckpt_checkpointclose.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  507. memcpy (&req_lib_ckpt_checkpointclose.checkpointName,
  508. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  509. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointclose,
  510. sizeof (struct req_lib_ckpt_checkpointclose), MSG_NOSIGNAL);
  511. if (error != SA_AIS_OK) {
  512. goto exit_put;
  513. }
  514. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_checkpointclose,
  515. sizeof (struct res_lib_ckpt_checkpointclose), MSG_WAITALL | MSG_NOSIGNAL);
  516. saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle);
  517. saHandleDestroy (&checkpointHandleDatabase, checkpointHandle);
  518. exit_put:
  519. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  520. error_exit:
  521. return (error);
  522. }
  523. SaAisErrorT
  524. saCkptCheckpointUnlink (
  525. SaCkptHandleT ckptHandle,
  526. const SaNameT *checkpointName)
  527. {
  528. SaAisErrorT error;
  529. struct ckptInstance *ckptInstance;
  530. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  531. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  532. error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance);
  533. if (error != SA_AIS_OK) {
  534. goto exit_noclose;
  535. }
  536. req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink);
  537. req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  538. memcpy (&req_lib_ckpt_checkpointunlink.checkpointName, checkpointName, sizeof (SaNameT));
  539. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointunlink,
  540. sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL);
  541. if (error != SA_AIS_OK) {
  542. goto exit_put;
  543. }
  544. error = saRecvRetry (ckptInstance->fd, &res_lib_ckpt_checkpointunlink,
  545. sizeof (struct res_lib_ckpt_checkpointunlink), MSG_WAITALL | MSG_NOSIGNAL);
  546. exit_put:
  547. saHandleInstancePut (&ckptHandleDatabase, ckptHandle);
  548. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error);
  549. exit_noclose:
  550. return (error);
  551. }
  552. SaAisErrorT
  553. saCkptCheckpointRetentionDurationSet (
  554. SaCkptCheckpointHandleT checkpointHandle,
  555. SaTimeT retentionDuration)
  556. {
  557. SaAisErrorT error;
  558. struct ckptCheckpointInstance *ckptCheckpointInstance;
  559. struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset;
  560. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  561. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  562. (void *)&ckptCheckpointInstance);
  563. if (error != SA_AIS_OK) {
  564. goto error_exit_noput;
  565. }
  566. req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset);
  567. req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  568. req_lib_ckpt_checkpointretentiondurationset.retentionDuration = retentionDuration;
  569. memcpy (&req_lib_ckpt_checkpointretentiondurationset.checkpointName,
  570. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  571. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  572. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL);
  573. if (error != SA_AIS_OK) {
  574. goto error_exit;
  575. }
  576. error = saRecvRetry (ckptCheckpointInstance->fd,
  577. &res_lib_ckpt_checkpointretentiondurationset,
  578. sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  579. MSG_WAITALL | MSG_NOSIGNAL);
  580. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  581. error_exit:
  582. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  583. error_exit_noput:
  584. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error);
  585. }
  586. SaAisErrorT
  587. saCkptActiveCheckpointSet (
  588. SaCkptCheckpointHandleT checkpointHandle)
  589. {
  590. SaAisErrorT error;
  591. struct ckptCheckpointInstance *ckptCheckpointInstance;
  592. struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset;
  593. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  594. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  595. (void *)&ckptCheckpointInstance);
  596. if (error != SA_AIS_OK) {
  597. goto error_exit;
  598. }
  599. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  600. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVEREPLICASET;
  601. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  602. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_activereplicaset,
  603. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  604. if (error != SA_AIS_OK) {
  605. goto error_exit;
  606. }
  607. error = saRecvRetry (ckptCheckpointInstance->fd,
  608. &res_lib_ckpt_activereplicaset,
  609. sizeof (struct res_lib_ckpt_activereplicaset),
  610. MSG_WAITALL | MSG_NOSIGNAL);
  611. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  612. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  613. error_exit:
  614. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  615. }
  616. SaAisErrorT
  617. saCkptCheckpointStatusGet (
  618. SaCkptCheckpointHandleT checkpointHandle,
  619. SaCkptCheckpointDescriptorT *checkpointStatus)
  620. {
  621. SaAisErrorT error;
  622. struct ckptCheckpointInstance *ckptCheckpointInstance;
  623. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  624. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  625. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  626. (void *)&ckptCheckpointInstance);
  627. if (error != SA_AIS_OK) {
  628. return (error);
  629. }
  630. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  631. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  632. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  633. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  634. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  635. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointstatusget,
  636. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  637. if (error != SA_AIS_OK) {
  638. goto error_exit;
  639. }
  640. error = saRecvRetry (ckptCheckpointInstance->fd,
  641. &res_lib_ckpt_checkpointstatusget,
  642. sizeof (struct res_lib_ckpt_checkpointstatusget),
  643. MSG_WAITALL | MSG_NOSIGNAL);
  644. if (error != SA_AIS_OK) {
  645. goto error_exit;
  646. }
  647. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  648. memcpy (checkpointStatus,
  649. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  650. sizeof (SaCkptCheckpointDescriptorT));
  651. error_exit:
  652. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  653. return (error);
  654. }
  655. SaAisErrorT
  656. saCkptSectionCreate (
  657. SaCkptCheckpointHandleT checkpointHandle,
  658. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  659. const void *initialData,
  660. SaUint32T initialDataSize)
  661. {
  662. SaAisErrorT error;
  663. struct ckptCheckpointInstance *ckptCheckpointInstance;
  664. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  665. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  666. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  667. (void *)&ckptCheckpointInstance);
  668. if (error != SA_AIS_OK) {
  669. return (error);
  670. }
  671. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  672. error = SA_AIS_ERR_ACCESS;
  673. goto error_exit;
  674. }
  675. req_lib_ckpt_sectioncreate.header.size =
  676. sizeof (struct req_lib_ckpt_sectioncreate) +
  677. sectionCreationAttributes->sectionId->idLen +
  678. initialDataSize;
  679. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  680. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  681. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  682. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  683. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  684. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  685. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  686. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectioncreate,
  687. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  688. if (error != SA_AIS_OK) {
  689. goto error_exit;
  690. }
  691. /*
  692. * Write section identifier to server
  693. */
  694. error = saSendRetry (ckptCheckpointInstance->fd, sectionCreationAttributes->sectionId->id,
  695. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  696. if (error != SA_AIS_OK) {
  697. goto error_exit;
  698. }
  699. error = saSendRetry (ckptCheckpointInstance->fd, initialData,
  700. initialDataSize, MSG_NOSIGNAL);
  701. if (error != SA_AIS_OK) {
  702. goto error_exit;
  703. }
  704. error = saRecvRetry (ckptCheckpointInstance->fd,
  705. &res_lib_ckpt_sectioncreate,
  706. sizeof (struct res_lib_ckpt_sectioncreate),
  707. MSG_WAITALL | MSG_NOSIGNAL);
  708. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  709. error_exit:
  710. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  711. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  712. }
  713. SaAisErrorT
  714. saCkptSectionDelete (
  715. SaCkptCheckpointHandleT checkpointHandle,
  716. const SaCkptSectionIdT *sectionId)
  717. {
  718. SaAisErrorT error;
  719. struct ckptCheckpointInstance *ckptCheckpointInstance;
  720. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  721. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  722. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  723. (void *)&ckptCheckpointInstance);
  724. if (error != SA_AIS_OK) {
  725. return (error);
  726. }
  727. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  728. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  729. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  730. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  731. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  732. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  733. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectiondelete,
  734. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  735. if (error != SA_AIS_OK) {
  736. goto error_exit;
  737. }
  738. /*
  739. * Write section identifier to server
  740. */
  741. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  742. sectionId->idLen, MSG_NOSIGNAL);
  743. if (error != SA_AIS_OK) {
  744. goto error_exit;
  745. }
  746. error = saRecvRetry (ckptCheckpointInstance->fd,
  747. &res_lib_ckpt_sectiondelete,
  748. sizeof (struct res_lib_ckpt_sectiondelete),
  749. MSG_WAITALL | MSG_NOSIGNAL);
  750. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  751. error_exit:
  752. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  753. return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  754. }
  755. SaAisErrorT
  756. saCkptSectionExpirationTimeSet (
  757. SaCkptCheckpointHandleT checkpointHandle,
  758. const SaCkptSectionIdT *sectionId,
  759. SaTimeT expirationTime)
  760. {
  761. SaAisErrorT error;
  762. struct ckptCheckpointInstance *ckptCheckpointInstance;
  763. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  764. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  765. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  766. (void *)&ckptCheckpointInstance);
  767. if (error != SA_AIS_OK) {
  768. goto error_exit_noput;
  769. }
  770. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  771. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  772. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  773. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  774. memcpy (&req_lib_ckpt_sectionexpirationtimeset.checkpointName,
  775. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  776. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  777. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionexpirationtimeset,
  778. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  779. if (error != SA_AIS_OK) {
  780. goto error_exit;
  781. }
  782. /*
  783. * Write section identifier to server
  784. */
  785. if (sectionId->idLen) {
  786. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  787. sectionId->idLen, MSG_NOSIGNAL);
  788. if (error != SA_AIS_OK) {
  789. goto error_exit;
  790. }
  791. }
  792. error = saRecvRetry (ckptCheckpointInstance->fd,
  793. &res_lib_ckpt_sectionexpirationtimeset,
  794. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  795. MSG_WAITALL | MSG_NOSIGNAL);
  796. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  797. error_exit:
  798. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  799. error_exit_noput:
  800. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  801. }
  802. SaAisErrorT
  803. saCkptSectionIterationInitialize (
  804. SaCkptCheckpointHandleT checkpointHandle,
  805. SaCkptSectionsChosenT sectionsChosen,
  806. SaTimeT expirationTime,
  807. SaCkptSectionIterationHandleT *sectionIterationHandle)
  808. {
  809. SaAisErrorT error;
  810. struct ckptCheckpointInstance *ckptCheckpointInstance;
  811. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  812. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  813. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  814. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  815. (void *)&ckptCheckpointInstance);
  816. if (error != SA_AIS_OK) {
  817. goto error_no_destroy;
  818. }
  819. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  820. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  821. if (error != SA_AIS_OK) {
  822. goto error_put_checkpoint_db;
  823. }
  824. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  825. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  826. if (error != SA_AIS_OK) {
  827. goto error_destroy;
  828. }
  829. ckptSectionIterationInstance->fd = ckptCheckpointInstance->fd;
  830. ckptSectionIterationInstance->checkpointHandle = checkpointHandle;
  831. pthread_mutex_init (&ckptSectionIterationInstance->mutex, NULL);
  832. /*
  833. * Setup section id list for iterator next
  834. */
  835. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  836. ckptSectionIterationInstance->maxSectionIdSize =
  837. ckptCheckpointInstance->maxSectionIdSize;
  838. error = saServiceConnect (&ckptSectionIterationInstance->fd,
  839. MESSAGE_REQ_CKPT_INIT);
  840. if (error != SA_AIS_OK) {
  841. goto error_put_destroy;
  842. }
  843. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  844. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  845. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  846. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  847. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  848. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  849. pthread_mutex_lock (&ckptSectionIterationInstance->mutex);
  850. error = saSendRetry (ckptSectionIterationInstance->fd,
  851. &req_lib_ckpt_sectioniteratorinitialize,
  852. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  853. MSG_NOSIGNAL);
  854. if (error != SA_AIS_OK) {
  855. goto error_put_destroy;
  856. }
  857. error = saRecvRetry (ckptSectionIterationInstance->fd,
  858. &res_lib_ckpt_sectioniteratorinitialize,
  859. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  860. MSG_WAITALL | MSG_NOSIGNAL);
  861. pthread_mutex_unlock (&ckptSectionIterationInstance->mutex);
  862. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  863. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
  864. error_put_destroy:
  865. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  866. error_destroy:
  867. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  868. error_put_checkpoint_db:
  869. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  870. error_no_destroy:
  871. return (error);
  872. }
  873. struct iteratorSectionIdListEntry {
  874. struct list_head list;
  875. char data[0];
  876. };
  877. SaAisErrorT
  878. saCkptSectionIterationNext (
  879. SaCkptSectionIterationHandleT sectionIterationHandle,
  880. SaCkptSectionDescriptorT *sectionDescriptor)
  881. {
  882. SaAisErrorT error;
  883. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  884. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  885. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  886. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  887. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  888. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  889. if (error != SA_AIS_OK) {
  890. goto error_exit;
  891. }
  892. /*
  893. * Allocate section id storage area
  894. */
  895. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  896. ckptSectionIterationInstance->maxSectionIdSize);
  897. if (iteratorSectionIdListEntry == 0) {
  898. error = SA_AIS_ERR_NO_MEMORY;
  899. goto error_put_nounlock;
  900. }
  901. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  902. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  903. pthread_mutex_lock (&ckptSectionIterationInstance->mutex);
  904. error = saSendRetry (ckptSectionIterationInstance->fd,
  905. &req_lib_ckpt_sectioniteratornext,
  906. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  907. if (error != SA_AIS_OK) {
  908. goto error_put;
  909. }
  910. error = saRecvRetry (ckptSectionIterationInstance->fd, &res_lib_ckpt_sectioniteratornext,
  911. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  912. if (error != SA_AIS_OK) {
  913. goto error_put;
  914. }
  915. memcpy (sectionDescriptor,
  916. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  917. sizeof (SaCkptSectionDescriptorT));
  918. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  919. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  920. error = saRecvRetry (ckptSectionIterationInstance->fd,
  921. sectionDescriptor->sectionId.id,
  922. res_lib_ckpt_sectioniteratornext.header.size -
  923. sizeof (struct res_lib_ckpt_sectioniteratornext),
  924. MSG_WAITALL | MSG_NOSIGNAL);
  925. }
  926. /*
  927. * Add to persistent memory list for this sectioniterator
  928. */
  929. if (error == SA_AIS_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_AIS_OK) {
  930. list_init (&iteratorSectionIdListEntry->list);
  931. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  932. }
  933. error_put:
  934. pthread_mutex_unlock (&ckptSectionIterationInstance->mutex);
  935. error_put_nounlock:
  936. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  937. error_exit:
  938. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  939. }
  940. SaAisErrorT
  941. saCkptSectionIterationFinalize (
  942. SaCkptSectionIterationHandleT sectionIterationHandle)
  943. {
  944. SaAisErrorT error;
  945. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  946. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  947. struct list_head *sectionIdIterationList;
  948. struct list_head *sectionIdIterationListNext;
  949. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  950. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  951. if (error != SA_AIS_OK) {
  952. goto error_noput;
  953. }
  954. /*
  955. * iterate list of section ids for this iterator to free the allocated memory
  956. * be careful to cache next pointer because free removes memory from use
  957. */
  958. for (sectionIdIterationList = ckptSectionIterationInstance->sectionIdListHead.next,
  959. sectionIdIterationListNext = sectionIdIterationList->next;
  960. sectionIdIterationList != &ckptSectionIterationInstance->sectionIdListHead;
  961. sectionIdIterationList = sectionIdIterationListNext,
  962. sectionIdIterationListNext = sectionIdIterationList->next) {
  963. iteratorSectionIdListEntry = list_entry (sectionIdIterationList,
  964. struct iteratorSectionIdListEntry, list);
  965. free (iteratorSectionIdListEntry);
  966. }
  967. saHandleInstancePut (&checkpointHandleDatabase,
  968. ckptSectionIterationInstance->checkpointHandle);
  969. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  970. saHandleDestroy (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  971. error_noput:
  972. return (error);
  973. }
  974. SaAisErrorT
  975. saCkptCheckpointWrite (
  976. SaCkptCheckpointHandleT checkpointHandle,
  977. const SaCkptIOVectorElementT *ioVector,
  978. SaUint32T numberOfElements,
  979. SaUint32T *erroneousVectorIndex)
  980. {
  981. SaAisErrorT error = SA_AIS_OK;
  982. struct ckptCheckpointInstance *ckptCheckpointInstance;
  983. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  984. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  985. int i;
  986. struct iovec iov[3];
  987. int iov_len = 0;
  988. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  989. (void *)&ckptCheckpointInstance);
  990. if (error != SA_AIS_OK) {
  991. return (error);
  992. }
  993. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  994. error = SA_AIS_ERR_ACCESS;
  995. goto error_put;
  996. }
  997. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  998. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  999. for (i = 0; i < numberOfElements; i++) {
  1000. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  1001. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  1002. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  1003. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  1004. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  1005. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1006. iov_len = 0;
  1007. /* TODO check for zero length stuff */
  1008. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  1009. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  1010. iov[1].iov_base = ioVector[i].sectionId.id;
  1011. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1012. iov[2].iov_base = ioVector[i].dataBuffer;
  1013. iov[2].iov_len = ioVector[i].dataSize;
  1014. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  1015. iov,
  1016. 3);
  1017. if (error != SA_AIS_OK) {
  1018. goto error_exit;
  1019. }
  1020. /*
  1021. * Receive response
  1022. */
  1023. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionwrite,
  1024. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1025. if (error != SA_AIS_OK) {
  1026. goto error_exit;
  1027. }
  1028. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1029. error = SA_AIS_ERR_TRY_AGAIN;
  1030. goto error_exit;
  1031. }
  1032. /*
  1033. * If error, report back erroneous index
  1034. */
  1035. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1036. if (erroneousVectorIndex) {
  1037. *erroneousVectorIndex = i;
  1038. }
  1039. goto error_exit;
  1040. }
  1041. }
  1042. error_exit:
  1043. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1044. error_put:
  1045. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1046. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1047. }
  1048. SaAisErrorT
  1049. saCkptSectionOverwrite (
  1050. SaCkptCheckpointHandleT checkpointHandle,
  1051. const SaCkptSectionIdT *sectionId,
  1052. const void *dataBuffer,
  1053. SaSizeT dataSize)
  1054. {
  1055. SaAisErrorT error;
  1056. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1057. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1058. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1059. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1060. (void *)&ckptCheckpointInstance);
  1061. if (error != SA_AIS_OK) {
  1062. return (error);
  1063. }
  1064. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1065. return (SA_AIS_ERR_ACCESS);
  1066. }
  1067. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1068. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1069. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1070. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1071. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1072. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1073. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1074. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_sectionoverwrite,
  1075. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1076. if (error != SA_AIS_OK) {
  1077. goto error_exit;
  1078. }
  1079. if (sectionId->idLen) {
  1080. error = saSendRetry (ckptCheckpointInstance->fd, sectionId->id,
  1081. sectionId->idLen, MSG_NOSIGNAL);
  1082. if (error != SA_AIS_OK) {
  1083. goto error_exit;
  1084. }
  1085. }
  1086. error = saSendRetry (ckptCheckpointInstance->fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1087. if (error != SA_AIS_OK) {
  1088. goto error_exit;
  1089. }
  1090. error = saRecvRetry (ckptCheckpointInstance->fd,
  1091. &res_lib_ckpt_sectionoverwrite,
  1092. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1093. MSG_WAITALL | MSG_NOSIGNAL);
  1094. error_exit:
  1095. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1096. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1097. return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1098. }
  1099. SaAisErrorT
  1100. saCkptCheckpointRead (
  1101. SaCkptCheckpointHandleT checkpointHandle,
  1102. SaCkptIOVectorElementT *ioVector,
  1103. SaUint32T numberOfElements,
  1104. SaUint32T *erroneousVectorIndex)
  1105. {
  1106. SaAisErrorT error = SA_AIS_OK;
  1107. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1108. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1109. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1110. int dataLength;
  1111. int i;
  1112. struct iovec iov[3];
  1113. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1114. (void *)&ckptCheckpointInstance);
  1115. if (error != SA_AIS_OK) {
  1116. return (error);
  1117. }
  1118. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1119. return (SA_AIS_ERR_ACCESS);
  1120. }
  1121. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1122. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1123. for (i = 0; i < numberOfElements; i++) {
  1124. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1125. ioVector[i].sectionId.idLen;
  1126. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1127. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1128. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1129. memcpy (&req_lib_ckpt_sectionread.checkpointName,
  1130. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1131. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1132. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1133. iov[1].iov_base = ioVector[i].sectionId.id;
  1134. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1135. error = saSendMsgRetry (ckptCheckpointInstance->fd,
  1136. iov,
  1137. 2);
  1138. /*
  1139. * Receive response header
  1140. */
  1141. error = saRecvRetry (ckptCheckpointInstance->fd, &res_lib_ckpt_sectionread,
  1142. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1143. if (error != SA_AIS_OK) {
  1144. goto error_exit;
  1145. }
  1146. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1147. /*
  1148. * Receive checkpoint section data
  1149. */
  1150. if (dataLength > 0) {
  1151. error = saRecvRetry (ckptCheckpointInstance->fd, ioVector[i].dataBuffer,
  1152. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1153. if (error != SA_AIS_OK) {
  1154. goto error_exit;
  1155. }
  1156. }
  1157. if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) {
  1158. if (erroneousVectorIndex) {
  1159. *erroneousVectorIndex = i;
  1160. }
  1161. goto error_exit;
  1162. }
  1163. /*
  1164. * Report back bytes of data read
  1165. */
  1166. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1167. }
  1168. error_exit:
  1169. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1170. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1171. return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error);
  1172. }
  1173. SaAisErrorT
  1174. saCkptCheckpointSynchronize (
  1175. SaCkptCheckpointHandleT checkpointHandle,
  1176. SaTimeT timeout)
  1177. {
  1178. SaAisErrorT error;
  1179. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1180. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1181. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1182. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1183. (void *)&ckptCheckpointInstance);
  1184. if (error != SA_AIS_OK) {
  1185. return (error);
  1186. }
  1187. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1188. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1189. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1190. error = saSendRetry (ckptCheckpointInstance->fd, &req_lib_ckpt_checkpointsynchronize,
  1191. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1192. if (error != SA_AIS_OK) {
  1193. goto error_exit;
  1194. }
  1195. error = saRecvRetry (ckptCheckpointInstance->fd,
  1196. &res_lib_ckpt_checkpointsynchronize,
  1197. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1198. MSG_WAITALL | MSG_NOSIGNAL);
  1199. error_exit:
  1200. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1201. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1202. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1203. }
  1204. SaAisErrorT
  1205. saCkptCheckpointSynchronizeAsync (
  1206. SaCkptHandleT ckptHandle,
  1207. SaCkptCheckpointHandleT checkpointHandle,
  1208. SaInvocationT invocation)
  1209. {
  1210. return (SA_AIS_OK);
  1211. /* TODO not implemented in executive
  1212. struct ckptInstance *ckptInstance;
  1213. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1214. SaAisErrorT error;
  1215. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1216. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1217. (void *)&ckptCheckpointInstance);
  1218. if (error != SA_AIS_OK) {
  1219. return (error);
  1220. }
  1221. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1222. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1223. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1224. pthread_mutex_lock (&ckptCheckpointInstance->mutex);
  1225. pthread_mutex_lock (&ckptInstance->mutex);
  1226. error = saSendRetry (ckptInstance->fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1227. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1228. pthread_mutex_unlock (&ckptInstance->mutex);
  1229. pthread_mutex_unlock (&ckptCheckpointInstance->mutex);
  1230. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1231. return (error);
  1232. */
  1233. }