ckpt.c 130 KB

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