ckpt.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  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_exit;
  586. }
  587. req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset);
  588. req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_ACTIVEREPLICASET;
  589. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  590. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset,
  591. sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL);
  592. if (error != SA_AIS_OK) {
  593. goto error_exit;
  594. }
  595. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  596. &res_lib_ckpt_activereplicaset,
  597. sizeof (struct res_lib_ckpt_activereplicaset),
  598. MSG_WAITALL | MSG_NOSIGNAL);
  599. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  600. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  601. error_exit:
  602. return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error);
  603. }
  604. SaAisErrorT
  605. saCkptCheckpointStatusGet (
  606. SaCkptCheckpointHandleT checkpointHandle,
  607. SaCkptCheckpointDescriptorT *checkpointStatus)
  608. {
  609. SaAisErrorT error;
  610. struct ckptCheckpointInstance *ckptCheckpointInstance;
  611. struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget;
  612. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  613. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  614. (void *)&ckptCheckpointInstance);
  615. if (error != SA_AIS_OK) {
  616. return (error);
  617. }
  618. req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget);
  619. req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  620. memcpy (&req_lib_ckpt_checkpointstatusget.checkpointName,
  621. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  622. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  623. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget,
  624. sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL);
  625. if (error != SA_AIS_OK) {
  626. goto error_exit;
  627. }
  628. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  629. &res_lib_ckpt_checkpointstatusget,
  630. sizeof (struct res_lib_ckpt_checkpointstatusget),
  631. MSG_WAITALL | MSG_NOSIGNAL);
  632. if (error != SA_AIS_OK) {
  633. goto error_exit;
  634. }
  635. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  636. memcpy (checkpointStatus,
  637. &res_lib_ckpt_checkpointstatusget.checkpointDescriptor,
  638. sizeof (SaCkptCheckpointDescriptorT));
  639. error_exit:
  640. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  641. return (error);
  642. }
  643. SaAisErrorT
  644. saCkptSectionCreate (
  645. SaCkptCheckpointHandleT checkpointHandle,
  646. SaCkptSectionCreationAttributesT *sectionCreationAttributes,
  647. const void *initialData,
  648. SaUint32T initialDataSize)
  649. {
  650. SaAisErrorT error;
  651. struct ckptCheckpointInstance *ckptCheckpointInstance;
  652. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate;
  653. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  654. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  655. (void *)&ckptCheckpointInstance);
  656. if (error != SA_AIS_OK) {
  657. return (error);
  658. }
  659. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  660. error = SA_AIS_ERR_ACCESS;
  661. goto error_exit;
  662. }
  663. req_lib_ckpt_sectioncreate.header.size =
  664. sizeof (struct req_lib_ckpt_sectioncreate) +
  665. sectionCreationAttributes->sectionId->idLen +
  666. initialDataSize;
  667. req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE;
  668. req_lib_ckpt_sectioncreate.idLen = sectionCreationAttributes->sectionId->idLen;
  669. req_lib_ckpt_sectioncreate.expirationTime = sectionCreationAttributes->expirationTime;
  670. req_lib_ckpt_sectioncreate.initialDataSize = initialDataSize;
  671. memcpy (&req_lib_ckpt_sectioncreate.checkpointName,
  672. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  673. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  674. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate,
  675. sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL);
  676. if (error != SA_AIS_OK) {
  677. goto error_exit;
  678. }
  679. /*
  680. * Write section identifier to server
  681. */
  682. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id,
  683. sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL);
  684. if (error != SA_AIS_OK) {
  685. goto error_exit;
  686. }
  687. error = saSendRetry (ckptCheckpointInstance->response_fd, initialData,
  688. initialDataSize, MSG_NOSIGNAL);
  689. if (error != SA_AIS_OK) {
  690. goto error_exit;
  691. }
  692. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  693. &res_lib_ckpt_sectioncreate,
  694. sizeof (struct res_lib_ckpt_sectioncreate),
  695. MSG_WAITALL | MSG_NOSIGNAL);
  696. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  697. error_exit:
  698. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  699. return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error);
  700. }
  701. SaAisErrorT
  702. saCkptSectionDelete (
  703. SaCkptCheckpointHandleT checkpointHandle,
  704. const SaCkptSectionIdT *sectionId)
  705. {
  706. SaAisErrorT error;
  707. struct ckptCheckpointInstance *ckptCheckpointInstance;
  708. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete;
  709. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  710. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  711. (void *)&ckptCheckpointInstance);
  712. if (error != SA_AIS_OK) {
  713. return (error);
  714. }
  715. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  716. req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen;
  717. req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE;
  718. req_lib_ckpt_sectiondelete.idLen = sectionId->idLen;
  719. memcpy (&req_lib_ckpt_sectiondelete.checkpointName,
  720. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  721. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete,
  722. sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL);
  723. if (error != SA_AIS_OK) {
  724. goto error_exit;
  725. }
  726. /*
  727. * Write section identifier to server
  728. */
  729. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  730. sectionId->idLen, MSG_NOSIGNAL);
  731. if (error != SA_AIS_OK) {
  732. goto error_exit;
  733. }
  734. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  735. &res_lib_ckpt_sectiondelete,
  736. sizeof (struct res_lib_ckpt_sectiondelete),
  737. MSG_WAITALL | MSG_NOSIGNAL);
  738. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  739. error_exit:
  740. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  741. return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error);
  742. }
  743. SaAisErrorT
  744. saCkptSectionExpirationTimeSet (
  745. SaCkptCheckpointHandleT checkpointHandle,
  746. const SaCkptSectionIdT *sectionId,
  747. SaTimeT expirationTime)
  748. {
  749. SaAisErrorT error;
  750. struct ckptCheckpointInstance *ckptCheckpointInstance;
  751. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  752. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  753. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  754. (void *)&ckptCheckpointInstance);
  755. if (error != SA_AIS_OK) {
  756. goto error_exit_noput;
  757. }
  758. req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen;
  759. req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  760. req_lib_ckpt_sectionexpirationtimeset.idLen = sectionId->idLen;
  761. req_lib_ckpt_sectionexpirationtimeset.expirationTime = expirationTime;
  762. memcpy (&req_lib_ckpt_sectionexpirationtimeset.checkpointName,
  763. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  764. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  765. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset,
  766. sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL);
  767. if (error != SA_AIS_OK) {
  768. goto error_exit;
  769. }
  770. /*
  771. * Write section identifier to server
  772. */
  773. if (sectionId->idLen) {
  774. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  775. sectionId->idLen, MSG_NOSIGNAL);
  776. if (error != SA_AIS_OK) {
  777. goto error_exit;
  778. }
  779. }
  780. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  781. &res_lib_ckpt_sectionexpirationtimeset,
  782. sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  783. MSG_WAITALL | MSG_NOSIGNAL);
  784. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  785. error_exit:
  786. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  787. error_exit_noput:
  788. return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error);
  789. }
  790. SaAisErrorT
  791. saCkptSectionIterationInitialize (
  792. SaCkptCheckpointHandleT checkpointHandle,
  793. SaCkptSectionsChosenT sectionsChosen,
  794. SaTimeT expirationTime,
  795. SaCkptSectionIterationHandleT *sectionIterationHandle)
  796. {
  797. SaAisErrorT error;
  798. struct ckptCheckpointInstance *ckptCheckpointInstance;
  799. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  800. struct req_lib_ckpt_sectioniteratorinitialize req_lib_ckpt_sectioniteratorinitialize;
  801. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  802. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  803. (void *)&ckptCheckpointInstance);
  804. if (error != SA_AIS_OK) {
  805. goto error_no_destroy;
  806. }
  807. error = saHandleCreate (&ckptSectionIterationHandleDatabase,
  808. sizeof (struct ckptSectionIterationInstance), sectionIterationHandle);
  809. if (error != SA_AIS_OK) {
  810. goto error_put_checkpoint_db;
  811. }
  812. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  813. *sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  814. if (error != SA_AIS_OK) {
  815. goto error_destroy;
  816. }
  817. ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd;
  818. ckptSectionIterationInstance->checkpointHandle = checkpointHandle;
  819. pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL);
  820. /*
  821. * Setup section id list for iterator next
  822. */
  823. list_init (&ckptSectionIterationInstance->sectionIdListHead);
  824. ckptSectionIterationInstance->maxSectionIdSize =
  825. ckptCheckpointInstance->maxSectionIdSize;
  826. req_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniteratorinitialize);
  827. req_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  828. req_lib_ckpt_sectioniteratorinitialize.sectionsChosen = sectionsChosen;
  829. req_lib_ckpt_sectioniteratorinitialize.expirationTime = expirationTime;
  830. memcpy (&req_lib_ckpt_sectioniteratorinitialize.checkpointName,
  831. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  832. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  833. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  834. &req_lib_ckpt_sectioniteratorinitialize,
  835. sizeof (struct req_lib_ckpt_sectioniteratorinitialize),
  836. MSG_NOSIGNAL);
  837. if (error != SA_AIS_OK) {
  838. goto error_put_destroy;
  839. }
  840. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  841. &res_lib_ckpt_sectioniteratorinitialize,
  842. sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  843. MSG_WAITALL | MSG_NOSIGNAL);
  844. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  845. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  846. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratorinitialize.header.error : error);
  847. error_put_destroy:
  848. saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  849. error_destroy:
  850. saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle);
  851. error_put_checkpoint_db:
  852. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  853. error_no_destroy:
  854. return (error);
  855. }
  856. struct iteratorSectionIdListEntry {
  857. struct list_head list;
  858. char data[0];
  859. };
  860. SaAisErrorT
  861. saCkptSectionIterationNext (
  862. SaCkptSectionIterationHandleT sectionIterationHandle,
  863. SaCkptSectionDescriptorT *sectionDescriptor)
  864. {
  865. SaAisErrorT error;
  866. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  867. struct req_lib_ckpt_sectioniteratornext req_lib_ckpt_sectioniteratornext;
  868. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  869. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  870. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  871. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  872. if (error != SA_AIS_OK) {
  873. goto error_exit;
  874. }
  875. /*
  876. * Allocate section id storage area
  877. */
  878. iteratorSectionIdListEntry = malloc (sizeof (struct list_head) +
  879. ckptSectionIterationInstance->maxSectionIdSize);
  880. if (iteratorSectionIdListEntry == 0) {
  881. error = SA_AIS_ERR_NO_MEMORY;
  882. goto error_put_nounlock;
  883. }
  884. req_lib_ckpt_sectioniteratornext.header.size = sizeof (struct req_lib_ckpt_sectioniteratornext);
  885. req_lib_ckpt_sectioniteratornext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  886. pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex);
  887. error = saSendRetry (ckptSectionIterationInstance->response_fd,
  888. &req_lib_ckpt_sectioniteratornext,
  889. sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL);
  890. if (error != SA_AIS_OK) {
  891. goto error_put;
  892. }
  893. error = saRecvRetry (ckptSectionIterationInstance->response_fd, &res_lib_ckpt_sectioniteratornext,
  894. sizeof (struct res_lib_ckpt_sectioniteratornext), MSG_WAITALL | MSG_NOSIGNAL);
  895. if (error != SA_AIS_OK) {
  896. goto error_put;
  897. }
  898. memcpy (sectionDescriptor,
  899. &res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  900. sizeof (SaCkptSectionDescriptorT));
  901. sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0];
  902. if ((res_lib_ckpt_sectioniteratornext.header.size - sizeof (struct res_lib_ckpt_sectioniteratornext)) > 0) {
  903. error = saRecvRetry (ckptSectionIterationInstance->response_fd,
  904. sectionDescriptor->sectionId.id,
  905. res_lib_ckpt_sectioniteratornext.header.size -
  906. sizeof (struct res_lib_ckpt_sectioniteratornext),
  907. MSG_WAITALL | MSG_NOSIGNAL);
  908. }
  909. /*
  910. * Add to persistent memory list for this sectioniterator
  911. */
  912. if (error == SA_AIS_OK && res_lib_ckpt_sectioniteratornext.header.error == SA_AIS_OK) {
  913. list_init (&iteratorSectionIdListEntry->list);
  914. list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead);
  915. }
  916. error_put:
  917. pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex);
  918. error_put_nounlock:
  919. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  920. error_exit:
  921. return (error == SA_AIS_OK ? res_lib_ckpt_sectioniteratornext.header.error : error);
  922. }
  923. SaAisErrorT
  924. saCkptSectionIterationFinalize (
  925. SaCkptSectionIterationHandleT sectionIterationHandle)
  926. {
  927. SaAisErrorT error;
  928. struct ckptSectionIterationInstance *ckptSectionIterationInstance;
  929. struct iteratorSectionIdListEntry *iteratorSectionIdListEntry;
  930. struct list_head *sectionIdIterationList;
  931. struct list_head *sectionIdIterationListNext;
  932. error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase,
  933. sectionIterationHandle, (void *)&ckptSectionIterationInstance);
  934. if (error != SA_AIS_OK) {
  935. goto error_noput;
  936. }
  937. /*
  938. * iterate list of section ids for this iterator to free the allocated memory
  939. * be careful to cache next pointer because free removes memory from use
  940. */
  941. for (sectionIdIterationList = ckptSectionIterationInstance->sectionIdListHead.next,
  942. sectionIdIterationListNext = sectionIdIterationList->next;
  943. sectionIdIterationList != &ckptSectionIterationInstance->sectionIdListHead;
  944. sectionIdIterationList = sectionIdIterationListNext,
  945. sectionIdIterationListNext = sectionIdIterationList->next) {
  946. iteratorSectionIdListEntry = list_entry (sectionIdIterationList,
  947. struct iteratorSectionIdListEntry, list);
  948. free (iteratorSectionIdListEntry);
  949. }
  950. saHandleInstancePut (&checkpointHandleDatabase,
  951. ckptSectionIterationInstance->checkpointHandle);
  952. saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  953. saHandleDestroy (&ckptSectionIterationHandleDatabase, sectionIterationHandle);
  954. error_noput:
  955. return (error);
  956. }
  957. SaAisErrorT
  958. saCkptCheckpointWrite (
  959. SaCkptCheckpointHandleT checkpointHandle,
  960. const SaCkptIOVectorElementT *ioVector,
  961. SaUint32T numberOfElements,
  962. SaUint32T *erroneousVectorIndex)
  963. {
  964. SaAisErrorT error = SA_AIS_OK;
  965. struct ckptCheckpointInstance *ckptCheckpointInstance;
  966. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  967. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  968. int i;
  969. struct iovec iov[3];
  970. int iov_len = 0;
  971. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  972. (void *)&ckptCheckpointInstance);
  973. if (error != SA_AIS_OK) {
  974. return (error);
  975. }
  976. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  977. error = SA_AIS_ERR_ACCESS;
  978. goto error_put;
  979. }
  980. req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE;
  981. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  982. for (i = 0; i < numberOfElements; i++) {
  983. req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize;
  984. req_lib_ckpt_sectionwrite.dataOffset = ioVector[i].dataOffset;
  985. req_lib_ckpt_sectionwrite.dataSize = ioVector[i].dataSize;
  986. req_lib_ckpt_sectionwrite.idLen = ioVector[i].sectionId.idLen;
  987. memcpy (&req_lib_ckpt_sectionwrite.checkpointName,
  988. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  989. iov_len = 0;
  990. /* TODO check for zero length stuff */
  991. iov[0].iov_base = (char *)&req_lib_ckpt_sectionwrite;
  992. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionwrite);
  993. iov[1].iov_base = ioVector[i].sectionId.id;
  994. iov[1].iov_len = ioVector[i].sectionId.idLen;
  995. iov[2].iov_base = ioVector[i].dataBuffer;
  996. iov[2].iov_len = ioVector[i].dataSize;
  997. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  998. iov,
  999. 3);
  1000. if (error != SA_AIS_OK) {
  1001. goto error_exit;
  1002. }
  1003. /*
  1004. * Receive response
  1005. */
  1006. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite,
  1007. sizeof (struct res_lib_ckpt_sectionwrite), MSG_WAITALL | MSG_NOSIGNAL);
  1008. if (error != SA_AIS_OK) {
  1009. goto error_exit;
  1010. }
  1011. if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) {
  1012. error = SA_AIS_ERR_TRY_AGAIN;
  1013. goto error_exit;
  1014. }
  1015. /*
  1016. * If error, report back erroneous index
  1017. */
  1018. if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) {
  1019. if (erroneousVectorIndex) {
  1020. *erroneousVectorIndex = i;
  1021. }
  1022. goto error_exit;
  1023. }
  1024. }
  1025. error_exit:
  1026. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1027. error_put:
  1028. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1029. return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error);
  1030. }
  1031. SaAisErrorT
  1032. saCkptSectionOverwrite (
  1033. SaCkptCheckpointHandleT checkpointHandle,
  1034. const SaCkptSectionIdT *sectionId,
  1035. const void *dataBuffer,
  1036. SaSizeT dataSize)
  1037. {
  1038. SaAisErrorT error;
  1039. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1040. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  1041. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1042. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1043. (void *)&ckptCheckpointInstance);
  1044. if (error != SA_AIS_OK) {
  1045. return (error);
  1046. }
  1047. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1048. return (SA_AIS_ERR_ACCESS);
  1049. }
  1050. req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize;
  1051. req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1052. req_lib_ckpt_sectionoverwrite.idLen = sectionId->idLen;
  1053. req_lib_ckpt_sectionoverwrite.dataSize = dataSize;
  1054. memcpy (&req_lib_ckpt_sectionoverwrite.checkpointName,
  1055. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1056. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1057. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite,
  1058. sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL);
  1059. if (error != SA_AIS_OK) {
  1060. goto error_exit;
  1061. }
  1062. if (sectionId->idLen) {
  1063. error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id,
  1064. sectionId->idLen, MSG_NOSIGNAL);
  1065. if (error != SA_AIS_OK) {
  1066. goto error_exit;
  1067. }
  1068. }
  1069. error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL);
  1070. if (error != SA_AIS_OK) {
  1071. goto error_exit;
  1072. }
  1073. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1074. &res_lib_ckpt_sectionoverwrite,
  1075. sizeof (struct res_lib_ckpt_sectionoverwrite),
  1076. MSG_WAITALL | MSG_NOSIGNAL);
  1077. error_exit:
  1078. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1079. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1080. return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error);
  1081. }
  1082. SaAisErrorT
  1083. saCkptCheckpointRead (
  1084. SaCkptCheckpointHandleT checkpointHandle,
  1085. SaCkptIOVectorElementT *ioVector,
  1086. SaUint32T numberOfElements,
  1087. SaUint32T *erroneousVectorIndex)
  1088. {
  1089. SaAisErrorT error = SA_AIS_OK;
  1090. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1091. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  1092. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1093. int dataLength;
  1094. int i;
  1095. struct iovec iov[3];
  1096. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1097. (void *)&ckptCheckpointInstance);
  1098. if (error != SA_AIS_OK) {
  1099. return (error);
  1100. }
  1101. if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1102. return (SA_AIS_ERR_ACCESS);
  1103. }
  1104. req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD;
  1105. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1106. for (i = 0; i < numberOfElements; i++) {
  1107. req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) +
  1108. ioVector[i].sectionId.idLen;
  1109. req_lib_ckpt_sectionread.idLen = ioVector[i].sectionId.idLen;
  1110. req_lib_ckpt_sectionread.dataOffset = ioVector[i].dataOffset;
  1111. req_lib_ckpt_sectionread.dataSize = ioVector[i].dataSize;
  1112. memcpy (&req_lib_ckpt_sectionread.checkpointName,
  1113. &ckptCheckpointInstance->checkpointName, sizeof (SaNameT));
  1114. iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
  1115. iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
  1116. iov[1].iov_base = ioVector[i].sectionId.id;
  1117. iov[1].iov_len = ioVector[i].sectionId.idLen;
  1118. error = saSendMsgRetry (ckptCheckpointInstance->response_fd,
  1119. iov,
  1120. 2);
  1121. /*
  1122. * Receive response header
  1123. */
  1124. error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionread,
  1125. sizeof (struct res_lib_ckpt_sectionread), MSG_WAITALL | MSG_NOSIGNAL);
  1126. if (error != SA_AIS_OK) {
  1127. goto error_exit;
  1128. }
  1129. dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread);
  1130. /*
  1131. * Receive checkpoint section data
  1132. */
  1133. if (dataLength > 0) {
  1134. error = saRecvRetry (ckptCheckpointInstance->response_fd, ioVector[i].dataBuffer,
  1135. dataLength, MSG_WAITALL | MSG_NOSIGNAL);
  1136. if (error != SA_AIS_OK) {
  1137. goto error_exit;
  1138. }
  1139. }
  1140. if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) {
  1141. if (erroneousVectorIndex) {
  1142. *erroneousVectorIndex = i;
  1143. }
  1144. goto error_exit;
  1145. }
  1146. /*
  1147. * Report back bytes of data read
  1148. */
  1149. ioVector[i].readSize = res_lib_ckpt_sectionread.dataRead;
  1150. }
  1151. error_exit:
  1152. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1153. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1154. return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error);
  1155. }
  1156. SaAisErrorT
  1157. saCkptCheckpointSynchronize (
  1158. SaCkptCheckpointHandleT checkpointHandle,
  1159. SaTimeT timeout)
  1160. {
  1161. SaAisErrorT error;
  1162. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1163. struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize;
  1164. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  1165. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1166. (void *)&ckptCheckpointInstance);
  1167. if (error != SA_AIS_OK) {
  1168. return (error);
  1169. }
  1170. req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize);
  1171. req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  1172. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1173. error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronize,
  1174. sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL);
  1175. if (error != SA_AIS_OK) {
  1176. goto error_exit;
  1177. }
  1178. error = saRecvRetry (ckptCheckpointInstance->response_fd,
  1179. &res_lib_ckpt_checkpointsynchronize,
  1180. sizeof (struct res_lib_ckpt_checkpointsynchronize),
  1181. MSG_WAITALL | MSG_NOSIGNAL);
  1182. error_exit:
  1183. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1184. saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle);
  1185. return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error);
  1186. }
  1187. SaAisErrorT
  1188. saCkptCheckpointSynchronizeAsync (
  1189. SaCkptHandleT ckptHandle,
  1190. SaCkptCheckpointHandleT checkpointHandle,
  1191. SaInvocationT invocation)
  1192. {
  1193. return (SA_AIS_OK);
  1194. /* TODO not implemented in executive
  1195. struct ckptInstance *ckptInstance;
  1196. struct ckptCheckpointInstance *ckptCheckpointInstance;
  1197. SaAisErrorT error;
  1198. struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync;
  1199. error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle,
  1200. (void *)&ckptCheckpointInstance);
  1201. if (error != SA_AIS_OK) {
  1202. return (error);
  1203. }
  1204. req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync);
  1205. req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  1206. req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation;
  1207. pthread_mutex_lock (&ckptCheckpointInstance->response_mutex);
  1208. pthread_mutex_lock (&ckptInstance->response_mutex);
  1209. error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync,
  1210. sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL);
  1211. pthread_mutex_unlock (&ckptInstance->response_mutex);
  1212. pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex);
  1213. saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle);
  1214. return (error);
  1215. */
  1216. }