ckpt.c 47 KB

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