ckpt.c 135 KB

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