ckpt.c 48 KB

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