ckpt.c 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513
  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 <arpa/inet.h>
  47. #include "../include/ais_types.h"
  48. #include "../include/saCkpt.h"
  49. #include "../include/ipc_ckpt.h"
  50. #include "../include/list.h"
  51. #include "../include/queue.h"
  52. #include "aispoll.h"
  53. #include "mempool.h"
  54. #include "util.h"
  55. #include "parse.h"
  56. #include "main.h"
  57. #include "totempg.h"
  58. #define LOG_SERVICE LOG_SERVICE_CKPT
  59. #define CKPT_MAX_SECTION_DATA_SEND (1024*400)
  60. #include "print.h"
  61. struct ckpt_identifier {
  62. SaNameT ckpt_name;
  63. SaCkptSectionIdT ckpt_section_id;
  64. };
  65. static int process_localhost_transition = 0;
  66. DECLARE_LIST_INIT(checkpoint_list_head);
  67. DECLARE_LIST_INIT(checkpoint_iterator_list_head);
  68. DECLARE_LIST_INIT(checkpoint_recovery_list_head);
  69. struct checkpoint_cleanup {
  70. struct list_head list;
  71. struct saCkptCheckpoint checkpoint;
  72. };
  73. typedef enum {
  74. SYNCHRONY_STATE_STARTED,
  75. SYNCHRONY_STATE_ENDED
  76. }synchrony_state;
  77. /* TODO static totempg_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle; */
  78. static int ckpt_exec_init_fn (struct openais_config *);
  79. static int ckpt_exit_fn (struct conn_info *conn_info);
  80. static int ckpt_init_two_fn (struct conn_info *conn_info);
  81. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required);
  82. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required);
  83. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required);
  84. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required);
  85. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required);
  86. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required);
  87. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required);
  88. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required);
  89. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required);
  90. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required);
  91. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  92. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required);
  93. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required);
  94. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message);
  95. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message);
  96. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message);
  97. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message);
  98. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message);
  99. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message);
  100. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message);
  101. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message);
  102. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message);
  103. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message);
  104. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message);
  105. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message);
  106. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message);
  107. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message);
  108. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message);
  109. static int message_handler_req_lib_ckpt_sectioniterationinitialize (struct conn_info *conn_info, void *message);
  110. static int message_handler_req_lib_ckpt_sectioniterationfinalize (struct conn_info *conn_info, void *message);
  111. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message);
  112. static void ckpt_recovery_activate (void);
  113. static void ckpt_recovery_initialize (void);
  114. static int ckpt_recovery_process (void);
  115. static void ckpt_recovery_finalize();
  116. static void ckpt_recovery_abort(void);
  117. static void ckpt_recovery_process_members_exit(struct in_addr *left_list,
  118. int left_list_entries);
  119. static void ckpt_replace_localhost_ip (struct in_addr *joined_list);
  120. void checkpoint_release (struct saCkptCheckpoint *checkpoint);
  121. void timer_function_retention (void *data);
  122. unsigned int abstime_to_msec (SaTimeT time);
  123. void timer_function_section_expire (void *data);
  124. static int recovery_checkpoint_open(SaNameT *checkpointName,
  125. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  126. struct ckpt_refcnt *ref_cnt);
  127. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  128. SaNameT *checkpointName,
  129. char* SectionId);
  130. static int recovery_section_write(int sectionIdLen, char* sectionId , SaNameT *checkpointName,
  131. void *newData, SaUint32T dataOffSet, SaUint32T dataSize);
  132. static synchrony_state recovery_state = SYNCHRONY_STATE_ENDED;
  133. static struct list_head *recovery_ckpt_next = 0;
  134. static struct list_head *recovery_ckpt_section_next = 0;
  135. static int recovery_section_data_offset = 0;
  136. static int recovery_section_send_flag = 0;
  137. static int recovery_abort = 0;
  138. static struct memb_ring_id saved_ring_id;
  139. static int ckpt_confchg_fn(
  140. enum totem_configuration_type configuration_type,
  141. struct in_addr *member_list, int member_list_entries,
  142. struct in_addr *left_list, int left_list_entries,
  143. struct in_addr *joined_list, int joined_list_entries,
  144. struct memb_ring_id *ring_id);
  145. /*
  146. * Executive Handler Definition
  147. */
  148. struct libais_handler ckpt_libais_handlers[] =
  149. {
  150. { /* 0 */
  151. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopen,
  152. .response_size = sizeof (struct res_lib_ckpt_checkpointopen),
  153. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN,
  154. .flow_control = FLOW_CONTROL_REQUIRED
  155. },
  156. { /* 1 */
  157. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointopenasync,
  158. .response_size = sizeof (struct res_lib_ckpt_checkpointopenasync),
  159. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC,
  160. .flow_control = FLOW_CONTROL_REQUIRED
  161. },
  162. { /* 2 */
  163. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointclose,
  164. .response_size = sizeof (struct res_lib_ckpt_checkpointclose),
  165. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE,
  166. .flow_control = FLOW_CONTROL_REQUIRED
  167. },
  168. { /* 3 */
  169. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  170. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  171. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  172. .flow_control = FLOW_CONTROL_REQUIRED
  173. },
  174. { /* 4 */
  175. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  176. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  177. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  178. .flow_control = FLOW_CONTROL_REQUIRED
  179. },
  180. { /* 5 */
  181. .libais_handler_fn = message_handler_req_lib_ckpt_activereplicaset,
  182. .response_size = sizeof (struct res_lib_ckpt_activereplicaset),
  183. .response_id = MESSAGE_RES_CKPT_ACTIVEREPLICASET,
  184. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  185. },
  186. { /* 6 */
  187. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  188. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  189. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  190. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  191. },
  192. { /* 7 */
  193. .libais_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  194. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  195. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  196. .flow_control = FLOW_CONTROL_REQUIRED
  197. },
  198. { /* 8 */
  199. .libais_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  200. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  201. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  202. .flow_control = FLOW_CONTROL_REQUIRED
  203. },
  204. { /* 9 */
  205. .libais_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  206. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  207. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  208. .flow_control = FLOW_CONTROL_REQUIRED
  209. },
  210. { /* 10 */
  211. .libais_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  212. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  213. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  214. .flow_control = FLOW_CONTROL_REQUIRED
  215. },
  216. { /* 11 */
  217. .libais_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  218. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  219. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  220. .flow_control = FLOW_CONTROL_REQUIRED
  221. },
  222. { /* 12 */
  223. .libais_handler_fn = message_handler_req_lib_ckpt_sectionread,
  224. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  225. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  226. .flow_control = FLOW_CONTROL_REQUIRED
  227. },
  228. { /* 13 */
  229. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  230. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  231. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  232. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  233. },
  234. { /* 14 */
  235. .libais_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  236. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), /* TODO RESPONSE */
  237. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  238. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  239. },
  240. { /* 15 */
  241. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniterationinitialize,
  242. .response_size = sizeof (struct res_lib_ckpt_sectioniterationinitialize),
  243. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE,
  244. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  245. },
  246. { /* 16 */
  247. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniterationfinalize,
  248. .response_size = sizeof (struct res_lib_ckpt_sectioniterationfinalize),
  249. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE,
  250. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  251. },
  252. { /* 17 */
  253. .libais_handler_fn = message_handler_req_lib_ckpt_sectioniteratornext,
  254. .response_size = sizeof (struct res_lib_ckpt_sectioniteratornext),
  255. .response_id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT,
  256. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  257. }
  258. };
  259. static int (*ckpt_aisexec_handler_fns[]) (void *msg, struct in_addr source_addr, int endian_conversion_required) = {
  260. message_handler_req_exec_ckpt_checkpointopen,
  261. message_handler_req_exec_ckpt_checkpointclose,
  262. message_handler_req_exec_ckpt_checkpointunlink,
  263. message_handler_req_exec_ckpt_checkpointretentiondurationset,
  264. message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  265. message_handler_req_exec_ckpt_sectioncreate,
  266. message_handler_req_exec_ckpt_sectiondelete,
  267. message_handler_req_exec_ckpt_sectionexpirationtimeset,
  268. message_handler_req_exec_ckpt_sectionwrite,
  269. message_handler_req_exec_ckpt_sectionoverwrite,
  270. message_handler_req_exec_ckpt_sectionread,
  271. message_handler_req_exec_ckpt_synchronize_state,
  272. message_handler_req_exec_ckpt_synchronize_section
  273. };
  274. struct service_handler ckpt_service_handler = {
  275. .libais_handlers = ckpt_libais_handlers,
  276. .libais_handlers_count = sizeof (ckpt_libais_handlers) / sizeof (struct libais_handler),
  277. .aisexec_handler_fns = ckpt_aisexec_handler_fns,
  278. .aisexec_handler_fns_count = sizeof (ckpt_aisexec_handler_fns) / sizeof (int (*)),
  279. .confchg_fn = ckpt_confchg_fn,
  280. .libais_init_two_fn = ckpt_init_two_fn,
  281. .libais_exit_fn = ckpt_exit_fn,
  282. .exec_init_fn = ckpt_exec_init_fn,
  283. .exec_dump_fn = 0,
  284. .sync_init = ckpt_recovery_initialize,
  285. .sync_process = ckpt_recovery_process,
  286. .sync_activate = ckpt_recovery_activate,
  287. .sync_abort = ckpt_recovery_abort,
  288. };
  289. /*
  290. * All data types used for executive messages
  291. */
  292. struct req_exec_ckpt_checkpointclose {
  293. struct req_header header;
  294. struct message_source source;
  295. SaNameT checkpointName;
  296. };
  297. struct req_exec_ckpt_checkpointretentiondurationset {
  298. struct req_header header;
  299. struct message_source source;
  300. SaNameT checkpointName;
  301. SaTimeT retentionDuration;
  302. };
  303. struct req_exec_ckpt_checkpointretentiondurationexpire {
  304. struct req_header header;
  305. SaNameT checkpointName;
  306. };
  307. struct req_exec_ckpt_checkpointopen {
  308. struct req_header header;
  309. struct message_source source;
  310. struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen;
  311. SaCkptCheckpointHandleT checkpointHandle;
  312. SaInvocationT invocation;
  313. int async_call;
  314. SaAisErrorT fail_with_error;
  315. };
  316. struct req_exec_ckpt_checkpointunlink {
  317. struct req_header header;
  318. struct message_source source;
  319. struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink;
  320. };
  321. struct req_exec_ckpt_sectioncreate {
  322. struct req_header header;
  323. struct message_source source;
  324. SaNameT checkpointName;
  325. struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate; /* this must be last */
  326. };
  327. struct req_exec_ckpt_sectiondelete {
  328. struct req_header header;
  329. struct message_source source;
  330. SaNameT checkpointName;
  331. struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete; /* this must be last */
  332. };
  333. struct req_exec_ckpt_sectionexpirationtimeset {
  334. struct req_header header;
  335. struct message_source source;
  336. SaNameT checkpointName;
  337. struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset;
  338. };
  339. struct req_exec_ckpt_sectionwrite {
  340. struct req_header header;
  341. struct message_source source;
  342. SaNameT checkpointName;
  343. struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite;
  344. };
  345. struct req_exec_ckpt_sectionoverwrite {
  346. struct req_header header;
  347. struct message_source source;
  348. SaNameT checkpointName;
  349. struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite;
  350. };
  351. struct req_exec_ckpt_sectionread {
  352. struct req_header header;
  353. struct message_source source;
  354. SaNameT checkpointName;
  355. struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread;
  356. };
  357. struct req_exec_ckpt_synchronize_state {
  358. struct req_header header;
  359. struct memb_ring_id previous_ring_id;
  360. SaNameT checkpointName;
  361. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes;
  362. SaCkptSectionDescriptorT sectionDescriptor;
  363. struct in_addr source_addr;
  364. struct ckpt_refcnt ckpt_refcount[PROCESSOR_COUNT_MAX];
  365. };
  366. struct req_exec_ckpt_synchronize_section {
  367. struct req_header header;
  368. struct memb_ring_id previous_ring_id;
  369. SaNameT checkpointName;
  370. SaCkptSectionIdT sectionId;
  371. SaUint32T dataOffSet;
  372. SaUint32T dataSize;
  373. };
  374. /*
  375. * Implementation
  376. */
  377. static int processor_index_set(struct in_addr *proc_addr,
  378. struct ckpt_refcnt *ckpt_refcount)
  379. {
  380. int i;
  381. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  382. if (ckpt_refcount[i].addr.s_addr == 0) {
  383. /*
  384. * If the source addresses do not match and this element
  385. * has no stored value then store the new value and
  386. * return the Index.
  387. */
  388. memcpy(&ckpt_refcount[i].addr, proc_addr, sizeof(struct in_addr));
  389. return i;
  390. }
  391. /*
  392. * If the source addresses match then this processor index
  393. * has already been set
  394. */
  395. else if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  396. return -1;
  397. }
  398. }
  399. /*
  400. * Could not Find an empty slot
  401. * to store the new Processor.
  402. */
  403. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  404. if (ckpt_refcount[i].addr.s_addr == 0) {
  405. log_printf (LOG_LEVEL_ERROR,"Processor Set: Index %d has proc 0 and count 0\n", i);
  406. }
  407. else {
  408. log_printf (LOG_LEVEL_ERROR,"Processor Set: Index %d has proc %s and count %d\n",
  409. i,
  410. inet_ntoa(ckpt_refcount[i].addr),
  411. ckpt_refcount[i].count);
  412. }
  413. }
  414. return -1;
  415. }
  416. static int processor_add (struct in_addr *proc_addr, int count, struct ckpt_refcnt *ckpt_refcount)
  417. {
  418. int i;
  419. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  420. if (ckpt_refcount[i].addr.s_addr == 0) {
  421. log_printf (LOG_LEVEL_DEBUG,"processor_add found empty slot to insert new item\n");
  422. memcpy(&ckpt_refcount[i].addr, proc_addr, sizeof(struct in_addr));
  423. ckpt_refcount[i].count = count;
  424. return i;
  425. }
  426. /*Dont know how we missed this in the processor find but update this*/
  427. else if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  428. ckpt_refcount[i].count += count;
  429. log_printf (LOG_LEVEL_DEBUG,"processor_add for existent proc. ip %s, New count = %d\n",
  430. inet_ntoa(ckpt_refcount[i].addr),
  431. ckpt_refcount[i].count);
  432. return i;
  433. }
  434. }
  435. /*
  436. * Could not Find an empty slot
  437. * to store the new Processor.
  438. */
  439. log_printf (LOG_LEVEL_ERROR,"Processor Add Failed. Dumping Refcount Array\n");
  440. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  441. if (ckpt_refcount[i].addr.s_addr == 0) {
  442. log_printf (LOG_LEVEL_ERROR,"Processor Add: Index %d has proc 0 and count 0\n", i);
  443. }
  444. else {
  445. log_printf (LOG_LEVEL_ERROR,"Processor Add: Index %d has proc %s and count %d\n",
  446. i,
  447. inet_ntoa(ckpt_refcount[i].addr),
  448. ckpt_refcount[i].count);
  449. }
  450. }
  451. return -1;
  452. }
  453. static int processor_index_find(struct in_addr *proc_addr,
  454. struct ckpt_refcnt *ckpt_refcount)
  455. {
  456. int i;
  457. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  458. /*
  459. * If the source addresses match then return the index
  460. */
  461. if (ckpt_refcount[i].addr.s_addr == proc_addr->s_addr) {
  462. return i;
  463. }
  464. }
  465. /*
  466. * Could not Find the Processor
  467. */
  468. return -1;
  469. }
  470. static int ckpt_refcount_total(struct ckpt_refcnt *ckpt_refcount)
  471. {
  472. int i;
  473. int total = 0;
  474. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  475. total += ckpt_refcount[i].count;
  476. }
  477. return total;
  478. }
  479. static void initialize_ckpt_refcount_array (struct ckpt_refcnt *ckpt_refcount)
  480. {
  481. memset((char*)ckpt_refcount, 0, PROCESSOR_COUNT_MAX * sizeof(struct ckpt_refcnt));
  482. }
  483. static void merge_ckpt_refcounts(struct ckpt_refcnt *local, struct ckpt_refcnt *network)
  484. {
  485. int index,i;
  486. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  487. if (local[i].addr.s_addr == 0) {
  488. continue;
  489. }
  490. index = processor_index_find (&local[i].addr, network);
  491. if (index == -1) { /*Could Not Find the Local Entry in the remote.Add to it*/
  492. log_printf (LOG_LEVEL_DEBUG,"calling processor_add for ip %s, count %d\n",
  493. inet_ntoa(local[i].addr),
  494. local[i].count);
  495. index = processor_add (&local[i].addr, local[i].count, network);
  496. if (index == -1) {
  497. log_printf(LOG_LEVEL_ERROR,
  498. "merge_ckpt_refcounts : could not add a new processor as the MAX limit of procs is reached.Exiting\n");
  499. assert(0);
  500. }
  501. }
  502. else {
  503. if (local[i].count == network[index].count) {
  504. /*Nothing to do here as the network is already up 2 date*/
  505. log_printf (LOG_LEVEL_DEBUG,"merge_ckpt_refcounts counts match, continue\n");
  506. continue;
  507. }
  508. else {
  509. /*Found a match for this proc in the Network choose the larger of the 2.*/
  510. network[index].count += local[i].count;
  511. log_printf (LOG_LEVEL_DEBUG,"setting count for %s = %d\n",
  512. inet_ntoa(network[index].addr),
  513. network[index].count);
  514. }
  515. }
  516. }
  517. }
  518. static void ckpt_recovery_initialize (void)
  519. {
  520. struct list_head *checkpoint_list;
  521. struct list_head *checkpoint_section_list;
  522. struct saCkptCheckpoint *checkpoint;
  523. struct saCkptCheckpointSection *section;
  524. struct saCkptCheckpoint *savedCheckpoint;
  525. struct saCkptCheckpointSection *savedSection;
  526. if (recovery_abort) { /*Abort was called.*/
  527. return;
  528. }
  529. /*
  530. * Save off the existing Checkpoints to be used by ckpt_recovery_process
  531. */
  532. for (checkpoint_list = checkpoint_list_head.next;
  533. checkpoint_list != &checkpoint_list_head;
  534. checkpoint_list = checkpoint_list->next) {
  535. checkpoint = list_entry (checkpoint_list,
  536. struct saCkptCheckpoint, list);
  537. if (checkpoint->referenceCount <= 0) {
  538. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_initialize checkpoint %s has referenceCount 0 ignoring.\n",
  539. (char*)&checkpoint->name.value);
  540. continue;
  541. }
  542. savedCheckpoint =
  543. (struct saCkptCheckpoint *) malloc (sizeof(struct saCkptCheckpoint));
  544. assert(savedCheckpoint);
  545. memcpy(savedCheckpoint, checkpoint, sizeof(struct saCkptCheckpoint));
  546. list_init(&savedCheckpoint->list);
  547. list_add(&savedCheckpoint->list,&checkpoint_recovery_list_head);
  548. list_init(&savedCheckpoint->checkpointSectionsListHead);
  549. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  550. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  551. checkpoint_section_list = checkpoint_section_list->next) {
  552. section = list_entry (checkpoint_section_list,
  553. struct saCkptCheckpointSection, list);
  554. savedSection =
  555. (struct saCkptCheckpointSection *) malloc (sizeof(struct saCkptCheckpointSection));
  556. assert(savedSection);
  557. poll_timer_delete_data (aisexec_poll_handle, section->expiration_timer);
  558. memcpy(savedSection, section, sizeof(struct saCkptCheckpointSection));
  559. list_init(&savedSection->list);
  560. list_add(&savedSection->list,&savedCheckpoint->checkpointSectionsListHead);
  561. }
  562. }
  563. if (list_empty (&checkpoint_recovery_list_head)) {
  564. return;
  565. }
  566. recovery_ckpt_next = checkpoint_recovery_list_head.next;
  567. savedCheckpoint = list_entry (recovery_ckpt_next,
  568. struct saCkptCheckpoint, list);
  569. recovery_ckpt_section_next = savedCheckpoint->checkpointSectionsListHead.next;
  570. }
  571. static int ckpt_recovery_process (void)
  572. {
  573. int i;
  574. struct req_exec_ckpt_synchronize_state request_exec_sync_state;
  575. struct req_exec_ckpt_synchronize_section request_exec_sync_section;
  576. struct iovec iovecs[3];
  577. struct saCkptCheckpoint *checkpoint;
  578. struct saCkptCheckpointSection *ckptCheckpointSection;
  579. SaSizeT origSectionSize;
  580. SaSizeT newSectionSize;
  581. if (recovery_abort) { /*Abort was called.*/
  582. goto recovery_exit_clean;
  583. }
  584. /*So Initialize did not have any checkpoints to Synchronize*/
  585. if ((recovery_ckpt_next == 0) && (recovery_ckpt_section_next == 0)) {
  586. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_process Nothing to Process ...\n");
  587. goto recovery_exit_clean;
  588. }
  589. /*
  590. * ALGORITHM :
  591. * 1.) extract the checkpoint if there.
  592. * 2.) If there is a checkpoint then there has to be a section
  593. * 3.) If the recovery_section_send_flag was not set in the previous
  594. * invocation that means we have to send out a sync_msg before
  595. * we send out the sections
  596. * 4.) Set the recovery_section_send_flag and send the sections.
  597. */
  598. while (1) { /*Go for as long as the oubound queue is not full*/
  599. if(recovery_ckpt_next != &checkpoint_recovery_list_head) {
  600. checkpoint = list_entry (recovery_ckpt_next,
  601. struct saCkptCheckpoint, list);
  602. if (recovery_ckpt_section_next == 0) {
  603. recovery_ckpt_section_next = checkpoint->checkpointSectionsListHead.next;
  604. }
  605. if (recovery_ckpt_section_next != &checkpoint->checkpointSectionsListHead) {
  606. ckptCheckpointSection = list_entry (recovery_ckpt_section_next,
  607. struct saCkptCheckpointSection, list);
  608. /*
  609. * None of the section data msgs have been sent
  610. * so lets start with sending the sync_msg
  611. */
  612. if (recovery_section_send_flag == 0) {
  613. if ((int)ckptCheckpointSection->sectionDescriptor.sectionId.id) {
  614. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message for ckpt = %s, section = %s.\n",
  615. (char*)&checkpoint->name.value,
  616. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id));
  617. } else {
  618. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message for ckpt = %s, section = default section.\n",
  619. (char*)&checkpoint->name.value);
  620. }
  621. request_exec_sync_state.header.size = sizeof (struct req_exec_ckpt_synchronize_state);
  622. request_exec_sync_state.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESTATE;
  623. memcpy(&request_exec_sync_state.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  624. memcpy(&request_exec_sync_state.checkpointName, &checkpoint->name, sizeof(SaNameT));
  625. memcpy(&request_exec_sync_state.checkpointCreationAttributes,
  626. &checkpoint->checkpointCreationAttributes,
  627. sizeof(SaCkptCheckpointCreationAttributesT));
  628. memcpy(&request_exec_sync_state.sectionDescriptor,
  629. &ckptCheckpointSection->sectionDescriptor,
  630. sizeof(SaCkptSectionDescriptorT));
  631. memcpy(&request_exec_sync_state.source_addr, &this_ip->sin_addr, sizeof(struct in_addr));
  632. memcpy(request_exec_sync_state.ckpt_refcount,
  633. checkpoint->ckpt_refcount,
  634. sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  635. request_exec_sync_state.sectionDescriptor.sectionId.id = 0;
  636. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync State Message Values\n");
  637. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  638. if (request_exec_sync_state.ckpt_refcount[i].addr.s_addr == 0) {
  639. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  640. request_exec_sync_state.ckpt_refcount[i].count);
  641. }
  642. else {
  643. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  644. i,
  645. inet_ntoa(request_exec_sync_state.ckpt_refcount[i].addr),
  646. request_exec_sync_state.ckpt_refcount[i].count);
  647. }
  648. }
  649. iovecs[0].iov_base = (char *)&request_exec_sync_state;
  650. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_state);
  651. /*
  652. * Populate the Section ID
  653. */
  654. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  655. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  656. request_exec_sync_state.header.size += iovecs[1].iov_len;
  657. /*
  658. * Check to see if we can queue the new message and if you can
  659. * then mcast the message else break and create callback.
  660. */
  661. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len)){
  662. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  663. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync State Message.\n");
  664. }
  665. else {
  666. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync State Message Outbound Queue full need to Wait for Callback.\n");
  667. return (1);
  668. }
  669. recovery_section_send_flag = 1;
  670. }
  671. origSectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize;
  672. newSectionSize = 0;
  673. /*
  674. * Now Create SyncSection messsages in chunks of CKPT_MAX_SECTION_DATA_SEND or less
  675. */
  676. while (recovery_section_data_offset < origSectionSize) {
  677. /*
  678. * Send a Max of CKPT_MAX_SECTION_DATA_SEND of section data
  679. */
  680. if ((origSectionSize - recovery_section_data_offset) > CKPT_MAX_SECTION_DATA_SEND) {
  681. newSectionSize = CKPT_MAX_SECTION_DATA_SEND;
  682. }
  683. else {
  684. newSectionSize = (origSectionSize - recovery_section_data_offset);
  685. }
  686. /*
  687. * Create and save a new Sync Section message.
  688. */
  689. request_exec_sync_section.header.size = sizeof (struct req_exec_ckpt_synchronize_section);
  690. request_exec_sync_section.header.id = MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESECTION;
  691. memcpy (&request_exec_sync_section.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  692. memcpy (&request_exec_sync_section.checkpointName, &checkpoint->name, sizeof(SaNameT));
  693. memcpy (&request_exec_sync_section.sectionId,
  694. &ckptCheckpointSection->sectionDescriptor.sectionId,
  695. sizeof(SaCkptSectionIdT));
  696. request_exec_sync_section.sectionId.id = 0;
  697. memcpy (&request_exec_sync_section.dataOffSet, &recovery_section_data_offset, sizeof(SaUint32T));
  698. memcpy (&request_exec_sync_section.dataSize, &newSectionSize, sizeof(SaUint32T));
  699. if (ckptCheckpointSection->sectionDescriptor.sectionId.id) {
  700. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync Section Message for ckpt = %s, section = %s, Data size = %d.\n",
  701. (char*)&checkpoint->name.value,
  702. ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id),
  703. newSectionSize);
  704. } else {
  705. log_printf (LOG_LEVEL_DEBUG, "CKPT: New Sync Section Message for ckpt = %s, default section, Data size = %d.\n",
  706. (char*)&checkpoint->name.value,newSectionSize);
  707. }
  708. /*
  709. * Populate the Sync Section Request
  710. */
  711. iovecs[0].iov_base = (char *)&request_exec_sync_section;
  712. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_section);
  713. /*
  714. * Populate the Section ID
  715. */
  716. iovecs[1].iov_base = ((char*)ckptCheckpointSection->sectionDescriptor.sectionId.id);
  717. iovecs[1].iov_len = ckptCheckpointSection->sectionDescriptor.sectionId.idLen;
  718. request_exec_sync_section.header.size += iovecs[1].iov_len;
  719. /*
  720. * Populate the Section Data.
  721. */
  722. iovecs[2].iov_base = ((char*)ckptCheckpointSection->sectionData + recovery_section_data_offset);
  723. iovecs[2].iov_len = newSectionSize;
  724. request_exec_sync_section.header.size += iovecs[2].iov_len;
  725. /*
  726. * Check to see if we can queue the new message and if you can
  727. * then mcast the message else break and create callback.
  728. */
  729. if (totempg_send_ok(iovecs[0].iov_len + iovecs[1].iov_len + iovecs[2].iov_len)){
  730. assert (totempg_mcast (iovecs, 3, TOTEMPG_AGREED) == 0);
  731. log_printf (LOG_LEVEL_DEBUG, "CKPT: Multicasted Sync Section Message.\n");
  732. }
  733. else {
  734. log_printf (LOG_LEVEL_DEBUG, "CKPT: Sync Section Message Outbound Queue full need to Wait for Callback.\n");
  735. return (1);
  736. }
  737. recovery_section_data_offset += newSectionSize;
  738. }
  739. recovery_section_send_flag = 0;
  740. recovery_section_data_offset = 0;
  741. recovery_ckpt_section_next = recovery_ckpt_section_next->next;
  742. continue;
  743. }
  744. else {
  745. /*
  746. * We have reached the end of a section List.
  747. * Move to the next element in the ckpt list.
  748. * Init the section ptr to 0 so it is re evaled
  749. */
  750. recovery_ckpt_next = recovery_ckpt_next->next;
  751. recovery_ckpt_section_next = 0;
  752. continue;
  753. }
  754. }
  755. /*Should only be here at the end of the traversal of the ckpt list*/
  756. ckpt_recovery_finalize();
  757. recovery_exit_clean:
  758. /*Re - Initialize the static's*/
  759. recovery_ckpt_next = 0;
  760. recovery_ckpt_section_next = 0;
  761. recovery_section_data_offset = 0;
  762. recovery_section_send_flag = 0;
  763. recovery_abort = 0;
  764. return (0);
  765. }
  766. }
  767. static void ckpt_recovery_finalize ()
  768. {
  769. struct list_head *checkpoint_list;
  770. struct list_head *checkpoint_section_list;
  771. struct saCkptCheckpoint *checkpoint;
  772. struct saCkptCheckpointSection *section;
  773. struct ckpt_identifier *ckpt_id;
  774. /*
  775. * Remove All elements from old checkpoint
  776. * list
  777. */
  778. checkpoint_list = checkpoint_list_head.next;
  779. while (!list_empty(&checkpoint_list_head)) {
  780. checkpoint = list_entry (checkpoint_list,
  781. struct saCkptCheckpoint, list);
  782. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  783. while (!list_empty(&checkpoint->checkpointSectionsListHead)) {
  784. section = list_entry (checkpoint_section_list,
  785. struct saCkptCheckpointSection, list);
  786. list_del (&section->list);
  787. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_finalize removed 0x%x.\n", section);
  788. free (section);
  789. checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  790. }
  791. list_del(&checkpoint->list);
  792. free(checkpoint);
  793. checkpoint_list = checkpoint_list_head.next;
  794. }
  795. /*
  796. * Initialize the old list again.
  797. */
  798. list_init(&checkpoint_list_head);
  799. /*
  800. * Copy the contents of the new list_head into the old list head
  801. */
  802. checkpoint_recovery_list_head.prev->next = &checkpoint_list_head;
  803. checkpoint_recovery_list_head.next->prev = &checkpoint_list_head;
  804. memcpy(&checkpoint_list_head, &checkpoint_recovery_list_head, sizeof(struct list_head));
  805. /*Timers might have been started before recovery happened .. restart them ..*/
  806. for (checkpoint_list = checkpoint_list_head.next;
  807. checkpoint_list != &checkpoint_list_head;
  808. checkpoint_list = checkpoint_list->next) {
  809. checkpoint = list_entry (checkpoint_list,
  810. struct saCkptCheckpoint, list);
  811. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  812. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  813. checkpoint_section_list = checkpoint_section_list->next) {
  814. section = list_entry (checkpoint_section_list,
  815. struct saCkptCheckpointSection, list);
  816. if (section->sectionDescriptor.expirationTime != SA_TIME_END) {
  817. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  818. assert(ckpt_id);
  819. memcpy(&ckpt_id->ckpt_name,&checkpoint->name,sizeof(SaNameT));
  820. memcpy(&ckpt_id->ckpt_section_id, &section->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  821. poll_timer_add (aisexec_poll_handle,
  822. abstime_to_msec (section->sectionDescriptor.expirationTime),
  823. ckpt_id,
  824. timer_function_section_expire,
  825. &section->expiration_timer);
  826. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_initialize expiration timer = 0x%x\n",
  827. section->expiration_timer);
  828. }
  829. }
  830. }
  831. /*
  832. * Initialize the new list head for reuse.
  833. */
  834. list_init(&checkpoint_recovery_list_head);
  835. log_printf (LOG_LEVEL_DEBUG, "CKPT: ckpt_recovery_finalize Done.\n");
  836. }
  837. static void ckpt_recovery_activate (void)
  838. {
  839. recovery_state = SYNCHRONY_STATE_ENDED;
  840. return;
  841. }
  842. static void ckpt_recovery_abort (void)
  843. {
  844. recovery_abort = 1;
  845. return;
  846. }
  847. static void ckpt_replace_localhost_ip (struct in_addr *joined_list) {
  848. struct list_head *checkpoint_list;
  849. struct saCkptCheckpoint *checkpoint;
  850. struct in_addr local_ip;
  851. int index;
  852. assert(joined_list);
  853. local_ip.s_addr = inet_addr("127.0.0.1");
  854. for (checkpoint_list = checkpoint_list_head.next;
  855. checkpoint_list != &checkpoint_list_head;
  856. checkpoint_list = checkpoint_list->next) {
  857. checkpoint = list_entry (checkpoint_list,
  858. struct saCkptCheckpoint, list);
  859. index = processor_index_find(&local_ip, checkpoint->ckpt_refcount);
  860. if (index == -1) {
  861. continue;
  862. }
  863. memcpy(&checkpoint->ckpt_refcount[index].addr, joined_list, sizeof(struct in_addr));
  864. log_printf (LOG_LEVEL_DEBUG, "Transitioning From Local Host replacing 127.0.0.1 with %s ...\n",
  865. inet_ntoa(*joined_list));
  866. }
  867. process_localhost_transition = 0;
  868. }
  869. static void ckpt_recovery_process_members_exit(struct in_addr *left_list,
  870. int left_list_entries)
  871. {
  872. struct list_head *checkpoint_list;
  873. struct saCkptCheckpoint *checkpoint;
  874. struct in_addr *member;
  875. struct in_addr local_ip;
  876. int index;
  877. int i;
  878. local_ip.s_addr = inet_addr("127.0.0.1");
  879. if (left_list_entries == 0) {
  880. return;
  881. }
  882. if ((left_list_entries == 1) &&
  883. (left_list->s_addr == local_ip.s_addr)) {
  884. process_localhost_transition = 1;
  885. return;
  886. }
  887. /*
  888. * Iterate left_list_entries.
  889. */
  890. member = left_list;
  891. for (i = 0; i < left_list_entries; i++) {
  892. for (checkpoint_list = checkpoint_list_head.next;
  893. checkpoint_list != &checkpoint_list_head;
  894. checkpoint_list = checkpoint_list->next) {
  895. checkpoint = list_entry (checkpoint_list,
  896. struct saCkptCheckpoint, list);
  897. index = processor_index_find(member, checkpoint->ckpt_refcount);
  898. if (index == -1) {
  899. continue;
  900. }
  901. /*
  902. * Decrement
  903. *
  904. */
  905. if (checkpoint->referenceCount >= 0) {
  906. checkpoint->referenceCount -= checkpoint->ckpt_refcount[index].count;
  907. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  908. &checkpoint->name.value,checkpoint->referenceCount);
  909. assert (checkpoint->referenceCount >= 0);
  910. } else {
  911. log_printf (LOG_LEVEL_ERROR, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  912. &checkpoint->name.value,checkpoint->referenceCount);
  913. assert(0);
  914. }
  915. checkpoint->ckpt_refcount[index].count = 0;
  916. memset((char*)&checkpoint->ckpt_refcount[index].addr, 0, sizeof(struct in_addr));
  917. /*
  918. * If checkpoint has been unlinked and this is the last reference, delete it
  919. */
  920. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  921. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Unlinking checkpoint %s.\n",
  922. &checkpoint->name.value);
  923. checkpoint_release (checkpoint);
  924. } else
  925. if ((checkpoint->expired == 0) && (checkpoint->referenceCount == 0)) {
  926. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: Starting timer to release checkpoint %s.\n",
  927. &checkpoint->name.value);
  928. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  929. poll_timer_add (aisexec_poll_handle,
  930. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  931. checkpoint,
  932. timer_function_retention,
  933. &checkpoint->retention_timer);
  934. }
  935. }
  936. member++;
  937. }
  938. return;
  939. }
  940. static int ckpt_confchg_fn (
  941. enum totem_configuration_type configuration_type,
  942. struct in_addr *member_list, int member_list_entries,
  943. struct in_addr *left_list, int left_list_entries,
  944. struct in_addr *joined_list, int joined_list_entries,
  945. struct memb_ring_id *ring_id)
  946. {
  947. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  948. #ifdef TODO
  949. totempg_recovery_plug_unplug (ckpt_checkpoint_recovery_plug_handle);
  950. #endif
  951. if (recovery_state == SYNCHRONY_STATE_ENDED) {
  952. memcpy (&saved_ring_id, ring_id, sizeof(struct memb_ring_id));
  953. }
  954. if (process_localhost_transition) {
  955. ckpt_replace_localhost_ip (joined_list);
  956. }
  957. }
  958. else if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  959. ckpt_recovery_process_members_exit(left_list, left_list_entries);
  960. recovery_state = SYNCHRONY_STATE_STARTED;
  961. recovery_abort = 0;
  962. }
  963. return (0);
  964. }
  965. static struct saCkptCheckpoint *ckpt_checkpoint_find_global (SaNameT *name)
  966. {
  967. struct list_head *checkpoint_list;
  968. struct saCkptCheckpoint *checkpoint;
  969. for (checkpoint_list = checkpoint_list_head.next;
  970. checkpoint_list != &checkpoint_list_head;
  971. checkpoint_list = checkpoint_list->next) {
  972. checkpoint = list_entry (checkpoint_list,
  973. struct saCkptCheckpoint, list);
  974. if (name_match (name, &checkpoint->name)) {
  975. return (checkpoint);
  976. }
  977. }
  978. return (0);
  979. }
  980. static void ckpt_checkpoint_remove_cleanup (
  981. struct conn_info *conn_info,
  982. struct saCkptCheckpoint *checkpoint)
  983. {
  984. struct list_head *list;
  985. struct checkpoint_cleanup *checkpoint_cleanup;
  986. for (list = conn_info->ais_ci.u.libckpt_ci.checkpoint_list.next;
  987. list != &conn_info->ais_ci.u.libckpt_ci.checkpoint_list;
  988. list = list->next) {
  989. checkpoint_cleanup = list_entry (list,
  990. struct checkpoint_cleanup, list);
  991. if (name_match (&checkpoint_cleanup->checkpoint.name, &checkpoint->name)
  992. || (checkpoint_cleanup->checkpoint.name.length == 0)) {
  993. list_del (&checkpoint_cleanup->list);
  994. free (checkpoint_cleanup);
  995. return;
  996. }
  997. }
  998. }
  999. static struct saCkptCheckpointSection *ckpt_checkpoint_find_globalSection (
  1000. struct saCkptCheckpoint *ckptCheckpoint,
  1001. char *id,
  1002. int idLen)
  1003. {
  1004. struct list_head *checkpoint_section_list;
  1005. struct saCkptCheckpointSection *ckptCheckpointSection;
  1006. if (idLen != 0) {
  1007. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", (char*)id, idLen);
  1008. }
  1009. else {
  1010. log_printf (LOG_LEVEL_DEBUG, "Finding default checkpoint section\n");
  1011. }
  1012. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  1013. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  1014. checkpoint_section_list = checkpoint_section_list->next) {
  1015. ckptCheckpointSection = list_entry (checkpoint_section_list,
  1016. struct saCkptCheckpointSection, list);
  1017. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen) {
  1018. log_printf (LOG_LEVEL_DEBUG, "Checking section id %*s\n",
  1019. ckptCheckpointSection->sectionDescriptor.sectionId.idLen,
  1020. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  1021. }
  1022. else {
  1023. log_printf (LOG_LEVEL_DEBUG, "Checking default section id\n");
  1024. }
  1025. /*
  1026. All 3 of these values being checked MUST be = 0 to return
  1027. The default section. If even one of them is NON zero follow
  1028. the normal route
  1029. */
  1030. if ((idLen ||
  1031. ckptCheckpointSection->sectionDescriptor.sectionId.id ||
  1032. ckptCheckpointSection->sectionDescriptor.sectionId.idLen) == 0) {
  1033. log_printf (LOG_LEVEL_DEBUG, "Returning default section\n");
  1034. return (ckptCheckpointSection);
  1035. }
  1036. if (ckptCheckpointSection->sectionDescriptor.sectionId.idLen == idLen &&
  1037. (ckptCheckpointSection->sectionDescriptor.sectionId.id)&&
  1038. (id)&&
  1039. (memcmp (ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1040. id, idLen) == 0)) {
  1041. log_printf (LOG_LEVEL_DEBUG, "Returning section %s(0x%x)\n", ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1042. ckptCheckpointSection);
  1043. return (ckptCheckpointSection);
  1044. }
  1045. }
  1046. return 0;
  1047. }
  1048. void checkpoint_section_release (struct saCkptCheckpointSection *section)
  1049. {
  1050. log_printf (LOG_LEVEL_DEBUG, "CKPT: checkpoint_section_release expiration timer = 0x%x\n", section->expiration_timer);
  1051. list_del (&section->list);
  1052. if (section->sectionDescriptor.sectionId.id) {
  1053. free (section->sectionDescriptor.sectionId.id);
  1054. }
  1055. if (section->sectionData) {
  1056. free (section->sectionData);
  1057. }
  1058. poll_timer_delete (aisexec_poll_handle, section->expiration_timer);
  1059. free (section);
  1060. }
  1061. void checkpoint_release (struct saCkptCheckpoint *checkpoint)
  1062. {
  1063. struct list_head *list;
  1064. struct saCkptCheckpointSection *section;
  1065. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1066. /*
  1067. * Release all checkpoint sections for this checkpoint
  1068. */
  1069. for (list = checkpoint->checkpointSectionsListHead.next;
  1070. list != &checkpoint->checkpointSectionsListHead;) {
  1071. section = list_entry (list,
  1072. struct saCkptCheckpointSection, list);
  1073. list = list->next;
  1074. checkpoint->sectionCount -= 1;
  1075. checkpoint_section_release (section);
  1076. }
  1077. list_del (&checkpoint->list);
  1078. free (checkpoint);
  1079. }
  1080. int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
  1081. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1082. struct iovec iovecs[2];
  1083. if (checkpoint->expired == 1) {
  1084. return (0);
  1085. }
  1086. req_exec_ckpt_checkpointclose.header.size =
  1087. sizeof (struct req_exec_ckpt_checkpointclose);
  1088. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1089. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1090. &checkpoint->name, sizeof (SaNameT));
  1091. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1092. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1093. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1094. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1095. return (0);
  1096. }
  1097. return (-1);
  1098. }
  1099. static int ckpt_exec_init_fn (struct openais_config *openais_config)
  1100. {
  1101. /*
  1102. * Initialize the saved ring ID.
  1103. */
  1104. saved_ring_id.seq = 0;
  1105. saved_ring_id.rep.s_addr = this_ip->sin_addr.s_addr;
  1106. #ifdef TODO
  1107. int res;
  1108. res = totempg_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  1109. if (res != 0) {
  1110. log_printf(LOG_LEVEL_ERROR,
  1111. "Could not create recovery plug for clm service.\n");
  1112. return (-1);
  1113. }
  1114. #endif
  1115. return (0);
  1116. }
  1117. static int ckpt_exit_fn (struct conn_info *conn_info)
  1118. {
  1119. struct checkpoint_cleanup *checkpoint_cleanup;
  1120. struct list_head *cleanup_list;
  1121. if (conn_info->conn_info_partner->service != CKPT_SERVICE) {
  1122. return 0;
  1123. }
  1124. log_printf(LOG_LEVEL_DEBUG, "ckpt_exit_fn conn_info = %#x, with fd = %d\n", conn_info, conn_info->fd);
  1125. /*
  1126. * close all checkpoints opened on this fd
  1127. */
  1128. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1129. while (!list_empty(&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list)) {
  1130. checkpoint_cleanup = list_entry (cleanup_list,
  1131. struct checkpoint_cleanup, list);
  1132. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  1133. ckpt_checkpoint_close (&checkpoint_cleanup->checkpoint);
  1134. }
  1135. list_del (&checkpoint_cleanup->list);
  1136. free (checkpoint_cleanup);
  1137. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1138. }
  1139. if (conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  1140. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  1141. }
  1142. list_del (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list);
  1143. return (0);
  1144. }
  1145. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  1146. {
  1147. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  1148. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  1149. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  1150. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  1151. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1152. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1153. struct checkpoint_cleanup *checkpoint_cleanup;
  1154. SaErrorT error = SA_AIS_OK;
  1155. int proc_index;
  1156. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  1157. if (req_exec_ckpt_checkpointopen->fail_with_error != SA_AIS_OK) {
  1158. error = req_exec_ckpt_checkpointopen->fail_with_error;
  1159. goto error_exit;
  1160. }
  1161. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  1162. /*
  1163. * If checkpoint doesn't exist, create one
  1164. */
  1165. if (ckptCheckpoint == 0) {
  1166. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1167. error = SA_AIS_ERR_NOT_EXIST;
  1168. goto error_exit;
  1169. }
  1170. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1171. if (ckptCheckpoint == 0) {
  1172. error = SA_AIS_ERR_NO_MEMORY;
  1173. goto error_exit;
  1174. }
  1175. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1176. if (ckptCheckpointSection == 0) {
  1177. free (ckptCheckpoint);
  1178. error = SA_AIS_ERR_NO_MEMORY;
  1179. goto error_exit;
  1180. }
  1181. memcpy (&ckptCheckpoint->name,
  1182. &req_lib_ckpt_checkpointopen->checkpointName,
  1183. sizeof (SaNameT));
  1184. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1185. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1186. sizeof (SaCkptCheckpointCreationAttributesT));
  1187. ckptCheckpoint->unlinked = 0;
  1188. list_init (&ckptCheckpoint->list);
  1189. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1190. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1191. ckptCheckpoint->referenceCount = 0;
  1192. ckptCheckpoint->retention_timer = 0;
  1193. ckptCheckpoint->expired = 0;
  1194. ckptCheckpoint->sectionCount = 0;
  1195. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1196. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1197. ckptCheckpoint->active_replica_set = 1;
  1198. } else
  1199. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1200. ckptCheckpoint->active_replica_set = 1;
  1201. } else {
  1202. ckptCheckpoint->active_replica_set = 0;
  1203. }
  1204. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1205. /*
  1206. * Add in default checkpoint section
  1207. */
  1208. list_init (&ckptCheckpointSection->list);
  1209. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1210. /*
  1211. * Default section id
  1212. */
  1213. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1214. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1215. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1216. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1217. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1218. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1219. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1220. assert(ckptCheckpointSection->sectionData);
  1221. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1222. ckptCheckpointSection->expiration_timer = 0;
  1223. } else {
  1224. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  1225. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  1226. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1227. sizeof (SaCkptCheckpointCreationAttributesT)) != 0) {
  1228. error = SA_AIS_ERR_EXIST;
  1229. goto error_exit;
  1230. }
  1231. }
  1232. /*
  1233. * If the checkpoint has been unlinked, it is an invalid name
  1234. */
  1235. if (ckptCheckpoint->unlinked) {
  1236. error = SA_AIS_ERR_NOT_EXIST; /* Is this the correct return ? */
  1237. goto error_exit;
  1238. }
  1239. /*
  1240. * Setup connection information and mark checkpoint as referenced
  1241. */
  1242. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  1243. ckptCheckpoint->referenceCount += 1;
  1244. /*
  1245. * Add the connection reference information to the Checkpoint to be
  1246. * sent out later as a part of the sync process.
  1247. *
  1248. */
  1249. proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  1250. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1251. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  1252. }
  1253. if (proc_index != -1 ) {
  1254. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  1255. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  1256. }
  1257. else {
  1258. log_printf (LOG_LEVEL_ERROR,
  1259. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1260. ckptCheckpoint);
  1261. }
  1262. /*
  1263. * Reset retention duration since this checkpoint was just opened
  1264. */
  1265. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1266. ckptCheckpoint->retention_timer = 0;
  1267. /*
  1268. * Send error result to CKPT library
  1269. */
  1270. error_exit:
  1271. /*
  1272. * If this node was the source of the message, respond to this node
  1273. */
  1274. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1275. /*
  1276. * If its an async call respond with the invocation and handle
  1277. */
  1278. if (req_exec_ckpt_checkpointopen->async_call) {
  1279. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1280. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1281. res_lib_ckpt_checkpointopenasync.header.error = error;
  1282. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  1283. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1284. libais_send_response (
  1285. req_exec_ckpt_checkpointopen->source.conn_info,
  1286. &res_lib_ckpt_checkpointopenasync,
  1287. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1288. libais_send_response (
  1289. req_exec_ckpt_checkpointopen->source.conn_info->conn_info_partner,
  1290. &res_lib_ckpt_checkpointopenasync,
  1291. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1292. } else {
  1293. /*
  1294. * otherwise respond with the normal checkpointopen response
  1295. */
  1296. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1297. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1298. res_lib_ckpt_checkpointopen.header.error = error;
  1299. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  1300. sizeof (struct res_lib_ckpt_checkpointopen));
  1301. }
  1302. if (error == SA_AIS_OK) {
  1303. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1304. if (checkpoint_cleanup == 0) {
  1305. free (ckptCheckpoint);
  1306. error = SA_AIS_ERR_NO_MEMORY;
  1307. } else {
  1308. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1309. list_add (&checkpoint_cleanup->list,
  1310. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1311. }
  1312. }
  1313. }
  1314. return (0);
  1315. }
  1316. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1317. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1318. struct ckpt_refcnt *ref_cnt)
  1319. {
  1320. int i;
  1321. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1322. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1323. SaErrorT error = SA_AIS_OK;
  1324. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1325. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1326. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1327. if (ref_cnt[i].addr.s_addr == 0) {
  1328. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1329. ref_cnt[i].count);
  1330. }
  1331. else {
  1332. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1333. i,
  1334. inet_ntoa(ref_cnt[i].addr),
  1335. ref_cnt[i].count);
  1336. }
  1337. }
  1338. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1339. /*
  1340. * If checkpoint doesn't exist, create one
  1341. */
  1342. if (ckptCheckpoint == 0) {
  1343. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1344. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1345. if (ckptCheckpoint == 0) {
  1346. error = SA_AIS_ERR_NO_MEMORY;
  1347. goto error_exit;
  1348. }
  1349. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1350. if (ckptCheckpointSection == 0) {
  1351. free (ckptCheckpoint);
  1352. error = SA_AIS_ERR_NO_MEMORY;
  1353. goto error_exit;
  1354. }
  1355. memcpy (&ckptCheckpoint->name,
  1356. checkpointName,
  1357. sizeof (SaNameT));
  1358. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1359. ckptAttributes,
  1360. sizeof (SaCkptCheckpointCreationAttributesT));
  1361. ckptCheckpoint->unlinked = 0;
  1362. list_init (&ckptCheckpoint->list);
  1363. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1364. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1365. ckptCheckpoint->retention_timer = 0;
  1366. ckptCheckpoint->expired = 0;
  1367. /*
  1368. * Add in default checkpoint section
  1369. */
  1370. list_init (&ckptCheckpointSection->list);
  1371. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1372. /*
  1373. * Default section id
  1374. */
  1375. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1376. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1377. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1378. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1379. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1380. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1381. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1382. assert(ckptCheckpointSection->sectionData);
  1383. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1384. ckptCheckpointSection->expiration_timer = 0;
  1385. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1386. }
  1387. else {
  1388. /*
  1389. * Setup connection information and mark checkpoint as referenced
  1390. */
  1391. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1392. }
  1393. /*
  1394. * If the checkpoint has been unlinked, it is an invalid name
  1395. */
  1396. if (ckptCheckpoint->unlinked) {
  1397. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1398. goto error_exit;
  1399. }
  1400. /*CHECK to see if there are any existing ckpts*/
  1401. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1402. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1403. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1404. }
  1405. else {
  1406. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1407. }
  1408. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1409. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1410. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1411. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1412. /*
  1413. * Reset retention duration since this checkpoint was just opened
  1414. */
  1415. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1416. ckptCheckpoint->retention_timer = 0;
  1417. /*
  1418. * Send error result to CKPT library
  1419. */
  1420. error_exit:
  1421. return (error);
  1422. }
  1423. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1424. {
  1425. int retcode;
  1426. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1427. = (struct req_exec_ckpt_synchronize_state *)message;
  1428. /*
  1429. * If the Incoming message's previous ring id == saved_ring_id
  1430. * Ignore because we have seen this message before.
  1431. */
  1432. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1433. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1434. return(0);
  1435. }
  1436. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1437. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1438. req_exec_ckpt_sync_state->ckpt_refcount);
  1439. if (retcode != SA_AIS_OK) {
  1440. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1441. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1442. }
  1443. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1444. &req_exec_ckpt_sync_state->checkpointName,
  1445. (char*)req_exec_ckpt_sync_state
  1446. + sizeof (struct req_exec_ckpt_synchronize_state));
  1447. if (retcode != SA_AIS_OK) {
  1448. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1449. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1450. }
  1451. return (0);
  1452. }
  1453. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1454. {
  1455. int retcode;
  1456. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1457. = (struct req_exec_ckpt_synchronize_section *)message;
  1458. /*
  1459. * If the Incoming message's previous ring id == saved_ring_id
  1460. * Ignore because we have seen this message before.
  1461. */
  1462. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1463. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1464. return(0);
  1465. }
  1466. /*
  1467. * Write the contents of the section to the checkpoint section.
  1468. */
  1469. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1470. (char*)req_exec_ckpt_sync_section
  1471. + sizeof (struct req_exec_ckpt_synchronize_section),
  1472. &req_exec_ckpt_sync_section->checkpointName,
  1473. (char*)req_exec_ckpt_sync_section
  1474. + sizeof (struct req_exec_ckpt_synchronize_section)
  1475. + req_exec_ckpt_sync_section->sectionId.idLen,
  1476. req_exec_ckpt_sync_section->dataOffSet,
  1477. req_exec_ckpt_sync_section->dataSize);
  1478. if (retcode != SA_AIS_OK) {
  1479. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1480. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1481. }
  1482. return (0);
  1483. }
  1484. unsigned int abstime_to_msec (SaTimeT time)
  1485. {
  1486. struct timeval tv;
  1487. unsigned long long curr_time;
  1488. unsigned long long msec_time;
  1489. gettimeofday (&tv, NULL);
  1490. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1491. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1492. msec_time = (((unsigned long long)time) / 1000000) -
  1493. (unsigned long long)curr_time;
  1494. return ((unsigned int)(msec_time));
  1495. }
  1496. void timer_function_section_expire (void *data)
  1497. {
  1498. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1499. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1500. struct ckpt_identifier *ckpt_id = 0;
  1501. ckpt_id = (struct ckpt_identifier *)data;
  1502. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1503. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1504. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1505. ckpt_id->ckpt_section_id.id,
  1506. (char *)&ckpt_id->ckpt_name.value);
  1507. }
  1508. else {
  1509. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1510. goto free_mem;
  1511. }
  1512. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1513. if (ckptCheckpoint == 0) {
  1514. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1515. (char *)&ckpt_id->ckpt_name.value);
  1516. goto free_mem;
  1517. }
  1518. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1519. ckpt_id->ckpt_section_id.id,
  1520. (int)ckpt_id->ckpt_section_id.idLen);
  1521. if (ckptCheckpointSection == 0) {
  1522. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1523. ckpt_id->ckpt_section_id.id,
  1524. (char *)&ckpt_id->ckpt_name.value);
  1525. goto free_mem;
  1526. }
  1527. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1528. ckpt_id->ckpt_section_id.id,
  1529. (char *)&ckpt_id->ckpt_name.value);
  1530. ckptCheckpoint->sectionCount -= 1;
  1531. checkpoint_section_release (ckptCheckpointSection);
  1532. free_mem :
  1533. free (ckpt_id);
  1534. }
  1535. void timer_function_retention (void *data)
  1536. {
  1537. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1538. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1539. struct iovec iovec;
  1540. checkpoint->retention_timer = 0;
  1541. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1542. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1543. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1544. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1545. &checkpoint->name,
  1546. sizeof (SaNameT));
  1547. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1548. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1549. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1550. }
  1551. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1552. {
  1553. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1554. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1555. struct saCkptCheckpoint *checkpoint = 0;
  1556. SaAisErrorT error = SA_AIS_OK;
  1557. int proc_index;
  1558. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1559. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1560. if (checkpoint == 0) {
  1561. goto error_exit;
  1562. }
  1563. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1564. checkpoint->referenceCount--;
  1565. /*
  1566. * Modify the connection reference information to the Checkpoint to be
  1567. * sent out later as a part of the sync process.
  1568. */
  1569. proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1570. if (proc_index != -1 ) {
  1571. checkpoint->ckpt_refcount[proc_index].count--;
  1572. }
  1573. else {
  1574. log_printf (LOG_LEVEL_ERROR,
  1575. "CKPT: Could Not find Processor Info %p info.\n",
  1576. checkpoint);
  1577. }
  1578. assert (checkpoint->referenceCount >= 0);
  1579. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1580. checkpoint->referenceCount);
  1581. /*
  1582. * If checkpoint has been unlinked and this is the last reference, delete it
  1583. */
  1584. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1585. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1586. checkpoint_release (checkpoint);
  1587. } else
  1588. if (checkpoint->referenceCount == 0) {
  1589. poll_timer_add (aisexec_poll_handle,
  1590. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1591. checkpoint,
  1592. timer_function_retention,
  1593. &checkpoint->retention_timer);
  1594. }
  1595. error_exit:
  1596. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1597. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1598. checkpoint);
  1599. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1600. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1601. res_lib_ckpt_checkpointclose.header.error = error;
  1602. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1603. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1604. }
  1605. return (0);
  1606. }
  1607. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1608. {
  1609. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1610. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1611. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1612. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1613. SaErrorT error = SA_AIS_OK;
  1614. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1615. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1616. if (ckptCheckpoint == 0) {
  1617. error = SA_AIS_ERR_NOT_EXIST;
  1618. goto error_exit;
  1619. }
  1620. if (ckptCheckpoint->unlinked) {
  1621. error = SA_AIS_ERR_INVALID_PARAM;
  1622. goto error_exit;
  1623. }
  1624. ckptCheckpoint->unlinked = 1;
  1625. /*
  1626. * Immediately delete entry if reference count is zero
  1627. */
  1628. if (ckptCheckpoint->referenceCount == 0) {
  1629. /*
  1630. * Remove retention timer since this checkpoint was unlinked and is no
  1631. * longer referenced
  1632. */
  1633. checkpoint_release (ckptCheckpoint);
  1634. }
  1635. error_exit:
  1636. /*
  1637. * If this node was the source of the message, respond to this node
  1638. */
  1639. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1640. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1641. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1642. res_lib_ckpt_checkpointunlink.header.error = error;
  1643. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1644. sizeof (struct res_lib_ckpt_checkpointunlink));
  1645. }
  1646. return (0);
  1647. }
  1648. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1649. {
  1650. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1651. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1652. struct saCkptCheckpoint *checkpoint;
  1653. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  1654. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1655. if (checkpoint) {
  1656. log_printf (LOG_LEVEL_DEBUG, "CKPT: Setting retention duration for checkpoint %s\n",
  1657. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1658. if (checkpoint->unlinked == 0) {
  1659. checkpoint->checkpointCreationAttributes.retentionDuration =
  1660. req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1661. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1662. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1663. poll_timer_add (aisexec_poll_handle,
  1664. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1665. checkpoint,
  1666. timer_function_retention,
  1667. &checkpoint->retention_timer);
  1668. }
  1669. error = SA_AIS_OK;
  1670. }
  1671. }
  1672. /*
  1673. * Respond to library if this processor sent the duration set request
  1674. */
  1675. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1676. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1677. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1678. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  1679. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1680. &res_lib_ckpt_checkpointretentiondurationset,
  1681. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1682. }
  1683. return (0);
  1684. }
  1685. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1686. {
  1687. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1688. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1689. struct saCkptCheckpoint *checkpoint;
  1690. struct iovec iovecs[2];
  1691. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1692. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount < 1)) {
  1693. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1694. checkpoint->expired = 1;
  1695. req_exec_ckpt_checkpointunlink.header.size =
  1696. sizeof (struct req_exec_ckpt_checkpointunlink);
  1697. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1698. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1699. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1700. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1701. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1702. sizeof (SaNameT));
  1703. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1704. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1705. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1706. }
  1707. return (0);
  1708. }
  1709. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1710. SaNameT *checkpointName,
  1711. char* SectionId)
  1712. {
  1713. struct saCkptCheckpoint *ckptCheckpoint;
  1714. struct saCkptCheckpointSection *ckptCheckpointSection;
  1715. void *initialData;
  1716. void *sectionId;
  1717. struct ckpt_identifier *ckpt_id = 0;
  1718. SaErrorT error = SA_AIS_OK;
  1719. if ((int)sectionDescriptor->sectionId.idLen) {
  1720. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1721. &checkpointName->value, SectionId);
  1722. } else {
  1723. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1724. &checkpointName->value);
  1725. }
  1726. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1727. if (ckptCheckpoint == 0) {
  1728. error = SA_AIS_ERR_NOT_EXIST;
  1729. goto error_exit;
  1730. }
  1731. /*
  1732. * Determine if user-specified checkpoint ID already exists
  1733. */
  1734. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1735. SectionId,
  1736. (int)sectionDescriptor->sectionId.idLen);
  1737. if (ckptCheckpointSection) {
  1738. error = SA_AIS_ERR_EXIST;
  1739. goto error_exit;
  1740. }
  1741. /*
  1742. * Allocate checkpoint section
  1743. */
  1744. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1745. if (ckptCheckpointSection == 0) {
  1746. error = SA_AIS_ERR_NO_MEMORY;
  1747. goto error_exit;
  1748. }
  1749. /*
  1750. * Allocate checkpoint section data
  1751. */
  1752. initialData = malloc (sectionDescriptor->sectionSize);
  1753. if (initialData == 0) {
  1754. free (ckptCheckpointSection);
  1755. error = SA_AIS_ERR_NO_MEMORY;
  1756. goto error_exit;
  1757. }
  1758. /*
  1759. * Allocate checkpoint section id
  1760. */
  1761. if (sectionDescriptor->sectionId.idLen) {
  1762. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1763. if (sectionId == 0) {
  1764. free (ckptCheckpointSection);
  1765. free (initialData);
  1766. error = SA_AIS_ERR_NO_MEMORY;
  1767. goto error_exit;
  1768. }
  1769. } else {
  1770. sectionId = 0;
  1771. }
  1772. /*
  1773. * Copy checkpoint section ID and initialize data.
  1774. */
  1775. if (SectionId) {
  1776. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  1777. } else {
  1778. sectionId = 0;
  1779. }
  1780. memset (initialData, 0, sectionDescriptor->sectionSize);
  1781. /*
  1782. * Configure checkpoint section
  1783. */
  1784. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1785. sectionDescriptor,
  1786. sizeof(SaCkptSectionDescriptorT));
  1787. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1788. ckptCheckpointSection->sectionData = initialData;
  1789. ckptCheckpointSection->expiration_timer = 0;
  1790. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1791. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1792. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1793. assert(ckpt_id);
  1794. memcpy(&ckpt_id->ckpt_name,checkpointName,sizeof(SaNameT));
  1795. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1796. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  1797. ckpt_id->ckpt_section_id.id,
  1798. (char *)&ckpt_id->ckpt_name.value);
  1799. poll_timer_add (aisexec_poll_handle,
  1800. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1801. ckpt_id,
  1802. timer_function_section_expire,
  1803. &ckptCheckpointSection->expiration_timer);
  1804. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create expiration timer = 0x%x\n",
  1805. ckptCheckpointSection->expiration_timer);
  1806. }
  1807. /*
  1808. * Add checkpoint section to checkpoint
  1809. */
  1810. list_init (&ckptCheckpointSection->list);
  1811. list_add (&ckptCheckpointSection->list,
  1812. &ckptCheckpoint->checkpointSectionsListHead);
  1813. error_exit:
  1814. return (error);
  1815. }
  1816. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1817. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1818. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1819. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1820. struct saCkptCheckpoint *ckptCheckpoint;
  1821. struct saCkptCheckpointSection *ckptCheckpointSection;
  1822. void *initialData;
  1823. void *sectionId;
  1824. struct ckpt_identifier *ckpt_id = 0;
  1825. SaErrorT error = SA_AIS_OK;
  1826. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1827. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1828. if (ckptCheckpoint == 0) {
  1829. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1830. goto error_exit;
  1831. }
  1832. if (ckptCheckpoint->sectionCount == ckptCheckpoint->checkpointCreationAttributes.maxSections) {
  1833. error = SA_AIS_ERR_NO_SPACE;
  1834. goto error_exit;
  1835. }
  1836. if (ckptCheckpoint->checkpointCreationAttributes.maxSections == 1) {
  1837. error = SA_AIS_ERR_EXIST;
  1838. goto error_exit;
  1839. }
  1840. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize <
  1841. req_lib_ckpt_sectioncreate->initialDataSize) {
  1842. error = SA_AIS_ERR_INVALID_PARAM;
  1843. goto error_exit;
  1844. }
  1845. /*
  1846. * Determine if user-specified checkpoint ID already exists
  1847. */
  1848. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1849. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1850. req_lib_ckpt_sectioncreate->idLen);
  1851. if (ckptCheckpointSection) {
  1852. error = SA_AIS_ERR_EXIST;
  1853. goto error_exit;
  1854. }
  1855. /*
  1856. * Allocate checkpoint section
  1857. */
  1858. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1859. if (ckptCheckpointSection == 0) {
  1860. error = SA_AIS_ERR_NO_MEMORY;
  1861. goto error_exit;
  1862. }
  1863. /*
  1864. * Allocate checkpoint section data
  1865. */
  1866. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1867. if (initialData == 0) {
  1868. free (ckptCheckpointSection);
  1869. error = SA_AIS_ERR_NO_MEMORY;
  1870. goto error_exit;
  1871. }
  1872. /*
  1873. * Allocate checkpoint section id
  1874. */
  1875. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1876. if (sectionId == 0) {
  1877. free (ckptCheckpointSection);
  1878. free (initialData);
  1879. error = SA_AIS_ERR_NO_MEMORY;
  1880. goto error_exit;
  1881. }
  1882. /*
  1883. * Copy checkpoint section and section ID
  1884. */
  1885. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1886. req_lib_ckpt_sectioncreate->idLen);
  1887. memcpy (initialData,
  1888. ((char *)req_lib_ckpt_sectioncreate) +
  1889. sizeof (struct req_lib_ckpt_sectioncreate) +
  1890. req_lib_ckpt_sectioncreate->idLen,
  1891. req_lib_ckpt_sectioncreate->initialDataSize);
  1892. /*
  1893. * Configure checkpoint section
  1894. */
  1895. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1896. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1897. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1898. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1899. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1900. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1901. ckptCheckpointSection->sectionData = initialData;
  1902. ckptCheckpointSection->expiration_timer = 0;
  1903. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1904. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1905. assert(ckpt_id);
  1906. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectioncreate->checkpointName,sizeof(SaNameT));
  1907. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1908. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  1909. ckpt_id->ckpt_section_id.id,
  1910. (char *)&ckpt_id->ckpt_name.value);
  1911. poll_timer_add (aisexec_poll_handle,
  1912. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1913. ckpt_id,
  1914. timer_function_section_expire,
  1915. &ckptCheckpointSection->expiration_timer);
  1916. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionicreate expiration timer = 0x%x\n",
  1917. ckptCheckpointSection->expiration_timer);
  1918. }
  1919. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_sectioncreate created section with id = %s, idLen = %d\n",
  1920. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1921. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  1922. /*
  1923. * Add checkpoint section to checkpoint
  1924. */
  1925. list_init (&ckptCheckpointSection->list);
  1926. list_add (&ckptCheckpointSection->list,
  1927. &ckptCheckpoint->checkpointSectionsListHead);
  1928. ckptCheckpoint->sectionCount += 1;
  1929. error_exit:
  1930. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1931. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1932. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1933. res_lib_ckpt_sectioncreate.header.error = error;
  1934. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1935. &res_lib_ckpt_sectioncreate,
  1936. sizeof (struct res_lib_ckpt_sectioncreate));
  1937. }
  1938. return (0);
  1939. }
  1940. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1941. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1942. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1943. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1944. struct saCkptCheckpoint *ckptCheckpoint;
  1945. struct saCkptCheckpointSection *ckptCheckpointSection;
  1946. SaErrorT error = SA_AIS_OK;
  1947. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1948. if (ckptCheckpoint == 0) {
  1949. error = SA_AIS_ERR_NOT_EXIST;
  1950. goto error_exit;
  1951. }
  1952. if (ckptCheckpoint->active_replica_set == 0) {
  1953. log_printf (LOG_LEVEL_NOTICE, "sectiondelete: no active replica, returning error.\n");
  1954. error = SA_AIS_ERR_NOT_EXIST;
  1955. goto error_exit;
  1956. }
  1957. /*
  1958. * Determine if the user is trying to delete the default section
  1959. */
  1960. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1961. error = SA_AIS_ERR_INVALID_PARAM;
  1962. goto error_exit;
  1963. }
  1964. /*
  1965. * Find checkpoint section to be deleted
  1966. */
  1967. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1968. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1969. req_lib_ckpt_sectiondelete->idLen);
  1970. if (ckptCheckpointSection == 0) {
  1971. error = SA_AIS_ERR_NOT_EXIST;
  1972. goto error_exit;
  1973. }
  1974. printf ("delete ckptCheckpointSection name %s\n",
  1975. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  1976. /*
  1977. * Delete checkpoint section
  1978. */
  1979. ckptCheckpoint->sectionCount -= 1;
  1980. checkpoint_section_release (ckptCheckpointSection);
  1981. /*
  1982. * return result to CKPT library
  1983. */
  1984. error_exit:
  1985. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  1986. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1987. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1988. res_lib_ckpt_sectiondelete.header.error = error;
  1989. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1990. &res_lib_ckpt_sectiondelete,
  1991. sizeof (struct res_lib_ckpt_sectiondelete));
  1992. }
  1993. return (0);
  1994. }
  1995. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1996. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1997. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1998. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1999. struct saCkptCheckpoint *ckptCheckpoint;
  2000. struct saCkptCheckpointSection *ckptCheckpointSection;
  2001. struct ckpt_identifier *ckpt_id = 0;
  2002. SaErrorT error = SA_AIS_OK;
  2003. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  2004. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  2005. if (ckptCheckpoint == 0) {
  2006. error = SA_AIS_ERR_NOT_EXIST;
  2007. goto error_exit;
  2008. }
  2009. if (ckptCheckpoint->active_replica_set == 0) {
  2010. log_printf (LOG_LEVEL_NOTICE, "expirationset: no active replica, returning error.\n");
  2011. error = SA_AIS_ERR_NOT_EXIST;
  2012. goto error_exit;
  2013. }
  2014. /*
  2015. * Determine if the user is trying to set expiration time for the default section
  2016. */
  2017. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  2018. error = SA_AIS_ERR_INVALID_PARAM;
  2019. goto error_exit;
  2020. }
  2021. /*
  2022. * Find checkpoint section that expiration time should be set for
  2023. */
  2024. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2025. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  2026. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  2027. req_lib_ckpt_sectionexpirationtimeset->idLen);
  2028. if (ckptCheckpointSection == 0) {
  2029. error = SA_AIS_ERR_NOT_EXIST;
  2030. goto error_exit;
  2031. }
  2032. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  2033. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  2034. ckptCheckpointSection->expiration_timer = 0;
  2035. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  2036. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2037. assert(ckpt_id);
  2038. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectionexpirationtimeset->checkpointName,sizeof(SaNameT));
  2039. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2040. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%x\n",
  2041. ckpt_id->ckpt_section_id.id,
  2042. (char *)&ckpt_id->ckpt_name.value,
  2043. ckpt_id);
  2044. poll_timer_add (aisexec_poll_handle,
  2045. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2046. ckpt_id,
  2047. timer_function_section_expire,
  2048. &ckptCheckpointSection->expiration_timer);
  2049. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%x\n",
  2050. ckptCheckpointSection->expiration_timer);
  2051. }
  2052. error_exit:
  2053. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2054. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2055. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2056. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2057. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  2058. &res_lib_ckpt_sectionexpirationtimeset,
  2059. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2060. }
  2061. return (0);
  2062. }
  2063. static int recovery_section_write(int sectionIdLen,
  2064. char* sectionId,
  2065. SaNameT *checkpointName,
  2066. void *newData,
  2067. SaUint32T dataOffSet,
  2068. SaUint32T dataSize)
  2069. {
  2070. struct saCkptCheckpoint *ckptCheckpoint;
  2071. struct saCkptCheckpointSection *ckptCheckpointSection;
  2072. int sizeRequired;
  2073. SaErrorT error = SA_AIS_OK;
  2074. char *sd;
  2075. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  2076. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  2077. if (ckptCheckpoint == 0) {
  2078. error = SA_AIS_ERR_NOT_EXIST;
  2079. goto error_exit;
  2080. }
  2081. /*
  2082. * Find checkpoint section to be written
  2083. */
  2084. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2085. sectionId,
  2086. sectionIdLen);
  2087. if (ckptCheckpointSection == 0) {
  2088. error = SA_AIS_ERR_NOT_EXIST;
  2089. goto error_exit;
  2090. }
  2091. /*
  2092. * If write would extend past end of section data, return error;
  2093. */
  2094. sizeRequired = dataOffSet + dataSize;
  2095. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2096. error = SA_AIS_ERR_ACCESS;
  2097. goto error_exit;
  2098. }
  2099. /*
  2100. * Write checkpoint section to section data
  2101. */
  2102. if (dataSize > 0) {
  2103. sd = (char *)ckptCheckpointSection->sectionData;
  2104. memcpy (&sd[dataOffSet],
  2105. newData,
  2106. dataSize);
  2107. }
  2108. error_exit:
  2109. return (error);
  2110. }
  2111. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2112. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2113. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  2114. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2115. struct saCkptCheckpoint *ckptCheckpoint;
  2116. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2117. int sizeRequired;
  2118. void *sectionData;
  2119. SaErrorT error = SA_AIS_OK;
  2120. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2121. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  2122. if (ckptCheckpoint == 0) {
  2123. log_printf (LOG_LEVEL_ERROR, "CKPT: ckpt_checkpoint_find_global returned 0 Calling error_exit.\n");
  2124. error = SA_AIS_ERR_NOT_EXIST;
  2125. goto error_exit;
  2126. }
  2127. if (ckptCheckpoint->active_replica_set == 0) {
  2128. log_printf (LOG_LEVEL_NOTICE, "checkpointwrite: no active replica, returning error.\n");
  2129. error = SA_AIS_ERR_NOT_EXIST;
  2130. goto error_exit;
  2131. }
  2132. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionwrite->dataSize) {
  2133. error = SA_AIS_ERR_INVALID_PARAM;
  2134. goto error_exit;
  2135. }
  2136. /*
  2137. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2138. */
  2139. /*
  2140. * Find checkpoint section to be written
  2141. */
  2142. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2143. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2144. req_lib_ckpt_sectionwrite->idLen);
  2145. if (ckptCheckpointSection == 0) {
  2146. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  2147. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2148. }
  2149. else {
  2150. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2151. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2152. }
  2153. error = SA_AIS_ERR_NOT_EXIST;
  2154. goto error_exit;
  2155. }
  2156. /*
  2157. * If write would extend past end of section data, enlarge section
  2158. */
  2159. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  2160. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2161. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  2162. if (sectionData == 0) {
  2163. log_printf (LOG_LEVEL_ERROR, "CKPT: sectionData realloc returned 0 Calling error_exit.\n");
  2164. error = SA_AIS_ERR_NO_MEMORY;
  2165. goto error_exit;
  2166. }
  2167. /*
  2168. * Install new section data
  2169. */
  2170. ckptCheckpointSection->sectionData = sectionData;
  2171. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  2172. }
  2173. /*
  2174. * Write checkpoint section to section data
  2175. */
  2176. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  2177. char *sd;
  2178. int *val;
  2179. val = ckptCheckpointSection->sectionData;
  2180. sd = (char *)ckptCheckpointSection->sectionData;
  2181. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  2182. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  2183. req_lib_ckpt_sectionwrite->idLen,
  2184. req_lib_ckpt_sectionwrite->dataSize);
  2185. }
  2186. /*
  2187. * Write write response to CKPT library
  2188. */
  2189. error_exit:
  2190. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2191. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2192. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2193. res_lib_ckpt_sectionwrite.header.error = error;
  2194. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  2195. &res_lib_ckpt_sectionwrite,
  2196. sizeof (struct res_lib_ckpt_sectionwrite));
  2197. }
  2198. return (0);
  2199. }
  2200. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2201. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2202. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  2203. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2204. struct saCkptCheckpoint *ckptCheckpoint;
  2205. struct saCkptCheckpointSection *ckptCheckpointSection;
  2206. void *sectionData;
  2207. SaErrorT error = SA_AIS_OK;
  2208. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2209. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  2210. if (ckptCheckpoint == 0) {
  2211. error = SA_AIS_ERR_NOT_EXIST;
  2212. goto error_exit;
  2213. }
  2214. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionoverwrite->dataSize) {
  2215. error = SA_AIS_ERR_INVALID_PARAM;
  2216. goto error_exit;
  2217. }
  2218. /*
  2219. * Find checkpoint section to be overwritten
  2220. */
  2221. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2222. ((char *)req_lib_ckpt_sectionoverwrite) +
  2223. sizeof (struct req_lib_ckpt_sectionoverwrite),
  2224. req_lib_ckpt_sectionoverwrite->idLen);
  2225. if (ckptCheckpointSection == 0) {
  2226. error = SA_AIS_ERR_NOT_EXIST;
  2227. goto error_exit;
  2228. }
  2229. /*
  2230. * Allocate checkpoint section data
  2231. */
  2232. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  2233. if (sectionData == 0) {
  2234. error = SA_AIS_ERR_NO_MEMORY;
  2235. goto error_exit;
  2236. }
  2237. memcpy (sectionData,
  2238. ((char *)req_lib_ckpt_sectionoverwrite) +
  2239. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  2240. req_lib_ckpt_sectionoverwrite->idLen,
  2241. req_lib_ckpt_sectionoverwrite->dataSize);
  2242. /*
  2243. * release old checkpoint section data
  2244. */
  2245. free (ckptCheckpointSection->sectionData);
  2246. /*
  2247. * Install overwritten checkpoint section data
  2248. */
  2249. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  2250. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2251. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2252. ckptCheckpointSection->sectionData = sectionData;
  2253. /*
  2254. * return result to CKPT library
  2255. */
  2256. error_exit:
  2257. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2258. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  2259. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2260. res_lib_ckpt_sectionoverwrite.header.error = error;
  2261. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  2262. &res_lib_ckpt_sectionoverwrite,
  2263. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2264. }
  2265. return (0);
  2266. }
  2267. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2268. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2269. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  2270. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2271. struct saCkptCheckpoint *ckptCheckpoint;
  2272. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2273. int sectionSize = 0;
  2274. SaErrorT error = SA_AIS_OK;
  2275. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2276. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  2277. if (ckptCheckpoint == 0) {
  2278. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  2279. goto error_exit;
  2280. }
  2281. /*
  2282. * Find checkpoint section to be read
  2283. */
  2284. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2285. ((char *)req_lib_ckpt_sectionread) +
  2286. sizeof (struct req_lib_ckpt_sectionread),
  2287. req_lib_ckpt_sectionread->idLen);
  2288. if (ckptCheckpointSection == 0) {
  2289. error = SA_AIS_ERR_NOT_EXIST;
  2290. goto error_exit;
  2291. }
  2292. /*
  2293. * Determine the section size
  2294. */
  2295. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  2296. req_lib_ckpt_sectionread->dataOffset;
  2297. /*
  2298. * If the library has less space available then can be sent from the
  2299. * section, reduce bytes sent to library to max requested
  2300. */
  2301. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  2302. sectionSize = req_lib_ckpt_sectionread->dataSize;
  2303. }
  2304. /*
  2305. * If dataOffset is past end of data, return INVALID PARAM
  2306. */
  2307. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  2308. sectionSize = 0;
  2309. error = SA_AIS_ERR_INVALID_PARAM;
  2310. goto error_exit;
  2311. }
  2312. /*
  2313. * Write read response to CKPT library
  2314. */
  2315. error_exit:
  2316. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2317. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  2318. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2319. res_lib_ckpt_sectionread.header.error = error;
  2320. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2321. &res_lib_ckpt_sectionread,
  2322. sizeof (struct res_lib_ckpt_sectionread));
  2323. /*
  2324. * Write checkpoint to CKPT library section if section has data
  2325. */
  2326. if (sectionSize) {
  2327. char *sd;
  2328. sd = (char *)ckptCheckpointSection->sectionData;
  2329. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2330. &sd[req_lib_ckpt_sectionread->dataOffset],
  2331. sectionSize);
  2332. }
  2333. }
  2334. return (0);
  2335. }
  2336. static int ckpt_init_two_fn (struct conn_info *conn_info)
  2337. {
  2338. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator
  2339. .list);
  2340. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  2341. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  2342. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  2343. list_add (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list,
  2344. &checkpoint_iterator_list_head);
  2345. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list);
  2346. return (0);
  2347. }
  2348. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  2349. {
  2350. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  2351. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2352. struct iovec iovecs[2];
  2353. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  2354. req_exec_ckpt_checkpointopen.header.size =
  2355. sizeof (struct req_exec_ckpt_checkpointopen);
  2356. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2357. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2358. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2359. req_lib_ckpt_checkpointopen,
  2360. sizeof (struct req_lib_ckpt_checkpointopen));
  2361. req_exec_ckpt_checkpointopen.async_call = 0;
  2362. req_exec_ckpt_checkpointopen.invocation = 0;
  2363. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  2364. req_exec_ckpt_checkpointopen.fail_with_error = SA_AIS_OK;
  2365. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2366. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2367. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2368. return (0);
  2369. }
  2370. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  2371. {
  2372. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  2373. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2374. struct iovec iovecs[2];
  2375. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2376. req_exec_ckpt_checkpointopen.header.size =
  2377. sizeof (struct req_exec_ckpt_checkpointopen);
  2378. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2379. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2380. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2381. req_lib_ckpt_checkpointopenasync,
  2382. sizeof (struct req_lib_ckpt_checkpointopen));
  2383. req_exec_ckpt_checkpointopen.async_call = 1;
  2384. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2385. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2386. req_exec_ckpt_checkpointopen.fail_with_error = req_lib_ckpt_checkpointopenasync->fail_with_error;
  2387. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2388. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2389. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2390. return (0);
  2391. }
  2392. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  2393. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  2394. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2395. struct iovec iovecs[2];
  2396. struct saCkptCheckpoint *checkpoint;
  2397. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2398. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2399. if (checkpoint && (checkpoint->expired == 0)) {
  2400. req_exec_ckpt_checkpointclose.header.size =
  2401. sizeof (struct req_exec_ckpt_checkpointclose);
  2402. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  2403. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  2404. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2405. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2406. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2407. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2408. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  2409. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2410. }
  2411. }
  2412. else {
  2413. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2414. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2415. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2416. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2417. libais_send_response (conn_info,
  2418. &res_lib_ckpt_checkpointclose,
  2419. sizeof (struct res_lib_ckpt_checkpointclose));
  2420. }
  2421. return (0);
  2422. }
  2423. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  2424. {
  2425. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  2426. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2427. struct iovec iovecs[2];
  2428. req_exec_ckpt_checkpointunlink.header.size =
  2429. sizeof (struct req_exec_ckpt_checkpointunlink);
  2430. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  2431. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  2432. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2433. req_lib_ckpt_checkpointunlink,
  2434. sizeof (struct req_lib_ckpt_checkpointunlink));
  2435. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2436. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2437. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2438. return (0);
  2439. }
  2440. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  2441. {
  2442. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  2443. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2444. struct iovec iovecs[2];
  2445. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  2446. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2447. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2448. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2449. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2450. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2451. sizeof (SaNameT));
  2452. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2453. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2454. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2455. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2456. return (0);
  2457. }
  2458. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2459. {
  2460. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2461. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2462. struct saCkptCheckpoint *checkpoint;
  2463. SaAisErrorT error = SA_AIS_OK;
  2464. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2465. /*
  2466. * Make sure checkpoint is collocated and async update option
  2467. */
  2468. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2469. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2470. error = SA_AIS_ERR_BAD_OPERATION;
  2471. }
  2472. checkpoint->active_replica_set = 1;
  2473. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2474. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2475. res_lib_ckpt_activereplicaset.header.error = error;
  2476. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2477. sizeof (struct res_lib_ckpt_activereplicaset));
  2478. return (0);
  2479. }
  2480. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2481. {
  2482. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2483. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2484. struct saCkptCheckpoint *checkpoint;
  2485. int memoryUsed = 0;
  2486. int numberOfSections = 0;
  2487. struct list_head *checkpoint_section_list;
  2488. struct saCkptCheckpointSection *checkpointSection;
  2489. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2490. /*
  2491. * Count memory used by checkpoint sections
  2492. */
  2493. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2494. if (checkpoint && (checkpoint->expired == 0)) {
  2495. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2496. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2497. checkpoint_section_list = checkpoint_section_list->next) {
  2498. checkpointSection = list_entry (checkpoint_section_list,
  2499. struct saCkptCheckpointSection, list);
  2500. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2501. numberOfSections += 1;
  2502. }
  2503. /*
  2504. * Build checkpoint status get response
  2505. */
  2506. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2507. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2508. if (checkpoint->active_replica_set == 1) {
  2509. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2510. } else {
  2511. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2512. }
  2513. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2514. &checkpoint->checkpointCreationAttributes,
  2515. sizeof (SaCkptCheckpointCreationAttributesT));
  2516. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2517. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2518. }
  2519. else {
  2520. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2521. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2522. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2523. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2524. }
  2525. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2526. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2527. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2528. return (0);
  2529. }
  2530. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2531. {
  2532. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2533. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2534. struct iovec iovecs[2];
  2535. struct saCkptCheckpoint *checkpoint;
  2536. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2537. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2538. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2539. if (checkpoint && (checkpoint->expired == 0)) {
  2540. /*
  2541. * checkpoint opened is writeable mode so send message to cluster
  2542. */
  2543. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2544. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2545. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2546. req_lib_ckpt_sectioncreate,
  2547. sizeof (struct req_lib_ckpt_sectioncreate));
  2548. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2549. &req_lib_ckpt_sectioncreate->checkpointName,
  2550. sizeof (SaNameT));
  2551. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2552. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2553. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2554. /*
  2555. * Send section name and initial data in message
  2556. */
  2557. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2558. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2559. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2560. if (iovecs[1].iov_len) {
  2561. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2562. iovecs[1].iov_base,
  2563. iovecs[1].iov_len);
  2564. }
  2565. #ifdef DEBUG
  2566. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2567. iovecs[1].iov_len);
  2568. printf ("|\n");
  2569. { int i;
  2570. char *abc = iovecs[1].iov_base;
  2571. for (i = 0; i < 14;i++) {
  2572. printf ("%c ", abc[i]);
  2573. }
  2574. }
  2575. printf ("|\n");
  2576. #endif
  2577. if (iovecs[1].iov_len > 0) {
  2578. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2579. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2580. } else {
  2581. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2582. }
  2583. }
  2584. else {
  2585. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2586. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2587. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2588. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2589. libais_send_response (conn_info,
  2590. &res_lib_ckpt_sectioncreate,
  2591. sizeof (struct res_lib_ckpt_sectioncreate));
  2592. }
  2593. return (0);
  2594. }
  2595. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2596. {
  2597. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2598. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2599. struct iovec iovecs[2];
  2600. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2601. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2602. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2603. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2604. &req_lib_ckpt_sectiondelete->checkpointName,
  2605. sizeof (SaNameT));
  2606. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2607. req_lib_ckpt_sectiondelete,
  2608. sizeof (struct req_lib_ckpt_sectiondelete));
  2609. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2610. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2611. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2612. /*
  2613. * Send section name
  2614. */
  2615. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2616. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2617. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2618. if (iovecs[1].iov_len > 0) {
  2619. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2620. } else {
  2621. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2622. }
  2623. return (0);
  2624. }
  2625. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2626. {
  2627. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2628. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2629. struct iovec iovecs[2];
  2630. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2631. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2632. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2633. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2634. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2635. sizeof (SaNameT));
  2636. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2637. req_lib_ckpt_sectionexpirationtimeset,
  2638. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2639. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2640. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2641. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2642. /*
  2643. * Send section name
  2644. */
  2645. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2646. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2647. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2648. if (iovecs[1].iov_len > 0) {
  2649. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2650. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2651. } else {
  2652. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2653. }
  2654. return (0);
  2655. }
  2656. int write_inv = 0;
  2657. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2658. {
  2659. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2660. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2661. struct iovec iovecs[2];
  2662. struct saCkptCheckpoint *checkpoint;
  2663. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2664. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2665. req_lib_ckpt_sectionwrite->dataSize,
  2666. req_lib_ckpt_sectionwrite->dataOffset);
  2667. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2668. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2669. req_lib_ckpt_sectionwrite->idLen);
  2670. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2671. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2672. if (checkpoint && (checkpoint->expired == 0)) {
  2673. /*
  2674. * checkpoint opened is writeable mode so send message to cluster
  2675. */
  2676. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2677. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2678. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2679. req_lib_ckpt_sectionwrite,
  2680. sizeof (struct req_lib_ckpt_sectionwrite));
  2681. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2682. &req_lib_ckpt_sectionwrite->checkpointName,
  2683. sizeof (SaNameT));
  2684. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2685. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2686. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2687. /*
  2688. * Send section name and data to write in message
  2689. */
  2690. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2691. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2692. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2693. if (iovecs[1].iov_len > 0) {
  2694. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2695. } else {
  2696. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2697. }
  2698. }
  2699. else {
  2700. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  2701. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2702. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2703. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2704. libais_send_response (conn_info,
  2705. &res_lib_ckpt_sectionwrite,
  2706. sizeof (struct res_lib_ckpt_sectionwrite));
  2707. }
  2708. return (0);
  2709. }
  2710. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2711. {
  2712. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2713. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2714. struct iovec iovecs[2];
  2715. struct saCkptCheckpoint *checkpoint;
  2716. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2717. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2718. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2719. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2720. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->active_replica_set == 1)) {
  2721. /*
  2722. * checkpoint opened is writeable mode so send message to cluster
  2723. */
  2724. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2725. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2726. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2727. req_lib_ckpt_sectionoverwrite,
  2728. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2729. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2730. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2731. sizeof (SaNameT));
  2732. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2733. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2734. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2735. /*
  2736. * Send section name and data to overwrite in message
  2737. */
  2738. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2739. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2740. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2741. if (iovecs[1].iov_len > 0) {
  2742. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2743. } else {
  2744. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2745. }
  2746. }
  2747. else {
  2748. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  2749. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2750. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2751. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2752. libais_send_response (conn_info,
  2753. &res_lib_ckpt_sectionoverwrite,
  2754. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2755. }
  2756. return (0);
  2757. }
  2758. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2759. {
  2760. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2761. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2762. struct iovec iovecs[2];
  2763. struct saCkptCheckpoint *checkpoint;
  2764. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2765. SaAisErrorT error = SA_AIS_OK;
  2766. log_printf (LOG_LEVEL_DEBUG, "Section read from API fd %d\n", conn_info->fd);
  2767. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2768. if (checkpoint && (checkpoint->expired == 0) &&
  2769. checkpoint->active_replica_set &&
  2770. req_lib_ckpt_sectionread->dataSize <=
  2771. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2772. /*
  2773. * checkpoint opened is writeable mode so send message to cluster
  2774. */
  2775. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2776. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2777. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2778. req_lib_ckpt_sectionread,
  2779. sizeof (struct req_lib_ckpt_sectionread));
  2780. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2781. &req_lib_ckpt_sectionread->checkpointName,
  2782. sizeof (SaNameT));
  2783. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2784. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2785. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2786. /*
  2787. * Send section name and data to overwrite in message
  2788. */
  2789. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2790. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2791. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2792. if (iovecs[1].iov_len > 0) {
  2793. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2794. } else {
  2795. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2796. }
  2797. return (0); /* DO NOT REMOVE */
  2798. }
  2799. if (checkpoint) {
  2800. if (checkpoint->active_replica_set == 0) {
  2801. log_printf (LOG_LEVEL_DEBUG,
  2802. "sectionread - active replica not set.\n");
  2803. error = SA_AIS_ERR_NOT_EXIST;
  2804. }
  2805. if (req_lib_ckpt_sectionread->dataSize >
  2806. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2807. log_printf (LOG_LEVEL_DEBUG,
  2808. "sectionread - data size greater then max section size.\n");
  2809. error = SA_AIS_ERR_INVALID_PARAM;
  2810. }
  2811. } else {
  2812. log_printf (LOG_LEVEL_ERROR,
  2813. "sectionread - could not find checkpoint.\n");
  2814. }
  2815. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  2816. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2817. res_lib_ckpt_sectionread.header.error = error;
  2818. libais_send_response (conn_info,
  2819. &res_lib_ckpt_sectionread,
  2820. sizeof (struct res_lib_ckpt_sectionread));
  2821. return (0);
  2822. }
  2823. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2824. {
  2825. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)message;
  2826. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  2827. struct saCkptCheckpoint *checkpoint;
  2828. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronize->checkpointName);
  2829. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2830. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  2831. } else
  2832. if (checkpoint->active_replica_set == 1) {
  2833. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  2834. } else {
  2835. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  2836. }
  2837. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  2838. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  2839. libais_send_response (conn_info,
  2840. &res_lib_ckpt_checkpointsynchronize,
  2841. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  2842. return (0);
  2843. }
  2844. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2845. {
  2846. struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)message;
  2847. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  2848. struct saCkptCheckpoint *checkpoint;
  2849. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronizeasync->checkpointName);
  2850. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2851. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION;
  2852. } else
  2853. if (checkpoint->active_replica_set == 1) {
  2854. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK;
  2855. } else {
  2856. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST;
  2857. }
  2858. res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync);
  2859. res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  2860. res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation;
  2861. libais_send_response (conn_info,
  2862. &res_lib_ckpt_checkpointsynchronizeasync,
  2863. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  2864. libais_send_response (conn_info->conn_info_partner,
  2865. &res_lib_ckpt_checkpointsynchronizeasync,
  2866. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  2867. return (0);
  2868. }
  2869. static int message_handler_req_lib_ckpt_sectioniterationinitialize (struct conn_info *conn_info, void *message)
  2870. {
  2871. struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)message;
  2872. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  2873. struct saCkptCheckpoint *ckptCheckpoint;
  2874. struct saCkptCheckpointSection *ckptCheckpointSection;
  2875. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2876. struct saCkptSectionIterator *ckptSectionIterator;
  2877. struct list_head *checkpoint_section_list;
  2878. int addEntry = 0;
  2879. int iteratorEntries = 0;
  2880. SaErrorT error = SA_AIS_OK;
  2881. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2882. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2883. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationinitialize->checkpointName);
  2884. if (ckptCheckpoint == 0) {
  2885. error = SA_AIS_ERR_NOT_EXIST;
  2886. goto error_exit;
  2887. }
  2888. if (ckptCheckpoint->active_replica_set == 0) {
  2889. log_printf (LOG_LEVEL_NOTICE, "iterationinitialize: no active replica, returning error.\n");
  2890. error = SA_AIS_ERR_NOT_EXIST;
  2891. goto error_exit;
  2892. }
  2893. /*
  2894. * Iterate list of checkpoint sections
  2895. */
  2896. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2897. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2898. checkpoint_section_list = checkpoint_section_list->next) {
  2899. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2900. struct saCkptCheckpointSection, list);
  2901. addEntry = 1;
  2902. /*
  2903. * Item should be added to iterator list
  2904. */
  2905. if (addEntry) {
  2906. iteratorEntries += 1;
  2907. ckptSectionIteratorEntries =
  2908. realloc (ckptSectionIterator->sectionIteratorEntries,
  2909. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2910. if (ckptSectionIteratorEntries == 0) {
  2911. if (ckptSectionIterator->sectionIteratorEntries) {
  2912. free (ckptSectionIterator->sectionIteratorEntries);
  2913. }
  2914. error = SA_AIS_ERR_NO_MEMORY;
  2915. goto error_exit;
  2916. }
  2917. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2918. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2919. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2920. }
  2921. }
  2922. ckptSectionIterator->iteratorCount = iteratorEntries;
  2923. error_exit:
  2924. res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize);
  2925. res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2926. res_lib_ckpt_sectioniterationinitialize.header.error = error;
  2927. libais_send_response (conn_info, &res_lib_ckpt_sectioniterationinitialize,
  2928. sizeof (struct res_lib_ckpt_sectioniterationinitialize));
  2929. return (0);
  2930. }
  2931. static int message_handler_req_lib_ckpt_sectioniterationfinalize (struct conn_info *conn_info, void *message)
  2932. {
  2933. struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)message;
  2934. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  2935. struct saCkptCheckpoint *ckptCheckpoint;
  2936. SaErrorT error = SA_AIS_OK;
  2937. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationfinalize->checkpointName);
  2938. if (ckptCheckpoint == 0) {
  2939. error = SA_AIS_ERR_NOT_EXIST;
  2940. goto error_exit;
  2941. }
  2942. if (ckptCheckpoint->active_replica_set == 0) {
  2943. log_printf (LOG_LEVEL_NOTICE, "iterationfinalize: no active replica, returning error.\n");
  2944. error = SA_AIS_ERR_NOT_EXIST;
  2945. goto error_exit;
  2946. }
  2947. error_exit:
  2948. res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize);
  2949. res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  2950. res_lib_ckpt_sectioniterationfinalize.header.error = error;
  2951. libais_send_response (conn_info, &res_lib_ckpt_sectioniterationfinalize,
  2952. sizeof (struct res_lib_ckpt_sectioniterationfinalize));
  2953. return (0);
  2954. }
  2955. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2956. {
  2957. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2958. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2959. struct saCkptSectionIterator *ckptSectionIterator;
  2960. SaErrorT error = SA_AIS_OK;
  2961. int sectionIdSize = 0;
  2962. int iteratorPos = 0;
  2963. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2964. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2965. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2966. /*
  2967. * Find active iterator entry
  2968. */
  2969. for (;;) {
  2970. /*
  2971. * No more sections in iterator
  2972. */
  2973. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2974. error = SA_AIS_ERR_NO_SECTIONS;
  2975. goto error_exit;
  2976. }
  2977. /*
  2978. * active iterator entry
  2979. */
  2980. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2981. break;
  2982. }
  2983. ckptSectionIterator->iteratorPos += 1;
  2984. }
  2985. /*
  2986. * Prepare response to API
  2987. */
  2988. iteratorPos = ckptSectionIterator->iteratorPos;
  2989. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2990. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2991. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2992. sizeof (SaCkptSectionDescriptorT));
  2993. /*
  2994. * Get to next iterator entry
  2995. */
  2996. ckptSectionIterator->iteratorPos += 1;
  2997. error_exit:
  2998. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2999. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  3000. res_lib_ckpt_sectioniteratornext.header.error = error;
  3001. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  3002. sizeof (struct res_lib_ckpt_sectioniteratornext));
  3003. libais_send_response (conn_info,
  3004. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  3005. sectionIdSize);
  3006. return (0);
  3007. }