ckpt.c 73 KB

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