ckpt.c 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293
  1. /*
  2. * Copyright (c) 2003-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Authors: Steven Dake (sdake@mvista.com)
  8. * Muni Bajpai (muni.osdl@gmail.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <sys/types.h>
  37. #include <sys/uio.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include <sys/time.h>
  41. #include <netinet/in.h>
  42. #include <unistd.h>
  43. #include <fcntl.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <errno.h>
  47. #include <signal.h>
  48. #include <arpa/inet.h>
  49. #include "../include/saAis.h"
  50. #include "../include/saCkpt.h"
  51. #include "../include/mar_ckpt.h"
  52. #include "../include/ipc_ckpt.h"
  53. #include "../include/list.h"
  54. #include "../include/queue.h"
  55. #include "../include/hdb.h"
  56. #include "../lcr/lcr_comp.h"
  57. #include "service.h"
  58. #include "mempool.h"
  59. #include "tlist.h"
  60. #include "timer.h"
  61. #include "util.h"
  62. #include "main.h"
  63. #include "ipc.h"
  64. #include "totempg.h"
  65. #include "print.h"
  66. #define CKPT_MAX_SECTION_DATA_SEND (1024*400)
  67. enum ckpt_message_req_types {
  68. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN = 0,
  69. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE = 1,
  70. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK = 2,
  71. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET = 3,
  72. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE = 4,
  73. MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE = 5,
  74. MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE = 6,
  75. MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET = 7,
  76. MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE = 8,
  77. MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE = 9,
  78. MESSAGE_REQ_EXEC_CKPT_SECTIONREAD = 10,
  79. MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESTATE = 11,
  80. MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESECTION = 12
  81. };
  82. struct checkpoint_section {
  83. struct list_head list;
  84. mar_ckpt_section_descriptor_t section_descriptor;
  85. void *section_data;
  86. timer_handle expiration_timer;
  87. };
  88. struct ckpt_refcnt {
  89. int count;
  90. unsigned int nodeid;
  91. };
  92. typedef struct {
  93. int count __attribute__((aligned(8)));
  94. unsigned int nodeid __attribute__((aligned(8)));
  95. } mar_ckpt_refcnt_t;
  96. static inline void marshall_to_mar_ckpt_refcnt_t (
  97. mar_ckpt_refcnt_t *dest,
  98. struct ckpt_refcnt *src)
  99. {
  100. dest->count = src->count;
  101. dest->nodeid = src->nodeid;
  102. }
  103. static inline void marshall_from_mar_ckpt_refcnt_t (
  104. struct ckpt_refcnt *dest,
  105. mar_ckpt_refcnt_t *src)
  106. {
  107. dest->count = src->count;
  108. dest->nodeid = src->nodeid;
  109. }
  110. static inline void swab_mar_ckpt_refcnt_t (mar_ckpt_refcnt_t *to_swab)
  111. {
  112. swab_mar_int32_t (&to_swab->count);
  113. swab_mar_uint32_t (&to_swab->nodeid);
  114. }
  115. struct checkpoint {
  116. struct list_head list;
  117. mar_name_t name;
  118. mar_uint32_t ckpt_id;
  119. mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes;
  120. struct list_head sections_list_head;
  121. int referenceCount;
  122. int unlinked;
  123. timer_handle retention_timer;
  124. int expired;
  125. int active_replica_set;
  126. int sectionCount;
  127. struct ckpt_refcnt ckpt_refcnt[PROCESSOR_COUNT_MAX];
  128. };
  129. struct iteration_entry {
  130. int active;
  131. struct checkpoint_section *checkpoint_section;
  132. };
  133. struct iteration_instance {
  134. struct iteration_entry *iteration_entries;
  135. int iteration_entries_count;
  136. unsigned int iteration_pos;
  137. };
  138. struct ckpt_pd {
  139. struct list_head checkpoint_list;
  140. struct hdb_handle_database iteration_hdb;
  141. unsigned int iteration_pos;
  142. };
  143. struct ckpt_identifier {
  144. mar_name_t ckpt_name;
  145. mar_uint32_t ckpt_id;
  146. mar_ckpt_section_id_t ckpt_section_id;
  147. };
  148. static int ckpt_exec_init_fn (struct objdb_iface_ver0 *);
  149. static int ckpt_lib_exit_fn (void *conn);
  150. static int ckpt_lib_init_fn (void *conn);
  151. static void message_handler_req_lib_ckpt_checkpointopen (
  152. void *conn,
  153. void *msg);
  154. static void message_handler_req_lib_ckpt_checkpointclose (
  155. void *conn,
  156. void *msg);
  157. static void message_handler_req_lib_ckpt_checkpointunlink (
  158. void *conn,
  159. void *msg);
  160. static void message_handler_req_lib_ckpt_checkpointretentiondurationset (
  161. void *conn,
  162. void *msg);
  163. static void message_handler_req_lib_ckpt_activereplicaset (
  164. void *conn,
  165. void *msg);
  166. static void message_handler_req_lib_ckpt_checkpointstatusget (
  167. void *conn,
  168. void *msg);
  169. static void message_handler_req_lib_ckpt_sectioncreate (
  170. void *conn,
  171. void *msg);
  172. static void message_handler_req_lib_ckpt_sectiondelete (
  173. void *conn,
  174. void *msg);
  175. static void message_handler_req_lib_ckpt_sectionexpirationtimeset (
  176. void *conn,
  177. void *msg);
  178. static void message_handler_req_lib_ckpt_sectionwrite (
  179. void *conn,
  180. void *msg);
  181. static void message_handler_req_lib_ckpt_sectionoverwrite (
  182. void *conn,
  183. void *msg);
  184. static void message_handler_req_lib_ckpt_sectionread (
  185. void *conn,
  186. void *msg);
  187. static void message_handler_req_lib_ckpt_checkpointsynchronize (
  188. void *conn,
  189. void *msg);
  190. static void message_handler_req_lib_ckpt_checkpointsynchronizeasync (
  191. void *conn,
  192. void *msg);
  193. static void message_handler_req_lib_ckpt_sectioniterationinitialize (
  194. void *conn,
  195. void *msg);
  196. static void message_handler_req_lib_ckpt_sectioniterationfinalize (
  197. void *conn,
  198. void *msg);
  199. static void message_handler_req_lib_ckpt_sectioniterationnext (
  200. void *conn,
  201. void *msg);
  202. static void message_handler_req_exec_ckpt_checkpointopen (
  203. void *message,
  204. unsigned int nodeid);
  205. static void message_handler_req_exec_ckpt_synchronize_state (
  206. void *message,
  207. unsigned int nodeid);
  208. static void message_handler_req_exec_ckpt_synchronize_section (
  209. void *message,
  210. unsigned int nodeid);
  211. static void message_handler_req_exec_ckpt_checkpointclose (
  212. void *message,
  213. unsigned int nodeid);
  214. static void message_handler_req_exec_ckpt_checkpointunlink (
  215. void *message,
  216. unsigned int nodeid);
  217. static void message_handler_req_exec_ckpt_checkpointretentiondurationset (
  218. void *message,
  219. unsigned int nodeid);
  220. static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire (
  221. void *message,
  222. unsigned int nodeid);
  223. static void message_handler_req_exec_ckpt_sectioncreate (
  224. void *message,
  225. unsigned int nodeid);
  226. static void message_handler_req_exec_ckpt_sectiondelete (
  227. void *message,
  228. unsigned int nodeid);
  229. static void message_handler_req_exec_ckpt_sectionexpirationtimeset (
  230. void *message,
  231. unsigned int nodeid);
  232. static void message_handler_req_exec_ckpt_sectionwrite (
  233. void *message,
  234. unsigned int nodeid);
  235. static void message_handler_req_exec_ckpt_sectionoverwrite (
  236. void *message,
  237. unsigned int nodeid);
  238. static void message_handler_req_exec_ckpt_sectionread (
  239. void *message,
  240. unsigned int nodeid);
  241. static void exec_ckpt_checkpointopen_endian_convert (void *msg);
  242. static void exec_ckpt_checkpointclose_endian_convert (void *msg);
  243. static void exec_ckpt_checkpointunlink_endian_convert (void *msg);
  244. static void exec_ckpt_checkpointretentiondurationset_endian_convert (void *msg);
  245. static void exec_ckpt_checkpointretentiondurationexpire_endian_convert (void *msg);
  246. static void exec_ckpt_sectioncreate_endian_convert (void *msg);
  247. static void exec_ckpt_sectiondelete_endian_convert (void *msg);
  248. static void exec_ckpt_sectrionexpirationtimeset_endian_convert (void *msg);
  249. static void exec_ckpt_sectionwrite_endian_convert (void *msg);
  250. static void exec_ckpt_sectionoverwrite_endian_convert (void *msg);
  251. static void exec_ckpt_sectionread_endian_convert (void *msg);
  252. static void exec_ckpt_synchronize_state_endian_convert (void *msg);
  253. static void exec_ckpt_synchronize_section_endian_convert (void *msg);
  254. static void ckpt_recovery_activate (void);
  255. static void ckpt_recovery_initialize (void);
  256. static int ckpt_recovery_process (void);
  257. static void ckpt_recovery_finalize (void);
  258. static void ckpt_recovery_abort(void);
  259. static void ckpt_recovery_process_members_exit (
  260. unsigned int *left_list,
  261. int left_list_entries);
  262. static void ckpt_replace_localhost_ip (unsigned int *joined_list);
  263. void checkpoint_release (struct checkpoint *checkpoint);
  264. void timer_function_retention (void *data);
  265. unsigned int abstime_to_msec (mar_time_t time);
  266. void timer_function_section_expire (void *data);
  267. void clean_checkpoint_list(struct list_head* head);
  268. static int recovery_checkpoint_open(
  269. mar_name_t *checkpoint_name,
  270. mar_uint32_t ckpt_id,
  271. mar_ckpt_checkpoint_creation_attributes_t *ckptAttributes,
  272. struct ckpt_refcnt *ref_cnt);
  273. static int recovery_section_create (
  274. mar_ckpt_section_descriptor_t *section_descriptor,
  275. mar_name_t *checkpoint_name,
  276. mar_uint32_t ckpt_id,
  277. char* section_id);
  278. static int recovery_section_write(
  279. int section_id_len,
  280. char *section_id,
  281. mar_name_t *checkpoint_name,
  282. mar_uint32_t ckpt_id,
  283. void *new_data,
  284. mar_uint32_t data_offset,
  285. mar_uint32_t data_size);
  286. static void dump_fn(void);
  287. static int process_localhost_transition = 0;
  288. DECLARE_LIST_INIT(checkpoint_list_head);
  289. DECLARE_LIST_INIT(checkpoint_iteration_list_head);
  290. DECLARE_LIST_INIT(checkpoint_recovery_list_head);
  291. /* cluster wide synchronized checkpoint ID */
  292. static mar_uint32_t global_ckpt_id = 0;
  293. struct checkpoint_cleanup {
  294. struct list_head list;
  295. struct checkpoint checkpoint;
  296. };
  297. typedef enum {
  298. SYNCHRONY_STATE_STARTED,
  299. SYNCHRONY_STATE_ENDED
  300. }synchrony_state;
  301. static synchrony_state recovery_state = SYNCHRONY_STATE_ENDED;
  302. static struct list_head *recovery_ckpt_next = 0;
  303. static struct list_head *recovery_ckpt_section_next = 0;
  304. static int recovery_section_data_offset = 0;
  305. static int recovery_section_send_flag = 0;
  306. static int recovery_abort = 0;
  307. static struct memb_ring_id saved_ring_id;
  308. static void ckpt_confchg_fn (
  309. enum totem_configuration_type configuration_type,
  310. unsigned int *member_list, int member_list_entries,
  311. unsigned int *left_list, int left_list_entries,
  312. unsigned int *joined_list, int joined_list_entries,
  313. struct memb_ring_id *ring_id);
  314. /*
  315. * Executive Handler Definition
  316. */
  317. static struct openais_lib_handler ckpt_lib_service[] =
  318. {
  319. { /* 0 */
  320. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointopen,
  321. .response_size = sizeof (struct res_lib_ckpt_checkpointopen),
  322. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN,
  323. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  324. },
  325. { /* 1 */
  326. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointclose,
  327. .response_size = sizeof (struct res_lib_ckpt_checkpointclose),
  328. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE,
  329. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  330. },
  331. { /* 2 */
  332. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointunlink,
  333. .response_size = sizeof (struct res_lib_ckpt_checkpointunlink),
  334. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK,
  335. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  336. },
  337. { /* 3 */
  338. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset,
  339. .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset),
  340. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET,
  341. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  342. },
  343. { /* 4 */
  344. .lib_handler_fn = message_handler_req_lib_ckpt_activereplicaset,
  345. .response_size = sizeof (struct res_lib_ckpt_activereplicaset),
  346. .response_id = MESSAGE_RES_CKPT_ACTIVEREPLICASET,
  347. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  348. },
  349. { /* 5 */
  350. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget,
  351. .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget),
  352. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET,
  353. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  354. },
  355. { /* 6 */
  356. .lib_handler_fn = message_handler_req_lib_ckpt_sectioncreate,
  357. .response_size = sizeof (struct res_lib_ckpt_sectioncreate),
  358. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE,
  359. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  360. },
  361. { /* 7 */
  362. .lib_handler_fn = message_handler_req_lib_ckpt_sectiondelete,
  363. .response_size = sizeof (struct res_lib_ckpt_sectiondelete),
  364. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE,
  365. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  366. },
  367. { /* 8 */
  368. .lib_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset,
  369. .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset),
  370. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET,
  371. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  372. },
  373. { /* 9 */
  374. .lib_handler_fn = message_handler_req_lib_ckpt_sectionwrite,
  375. .response_size = sizeof (struct res_lib_ckpt_sectionwrite),
  376. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE,
  377. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  378. },
  379. { /* 10 */
  380. .lib_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite,
  381. .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite),
  382. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE,
  383. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  384. },
  385. { /* 11 */
  386. .lib_handler_fn = message_handler_req_lib_ckpt_sectionread,
  387. .response_size = sizeof (struct res_lib_ckpt_sectionread),
  388. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD,
  389. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  390. },
  391. { /* 12 */
  392. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize,
  393. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize),
  394. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE,
  395. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  396. },
  397. { /* 13 */
  398. .lib_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync,
  399. .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), /* TODO RESPONSE */
  400. .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC,
  401. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  402. },
  403. { /* 14 */
  404. .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationinitialize,
  405. .response_size = sizeof (struct res_lib_ckpt_sectioniterationinitialize),
  406. .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE,
  407. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  408. },
  409. { /* 15 */
  410. .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationfinalize,
  411. .response_size = sizeof (struct res_lib_ckpt_sectioniterationfinalize),
  412. .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE,
  413. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  414. },
  415. { /* 16 */
  416. .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationnext,
  417. .response_size = sizeof (struct res_lib_ckpt_sectioniterationnext),
  418. .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONNEXT,
  419. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  420. }
  421. };
  422. static struct openais_exec_handler ckpt_exec_service[] = {
  423. {
  424. .exec_handler_fn = message_handler_req_exec_ckpt_checkpointopen,
  425. .exec_endian_convert_fn = exec_ckpt_checkpointopen_endian_convert
  426. },
  427. {
  428. .exec_handler_fn = message_handler_req_exec_ckpt_checkpointclose,
  429. .exec_endian_convert_fn = exec_ckpt_checkpointclose_endian_convert
  430. },
  431. {
  432. .exec_handler_fn = message_handler_req_exec_ckpt_checkpointunlink,
  433. .exec_endian_convert_fn = exec_ckpt_checkpointunlink_endian_convert
  434. },
  435. {
  436. .exec_handler_fn = message_handler_req_exec_ckpt_checkpointretentiondurationset,
  437. .exec_endian_convert_fn = exec_ckpt_checkpointretentiondurationset_endian_convert
  438. },
  439. {
  440. .exec_handler_fn = message_handler_req_exec_ckpt_checkpointretentiondurationexpire,
  441. .exec_endian_convert_fn = exec_ckpt_checkpointretentiondurationexpire_endian_convert
  442. },
  443. {
  444. .exec_handler_fn = message_handler_req_exec_ckpt_sectioncreate,
  445. .exec_endian_convert_fn = exec_ckpt_sectioncreate_endian_convert
  446. },
  447. {
  448. .exec_handler_fn = message_handler_req_exec_ckpt_sectiondelete,
  449. .exec_endian_convert_fn = exec_ckpt_sectiondelete_endian_convert
  450. },
  451. {
  452. .exec_handler_fn = message_handler_req_exec_ckpt_sectionexpirationtimeset,
  453. .exec_endian_convert_fn = exec_ckpt_sectrionexpirationtimeset_endian_convert
  454. },
  455. {
  456. .exec_handler_fn = message_handler_req_exec_ckpt_sectionwrite,
  457. .exec_endian_convert_fn = exec_ckpt_sectionwrite_endian_convert
  458. },
  459. {
  460. .exec_handler_fn = message_handler_req_exec_ckpt_sectionoverwrite,
  461. .exec_endian_convert_fn = exec_ckpt_sectionoverwrite_endian_convert
  462. },
  463. {
  464. .exec_handler_fn = message_handler_req_exec_ckpt_sectionread,
  465. .exec_endian_convert_fn = exec_ckpt_sectionread_endian_convert
  466. },
  467. {
  468. .exec_handler_fn = message_handler_req_exec_ckpt_synchronize_state,
  469. .exec_endian_convert_fn = exec_ckpt_synchronize_state_endian_convert
  470. },
  471. {
  472. .exec_handler_fn = message_handler_req_exec_ckpt_synchronize_section,
  473. .exec_endian_convert_fn = exec_ckpt_synchronize_section_endian_convert
  474. }
  475. };
  476. struct openais_service_handler ckpt_service_handler = {
  477. .name = (unsigned char *)"openais checkpoint service B.01.01",
  478. .id = CKPT_SERVICE,
  479. .private_data_size = sizeof (struct ckpt_pd),
  480. .lib_init_fn = ckpt_lib_init_fn,
  481. .lib_exit_fn = ckpt_lib_exit_fn,
  482. .lib_service = ckpt_lib_service,
  483. .lib_service_count = sizeof (ckpt_lib_service) / sizeof (struct openais_lib_handler),
  484. .exec_init_fn = ckpt_exec_init_fn,
  485. .exec_dump_fn = dump_fn,
  486. .exec_service = ckpt_exec_service,
  487. .exec_service_count = sizeof (ckpt_exec_service) / sizeof (struct openais_exec_handler),
  488. .confchg_fn = ckpt_confchg_fn,
  489. .sync_init = ckpt_recovery_initialize,
  490. .sync_process = ckpt_recovery_process,
  491. .sync_activate = ckpt_recovery_activate,
  492. .sync_abort = ckpt_recovery_abort,
  493. };
  494. /*
  495. * Dynamic loader definition
  496. */
  497. static struct openais_service_handler *ckpt_get_handler_ver0 (void);
  498. static struct openais_service_handler_iface_ver0 ckpt_service_handler_iface = {
  499. .openais_get_service_handler_ver0 = ckpt_get_handler_ver0
  500. };
  501. static struct lcr_iface openais_ckpt_ver0[1] = {
  502. {
  503. .name = "openais_ckpt",
  504. .version = 0,
  505. .versions_replace = 0,
  506. .versions_replace_count = 0,
  507. .dependencies = 0,
  508. .dependency_count = 0,
  509. .constructor = NULL,
  510. .destructor = NULL,
  511. .interfaces = NULL
  512. }
  513. };
  514. static struct lcr_comp ckpt_comp_ver0 = {
  515. .iface_count = 1,
  516. .ifaces = openais_ckpt_ver0
  517. };
  518. static struct openais_service_handler *ckpt_get_handler_ver0 (void)
  519. {
  520. return (&ckpt_service_handler);
  521. }
  522. __attribute__ ((constructor)) static void register_this_component (void) {
  523. lcr_interfaces_set (&openais_ckpt_ver0[0], &ckpt_service_handler_iface);
  524. lcr_component_register (&ckpt_comp_ver0);
  525. }
  526. /*
  527. * All data types used for executive messages
  528. */
  529. struct req_exec_ckpt_checkpointopen {
  530. mar_req_header_t header __attribute__((aligned(8)));
  531. mar_message_source_t source __attribute__((aligned(8)));
  532. mar_name_t checkpoint_name __attribute__((aligned(8)));
  533. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  534. mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8)));
  535. mar_uint32_t checkpoint_creation_attributes_set __attribute__((aligned(8)));
  536. mar_ckpt_checkpoint_open_flags_t checkpoint_open_flags __attribute__((aligned(8)));
  537. mar_ckpt_checkpoint_handle_t checkpoint_handle __attribute__((aligned(8)));
  538. mar_invocation_t invocation __attribute__((aligned(8)));
  539. mar_uint32_t async_call __attribute__((aligned(8)));
  540. mar_uint32_t fail_with_error __attribute__((aligned(8)));
  541. };
  542. struct req_exec_ckpt_checkpointclose {
  543. mar_req_header_t header __attribute__((aligned(8)));
  544. mar_message_source_t source __attribute__((aligned(8)));
  545. mar_name_t checkpoint_name __attribute__((aligned(8)));
  546. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  547. };
  548. struct req_exec_ckpt_checkpointretentiondurationset {
  549. mar_req_header_t header __attribute__((aligned(8)));
  550. mar_message_source_t source __attribute__((aligned(8)));
  551. mar_name_t checkpoint_name __attribute__((aligned(8)));
  552. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  553. mar_time_t retention_duration __attribute__((aligned(8)));
  554. };
  555. struct req_exec_ckpt_checkpointretentiondurationexpire {
  556. mar_req_header_t header __attribute__((aligned(8)));
  557. mar_name_t checkpoint_name __attribute__((aligned(8)));
  558. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  559. };
  560. struct req_exec_ckpt_checkpointunlink {
  561. mar_req_header_t header __attribute__((aligned(8)));
  562. mar_message_source_t source __attribute__((aligned(8)));
  563. mar_name_t checkpoint_name __attribute__((aligned(8)));
  564. };
  565. struct req_exec_ckpt_sectioncreate {
  566. mar_req_header_t header __attribute__((aligned(8)));
  567. mar_message_source_t source __attribute__((aligned(8)));
  568. mar_name_t checkpoint_name __attribute__((aligned(8)));
  569. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  570. mar_uint32_t id_len __attribute__((aligned(8)));
  571. mar_time_t expiration_time __attribute__((aligned(8)));
  572. mar_uint32_t initial_data_size __attribute__((aligned(8)));
  573. };
  574. struct req_exec_ckpt_sectiondelete {
  575. mar_req_header_t header __attribute__((aligned(8)));
  576. mar_message_source_t source __attribute__((aligned(8)));
  577. mar_name_t checkpoint_name __attribute__((aligned(8)));
  578. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  579. mar_uint32_t id_len __attribute__((aligned(8)));
  580. };
  581. struct req_exec_ckpt_sectionexpirationtimeset {
  582. mar_req_header_t header __attribute__((aligned(8)));
  583. mar_message_source_t source __attribute__((aligned(8)));
  584. mar_name_t checkpoint_name __attribute__((aligned(8)));
  585. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  586. mar_uint32_t id_len __attribute__((aligned(8)));
  587. mar_time_t expiration_time __attribute__((aligned(8)));
  588. };
  589. struct req_exec_ckpt_sectionwrite {
  590. mar_req_header_t header __attribute__((aligned(8)));
  591. mar_message_source_t source __attribute__((aligned(8)));
  592. mar_name_t checkpoint_name __attribute__((aligned(8)));
  593. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  594. mar_uint32_t id_len __attribute__((aligned(8)));
  595. mar_offset_t data_offset __attribute__((aligned(8)));
  596. mar_offset_t data_size __attribute__((aligned(8)));
  597. };
  598. struct req_exec_ckpt_sectionoverwrite {
  599. mar_req_header_t header __attribute__((aligned(8)));
  600. mar_message_source_t source __attribute__((aligned(8)));
  601. mar_name_t checkpoint_name __attribute__((aligned(8)));
  602. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  603. mar_uint32_t id_len __attribute__((aligned(8)));
  604. mar_offset_t data_size __attribute__((aligned(8)));
  605. };
  606. struct req_exec_ckpt_sectionread {
  607. mar_req_header_t header __attribute__((aligned(8)));
  608. mar_message_source_t source __attribute__((aligned(8)));
  609. mar_name_t checkpoint_name __attribute__((aligned(8)));
  610. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  611. mar_uint32_t id_len __attribute__((aligned(8)));
  612. mar_offset_t data_offset __attribute__((aligned(8)));
  613. mar_offset_t data_size __attribute__((aligned(8)));
  614. };
  615. struct req_exec_ckpt_synchronize_state {
  616. mar_req_header_t header __attribute__((aligned(8)));
  617. struct memb_ring_id previous_ring_id __attribute__((aligned(8)));
  618. mar_name_t checkpoint_name __attribute__((aligned(8)));
  619. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  620. mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8)));
  621. mar_ckpt_section_descriptor_t section_descriptor __attribute__((aligned(8)));
  622. mar_uint32_t nodeid __attribute__((aligned(8)));
  623. mar_ckpt_refcnt_t ckpt_refcnt[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
  624. };
  625. struct req_exec_ckpt_synchronize_section {
  626. mar_req_header_t header __attribute__((aligned(8)));
  627. struct memb_ring_id previous_ring_id __attribute__((aligned(8)));
  628. mar_name_t checkpoint_name __attribute__((aligned(8)));
  629. mar_uint32_t ckpt_id __attribute__((aligned(8)));
  630. mar_uint32_t id_len __attribute__((aligned(8)));
  631. mar_offset_t data_offset __attribute__((aligned(8)));
  632. mar_offset_t data_size __attribute__((aligned(8)));
  633. };
  634. /*
  635. * Implementation
  636. */
  637. static int processor_index_set(
  638. unsigned int nodeid,
  639. struct ckpt_refcnt *ckpt_refcnt)
  640. {
  641. int i;
  642. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  643. if (ckpt_refcnt[i].nodeid == 0) {
  644. /*
  645. * If the source addresses do not match and this element
  646. * has no stored value then store the new value and
  647. * return the Index.
  648. */
  649. ckpt_refcnt[i].nodeid = nodeid;
  650. return i;
  651. }
  652. /*
  653. * If the source addresses match then this processor index
  654. * has already been set
  655. */
  656. else
  657. if (ckpt_refcnt[i].nodeid == nodeid) {
  658. return -1;
  659. }
  660. }
  661. /*
  662. * Could not Find an empty slot
  663. * to store the new Processor.
  664. */
  665. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  666. log_printf (LOG_LEVEL_ERROR,"Processor Set: Index %d has proc %s and count %d\n",
  667. i,
  668. totempg_ifaces_print (ckpt_refcnt[i].nodeid),
  669. ckpt_refcnt[i].count);
  670. }
  671. return -1;
  672. }
  673. static int processor_add (
  674. unsigned int nodeid,
  675. int count,
  676. struct ckpt_refcnt *ckpt_refcnt)
  677. {
  678. int i;
  679. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  680. if (ckpt_refcnt[i].nodeid == 0) {
  681. log_printf (LOG_LEVEL_DEBUG,"processor_add found empty slot to insert new item\n");
  682. ckpt_refcnt[i].nodeid = nodeid;
  683. ckpt_refcnt[i].count = count;
  684. return i;
  685. }
  686. /*Dont know how we missed this in the processor find but update this*/
  687. else
  688. if (ckpt_refcnt[i].nodeid == nodeid) {
  689. ckpt_refcnt[i].count += count;
  690. log_printf (LOG_LEVEL_DEBUG,"processor_add for existent proc. nodeid %s, New count = %d\n",
  691. totempg_ifaces_print (ckpt_refcnt[i].nodeid),
  692. ckpt_refcnt[i].count);
  693. return i;
  694. }
  695. }
  696. /*
  697. * Could not Find an empty slot
  698. * to store the new Processor.
  699. */
  700. log_printf (LOG_LEVEL_ERROR,"Processor Add Failed. Dumping Refcount Array\n");
  701. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  702. log_printf (LOG_LEVEL_ERROR,"Processor Add: Index %d has proc %s and count %d\n",
  703. i,
  704. totempg_ifaces_print (ckpt_refcnt[i].nodeid),
  705. ckpt_refcnt[i].count);
  706. }
  707. return -1;
  708. }
  709. static int processor_index_find(
  710. unsigned int nodeid,
  711. struct ckpt_refcnt *ckpt_refcnt)
  712. {
  713. int i;
  714. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  715. /*
  716. * If the source addresses match then return the index
  717. */
  718. if (ckpt_refcnt[i].nodeid == nodeid) {
  719. return i;
  720. }
  721. }
  722. /*
  723. * Could not Find the Processor
  724. */
  725. return -1;
  726. }
  727. static int ckpt_refcnt_total(struct ckpt_refcnt *ckpt_refcnt)
  728. {
  729. int i;
  730. int total = 0;
  731. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  732. total += ckpt_refcnt[i].count;
  733. }
  734. return total;
  735. }
  736. static void initialize_ckpt_refcnt_array (
  737. struct ckpt_refcnt *ckpt_refcnt)
  738. {
  739. memset((char*)ckpt_refcnt, 0,
  740. PROCESSOR_COUNT_MAX * sizeof(struct ckpt_refcnt));
  741. }
  742. static void merge_ckpt_refcnts (
  743. struct ckpt_refcnt *local,
  744. struct ckpt_refcnt *network)
  745. {
  746. int index,i;
  747. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  748. index = processor_index_find (local[i].nodeid, network);
  749. if (index == -1) { /*Could Not Find the Local Entry in the remote.Add to it*/
  750. log_printf (LOG_LEVEL_DEBUG,"calling processor_add for nodeid %s, count %d\n",
  751. totempg_ifaces_print (local[i].nodeid),
  752. local[i].count);
  753. index = processor_add (local[i].nodeid, local[i].count, network);
  754. if (index == -1) {
  755. log_printf(LOG_LEVEL_ERROR,
  756. "merge_ckpt_refcnts : could not add a new processor as the MAX limit of procs is reached.Exiting\n");
  757. assert(0);
  758. }
  759. }
  760. else {
  761. if (local[i].count == network[index].count) {
  762. /*Nothing to do here as the network is already up 2 date*/
  763. log_printf (LOG_LEVEL_DEBUG,"merge_ckpt_refcnts counts match, continue\n");
  764. continue;
  765. }
  766. else {
  767. /*Found a match for this proc in the Network choose the larger of the 2.*/
  768. network[index].count += local[i].count;
  769. log_printf (LOG_LEVEL_DEBUG,"setting count for nodeid %s = %d\n",
  770. totempg_ifaces_print (network[index].nodeid),
  771. network[index].count);
  772. }
  773. }
  774. }
  775. }
  776. static void ckpt_recovery_initialize (void)
  777. {
  778. struct list_head *checkpoint_list;
  779. struct list_head *checkpoint_section_list;
  780. struct checkpoint *checkpoint;
  781. struct checkpoint_section *section;
  782. struct checkpoint *savedCheckpoint;
  783. struct checkpoint_section *savedSection;
  784. if (recovery_abort) { /*Abort was called.*/
  785. return;
  786. }
  787. /*
  788. * Save off the existing Checkpoints to be used by ckpt_recovery_process
  789. */
  790. for (checkpoint_list = checkpoint_list_head.next;
  791. checkpoint_list != &checkpoint_list_head;
  792. checkpoint_list = checkpoint_list->next) {
  793. checkpoint = list_entry (checkpoint_list,
  794. struct checkpoint, list);
  795. if (checkpoint->referenceCount < 1) { /*defect 1192*/
  796. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_initialize checkpoint %s has referenceCount < 1 ignoring.\n",
  797. checkpoint->name.value);
  798. continue;
  799. }
  800. savedCheckpoint =
  801. (struct checkpoint *) malloc (sizeof(struct checkpoint));
  802. assert(savedCheckpoint);
  803. memcpy(savedCheckpoint, checkpoint, sizeof(struct checkpoint));
  804. list_init(&savedCheckpoint->list);
  805. list_add_tail(&savedCheckpoint->list,&checkpoint_recovery_list_head);
  806. list_init(&savedCheckpoint->sections_list_head);
  807. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  808. checkpoint_section_list != &checkpoint->sections_list_head;
  809. checkpoint_section_list = checkpoint_section_list->next) {
  810. section = list_entry (checkpoint_section_list,
  811. struct checkpoint_section, list);
  812. savedSection =
  813. (struct checkpoint_section *) malloc (sizeof(struct checkpoint_section));
  814. assert(savedSection);
  815. openais_timer_delete_data (section->expiration_timer);
  816. memcpy(savedSection, section, sizeof(struct checkpoint_section));
  817. list_init(&savedSection->list);
  818. list_add_tail(&savedSection->list,&savedCheckpoint->sections_list_head);
  819. }
  820. }
  821. if (list_empty (&checkpoint_recovery_list_head)) {
  822. return;
  823. }
  824. recovery_ckpt_next = checkpoint_recovery_list_head.next;
  825. savedCheckpoint = list_entry (recovery_ckpt_next,
  826. struct checkpoint, list);
  827. recovery_ckpt_section_next = savedCheckpoint->sections_list_head.next;
  828. }
  829. static int ckpt_recovery_process (void)
  830. {
  831. struct req_exec_ckpt_synchronize_state request_exec_sync_state;
  832. struct req_exec_ckpt_synchronize_section request_exec_sync_section;
  833. struct iovec iovecs[3];
  834. struct checkpoint *checkpoint;
  835. struct checkpoint_section *checkpoint_section;
  836. mar_size_t origSectionSize;
  837. mar_size_t newSectionSize;
  838. int res;
  839. unsigned int i;
  840. if (recovery_abort) { /*Abort was called.*/
  841. goto recovery_exit_clean;
  842. }
  843. /*So Initialize did not have any checkpoints to Synchronize*/
  844. if ((recovery_ckpt_next == 0) && (recovery_ckpt_section_next == 0)) {
  845. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process Nothing to Process ...\n");
  846. goto recovery_exit_clean;
  847. }
  848. /*
  849. * ALGORITHM :
  850. * 1.) extract the checkpoint if there.
  851. * 2.) If there is a checkpoint then there has to be a section
  852. * 3.) If the recovery_section_send_flag was not set in the previous
  853. * invocation that means we have to send out a sync_msg before
  854. * we send out the sections
  855. * 4.) Set the recovery_section_send_flag and send the sections.
  856. */
  857. while (1) { /*Go for as long as the oubound queue is not full*/
  858. if(recovery_ckpt_next != &checkpoint_recovery_list_head) {
  859. checkpoint = list_entry (recovery_ckpt_next,
  860. struct checkpoint, list);
  861. if (recovery_ckpt_section_next == 0) {
  862. recovery_ckpt_section_next = checkpoint->sections_list_head.next;
  863. }
  864. if (recovery_ckpt_section_next != &checkpoint->sections_list_head) {
  865. checkpoint_section = list_entry (recovery_ckpt_section_next,
  866. struct checkpoint_section, list);
  867. /*
  868. * None of the section data msgs have been sent
  869. * so lets start with sending the sync_msg
  870. */
  871. if (recovery_section_send_flag == 0) {
  872. if (checkpoint_section->section_descriptor.section_id.id) {
  873. log_printf (LOG_LEVEL_DEBUG, "New Sync State Message for ckpt = %s, section = %s.\n",
  874. checkpoint->name.value,
  875. (char *)checkpoint_section->section_descriptor.section_id.id);
  876. } else {
  877. log_printf (LOG_LEVEL_DEBUG, "New Sync State Message for ckpt = %s, section = default section.\n",
  878. checkpoint->name.value);
  879. }
  880. request_exec_sync_state.header.size = sizeof (struct req_exec_ckpt_synchronize_state);
  881. request_exec_sync_state.header.id =
  882. SERVICE_ID_MAKE (CKPT_SERVICE,
  883. MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESTATE);
  884. memcpy(&request_exec_sync_state.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  885. memcpy(&request_exec_sync_state.checkpoint_name,
  886. &checkpoint->name,
  887. sizeof(mar_name_t));
  888. memcpy(&request_exec_sync_state.checkpoint_creation_attributes,
  889. &checkpoint->checkpoint_creation_attributes,
  890. sizeof(mar_ckpt_checkpoint_creation_attributes_t));
  891. memcpy(&request_exec_sync_state.section_descriptor,
  892. &checkpoint_section->section_descriptor,
  893. sizeof(mar_ckpt_section_descriptor_t));
  894. request_exec_sync_state.ckpt_id = checkpoint->ckpt_id;
  895. request_exec_sync_state.nodeid = this_ip->nodeid;
  896. for (i = 0; i < PROCESSOR_COUNT_MAX; i++) {
  897. marshall_to_mar_ckpt_refcnt_t (
  898. &request_exec_sync_state.ckpt_refcnt[i],
  899. &checkpoint->ckpt_refcnt[i]);
  900. }
  901. request_exec_sync_state.section_descriptor.section_id.id = 0;
  902. log_printf (LOG_LEVEL_DEBUG, "New Sync State Message Values\n");
  903. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  904. if (request_exec_sync_state.ckpt_refcnt[i].nodeid) {
  905. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  906. i,
  907. totempg_ifaces_print (request_exec_sync_state.ckpt_refcnt[i].nodeid),
  908. request_exec_sync_state.ckpt_refcnt[i].count);
  909. }
  910. }
  911. iovecs[0].iov_base = (char *)&request_exec_sync_state;
  912. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_state);
  913. /*
  914. * Populate the Section ID
  915. */
  916. iovecs[1].iov_base = ((char*)checkpoint_section->section_descriptor.section_id.id);
  917. iovecs[1].iov_len = checkpoint_section->section_descriptor.section_id.id_len;
  918. request_exec_sync_state.header.size += iovecs[1].iov_len;
  919. /*
  920. * Check to see if we can queue the new message and if you can
  921. * then mcast the message else break and create callback.
  922. */
  923. res = totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED);
  924. if (res == 0) {
  925. log_printf (LOG_LEVEL_DEBUG, "Multicasted Sync State Message.\n");
  926. }
  927. else {
  928. log_printf (LOG_LEVEL_DEBUG, "Sync State Message Outbound Queue full need to Wait for Callback.\n");
  929. return (1);
  930. }
  931. recovery_section_send_flag = 1;
  932. }
  933. origSectionSize = checkpoint_section->section_descriptor.section_size;
  934. newSectionSize = 0;
  935. /*
  936. * Now Create SyncSection messsages in chunks of CKPT_MAX_SECTION_DATA_SEND or less
  937. */
  938. while (recovery_section_data_offset < origSectionSize) {
  939. /*
  940. * Send a Max of CKPT_MAX_SECTION_DATA_SEND of section data
  941. */
  942. if ((origSectionSize - recovery_section_data_offset) > CKPT_MAX_SECTION_DATA_SEND) {
  943. newSectionSize = CKPT_MAX_SECTION_DATA_SEND;
  944. }
  945. else {
  946. newSectionSize = (origSectionSize - recovery_section_data_offset);
  947. }
  948. /*
  949. * Create and save a new Sync Section message.
  950. */
  951. request_exec_sync_section.header.size = sizeof (struct req_exec_ckpt_synchronize_section);
  952. request_exec_sync_section.header.id =
  953. SERVICE_ID_MAKE (CKPT_SERVICE,
  954. MESSAGE_REQ_EXEC_CKPT_SYNCHRONIZESECTION);
  955. memcpy (&request_exec_sync_section.previous_ring_id, &saved_ring_id, sizeof(struct memb_ring_id));
  956. memcpy (&request_exec_sync_section.checkpoint_name, &checkpoint->name, sizeof(mar_name_t));
  957. request_exec_sync_section.id_len =
  958. checkpoint_section->section_descriptor.section_id.id_len;
  959. memcpy (&request_exec_sync_section.data_offset, &recovery_section_data_offset, sizeof(mar_uint32_t));
  960. memcpy (&request_exec_sync_section.data_size, &newSectionSize, sizeof(mar_uint32_t));
  961. if (checkpoint_section->section_descriptor.section_id.id) {
  962. log_printf (LOG_LEVEL_DEBUG, "New Sync Section Message for ckpt = %s, section = %s, Data size = %d.\n",
  963. checkpoint->name.value,
  964. (char *)checkpoint_section->section_descriptor.section_id.id,
  965. (int)newSectionSize);
  966. } else {
  967. log_printf (LOG_LEVEL_DEBUG, "New Sync Section Message for ckpt = %s, default section, Data size = %d.\n",
  968. checkpoint->name.value,
  969. (int)newSectionSize);
  970. }
  971. /*
  972. * Populate the Sync Section Request
  973. */
  974. iovecs[0].iov_base = (char *)&request_exec_sync_section;
  975. iovecs[0].iov_len = sizeof (struct req_exec_ckpt_synchronize_section);
  976. /*
  977. * Populate the Section ID
  978. */
  979. iovecs[1].iov_base = ((char*)checkpoint_section->section_descriptor.section_id.id);
  980. iovecs[1].iov_len = checkpoint_section->section_descriptor.section_id.id_len;
  981. request_exec_sync_section.header.size += iovecs[1].iov_len;
  982. /*
  983. * Populate the Section Data.
  984. */
  985. iovecs[2].iov_base = ((char*)checkpoint_section->section_data + recovery_section_data_offset);
  986. iovecs[2].iov_len = newSectionSize;
  987. request_exec_sync_section.header.size += iovecs[2].iov_len;
  988. request_exec_sync_section.ckpt_id = checkpoint->ckpt_id;
  989. /*
  990. * Check to see if we can queue the new message and if you can
  991. * then mcast the message else break and create callback.
  992. */
  993. res = totempg_groups_mcast_joined (openais_group_handle, iovecs, 3, TOTEMPG_AGREED);
  994. if (res == 0) {
  995. log_printf (LOG_LEVEL_DEBUG, "Multicasted Sync Section Message.\n");
  996. } else {
  997. log_printf (LOG_LEVEL_DEBUG, "Sync Section Message Outbound Queue full need to Wait for Callback.\n");
  998. return (1);
  999. }
  1000. recovery_section_data_offset += newSectionSize;
  1001. }
  1002. recovery_section_send_flag = 0;
  1003. recovery_section_data_offset = 0;
  1004. recovery_ckpt_section_next = recovery_ckpt_section_next->next;
  1005. continue;
  1006. }
  1007. else {
  1008. /*
  1009. * We have reached the end of a section List.
  1010. * Move to the next element in the ckpt list.
  1011. * Init the section ptr to 0 so it is re evaled
  1012. */
  1013. recovery_ckpt_next = recovery_ckpt_next->next;
  1014. recovery_ckpt_section_next = 0;
  1015. continue;
  1016. }
  1017. }
  1018. /*Should only be here at the end of the traversal of the ckpt list*/
  1019. ckpt_recovery_finalize();
  1020. recovery_exit_clean:
  1021. /*Re - Initialize the static's*/
  1022. recovery_ckpt_next = 0;
  1023. recovery_ckpt_section_next = 0;
  1024. recovery_section_data_offset = 0;
  1025. recovery_section_send_flag = 0;
  1026. recovery_abort = 0;
  1027. return (0);
  1028. }
  1029. }
  1030. static void ckpt_recovery_finalize (void)
  1031. {
  1032. struct list_head *checkpoint_list;
  1033. struct list_head *checkpoint_section_list;
  1034. struct checkpoint *checkpoint;
  1035. struct checkpoint_section *section;
  1036. struct ckpt_identifier *ckpt_id;
  1037. /*
  1038. * Remove All elements from old checkpoint
  1039. * list
  1040. */
  1041. checkpoint_list = checkpoint_list_head.next;
  1042. while (!list_empty(&checkpoint_list_head)) {
  1043. checkpoint = list_entry (checkpoint_list,
  1044. struct checkpoint, list);
  1045. checkpoint_section_list = checkpoint->sections_list_head.next;
  1046. while (!list_empty(&checkpoint->sections_list_head)) {
  1047. section = list_entry (checkpoint_section_list,
  1048. struct checkpoint_section, list);
  1049. list_del (&section->list);
  1050. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_finalize removed 0x%p.\n", section);
  1051. free (section);
  1052. checkpoint_section_list = checkpoint->sections_list_head.next;
  1053. }
  1054. list_del(&checkpoint->list);
  1055. free(checkpoint);
  1056. checkpoint_list = checkpoint_list_head.next;
  1057. }
  1058. /*
  1059. * Initialize the old list again.
  1060. */
  1061. list_init(&checkpoint_list_head);
  1062. /*
  1063. * Copy the contents of the new list_head into the old list head
  1064. */
  1065. checkpoint_recovery_list_head.prev->next = &checkpoint_list_head;
  1066. checkpoint_recovery_list_head.next->prev = &checkpoint_list_head;
  1067. memcpy(&checkpoint_list_head, &checkpoint_recovery_list_head, sizeof(struct list_head));
  1068. /*Timers might have been started before recovery happened .. restart them ..*/
  1069. for (checkpoint_list = checkpoint_list_head.next;
  1070. checkpoint_list != &checkpoint_list_head;
  1071. checkpoint_list = checkpoint_list->next) {
  1072. checkpoint = list_entry (checkpoint_list,
  1073. struct checkpoint, list);
  1074. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  1075. checkpoint_section_list != &checkpoint->sections_list_head;
  1076. checkpoint_section_list = checkpoint_section_list->next) {
  1077. section = list_entry (checkpoint_section_list,
  1078. struct checkpoint_section, list);
  1079. if (section->section_descriptor.expiration_time != SA_TIME_END) {
  1080. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1081. assert(ckpt_id);
  1082. memcpy(&ckpt_id->ckpt_name,&checkpoint->name,sizeof(mar_name_t));
  1083. memcpy(&ckpt_id->ckpt_section_id, &section->section_descriptor.section_id,sizeof(mar_ckpt_section_id_t));
  1084. openais_timer_add (
  1085. abstime_to_msec (section->section_descriptor.expiration_time),
  1086. ckpt_id,
  1087. timer_function_section_expire,
  1088. &section->expiration_timer);
  1089. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_initialize expiration timer = 0x%p\n",
  1090. section->expiration_timer);
  1091. }
  1092. }
  1093. }
  1094. /*
  1095. * Initialize the new list head for reuse.
  1096. */
  1097. list_init(&checkpoint_recovery_list_head);
  1098. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_finalize Done.\n");
  1099. }
  1100. static void ckpt_recovery_activate (void)
  1101. {
  1102. recovery_state = SYNCHRONY_STATE_ENDED;
  1103. return;
  1104. }
  1105. static void ckpt_recovery_abort (void)
  1106. {
  1107. recovery_abort = 1;
  1108. return;
  1109. }
  1110. static void ckpt_replace_localhost_ip (unsigned int *joined_list) {
  1111. struct list_head *checkpoint_list;
  1112. struct checkpoint *checkpoint;
  1113. unsigned int localhost_nodeid = 0;
  1114. int index;
  1115. assert(joined_list);
  1116. for (checkpoint_list = checkpoint_list_head.next;
  1117. checkpoint_list != &checkpoint_list_head;
  1118. checkpoint_list = checkpoint_list->next) {
  1119. checkpoint = list_entry (checkpoint_list,
  1120. struct checkpoint, list);
  1121. index = processor_index_find(localhost_nodeid, checkpoint->ckpt_refcnt);
  1122. if (index == -1) {
  1123. continue;
  1124. }
  1125. checkpoint->ckpt_refcnt[index].nodeid = joined_list[0];
  1126. log_printf (LOG_LEVEL_DEBUG, "Transitioning From Local Host replacing 127.0.0.1 with %x ...\n",
  1127. joined_list[0]);
  1128. }
  1129. process_localhost_transition = 0;
  1130. }
  1131. static void ckpt_recovery_process_members_exit (
  1132. unsigned int *left_list,
  1133. int left_list_entries)
  1134. {
  1135. struct list_head *checkpoint_list;
  1136. struct checkpoint *checkpoint;
  1137. unsigned int *member_nodeid;
  1138. unsigned int localhost_nodeid;
  1139. int index;
  1140. int i;
  1141. localhost_nodeid = 0; // TODO
  1142. if (left_list_entries == 0) {
  1143. return;
  1144. }
  1145. // TODO this is wrong
  1146. if ((left_list_entries == 1) &&
  1147. *left_list == localhost_nodeid) {
  1148. process_localhost_transition = 1;
  1149. return;
  1150. }
  1151. /*
  1152. * Iterate left_list_entries.
  1153. */
  1154. member_nodeid = left_list;
  1155. for (i = 0; i < left_list_entries; i++) {
  1156. checkpoint_list = checkpoint_list_head.next;
  1157. iterate_while_loop:
  1158. while (checkpoint_list != &checkpoint_list_head) {
  1159. checkpoint = list_entry (checkpoint_list,
  1160. struct checkpoint, list);
  1161. assert (checkpoint > 0);
  1162. index = processor_index_find(*member_nodeid,
  1163. checkpoint->ckpt_refcnt);
  1164. assert (-1 <= index);
  1165. assert (index < PROCESSOR_COUNT_MAX);
  1166. if (index < 0) {
  1167. checkpoint_list = checkpoint_list->next;
  1168. goto iterate_while_loop;
  1169. }
  1170. /*
  1171. * Decrement
  1172. *
  1173. */
  1174. if (checkpoint->referenceCount > 0) { /*defect 1192*/
  1175. checkpoint->referenceCount -= checkpoint->ckpt_refcnt[index].count;
  1176. log_printf (LOG_LEVEL_DEBUG, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  1177. checkpoint->name.value,checkpoint->referenceCount);
  1178. assert (checkpoint->referenceCount > 0);/*defect 1192*/
  1179. } else {
  1180. log_printf (LOG_LEVEL_ERROR, "ckpt_recovery_process_members_exit: refCount for %s = %d.\n",
  1181. checkpoint->name.value,checkpoint->referenceCount);
  1182. assert(0);
  1183. }
  1184. checkpoint->ckpt_refcnt[index].count = 0;
  1185. checkpoint->ckpt_refcnt[index].nodeid = 0;
  1186. checkpoint_list = checkpoint_list->next;
  1187. }
  1188. member_nodeid++;
  1189. }
  1190. clean_checkpoint_list(&checkpoint_list_head);
  1191. return;
  1192. }
  1193. void clean_checkpoint_list(struct list_head *head)
  1194. {
  1195. struct list_head *checkpoint_list;
  1196. struct checkpoint *checkpoint;
  1197. if (list_empty(head)) {
  1198. log_printf (LOG_LEVEL_NOTICE, "clean_checkpoint_list: List is empty \n");
  1199. return;
  1200. }
  1201. checkpoint_list = head->next;
  1202. while (checkpoint_list != head) {
  1203. checkpoint = list_entry (checkpoint_list,
  1204. struct checkpoint, list);
  1205. assert (checkpoint > 0);
  1206. /*
  1207. * If checkpoint has been unlinked and this is the last reference, delete it
  1208. */
  1209. if (checkpoint->unlinked && checkpoint->referenceCount == 1) { /*defect 1129*/
  1210. log_printf (LOG_LEVEL_NOTICE,"clean_checkpoint_list: deallocating checkpoint %s.\n",
  1211. checkpoint->name.value);
  1212. checkpoint_list = checkpoint_list->next;
  1213. checkpoint_release (checkpoint);
  1214. continue;
  1215. }
  1216. else if ((checkpoint->expired == 0) && (checkpoint->referenceCount == 1)) { /*defect 1192*/
  1217. log_printf (LOG_LEVEL_NOTICE, "clean_checkpoint_list: Starting timer to release checkpoint %s.\n",
  1218. checkpoint->name.value);
  1219. openais_timer_delete (checkpoint->retention_timer);
  1220. openais_timer_add (
  1221. checkpoint->checkpoint_creation_attributes.retention_duration / 1000000,
  1222. checkpoint,
  1223. timer_function_retention,
  1224. &checkpoint->retention_timer);
  1225. }
  1226. checkpoint_list = checkpoint_list->next;
  1227. }
  1228. }
  1229. static void ckpt_confchg_fn (
  1230. enum totem_configuration_type configuration_type,
  1231. unsigned int *member_list, int member_list_entries,
  1232. unsigned int *left_list, int left_list_entries,
  1233. unsigned int *joined_list, int joined_list_entries,
  1234. struct memb_ring_id *ring_id)
  1235. {
  1236. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  1237. if (recovery_state == SYNCHRONY_STATE_ENDED) {
  1238. memcpy (&saved_ring_id, ring_id, sizeof(struct memb_ring_id));
  1239. }
  1240. if (process_localhost_transition) {
  1241. ckpt_replace_localhost_ip (joined_list);
  1242. }
  1243. }
  1244. else if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  1245. ckpt_recovery_process_members_exit(left_list, left_list_entries);
  1246. recovery_state = SYNCHRONY_STATE_STARTED;
  1247. recovery_abort = 0;
  1248. }
  1249. }
  1250. static struct checkpoint *checkpoint_find (
  1251. mar_name_t *name,
  1252. mar_uint32_t ckpt_id)
  1253. {
  1254. struct list_head *checkpoint_list;
  1255. struct checkpoint *checkpoint;
  1256. for (checkpoint_list = checkpoint_list_head.next;
  1257. checkpoint_list != &checkpoint_list_head;
  1258. checkpoint_list = checkpoint_list->next) {
  1259. checkpoint = list_entry (checkpoint_list,
  1260. struct checkpoint, list);
  1261. if (mar_name_match (name, &checkpoint->name) &&
  1262. ckpt_id == checkpoint->ckpt_id) {
  1263. return (checkpoint);
  1264. }
  1265. }
  1266. return (0);
  1267. }
  1268. static struct checkpoint *checkpoint_find_linked (
  1269. mar_name_t *name)
  1270. {
  1271. struct list_head *checkpoint_list;
  1272. struct checkpoint *checkpoint;
  1273. for (checkpoint_list = checkpoint_list_head.next;
  1274. checkpoint_list != &checkpoint_list_head;
  1275. checkpoint_list = checkpoint_list->next) {
  1276. checkpoint = list_entry (checkpoint_list,
  1277. struct checkpoint, list);
  1278. if (mar_name_match (name, &checkpoint->name) &&
  1279. checkpoint->unlinked == 0) {
  1280. return (checkpoint);
  1281. }
  1282. }
  1283. return (0);
  1284. }
  1285. static void ckpt_checkpoint_remove_cleanup (
  1286. void *conn,
  1287. struct checkpoint *checkpoint)
  1288. {
  1289. struct list_head *list;
  1290. struct checkpoint_cleanup *checkpoint_cleanup;
  1291. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  1292. for (list = ckpt_pd->checkpoint_list.next;
  1293. list != &ckpt_pd->checkpoint_list;
  1294. list = list->next) {
  1295. checkpoint_cleanup = list_entry (list, struct checkpoint_cleanup, list);
  1296. if (mar_name_match (&checkpoint_cleanup->checkpoint.name, &checkpoint->name)
  1297. || (checkpoint_cleanup->checkpoint.name.length == 0)) {
  1298. list_del (&checkpoint_cleanup->list);
  1299. free (checkpoint_cleanup);
  1300. return;
  1301. }
  1302. }
  1303. }
  1304. static struct checkpoint_section *checkpoint_section_find (
  1305. struct checkpoint *checkpoint,
  1306. char *id,
  1307. int id_len)
  1308. {
  1309. struct list_head *checkpoint_section_list;
  1310. struct checkpoint_section *checkpoint_section;
  1311. if (id_len != 0) {
  1312. log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", (char*)id, id_len);
  1313. }
  1314. else {
  1315. log_printf (LOG_LEVEL_DEBUG, "Finding default checkpoint section\n");
  1316. }
  1317. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  1318. checkpoint_section_list != &checkpoint->sections_list_head;
  1319. checkpoint_section_list = checkpoint_section_list->next) {
  1320. checkpoint_section = list_entry (checkpoint_section_list,
  1321. struct checkpoint_section, list);
  1322. if (checkpoint_section->section_descriptor.section_id.id_len) {
  1323. log_printf (LOG_LEVEL_DEBUG, "Checking section id %*s\n",
  1324. checkpoint_section->section_descriptor.section_id.id_len,
  1325. checkpoint_section->section_descriptor.section_id.id);
  1326. }
  1327. else {
  1328. log_printf (LOG_LEVEL_DEBUG, "Checking default section id\n");
  1329. }
  1330. /*
  1331. All 3 of these values being checked MUST be = 0 to return
  1332. The default section. If even one of them is NON zero follow
  1333. the normal route
  1334. */
  1335. if ((id_len ||
  1336. checkpoint_section->section_descriptor.section_id.id ||
  1337. checkpoint_section->section_descriptor.section_id.id_len) == 0) {
  1338. log_printf (LOG_LEVEL_DEBUG, "Returning default section\n");
  1339. return (checkpoint_section);
  1340. }
  1341. if (checkpoint_section->section_descriptor.section_id.id_len == id_len &&
  1342. (checkpoint_section->section_descriptor.section_id.id)&&
  1343. (id)&&
  1344. (memcmp (checkpoint_section->section_descriptor.section_id.id,
  1345. id, id_len) == 0)) {
  1346. log_printf (LOG_LEVEL_DEBUG, "Returning section %s(0x%p)\n", checkpoint_section->section_descriptor.section_id.id,
  1347. checkpoint_section);
  1348. return (checkpoint_section);
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. /*
  1354. * defect 1112: We need to be able to call section release without
  1355. * having to to delete the timer as in the case of release being called
  1356. * from timer_function_section_expire where the expiry already takes care
  1357. * of the timer and its data
  1358. */
  1359. void checkpoint_section_and_associate_timer_cleanup (struct checkpoint_section *section,int deleteTimer)
  1360. {
  1361. list_del (&section->list);
  1362. if (section->section_descriptor.section_id.id) {
  1363. free (section->section_descriptor.section_id.id);
  1364. }
  1365. if (section->section_data) {
  1366. free (section->section_data);
  1367. }
  1368. /*
  1369. * defect 1112 on a section release we need to delete the timer AND its data or memory leaks
  1370. */
  1371. if (deleteTimer) {
  1372. openais_timer_delete_data (section->expiration_timer);
  1373. }
  1374. free (section);
  1375. }
  1376. void checkpoint_section_release (struct checkpoint_section *section)
  1377. {
  1378. log_printf (LOG_LEVEL_DEBUG, "checkpoint_section_release expiration timer = 0x%p\n", section->expiration_timer);
  1379. checkpoint_section_and_associate_timer_cleanup (section, 1);
  1380. }
  1381. void checkpoint_release (struct checkpoint *checkpoint)
  1382. {
  1383. struct list_head *list;
  1384. struct checkpoint_section *section;
  1385. openais_timer_delete (checkpoint->retention_timer);
  1386. /*
  1387. * Release all checkpoint sections for this checkpoint
  1388. */
  1389. for (list = checkpoint->sections_list_head.next;
  1390. list != &checkpoint->sections_list_head;) {
  1391. section = list_entry (list,
  1392. struct checkpoint_section, list);
  1393. list = list->next;
  1394. checkpoint->sectionCount -= 1;
  1395. checkpoint_section_release (section);
  1396. }
  1397. list_del (&checkpoint->list);
  1398. free (checkpoint);
  1399. }
  1400. int ckpt_checkpoint_close (struct checkpoint *checkpoint) {
  1401. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1402. struct iovec iovec;
  1403. if (checkpoint->expired == 1) {
  1404. return (0);
  1405. }
  1406. req_exec_ckpt_checkpointclose.header.size =
  1407. sizeof (struct req_exec_ckpt_checkpointclose);
  1408. req_exec_ckpt_checkpointclose.header.id =
  1409. SERVICE_ID_MAKE (CKPT_SERVICE,
  1410. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE);
  1411. memcpy (&req_exec_ckpt_checkpointclose.checkpoint_name,
  1412. &checkpoint->name, sizeof (mar_name_t));
  1413. req_exec_ckpt_checkpointclose.ckpt_id = checkpoint->ckpt_id;
  1414. memset (&req_exec_ckpt_checkpointclose.source, 0,
  1415. sizeof (mar_message_source_t));
  1416. iovec.iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1417. iovec.iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1418. if (totempg_groups_send_ok_joined (openais_group_handle, &iovec, 1)) {
  1419. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  1420. return (0);
  1421. }
  1422. return (-1);
  1423. }
  1424. static int ckpt_exec_init_fn (struct objdb_iface_ver0 *objdb)
  1425. {
  1426. log_init ("CKPT");
  1427. /*
  1428. * Initialize the saved ring ID.
  1429. */
  1430. saved_ring_id.seq = 0;
  1431. totemip_copy(&saved_ring_id.rep, this_ip);
  1432. return (0);
  1433. }
  1434. /*
  1435. * Endian conversion routines for executive message handlers
  1436. */
  1437. static void exec_ckpt_checkpointopen_endian_convert (void *msg)
  1438. {
  1439. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)msg;
  1440. swab_mar_req_header_t (&req_exec_ckpt_checkpointopen->header);
  1441. swab_mar_message_source_t (&req_exec_ckpt_checkpointopen->source);
  1442. swab_mar_name_t (&req_exec_ckpt_checkpointopen->checkpoint_name);
  1443. swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->ckpt_id);
  1444. swab_mar_ckpt_checkpoint_creation_attributes_t (&req_exec_ckpt_checkpointopen->checkpoint_creation_attributes);
  1445. swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->checkpoint_creation_attributes_set);
  1446. swab_mar_ckpt_checkpoint_open_flags_t (&req_exec_ckpt_checkpointopen->checkpoint_open_flags);
  1447. swab_mar_ckpt_checkpoint_handle_t (&req_exec_ckpt_checkpointopen->checkpoint_handle);
  1448. swab_mar_invocation_t (&req_exec_ckpt_checkpointopen->invocation);
  1449. swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->async_call);
  1450. swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->fail_with_error);
  1451. }
  1452. static void exec_ckpt_checkpointclose_endian_convert (void *msg)
  1453. {
  1454. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)msg;
  1455. swab_mar_req_header_t (&req_exec_ckpt_checkpointclose->header);
  1456. swab_mar_message_source_t (&req_exec_ckpt_checkpointclose->source);
  1457. swab_mar_name_t (&req_exec_ckpt_checkpointclose->checkpoint_name);
  1458. swab_mar_uint32_t (&req_exec_ckpt_checkpointclose->ckpt_id);
  1459. }
  1460. static void exec_ckpt_checkpointunlink_endian_convert (void *msg)
  1461. {
  1462. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)msg;
  1463. swab_mar_req_header_t (&req_exec_ckpt_checkpointunlink->header);
  1464. swab_mar_message_source_t (&req_exec_ckpt_checkpointunlink->source);
  1465. swab_mar_name_t (&req_exec_ckpt_checkpointunlink->checkpoint_name);
  1466. }
  1467. static void exec_ckpt_checkpointretentiondurationset_endian_convert (void *msg)
  1468. {
  1469. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)msg;
  1470. swab_mar_req_header_t (&req_exec_ckpt_checkpointretentiondurationset->header);
  1471. swab_mar_message_source_t (&req_exec_ckpt_checkpointretentiondurationset->source);
  1472. swab_mar_name_t (&req_exec_ckpt_checkpointretentiondurationset->checkpoint_name);
  1473. swab_mar_uint32_t (&req_exec_ckpt_checkpointretentiondurationset->ckpt_id);
  1474. swab_mar_time_t (&req_exec_ckpt_checkpointretentiondurationset->retention_duration);
  1475. }
  1476. static void exec_ckpt_checkpointretentiondurationexpire_endian_convert (void *msg)
  1477. {
  1478. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)msg;
  1479. swab_mar_req_header_t (&req_exec_ckpt_checkpointretentiondurationexpire->header);
  1480. swab_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name);
  1481. swab_mar_uint32_t (&req_exec_ckpt_checkpointretentiondurationexpire->ckpt_id);
  1482. }
  1483. static void exec_ckpt_sectioncreate_endian_convert (void *msg)
  1484. {
  1485. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)msg;
  1486. swab_mar_req_header_t (&req_exec_ckpt_sectioncreate->header);
  1487. swab_mar_message_source_t (&req_exec_ckpt_sectioncreate->source);
  1488. swab_mar_name_t (&req_exec_ckpt_sectioncreate->checkpoint_name);
  1489. swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->ckpt_id);
  1490. swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->id_len);
  1491. swab_mar_time_t (&req_exec_ckpt_sectioncreate->expiration_time);
  1492. swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->initial_data_size);
  1493. }
  1494. static void exec_ckpt_sectiondelete_endian_convert (void *msg)
  1495. {
  1496. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)msg;
  1497. swab_mar_req_header_t (&req_exec_ckpt_sectiondelete->header);
  1498. swab_mar_message_source_t (&req_exec_ckpt_sectiondelete->source);
  1499. swab_mar_name_t (&req_exec_ckpt_sectiondelete->checkpoint_name);
  1500. swab_mar_uint32_t (&req_exec_ckpt_sectiondelete->ckpt_id);
  1501. swab_mar_uint32_t (&req_exec_ckpt_sectiondelete->id_len);
  1502. }
  1503. static void exec_ckpt_sectrionexpirationtimeset_endian_convert (void *msg)
  1504. {
  1505. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)msg;
  1506. swab_mar_req_header_t (&req_exec_ckpt_sectionexpirationtimeset->header);
  1507. swab_mar_message_source_t (&req_exec_ckpt_sectionexpirationtimeset->source);
  1508. swab_mar_name_t (&req_exec_ckpt_sectionexpirationtimeset->checkpoint_name);
  1509. swab_mar_uint32_t (&req_exec_ckpt_sectionexpirationtimeset->ckpt_id);
  1510. swab_mar_uint32_t (&req_exec_ckpt_sectionexpirationtimeset->id_len);
  1511. swab_mar_time_t (&req_exec_ckpt_sectionexpirationtimeset->expiration_time);
  1512. }
  1513. static void exec_ckpt_sectionwrite_endian_convert (void *msg)
  1514. {
  1515. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)msg;
  1516. swab_mar_req_header_t (&req_exec_ckpt_sectionwrite->header);
  1517. swab_mar_message_source_t (&req_exec_ckpt_sectionwrite->source);
  1518. swab_mar_name_t (&req_exec_ckpt_sectionwrite->checkpoint_name);
  1519. swab_mar_uint32_t (&req_exec_ckpt_sectionwrite->ckpt_id);
  1520. swab_mar_uint32_t (&req_exec_ckpt_sectionwrite->id_len);
  1521. swab_mar_offset_t (&req_exec_ckpt_sectionwrite->data_size);
  1522. }
  1523. static void exec_ckpt_sectionoverwrite_endian_convert (void *msg)
  1524. {
  1525. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)msg;
  1526. swab_mar_req_header_t (&req_exec_ckpt_sectionoverwrite->header);
  1527. swab_mar_message_source_t (&req_exec_ckpt_sectionoverwrite->source);
  1528. swab_mar_name_t (&req_exec_ckpt_sectionoverwrite->checkpoint_name);
  1529. swab_mar_uint32_t (&req_exec_ckpt_sectionoverwrite->ckpt_id);
  1530. swab_mar_uint32_t (&req_exec_ckpt_sectionoverwrite->id_len);
  1531. swab_mar_offset_t (&req_exec_ckpt_sectionoverwrite->data_size);
  1532. }
  1533. static void exec_ckpt_sectionread_endian_convert (void *msg)
  1534. {
  1535. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)msg;
  1536. swab_mar_req_header_t (&req_exec_ckpt_sectionread->header);
  1537. swab_mar_message_source_t (&req_exec_ckpt_sectionread->source);
  1538. swab_mar_name_t (&req_exec_ckpt_sectionread->checkpoint_name);
  1539. swab_mar_uint32_t (&req_exec_ckpt_sectionread->ckpt_id);
  1540. swab_mar_uint32_t (&req_exec_ckpt_sectionread->id_len);
  1541. swab_mar_offset_t (&req_exec_ckpt_sectionread->data_offset);
  1542. swab_mar_offset_t (&req_exec_ckpt_sectionread->data_size);
  1543. }
  1544. static void exec_ckpt_synchronize_state_endian_convert (void *msg)
  1545. {
  1546. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_synchronize_state = (struct req_exec_ckpt_synchronize_state *)msg;
  1547. unsigned int i;
  1548. swab_mar_req_header_t (&req_exec_ckpt_synchronize_state->header);
  1549. // swab_mar_memb_ring_id_t (&req_exec_ckpt_synchronize_state->memb_ring_id);
  1550. swab_mar_name_t (&req_exec_ckpt_synchronize_state->checkpoint_name);
  1551. swab_mar_uint32_t (&req_exec_ckpt_synchronize_state->ckpt_id);
  1552. swab_mar_ckpt_checkpoint_creation_attributes_t (&req_exec_ckpt_synchronize_state->checkpoint_creation_attributes);
  1553. swab_mar_ckpt_section_descriptor_t (&req_exec_ckpt_synchronize_state->section_descriptor);
  1554. swab_mar_uint32_t (&req_exec_ckpt_synchronize_state->nodeid);
  1555. for (i = 0; i < PROCESSOR_COUNT_MAX; i++) {
  1556. swab_mar_ckpt_refcnt_t (&req_exec_ckpt_synchronize_state->ckpt_refcnt[i]);
  1557. }
  1558. }
  1559. static void exec_ckpt_synchronize_section_endian_convert (void *msg)
  1560. {
  1561. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_synchronize_section = (struct req_exec_ckpt_synchronize_section *)msg;
  1562. swab_mar_req_header_t (&req_exec_ckpt_synchronize_section->header);
  1563. // swab_mar_memb_ring_id_t (&req_exec_ckpt_synchronize_section->memb_ring_id);
  1564. swab_mar_name_t (&req_exec_ckpt_synchronize_section->checkpoint_name);
  1565. swab_mar_uint32_t (&req_exec_ckpt_synchronize_section->ckpt_id);
  1566. swab_mar_uint32_t (&req_exec_ckpt_synchronize_section->id_len);
  1567. swab_mar_offset_t (&req_exec_ckpt_synchronize_section->data_offset);
  1568. swab_mar_offset_t (&req_exec_ckpt_synchronize_section->data_size);
  1569. }
  1570. /*
  1571. * Executive message handlers
  1572. */
  1573. static void message_handler_req_exec_ckpt_checkpointopen (
  1574. void *message,
  1575. unsigned int nodeid)
  1576. {
  1577. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  1578. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  1579. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  1580. struct checkpoint *checkpoint = 0;
  1581. struct checkpoint_section *checkpoint_section = 0;
  1582. struct checkpoint_cleanup *checkpoint_cleanup = 0;
  1583. struct ckpt_pd *ckpt_pd;
  1584. SaAisErrorT error = SA_AIS_OK;
  1585. int proc_index;
  1586. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  1587. if (req_exec_ckpt_checkpointopen->fail_with_error != SA_AIS_OK) {
  1588. error = req_exec_ckpt_checkpointopen->fail_with_error;
  1589. goto error_exit;
  1590. }
  1591. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1592. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1593. if (checkpoint_cleanup == 0) {
  1594. error = SA_AIS_ERR_NO_MEMORY;
  1595. goto error_exit;
  1596. }
  1597. }
  1598. checkpoint = checkpoint_find_linked (&req_exec_ckpt_checkpointopen->checkpoint_name);
  1599. /*
  1600. * If checkpoint doesn't exist, create one
  1601. */
  1602. if (checkpoint == 0) {
  1603. if ((req_exec_ckpt_checkpointopen->checkpoint_open_flags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1604. error = SA_AIS_ERR_NOT_EXIST;
  1605. goto error_exit;
  1606. }
  1607. checkpoint = malloc (sizeof (struct checkpoint));
  1608. if (checkpoint == 0) {
  1609. error = SA_AIS_ERR_NO_MEMORY;
  1610. goto error_exit;
  1611. }
  1612. memcpy (&checkpoint->name,
  1613. &req_exec_ckpt_checkpointopen->checkpoint_name,
  1614. sizeof (mar_name_t));
  1615. memcpy (&checkpoint->checkpoint_creation_attributes,
  1616. &req_exec_ckpt_checkpointopen->checkpoint_creation_attributes,
  1617. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  1618. checkpoint->unlinked = 0;
  1619. list_init (&checkpoint->list);
  1620. list_init (&checkpoint->sections_list_head);
  1621. list_add (&checkpoint->list, &checkpoint_list_head);
  1622. checkpoint->referenceCount = 1;
  1623. checkpoint->retention_timer = 0;
  1624. checkpoint->expired = 0;
  1625. checkpoint->sectionCount = 0;
  1626. checkpoint->ckpt_id = global_ckpt_id++;
  1627. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1628. (checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1629. checkpoint->active_replica_set = 1;
  1630. } else
  1631. if ((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1632. checkpoint->active_replica_set = 1;
  1633. } else {
  1634. checkpoint->active_replica_set = 0;
  1635. }
  1636. initialize_ckpt_refcnt_array(checkpoint->ckpt_refcnt);
  1637. /*
  1638. * Create default section id if max_sections is 1
  1639. */
  1640. if (checkpoint->checkpoint_creation_attributes.max_sections == 1) {
  1641. /*
  1642. * Add in default checkpoint section
  1643. */
  1644. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  1645. if (checkpoint_section == 0) {
  1646. free (checkpoint);
  1647. error = SA_AIS_ERR_NO_MEMORY;
  1648. goto error_exit;
  1649. }
  1650. list_init (&checkpoint_section->list);
  1651. list_add (&checkpoint_section->list, &checkpoint->sections_list_head);
  1652. checkpoint_section->section_descriptor.section_id.id = 0;
  1653. checkpoint_section->section_descriptor.section_id.id_len = 0;
  1654. checkpoint_section->section_descriptor.expiration_time = SA_TIME_END;
  1655. checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID;
  1656. checkpoint_section->section_descriptor.last_update = 0; /*current time*/
  1657. checkpoint_section->section_descriptor.section_size = 0;
  1658. checkpoint_section->section_data = NULL;
  1659. checkpoint_section->expiration_timer = 0;
  1660. }
  1661. } else {
  1662. if (req_exec_ckpt_checkpointopen->checkpoint_creation_attributes_set &&
  1663. memcmp (&checkpoint->checkpoint_creation_attributes,
  1664. &req_exec_ckpt_checkpointopen->checkpoint_creation_attributes,
  1665. sizeof (mar_ckpt_checkpoint_creation_attributes_t)) != 0) {
  1666. error = SA_AIS_ERR_EXIST;
  1667. goto error_exit;
  1668. }
  1669. }
  1670. assert (checkpoint->unlinked == 0);
  1671. /*
  1672. * Setup connection information and mark checkpoint as referenced
  1673. */
  1674. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", checkpoint);
  1675. checkpoint->referenceCount += 1;
  1676. /*
  1677. * Add the connection reference information to the Checkpoint to be
  1678. * sent out later as a part of the sync process.
  1679. *
  1680. */
  1681. proc_index = processor_index_find(nodeid,checkpoint->ckpt_refcnt);
  1682. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1683. proc_index = processor_index_set(nodeid,checkpoint->ckpt_refcnt);
  1684. }
  1685. if (proc_index != -1 ) {
  1686. checkpoint->ckpt_refcnt[proc_index].nodeid = nodeid;
  1687. checkpoint->ckpt_refcnt[proc_index].count++;
  1688. }
  1689. else {
  1690. log_printf (LOG_LEVEL_ERROR,
  1691. "MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1692. checkpoint);
  1693. }
  1694. /*
  1695. * Reset retention duration since this checkpoint was just opened
  1696. */
  1697. openais_timer_delete (checkpoint->retention_timer);
  1698. checkpoint->retention_timer = 0;
  1699. /*
  1700. * Send error result to CKPT library
  1701. */
  1702. error_exit:
  1703. /*
  1704. * If this node was the source of the message, respond to this node
  1705. */
  1706. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1707. /*
  1708. * If its an async call respond with the invocation and handle
  1709. */
  1710. if (req_exec_ckpt_checkpointopen->async_call) {
  1711. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1712. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1713. res_lib_ckpt_checkpointopenasync.header.error = error;
  1714. res_lib_ckpt_checkpointopenasync.checkpoint_handle = req_exec_ckpt_checkpointopen->checkpoint_handle;
  1715. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1716. if (error == SA_AIS_OK) {
  1717. res_lib_ckpt_checkpointopenasync.ckpt_id = checkpoint->ckpt_id;
  1718. }
  1719. openais_conn_send_response (
  1720. req_exec_ckpt_checkpointopen->source.conn,
  1721. &res_lib_ckpt_checkpointopenasync,
  1722. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1723. openais_conn_send_response (
  1724. openais_conn_partner_get (req_exec_ckpt_checkpointopen->source.conn),
  1725. &res_lib_ckpt_checkpointopenasync,
  1726. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1727. } else {
  1728. /*
  1729. * otherwise respond with the normal checkpointopen response
  1730. */
  1731. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1732. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1733. if (error == SA_AIS_OK) {
  1734. res_lib_ckpt_checkpointopen.ckpt_id = checkpoint->ckpt_id;
  1735. }
  1736. res_lib_ckpt_checkpointopen.header.error = error;
  1737. openais_conn_send_response (
  1738. req_exec_ckpt_checkpointopen->source.conn,
  1739. &res_lib_ckpt_checkpointopen,
  1740. sizeof (struct res_lib_ckpt_checkpointopen));
  1741. }
  1742. /*
  1743. * This is the path taken when all goes well and this call was local
  1744. */
  1745. if (error == SA_AIS_OK) {
  1746. memcpy(&checkpoint_cleanup->checkpoint,checkpoint,sizeof(struct checkpoint));
  1747. ckpt_pd = openais_conn_private_data_get (req_exec_ckpt_checkpointopen->source.conn);
  1748. list_add (&checkpoint_cleanup->list,
  1749. &ckpt_pd->checkpoint_list);
  1750. } else {
  1751. /*
  1752. * We allocated this in the hope of using it but an error occured
  1753. * so deallocate it.
  1754. */
  1755. free (checkpoint_cleanup);
  1756. }
  1757. }
  1758. }
  1759. static int recovery_checkpoint_open (
  1760. mar_name_t *checkpoint_name,
  1761. mar_uint32_t ckpt_id,
  1762. mar_ckpt_checkpoint_creation_attributes_t *ckptAttributes,
  1763. struct ckpt_refcnt *ref_cnt)
  1764. {
  1765. int i;
  1766. struct checkpoint *checkpoint = 0;
  1767. struct checkpoint_section *checkpoint_section = 0;
  1768. SaAisErrorT error = SA_AIS_OK;
  1769. log_printf (LOG_LEVEL_DEBUG, "recovery_checkpoint_open %s\n", checkpoint_name->value);
  1770. log_printf (LOG_LEVEL_DEBUG, "recovery_checkpoint_open refcnt Values\n");
  1771. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1772. if (ref_cnt[i].nodeid) {
  1773. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1774. i,
  1775. totempg_ifaces_print (ref_cnt[i].nodeid),
  1776. ref_cnt[i].count);
  1777. }
  1778. }
  1779. checkpoint = checkpoint_find (checkpoint_name, ckpt_id);
  1780. /*
  1781. * If checkpoint doesn't exist, create one
  1782. */
  1783. if (checkpoint == 0) {
  1784. log_printf (LOG_LEVEL_DEBUG, "recovery_checkpoint_open Allocating new Checkpoint %s\n", checkpoint_name->value);
  1785. checkpoint = malloc (sizeof (struct checkpoint));
  1786. if (checkpoint == 0) {
  1787. error = SA_AIS_ERR_NO_MEMORY;
  1788. goto error_exit;
  1789. }
  1790. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  1791. if (checkpoint_section == 0) {
  1792. free (checkpoint);
  1793. error = SA_AIS_ERR_NO_MEMORY;
  1794. goto error_exit;
  1795. }
  1796. memcpy (&checkpoint->name,
  1797. checkpoint_name,
  1798. sizeof (mar_name_t));
  1799. memcpy (&checkpoint->checkpoint_creation_attributes,
  1800. ckptAttributes,
  1801. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  1802. checkpoint->ckpt_id = ckpt_id;
  1803. /*
  1804. * TODO this is wrong - worry about unlinked value of checkpoint sync
  1805. */
  1806. checkpoint->unlinked = 0;
  1807. list_init (&checkpoint->list);
  1808. list_init (&checkpoint->sections_list_head);
  1809. list_add (&checkpoint->list, &checkpoint_list_head);
  1810. checkpoint->retention_timer = 0;
  1811. checkpoint->expired = 0;
  1812. /*
  1813. * Add in default checkpoint section
  1814. */
  1815. list_init (&checkpoint_section->list);
  1816. list_add (&checkpoint_section->list, &checkpoint->sections_list_head);
  1817. /*
  1818. * Default section id
  1819. */
  1820. checkpoint_section->section_descriptor.section_id.id = 0;
  1821. checkpoint_section->section_descriptor.section_id.id_len = 0;
  1822. checkpoint_section->section_descriptor.expiration_time = SA_TIME_END;
  1823. checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID;
  1824. checkpoint_section->section_descriptor.last_update = 0; /*current time*/
  1825. checkpoint_section->section_descriptor.section_size = strlen("Factory installed data\0")+1;
  1826. checkpoint_section->section_data = malloc(strlen("Factory installed data\0")+1);
  1827. assert(checkpoint_section->section_data);
  1828. memcpy(checkpoint_section->section_data, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1829. checkpoint_section->expiration_timer = 0;
  1830. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1831. (checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1832. checkpoint->active_replica_set = 1;
  1833. } else
  1834. if ((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1835. checkpoint->active_replica_set = 1;
  1836. } else {
  1837. checkpoint->active_replica_set = 0;
  1838. }
  1839. initialize_ckpt_refcnt_array(checkpoint->ckpt_refcnt);
  1840. }
  1841. else {
  1842. /*
  1843. * Setup connection information and mark checkpoint as referenced
  1844. */
  1845. log_printf (LOG_LEVEL_DEBUG, "recovery CHECKPOINT reopened is %p\n", checkpoint);
  1846. }
  1847. /* synchronize global_ckpt_id to max(ckpt_id,global_ckpt_id)+1 */
  1848. if (ckpt_id >= global_ckpt_id) {
  1849. global_ckpt_id = ckpt_id + 1;
  1850. }
  1851. /*CHECK to see if there are any existing ckpts*/
  1852. if ((checkpoint->ckpt_refcnt) && (ckpt_refcnt_total(checkpoint->ckpt_refcnt) > 0)) {
  1853. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcnts\n");
  1854. merge_ckpt_refcnts(checkpoint->ckpt_refcnt, ref_cnt);
  1855. }
  1856. else {
  1857. initialize_ckpt_refcnt_array(checkpoint->ckpt_refcnt);
  1858. }
  1859. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1860. /*
  1861. * The reason why we are adding 1 is because there is an assignment vis-a-via an increment in the
  1862. * the next line. Whether the ckpt was opened earlier or just now, the referenceCount is getting
  1863. * obliterated in the next line.
  1864. */
  1865. checkpoint->referenceCount = ckpt_refcnt_total(ref_cnt) + 1; /*defect 1192*/
  1866. log_printf (LOG_LEVEL_DEBUG, "OPEN checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1867. memcpy (checkpoint->ckpt_refcnt,
  1868. ref_cnt,
  1869. sizeof(struct ckpt_refcnt) * PROCESSOR_COUNT_MAX);
  1870. /*
  1871. * Reset retention duration since this checkpoint was just opened
  1872. */
  1873. openais_timer_delete (checkpoint->retention_timer);
  1874. checkpoint->retention_timer = 0;
  1875. /*
  1876. * Send error result to CKPT library
  1877. */
  1878. error_exit:
  1879. return (error);
  1880. }
  1881. static void message_handler_req_exec_ckpt_synchronize_state (
  1882. void *message,
  1883. unsigned int nodeid)
  1884. {
  1885. int retcode;
  1886. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1887. = (struct req_exec_ckpt_synchronize_state *)message;
  1888. struct ckpt_refcnt local_ckpt_refcnt[PROCESSOR_COUNT_MAX];
  1889. unsigned int i;
  1890. /*
  1891. * If the Incoming message's previous ring id == saved_ring_id
  1892. * Ignore because we have seen this message before.
  1893. */
  1894. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1895. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1896. return;
  1897. }
  1898. for (i = 0; i < PROCESSOR_COUNT_MAX; i++) {
  1899. marshall_from_mar_ckpt_refcnt_t (&local_ckpt_refcnt[i],
  1900. &req_exec_ckpt_sync_state->ckpt_refcnt[i]);
  1901. }
  1902. retcode = recovery_checkpoint_open (
  1903. &req_exec_ckpt_sync_state->checkpoint_name,
  1904. req_exec_ckpt_sync_state->ckpt_id,
  1905. &req_exec_ckpt_sync_state->checkpoint_creation_attributes,
  1906. local_ckpt_refcnt);
  1907. if (retcode != SA_AIS_OK) {
  1908. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state\n");
  1909. log_printf(LOG_LEVEL_DEBUG, "recovery_checkpoint_open returned %d\n",retcode);
  1910. }
  1911. retcode = recovery_section_create (
  1912. &req_exec_ckpt_sync_state->section_descriptor,
  1913. &req_exec_ckpt_sync_state->checkpoint_name,
  1914. req_exec_ckpt_sync_state->ckpt_id,
  1915. (char*)req_exec_ckpt_sync_state
  1916. + sizeof (struct req_exec_ckpt_synchronize_state));
  1917. if (retcode != SA_AIS_OK) {
  1918. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state\n");
  1919. log_printf(LOG_LEVEL_DEBUG, "recovery_section_create returned %d\n",retcode);
  1920. }
  1921. }
  1922. static void message_handler_req_exec_ckpt_synchronize_section (
  1923. void *message,
  1924. unsigned int nodeid)
  1925. {
  1926. int retcode;
  1927. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1928. = (struct req_exec_ckpt_synchronize_section *)message;
  1929. /*
  1930. * If the Incoming message's previous ring id == saved_ring_id
  1931. * Ignore because we have seen this message before.
  1932. */
  1933. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1934. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1935. return;
  1936. }
  1937. /*
  1938. * Write the contents of the section to the checkpoint section.
  1939. */
  1940. retcode = recovery_section_write(
  1941. req_exec_ckpt_sync_section->id_len,
  1942. (char*)req_exec_ckpt_sync_section +
  1943. sizeof (struct req_exec_ckpt_synchronize_section),
  1944. &req_exec_ckpt_sync_section->checkpoint_name,
  1945. req_exec_ckpt_sync_section->ckpt_id,
  1946. (char*)req_exec_ckpt_sync_section
  1947. + sizeof (struct req_exec_ckpt_synchronize_section)
  1948. + req_exec_ckpt_sync_section->id_len,
  1949. req_exec_ckpt_sync_section->data_offset,
  1950. req_exec_ckpt_sync_section->data_size);
  1951. if (retcode != SA_AIS_OK) {
  1952. log_printf(LOG_LEVEL_ERROR, "message_handler_req_exec_ckpt_synchronize_section\n");
  1953. log_printf(LOG_LEVEL_ERROR, "recovery_section_write returned %d\n",retcode);
  1954. }
  1955. }
  1956. unsigned int abstime_to_msec (mar_time_t time)
  1957. {
  1958. struct timeval tv;
  1959. unsigned long long curr_time;
  1960. unsigned long long msec_time;
  1961. gettimeofday (&tv, NULL);
  1962. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1963. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1964. msec_time = (((unsigned long long)time) / 1000000) -
  1965. (unsigned long long)curr_time;
  1966. return ((unsigned int)(msec_time));
  1967. }
  1968. void timer_function_section_expire (void *data)
  1969. {
  1970. struct checkpoint *checkpoint = 0;
  1971. struct checkpoint_section *checkpoint_section = 0;
  1972. struct ckpt_identifier *ckpt_id = 0;
  1973. ckpt_id = (struct ckpt_identifier *)data;
  1974. log_printf (LOG_LEVEL_DEBUG, "timer_function_section_expire data = 0x%p\n",data);
  1975. if (ckpt_id->ckpt_section_id.id_len && ckpt_id->ckpt_section_id.id) {
  1976. log_printf (LOG_LEVEL_DEBUG, "Attempting to expire section %s in ckpt %s\n",
  1977. ckpt_id->ckpt_section_id.id,
  1978. ckpt_id->ckpt_name.value);
  1979. }
  1980. else {
  1981. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire data incorect\n");
  1982. goto free_mem;
  1983. }
  1984. checkpoint = checkpoint_find (&ckpt_id->ckpt_name, ckpt_id->ckpt_id);
  1985. if (checkpoint == 0) {
  1986. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find ckpt %s\n",
  1987. ckpt_id->ckpt_name.value);
  1988. goto free_mem;
  1989. }
  1990. checkpoint_section = checkpoint_section_find (checkpoint,
  1991. (char *)ckpt_id->ckpt_section_id.id,
  1992. (int)ckpt_id->ckpt_section_id.id_len);
  1993. if (checkpoint_section == 0) {
  1994. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find section %s in ckpt %s\n",
  1995. ckpt_id->ckpt_section_id.id,
  1996. ckpt_id->ckpt_name.value);
  1997. goto free_mem;
  1998. }
  1999. log_printf (LOG_LEVEL_DEBUG, "Expiring section %s in ckpt %s\n",
  2000. ckpt_id->ckpt_section_id.id,
  2001. ckpt_id->ckpt_name.value);
  2002. checkpoint->sectionCount -= 1;
  2003. /*
  2004. * defect id 1112 "memory leak in checkpoint service" Dont try
  2005. * to delete the timer as the timer mechanism takes care of that.
  2006. * Just delete the data after this call
  2007. */
  2008. checkpoint_section_and_associate_timer_cleanup (checkpoint_section, 0);
  2009. free_mem :
  2010. free (ckpt_id);
  2011. }
  2012. void timer_function_retention (void *data)
  2013. {
  2014. struct checkpoint *checkpoint = (struct checkpoint *)data;
  2015. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  2016. struct iovec iovec;
  2017. checkpoint->retention_timer = 0;
  2018. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  2019. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  2020. req_exec_ckpt_checkpointretentiondurationexpire.header.id =
  2021. SERVICE_ID_MAKE (CKPT_SERVICE,
  2022. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE);
  2023. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpoint_name,
  2024. &checkpoint->name,
  2025. sizeof (mar_name_t));
  2026. req_exec_ckpt_checkpointretentiondurationexpire.ckpt_id =
  2027. checkpoint->ckpt_id;
  2028. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  2029. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  2030. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2031. }
  2032. static void message_handler_req_exec_ckpt_checkpointclose (
  2033. void *message,
  2034. unsigned int nodeid)
  2035. {
  2036. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  2037. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2038. struct checkpoint *checkpoint = 0;
  2039. SaAisErrorT error = SA_AIS_OK;
  2040. int proc_index;
  2041. int release_checkpoint = 0;
  2042. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n",
  2043. get_mar_name_t (&req_exec_ckpt_checkpointclose->checkpoint_name));
  2044. checkpoint = checkpoint_find (
  2045. &req_exec_ckpt_checkpointclose->checkpoint_name,
  2046. req_exec_ckpt_checkpointclose->ckpt_id);
  2047. if (checkpoint == 0) {
  2048. error = SA_AIS_ERR_NOT_EXIST;
  2049. goto error_exit;
  2050. }
  2051. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  2052. checkpoint->referenceCount--;
  2053. /*
  2054. * Modify the connection reference information to the Checkpoint to be
  2055. * sent out later as a part of the sync process.
  2056. */
  2057. proc_index = processor_index_find(nodeid, checkpoint->ckpt_refcnt);
  2058. if (proc_index != -1 ) {
  2059. checkpoint->ckpt_refcnt[proc_index].count--;
  2060. }
  2061. else {
  2062. log_printf (LOG_LEVEL_ERROR,
  2063. "Could Not find Processor Info %p info.\n",
  2064. checkpoint);
  2065. }
  2066. assert (checkpoint->referenceCount > 0); /*defect 1192*/
  2067. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  2068. checkpoint->referenceCount);
  2069. /*
  2070. * If checkpoint has been unlinked and this is the last reference, delete it
  2071. */
  2072. if (checkpoint->unlinked && checkpoint->referenceCount == 1) { /*defect 1192*/
  2073. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  2074. release_checkpoint = 1;
  2075. } else
  2076. if (checkpoint->referenceCount == 1) { /*defect 1192*/
  2077. openais_timer_add (
  2078. checkpoint->checkpoint_creation_attributes.retention_duration / 1000000,
  2079. checkpoint,
  2080. timer_function_retention,
  2081. &checkpoint->retention_timer);
  2082. }
  2083. error_exit:
  2084. /*
  2085. * Remove the checkpoint from my connections checkpoint list
  2086. */
  2087. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  2088. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2089. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2090. res_lib_ckpt_checkpointclose.header.error = error;
  2091. openais_conn_send_response (req_exec_ckpt_checkpointclose->source.conn,
  2092. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  2093. if (error == SA_AIS_OK) {
  2094. ckpt_checkpoint_remove_cleanup (
  2095. req_exec_ckpt_checkpointclose->source.conn,
  2096. checkpoint);
  2097. }
  2098. }
  2099. /*
  2100. * Release the checkpoint if instructed to do so.
  2101. */
  2102. if (error == SA_AIS_OK && release_checkpoint) {
  2103. checkpoint_release(checkpoint);
  2104. }
  2105. }
  2106. static void message_handler_req_exec_ckpt_checkpointunlink (
  2107. void *message,
  2108. unsigned int nodeid)
  2109. {
  2110. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  2111. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  2112. struct checkpoint *checkpoint = 0;
  2113. SaAisErrorT error = SA_AIS_OK;
  2114. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  2115. checkpoint = checkpoint_find_linked (
  2116. &req_exec_ckpt_checkpointunlink->checkpoint_name);
  2117. if (checkpoint == 0) {
  2118. error = SA_AIS_ERR_NOT_EXIST;
  2119. goto error_exit;
  2120. }
  2121. assert (checkpoint->unlinked == 0);
  2122. checkpoint->unlinked = 1;
  2123. /*
  2124. * Immediately delete entry if reference count is zero
  2125. */
  2126. if (checkpoint->referenceCount == 1) {
  2127. /*
  2128. * Remove retention timer since this checkpoint was unlinked and is no
  2129. * longer referenced
  2130. */
  2131. checkpoint_release (checkpoint);
  2132. }
  2133. error_exit:
  2134. /*
  2135. * If this node was the source of the message, respond to this node
  2136. */
  2137. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  2138. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  2139. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  2140. res_lib_ckpt_checkpointunlink.header.error = error;
  2141. openais_conn_send_response (
  2142. req_exec_ckpt_checkpointunlink->source.conn,
  2143. &res_lib_ckpt_checkpointunlink,
  2144. sizeof (struct res_lib_ckpt_checkpointunlink));
  2145. }
  2146. }
  2147. static void message_handler_req_exec_ckpt_checkpointretentiondurationset (
  2148. void *message,
  2149. unsigned int nodeid)
  2150. {
  2151. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  2152. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  2153. struct checkpoint *checkpoint;
  2154. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  2155. checkpoint = checkpoint_find (
  2156. &req_exec_ckpt_checkpointretentiondurationset->checkpoint_name,
  2157. req_exec_ckpt_checkpointretentiondurationset->ckpt_id);
  2158. if (checkpoint) {
  2159. log_printf (LOG_LEVEL_DEBUG, "Setting retention duration for checkpoint %s\n",
  2160. get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationset->checkpoint_name));
  2161. if (checkpoint->unlinked == 0) {
  2162. checkpoint->checkpoint_creation_attributes.retention_duration =
  2163. req_exec_ckpt_checkpointretentiondurationset->retention_duration;
  2164. if (checkpoint->expired == 0 && checkpoint->referenceCount == 1) { /*defect 1192*/
  2165. openais_timer_delete (checkpoint->retention_timer);
  2166. openais_timer_add (
  2167. checkpoint->checkpoint_creation_attributes.retention_duration / 1000000,
  2168. checkpoint,
  2169. timer_function_retention,
  2170. &checkpoint->retention_timer);
  2171. }
  2172. error = SA_AIS_OK;
  2173. }
  2174. }
  2175. /*
  2176. * Respond to library if this processor sent the duration set request
  2177. */
  2178. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  2179. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  2180. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  2181. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  2182. openais_conn_send_response (
  2183. req_exec_ckpt_checkpointretentiondurationset->source.conn,
  2184. &res_lib_ckpt_checkpointretentiondurationset,
  2185. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  2186. }
  2187. }
  2188. static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire (
  2189. void *message,
  2190. unsigned int nodeid)
  2191. {
  2192. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  2193. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2194. struct checkpoint *checkpoint;
  2195. struct iovec iovec;
  2196. checkpoint = checkpoint_find (
  2197. &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name,
  2198. req_exec_ckpt_checkpointretentiondurationexpire->ckpt_id);
  2199. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount == 1)) {
  2200. log_printf (LOG_LEVEL_DEBUG, "Expiring checkpoint %s\n",
  2201. get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name));
  2202. checkpoint->expired = 1;
  2203. req_exec_ckpt_checkpointunlink.header.size =
  2204. sizeof (struct req_exec_ckpt_checkpointunlink);
  2205. req_exec_ckpt_checkpointunlink.header.id =
  2206. SERVICE_ID_MAKE (CKPT_SERVICE,
  2207. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  2208. req_exec_ckpt_checkpointunlink.source.conn = 0;
  2209. req_exec_ckpt_checkpointunlink.source.nodeid = 0;
  2210. memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name,
  2211. &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name,
  2212. sizeof (mar_name_t));
  2213. iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2214. iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2215. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2216. }
  2217. }
  2218. static int recovery_section_create (
  2219. mar_ckpt_section_descriptor_t *section_descriptor,
  2220. mar_name_t *checkpoint_name,
  2221. mar_uint32_t ckpt_id,
  2222. char *section_id)
  2223. {
  2224. struct checkpoint *checkpoint;
  2225. struct checkpoint_section *checkpoint_section;
  2226. void *initial_data;
  2227. struct ckpt_identifier *ckpt_identifier = 0;
  2228. SaAisErrorT error = SA_AIS_OK;
  2229. void *section_id_new;
  2230. if ((int)section_descriptor->section_id.id_len) {
  2231. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create for checkpoint %s, section %s.\n",
  2232. checkpoint_name->value, section_id);
  2233. } else {
  2234. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create for checkpoint %s, default section.\n",
  2235. checkpoint_name->value);
  2236. }
  2237. checkpoint = checkpoint_find (checkpoint_name, ckpt_id);
  2238. if (checkpoint == 0) {
  2239. error = SA_AIS_ERR_NOT_EXIST;
  2240. goto error_exit;
  2241. }
  2242. /*
  2243. * Determine if user-specified checkpoint ID already exists
  2244. */
  2245. checkpoint_section = checkpoint_section_find (
  2246. checkpoint,
  2247. section_id,
  2248. (int)section_descriptor->section_id.id_len);
  2249. if (checkpoint_section) {
  2250. /*
  2251. * This use case is mostly for the default section and is not probable for any other
  2252. * sections.
  2253. */
  2254. if (section_descriptor->section_size
  2255. > checkpoint_section->section_descriptor.section_size) {
  2256. void *section_data_tmp;
  2257. log_printf (LOG_LEVEL_NOTICE,
  2258. "recovery_section_create reallocating data. Present Size: %d, New Size: %d\n",
  2259. (int)checkpoint_section->section_descriptor.section_size,
  2260. (int)section_descriptor->section_size);
  2261. section_data_tmp =
  2262. realloc (checkpoint_section->section_data, section_descriptor->section_size);
  2263. if (section_data_tmp == NULL) {
  2264. log_printf (LOG_LEVEL_ERROR,
  2265. "recovery_section_create section_data realloc returned NULL Calling error_exit.\n");
  2266. error = SA_AIS_ERR_NO_MEMORY;
  2267. checkpoint_section_release(checkpoint_section);
  2268. goto error_exit;
  2269. }
  2270. checkpoint_section->section_data = section_data_tmp;
  2271. checkpoint_section->section_descriptor.section_size = section_descriptor->section_size;
  2272. error = SA_AIS_OK;
  2273. }
  2274. else {
  2275. error = SA_AIS_ERR_EXIST;
  2276. }
  2277. goto error_exit;
  2278. }
  2279. /*
  2280. * Allocate checkpoint section
  2281. */
  2282. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  2283. if (checkpoint_section == 0) {
  2284. error = SA_AIS_ERR_NO_MEMORY;
  2285. goto error_exit;
  2286. }
  2287. /*
  2288. * Allocate checkpoint section data
  2289. */
  2290. initial_data = malloc (section_descriptor->section_size);
  2291. if (initial_data == 0) {
  2292. free (checkpoint_section);
  2293. error = SA_AIS_ERR_NO_MEMORY;
  2294. goto error_exit;
  2295. }
  2296. /*
  2297. * Allocate checkpoint section id
  2298. */
  2299. section_id_new = NULL;
  2300. if (section_descriptor->section_id.id_len) {
  2301. section_id_new = malloc ((int)section_descriptor->section_id.id_len);
  2302. if (section_id_new == 0) {
  2303. free (checkpoint_section);
  2304. free (initial_data);
  2305. error = SA_AIS_ERR_NO_MEMORY;
  2306. goto error_exit;
  2307. }
  2308. }
  2309. /*
  2310. * Copy checkpoint section ID and initialize data.
  2311. */
  2312. if (section_id) {
  2313. memcpy ((char*)section_id_new, (char*)section_id,
  2314. (int)section_descriptor->section_id.id_len);
  2315. }
  2316. memset (initial_data, 0, section_descriptor->section_size);
  2317. /*
  2318. * Configure checkpoint section
  2319. */
  2320. memcpy(&checkpoint_section->section_descriptor,
  2321. section_descriptor,
  2322. sizeof(mar_ckpt_section_descriptor_t));
  2323. checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID;
  2324. checkpoint_section->section_data = initial_data;
  2325. checkpoint_section->expiration_timer = 0;
  2326. checkpoint_section->section_descriptor.section_id.id = section_id_new;
  2327. if (section_descriptor->expiration_time != SA_TIME_END) {
  2328. ckpt_identifier = malloc (sizeof(struct ckpt_identifier));
  2329. assert(ckpt_identifier);
  2330. memcpy(&ckpt_identifier->ckpt_name, checkpoint_name,
  2331. sizeof(mar_name_t));
  2332. ckpt_identifier->ckpt_id = ckpt_id;
  2333. memcpy(&ckpt_identifier->ckpt_section_id,
  2334. &checkpoint_section->section_descriptor.section_id,
  2335. sizeof(mar_ckpt_section_id_t));
  2336. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  2337. ckpt_identifier->ckpt_section_id.id,
  2338. ckpt_identifier->ckpt_name.value);
  2339. openais_timer_add (
  2340. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2341. ckpt_identifier,
  2342. timer_function_section_expire,
  2343. &checkpoint_section->expiration_timer);
  2344. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create expiration timer = 0x%p\n",
  2345. checkpoint_section->expiration_timer);
  2346. }
  2347. /*
  2348. * Add checkpoint section to checkpoint
  2349. */
  2350. list_init (&checkpoint_section->list);
  2351. list_add (&checkpoint_section->list,
  2352. &checkpoint->sections_list_head);
  2353. error_exit:
  2354. return (error);
  2355. }
  2356. static void message_handler_req_exec_ckpt_sectioncreate (
  2357. void *message,
  2358. unsigned int nodeid)
  2359. {
  2360. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  2361. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2362. struct checkpoint *checkpoint;
  2363. struct checkpoint_section *checkpoint_section;
  2364. void *initial_data;
  2365. void *section_id;
  2366. struct ckpt_identifier *ckpt_id = 0;
  2367. SaAisErrorT error = SA_AIS_OK;
  2368. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  2369. checkpoint = checkpoint_find (
  2370. &req_exec_ckpt_sectioncreate->checkpoint_name,
  2371. req_exec_ckpt_sectioncreate->ckpt_id);
  2372. if (checkpoint == 0) {
  2373. error = SA_AIS_ERR_NOT_EXIST;
  2374. goto error_exit;
  2375. }
  2376. if (checkpoint->sectionCount == checkpoint->checkpoint_creation_attributes.max_sections) {
  2377. error = SA_AIS_ERR_NO_SPACE;
  2378. goto error_exit;
  2379. }
  2380. if (checkpoint->checkpoint_creation_attributes.max_sections == 1) {
  2381. error = SA_AIS_ERR_EXIST;
  2382. goto error_exit;
  2383. }
  2384. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2385. req_exec_ckpt_sectioncreate->initial_data_size) {
  2386. error = SA_AIS_ERR_INVALID_PARAM;
  2387. goto error_exit;
  2388. }
  2389. /*
  2390. * Determine if user-specified checkpoint section already exists
  2391. */
  2392. checkpoint_section = checkpoint_section_find (checkpoint,
  2393. ((char *)req_exec_ckpt_sectioncreate) +
  2394. sizeof (struct req_exec_ckpt_sectioncreate),
  2395. req_exec_ckpt_sectioncreate->id_len);
  2396. if (checkpoint_section) {
  2397. error = SA_AIS_ERR_EXIST;
  2398. goto error_exit;
  2399. }
  2400. /*
  2401. * Allocate checkpoint section
  2402. */
  2403. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  2404. if (checkpoint_section == 0) {
  2405. error = SA_AIS_ERR_NO_MEMORY;
  2406. goto error_exit;
  2407. }
  2408. /*
  2409. * Allocate checkpoint section data
  2410. */
  2411. initial_data = malloc (req_exec_ckpt_sectioncreate->initial_data_size);
  2412. if (initial_data == 0) {
  2413. free (checkpoint_section);
  2414. error = SA_AIS_ERR_NO_MEMORY;
  2415. goto error_exit;
  2416. }
  2417. /*
  2418. * Allocate checkpoint section id
  2419. */
  2420. section_id = malloc (req_exec_ckpt_sectioncreate->id_len + 1);
  2421. if (section_id == 0) {
  2422. free (checkpoint_section);
  2423. free (initial_data);
  2424. error = SA_AIS_ERR_NO_MEMORY;
  2425. goto error_exit;
  2426. }
  2427. /*
  2428. * Copy checkpoint section and section ID
  2429. */
  2430. memcpy (section_id,
  2431. ((char *)req_exec_ckpt_sectioncreate) +
  2432. sizeof (struct req_exec_ckpt_sectioncreate),
  2433. req_exec_ckpt_sectioncreate->id_len);
  2434. /*Must be null terminated if it already isn't*/
  2435. ((char*)(section_id))[req_exec_ckpt_sectioncreate->id_len] = '\0';
  2436. memcpy (initial_data,
  2437. ((char *)req_exec_ckpt_sectioncreate) +
  2438. sizeof (struct req_exec_ckpt_sectioncreate) +
  2439. req_exec_ckpt_sectioncreate->id_len,
  2440. req_exec_ckpt_sectioncreate->initial_data_size);
  2441. /*
  2442. * Configure checkpoint section
  2443. */
  2444. checkpoint_section->section_descriptor.section_id.id = section_id;
  2445. checkpoint_section->section_descriptor.section_id.id_len =
  2446. req_exec_ckpt_sectioncreate->id_len;
  2447. checkpoint_section->section_descriptor.section_size =
  2448. req_exec_ckpt_sectioncreate->initial_data_size;
  2449. checkpoint_section->section_descriptor.expiration_time =
  2450. req_exec_ckpt_sectioncreate->expiration_time;
  2451. checkpoint_section->section_descriptor.section_state =
  2452. SA_CKPT_SECTION_VALID;
  2453. checkpoint_section->section_descriptor.last_update = 0; /* TODO current time */
  2454. checkpoint_section->section_data = initial_data;
  2455. checkpoint_section->expiration_timer = 0;
  2456. if (req_exec_ckpt_sectioncreate->expiration_time != SA_TIME_END) {
  2457. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2458. assert(ckpt_id);
  2459. memcpy(&ckpt_id->ckpt_name,
  2460. &req_exec_ckpt_sectioncreate->checkpoint_name,
  2461. sizeof(mar_name_t));
  2462. ckpt_id->ckpt_id = req_exec_ckpt_sectioncreate->ckpt_id;
  2463. memcpy(&ckpt_id->ckpt_section_id,
  2464. &checkpoint_section->section_descriptor.section_id,
  2465. sizeof(mar_ckpt_section_id_t));
  2466. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  2467. ckpt_id->ckpt_section_id.id,
  2468. ckpt_id->ckpt_name.value);
  2469. openais_timer_add (
  2470. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2471. ckpt_id,
  2472. timer_function_section_expire,
  2473. &checkpoint_section->expiration_timer);
  2474. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionicreate expiration timer = 0x%p\n",
  2475. checkpoint_section->expiration_timer);
  2476. }
  2477. log_printf (LOG_LEVEL_DEBUG,
  2478. "message_handler_req_exec_ckpt_sectioncreate created section with id = %s, id_len = %d\n",
  2479. checkpoint_section->section_descriptor.section_id.id,
  2480. checkpoint_section->section_descriptor.section_id.id_len);
  2481. /*
  2482. * Add checkpoint section to checkpoint
  2483. */
  2484. list_init (&checkpoint_section->list);
  2485. list_add (&checkpoint_section->list,
  2486. &checkpoint->sections_list_head);
  2487. checkpoint->sectionCount += 1;
  2488. error_exit:
  2489. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  2490. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2491. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2492. res_lib_ckpt_sectioncreate.header.error = error;
  2493. openais_conn_send_response (req_exec_ckpt_sectioncreate->source.conn,
  2494. &res_lib_ckpt_sectioncreate,
  2495. sizeof (struct res_lib_ckpt_sectioncreate));
  2496. }
  2497. }
  2498. static void message_handler_req_exec_ckpt_sectiondelete (
  2499. void *message,
  2500. unsigned int nodeid)
  2501. {
  2502. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  2503. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  2504. struct checkpoint *checkpoint;
  2505. struct checkpoint_section *checkpoint_section;
  2506. SaAisErrorT error = SA_AIS_OK;
  2507. checkpoint = checkpoint_find (
  2508. &req_exec_ckpt_sectiondelete->checkpoint_name,
  2509. req_exec_ckpt_sectiondelete->ckpt_id);
  2510. if (checkpoint == 0) {
  2511. error = SA_AIS_ERR_NOT_EXIST;
  2512. goto error_exit;
  2513. }
  2514. if (checkpoint->active_replica_set == 0) {
  2515. log_printf (LOG_LEVEL_DEBUG, "sectiondelete: no active replica, returning error.\n");
  2516. error = SA_AIS_ERR_NOT_EXIST;
  2517. goto error_exit;
  2518. }
  2519. /*
  2520. * Determine if the user is trying to delete the default section
  2521. */
  2522. if (req_exec_ckpt_sectiondelete->id_len == 0) {
  2523. error = SA_AIS_ERR_INVALID_PARAM;
  2524. goto error_exit;
  2525. }
  2526. /*
  2527. * Find checkpoint section to be deleted
  2528. */
  2529. checkpoint_section = checkpoint_section_find (checkpoint,
  2530. ((char *)(req_exec_ckpt_sectiondelete) + sizeof (struct req_exec_ckpt_sectiondelete)),
  2531. req_exec_ckpt_sectiondelete->id_len);
  2532. if (checkpoint_section == 0) {
  2533. error = SA_AIS_ERR_NOT_EXIST;
  2534. goto error_exit;
  2535. }
  2536. /*
  2537. * Delete checkpoint section
  2538. */
  2539. checkpoint->sectionCount -= 1;
  2540. checkpoint_section_release (checkpoint_section);
  2541. /*
  2542. * return result to CKPT library
  2543. */
  2544. error_exit:
  2545. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  2546. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  2547. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  2548. res_lib_ckpt_sectiondelete.header.error = error;
  2549. openais_conn_send_response (
  2550. req_exec_ckpt_sectiondelete->source.conn,
  2551. &res_lib_ckpt_sectiondelete,
  2552. sizeof (struct res_lib_ckpt_sectiondelete));
  2553. }
  2554. }
  2555. static void message_handler_req_exec_ckpt_sectionexpirationtimeset (
  2556. void *message,
  2557. unsigned int nodeid)
  2558. {
  2559. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  2560. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  2561. struct checkpoint *checkpoint;
  2562. struct checkpoint_section *checkpoint_section;
  2563. struct ckpt_identifier *ckpt_id = 0;
  2564. SaAisErrorT error = SA_AIS_OK;
  2565. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiration time\n");
  2566. checkpoint = checkpoint_find (
  2567. &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name,
  2568. req_exec_ckpt_sectionexpirationtimeset->ckpt_id);
  2569. if (checkpoint == 0) {
  2570. error = SA_AIS_ERR_NOT_EXIST;
  2571. goto error_exit;
  2572. }
  2573. if (checkpoint->active_replica_set == 0) {
  2574. log_printf (LOG_LEVEL_DEBUG, "expirationset: no active replica, returning error.\n");
  2575. error = SA_AIS_ERR_NOT_EXIST;
  2576. goto error_exit;
  2577. }
  2578. /*
  2579. * Determine if the user is trying to set expiration time for the default section
  2580. */
  2581. if (req_exec_ckpt_sectionexpirationtimeset->id_len == 0) {
  2582. error = SA_AIS_ERR_INVALID_PARAM;
  2583. goto error_exit;
  2584. }
  2585. /*
  2586. * Find checkpoint section that expiration time should be set for
  2587. */
  2588. checkpoint_section = checkpoint_section_find (checkpoint,
  2589. ((char *)req_exec_ckpt_sectionexpirationtimeset) +
  2590. sizeof (struct req_exec_ckpt_sectionexpirationtimeset),
  2591. req_exec_ckpt_sectionexpirationtimeset->id_len);
  2592. if (checkpoint_section == 0) {
  2593. error = SA_AIS_ERR_NOT_EXIST;
  2594. goto error_exit;
  2595. }
  2596. checkpoint_section->section_descriptor.expiration_time =
  2597. req_exec_ckpt_sectionexpirationtimeset->expiration_time;
  2598. openais_timer_delete (checkpoint_section->expiration_timer);
  2599. checkpoint_section->expiration_timer = 0;
  2600. if (req_exec_ckpt_sectionexpirationtimeset->expiration_time != SA_TIME_END) {
  2601. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2602. assert(ckpt_id);
  2603. memcpy(&ckpt_id->ckpt_name,
  2604. &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name,
  2605. sizeof(mar_name_t));
  2606. ckpt_id->ckpt_id =
  2607. req_exec_ckpt_sectionexpirationtimeset->ckpt_id;
  2608. memcpy(&ckpt_id->ckpt_section_id,
  2609. &checkpoint_section->section_descriptor.section_id,
  2610. sizeof(mar_ckpt_section_id_t));
  2611. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%p\n",
  2612. ckpt_id->ckpt_section_id.id,
  2613. ckpt_id->ckpt_name.value,
  2614. ckpt_id);
  2615. openais_timer_add (
  2616. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2617. ckpt_id,
  2618. timer_function_section_expire,
  2619. &checkpoint_section->expiration_timer);
  2620. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%p\n",
  2621. checkpoint_section->expiration_timer);
  2622. }
  2623. error_exit:
  2624. if (message_source_is_local (&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2625. res_lib_ckpt_sectionexpirationtimeset.header.size =
  2626. sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2627. res_lib_ckpt_sectionexpirationtimeset.header.id =
  2628. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2629. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2630. openais_conn_send_response (
  2631. req_exec_ckpt_sectionexpirationtimeset->source.conn,
  2632. &res_lib_ckpt_sectionexpirationtimeset,
  2633. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2634. }
  2635. }
  2636. static int recovery_section_write(
  2637. int section_id_len,
  2638. char* section_id,
  2639. mar_name_t *checkpoint_name,
  2640. mar_uint32_t ckpt_id,
  2641. void *new_data,
  2642. mar_uint32_t data_offset,
  2643. mar_uint32_t data_size)
  2644. {
  2645. struct checkpoint *checkpoint;
  2646. struct checkpoint_section *checkpoint_section;
  2647. int size_required;
  2648. SaAisErrorT error = SA_AIS_OK;
  2649. char *sd;
  2650. log_printf (LOG_LEVEL_DEBUG, "recovery_section_write.\n");
  2651. checkpoint = checkpoint_find (checkpoint_name, ckpt_id);
  2652. if (checkpoint == 0) {
  2653. error = SA_AIS_ERR_NOT_EXIST;
  2654. goto error_exit;
  2655. }
  2656. /*
  2657. * Find checkpoint section to be written
  2658. */
  2659. checkpoint_section = checkpoint_section_find (checkpoint,
  2660. section_id, section_id_len);
  2661. if (checkpoint_section == 0) {
  2662. error = SA_AIS_ERR_NOT_EXIST;
  2663. goto error_exit;
  2664. }
  2665. /*
  2666. * If write would extend past end of section data, return error;
  2667. */
  2668. size_required = data_offset + data_size;
  2669. if (size_required > checkpoint_section->section_descriptor.section_size) {
  2670. log_printf (LOG_LEVEL_ERROR,
  2671. "recovery_section_write. write-past-end size_required:(%d), data_offset:(%d), data_size:(%d), sync-section-size:(%d)\n",
  2672. size_required, data_offset, data_size,
  2673. (int)checkpoint_section->section_descriptor.section_size);
  2674. error = SA_AIS_ERR_ACCESS;
  2675. goto error_exit;
  2676. }
  2677. /*
  2678. * Write checkpoint section to section data
  2679. */
  2680. if (data_size > 0) {
  2681. sd = (char *)checkpoint_section->section_data;
  2682. memcpy (&sd[data_offset], new_data, data_size);
  2683. }
  2684. error_exit:
  2685. return (error);
  2686. }
  2687. static void message_handler_req_exec_ckpt_sectionwrite (
  2688. void *message,
  2689. unsigned int nodeid)
  2690. {
  2691. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2692. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2693. struct checkpoint *checkpoint;
  2694. struct checkpoint_section *checkpoint_section = 0;
  2695. int size_required;
  2696. void *section_data;
  2697. SaAisErrorT error = SA_AIS_OK;
  2698. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2699. checkpoint = checkpoint_find (
  2700. &req_exec_ckpt_sectionwrite->checkpoint_name,
  2701. req_exec_ckpt_sectionwrite->ckpt_id);
  2702. if (checkpoint == 0) {
  2703. log_printf (LOG_LEVEL_ERROR, "checkpoint_find returned 0 Calling error_exit.\n");
  2704. error = SA_AIS_ERR_NOT_EXIST;
  2705. goto error_exit;
  2706. }
  2707. if (checkpoint->active_replica_set == 0) {
  2708. log_printf (LOG_LEVEL_DEBUG, "checkpointwrite: no active replica, returning error.\n");
  2709. error = SA_AIS_ERR_NOT_EXIST;
  2710. goto error_exit;
  2711. }
  2712. if (checkpoint->checkpoint_creation_attributes.max_section_size < req_exec_ckpt_sectionwrite->data_size) {
  2713. error = SA_AIS_ERR_INVALID_PARAM;
  2714. goto error_exit;
  2715. }
  2716. log_printf (LOG_LEVEL_DEBUG, "writing checkpoint section is %s\n",
  2717. ((char *)req_exec_ckpt_sectionwrite) +
  2718. sizeof (struct req_exec_ckpt_sectionwrite));
  2719. /*
  2720. * Find checkpoint section to be written
  2721. */
  2722. checkpoint_section = checkpoint_section_find (checkpoint,
  2723. ((char *)req_exec_ckpt_sectionwrite) +
  2724. sizeof (struct req_exec_ckpt_sectionwrite),
  2725. req_exec_ckpt_sectionwrite->id_len);
  2726. if (checkpoint_section == 0) {
  2727. if (req_exec_ckpt_sectionwrite->id_len == 0) {
  2728. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2729. }
  2730. else {
  2731. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2732. ((char *)req_exec_ckpt_sectionwrite) +
  2733. sizeof (struct req_exec_ckpt_sectionwrite));
  2734. }
  2735. error = SA_AIS_ERR_NOT_EXIST;
  2736. goto error_exit;
  2737. }
  2738. /*
  2739. * If write would extend past end of section data, enlarge section
  2740. */
  2741. size_required = req_exec_ckpt_sectionwrite->data_offset +
  2742. req_exec_ckpt_sectionwrite->data_size;
  2743. if (size_required > checkpoint_section->section_descriptor.section_size) {
  2744. section_data = realloc (checkpoint_section->section_data, size_required);
  2745. if (section_data == NULL) {
  2746. log_printf (LOG_LEVEL_ERROR, "section_data realloc returned NULL Calling error_exit.\n");
  2747. error = SA_AIS_ERR_NO_MEMORY;
  2748. goto error_exit;
  2749. }
  2750. /*
  2751. * Install new section data
  2752. */
  2753. checkpoint_section->section_data = section_data;
  2754. checkpoint_section->section_descriptor.section_size = size_required;
  2755. }
  2756. /*
  2757. * Write checkpoint section to section data
  2758. */
  2759. if (req_exec_ckpt_sectionwrite->data_size > 0) {
  2760. char *sd;
  2761. int *val;
  2762. val = checkpoint_section->section_data;
  2763. sd = (char *)checkpoint_section->section_data;
  2764. memcpy (&sd[req_exec_ckpt_sectionwrite->data_offset],
  2765. ((char *)req_exec_ckpt_sectionwrite) +
  2766. sizeof (struct req_exec_ckpt_sectionwrite) +
  2767. req_exec_ckpt_sectionwrite->id_len,
  2768. req_exec_ckpt_sectionwrite->data_size);
  2769. }
  2770. /*
  2771. * Write sectionwrite response to CKPT library
  2772. */
  2773. error_exit:
  2774. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2775. res_lib_ckpt_sectionwrite.header.size =
  2776. sizeof (struct res_lib_ckpt_sectionwrite);
  2777. res_lib_ckpt_sectionwrite.header.id =
  2778. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2779. res_lib_ckpt_sectionwrite.header.error = error;
  2780. openais_conn_send_response (
  2781. req_exec_ckpt_sectionwrite->source.conn,
  2782. &res_lib_ckpt_sectionwrite,
  2783. sizeof (struct res_lib_ckpt_sectionwrite));
  2784. }
  2785. }
  2786. static void message_handler_req_exec_ckpt_sectionoverwrite (
  2787. void *message,
  2788. unsigned int nodeid)
  2789. {
  2790. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2791. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2792. struct checkpoint *checkpoint;
  2793. struct checkpoint_section *checkpoint_section;
  2794. void *section_data;
  2795. SaAisErrorT error = SA_AIS_OK;
  2796. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2797. checkpoint = checkpoint_find (
  2798. &req_exec_ckpt_sectionoverwrite->checkpoint_name,
  2799. req_exec_ckpt_sectionoverwrite->ckpt_id);
  2800. if (checkpoint == 0) {
  2801. error = SA_AIS_ERR_NOT_EXIST;
  2802. goto error_exit;
  2803. }
  2804. if (checkpoint->active_replica_set == 0) {
  2805. log_printf (LOG_LEVEL_DEBUG, "sectionoverwrite: no active replica, returning error.\n");
  2806. error = SA_AIS_ERR_NOT_EXIST;
  2807. goto error_exit;
  2808. }
  2809. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2810. req_exec_ckpt_sectionoverwrite->data_size) {
  2811. error = SA_AIS_ERR_INVALID_PARAM;
  2812. goto error_exit;
  2813. }
  2814. /*
  2815. * Find checkpoint section to be overwritten
  2816. */
  2817. checkpoint_section = checkpoint_section_find (checkpoint,
  2818. ((char *)req_exec_ckpt_sectionoverwrite) +
  2819. sizeof (struct req_exec_ckpt_sectionoverwrite),
  2820. req_exec_ckpt_sectionoverwrite->id_len);
  2821. if (checkpoint_section == 0) {
  2822. error = SA_AIS_ERR_NOT_EXIST;
  2823. goto error_exit;
  2824. }
  2825. /*
  2826. * Allocate checkpoint section data
  2827. */
  2828. section_data = malloc (req_exec_ckpt_sectionoverwrite->data_size);
  2829. if (section_data == 0) {
  2830. error = SA_AIS_ERR_NO_MEMORY;
  2831. goto error_exit;
  2832. }
  2833. memcpy (section_data,
  2834. ((char *)req_exec_ckpt_sectionoverwrite) +
  2835. sizeof (struct req_exec_ckpt_sectionoverwrite) +
  2836. req_exec_ckpt_sectionoverwrite->id_len,
  2837. req_exec_ckpt_sectionoverwrite->data_size);
  2838. /*
  2839. * release old checkpoint section data
  2840. */
  2841. free (checkpoint_section->section_data);
  2842. /*
  2843. * Install overwritten checkpoint section data
  2844. */
  2845. checkpoint_section->section_descriptor.section_size =
  2846. req_exec_ckpt_sectionoverwrite->data_size;
  2847. checkpoint_section->section_descriptor.section_state =
  2848. SA_CKPT_SECTION_VALID;
  2849. /*
  2850. * TODO current time
  2851. */
  2852. checkpoint_section->section_descriptor.last_update = 0;
  2853. checkpoint_section->section_data = section_data;
  2854. /*
  2855. * return result to CKPT library
  2856. */
  2857. error_exit:
  2858. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2859. res_lib_ckpt_sectionoverwrite.header.size =
  2860. sizeof (struct res_lib_ckpt_sectionoverwrite);
  2861. res_lib_ckpt_sectionoverwrite.header.id =
  2862. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2863. res_lib_ckpt_sectionoverwrite.header.error = error;
  2864. openais_conn_send_response (
  2865. req_exec_ckpt_sectionoverwrite->source.conn,
  2866. &res_lib_ckpt_sectionoverwrite,
  2867. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2868. }
  2869. }
  2870. static void message_handler_req_exec_ckpt_sectionread (
  2871. void *message,
  2872. unsigned int nodeid)
  2873. {
  2874. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2875. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2876. struct checkpoint *checkpoint;
  2877. struct checkpoint_section *checkpoint_section = 0;
  2878. int section_size = 0;
  2879. SaAisErrorT error = SA_AIS_OK;
  2880. res_lib_ckpt_sectionread.data_read = 0;
  2881. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2882. checkpoint = checkpoint_find (
  2883. &req_exec_ckpt_sectionread->checkpoint_name,
  2884. req_exec_ckpt_sectionread->ckpt_id);
  2885. if (checkpoint == 0) {
  2886. error = SA_AIS_ERR_LIBRARY;
  2887. goto error_exit;
  2888. }
  2889. if (checkpoint->active_replica_set == 0) {
  2890. error = SA_AIS_ERR_NOT_EXIST;
  2891. goto error_exit;
  2892. }
  2893. /*
  2894. * Find checkpoint section to be read
  2895. */
  2896. checkpoint_section = checkpoint_section_find (checkpoint,
  2897. ((char *)req_exec_ckpt_sectionread) +
  2898. sizeof (struct req_exec_ckpt_sectionread),
  2899. req_exec_ckpt_sectionread->id_len);
  2900. if (checkpoint_section == 0) {
  2901. error = SA_AIS_ERR_NOT_EXIST;
  2902. goto error_exit;
  2903. }
  2904. /*
  2905. * If data size is greater then max section size, return INVALID_PARAM
  2906. */
  2907. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2908. req_exec_ckpt_sectionread->data_size) {
  2909. error = SA_AIS_ERR_INVALID_PARAM;
  2910. goto error_exit;
  2911. }
  2912. /*
  2913. * If data_offset is past end of data, return INVALID_PARAM
  2914. */
  2915. if (req_exec_ckpt_sectionread->data_offset > checkpoint_section->section_descriptor.section_size) {
  2916. error = SA_AIS_ERR_INVALID_PARAM;
  2917. goto error_exit;
  2918. }
  2919. /*
  2920. * Determine the section size
  2921. */
  2922. section_size = checkpoint_section->section_descriptor.section_size -
  2923. req_exec_ckpt_sectionread->data_offset;
  2924. /*
  2925. * If the library has less space available then can be sent from the
  2926. * section, reduce bytes sent to library to max requested
  2927. */
  2928. if (section_size > req_exec_ckpt_sectionread->data_size) {
  2929. section_size = req_exec_ckpt_sectionread->data_size;
  2930. }
  2931. /*
  2932. * Write read response to CKPT library
  2933. */
  2934. error_exit:
  2935. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2936. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + section_size;
  2937. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2938. res_lib_ckpt_sectionread.header.error = error;
  2939. if (section_size != 0) {
  2940. res_lib_ckpt_sectionread.data_read = section_size;
  2941. }
  2942. openais_conn_send_response (
  2943. req_exec_ckpt_sectionread->source.conn,
  2944. &res_lib_ckpt_sectionread,
  2945. sizeof (struct res_lib_ckpt_sectionread));
  2946. /*
  2947. * Write checkpoint to CKPT library section if section has data
  2948. */
  2949. if (error == SA_AIS_OK) {
  2950. char *sd;
  2951. sd = (char *)checkpoint_section->section_data;
  2952. openais_conn_send_response (
  2953. req_exec_ckpt_sectionread->source.conn,
  2954. &sd[req_exec_ckpt_sectionread->data_offset],
  2955. section_size);
  2956. }
  2957. }
  2958. }
  2959. static int ckpt_lib_init_fn (void *conn)
  2960. {
  2961. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2962. hdb_create (&ckpt_pd->iteration_hdb);
  2963. /* TODO
  2964. list_add (&ckpt_pd->sectionIterator.list,
  2965. &checkpoint_iteration_list_head);
  2966. */
  2967. list_init (&ckpt_pd->checkpoint_list);
  2968. return (0);
  2969. }
  2970. static int ckpt_lib_exit_fn (void *conn)
  2971. {
  2972. struct checkpoint_cleanup *checkpoint_cleanup;
  2973. struct list_head *cleanup_list;
  2974. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2975. log_printf (LOG_LEVEL_DEBUG, "checkpoint exit conn %p\n", conn);
  2976. /*
  2977. * close all checkpoints opened on this connection
  2978. */
  2979. cleanup_list = ckpt_pd->checkpoint_list.next;
  2980. while (!list_empty(&ckpt_pd->checkpoint_list)) {
  2981. checkpoint_cleanup = list_entry (cleanup_list,
  2982. struct checkpoint_cleanup, list);
  2983. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  2984. ckpt_checkpoint_close (
  2985. &checkpoint_cleanup->checkpoint);
  2986. }
  2987. list_del (&checkpoint_cleanup->list);
  2988. free (checkpoint_cleanup);
  2989. cleanup_list = ckpt_pd->checkpoint_list.next;
  2990. }
  2991. /* TODO
  2992. if (ckpt_pd->sectionIterator.sectionIteratorEntries) {
  2993. free (ckpt_pd->sectionIterator.sectionIteratorEntries);
  2994. }
  2995. list_del (&ckpt_pd->sectionIterator.list);
  2996. */
  2997. return (0);
  2998. }
  2999. static void message_handler_req_lib_ckpt_checkpointopen (
  3000. void *conn,
  3001. void *msg)
  3002. {
  3003. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)msg;
  3004. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  3005. struct iovec iovec;
  3006. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  3007. req_exec_ckpt_checkpointopen.header.size =
  3008. sizeof (struct req_exec_ckpt_checkpointopen);
  3009. req_exec_ckpt_checkpointopen.header.id =
  3010. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN);
  3011. message_source_set (&req_exec_ckpt_checkpointopen.source, conn);
  3012. memcpy (&req_exec_ckpt_checkpointopen.checkpoint_name,
  3013. &req_lib_ckpt_checkpointopen->checkpoint_name,
  3014. sizeof (mar_name_t));
  3015. req_exec_ckpt_checkpointopen.ckpt_id =
  3016. req_lib_ckpt_checkpointopen->ckpt_id;
  3017. memcpy (&req_exec_ckpt_checkpointopen.checkpoint_creation_attributes,
  3018. &req_lib_ckpt_checkpointopen->checkpoint_creation_attributes,
  3019. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  3020. req_exec_ckpt_checkpointopen.checkpoint_creation_attributes_set =
  3021. req_lib_ckpt_checkpointopen->checkpoint_creation_attributes_set;
  3022. req_exec_ckpt_checkpointopen.checkpoint_open_flags =
  3023. req_lib_ckpt_checkpointopen->checkpoint_open_flags;
  3024. req_exec_ckpt_checkpointopen.invocation =
  3025. req_lib_ckpt_checkpointopen->invocation;
  3026. req_exec_ckpt_checkpointopen.checkpoint_handle =
  3027. req_lib_ckpt_checkpointopen->checkpoint_handle;
  3028. req_exec_ckpt_checkpointopen.fail_with_error =
  3029. req_lib_ckpt_checkpointopen->fail_with_error;
  3030. req_exec_ckpt_checkpointopen.async_call =
  3031. req_lib_ckpt_checkpointopen->async_call;
  3032. iovec.iov_base = (char *)&req_exec_ckpt_checkpointopen;
  3033. iovec.iov_len = sizeof (req_exec_ckpt_checkpointopen);
  3034. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3035. }
  3036. static void message_handler_req_lib_ckpt_checkpointclose (
  3037. void *conn,
  3038. void *msg)
  3039. {
  3040. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)msg;
  3041. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  3042. struct iovec iovec;
  3043. req_exec_ckpt_checkpointclose.header.size =
  3044. sizeof (struct req_exec_ckpt_checkpointclose);
  3045. req_exec_ckpt_checkpointclose.header.id =
  3046. SERVICE_ID_MAKE (CKPT_SERVICE,
  3047. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE);
  3048. message_source_set (&req_exec_ckpt_checkpointclose.source, conn);
  3049. memcpy (&req_exec_ckpt_checkpointclose.checkpoint_name,
  3050. &req_lib_ckpt_checkpointclose->checkpoint_name, sizeof (mar_name_t));
  3051. req_exec_ckpt_checkpointclose.ckpt_id =
  3052. req_lib_ckpt_checkpointclose->ckpt_id;
  3053. iovec.iov_base = (char *)&req_exec_ckpt_checkpointclose;
  3054. iovec.iov_len = sizeof (req_exec_ckpt_checkpointclose);
  3055. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3056. }
  3057. static void message_handler_req_lib_ckpt_checkpointunlink (
  3058. void *conn,
  3059. void *msg)
  3060. {
  3061. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)msg;
  3062. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  3063. struct iovec iovec;
  3064. req_exec_ckpt_checkpointunlink.header.size =
  3065. sizeof (struct req_exec_ckpt_checkpointunlink);
  3066. req_exec_ckpt_checkpointunlink.header.id =
  3067. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  3068. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn);
  3069. memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name,
  3070. &req_lib_ckpt_checkpointunlink->checkpoint_name,
  3071. sizeof (mar_name_t));
  3072. iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  3073. iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  3074. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  3075. TOTEMPG_AGREED) == 0);
  3076. }
  3077. static void message_handler_req_lib_ckpt_checkpointretentiondurationset (
  3078. void *conn,
  3079. void *msg)
  3080. {
  3081. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)msg;
  3082. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  3083. struct iovec iovec;
  3084. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API conn %p\n", conn);
  3085. req_exec_ckpt_checkpointretentiondurationset.header.id =
  3086. SERVICE_ID_MAKE (CKPT_SERVICE,
  3087. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET);
  3088. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  3089. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn);
  3090. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpoint_name,
  3091. &req_lib_ckpt_checkpointretentiondurationset->checkpoint_name,
  3092. sizeof (mar_name_t));
  3093. req_exec_ckpt_checkpointretentiondurationset.ckpt_id =
  3094. req_lib_ckpt_checkpointretentiondurationset->ckpt_id;
  3095. req_exec_ckpt_checkpointretentiondurationset.retention_duration =
  3096. req_lib_ckpt_checkpointretentiondurationset->retention_duration;
  3097. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  3098. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  3099. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  3100. TOTEMPG_AGREED) == 0);
  3101. }
  3102. static void message_handler_req_lib_ckpt_activereplicaset (
  3103. void *conn,
  3104. void *msg)
  3105. {
  3106. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)msg;
  3107. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  3108. struct checkpoint *checkpoint;
  3109. SaAisErrorT error = SA_AIS_OK;
  3110. checkpoint = checkpoint_find (
  3111. &req_lib_ckpt_activereplicaset->checkpoint_name,
  3112. req_lib_ckpt_activereplicaset->ckpt_id);
  3113. /*
  3114. * Make sure checkpoint is collocated and async update option
  3115. */
  3116. if (((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  3117. (checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3118. error = SA_AIS_ERR_BAD_OPERATION;
  3119. }
  3120. checkpoint->active_replica_set = 1;
  3121. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  3122. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  3123. res_lib_ckpt_activereplicaset.header.error = error;
  3124. openais_conn_send_response (
  3125. conn,
  3126. &res_lib_ckpt_activereplicaset,
  3127. sizeof (struct res_lib_ckpt_activereplicaset));
  3128. }
  3129. static void message_handler_req_lib_ckpt_checkpointstatusget (
  3130. void *conn,
  3131. void *msg)
  3132. {
  3133. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)msg;
  3134. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  3135. struct checkpoint *checkpoint;
  3136. int memory_used = 0;
  3137. int number_of_sections = 0;
  3138. struct list_head *checkpoint_section_list;
  3139. struct checkpoint_section *checkpointSection;
  3140. /*
  3141. * Count memory used by checkpoint sections
  3142. */
  3143. checkpoint = checkpoint_find (
  3144. &req_lib_ckpt_checkpointstatusget->checkpoint_name,
  3145. req_lib_ckpt_checkpointstatusget->ckpt_id);
  3146. if (checkpoint && (checkpoint->expired == 0)) {
  3147. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  3148. checkpoint_section_list != &checkpoint->sections_list_head;
  3149. checkpoint_section_list = checkpoint_section_list->next) {
  3150. checkpointSection = list_entry (checkpoint_section_list,
  3151. struct checkpoint_section, list);
  3152. memory_used += checkpointSection->section_descriptor.section_size;
  3153. number_of_sections += 1;
  3154. }
  3155. /*
  3156. * Build checkpoint status get response
  3157. */
  3158. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  3159. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  3160. if (checkpoint->active_replica_set == 1) {
  3161. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  3162. } else {
  3163. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  3164. }
  3165. memcpy (&res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.checkpoint_creation_attributes,
  3166. &checkpoint->checkpoint_creation_attributes,
  3167. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  3168. res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.number_of_sections = number_of_sections;
  3169. res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.memory_used = memory_used;
  3170. }
  3171. else {
  3172. log_printf (LOG_LEVEL_ERROR, "#### Could Not Find the Checkpoint's status so Returning Error. ####\n");
  3173. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  3174. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  3175. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  3176. }
  3177. openais_conn_send_response (
  3178. conn,
  3179. &res_lib_ckpt_checkpointstatusget,
  3180. sizeof (struct res_lib_ckpt_checkpointstatusget));
  3181. }
  3182. static void message_handler_req_lib_ckpt_sectioncreate (
  3183. void *conn,
  3184. void *msg)
  3185. {
  3186. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)msg;
  3187. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  3188. struct iovec iovecs[2];
  3189. log_printf (LOG_LEVEL_DEBUG, "Section create from conn %p\n", conn);
  3190. req_exec_ckpt_sectioncreate.header.id =
  3191. SERVICE_ID_MAKE (CKPT_SERVICE,
  3192. MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE);
  3193. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  3194. message_source_set (&req_exec_ckpt_sectioncreate.source, conn);
  3195. memcpy (&req_exec_ckpt_sectioncreate.checkpoint_name,
  3196. &req_lib_ckpt_sectioncreate->checkpoint_name,
  3197. sizeof (mar_name_t));
  3198. req_exec_ckpt_sectioncreate.ckpt_id =
  3199. req_lib_ckpt_sectioncreate->ckpt_id;
  3200. req_exec_ckpt_sectioncreate.id_len = req_lib_ckpt_sectioncreate->id_len;
  3201. req_exec_ckpt_sectioncreate.expiration_time =
  3202. req_lib_ckpt_sectioncreate->expiration_time;
  3203. req_exec_ckpt_sectioncreate.initial_data_size =
  3204. req_lib_ckpt_sectioncreate->initial_data_size;
  3205. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  3206. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  3207. /*
  3208. * Send section name and initial data in message
  3209. */
  3210. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  3211. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  3212. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  3213. if (iovecs[1].iov_len) {
  3214. log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_ckpt_sectioncreate Section = %p, id_len = %d\n",
  3215. iovecs[1].iov_base,
  3216. (int)iovecs[1].iov_len);
  3217. }
  3218. if (iovecs[1].iov_len > 0) {
  3219. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  3220. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3221. } else {
  3222. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3223. }
  3224. }
  3225. static void message_handler_req_lib_ckpt_sectiondelete (
  3226. void *conn,
  3227. void *msg)
  3228. {
  3229. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)msg;
  3230. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  3231. struct iovec iovecs[2];
  3232. log_printf (LOG_LEVEL_DEBUG, "section delete from conn %p\n", conn);
  3233. req_exec_ckpt_sectiondelete.header.id =
  3234. SERVICE_ID_MAKE (CKPT_SERVICE,
  3235. MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE);
  3236. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  3237. message_source_set (&req_exec_ckpt_sectiondelete.source, conn);
  3238. memcpy (&req_exec_ckpt_sectiondelete.checkpoint_name,
  3239. &req_lib_ckpt_sectiondelete->checkpoint_name,
  3240. sizeof (mar_name_t));
  3241. req_exec_ckpt_sectiondelete.ckpt_id =
  3242. req_lib_ckpt_sectiondelete->ckpt_id;
  3243. req_exec_ckpt_sectiondelete.id_len = req_lib_ckpt_sectiondelete->id_len;
  3244. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  3245. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  3246. /*
  3247. * Send section name
  3248. */
  3249. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) +
  3250. sizeof (struct req_lib_ckpt_sectiondelete);
  3251. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size -
  3252. sizeof (struct req_lib_ckpt_sectiondelete);
  3253. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  3254. if (iovecs[1].iov_len > 0) {
  3255. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3256. } else {
  3257. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3258. }
  3259. }
  3260. static void message_handler_req_lib_ckpt_sectionexpirationtimeset (
  3261. void *conn,
  3262. void *msg)
  3263. {
  3264. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)msg;
  3265. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  3266. struct iovec iovecs[2];
  3267. log_printf (LOG_LEVEL_DEBUG, "section expiration time set from conn %p\n", conn);
  3268. req_exec_ckpt_sectionexpirationtimeset.header.id =
  3269. SERVICE_ID_MAKE (CKPT_SERVICE,
  3270. MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET);
  3271. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  3272. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn);
  3273. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpoint_name,
  3274. &req_lib_ckpt_sectionexpirationtimeset->checkpoint_name,
  3275. sizeof (mar_name_t));
  3276. req_exec_ckpt_sectionexpirationtimeset.ckpt_id =
  3277. req_lib_ckpt_sectionexpirationtimeset->ckpt_id;
  3278. req_exec_ckpt_sectionexpirationtimeset.id_len =
  3279. req_lib_ckpt_sectionexpirationtimeset->id_len;
  3280. req_exec_ckpt_sectionexpirationtimeset.expiration_time =
  3281. req_lib_ckpt_sectionexpirationtimeset->expiration_time;
  3282. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  3283. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  3284. /*
  3285. * Send section name
  3286. */
  3287. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  3288. sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  3289. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size -
  3290. sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  3291. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  3292. if (iovecs[1].iov_len > 0) {
  3293. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3294. } else {
  3295. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3296. }
  3297. }
  3298. static void message_handler_req_lib_ckpt_sectionwrite (
  3299. void *conn,
  3300. void *msg)
  3301. {
  3302. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)msg;
  3303. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  3304. struct iovec iovecs[2];
  3305. log_printf (LOG_LEVEL_DEBUG, "Received data from lib with len = %d and ref = 0x%lx\n",
  3306. (int)req_lib_ckpt_sectionwrite->data_size,
  3307. (long)req_lib_ckpt_sectionwrite->data_offset);
  3308. log_printf (LOG_LEVEL_DEBUG, "Checkpoint section being written to is %s, id_len = %d\n",
  3309. ((char *)req_lib_ckpt_sectionwrite) +
  3310. sizeof (struct req_lib_ckpt_sectionwrite),
  3311. req_lib_ckpt_sectionwrite->id_len);
  3312. log_printf (LOG_LEVEL_DEBUG, "Section write from conn %p\n", conn);
  3313. /*
  3314. * checkpoint opened is writeable mode so send message to cluster
  3315. */
  3316. req_exec_ckpt_sectionwrite.header.id =
  3317. SERVICE_ID_MAKE (CKPT_SERVICE,
  3318. MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE);
  3319. req_exec_ckpt_sectionwrite.header.size =
  3320. sizeof (struct req_exec_ckpt_sectionwrite);
  3321. message_source_set (&req_exec_ckpt_sectionwrite.source, conn);
  3322. memcpy (&req_exec_ckpt_sectionwrite.checkpoint_name,
  3323. &req_lib_ckpt_sectionwrite->checkpoint_name,
  3324. sizeof (mar_name_t));
  3325. req_exec_ckpt_sectionwrite.ckpt_id =
  3326. req_lib_ckpt_sectionwrite->ckpt_id;
  3327. req_exec_ckpt_sectionwrite.id_len =
  3328. req_lib_ckpt_sectionwrite->id_len;
  3329. req_exec_ckpt_sectionwrite.data_offset =
  3330. req_lib_ckpt_sectionwrite->data_offset;
  3331. req_exec_ckpt_sectionwrite.data_size =
  3332. req_lib_ckpt_sectionwrite->data_size;
  3333. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  3334. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  3335. /*
  3336. * Send section name and data to write in message
  3337. */
  3338. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) +
  3339. sizeof (struct req_lib_ckpt_sectionwrite);
  3340. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size -
  3341. sizeof (struct req_lib_ckpt_sectionwrite);
  3342. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  3343. if (iovecs[1].iov_len > 0) {
  3344. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3345. } else {
  3346. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3347. }
  3348. }
  3349. static void message_handler_req_lib_ckpt_sectionoverwrite (
  3350. void *conn,
  3351. void *msg)
  3352. {
  3353. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)msg;
  3354. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  3355. struct iovec iovecs[2];
  3356. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from conn %p\n", conn);
  3357. req_exec_ckpt_sectionoverwrite.header.id =
  3358. SERVICE_ID_MAKE (CKPT_SERVICE,
  3359. MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE);
  3360. req_exec_ckpt_sectionoverwrite.header.size =
  3361. sizeof (struct req_exec_ckpt_sectionoverwrite);
  3362. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn);
  3363. memcpy (&req_exec_ckpt_sectionoverwrite.checkpoint_name,
  3364. &req_lib_ckpt_sectionoverwrite->checkpoint_name,
  3365. sizeof (mar_name_t));
  3366. req_exec_ckpt_sectionoverwrite.ckpt_id =
  3367. req_lib_ckpt_sectionoverwrite->ckpt_id;
  3368. req_exec_ckpt_sectionoverwrite.id_len =
  3369. req_lib_ckpt_sectionoverwrite->id_len;
  3370. req_exec_ckpt_sectionoverwrite.data_size =
  3371. req_lib_ckpt_sectionoverwrite->data_size;
  3372. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  3373. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  3374. /*
  3375. * Send section name and data to overwrite in message
  3376. */
  3377. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) +
  3378. sizeof (struct req_lib_ckpt_sectionoverwrite);
  3379. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size -
  3380. sizeof (struct req_lib_ckpt_sectionoverwrite);
  3381. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  3382. if (iovecs[1].iov_len > 0) {
  3383. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3384. } else {
  3385. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3386. }
  3387. }
  3388. static void message_handler_req_lib_ckpt_sectionread (
  3389. void *conn,
  3390. void *msg)
  3391. {
  3392. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)msg;
  3393. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  3394. struct iovec iovecs[2];
  3395. log_printf (LOG_LEVEL_DEBUG, "Section read from conn %p\n", conn);
  3396. /*
  3397. * checkpoint opened is writeable mode so send message to cluster
  3398. */
  3399. req_exec_ckpt_sectionread.header.id =
  3400. SERVICE_ID_MAKE (CKPT_SERVICE,
  3401. MESSAGE_REQ_EXEC_CKPT_SECTIONREAD);
  3402. req_exec_ckpt_sectionread.header.size =
  3403. sizeof (struct req_exec_ckpt_sectionread);
  3404. message_source_set (&req_exec_ckpt_sectionread.source, conn);
  3405. memcpy (&req_exec_ckpt_sectionread.checkpoint_name,
  3406. &req_lib_ckpt_sectionread->checkpoint_name,
  3407. sizeof (mar_name_t));
  3408. req_exec_ckpt_sectionread.ckpt_id =
  3409. req_lib_ckpt_sectionread->ckpt_id;
  3410. req_exec_ckpt_sectionread.id_len =
  3411. req_lib_ckpt_sectionread->id_len;
  3412. req_exec_ckpt_sectionread.data_offset =
  3413. req_lib_ckpt_sectionread->data_offset;
  3414. req_exec_ckpt_sectionread.data_size =
  3415. req_lib_ckpt_sectionread->data_size;
  3416. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  3417. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  3418. /*
  3419. * Send section name and data to overwrite in message
  3420. */
  3421. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) +
  3422. sizeof (struct req_lib_ckpt_sectionread);
  3423. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size -
  3424. sizeof (struct req_lib_ckpt_sectionread);
  3425. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  3426. if (iovecs[1].iov_len > 0) {
  3427. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3428. } else {
  3429. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3430. }
  3431. }
  3432. static void message_handler_req_lib_ckpt_checkpointsynchronize (
  3433. void *conn,
  3434. void *msg)
  3435. {
  3436. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)msg;
  3437. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  3438. struct checkpoint *checkpoint;
  3439. checkpoint = checkpoint_find (
  3440. &req_lib_ckpt_checkpointsynchronize->checkpoint_name,
  3441. req_lib_ckpt_checkpointsynchronize->ckpt_id);
  3442. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3443. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  3444. } else
  3445. if (checkpoint->active_replica_set == 1) {
  3446. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  3447. } else {
  3448. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  3449. }
  3450. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  3451. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  3452. openais_conn_send_response (
  3453. conn,
  3454. &res_lib_ckpt_checkpointsynchronize,
  3455. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  3456. }
  3457. static void message_handler_req_lib_ckpt_checkpointsynchronizeasync (
  3458. void *conn,
  3459. void *msg)
  3460. {
  3461. struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)msg;
  3462. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  3463. struct checkpoint *checkpoint;
  3464. checkpoint = checkpoint_find (
  3465. &req_lib_ckpt_checkpointsynchronizeasync->checkpoint_name,
  3466. req_lib_ckpt_checkpointsynchronizeasync->ckpt_id);
  3467. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3468. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION;
  3469. } else
  3470. if (checkpoint->active_replica_set == 1) {
  3471. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK;
  3472. } else {
  3473. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST;
  3474. }
  3475. res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync);
  3476. res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  3477. res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation;
  3478. openais_conn_send_response (
  3479. conn,
  3480. &res_lib_ckpt_checkpointsynchronizeasync,
  3481. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3482. openais_conn_send_response (
  3483. openais_conn_partner_get (conn),
  3484. &res_lib_ckpt_checkpointsynchronizeasync,
  3485. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3486. }
  3487. static void message_handler_req_lib_ckpt_sectioniterationinitialize (
  3488. void *conn,
  3489. void *msg)
  3490. {
  3491. struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)msg;
  3492. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  3493. struct checkpoint *checkpoint;
  3494. struct checkpoint_section *checkpoint_section;
  3495. struct iteration_entry *iteration_entries;
  3496. struct list_head *section_list;
  3497. struct iteration_instance *iteration_instance;
  3498. void *iteration_instance_p;
  3499. unsigned int iteration_handle = 0;
  3500. int res;
  3501. SaAisErrorT error = SA_AIS_OK;
  3502. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3503. log_printf (LOG_LEVEL_DEBUG, "section iteration initialize\n");
  3504. checkpoint = checkpoint_find (
  3505. &req_lib_ckpt_sectioniterationinitialize->checkpoint_name,
  3506. req_lib_ckpt_sectioniterationinitialize->ckpt_id);
  3507. if (checkpoint == 0) {
  3508. error = SA_AIS_ERR_NOT_EXIST;
  3509. goto error_exit;
  3510. }
  3511. if (checkpoint->active_replica_set == 0) {
  3512. log_printf (LOG_LEVEL_DEBUG, "iterationinitialize: no active replica, returning error.\n");
  3513. error = SA_AIS_ERR_NOT_EXIST;
  3514. goto error_exit;
  3515. }
  3516. res = hdb_handle_create (&ckpt_pd->iteration_hdb, sizeof(struct iteration_instance),
  3517. &iteration_handle);
  3518. if (res != 0) {
  3519. goto error_exit;
  3520. }
  3521. res = hdb_handle_get (&ckpt_pd->iteration_hdb, iteration_handle,
  3522. &iteration_instance_p);
  3523. if (res != 0) {
  3524. hdb_handle_destroy (&ckpt_pd->iteration_hdb, iteration_handle);
  3525. goto error_exit;
  3526. }
  3527. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3528. iteration_instance->iteration_entries = NULL;
  3529. iteration_instance->iteration_entries_count = 0;
  3530. iteration_instance->iteration_pos = 0;
  3531. /*
  3532. * Iterate list of checkpoint sections
  3533. */
  3534. for (section_list = checkpoint->sections_list_head.next;
  3535. section_list != &checkpoint->sections_list_head;
  3536. section_list = section_list->next) {
  3537. checkpoint_section = list_entry (section_list,
  3538. struct checkpoint_section, list);
  3539. switch (req_lib_ckpt_sectioniterationinitialize->sections_chosen) {
  3540. case SA_CKPT_SECTIONS_FOREVER:
  3541. if (checkpoint_section->section_descriptor.expiration_time != SA_TIME_END) {
  3542. continue;
  3543. }
  3544. break;
  3545. case SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME:
  3546. if (checkpoint_section->section_descriptor.expiration_time > req_lib_ckpt_sectioniterationinitialize->expiration_time) {
  3547. continue;
  3548. }
  3549. break;
  3550. case SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME:
  3551. if (checkpoint_section->section_descriptor.expiration_time < req_lib_ckpt_sectioniterationinitialize->expiration_time) {
  3552. continue;
  3553. }
  3554. break;
  3555. case SA_CKPT_SECTIONS_CORRUPTED:
  3556. /* there can be no corrupted sections - do nothing */
  3557. break;
  3558. case SA_CKPT_SECTIONS_ANY:
  3559. /* iterate all sections - do nothing */
  3560. break;
  3561. }
  3562. iteration_instance->iteration_entries_count += 1;
  3563. iteration_entries = realloc (iteration_instance->iteration_entries,
  3564. sizeof (struct iteration_entry) * iteration_instance->iteration_entries_count);
  3565. if (iteration_entries == NULL) {
  3566. error = SA_AIS_ERR_NO_MEMORY;
  3567. goto error_put;
  3568. }
  3569. iteration_instance->iteration_entries = iteration_entries;
  3570. iteration_entries[iteration_instance->iteration_entries_count - 1].active = 1;
  3571. iteration_entries[iteration_instance->iteration_entries_count - 1].checkpoint_section = checkpoint_section;
  3572. }
  3573. error_put:
  3574. hdb_handle_put (&ckpt_pd->iteration_hdb, iteration_handle);
  3575. error_exit:
  3576. res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize);
  3577. res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE;
  3578. res_lib_ckpt_sectioniterationinitialize.header.error = error;
  3579. res_lib_ckpt_sectioniterationinitialize.iteration_handle = iteration_handle;
  3580. res_lib_ckpt_sectioniterationinitialize.max_section_id_size =
  3581. checkpoint->checkpoint_creation_attributes.max_section_id_size;
  3582. openais_conn_send_response (
  3583. conn,
  3584. &res_lib_ckpt_sectioniterationinitialize,
  3585. sizeof (struct res_lib_ckpt_sectioniterationinitialize));
  3586. }
  3587. static void message_handler_req_lib_ckpt_sectioniterationfinalize (
  3588. void *conn,
  3589. void *msg)
  3590. {
  3591. struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)msg;
  3592. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  3593. SaAisErrorT error = SA_AIS_OK;
  3594. struct iteration_instance *iteration_instance;
  3595. void *iteration_instance_p;
  3596. unsigned int res;
  3597. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3598. res = hdb_handle_get (&ckpt_pd->iteration_hdb,
  3599. req_lib_ckpt_sectioniterationfinalize->iteration_handle,
  3600. &iteration_instance_p);
  3601. if (res != 0) {
  3602. error = SA_AIS_ERR_LIBRARY;
  3603. goto error_exit;
  3604. }
  3605. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3606. free (iteration_instance->iteration_entries);
  3607. hdb_handle_put (&ckpt_pd->iteration_hdb,
  3608. req_lib_ckpt_sectioniterationfinalize->iteration_handle);
  3609. hdb_handle_destroy (&ckpt_pd->iteration_hdb,
  3610. req_lib_ckpt_sectioniterationfinalize->iteration_handle);
  3611. hdb_destroy (&ckpt_pd->iteration_hdb);
  3612. error_exit:
  3613. res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize);
  3614. res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE;
  3615. res_lib_ckpt_sectioniterationfinalize.header.error = error;
  3616. openais_conn_send_response (
  3617. conn,
  3618. &res_lib_ckpt_sectioniterationfinalize,
  3619. sizeof (struct res_lib_ckpt_sectioniterationfinalize));
  3620. }
  3621. static void message_handler_req_lib_ckpt_sectioniterationnext (
  3622. void *conn,
  3623. void *msg)
  3624. {
  3625. struct req_lib_ckpt_sectioniterationnext *req_lib_ckpt_sectioniterationnext = (struct req_lib_ckpt_sectioniterationnext *)msg;
  3626. struct res_lib_ckpt_sectioniterationnext res_lib_ckpt_sectioniterationnext;
  3627. SaAisErrorT error = SA_AIS_OK;
  3628. int section_id_size = 0;
  3629. unsigned int res;
  3630. struct iteration_instance *iteration_instance = NULL;
  3631. void *iteration_instance_p;
  3632. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3633. log_printf (LOG_LEVEL_DEBUG, "section iteration next\n");
  3634. res = hdb_handle_get (&ckpt_pd->iteration_hdb,
  3635. req_lib_ckpt_sectioniterationnext->iteration_handle,
  3636. &iteration_instance_p);
  3637. if (res != 0) {
  3638. error = SA_AIS_ERR_LIBRARY;
  3639. goto error_exit;
  3640. }
  3641. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3642. /*
  3643. * Find active iteration entry
  3644. */
  3645. for (;;) {
  3646. /*
  3647. * No more sections in iteration
  3648. */
  3649. if (iteration_instance->iteration_pos == iteration_instance->iteration_entries_count) {
  3650. error = SA_AIS_ERR_NO_SECTIONS;
  3651. goto error_put;
  3652. }
  3653. /*
  3654. * active iteration entry
  3655. */
  3656. if (iteration_instance->iteration_entries[iteration_instance->iteration_pos].active == 1) {
  3657. break;
  3658. }
  3659. iteration_instance->iteration_pos += 1;
  3660. }
  3661. /*
  3662. * Prepare response to API
  3663. */
  3664. section_id_size = iteration_instance->iteration_entries[iteration_instance->iteration_pos].checkpoint_section->section_descriptor.section_id.id_len;
  3665. memcpy (&res_lib_ckpt_sectioniterationnext.section_descriptor,
  3666. &iteration_instance->iteration_entries[iteration_instance->iteration_pos].checkpoint_section->section_descriptor,
  3667. sizeof (mar_ckpt_section_descriptor_t));
  3668. /*
  3669. * Get to next iteration entry
  3670. */
  3671. iteration_instance->iteration_pos += 1;
  3672. error_put:
  3673. hdb_handle_put (&ckpt_pd->iteration_hdb, req_lib_ckpt_sectioniterationnext->iteration_handle);
  3674. error_exit:
  3675. res_lib_ckpt_sectioniterationnext.header.size = sizeof (struct res_lib_ckpt_sectioniterationnext) + section_id_size;
  3676. res_lib_ckpt_sectioniterationnext.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONNEXT;
  3677. res_lib_ckpt_sectioniterationnext.header.error = error;
  3678. openais_conn_send_response (
  3679. conn,
  3680. &res_lib_ckpt_sectioniterationnext,
  3681. sizeof (struct res_lib_ckpt_sectioniterationnext));
  3682. if (error == SA_AIS_OK) {
  3683. openais_conn_send_response (
  3684. conn,
  3685. iteration_instance->iteration_entries[
  3686. iteration_instance->iteration_pos - 1].
  3687. checkpoint_section->section_descriptor.section_id.id,
  3688. section_id_size);
  3689. }
  3690. }
  3691. static void dump_fn (void)
  3692. {
  3693. #ifdef DEBUG
  3694. struct list_head *checkpoint_list;
  3695. struct checkpoint *checkpoint;
  3696. struct list_head *checkpoint_section_list;
  3697. struct checkpoint_section *section;
  3698. log_printf (LOG_LEVEL_NOTICE,
  3699. "========== Checkpoint Information ===========");
  3700. log_printf (LOG_LEVEL_NOTICE, "global_ckpt_id: %u", global_ckpt_id);
  3701. for (checkpoint_list = checkpoint_list_head.next;
  3702. checkpoint_list != &checkpoint_list_head;
  3703. checkpoint_list = checkpoint_list->next) {
  3704. checkpoint = list_entry (checkpoint_list, struct checkpoint, list);
  3705. if (checkpoint == NULL) {
  3706. return;
  3707. }
  3708. log_printf (LOG_LEVEL_NOTICE, "Checkpoint %s (%d):",
  3709. checkpoint->name.value, checkpoint->name.length);
  3710. log_printf (LOG_LEVEL_NOTICE, " id: %u", checkpoint->ckpt_id);
  3711. log_printf (LOG_LEVEL_NOTICE, " sec cnt: %u", checkpoint->sectionCount);
  3712. log_printf (LOG_LEVEL_NOTICE, " ref cnt: %u", checkpoint->referenceCount);
  3713. log_printf (LOG_LEVEL_NOTICE, " unlinked: %u", checkpoint->unlinked);
  3714. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  3715. checkpoint_section_list != &checkpoint->sections_list_head;
  3716. checkpoint_section_list = checkpoint_section_list->next) {
  3717. section = list_entry (checkpoint_section_list,
  3718. struct checkpoint_section, list);
  3719. log_printf (LOG_LEVEL_NOTICE, " Section %s (%d)",
  3720. section->section_descriptor.section_id.id,
  3721. section->section_descriptor.section_id.id_len);
  3722. log_printf (LOG_LEVEL_NOTICE, " size: %llu",
  3723. section->section_descriptor.section_size);
  3724. log_printf (LOG_LEVEL_NOTICE, " state: %u",
  3725. section->section_descriptor.section_state);
  3726. log_printf (LOG_LEVEL_NOTICE, " exp time: %llu",
  3727. section->section_descriptor.expiration_time);
  3728. }
  3729. }
  3730. #endif
  3731. }