ckpt.c 47 KB

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