ckpt.c 65 KB

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