ckpt.c 46 KB

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