ckpt.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729
  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/saCkpt.h"
  48. #include "../include/ipc_ckpt.h"
  49. #include "../include/list.h"
  50. #include "../include/queue.h"
  51. #include "aispoll.h"
  52. #include "mempool.h"
  53. #include "util.h"
  54. #include "parse.h"
  55. #include "main.h"
  56. #include "totempg.h"
  57. #define LOG_SERVICE LOG_SERVICE_CKPT
  58. #define CKPT_MAX_SECTION_DATA_SEND (1024*400)
  59. #include "print.h"
  60. DECLARE_LIST_INIT(checkpoint_list_head);
  61. DECLARE_LIST_INIT(checkpoint_iterator_list_head);
  62. DECLARE_LIST_INIT(checkpoint_recovery_list_head);
  63. struct checkpoint_cleanup {
  64. struct list_head list;
  65. struct saCkptCheckpoint checkpoint;
  66. };
  67. typedef enum {
  68. SYNCHRONY_STATE_STARTED,
  69. SYNCHRONY_STATE_ENDED
  70. }synchrony_state;
  71. /* TODO static totempg_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle; */
  72. static int ckpt_exec_init_fn (void);
  73. static int ckpt_exit_fn (struct conn_info *conn_info);
  74. static int message_handler_req_lib_activatepoll (struct conn_info *, void *message);
  75. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required);
  76. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required);
  77. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required);
  78. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required);
  79. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required);
  80. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required);
  81. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required);
  82. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required);
  83. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required);
  84. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required);
  85. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  86. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  87. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required);
  88. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message);
  89. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message);
  90. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message);
  91. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message);
  92. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message);
  93. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message);
  94. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message);
  95. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message);
  96. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message);
  97. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message);
  98. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message);
  99. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message);
  100. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message);
  101. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message);
  102. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message);
  103. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message);
  104. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message);
  105. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message);
  106. static void ckpt_recovery_activate (void);
  107. static void ckpt_recovery_initialize (void);
  108. static int ckpt_recovery_process (void);
  109. static void ckpt_recovery_finalize();
  110. static void ckpt_recovery_abort(void);
  111. static void ckpt_recovery_process_members_exit(struct in_addr *left_list, int left_list_entries);
  112. void checkpoint_release (struct saCkptCheckpoint *checkpoint);
  113. void timer_function_retention (void *data);
  114. static int recovery_checkpoint_open(SaNameT *checkpointName,
  115. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  116. struct ckpt_refcnt *ref_cnt);
  117. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  118. SaNameT *checkpointName,
  119. char* SectionId);
  120. static int recovery_section_write(int sectionIdLen, char* sectionId , SaNameT *checkpointName,
  121. void *newData, SaUint32T dataOffSet, SaUint32T dataSize);
  122. static synchrony_state recovery_state = SYNCHRONY_STATE_ENDED;
  123. static struct list_head *recovery_ckpt_next = 0;
  124. static struct list_head *recovery_ckpt_section_next = 0;
  125. static int recovery_section_data_offset = 0;
  126. static int recovery_section_send_flag = 0;
  127. static int recovery_abort = 0;
  128. static struct memb_ring_id saved_ring_id;
  129. static int ckpt_confchg_fn(
  130. enum totem_configuration_type configuration_type,
  131. struct in_addr *member_list, void *member_list_private,
  132. int member_list_entries,
  133. struct in_addr *left_list, void *left_list_private,
  134. int left_list_entries,
  135. struct in_addr *joined_list, void *joined_list_private,
  136. int joined_list_entries,
  137. struct memb_ring_id *ring_id);
  138. struct libais_handler ckpt_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. .flow_control = FLOW_CONTROL_REQUIRED
  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. .flow_control = FLOW_CONTROL_REQUIRED
  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. .flow_control = FLOW_CONTROL_REQUIRED
  157. },
  158. { /* 3 */
  159. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointclose,
  160. .response_size = sizeof (struct res_lib_ckpt_checkpointclose),
  161. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE,
  162. .flow_control = FLOW_CONTROL_REQUIRED
  163. },
  164. { /* 4 */
  165. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  166. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  167. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  168. .flow_control = FLOW_CONTROL_REQUIRED
  169. },
  170. { /* 5 */
  171. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  172. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  173. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  174. .flow_control = FLOW_CONTROL_REQUIRED
  175. },
  176. { /* 6 */
  177. .libais_handler_fn = message_handler_req_lib_ckpt_activereplicaset,
  178. .response_size = sizeof (struct res_lib_ckpt_activereplicaset),
  179. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_ACTIVEREPLICASET,
  180. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  181. },
  182. { /* 7 */
  183. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  184. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  185. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  186. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  187. },
  188. { /* 8 */
  189. .libais_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  190. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  191. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  192. .flow_control = FLOW_CONTROL_REQUIRED
  193. },
  194. { /* 9 */
  195. .libais_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  196. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  197. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  198. .flow_control = FLOW_CONTROL_REQUIRED
  199. },
  200. { /* 10 */
  201. .libais_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  202. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  203. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  204. .flow_control = FLOW_CONTROL_REQUIRED
  205. },
  206. { /* 11 */
  207. .libais_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  208. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  209. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  210. .flow_control = FLOW_CONTROL_REQUIRED
  211. },
  212. { /* 12 */
  213. .libais_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  214. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  215. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  216. .flow_control = FLOW_CONTROL_REQUIRED
  217. },
  218. { /* 13 */
  219. .libais_handler_fn = message_handler_req_lib_ckpt_sectionread,
  220. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  221. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  222. .flow_control = FLOW_CONTROL_REQUIRED
  223. },
  224. { /* 14 */
  225. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  226. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  227. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  228. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  229. },
  230. { /* 15 */
  231. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  232. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), /* TODO RESPONSE */
  233. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  234. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  235. },
  236. { /* 16 */
  237. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratorinitialize,
  238. .response_size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize),
  239. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE,
  240. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  241. },
  242. { /* 17 */
  243. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratornext,
  244. .response_size = sizeof (struct res_lib_ckpt_sectioniteratornext),
  245. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT,
  246. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  247. }
  248. };
  249. static int (*ckpt_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr, int endian_conversion_required) = {
  250. message_handler_req_exec_ckpt_checkpointopen,
  251. message_handler_req_exec_ckpt_checkpointclose,
  252. message_handler_req_exec_ckpt_checkpointunlink,
  253. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  254. message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  255. message_handler_req_exec_ckpt_sectioncreate,
  256. message_handler_req_exec_ckpt_sectiondelete,
  257. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  258. message_handler_req_exec_ckpt_sectionwrite,
  259. message_handler_req_exec_ckpt_sectionoverwrite,
  260. message_handler_req_exec_ckpt_sectionread,
  261. message_handler_req_exec_ckpt_synchronize_state,
  262. message_handler_req_exec_ckpt_synchronize_section
  263. };
  264. struct service_handler ckpt_service_handler = {
  265. .libais_handlers = ckpt_libais_handlers,
  266. .libais_handlers_count = sizeof (ckpt_libais_handlers) / sizeof (struct libais_handler),
  267. .aisexec_handler_fns = ckpt_aisexec_handler_fns,
  268. .aisexec_handler_fns_count = sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  269. .confchg_fn = ckpt_confchg_fn,
  270. .libais_init_fn = message_handler_req_lib_ckpt_init,
  271. .libais_exit_fn = ckpt_exit_fn,
  272. .exec_init_fn = ckpt_exec_init_fn,
  273. .exec_dump_fn = 0,
  274. .sync_init = ckpt_recovery_initialize,
  275. .sync_process = ckpt_recovery_process,
  276. .sync_activate = ckpt_recovery_activate,
  277. .sync_abort = ckpt_recovery_abort,
  278. };
  279. static int processor_index_set(struct in_addr *proc_addr,
  280. struct ckpt_refcnt *ckpt_refcount)
  281. {
  282. int i;
  283. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  284. /*
  285. * If the source addresses match then this processor index
  286. * has already been set
  287. */
  288. if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  289. return -1;
  290. } else if (ckpt_refcount[i].addr.s_addr == 0) {
  291. /*
  292. * If the source addresses do not match and this element
  293. * has no stored value then store the new value and
  294. * return the Index.
  295. */
  296. memcpy(&ckpt_refcount[i].addr, proc_addr, sizeof(struct in_addr));
  297. return i;
  298. }
  299. }
  300. /*
  301. * Could not Find an empty slot
  302. * to store the new Processor.
  303. */
  304. return -1;
  305. }
  306. static int processor_index_find(struct in_addr *proc_addr,
  307. struct ckpt_refcnt *ckpt_refcount)
  308. {
  309. int i;
  310. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  311. /*
  312. * If the source addresses match then return the index
  313. */
  314. if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  315. return i;
  316. }
  317. }
  318. /*
  319. * Could not Find the Processor
  320. */
  321. return -1;
  322. }
  323. static int ckpt_refcount_total(struct ckpt_refcnt *ckpt_refcount)
  324. {
  325. int i;
  326. int total = 0;
  327. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  328. total += ckpt_refcount[i].count;
  329. }
  330. return total;
  331. }
  332. static void initialize_ckpt_refcount_array (struct ckpt_refcnt *ckpt_refcount)
  333. {
  334. memset((char*)ckpt_refcount, 0, PROCESSOR_COUNT_MAX * sizeof(struct ckpt_refcnt));
  335. }
  336. static void ckpt_recovery_initialize (void)
  337. {
  338. struct list_head *checkpoint_list;
  339. struct list_head *checkpoint_section_list;
  340. struct saCkptCheckpoint *checkpoint;
  341. struct saCkptCheckpointSection *section;
  342. struct saCkptCheckpoint *savedCheckpoint;
  343. struct saCkptCheckpointSection *savedSection;
  344. if (recovery_abort) { /*Abort was called.*/
  345. return;
  346. }
  347. /*
  348. * Save off the existing Checkpoints to be used by ckpt_recovery_process
  349. */
  350. for (checkpoint_list = checkpoint_list_head.next;
  351. checkpoint_list != &checkpoint_list_head;
  352. checkpoint_list = checkpoint_list->next) {
  353. checkpoint = list_entry (checkpoint_list,
  354. struct saCkptCheckpoint, list);
  355. if (checkpoint->referenceCount <= 0) {
  356. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_initialize checkpoint %s has referenceCount 0 ignoring.\n",
  357. (char*)&checkpoint->name.value);
  358. continue;
  359. }
  360. savedCheckpoint =
  361. (struct saCkptCheckpoint *) malloc (sizeof(struct saCkptCheckpoint));
  362. assert(savedCheckpoint);
  363. memcpy(savedCheckpoint, checkpoint, sizeof(struct saCkptCheckpoint));
  364. list_init(&savedCheckpoint->list);
  365. list_add(&savedCheckpoint->list,&checkpoint_recovery_list_head);
  366. list_init(&savedCheckpoint->checkpointSectionsListHead);
  367. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  368. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  369. checkpoint_section_list = checkpoint_section_list->next) {
  370. section = list_entry (checkpoint_section_list,
  371. struct saCkptCheckpointSection, list);
  372. savedSection =
  373. (struct saCkptCheckpointSection *) malloc (sizeof(struct saCkptCheckpointSection));
  374. assert(savedSection);
  375. memcpy(savedSection, section, sizeof(struct saCkptCheckpointSection));
  376. list_init(&savedSection->list);
  377. list_add(&savedSection->list,&savedCheckpoint->checkpointSectionsListHead);
  378. }
  379. }
  380. if (list_empty (&checkpoint_recovery_list_head)) {
  381. return;
  382. }
  383. recovery_ckpt_next = checkpoint_recovery_list_head.next;
  384. savedCheckpoint = list_entry (recovery_ckpt_next,
  385. struct saCkptCheckpoint, list);
  386. recovery_ckpt_section_next = savedCheckpoint->checkpointSectionsListHead.next;
  387. }
  388. static int ckpt_recovery_process (void)
  389. {
  390. struct req_exec_ckpt_synchronize_state request_exec_sync_state;
  391. struct req_exec_ckpt_synchronize_section request_exec_sync_section;
  392. struct iovec iovecs[3];
  393. struct saCkptCheckpoint *checkpoint;
  394. struct saCkptCheckpointSection *ckptCheckpointSection;
  395. SaSizeT origSectionSize;
  396. SaSizeT newSectionSize;
  397. if (recovery_abort) { /*Abort was called.*/
  398. goto recovery_exit_clean;
  399. }
  400. /*So Initialize did not have any checkpoints to Synchronize*/
  401. if ((recovery_ckpt_next == 0) && (recovery_ckpt_section_next == 0)) {
  402. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_process Nothing to Process ...\n");
  403. goto recovery_exit_clean;
  404. }
  405. /*
  406. * ALGORITHM :
  407. * 1.) extract the checkpoint if there.
  408. * 2.) If there is a checkpoint then there has to be a section
  409. * 3.) If the recovery_section_send_flag was not set in the previous
  410. * invocation that means we have to send out a sync_msg before
  411. * we send out the sections
  412. * 4.) Set the recovery_section_send_flag and send the sections.
  413. */
  414. while (1) { /*Go for as long as the oubound queue is not full*/
  415. if(recovery_ckpt_next != &checkpoint_recovery_list_head) {
  416. checkpoint = list_entry (recovery_ckpt_next,
  417. struct saCkptCheckpoint, list);
  418. if (recovery_ckpt_section_next == 0) {
  419. recovery_ckpt_section_next = checkpoint->checkpointSectionsListHead.next;
  420. }
  421. if (recovery_ckpt_section_next != &checkpoint->checkpointSectionsListHead) {
  422. ckptCheckpointSection = list_entry (recovery_ckpt_section_next,
  423. struct saCkptCheckpointSection, list);
  424. /*
  425. * None of the section data msgs have been sent
  426. * so lets start with sending the sync_msg
  427. */
  428. if (recovery_section_send_flag == 0) {
  429. if (ckptCheckpointSection->sectionDescriptor.sectionId.id == 0) {
  430. /*
  431. * This is the default section forget sending this.
  432. */
  433. recovery_ckpt_section_next = recovery_ckpt_section_next->next;
  434. continue;
  435. }
  436. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message for ckpt = %s, section = %s.\n",
  437. (char*)&checkpoint->name.value,
  438. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id));
  439. request_exec_sync_state.header.size = sizeof (struct req_exec_ckpt_synchronize_state);
  440. request_exec_sync_state.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESTATE;
  441. memcpy(&request_exec_sync_state.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  442. memcpy(&request_exec_sync_state.checkpointName, &checkpoint->name, sizeof(SaNameT));
  443. memcpy(&request_exec_sync_state.checkpointCreationAttributes,
  444. &checkpoint->checkpointCreationAttributes,
  445. sizeof(SaCkptCheckpointCreationAttributesT));
  446. memcpy(&request_exec_sync_state.sectionDescriptor,
  447. &ckptCheckpointSection->sectionDescriptor,
  448. sizeof(SaCkptSectionDescriptorT));
  449. memcpy(&request_exec_sync_state.source_addr, &this_ip->sin_addr, sizeof(struct in_addr));
  450. memcpy(request_exec_sync_state.ckpt_refcount,
  451. checkpoint->ckpt_refcount,
  452. sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  453. request_exec_sync_state.sectionDescriptor.sectionId.id = 0;
  454. iovecs[0].iov_base = (char *)&request_exec_sync_state;
  455. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_state);
  456. /*
  457. * Populate the Section ID
  458. */
  459. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  460. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  461. /*
  462. * Check to see if we can queue the new message and if you can
  463. * then mcast the message else break and create callback.
  464. */
  465. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len)){
  466. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  467. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync State Message.\n");
  468. }
  469. else {
  470. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync State Message Outbound Queue full need to Wait for Callback.\n");
  471. return (1);
  472. }
  473. recovery_section_send_flag = 1;
  474. }
  475. origSectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize;
  476. newSectionSize = 0;
  477. /*
  478. * Now Create SyncSection messsages in chunks of CKPT_MAX_SECTION_DATA_SEND or less
  479. */
  480. while (recovery_section_data_offset < origSectionSize) {
  481. /*
  482. * Send a Max of CKPT_MAX_SECTION_DATA_SEND of section data
  483. */
  484. if ((origSectionSize - recovery_section_data_offset) > CKPT_MAX_SECTION_DATA_SEND) {
  485. newSectionSize = CKPT_MAX_SECTION_DATA_SEND;
  486. }
  487. else {
  488. newSectionSize = (origSectionSize - recovery_section_data_offset);
  489. }
  490. /*
  491. * Create and save a new Sync Section message.
  492. */
  493. request_exec_sync_section.header.size = sizeof (struct req_exec_ckpt_synchronize_section);
  494. request_exec_sync_section.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESECTION;
  495. memcpy (&request_exec_sync_section.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  496. memcpy (&request_exec_sync_section.checkpointName, &checkpoint->name, sizeof(SaNameT));
  497. memcpy (&request_exec_sync_section.sectionId,
  498. &ckptCheckpointSection->sectionDescriptor.sectionId,
  499. sizeof(SaCkptSectionIdT));
  500. request_exec_sync_section.sectionId.id = 0;
  501. memcpy (&request_exec_sync_section.dataOffSet, &recovery_section_data_offset, sizeof(SaUint32T));
  502. memcpy (&request_exec_sync_section.dataSize, &newSectionSize, sizeof(SaUint32T));
  503. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync Section Message for ckpt = %s, section = %s, Data size = %d.\n",
  504. (char*)&checkpoint->name.value,
  505. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id),
  506. newSectionSize);
  507. /*
  508. * Populate the Sync Section Request
  509. */
  510. iovecs[0].iov_base = (char *)&request_exec_sync_section;
  511. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_section);
  512. /*
  513. * Populate the Section ID
  514. */
  515. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  516. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  517. /*
  518. * Populate the Section Data.
  519. */
  520. iovecs[2].iov_base = ((char*)ckptCheckpointSection->sectionData + recovery_section_data_offset);
  521. iovecs[2].iov_len = newSectionSize;
  522. /*
  523. * Check to see if we can queue the new message and if you can
  524. * then mcast the message else break and create callback.
  525. */
  526. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len + iovecs[2].iov_len)){
  527. assert (totempg_mcast (iovecs, 3, TOTEMPG_AGREED) == 0);
  528. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync Section Message.\n");
  529. }
  530. else {
  531. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync Section Message Outbound Queue full need to Wait for Callback.\n");
  532. return (1);
  533. }
  534. recovery_section_data_offset += newSectionSize;
  535. }
  536. recovery_section_send_flag = 0;
  537. recovery_section_data_offset = 0;
  538. recovery_ckpt_section_next = recovery_ckpt_section_next->next;
  539. continue;
  540. }
  541. else {
  542. /*
  543. * We have reached the end of a section List.
  544. * Move to the next element in the ckpt list.
  545. * Init the section ptr to 0 so it is re evaled
  546. */
  547. recovery_ckpt_next = recovery_ckpt_next->next;
  548. recovery_ckpt_section_next = 0;
  549. continue;
  550. }
  551. }
  552. /*Should only be here at the end of the traversal of the ckpt list*/
  553. ckpt_recovery_finalize();
  554. recovery_exit_clean:
  555. /*Re - Initialize the static's*/
  556. recovery_ckpt_next = 0;
  557. recovery_ckpt_section_next = 0;
  558. recovery_section_data_offset = 0;
  559. recovery_section_send_flag = 0;
  560. recovery_abort = 0;
  561. return (0);
  562. }
  563. }
  564. static void ckpt_recovery_finalize ()
  565. {
  566. struct list_head *checkpoint_list;
  567. struct list_head *checkpoint_section_list;
  568. struct saCkptCheckpoint *checkpoint;
  569. struct saCkptCheckpointSection *section;
  570. /*
  571. * Remove All elements from old checkpoint
  572. * list
  573. */
  574. checkpoint_list = checkpoint_list_head.next;
  575. while (!list_empty(&checkpoint_list_head)) {
  576. checkpoint = list_entry (checkpoint_list,
  577. struct saCkptCheckpoint, list);
  578. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  579. while (!list_empty(&checkpoint->checkpointSectionsListHead)) {
  580. section = list_entry (checkpoint_section_list,
  581. struct saCkptCheckpointSection, list);
  582. list_del (&section->list);
  583. free (section);
  584. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  585. }
  586. list_del(&checkpoint->list);
  587. free(checkpoint);
  588. checkpoint_list = checkpoint_list_head.next;
  589. }
  590. /*
  591. * Initialize the old list again.
  592. */
  593. list_init(&checkpoint_list_head);
  594. /*
  595. * Copy the contents of the new list_head into the old list head
  596. */
  597. checkpoint_recovery_list_head.prev->next = &checkpoint_list_head;
  598. checkpoint_recovery_list_head.next->prev = &checkpoint_list_head;
  599. memcpy(&checkpoint_list_head, &checkpoint_recovery_list_head, sizeof(struct list_head));
  600. /*
  601. * Initialize the new list head for reuse.
  602. */
  603. list_init(&checkpoint_recovery_list_head);
  604. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_finalize Done.\n");
  605. }
  606. static void ckpt_recovery_activate (void)
  607. {
  608. recovery_state = SYNCHRONY_STATE_ENDED;
  609. return;
  610. }
  611. static void ckpt_recovery_abort (void)
  612. {
  613. recovery_abort = 1;
  614. return;
  615. }
  616. static void ckpt_recovery_process_members_exit(struct in_addr *left_list, int left_list_entries)
  617. {
  618. struct list_head *checkpoint_list;
  619. struct saCkptCheckpoint *checkpoint;
  620. struct in_addr *member;
  621. int index;
  622. int i;
  623. if (left_list_entries == 0) {
  624. return;
  625. }
  626. /*
  627. * Iterate left_list_entries.
  628. */
  629. member = left_list;
  630. for (i = 0; i < left_list_entries; i++) {
  631. for (checkpoint_list = checkpoint_list_head.next;
  632. checkpoint_list != &checkpoint_list_head;
  633. checkpoint_list = checkpoint_list->next) {
  634. checkpoint = list_entry (checkpoint_list,
  635. struct saCkptCheckpoint, list);
  636. index = processor_index_find(member, checkpoint->ckpt_refcount);
  637. if (index == -1) {
  638. continue;
  639. }
  640. /*
  641. * Decrement
  642. *
  643. */
  644. if (checkpoint->referenceCount >= 0) {
  645. checkpoint->referenceCount -= checkpoint->ckpt_refcount[index].count;
  646. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  647. &checkpoint->name.value,checkpoint->referenceCount);
  648. assert (checkpoint->referenceCount >= 0);
  649. } else {
  650. log_printf (LOG_LEVEL_ERROR, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  651. &checkpoint->name.value,checkpoint->referenceCount);
  652. assert(0);
  653. }
  654. checkpoint->ckpt_refcount[index].count = 0;
  655. memset((char*)&checkpoint->ckpt_refcount[index].addr, 0, sizeof(struct in_addr));
  656. /*
  657. * If checkpoint has been unlinked and this is the last reference, delete it
  658. */
  659. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  660. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Unlinking checkpoint %s.\n",
  661. &checkpoint->name.value);
  662. checkpoint_release (checkpoint);
  663. } else
  664. if (checkpoint->referenceCount == 0) {
  665. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Starting timer to release checkpoint %s.\n",
  666. &checkpoint->name.value);
  667. poll_timer_add (aisexec_poll_handle,
  668. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  669. checkpoint,
  670. timer_function_retention,
  671. &checkpoint->retention_timer);
  672. }
  673. }
  674. member++;
  675. }
  676. return;
  677. }
  678. static int ckpt_confchg_fn (
  679. enum totem_configuration_type configuration_type,
  680. struct in_addr *member_list, void *member_list_private,
  681. int member_list_entries,
  682. struct in_addr *left_list, void *left_list_private,
  683. int left_list_entries,
  684. struct in_addr *joined_list, void *joined_list_private,
  685. int joined_list_entries,
  686. struct memb_ring_id *ring_id)
  687. {
  688. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  689. #ifdef TODO
  690. totempg_recovery_plug_unplug (ckpt_checkpoint_recovery_plug_handle);
  691. #endif
  692. if (recovery_state == SYNCHRONY_STATE_ENDED) {
  693. memcpy (&saved_ring_id, ring_id, sizeof(struct memb_ring_id));
  694. }
  695. }
  696. else if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  697. ckpt_recovery_process_members_exit(left_list, left_list_entries);
  698. recovery_state = SYNCHRONY_STATE_STARTED;
  699. recovery_abort = 0;
  700. }
  701. return (0);
  702. }
  703. static struct saCkptCheckpoint *ckpt_checkpoint_find_global (SaNameT *name)
  704. {
  705. struct list_head *checkpoint_list;
  706. struct saCkptCheckpoint *checkpoint;
  707. for (checkpoint_list = checkpoint_list_head.next;
  708. checkpoint_list != &checkpoint_list_head;
  709. checkpoint_list = checkpoint_list->next) {
  710. checkpoint = list_entry (checkpoint_list,
  711. struct saCkptCheckpoint, list);
  712. if (name_match (name, &checkpoint->name)) {
  713. return (checkpoint);
  714. }
  715. }
  716. return (0);
  717. }
  718. static void ckpt_checkpoint_remove_cleanup (
  719. struct conn_info *conn_info,
  720. struct saCkptCheckpoint *checkpoint)
  721. {
  722. struct list_head *list;
  723. struct checkpoint_cleanup *checkpoint_cleanup;
  724. for (list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  725. list != &conn_info->ais_ci.u.libckpt_ci.checkpoint_list;
  726. list = list->next) {
  727. checkpoint_cleanup = list_entry (list,
  728. struct checkpoint_cleanup, list);
  729. if (name_match (&checkpoint_cleanup->checkpoint.name, &checkpoint->name)
  730. || (checkpoint_cleanup->checkpoint.name.length == 0)) {
  731. list_del (&checkpoint_cleanup->list);
  732. free (checkpoint_cleanup);
  733. return;
  734. }
  735. }
  736. }
  737. static struct saCkptCheckpointSection *ckpt_checkpoint_find_globalSection (
  738. struct saCkptCheckpoint *ckptCheckpoint,
  739. char *id,
  740. int idLen)
  741. {
  742. struct list_head *checkpoint_section_list;
  743. struct saCkptCheckpointSection *ckptCheckpointSection;
  744. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", (char*)id, idLen);
  745. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  746. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  747. checkpoint_section_list = checkpoint_section_list->next) {
  748. ckptCheckpointSection = list_entry (checkpoint_section_list,
  749. struct saCkptCheckpointSection, list);
  750. log_printf (LOG_LEVEL_DEBUG, "Checking section id %*s\n",
  751. (int)ckptCheckpointSection->sectionDescriptor.sectionId.idLen,
  752. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  753. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  754. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  755. id, idLen) == 0)) {
  756. return (ckptCheckpointSection);
  757. }
  758. }
  759. return 0;
  760. }
  761. void checkpoint_section_release (struct saCkptCheckpointSection *section)
  762. {
  763. list_del (&section->list);
  764. free (section->sectionDescriptor.sectionId.id);
  765. free (section->sectionData);
  766. poll_timer_delete (aisexec_poll_handle, section->expiration_timer);
  767. free (section);
  768. }
  769. void checkpoint_release (struct saCkptCheckpoint *checkpoint)
  770. {
  771. struct list_head *list;
  772. struct saCkptCheckpointSection *section;
  773. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  774. /*
  775. * Release all checkpoint sections for this checkpoint
  776. */
  777. for (list = checkpoint->checkpointSectionsListHead.next;
  778. list != &checkpoint->checkpointSectionsListHead;) {
  779. section = list_entry (list,
  780. struct saCkptCheckpointSection, list);
  781. list = list->next;
  782. checkpoint_section_release (section);
  783. }
  784. list_del (&checkpoint->list);
  785. free (checkpoint);
  786. }
  787. int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
  788. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  789. struct iovec iovecs[2];
  790. if (checkpoint->expired == 1) {
  791. return (0);
  792. }
  793. req_exec_ckpt_checkpointclose.header.size =
  794. sizeof (struct req_exec_ckpt_checkpointclose);
  795. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  796. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  797. &checkpoint->name, sizeof (SaNameT));
  798. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  799. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  800. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  801. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  802. return (0);
  803. }
  804. return (-1);
  805. }
  806. static int ckpt_exec_init_fn (void)
  807. {
  808. /*
  809. * Initialize the saved ring ID.
  810. */
  811. saved_ring_id.seq = 0;
  812. saved_ring_id.rep.s_addr = this_ip->sin_addr.s_addr;
  813. #ifdef TODO
  814. int res;
  815. res = totempg_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  816. if (res != 0) {
  817. log_printf(LOG_LEVEL_ERROR,
  818. "Could not create recovery plug for clm service.\n");
  819. return (-1);
  820. }
  821. #endif
  822. return (0);
  823. }
  824. static int ckpt_exit_fn (struct conn_info *conn_info)
  825. {
  826. struct checkpoint_cleanup *checkpoint_cleanup;
  827. struct list_head *cleanup_list;
  828. if (conn_info->service != SOCKET_SERVICE_CKPT) {
  829. return 0;
  830. }
  831. /*
  832. * close all checkpoints opened on this fd
  833. */
  834. cleanup_list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  835. while (!list_empty(&conn_info->ais_ci.u.libckpt_ci.checkpoint_list)) {
  836. checkpoint_cleanup = list_entry (cleanup_list,
  837. struct checkpoint_cleanup, list);
  838. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  839. ckpt_checkpoint_close (&checkpoint_cleanup->checkpoint);
  840. }
  841. list_del (&checkpoint_cleanup->list);
  842. free (checkpoint_cleanup);
  843. cleanup_list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  844. }
  845. if (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  846. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  847. }
  848. list_del (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  849. return (0);
  850. }
  851. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  852. {
  853. struct res_lib_activatepoll res_lib_activatepoll;
  854. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  855. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  856. res_lib_activatepoll.header.error = SA_AIS_OK;
  857. libais_send_response (conn_info, &res_lib_activatepoll,
  858. sizeof (struct res_lib_activatepoll));
  859. return (0);
  860. }
  861. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  862. {
  863. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  864. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  865. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  866. struct saCkptCheckpoint *ckptCheckpoint = 0;
  867. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  868. struct checkpoint_cleanup *checkpoint_cleanup;
  869. SaErrorT error = SA_AIS_OK;
  870. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  871. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  872. /*
  873. * If checkpoint doesn't exist, create one
  874. */
  875. if (ckptCheckpoint == 0) {
  876. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  877. if (ckptCheckpoint == 0) {
  878. error = SA_AIS_ERR_NO_MEMORY;
  879. goto error_exit;
  880. }
  881. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  882. if (ckptCheckpointSection == 0) {
  883. free (ckptCheckpoint);
  884. error = SA_AIS_ERR_NO_MEMORY;
  885. goto error_exit;
  886. }
  887. memcpy (&ckptCheckpoint->name,
  888. &req_lib_ckpt_checkpointopen->checkpointName,
  889. sizeof (SaNameT));
  890. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  891. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  892. sizeof (SaCkptCheckpointCreationAttributesT));
  893. ckptCheckpoint->unlinked = 0;
  894. list_init (&ckptCheckpoint->list);
  895. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  896. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  897. ckptCheckpoint->referenceCount = 0;
  898. ckptCheckpoint->retention_timer = 0;
  899. ckptCheckpoint->expired = 0;
  900. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  901. /*
  902. * Add in default checkpoint section
  903. */
  904. list_init (&ckptCheckpointSection->list);
  905. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  906. /*
  907. * Default section id
  908. */
  909. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  910. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  911. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  912. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  913. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  914. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  915. ckptCheckpointSection->sectionData = 0;
  916. ckptCheckpointSection->expiration_timer = 0;
  917. }
  918. /*
  919. * If the checkpoint has been unlinked, it is an invalid name
  920. */
  921. if (ckptCheckpoint->unlinked) {
  922. error = SA_AIS_ERR_INVALID_PARAM; /* Is this the correct return ? */
  923. goto error_exit;
  924. }
  925. /*
  926. * Setup connection information and mark checkpoint as referenced
  927. */
  928. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  929. ckptCheckpoint->referenceCount += 1;
  930. /*
  931. * Add the connection reference information to the Checkpoint to be
  932. * sent out later as a part of the sync process.
  933. *
  934. */
  935. int proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  936. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  937. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  938. }
  939. if (proc_index != -1 ) {
  940. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  941. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  942. }
  943. else {
  944. log_printf (LOG_LEVEL_ERROR,
  945. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  946. ckptCheckpoint);
  947. }
  948. /*
  949. * Reset retention duration since this checkpoint was just opened
  950. */
  951. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  952. ckptCheckpoint->retention_timer = 0;
  953. /*
  954. * Send error result to CKPT library
  955. */
  956. error_exit:
  957. /*
  958. * If this node was the source of the message, respond to this node
  959. */
  960. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  961. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  962. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  963. res_lib_ckpt_checkpointopen.header.error = error;
  964. if (error == SA_AIS_OK) {
  965. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  966. if (checkpoint_cleanup == 0) {
  967. free (ckptCheckpoint);
  968. error = SA_AIS_ERR_NO_MEMORY;
  969. } else {
  970. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  971. list_add (&checkpoint_cleanup->list,
  972. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  973. }
  974. }
  975. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  976. sizeof (struct res_lib_ckpt_checkpointopen));
  977. }
  978. /* return (error == SA_AIS_OK ? 0 : -1); */
  979. return (0);
  980. }
  981. static int recovery_checkpoint_open(SaNameT *checkpointName,
  982. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  983. struct ckpt_refcnt *ref_cnt)
  984. {
  985. struct saCkptCheckpoint *ckptCheckpoint = 0;
  986. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  987. SaErrorT error = SA_AIS_OK;
  988. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  989. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  990. /*
  991. * If checkpoint doesn't exist, create one
  992. */
  993. if (ckptCheckpoint == 0) {
  994. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  995. if (ckptCheckpoint == 0) {
  996. error = SA_AIS_ERR_NO_MEMORY;
  997. goto error_exit;
  998. }
  999. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1000. if (ckptCheckpointSection == 0) {
  1001. free (ckptCheckpoint);
  1002. error = SA_AIS_ERR_NO_MEMORY;
  1003. goto error_exit;
  1004. }
  1005. memcpy (&ckptCheckpoint->name,
  1006. checkpointName,
  1007. sizeof (SaNameT));
  1008. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1009. ckptAttributes,
  1010. sizeof (SaCkptCheckpointCreationAttributesT));
  1011. ckptCheckpoint->unlinked = 0;
  1012. list_init (&ckptCheckpoint->list);
  1013. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1014. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1015. ckptCheckpoint->retention_timer = 0;
  1016. ckptCheckpoint->expired = 0;
  1017. /*
  1018. * Add in default checkpoint section
  1019. */
  1020. list_init (&ckptCheckpointSection->list);
  1021. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1022. /*
  1023. * Default section id
  1024. */
  1025. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1026. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1027. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  1028. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1029. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1030. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1031. ckptCheckpointSection->sectionData = 0;
  1032. ckptCheckpointSection->expiration_timer = 0;
  1033. }
  1034. /*
  1035. * If the checkpoint has been unlinked, it is an invalid name
  1036. */
  1037. if (ckptCheckpoint->unlinked) {
  1038. error = SA_AIS_ERR_BAD_CHECKPOINT; /* Is this the correct return ? */
  1039. goto error_exit;
  1040. }
  1041. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1042. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1043. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1044. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1045. /*
  1046. * Setup connection information and mark checkpoint as referenced
  1047. */
  1048. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1049. /*
  1050. * Reset retention duration since this checkpoint was just opened
  1051. */
  1052. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1053. ckptCheckpoint->retention_timer = 0;
  1054. /*
  1055. * Send error result to CKPT library
  1056. */
  1057. error_exit:
  1058. return (error);
  1059. }
  1060. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1061. {
  1062. int retcode;
  1063. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1064. = (struct req_exec_ckpt_synchronize_state *)message;
  1065. /*
  1066. * If the Incoming message's previous ring id == saved_ring_id
  1067. * Ignore because we have seen this message before.
  1068. */
  1069. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1070. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1071. return(0);
  1072. }
  1073. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1074. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1075. req_exec_ckpt_sync_state->ckpt_refcount);
  1076. if (retcode != SA_AIS_OK) {
  1077. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1078. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1079. }
  1080. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1081. &req_exec_ckpt_sync_state->checkpointName,
  1082. (char*)req_exec_ckpt_sync_state
  1083. + sizeof (struct req_exec_ckpt_synchronize_state));
  1084. if (retcode != SA_AIS_OK) {
  1085. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1086. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1087. }
  1088. return (0);
  1089. }
  1090. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1091. {
  1092. int retcode;
  1093. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1094. = (struct req_exec_ckpt_synchronize_section *)message;
  1095. /*
  1096. * If the Incoming message's previous ring id == saved_ring_id
  1097. * Ignore because we have seen this message before.
  1098. */
  1099. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1100. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1101. return(0);
  1102. }
  1103. /*
  1104. * Write the contents of the section to the checkpoint section.
  1105. */
  1106. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1107. (char*)req_exec_ckpt_sync_section
  1108. + sizeof (struct req_exec_ckpt_synchronize_section),
  1109. &req_exec_ckpt_sync_section->checkpointName,
  1110. (char*)req_exec_ckpt_sync_section
  1111. + sizeof (struct req_exec_ckpt_synchronize_section)
  1112. + req_exec_ckpt_sync_section->sectionId.idLen,
  1113. req_exec_ckpt_sync_section->dataOffSet,
  1114. req_exec_ckpt_sync_section->dataSize);
  1115. if (retcode != SA_AIS_OK) {
  1116. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1117. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1118. }
  1119. return (0);
  1120. }
  1121. unsigned int abstime_to_msec (SaTimeT time)
  1122. {
  1123. struct timeval tv;
  1124. unsigned long long curr_time;
  1125. unsigned long long msec_time;
  1126. gettimeofday (&tv, NULL);
  1127. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1128. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1129. msec_time = (((unsigned long long)time) / 1000000) -
  1130. (unsigned long long)curr_time;
  1131. return ((unsigned int)(msec_time));
  1132. }
  1133. void timer_function_section_expire (void *data)
  1134. {
  1135. struct saCkptCheckpointSection *section = (struct saCkptCheckpointSection *)data;
  1136. if (section->sectionDescriptor.sectionId.id) {
  1137. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring section %s\n", section->sectionDescriptor.sectionId.id);
  1138. }
  1139. checkpoint_section_release (section);
  1140. }
  1141. void timer_function_retention (void *data)
  1142. {
  1143. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1144. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1145. struct iovec iovec;
  1146. checkpoint->retention_timer = 0;
  1147. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1148. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1149. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1150. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1151. &checkpoint->name,
  1152. sizeof (SaNameT));
  1153. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1154. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1155. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1156. }
  1157. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1158. {
  1159. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1160. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1161. struct saCkptCheckpoint *checkpoint = 0;
  1162. SaAisErrorT error = SA_AIS_OK;
  1163. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1164. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1165. if (checkpoint == 0) {
  1166. goto error_exit;
  1167. }
  1168. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1169. checkpoint->referenceCount--;
  1170. /*
  1171. * Modify the connection reference information to the Checkpoint to be
  1172. * sent out later as a part of the sync process.
  1173. */
  1174. int proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1175. if (proc_index != -1 ) {
  1176. checkpoint->ckpt_refcount[proc_index].count--;
  1177. }
  1178. else {
  1179. log_printf (LOG_LEVEL_ERROR,
  1180. "CKPT: Could Not find Processor Info %p info.\n",
  1181. checkpoint);
  1182. }
  1183. assert (checkpoint->referenceCount >= 0);
  1184. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1185. checkpoint->referenceCount);
  1186. /*
  1187. * If checkpoint has been unlinked and this is the last reference, delete it
  1188. */
  1189. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1190. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1191. checkpoint_release (checkpoint);
  1192. } else
  1193. if (checkpoint->referenceCount == 0) {
  1194. poll_timer_add (aisexec_poll_handle,
  1195. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1196. checkpoint,
  1197. timer_function_retention,
  1198. &checkpoint->retention_timer);
  1199. }
  1200. error_exit:
  1201. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1202. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1203. checkpoint);
  1204. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1205. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1206. res_lib_ckpt_checkpointclose.header.error = error;
  1207. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1208. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1209. }
  1210. return (0);
  1211. }
  1212. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1213. {
  1214. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1215. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1216. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1217. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1218. SaErrorT error = SA_AIS_OK;
  1219. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1220. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1221. if (ckptCheckpoint == 0) {
  1222. error = SA_AIS_ERR_NOT_EXIST;
  1223. goto error_exit;
  1224. }
  1225. if (ckptCheckpoint->unlinked) {
  1226. error = SA_AIS_ERR_INVALID_PARAM;
  1227. goto error_exit;
  1228. }
  1229. ckptCheckpoint->unlinked = 1;
  1230. /*
  1231. * Immediately delete entry if reference count is zero
  1232. */
  1233. if (ckptCheckpoint->referenceCount == 0) {
  1234. /*
  1235. * Remove retention timer since this checkpoint was unlinked and is no
  1236. * longer referenced
  1237. */
  1238. checkpoint_release (ckptCheckpoint);
  1239. }
  1240. error_exit:
  1241. /*
  1242. * If this node was the source of the message, respond to this node
  1243. */
  1244. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1245. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1246. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1247. res_lib_ckpt_checkpointunlink.header.error = error;
  1248. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1249. sizeof (struct res_lib_ckpt_checkpointunlink));
  1250. }
  1251. return (0);
  1252. }
  1253. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1254. {
  1255. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1256. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1257. struct saCkptCheckpoint *checkpoint;
  1258. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1259. if (checkpoint) {
  1260. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  1261. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1262. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1263. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1264. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1265. poll_timer_add (aisexec_poll_handle,
  1266. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1267. checkpoint,
  1268. timer_function_retention,
  1269. &checkpoint->retention_timer);
  1270. }
  1271. }
  1272. /*
  1273. * Respond to library if this processor sent the duration set request
  1274. */
  1275. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1276. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1277. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1278. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_AIS_OK;
  1279. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1280. &res_lib_ckpt_checkpointretentiondurationset,
  1281. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1282. }
  1283. return (0);
  1284. }
  1285. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1286. {
  1287. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1288. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1289. struct saCkptCheckpoint *checkpoint;
  1290. struct iovec iovecs[2];
  1291. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1292. if (checkpoint && checkpoint->expired == 0) {
  1293. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1294. checkpoint->expired = 1;
  1295. req_exec_ckpt_checkpointunlink.header.size =
  1296. sizeof (struct req_exec_ckpt_checkpointunlink);
  1297. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1298. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1299. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1300. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1301. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1302. sizeof (SaNameT));
  1303. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1304. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1305. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1306. }
  1307. return (0);
  1308. }
  1309. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1310. SaNameT *checkpointName,
  1311. char* SectionId)
  1312. {
  1313. struct saCkptCheckpoint *ckptCheckpoint;
  1314. struct saCkptCheckpointSection *ckptCheckpointSection;
  1315. void *initialData;
  1316. void *sectionId;
  1317. SaErrorT error = SA_AIS_OK;
  1318. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1319. &checkpointName->value, SectionId);
  1320. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1321. if (ckptCheckpoint == 0) {
  1322. error = SA_AIS_ERR_NOT_EXIST;
  1323. goto error_exit;
  1324. }
  1325. /*
  1326. * Determine if user-specified checkpoint ID already exists
  1327. */
  1328. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1329. SectionId,
  1330. (int)sectionDescriptor->sectionId.idLen);
  1331. if (ckptCheckpointSection) {
  1332. error = SA_AIS_ERR_EXIST;
  1333. goto error_exit;
  1334. }
  1335. /*
  1336. * Allocate checkpoint section
  1337. */
  1338. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1339. if (ckptCheckpointSection == 0) {
  1340. error = SA_AIS_ERR_NO_MEMORY;
  1341. goto error_exit;
  1342. }
  1343. /*
  1344. * Allocate checkpoint section data
  1345. */
  1346. initialData = malloc (sectionDescriptor->sectionSize);
  1347. if (initialData == 0) {
  1348. free (ckptCheckpointSection);
  1349. error = SA_AIS_ERR_NO_MEMORY;
  1350. goto error_exit;
  1351. }
  1352. /*
  1353. * Allocate checkpoint section id
  1354. */
  1355. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1356. if (sectionId == 0) {
  1357. free (ckptCheckpointSection);
  1358. free (initialData);
  1359. error = SA_AIS_ERR_NO_MEMORY;
  1360. goto error_exit;
  1361. }
  1362. /*
  1363. * Copy checkpoint section ID and initialize data.
  1364. */
  1365. memcpy ((char*)sectionId, SectionId,
  1366. (int)sectionDescriptor->sectionId.idLen);
  1367. memset (initialData, 0, sectionDescriptor->sectionSize);
  1368. /*
  1369. * Configure checkpoint section
  1370. */
  1371. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1372. sectionDescriptor,
  1373. sizeof(SaCkptSectionDescriptorT));
  1374. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1375. ckptCheckpointSection->sectionData = initialData;
  1376. ckptCheckpointSection->expiration_timer = 0;
  1377. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1378. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1379. poll_timer_add (aisexec_poll_handle,
  1380. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1381. ckptCheckpointSection,
  1382. timer_function_section_expire,
  1383. &ckptCheckpointSection->expiration_timer);
  1384. }
  1385. /*
  1386. * Add checkpoint section to checkpoint
  1387. */
  1388. list_init (&ckptCheckpointSection->list);
  1389. list_add (&ckptCheckpointSection->list,
  1390. &ckptCheckpoint->checkpointSectionsListHead);
  1391. error_exit:
  1392. return (error);
  1393. }
  1394. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1395. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1396. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1397. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1398. struct saCkptCheckpoint *ckptCheckpoint;
  1399. struct saCkptCheckpointSection *ckptCheckpointSection;
  1400. void *initialData;
  1401. void *sectionId;
  1402. SaErrorT error = SA_AIS_OK;
  1403. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1404. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1405. if (ckptCheckpoint == 0) {
  1406. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1407. goto error_exit;
  1408. }
  1409. /*
  1410. * Determine if user-specified checkpoint ID already exists
  1411. */
  1412. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1413. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1414. req_lib_ckpt_sectioncreate->idLen);
  1415. if (ckptCheckpointSection) {
  1416. error = SA_AIS_ERR_EXIST;
  1417. goto error_exit;
  1418. }
  1419. /*
  1420. * Allocate checkpoint section
  1421. */
  1422. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1423. if (ckptCheckpointSection == 0) {
  1424. error = SA_AIS_ERR_NO_MEMORY;
  1425. goto error_exit;
  1426. }
  1427. /*
  1428. * Allocate checkpoint section data
  1429. */
  1430. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1431. if (initialData == 0) {
  1432. free (ckptCheckpointSection);
  1433. error = SA_AIS_ERR_NO_MEMORY;
  1434. goto error_exit;
  1435. }
  1436. /*
  1437. * Allocate checkpoint section id
  1438. */
  1439. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1440. if (sectionId == 0) {
  1441. free (ckptCheckpointSection);
  1442. free (initialData);
  1443. error = SA_AIS_ERR_NO_MEMORY;
  1444. goto error_exit;
  1445. }
  1446. /*
  1447. * Copy checkpoint section and section ID
  1448. */
  1449. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1450. req_lib_ckpt_sectioncreate->idLen);
  1451. memcpy (initialData,
  1452. ((char *)req_lib_ckpt_sectioncreate) +
  1453. sizeof (struct req_lib_ckpt_sectioncreate) +
  1454. req_lib_ckpt_sectioncreate->idLen,
  1455. req_lib_ckpt_sectioncreate->initialDataSize);
  1456. /*
  1457. * Configure checkpoint section
  1458. */
  1459. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1460. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1461. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1462. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1463. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1464. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1465. ckptCheckpointSection->sectionData = initialData;
  1466. ckptCheckpointSection->expiration_timer = 0;
  1467. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1468. poll_timer_add (aisexec_poll_handle,
  1469. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1470. ckptCheckpointSection,
  1471. timer_function_section_expire,
  1472. &ckptCheckpointSection->expiration_timer);
  1473. }
  1474. /*
  1475. * Add checkpoint section to checkpoint
  1476. */
  1477. list_init (&ckptCheckpointSection->list);
  1478. list_add (&ckptCheckpointSection->list,
  1479. &ckptCheckpoint->checkpointSectionsListHead);
  1480. error_exit:
  1481. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1482. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1483. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1484. res_lib_ckpt_sectioncreate.header.error = error;
  1485. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1486. &res_lib_ckpt_sectioncreate,
  1487. sizeof (struct res_lib_ckpt_sectioncreate));
  1488. }
  1489. return (0);
  1490. }
  1491. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1492. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1493. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1494. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1495. struct saCkptCheckpoint *ckptCheckpoint;
  1496. struct saCkptCheckpointSection *ckptCheckpointSection;
  1497. SaErrorT error = SA_AIS_OK;
  1498. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1499. if (ckptCheckpoint == 0) {
  1500. error = SA_AIS_ERR_NOT_EXIST;
  1501. goto error_exit;
  1502. }
  1503. /*
  1504. * Determine if the user is trying to delete the default section
  1505. */
  1506. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1507. error = SA_AIS_ERR_INVALID_PARAM;
  1508. goto error_exit;
  1509. }
  1510. /*
  1511. * Find checkpoint section to be deleted
  1512. */
  1513. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1514. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1515. req_lib_ckpt_sectiondelete->idLen);
  1516. if (ckptCheckpointSection == 0) {
  1517. error = SA_AIS_ERR_NOT_EXIST;
  1518. goto error_exit;
  1519. }
  1520. /*
  1521. * Delete checkpoint section
  1522. */
  1523. checkpoint_section_release (ckptCheckpointSection);
  1524. /*
  1525. * return result to CKPT library
  1526. */
  1527. error_exit:
  1528. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  1529. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1530. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1531. res_lib_ckpt_sectiondelete.header.error = error;
  1532. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1533. &res_lib_ckpt_sectiondelete,
  1534. sizeof (struct res_lib_ckpt_sectiondelete));
  1535. }
  1536. return (0);
  1537. }
  1538. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1539. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1540. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1541. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1542. struct saCkptCheckpoint *ckptCheckpoint;
  1543. struct saCkptCheckpointSection *ckptCheckpointSection;
  1544. SaErrorT error = SA_AIS_OK;
  1545. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  1546. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  1547. if (ckptCheckpoint == 0) {
  1548. error = SA_AIS_ERR_NOT_EXIST;
  1549. goto error_exit;
  1550. }
  1551. /*
  1552. * Determine if the user is trying to set expiration time for the default section
  1553. */
  1554. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  1555. error = SA_AIS_ERR_INVALID_PARAM;
  1556. goto error_exit;
  1557. }
  1558. /*
  1559. * Find checkpoint section that expiration time should be set for
  1560. */
  1561. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1562. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  1563. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  1564. req_lib_ckpt_sectionexpirationtimeset->idLen);
  1565. if (ckptCheckpointSection == 0) {
  1566. error = SA_AIS_ERR_NOT_EXIST;
  1567. goto error_exit;
  1568. }
  1569. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  1570. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  1571. ckptCheckpointSection->expiration_timer = 0;
  1572. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  1573. poll_timer_add (aisexec_poll_handle,
  1574. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1575. ckptCheckpointSection,
  1576. timer_function_section_expire,
  1577. &ckptCheckpointSection->expiration_timer);
  1578. }
  1579. error_exit:
  1580. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  1581. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  1582. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  1583. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  1584. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  1585. &res_lib_ckpt_sectionexpirationtimeset,
  1586. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  1587. }
  1588. return (0);
  1589. }
  1590. static int recovery_section_write(int sectionIdLen,
  1591. char* sectionId,
  1592. SaNameT *checkpointName,
  1593. void *newData,
  1594. SaUint32T dataOffSet,
  1595. SaUint32T dataSize)
  1596. {
  1597. struct saCkptCheckpoint *ckptCheckpoint;
  1598. struct saCkptCheckpointSection *ckptCheckpointSection;
  1599. int sizeRequired;
  1600. SaErrorT error = SA_AIS_OK;
  1601. char *sd;
  1602. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  1603. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1604. if (ckptCheckpoint == 0) {
  1605. error = SA_AIS_ERR_NOT_EXIST;
  1606. goto error_exit;
  1607. }
  1608. /*
  1609. * Find checkpoint section to be written
  1610. */
  1611. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1612. sectionId,
  1613. sectionIdLen);
  1614. if (ckptCheckpointSection == 0) {
  1615. error = SA_AIS_ERR_NOT_EXIST;
  1616. goto error_exit;
  1617. }
  1618. /*
  1619. * If write would extend past end of section data, return error;
  1620. */
  1621. sizeRequired = dataOffSet + dataSize;
  1622. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1623. error = SA_AIS_ERR_ACCESS;
  1624. goto error_exit;
  1625. }
  1626. /*
  1627. * Write checkpoint section to section data
  1628. */
  1629. if (dataSize > 0) {
  1630. sd = (char *)ckptCheckpointSection->sectionData;
  1631. memcpy (&sd[dataOffSet],
  1632. newData,
  1633. dataSize);
  1634. }
  1635. error_exit:
  1636. return (error);
  1637. }
  1638. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1639. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  1640. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  1641. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1642. struct saCkptCheckpoint *ckptCheckpoint;
  1643. struct saCkptCheckpointSection *ckptCheckpointSection;
  1644. int sizeRequired;
  1645. void *sectionData;
  1646. SaErrorT error = SA_AIS_OK;
  1647. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  1648. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  1649. if (ckptCheckpoint == 0) {
  1650. error = SA_AIS_ERR_NOT_EXIST;
  1651. goto error_exit;
  1652. }
  1653. /*
  1654. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1655. */
  1656. /*
  1657. * Find checkpoint section to be written
  1658. */
  1659. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1660. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  1661. req_lib_ckpt_sectionwrite->idLen);
  1662. if (ckptCheckpointSection == 0) {
  1663. printf ("CANT FIND SECTION '%s'\n",
  1664. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1665. error = SA_AIS_ERR_NOT_EXIST;
  1666. goto error_exit;
  1667. }
  1668. /*
  1669. * If write would extend past end of section data, enlarge section
  1670. */
  1671. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  1672. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1673. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  1674. if (sectionData == 0) {
  1675. error = SA_AIS_ERR_NO_MEMORY;
  1676. goto error_exit;
  1677. }
  1678. /*
  1679. * Install new section data
  1680. */
  1681. ckptCheckpointSection->sectionData = sectionData;
  1682. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  1683. }
  1684. /*
  1685. * Write checkpoint section to section data
  1686. */
  1687. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  1688. char *sd;
  1689. int *val;
  1690. val = ckptCheckpointSection->sectionData;
  1691. sd = (char *)ckptCheckpointSection->sectionData;
  1692. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  1693. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  1694. req_lib_ckpt_sectionwrite->idLen,
  1695. req_lib_ckpt_sectionwrite->dataSize);
  1696. }
  1697. /*
  1698. * Write write response to CKPT library
  1699. */
  1700. error_exit:
  1701. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  1702. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1703. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1704. res_lib_ckpt_sectionwrite.header.error = error;
  1705. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  1706. &res_lib_ckpt_sectionwrite,
  1707. sizeof (struct res_lib_ckpt_sectionwrite));
  1708. }
  1709. return (0);
  1710. }
  1711. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1712. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  1713. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  1714. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1715. struct saCkptCheckpoint *ckptCheckpoint;
  1716. struct saCkptCheckpointSection *ckptCheckpointSection;
  1717. void *sectionData;
  1718. SaErrorT error = SA_AIS_OK;
  1719. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  1720. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  1721. if (ckptCheckpoint == 0) {
  1722. error = SA_AIS_ERR_NOT_EXIST;
  1723. goto error_exit;
  1724. }
  1725. /*
  1726. * Find checkpoint section to be overwritten
  1727. */
  1728. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1729. ((char *)req_lib_ckpt_sectionoverwrite) +
  1730. sizeof (struct req_lib_ckpt_sectionoverwrite),
  1731. req_lib_ckpt_sectionoverwrite->idLen);
  1732. if (ckptCheckpointSection == 0) {
  1733. error = SA_AIS_ERR_NOT_EXIST;
  1734. goto error_exit;
  1735. }
  1736. /*
  1737. * Allocate checkpoint section data
  1738. */
  1739. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  1740. if (sectionData == 0) {
  1741. error = SA_AIS_ERR_NO_MEMORY;
  1742. goto error_exit;
  1743. }
  1744. memcpy (sectionData,
  1745. ((char *)req_lib_ckpt_sectionoverwrite) +
  1746. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  1747. req_lib_ckpt_sectionoverwrite->idLen,
  1748. req_lib_ckpt_sectionoverwrite->dataSize);
  1749. /*
  1750. * release old checkpoint section data
  1751. */
  1752. free (ckptCheckpointSection->sectionData);
  1753. /*
  1754. * Install overwritten checkpoint section data
  1755. */
  1756. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  1757. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1758. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1759. ckptCheckpointSection->sectionData = sectionData;
  1760. /*
  1761. * return result to CKPT library
  1762. */
  1763. error_exit:
  1764. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  1765. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1766. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1767. res_lib_ckpt_sectionoverwrite.header.error = error;
  1768. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  1769. &res_lib_ckpt_sectionoverwrite,
  1770. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1771. }
  1772. return (0);
  1773. }
  1774. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1775. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  1776. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  1777. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1778. struct saCkptCheckpoint *ckptCheckpoint;
  1779. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1780. int sectionSize = 0;
  1781. SaErrorT error = SA_AIS_OK;
  1782. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  1783. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  1784. if (ckptCheckpoint == 0) {
  1785. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  1786. goto error_exit;
  1787. }
  1788. /*
  1789. * Find checkpoint section to be read
  1790. */
  1791. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1792. ((char *)req_lib_ckpt_sectionread) +
  1793. sizeof (struct req_lib_ckpt_sectionread),
  1794. req_lib_ckpt_sectionread->idLen);
  1795. if (ckptCheckpointSection == 0) {
  1796. error = SA_AIS_ERR_NOT_EXIST;
  1797. goto error_exit;
  1798. }
  1799. /*
  1800. * Determine the section size
  1801. */
  1802. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1803. req_lib_ckpt_sectionread->dataOffset;
  1804. /*
  1805. * If the library has less space available then can be sent from the
  1806. * section, reduce bytes sent to library to max requested
  1807. */
  1808. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1809. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1810. }
  1811. /*
  1812. * If dataOffset is past end of data, return INVALID PARAM
  1813. */
  1814. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1815. sectionSize = 0;
  1816. error = SA_AIS_ERR_INVALID_PARAM;
  1817. goto error_exit;
  1818. }
  1819. /*
  1820. * Write read response to CKPT library
  1821. */
  1822. error_exit:
  1823. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  1824. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1825. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1826. res_lib_ckpt_sectionread.header.error = error;
  1827. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1828. &res_lib_ckpt_sectionread,
  1829. sizeof (struct res_lib_ckpt_sectionread));
  1830. /*
  1831. * Write checkpoint to CKPT library section if section has data
  1832. */
  1833. if (sectionSize) {
  1834. char *sd;
  1835. sd = (char *)ckptCheckpointSection->sectionData;
  1836. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1837. &sd[req_lib_ckpt_sectionread->dataOffset],
  1838. sectionSize);
  1839. }
  1840. }
  1841. return (0);
  1842. }
  1843. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message)
  1844. {
  1845. struct res_lib_init res_lib_init;
  1846. SaErrorT error = SA_AIS_ERR_ACCESS;
  1847. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT checkpoint.\n");
  1848. if (conn_info->authenticated) {
  1849. conn_info->service = SOCKET_SERVICE_CKPT;
  1850. list_init (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  1851. conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1852. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1853. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1854. list_add (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list,
  1855. &checkpoint_iterator_list_head);
  1856. list_init (&conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1857. error = SA_AIS_OK;
  1858. }
  1859. res_lib_init.header.size = sizeof (struct res_lib_init);
  1860. res_lib_init.header.id = MESSAGE_RES_INIT;
  1861. res_lib_init.header.error = error;
  1862. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1863. if (conn_info->authenticated) {
  1864. return (0);
  1865. }
  1866. return (-1);
  1867. }
  1868. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1869. {
  1870. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1871. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1872. struct iovec iovecs[2];
  1873. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1874. req_exec_ckpt_checkpointopen.header.size =
  1875. sizeof (struct req_exec_ckpt_checkpointopen);
  1876. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1877. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  1878. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1879. req_lib_ckpt_checkpointopen,
  1880. sizeof (struct req_lib_ckpt_checkpointopen));
  1881. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1882. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1883. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1884. return (0);
  1885. }
  1886. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1887. {
  1888. return (0);
  1889. }
  1890. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  1891. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  1892. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1893. struct saCkptCheckpoint *checkpoint;
  1894. struct iovec iovecs[2];
  1895. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  1896. if (checkpoint->expired == 1) {
  1897. return (0);
  1898. }
  1899. req_exec_ckpt_checkpointclose.header.size =
  1900. sizeof (struct req_exec_ckpt_checkpointclose);
  1901. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1902. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  1903. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1904. &checkpoint->name, sizeof (SaNameT));
  1905. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1906. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1907. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1908. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1909. }
  1910. return (0);
  1911. }
  1912. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1913. {
  1914. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1915. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1916. struct iovec iovecs[2];
  1917. req_exec_ckpt_checkpointunlink.header.size =
  1918. sizeof (struct req_exec_ckpt_checkpointunlink);
  1919. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1920. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  1921. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1922. req_lib_ckpt_checkpointunlink,
  1923. sizeof (struct req_lib_ckpt_checkpointunlink));
  1924. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1925. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1926. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1927. return (0);
  1928. }
  1929. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1930. {
  1931. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1932. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1933. struct iovec iovecs[2];
  1934. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  1935. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  1936. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  1937. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  1938. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  1939. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  1940. sizeof (SaNameT));
  1941. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  1942. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  1943. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  1944. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1945. return (0);
  1946. }
  1947. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  1948. {
  1949. return (0);
  1950. }
  1951. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  1952. {
  1953. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  1954. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  1955. struct saCkptCheckpoint *checkpoint;
  1956. int memoryUsed = 0;
  1957. int numberOfSections = 0;
  1958. struct list_head *checkpoint_section_list;
  1959. struct saCkptCheckpointSection *checkpointSection;
  1960. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  1961. /*
  1962. * Count memory used by checkpoint sections
  1963. */
  1964. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  1965. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  1966. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  1967. checkpoint_section_list = checkpoint_section_list->next) {
  1968. checkpointSection = list_entry (checkpoint_section_list,
  1969. struct saCkptCheckpointSection, list);
  1970. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  1971. numberOfSections += 1;
  1972. }
  1973. /*
  1974. * Build checkpoint status get response
  1975. */
  1976. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  1977. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  1978. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  1979. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  1980. &checkpoint->checkpointCreationAttributes,
  1981. sizeof (SaCkptCheckpointCreationAttributesT));
  1982. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  1983. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  1984. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  1985. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  1986. sizeof (struct res_lib_ckpt_checkpointstatusget));
  1987. return (0);
  1988. }
  1989. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  1990. {
  1991. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  1992. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  1993. struct iovec iovecs[2];
  1994. struct saCkptCheckpoint *checkpoint;
  1995. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  1996. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  1997. /*
  1998. * checkpoint opened is writeable mode so send message to cluster
  1999. */
  2000. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2001. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2002. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2003. req_lib_ckpt_sectioncreate,
  2004. sizeof (struct req_lib_ckpt_sectioncreate));
  2005. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2006. &req_lib_ckpt_sectioncreate->checkpointName,
  2007. sizeof (SaNameT));
  2008. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2009. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2010. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2011. /*
  2012. * Send section name and initial data in message
  2013. */
  2014. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2015. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2016. #ifdef DEBUG
  2017. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2018. iovecs[1].iov_len);
  2019. printf ("|\n");
  2020. { int i;
  2021. char *abc = iovecs[1].iov_base;
  2022. for (i = 0; i < 14;i++) {
  2023. printf ("%c ", abc[i]);
  2024. }
  2025. }
  2026. printf ("|\n");
  2027. #endif
  2028. if (iovecs[1].iov_len > 0) {
  2029. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2030. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2031. } else {
  2032. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2033. }
  2034. return (0);
  2035. }
  2036. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2037. {
  2038. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2039. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2040. struct iovec iovecs[2];
  2041. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2042. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2043. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2044. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2045. &req_lib_ckpt_sectiondelete->checkpointName,
  2046. sizeof (SaNameT));
  2047. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2048. req_lib_ckpt_sectiondelete,
  2049. sizeof (struct req_lib_ckpt_sectiondelete));
  2050. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2051. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2052. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2053. /*
  2054. * Send section name
  2055. */
  2056. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2057. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2058. if (iovecs[1].iov_len > 0) {
  2059. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2060. } else {
  2061. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2062. }
  2063. return (0);
  2064. }
  2065. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2066. {
  2067. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2068. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2069. struct iovec iovecs[2];
  2070. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2071. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2072. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2073. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2074. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2075. sizeof (SaNameT));
  2076. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2077. req_lib_ckpt_sectionexpirationtimeset,
  2078. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2079. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2080. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2081. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2082. /*
  2083. * Send section name
  2084. */
  2085. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2086. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2087. if (iovecs[1].iov_len > 0) {
  2088. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2089. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2090. } else {
  2091. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2092. }
  2093. return (0);
  2094. }
  2095. int write_inv = 0;
  2096. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2097. {
  2098. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2099. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2100. struct iovec iovecs[2];
  2101. struct saCkptCheckpoint *checkpoint;
  2102. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2103. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2104. /*
  2105. * checkpoint opened is writeable mode so send message to cluster
  2106. */
  2107. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2108. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2109. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2110. req_lib_ckpt_sectionwrite,
  2111. sizeof (struct req_lib_ckpt_sectionwrite));
  2112. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2113. &req_lib_ckpt_sectionwrite->checkpointName,
  2114. sizeof (SaNameT));
  2115. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2116. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2117. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2118. /*
  2119. * Send section name and data to write in message
  2120. */
  2121. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2122. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2123. /*
  2124. printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2125. */
  2126. if (iovecs[1].iov_len > 0) {
  2127. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2128. } else {
  2129. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2130. }
  2131. return (0);
  2132. }
  2133. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2134. {
  2135. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2136. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2137. struct iovec iovecs[2];
  2138. struct saCkptCheckpoint *checkpoint;
  2139. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2140. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2141. /*
  2142. * checkpoint opened is writeable mode so send message to cluster
  2143. */
  2144. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2145. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2146. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2147. req_lib_ckpt_sectionoverwrite,
  2148. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2149. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2150. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2151. sizeof (SaNameT));
  2152. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2153. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2154. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2155. /*
  2156. * Send section name and data to overwrite in message
  2157. */
  2158. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2159. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2160. if (iovecs[1].iov_len > 0) {
  2161. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2162. } else {
  2163. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2164. }
  2165. return (0);
  2166. }
  2167. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2168. {
  2169. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2170. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2171. struct iovec iovecs[2];
  2172. struct saCkptCheckpoint *checkpoint;
  2173. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2174. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2175. /*
  2176. * checkpoint opened is writeable mode so send message to cluster
  2177. */
  2178. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2179. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2180. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2181. req_lib_ckpt_sectionread,
  2182. sizeof (struct req_lib_ckpt_sectionread));
  2183. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2184. &req_lib_ckpt_sectionread->checkpointName,
  2185. sizeof (SaNameT));
  2186. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2187. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2188. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2189. /*
  2190. * Send section name and data to overwrite in message
  2191. */
  2192. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2193. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2194. if (iovecs[1].iov_len > 0) {
  2195. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2196. } else {
  2197. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2198. }
  2199. return (0);
  2200. }
  2201. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2202. {
  2203. return (0);
  2204. }
  2205. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2206. {
  2207. return (0);
  2208. }
  2209. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2210. {
  2211. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2212. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2213. struct saCkptCheckpoint *ckptCheckpoint;
  2214. struct saCkptCheckpointSection *ckptCheckpointSection;
  2215. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2216. struct saCkptSectionIterator *ckptSectionIterator;
  2217. struct list_head *checkpoint_section_list;
  2218. int addEntry = 0;
  2219. int iteratorEntries = 0;
  2220. SaErrorT error = SA_AIS_OK;
  2221. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2222. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2223. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2224. if (ckptCheckpoint == 0) {
  2225. error = SA_AIS_ERR_NOT_EXIST;
  2226. goto error_exit;
  2227. }
  2228. /*
  2229. * Iterate list of checkpoint sections
  2230. */
  2231. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2232. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2233. checkpoint_section_list = checkpoint_section_list->next) {
  2234. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2235. struct saCkptCheckpointSection, list);
  2236. addEntry = 1;
  2237. /*
  2238. * Item should be added to iterator list
  2239. */
  2240. if (addEntry) {
  2241. iteratorEntries += 1;
  2242. ckptSectionIteratorEntries =
  2243. realloc (ckptSectionIterator->sectionIteratorEntries,
  2244. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2245. if (ckptSectionIteratorEntries == 0) {
  2246. if (ckptSectionIterator->sectionIteratorEntries) {
  2247. free (ckptSectionIterator->sectionIteratorEntries);
  2248. }
  2249. error = SA_AIS_ERR_NO_MEMORY;
  2250. goto error_exit;
  2251. }
  2252. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2253. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2254. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2255. }
  2256. }
  2257. ckptSectionIterator->iteratorCount = iteratorEntries;
  2258. error_exit:
  2259. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2260. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2261. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2262. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2263. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2264. return (0);
  2265. }
  2266. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2267. {
  2268. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2269. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2270. struct saCkptSectionIterator *ckptSectionIterator;
  2271. SaErrorT error = SA_AIS_OK;
  2272. int sectionIdSize = 0;
  2273. int iteratorPos = 0;
  2274. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2275. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2276. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2277. /*
  2278. * Find active iterator entry
  2279. */
  2280. for (;;) {
  2281. /*
  2282. * No more sections in iterator
  2283. */
  2284. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2285. error = SA_AIS_ERR_NOT_EXIST;
  2286. goto error_exit;
  2287. }
  2288. /*
  2289. * active iterator entry
  2290. */
  2291. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2292. break;
  2293. }
  2294. ckptSectionIterator->iteratorPos += 1;
  2295. }
  2296. /*
  2297. * Prepare response to API
  2298. */
  2299. iteratorPos = ckptSectionIterator->iteratorPos;
  2300. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2301. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2302. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2303. sizeof (SaCkptSectionDescriptorT));
  2304. /*
  2305. * Get to next iterator entry
  2306. */
  2307. ckptSectionIterator->iteratorPos += 1;
  2308. error_exit:
  2309. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2310. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2311. res_lib_ckpt_sectioniteratornext.header.error = error;
  2312. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2313. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2314. libais_send_response (conn_info,
  2315. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2316. sectionIdSize);
  2317. return (0);
  2318. }