ckpt.c 71 KB

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