ckpt.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. /*
  2. * Copyright (c) 2003-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 <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <sys/time.h>
  39. #include <netinet/in.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include "../include/ais_types.h"
  47. #include "../include/ais_msg.h"
  48. #include "../include/list.h"
  49. #include "../include/queue.h"
  50. #include "aispoll.h"
  51. #include "mempool.h"
  52. #include "util.h"
  53. #include "parse.h"
  54. #include "main.h"
  55. #include "print.h"
  56. #include "gmi.h"
  57. DECLARE_LIST_INIT(checkpointListHead);
  58. DECLARE_LIST_INIT(checkpointIteratorListHead);
  59. static gmi_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle;
  60. static int ckpt_checkpoint_exec_init_fn (void);
  61. static int ckpt_checkpoint_exit_fn (struct conn_info *conn_info);
  62. static int ckptSectionIteratorApiFinalize (struct conn_info *conn_info);
  63. static int message_handler_req_lib_activatepoll (struct conn_info *, void *message);
  64. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr);
  65. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr);
  66. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr);
  67. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr);
  68. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr);
  69. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr);
  70. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr);
  71. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr);
  72. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr);
  73. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr);
  74. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr);
  75. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message);
  76. static int message_handler_req_lib_ckpt_checkpoint_init (struct conn_info *conn_info, void *message);
  77. static int message_handler_req_lib_ckpt_sectioniterator_init (struct conn_info *conn_info, void *message);
  78. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message);
  79. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message);
  80. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message);
  81. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message);
  82. static int message_handler_req_lib_ckpt_activecheckpointset (struct conn_info *conn_info, void *message);
  83. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message);
  84. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message);
  85. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message);
  86. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message);
  87. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message);
  88. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message);
  89. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message);
  90. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message);
  91. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message);
  92. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message);
  93. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message);
  94. static int ckpt_checkpoint_confchg_fn (
  95. enum gmi_configuration_type configuration_type,
  96. struct sockaddr_in *member_list, int member_list_entries,
  97. struct sockaddr_in *left_list, int left_list_entries,
  98. struct sockaddr_in *joined_list, int joined_list_entries) {
  99. if (configuration_type == GMI_CONFIGURATION_REGULAR) {
  100. gmi_recovery_plug_unplug (ckpt_checkpoint_recovery_plug_handle);
  101. }
  102. return (0);
  103. }
  104. struct libais_handler ckpt_libais_handlers[] =
  105. {
  106. { /* 0 */
  107. .libais_handler_fn = message_handler_req_lib_activatepoll,
  108. .response_size = sizeof (struct res_lib_activatepoll),
  109. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL,
  110. .gmi_prio = GMI_PRIO_RECOVERY
  111. }
  112. };
  113. /*
  114. * TODO
  115. */
  116. int (*ckpt_aisexec_handler_fns[]) (void *, struct in_addr source_addr) = {
  117. };
  118. /*
  119. * exported service
  120. */
  121. struct service_handler ckpt_service_handler = {
  122. .libais_handlers = ckpt_libais_handlers,
  123. .libais_handlers_count = sizeof (ckpt_libais_handlers) / sizeof (struct libais_handler),
  124. .aisexec_handler_fns = ckpt_aisexec_handler_fns,
  125. .aisexec_handler_fns_count = sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  126. .confchg_fn = 0, /* ckpt service handler is not distributed */
  127. .libais_init_fn = message_handler_req_lib_ckpt_init,
  128. .libais_exit_fn = 0,
  129. .exec_init_fn = 0
  130. };
  131. struct libais_handler ckpt_checkpoint_libais_handlers[] =
  132. {
  133. { /* 0 */
  134. .libais_handler_fn = message_handler_req_lib_activatepoll,
  135. .response_size = sizeof (struct res_lib_activatepoll),
  136. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL,
  137. .gmi_prio = GMI_PRIO_RECOVERY
  138. },
  139. { /* 1 */
  140. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopen,
  141. .response_size = sizeof (struct res_lib_ckpt_checkpointopen),
  142. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN,
  143. .gmi_prio = GMI_PRIO_MED
  144. },
  145. { /* 2 */
  146. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopenasync,
  147. .response_size = sizeof (struct res_lib_ckpt_checkpointopenasync),
  148. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC,
  149. .gmi_prio = GMI_PRIO_MED
  150. },
  151. { /* 3 */
  152. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  153. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  154. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  155. .gmi_prio = GMI_PRIO_MED
  156. },
  157. { /* 4 */
  158. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  159. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  160. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  161. .gmi_prio = GMI_PRIO_LOW
  162. },
  163. { /* 5 */
  164. .libais_handler_fn = message_handler_req_lib_ckpt_activecheckpointset,
  165. .response_size = sizeof (struct res_lib_ckpt_activecheckpointset),
  166. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_ACTIVECHECKPOINTSET,
  167. .gmi_prio = GMI_PRIO_MED
  168. },
  169. { /* 6 */
  170. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  171. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  172. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  173. .gmi_prio = GMI_PRIO_MED
  174. },
  175. { /* 7 */
  176. .libais_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  177. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  178. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  179. .gmi_prio = GMI_PRIO_MED
  180. },
  181. { /* 8 */
  182. .libais_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  183. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  184. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  185. .gmi_prio = GMI_PRIO_MED
  186. },
  187. { /* 9 */
  188. .libais_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  189. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  190. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  191. .gmi_prio = GMI_PRIO_LOW
  192. },
  193. { /* 10 */
  194. .libais_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  195. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  196. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  197. .gmi_prio = GMI_PRIO_LOW
  198. },
  199. { /* 11 */
  200. .libais_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  201. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  202. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  203. .gmi_prio = GMI_PRIO_LOW
  204. },
  205. { /* 12 */
  206. .libais_handler_fn = message_handler_req_lib_ckpt_sectionread,
  207. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  208. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  209. .gmi_prio = GMI_PRIO_LOW
  210. },
  211. { /* 13 */
  212. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  213. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  214. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  215. .gmi_prio = GMI_PRIO_MED
  216. },
  217. { /* 14 */
  218. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  219. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), // TODO RESPONSE
  220. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  221. .gmi_prio = GMI_PRIO_MED
  222. },
  223. };
  224. static int (*ckpt_checkpoint_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr) = {
  225. message_handler_req_exec_ckpt_checkpointopen,
  226. message_handler_req_exec_ckpt_checkpointclose,
  227. message_handler_req_exec_ckpt_checkpointunlink,
  228. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  229. message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  230. message_handler_req_exec_ckpt_sectioncreate,
  231. message_handler_req_exec_ckpt_sectiondelete,
  232. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  233. message_handler_req_exec_ckpt_sectionwrite,
  234. message_handler_req_exec_ckpt_sectionoverwrite,
  235. message_handler_req_exec_ckpt_sectionread
  236. };
  237. struct service_handler ckpt_checkpoint_service_handler = {
  238. .libais_handlers = ckpt_checkpoint_libais_handlers,
  239. .libais_handlers_count = sizeof (ckpt_checkpoint_libais_handlers) / sizeof (struct libais_handler),
  240. .aisexec_handler_fns = ckpt_checkpoint_aisexec_handler_fns,
  241. .aisexec_handler_fns_count = sizeof (ckpt_checkpoint_aisexec_handler_fns) / sizeof (int (*)),
  242. .confchg_fn = ckpt_checkpoint_confchg_fn,
  243. .libais_init_fn = message_handler_req_lib_ckpt_checkpoint_init,
  244. .libais_exit_fn = ckpt_checkpoint_exit_fn,
  245. .exec_init_fn = ckpt_checkpoint_exec_init_fn
  246. };
  247. struct libais_handler ckpt_sectioniterator_libais_handlers[] =
  248. {
  249. { /* 0 */
  250. .libais_handler_fn = message_handler_req_lib_activatepoll,
  251. .response_size = sizeof (struct res_lib_activatepoll),
  252. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL,
  253. .gmi_prio = GMI_PRIO_RECOVERY
  254. },
  255. { /* 1 */
  256. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratorinitialize,
  257. .response_size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  258. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE,
  259. .gmi_prio = GMI_PRIO_RECOVERY
  260. },
  261. { /* 2 */
  262. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratornext,
  263. .response_size = sizeof (struct res_lib_ckpt_sectioniteratornext),
  264. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT,
  265. .gmi_prio = GMI_PRIO_RECOVERY
  266. }
  267. };
  268. static int (*ckpt_sectioniterator_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr) = {
  269. };
  270. struct service_handler ckpt_sectioniterator_service_handler = {
  271. .libais_handlers = ckpt_sectioniterator_libais_handlers,
  272. .libais_handlers_count = sizeof (ckpt_sectioniterator_libais_handlers) / sizeof (struct libais_handler),
  273. .aisexec_handler_fns = ckpt_sectioniterator_aisexec_handler_fns ,
  274. .aisexec_handler_fns_count = sizeof (ckpt_sectioniterator_aisexec_handler_fns) / sizeof (int (*)),
  275. .confchg_fn = 0, /* Section Iterators are not distributed */
  276. .libais_init_fn = message_handler_req_lib_ckpt_sectioniterator_init,
  277. .libais_exit_fn = ckptSectionIteratorApiFinalize,
  278. .exec_init_fn = 0
  279. };
  280. static struct saCkptCheckpoint *findCheckpoint (SaNameT *name)
  281. {
  282. struct list_head *checkpointList;
  283. struct saCkptCheckpoint *checkpoint;
  284. for (checkpointList = checkpointListHead.next;
  285. checkpointList != &checkpointListHead;
  286. checkpointList = checkpointList->next) {
  287. checkpoint = list_entry (checkpointList,
  288. struct saCkptCheckpoint, list);
  289. if (name_match (name, &checkpoint->name)) {
  290. return (checkpoint);
  291. }
  292. }
  293. return (0);
  294. }
  295. static struct saCkptCheckpointSection *findCheckpointSection (
  296. struct saCkptCheckpoint *ckptCheckpoint,
  297. char *id,
  298. int idLen)
  299. {
  300. struct list_head *checkpointSectionList;
  301. struct saCkptCheckpointSection *ckptCheckpointSection;
  302. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", id, idLen);
  303. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  304. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  305. checkpointSectionList = checkpointSectionList->next) {
  306. ckptCheckpointSection = list_entry (checkpointSectionList,
  307. struct saCkptCheckpointSection, list);
  308. log_printf (LOG_LEVEL_DEBUG, "Checking section id %s %d\n",
  309. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  310. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  311. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  312. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  313. id, idLen) == 0)) {
  314. return (ckptCheckpointSection);
  315. }
  316. }
  317. return 0;
  318. }
  319. void checkpoint_section_release (struct saCkptCheckpointSection *section)
  320. {
  321. list_del (&section->list);
  322. free (section->sectionDescriptor.sectionId.id);
  323. free (section->sectionData);
  324. poll_timer_delete (*gmi_poll_handle, section->expiration_timer);
  325. free (section);
  326. }
  327. void checkpoint_release (struct saCkptCheckpoint *checkpoint)
  328. {
  329. struct list_head *list;
  330. struct saCkptCheckpointSection *section;
  331. poll_timer_delete (*gmi_poll_handle, checkpoint->retention_timer);
  332. /*
  333. * Release all checkpoint sections for this checkpoint
  334. */
  335. for (list = checkpoint->checkpointSectionsListHead.next;
  336. list != &checkpoint->checkpointSectionsListHead;) {
  337. section = list_entry (list,
  338. struct saCkptCheckpointSection, list);
  339. list = list->next;
  340. checkpoint_section_release (section);
  341. }
  342. list_del (&checkpoint->list);
  343. free (checkpoint);
  344. }
  345. int sendCkptCheckpointClose (struct saCkptCheckpoint *checkpoint) {
  346. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  347. struct iovec iovecs[2];
  348. if (checkpoint->expired == 1) {
  349. return (0);
  350. }
  351. req_exec_ckpt_checkpointclose.header.size =
  352. sizeof (struct req_exec_ckpt_checkpointclose);
  353. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  354. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  355. &checkpoint->name,
  356. sizeof (SaNameT));
  357. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  358. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  359. if (gmi_send_ok (GMI_PRIO_HIGH, sizeof (struct req_exec_ckpt_checkpointclose))) {
  360. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_HIGH) == 0);
  361. return (0);
  362. }
  363. return (-1);
  364. }
  365. static int ckpt_checkpoint_exec_init_fn (void)
  366. {
  367. int res;
  368. res = gmi_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  369. if (res != 0) {
  370. log_printf(LOG_LEVEL_ERROR,
  371. "Could not create recovery plug for clm service.\n");
  372. return (-1);
  373. }
  374. return (0);
  375. }
  376. static int ckpt_checkpoint_exit_fn (struct conn_info *conn_info)
  377. {
  378. /*
  379. * close checkpoint opened from this fd
  380. */
  381. if (conn_info->service == SOCKET_SERVICE_CKPT_CHECKPOINT &&
  382. conn_info->ais_ci.u.libckpt_ci.checkpoint) {
  383. log_printf (LOG_LEVEL_DEBUG, "Trying to finalize %d %s\n", conn_info,
  384. getSaNameT (&conn_info->ais_ci.u.libckpt_ci.checkpoint->name));
  385. sendCkptCheckpointClose (conn_info->ais_ci.u.libckpt_ci.checkpoint);
  386. }
  387. return (0);
  388. }
  389. static int ckptSectionIteratorApiFinalize (struct conn_info *conn_info) {
  390. /*
  391. * If section iterator connection, unlink from list and free section iterator data
  392. */
  393. if (conn_info->service == SOCKET_SERVICE_CKPT_SECTIONITERATOR) {
  394. log_printf (LOG_LEVEL_DEBUG, "freeing section iterator\n");
  395. if (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  396. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  397. }
  398. list_del (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  399. }
  400. return (0);
  401. }
  402. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  403. {
  404. struct res_lib_activatepoll res_lib_activatepoll;
  405. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  406. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  407. res_lib_activatepoll.header.error = SA_OK;
  408. libais_send_response (conn_info, &res_lib_activatepoll,
  409. sizeof (struct res_lib_activatepoll));
  410. return (0);
  411. }
  412. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr)
  413. {
  414. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  415. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  416. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  417. struct saCkptCheckpoint *ckptCheckpoint = 0;
  418. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  419. SaErrorT error = SA_OK;
  420. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  421. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_checkpointopen->checkpointName);
  422. /*
  423. * If checkpoint doesn't exist, create one
  424. */
  425. if (ckptCheckpoint == 0) {
  426. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  427. if (ckptCheckpoint == 0) {
  428. error = SA_ERR_NO_MEMORY;
  429. goto error_exit;
  430. }
  431. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  432. if (ckptCheckpointSection == 0) {
  433. free (ckptCheckpoint);
  434. error = SA_ERR_NO_MEMORY;
  435. goto error_exit;
  436. }
  437. memcpy (&ckptCheckpoint->name,
  438. &req_lib_ckpt_checkpointopen->checkpointName,
  439. sizeof (SaNameT));
  440. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  441. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  442. sizeof (SaCkptCheckpointCreationAttributesT));
  443. ckptCheckpoint->unlinked = 0;
  444. list_init (&ckptCheckpoint->list);
  445. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  446. list_add (&ckptCheckpoint->list, &checkpointListHead);
  447. ckptCheckpoint->referenceCount = 0;
  448. ckptCheckpoint->retention_timer = 0;
  449. ckptCheckpoint->expired = 0;
  450. /*
  451. * Add in default checkpoint section
  452. */
  453. list_init (&ckptCheckpointSection->list);
  454. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  455. /*
  456. * Default section id
  457. */
  458. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  459. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  460. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  461. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  462. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  463. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // current time
  464. ckptCheckpointSection->sectionData = 0;
  465. ckptCheckpointSection->expiration_timer = 0;
  466. }
  467. /*
  468. * If the checkpoint has been unlinked, it is an invalid name
  469. */
  470. if (ckptCheckpoint->unlinked) {
  471. error = SA_ERR_INVALID_PARAM; /* Is this the correct return ? */
  472. goto error_exit;
  473. }
  474. /*
  475. * Setup connection information and mark checkpoint as referenced
  476. */
  477. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  478. ckptCheckpoint->referenceCount += 1;
  479. /*
  480. * Reset retention duration since this checkpoint was just opened
  481. */
  482. poll_timer_delete (*gmi_poll_handle, ckptCheckpoint->retention_timer);
  483. ckptCheckpoint->retention_timer = 0;
  484. /*
  485. * Send error result to CKPT library
  486. */
  487. error_exit:
  488. /*
  489. * If this node was the source of the message, respond to this node
  490. */
  491. if (req_exec_ckpt_checkpointopen->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  492. req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint = ckptCheckpoint;
  493. req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags = req_lib_ckpt_checkpointopen->checkpointOpenFlags;
  494. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  495. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  496. res_lib_ckpt_checkpointopen.header.error = error;
  497. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  498. sizeof (struct res_lib_ckpt_checkpointopen));
  499. }
  500. // return (error == SA_OK ? 0 : -1);
  501. return (0);
  502. }
  503. unsigned int abstime_to_msec (SaTimeT time)
  504. {
  505. struct timeval tv;
  506. unsigned long long curr_time;
  507. unsigned long long msec_time;
  508. gettimeofday (&tv, NULL);
  509. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  510. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  511. msec_time = (((unsigned long long)time) / 1000000) -
  512. (unsigned long long)curr_time;
  513. return ((unsigned int)(msec_time));
  514. }
  515. void timer_function_section_expire (void *data)
  516. {
  517. struct saCkptCheckpointSection *section = (struct saCkptCheckpointSection *)data;
  518. if (section->sectionDescriptor.sectionId.id) {
  519. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring section %s\n", section->sectionDescriptor.sectionId.id);
  520. }
  521. checkpoint_section_release (section);
  522. }
  523. void timer_function_retention (void *data)
  524. {
  525. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  526. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  527. struct iovec iovec;
  528. checkpoint->retention_timer = 0;
  529. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  530. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  531. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  532. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  533. &checkpoint->name,
  534. sizeof (SaNameT));
  535. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  536. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  537. assert (gmi_mcast (&aisexec_groupname, &iovec, 1, GMI_PRIO_MED) == 0);
  538. }
  539. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr)
  540. {
  541. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  542. struct saCkptCheckpoint *checkpoint = 0;
  543. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  544. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointclose->checkpointName);
  545. if (checkpoint == 0) {
  546. return (0);
  547. }
  548. checkpoint->referenceCount--;
  549. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  550. checkpoint->referenceCount);
  551. /*
  552. * If checkpoint has been unlinked and this is the last reference, delete it
  553. */
  554. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  555. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  556. checkpoint_release (checkpoint);
  557. } else
  558. if (checkpoint->referenceCount == 0) {
  559. poll_timer_add (*gmi_poll_handle,
  560. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  561. checkpoint,
  562. timer_function_retention,
  563. &checkpoint->retention_timer);
  564. }
  565. return (0);
  566. }
  567. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr)
  568. {
  569. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  570. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  571. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  572. struct saCkptCheckpoint *ckptCheckpoint = 0;
  573. SaErrorT error = SA_OK;
  574. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  575. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_checkpointunlink->checkpointName);
  576. if (ckptCheckpoint == 0) {
  577. error = SA_ERR_NOT_EXIST;
  578. goto error_exit;
  579. }
  580. if (ckptCheckpoint->unlinked) {
  581. error = SA_ERR_INVALID_PARAM;
  582. goto error_exit;
  583. }
  584. ckptCheckpoint->unlinked = 1;
  585. /*
  586. * Immediately delete entry if reference count is zero
  587. */
  588. if (ckptCheckpoint->referenceCount == 0) {
  589. /*
  590. * Remove retention timer since this checkpoint was unlinked and is no
  591. * longer referenced
  592. */
  593. checkpoint_release (ckptCheckpoint);
  594. }
  595. error_exit:
  596. /*
  597. * If this node was the source of the message, respond to this node
  598. */
  599. if (req_exec_ckpt_checkpointunlink->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  600. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  601. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  602. res_lib_ckpt_checkpointunlink.header.error = error;
  603. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  604. sizeof (struct res_lib_ckpt_checkpointunlink));
  605. }
  606. return (0);
  607. }
  608. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr)
  609. {
  610. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  611. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  612. struct saCkptCheckpoint *checkpoint;
  613. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  614. if (checkpoint) {
  615. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  616. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  617. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  618. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  619. poll_timer_delete (*gmi_poll_handle, checkpoint->retention_timer);
  620. poll_timer_add (*gmi_poll_handle,
  621. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  622. checkpoint,
  623. timer_function_retention,
  624. &checkpoint->retention_timer);
  625. }
  626. }
  627. /*
  628. * Respond to library if this processor sent the duration set request
  629. */
  630. if (req_exec_ckpt_checkpointretentiondurationset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  631. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  632. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  633. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_OK;
  634. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  635. &res_lib_ckpt_checkpointretentiondurationset,
  636. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  637. }
  638. return (0);
  639. }
  640. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr)
  641. {
  642. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  643. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  644. struct saCkptCheckpoint *checkpoint;
  645. struct iovec iovecs[2];
  646. checkpoint = findCheckpoint (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  647. if (checkpoint && checkpoint->expired == 0) {
  648. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  649. checkpoint->expired = 1;
  650. req_exec_ckpt_checkpointunlink.header.size =
  651. sizeof (struct req_exec_ckpt_checkpointunlink);
  652. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  653. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  654. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  655. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  656. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  657. sizeof (SaNameT));
  658. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  659. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  660. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED) == 0);
  661. }
  662. return (0);
  663. }
  664. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr) {
  665. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  666. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  667. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  668. struct saCkptCheckpoint *ckptCheckpoint;
  669. struct saCkptCheckpointSection *ckptCheckpointSection;
  670. void *initialData;
  671. void *sectionId;
  672. SaErrorT error = SA_OK;
  673. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  674. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectioncreate->checkpointName);
  675. if (ckptCheckpoint == 0) {
  676. error = SA_ERR_SYSTEM; // TODO find the right error for this
  677. goto error_exit;
  678. }
  679. /*
  680. * Determine if user-specified checkpoint ID already exists
  681. */
  682. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  683. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  684. req_lib_ckpt_sectioncreate->idLen);
  685. if (ckptCheckpointSection) {
  686. error = SA_ERR_EXIST;
  687. goto error_exit;
  688. }
  689. /*
  690. * Allocate checkpoint section
  691. */
  692. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  693. if (ckptCheckpointSection == 0) {
  694. error = SA_ERR_NO_MEMORY;
  695. goto error_exit;
  696. }
  697. /*
  698. * Allocate checkpoint section data
  699. */
  700. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  701. if (initialData == 0) {
  702. free (ckptCheckpointSection);
  703. error = SA_ERR_NO_MEMORY;
  704. goto error_exit;
  705. }
  706. /*
  707. * Allocate checkpoint section id
  708. */
  709. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  710. if (sectionId == 0) {
  711. free (ckptCheckpointSection);
  712. free (initialData);
  713. error = SA_ERR_NO_MEMORY;
  714. goto error_exit;
  715. }
  716. /*
  717. * Copy checkpoint section and section ID
  718. */
  719. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  720. req_lib_ckpt_sectioncreate->idLen);
  721. memcpy (initialData,
  722. ((char *)req_lib_ckpt_sectioncreate) +
  723. sizeof (struct req_lib_ckpt_sectioncreate) +
  724. req_lib_ckpt_sectioncreate->idLen,
  725. req_lib_ckpt_sectioncreate->initialDataSize);
  726. /*
  727. * Configure checkpoint section
  728. */
  729. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  730. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  731. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  732. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  733. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  734. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  735. ckptCheckpointSection->sectionData = initialData;
  736. ckptCheckpointSection->expiration_timer = 0;
  737. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  738. poll_timer_add (*gmi_poll_handle,
  739. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  740. ckptCheckpointSection,
  741. timer_function_section_expire,
  742. &ckptCheckpointSection->expiration_timer);
  743. }
  744. /*
  745. * Add checkpoint section to checkpoint
  746. */
  747. list_init (&ckptCheckpointSection->list);
  748. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  749. error_exit:
  750. if (req_exec_ckpt_sectioncreate->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  751. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  752. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  753. res_lib_ckpt_sectioncreate.header.error = error;
  754. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  755. &res_lib_ckpt_sectioncreate,
  756. sizeof (struct res_lib_ckpt_sectioncreate));
  757. }
  758. return (0);
  759. }
  760. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr) {
  761. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  762. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  763. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  764. struct saCkptCheckpoint *ckptCheckpoint;
  765. struct saCkptCheckpointSection *ckptCheckpointSection;
  766. SaErrorT error = SA_OK;
  767. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectiondelete->checkpointName);
  768. if (ckptCheckpoint == 0) {
  769. error = SA_ERR_NOT_EXIST;
  770. goto error_exit;
  771. }
  772. /*
  773. * Determine if the user is trying to delete the default section
  774. */
  775. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  776. error = SA_ERR_INVALID_PARAM;
  777. goto error_exit;
  778. }
  779. /*
  780. * Find checkpoint section to be deleted
  781. */
  782. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  783. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  784. req_lib_ckpt_sectiondelete->idLen);
  785. if (ckptCheckpointSection == 0) {
  786. printf ("section not found\n");
  787. error = SA_ERR_NOT_EXIST;
  788. goto error_exit;
  789. }
  790. /*
  791. * Delete checkpoint section
  792. */
  793. checkpoint_section_release (ckptCheckpointSection);
  794. /*
  795. * return result to CKPT library
  796. */
  797. error_exit:
  798. if (req_exec_ckpt_sectiondelete->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  799. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  800. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  801. res_lib_ckpt_sectiondelete.header.error = error;
  802. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  803. &res_lib_ckpt_sectiondelete,
  804. sizeof (struct res_lib_ckpt_sectiondelete));
  805. }
  806. return (0);
  807. }
  808. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr) {
  809. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  810. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  811. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  812. struct saCkptCheckpoint *ckptCheckpoint;
  813. struct saCkptCheckpointSection *ckptCheckpointSection;
  814. SaErrorT error = SA_OK;
  815. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  816. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  817. if (ckptCheckpoint == 0) {
  818. error = SA_ERR_NOT_EXIST;
  819. goto error_exit;
  820. }
  821. /*
  822. * Determine if the user is trying to set expiration time for the default section
  823. */
  824. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  825. error = SA_ERR_INVALID_PARAM;
  826. goto error_exit;
  827. }
  828. /*
  829. * Find checkpoint section that expiration time should be set for
  830. */
  831. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  832. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  833. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  834. req_lib_ckpt_sectionexpirationtimeset->idLen);
  835. if (ckptCheckpointSection == 0) {
  836. error = SA_ERR_NOT_EXIST;
  837. goto error_exit;
  838. }
  839. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  840. poll_timer_delete (*gmi_poll_handle, ckptCheckpointSection->expiration_timer);
  841. ckptCheckpointSection->expiration_timer = 0;
  842. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  843. poll_timer_add (*gmi_poll_handle,
  844. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  845. ckptCheckpointSection,
  846. timer_function_section_expire,
  847. &ckptCheckpointSection->expiration_timer);
  848. }
  849. error_exit:
  850. if (req_exec_ckpt_sectionexpirationtimeset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  851. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  852. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  853. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  854. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  855. &res_lib_ckpt_sectionexpirationtimeset,
  856. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  857. }
  858. return (0);
  859. }
  860. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr) {
  861. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  862. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  863. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  864. struct saCkptCheckpoint *ckptCheckpoint;
  865. struct saCkptCheckpointSection *ckptCheckpointSection;
  866. int sizeRequired;
  867. void *sectionData;
  868. SaErrorT error = SA_OK;
  869. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  870. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionwrite->checkpointName);
  871. if (ckptCheckpoint == 0) {
  872. error = SA_ERR_NOT_EXIST;
  873. goto error_exit;
  874. }
  875. //printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  876. /*
  877. * Find checkpoint section to be written
  878. */
  879. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  880. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  881. req_lib_ckpt_sectionwrite->idLen);
  882. if (ckptCheckpointSection == 0) {
  883. printf ("CANT FIND SECTION '%s'\n",
  884. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  885. error = SA_ERR_NOT_EXIST;
  886. goto error_exit;
  887. }
  888. /*
  889. * If write would extend past end of section data, enlarge section
  890. */
  891. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  892. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  893. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  894. if (sectionData == 0) {
  895. error = SA_ERR_NO_MEMORY;
  896. goto error_exit;
  897. }
  898. /*
  899. * Install new section data
  900. */
  901. ckptCheckpointSection->sectionData = sectionData;
  902. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  903. }
  904. /*
  905. * Write checkpoint section to section data
  906. */
  907. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  908. char *sd;
  909. int *val;
  910. val = ckptCheckpointSection->sectionData;
  911. sd = (char *)ckptCheckpointSection->sectionData;
  912. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  913. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  914. req_lib_ckpt_sectionwrite->idLen,
  915. req_lib_ckpt_sectionwrite->dataSize);
  916. }
  917. /*
  918. * Write write response to CKPT library
  919. */
  920. error_exit:
  921. if (req_exec_ckpt_sectionwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  922. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  923. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  924. res_lib_ckpt_sectionwrite.header.error = error;
  925. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  926. &res_lib_ckpt_sectionwrite,
  927. sizeof (struct res_lib_ckpt_sectionwrite));
  928. }
  929. return (0);
  930. }
  931. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr) {
  932. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  933. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  934. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  935. struct saCkptCheckpoint *ckptCheckpoint;
  936. struct saCkptCheckpointSection *ckptCheckpointSection;
  937. void *sectionData;
  938. SaErrorT error = SA_OK;
  939. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  940. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionoverwrite->checkpointName);
  941. if (ckptCheckpoint == 0) {
  942. error = SA_ERR_NOT_EXIST;
  943. goto error_exit;
  944. }
  945. /*
  946. * Find checkpoint section to be overwritten
  947. */
  948. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  949. ((char *)req_lib_ckpt_sectionoverwrite) +
  950. sizeof (struct req_lib_ckpt_sectionoverwrite),
  951. req_lib_ckpt_sectionoverwrite->idLen);
  952. if (ckptCheckpointSection == 0) {
  953. error = SA_ERR_NOT_EXIST;
  954. goto error_exit;
  955. }
  956. /*
  957. * Allocate checkpoint section data
  958. */
  959. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  960. if (sectionData == 0) {
  961. error = SA_ERR_NO_MEMORY;
  962. goto error_exit;
  963. }
  964. memcpy (sectionData,
  965. ((char *)req_lib_ckpt_sectionoverwrite) +
  966. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  967. req_lib_ckpt_sectionoverwrite->idLen,
  968. req_lib_ckpt_sectionoverwrite->dataSize);
  969. /*
  970. * release old checkpoint section data
  971. */
  972. free (ckptCheckpointSection->sectionData);
  973. /*
  974. * Install overwritten checkpoint section data
  975. */
  976. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  977. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  978. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; // TODO current time
  979. ckptCheckpointSection->sectionData = sectionData;
  980. /*
  981. * return result to CKPT library
  982. */
  983. error_exit:
  984. if (req_exec_ckpt_sectionoverwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  985. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  986. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  987. res_lib_ckpt_sectionoverwrite.header.error = error;
  988. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  989. &res_lib_ckpt_sectionoverwrite,
  990. sizeof (struct res_lib_ckpt_sectionoverwrite));
  991. }
  992. return (0);
  993. }
  994. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr) {
  995. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  996. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  997. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  998. struct saCkptCheckpoint *ckptCheckpoint;
  999. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1000. int sectionSize = 0;
  1001. SaErrorT error = SA_OK;
  1002. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  1003. ckptCheckpoint = findCheckpoint (&req_exec_ckpt_sectionread->checkpointName);
  1004. if (ckptCheckpoint == 0) {
  1005. error = SA_ERR_SYSTEM; // TODO find the right error for this
  1006. goto error_exit;
  1007. }
  1008. /*
  1009. * Find checkpoint section to be read
  1010. */
  1011. ckptCheckpointSection = findCheckpointSection (ckptCheckpoint,
  1012. ((char *)req_lib_ckpt_sectionread) +
  1013. sizeof (struct req_lib_ckpt_sectionread),
  1014. req_lib_ckpt_sectionread->idLen);
  1015. if (ckptCheckpointSection == 0) {
  1016. error = SA_ERR_NOT_EXIST;
  1017. goto error_exit;
  1018. }
  1019. /*
  1020. * Determine the section size
  1021. */
  1022. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1023. req_lib_ckpt_sectionread->dataOffset;
  1024. /*
  1025. * If the library has less space available then can be sent from the
  1026. * section, reduce bytes sent to library to max requested
  1027. */
  1028. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1029. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1030. }
  1031. /*
  1032. * If dataOffset is past end of data, return INVALID PARAM
  1033. */
  1034. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1035. sectionSize = 0;
  1036. error = SA_ERR_INVALID_PARAM;
  1037. goto error_exit;
  1038. }
  1039. /*
  1040. * Write read response to CKPT library
  1041. */
  1042. error_exit:
  1043. if (req_exec_ckpt_sectionread->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1044. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1045. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1046. res_lib_ckpt_sectionread.header.error = error;
  1047. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1048. &res_lib_ckpt_sectionread,
  1049. sizeof (struct res_lib_ckpt_sectionread));
  1050. /*
  1051. * Write checkpoint to CKPT library section if section has data
  1052. */
  1053. if (sectionSize) {
  1054. char *sd;
  1055. sd = (char *)ckptCheckpointSection->sectionData;
  1056. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1057. &sd[req_lib_ckpt_sectionread->dataOffset],
  1058. sectionSize);
  1059. }
  1060. }
  1061. return (0);
  1062. }
  1063. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message)
  1064. {
  1065. struct res_lib_init res_lib_init;
  1066. SaErrorT error = SA_ERR_SECURITY;
  1067. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT.\n");
  1068. if (conn_info->authenticated) {
  1069. conn_info->service = SOCKET_SERVICE_CKPT;
  1070. error = SA_OK;
  1071. }
  1072. res_lib_init.header.size = sizeof (struct res_lib_init);
  1073. res_lib_init.header.id = MESSAGE_RES_INIT;
  1074. res_lib_init.header.error = error;
  1075. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1076. if (conn_info->authenticated) {
  1077. return (0);
  1078. }
  1079. return (-1);
  1080. }
  1081. static int message_handler_req_lib_ckpt_checkpoint_init (struct conn_info *conn_info, void *message)
  1082. {
  1083. struct res_lib_init res_lib_init;
  1084. SaErrorT error = SA_ERR_SECURITY;
  1085. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT checkpoint.\n");
  1086. if (conn_info->authenticated) {
  1087. conn_info->service = SOCKET_SERVICE_CKPT_CHECKPOINT;
  1088. conn_info->ais_ci.u.libckpt_ci.checkpoint = 0;
  1089. conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags = 0;
  1090. error = SA_OK;
  1091. }
  1092. res_lib_init.header.size = sizeof (struct res_lib_init);
  1093. res_lib_init.header.id = MESSAGE_RES_INIT;
  1094. res_lib_init.header.error = error;
  1095. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1096. if (conn_info->authenticated) {
  1097. return (0);
  1098. }
  1099. return (-1);
  1100. }
  1101. static int message_handler_req_lib_ckpt_sectioniterator_init (struct conn_info *conn_info, void *message)
  1102. {
  1103. struct res_lib_init res_lib_init;
  1104. SaErrorT error = SA_ERR_SECURITY;
  1105. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT section iterator.\n");
  1106. if (conn_info->authenticated) {
  1107. conn_info->service = SOCKET_SERVICE_CKPT_SECTIONITERATOR;
  1108. list_init (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  1109. conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1110. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1111. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1112. list_add (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list,
  1113. &checkpointIteratorListHead);
  1114. error = SA_OK;
  1115. }
  1116. res_lib_init.header.size = sizeof (struct res_lib_init);
  1117. res_lib_init.header.id = MESSAGE_RES_INIT;
  1118. res_lib_init.header.error = error;
  1119. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1120. if (conn_info->authenticated) {
  1121. return (0);
  1122. }
  1123. return (-1);
  1124. }
  1125. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1126. {
  1127. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1128. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1129. struct iovec iovecs[2];
  1130. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1131. req_exec_ckpt_checkpointopen.header.size =
  1132. sizeof (struct req_exec_ckpt_checkpointopen);
  1133. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1134. req_exec_ckpt_checkpointopen.source.conn_info = conn_info;
  1135. req_exec_ckpt_checkpointopen.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1136. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1137. req_lib_ckpt_checkpointopen,
  1138. sizeof (struct req_lib_ckpt_checkpointopen));
  1139. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1140. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1141. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED) == 0);
  1142. return (0);
  1143. }
  1144. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1145. {
  1146. return (0);
  1147. }
  1148. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1149. {
  1150. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1151. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1152. struct iovec iovecs[2];
  1153. req_exec_ckpt_checkpointunlink.header.size =
  1154. sizeof (struct req_exec_ckpt_checkpointunlink);
  1155. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1156. req_exec_ckpt_checkpointunlink.source.conn_info = conn_info;
  1157. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1158. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1159. req_lib_ckpt_checkpointunlink,
  1160. sizeof (struct req_lib_ckpt_checkpointunlink));
  1161. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1162. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1163. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED) == 0);
  1164. return (0);
  1165. }
  1166. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1167. {
  1168. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1169. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1170. struct iovec iovecs[2];
  1171. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info);
  1172. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  1173. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  1174. req_exec_ckpt_checkpointretentiondurationset.source.conn_info = conn_info;
  1175. req_exec_ckpt_checkpointretentiondurationset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1176. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  1177. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1178. sizeof (SaNameT));
  1179. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  1180. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  1181. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  1182. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW) == 0);
  1183. return (0);
  1184. }
  1185. static int message_handler_req_lib_ckpt_activecheckpointset (struct conn_info *conn_info, void *message)
  1186. {
  1187. return (0);
  1188. }
  1189. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  1190. {
  1191. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  1192. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  1193. struct saCkptCheckpoint *checkpoint;
  1194. int memoryUsed = 0;
  1195. int numberOfSections = 0;
  1196. struct list_head *checkpointSectionList;
  1197. struct saCkptCheckpointSection *checkpointSection;
  1198. req_lib_ckpt_checkpointstatusget = 0; /* The request info isn't used */
  1199. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  1200. /*
  1201. * Count memory used by checkpoint sections
  1202. */
  1203. checkpoint = conn_info->ais_ci.u.libckpt_ci.checkpoint;
  1204. for (checkpointSectionList = checkpoint->checkpointSectionsListHead.next;
  1205. checkpointSectionList != &checkpoint->checkpointSectionsListHead;
  1206. checkpointSectionList = checkpointSectionList->next) {
  1207. checkpointSection = list_entry (checkpointSectionList,
  1208. struct saCkptCheckpointSection, list);
  1209. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  1210. numberOfSections += 1;
  1211. }
  1212. /*
  1213. * Build checkpoint status get response
  1214. */
  1215. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  1216. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  1217. res_lib_ckpt_checkpointstatusget.header.error = SA_OK;
  1218. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointStatus.checkpointCreationAttributes,
  1219. &checkpoint->checkpointCreationAttributes,
  1220. sizeof (SaCkptCheckpointCreationAttributesT));
  1221. res_lib_ckpt_checkpointstatusget.checkpointStatus.numberOfSections = numberOfSections;
  1222. res_lib_ckpt_checkpointstatusget.checkpointStatus.memoryUsed = memoryUsed;
  1223. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  1224. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  1225. sizeof (struct res_lib_ckpt_checkpointstatusget));
  1226. return (0);
  1227. }
  1228. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  1229. {
  1230. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  1231. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  1232. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1233. struct iovec iovecs[2];
  1234. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info);
  1235. /*
  1236. * Determine if checkpoint is opened in write mode If not, send error to api
  1237. */
  1238. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1239. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1240. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1241. res_lib_ckpt_sectioncreate.header.error = SA_ERR_ACCESS;
  1242. libais_send_response (conn_info, &res_lib_ckpt_sectioncreate,
  1243. sizeof (struct res_lib_ckpt_sectioncreate));
  1244. return (0);
  1245. }
  1246. /*
  1247. * checkpoint opened is writeable mode so send message to cluster
  1248. */
  1249. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  1250. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  1251. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  1252. req_lib_ckpt_sectioncreate,
  1253. sizeof (struct req_lib_ckpt_sectioncreate));
  1254. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  1255. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1256. sizeof (SaNameT));
  1257. req_exec_ckpt_sectioncreate.source.conn_info = conn_info;
  1258. req_exec_ckpt_sectioncreate.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1259. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  1260. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  1261. /*
  1262. * Send section name and initial data in message
  1263. */
  1264. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  1265. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  1266. #ifdef DEBUG
  1267. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  1268. iovecs[1].iov_len);
  1269. printf ("|\n");
  1270. { int i;
  1271. char *abc = iovecs[1].iov_base;
  1272. for (i = 0; i < 14;i++) {
  1273. printf ("%c ", abc[i]);
  1274. }
  1275. }
  1276. printf ("|\n");
  1277. #endif
  1278. if (iovecs[1].iov_len > 0) {
  1279. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1280. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED) == 0);
  1281. } else {
  1282. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED) == 0);
  1283. }
  1284. return (0);
  1285. }
  1286. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  1287. {
  1288. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  1289. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  1290. struct iovec iovecs[2];
  1291. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info);
  1292. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  1293. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  1294. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  1295. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1296. sizeof (SaNameT));
  1297. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  1298. req_lib_ckpt_sectiondelete,
  1299. sizeof (struct req_lib_ckpt_sectiondelete));
  1300. req_exec_ckpt_sectiondelete.source.conn_info = conn_info;
  1301. req_exec_ckpt_sectiondelete.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1302. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  1303. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  1304. /*
  1305. * Send section name
  1306. */
  1307. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  1308. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  1309. if (iovecs[1].iov_len > 0) {
  1310. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_MED) == 0);
  1311. } else {
  1312. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED) == 0);
  1313. }
  1314. return (0);
  1315. }
  1316. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  1317. {
  1318. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  1319. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  1320. struct iovec iovecs[2];
  1321. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info);
  1322. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  1323. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  1324. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  1325. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1326. sizeof (SaNameT));
  1327. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  1328. req_lib_ckpt_sectionexpirationtimeset,
  1329. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  1330. req_exec_ckpt_sectionexpirationtimeset.source.conn_info = conn_info;
  1331. req_exec_ckpt_sectionexpirationtimeset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1332. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  1333. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  1334. /*
  1335. * Send section name
  1336. */
  1337. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1338. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  1339. if (iovecs[1].iov_len > 0) {
  1340. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %s\n", iovecs[1].iov_base);
  1341. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW) == 0);
  1342. } else {
  1343. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW) == 0);
  1344. }
  1345. return (0);
  1346. }
  1347. int write_inv = 0;
  1348. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  1349. {
  1350. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  1351. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  1352. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1353. struct iovec iovecs[2];
  1354. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info);
  1355. // UNDO printf ("section write %d\n", write_inv++);
  1356. /*
  1357. * Determine if checkpoint is opened in write mode If not, send error to api
  1358. */
  1359. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1360. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1361. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1362. res_lib_ckpt_sectionwrite.header.error = SA_ERR_ACCESS;
  1363. libais_send_response (conn_info, &res_lib_ckpt_sectionwrite,
  1364. sizeof (struct res_lib_ckpt_sectionwrite));
  1365. return (0);
  1366. }
  1367. /*
  1368. * checkpoint opened is writeable mode so send message to cluster
  1369. */
  1370. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  1371. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  1372. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  1373. req_lib_ckpt_sectionwrite,
  1374. sizeof (struct req_lib_ckpt_sectionwrite));
  1375. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  1376. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1377. sizeof (SaNameT));
  1378. req_exec_ckpt_sectionwrite.source.conn_info = conn_info;
  1379. req_exec_ckpt_sectionwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1380. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  1381. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  1382. /*
  1383. * Send section name and data to write in message
  1384. */
  1385. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  1386. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  1387. //printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1388. if (iovecs[1].iov_len > 0) {
  1389. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW) == 0);
  1390. } else {
  1391. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW) == 0);
  1392. }
  1393. return (0);
  1394. }
  1395. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  1396. {
  1397. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  1398. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  1399. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1400. struct iovec iovecs[2];
  1401. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info);
  1402. /*
  1403. * Determine if checkpoint is opened in write mode If not, send error to api
  1404. */
  1405. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) {
  1406. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1407. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1408. res_lib_ckpt_sectionoverwrite.header.error = SA_ERR_ACCESS;
  1409. libais_send_response (conn_info, &res_lib_ckpt_sectionoverwrite,
  1410. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1411. return (0);
  1412. }
  1413. /*
  1414. * checkpoint opened is writeable mode so send message to cluster
  1415. */
  1416. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  1417. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  1418. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  1419. req_lib_ckpt_sectionoverwrite,
  1420. sizeof (struct req_lib_ckpt_sectionoverwrite));
  1421. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  1422. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1423. sizeof (SaNameT));
  1424. req_exec_ckpt_sectionoverwrite.source.conn_info = conn_info;
  1425. req_exec_ckpt_sectionoverwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1426. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  1427. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  1428. /*
  1429. * Send section name and data to overwrite in message
  1430. */
  1431. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  1432. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  1433. if (iovecs[1].iov_len > 0) {
  1434. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW) == 0);
  1435. } else {
  1436. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW) == 0);
  1437. }
  1438. return (0);
  1439. }
  1440. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  1441. {
  1442. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  1443. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  1444. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1445. struct iovec iovecs[2];
  1446. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info);
  1447. /*
  1448. * Determine if checkpoint is opened in write mode If not, send error to api
  1449. */
  1450. if ((conn_info->ais_ci.u.libckpt_ci.checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) {
  1451. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  1452. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1453. res_lib_ckpt_sectionread.header.error = SA_ERR_ACCESS;
  1454. libais_send_response (conn_info, &res_lib_ckpt_sectionread,
  1455. sizeof (struct res_lib_ckpt_sectionread));
  1456. return (0);
  1457. }
  1458. /*
  1459. * checkpoint opened is writeable mode so send message to cluster
  1460. */
  1461. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  1462. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  1463. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  1464. req_lib_ckpt_sectionread,
  1465. sizeof (struct req_lib_ckpt_sectionread));
  1466. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  1467. &conn_info->ais_ci.u.libckpt_ci.checkpoint->name,
  1468. sizeof (SaNameT));
  1469. req_exec_ckpt_sectionread.source.conn_info = conn_info;
  1470. req_exec_ckpt_sectionread.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1471. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  1472. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  1473. /*
  1474. * Send section name and data to overwrite in message
  1475. */
  1476. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  1477. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  1478. if (iovecs[1].iov_len > 0) {
  1479. assert (gmi_mcast (&aisexec_groupname, iovecs, 2, GMI_PRIO_LOW) == 0);
  1480. } else {
  1481. assert (gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_LOW) == 0);
  1482. }
  1483. return (0);
  1484. }
  1485. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  1486. {
  1487. return (0);
  1488. }
  1489. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  1490. {
  1491. return (0);
  1492. }
  1493. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  1494. {
  1495. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  1496. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  1497. struct saCkptCheckpoint *ckptCheckpoint;
  1498. struct saCkptCheckpointSection *ckptCheckpointSection;
  1499. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  1500. struct saCkptSectionIterator *ckptSectionIterator;
  1501. struct list_head *checkpointSectionList;
  1502. int addEntry = 0;
  1503. int iteratorEntries = 0;
  1504. SaErrorT error = SA_OK;
  1505. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  1506. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1507. ckptCheckpoint = findCheckpoint (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  1508. if (ckptCheckpoint == 0) {
  1509. error = SA_ERR_NOT_EXIST;
  1510. goto error_exit;
  1511. }
  1512. /*
  1513. * Iterate list of checkpoint sections
  1514. */
  1515. for (checkpointSectionList = ckptCheckpoint->checkpointSectionsListHead.next;
  1516. checkpointSectionList != &ckptCheckpoint->checkpointSectionsListHead;
  1517. checkpointSectionList = checkpointSectionList->next) {
  1518. ckptCheckpointSection = list_entry (checkpointSectionList,
  1519. struct saCkptCheckpointSection, list);
  1520. addEntry = 1;
  1521. /*
  1522. * Item should be added to iterator list
  1523. */
  1524. if (addEntry) {
  1525. iteratorEntries += 1;
  1526. ckptSectionIteratorEntries =
  1527. realloc (ckptSectionIterator->sectionIteratorEntries,
  1528. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  1529. if (ckptSectionIteratorEntries == 0) {
  1530. if (ckptSectionIterator->sectionIteratorEntries) {
  1531. free (ckptSectionIterator->sectionIteratorEntries);
  1532. }
  1533. error = SA_ERR_NO_MEMORY;
  1534. goto error_exit;
  1535. }
  1536. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  1537. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  1538. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  1539. }
  1540. }
  1541. ckptSectionIterator->iteratorCount = iteratorEntries;
  1542. error_exit:
  1543. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  1544. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  1545. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  1546. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  1547. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  1548. return (0);
  1549. }
  1550. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  1551. {
  1552. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  1553. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  1554. struct saCkptSectionIterator *ckptSectionIterator;
  1555. SaErrorT error = SA_OK;
  1556. int sectionIdSize = 0;
  1557. int iteratorPos = 0;
  1558. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  1559. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  1560. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  1561. /*
  1562. * Find active iterator entry
  1563. */
  1564. for (;;) {
  1565. /*
  1566. * No more sections in iterator
  1567. */
  1568. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  1569. error = SA_ERR_NOT_EXIST;
  1570. goto error_exit;
  1571. }
  1572. /*
  1573. * active iterator entry
  1574. */
  1575. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  1576. break;
  1577. }
  1578. ckptSectionIterator->iteratorPos += 1;
  1579. }
  1580. /*
  1581. * Prepare response to API
  1582. */
  1583. iteratorPos = ckptSectionIterator->iteratorPos;
  1584. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  1585. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  1586. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  1587. sizeof (SaCkptSectionDescriptorT));
  1588. /*
  1589. * Get to next iterator entry
  1590. */
  1591. ckptSectionIterator->iteratorPos += 1;
  1592. error_exit:
  1593. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  1594. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  1595. res_lib_ckpt_sectioniteratornext.header.error = error;
  1596. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  1597. sizeof (struct res_lib_ckpt_sectioniteratornext));
  1598. libais_send_response (conn_info,
  1599. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  1600. sectionIdSize);
  1601. return (0);
  1602. }