ckpt.c 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296
  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. #if 0
  1813. /*
  1814. * Add in default checkpoint section
  1815. */
  1816. list_init (&checkpoint_section->list);
  1817. list_add (&checkpoint_section->list, &checkpoint->sections_list_head);
  1818. /*
  1819. * Default section id
  1820. */
  1821. checkpoint_section->section_descriptor.section_id.id = 0;
  1822. checkpoint_section->section_descriptor.section_id.id_len = 0;
  1823. checkpoint_section->section_descriptor.expiration_time = SA_TIME_END;
  1824. checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID;
  1825. checkpoint_section->section_descriptor.last_update = 0; /*current time*/
  1826. checkpoint_section->section_descriptor.section_size = strlen("Factory installed data\0")+1;
  1827. checkpoint_section->section_data = malloc(strlen("Factory installed data\0")+1);
  1828. assert(checkpoint_section->section_data);
  1829. memcpy(checkpoint_section->section_data, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1830. checkpoint_section->expiration_timer = 0;
  1831. #endif
  1832. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1833. (checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1834. checkpoint->active_replica_set = 1;
  1835. } else
  1836. if ((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1837. checkpoint->active_replica_set = 1;
  1838. } else {
  1839. checkpoint->active_replica_set = 0;
  1840. }
  1841. initialize_ckpt_refcnt_array(checkpoint->ckpt_refcnt);
  1842. }
  1843. else {
  1844. /*
  1845. * Setup connection information and mark checkpoint as referenced
  1846. */
  1847. log_printf (LOG_LEVEL_DEBUG, "recovery CHECKPOINT reopened is %p\n", checkpoint);
  1848. }
  1849. /* synchronize global_ckpt_id to max(ckpt_id,global_ckpt_id)+1 */
  1850. if (ckpt_id >= global_ckpt_id) {
  1851. global_ckpt_id = ckpt_id + 1;
  1852. }
  1853. /*CHECK to see if there are any existing ckpts*/
  1854. if ((checkpoint->ckpt_refcnt) && (ckpt_refcnt_total(checkpoint->ckpt_refcnt) > 0)) {
  1855. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcnts\n");
  1856. merge_ckpt_refcnts(checkpoint->ckpt_refcnt, ref_cnt);
  1857. }
  1858. else {
  1859. initialize_ckpt_refcnt_array(checkpoint->ckpt_refcnt);
  1860. }
  1861. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1862. /*
  1863. * The reason why we are adding 1 is because there is an assignment vis-a-via an increment in the
  1864. * the next line. Whether the ckpt was opened earlier or just now, the referenceCount is getting
  1865. * obliterated in the next line.
  1866. */
  1867. checkpoint->referenceCount = ckpt_refcnt_total(ref_cnt) + 1; /*defect 1192*/
  1868. log_printf (LOG_LEVEL_DEBUG, "OPEN checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1869. memcpy (checkpoint->ckpt_refcnt,
  1870. ref_cnt,
  1871. sizeof(struct ckpt_refcnt) * PROCESSOR_COUNT_MAX);
  1872. /*
  1873. * Reset retention duration since this checkpoint was just opened
  1874. */
  1875. openais_timer_delete (checkpoint->retention_timer);
  1876. checkpoint->retention_timer = 0;
  1877. /*
  1878. * Send error result to CKPT library
  1879. */
  1880. error_exit:
  1881. return (error);
  1882. }
  1883. static void message_handler_req_exec_ckpt_synchronize_state (
  1884. void *message,
  1885. unsigned int nodeid)
  1886. {
  1887. int retcode;
  1888. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1889. = (struct req_exec_ckpt_synchronize_state *)message;
  1890. struct ckpt_refcnt local_ckpt_refcnt[PROCESSOR_COUNT_MAX];
  1891. unsigned int i;
  1892. /*
  1893. * If the Incoming message's previous ring id == saved_ring_id
  1894. * Ignore because we have seen this message before.
  1895. */
  1896. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1897. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1898. return;
  1899. }
  1900. for (i = 0; i < PROCESSOR_COUNT_MAX; i++) {
  1901. marshall_from_mar_ckpt_refcnt_t (&local_ckpt_refcnt[i],
  1902. &req_exec_ckpt_sync_state->ckpt_refcnt[i]);
  1903. }
  1904. retcode = recovery_checkpoint_open (
  1905. &req_exec_ckpt_sync_state->checkpoint_name,
  1906. req_exec_ckpt_sync_state->ckpt_id,
  1907. &req_exec_ckpt_sync_state->checkpoint_creation_attributes,
  1908. local_ckpt_refcnt);
  1909. if (retcode != SA_AIS_OK) {
  1910. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state\n");
  1911. log_printf(LOG_LEVEL_DEBUG, "recovery_checkpoint_open returned %d\n",retcode);
  1912. }
  1913. retcode = recovery_section_create (
  1914. &req_exec_ckpt_sync_state->section_descriptor,
  1915. &req_exec_ckpt_sync_state->checkpoint_name,
  1916. req_exec_ckpt_sync_state->ckpt_id,
  1917. (char*)req_exec_ckpt_sync_state
  1918. + sizeof (struct req_exec_ckpt_synchronize_state));
  1919. if (retcode != SA_AIS_OK) {
  1920. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_state\n");
  1921. log_printf(LOG_LEVEL_DEBUG, "recovery_section_create returned %d\n",retcode);
  1922. }
  1923. }
  1924. static void message_handler_req_exec_ckpt_synchronize_section (
  1925. void *message,
  1926. unsigned int nodeid)
  1927. {
  1928. int retcode;
  1929. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1930. = (struct req_exec_ckpt_synchronize_section *)message;
  1931. /*
  1932. * If the Incoming message's previous ring id == saved_ring_id
  1933. * Ignore because we have seen this message before.
  1934. */
  1935. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1936. log_printf(LOG_LEVEL_DEBUG, "message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1937. return;
  1938. }
  1939. /*
  1940. * Write the contents of the section to the checkpoint section.
  1941. */
  1942. retcode = recovery_section_write(
  1943. req_exec_ckpt_sync_section->id_len,
  1944. (char*)req_exec_ckpt_sync_section +
  1945. sizeof (struct req_exec_ckpt_synchronize_section),
  1946. &req_exec_ckpt_sync_section->checkpoint_name,
  1947. req_exec_ckpt_sync_section->ckpt_id,
  1948. (char*)req_exec_ckpt_sync_section
  1949. + sizeof (struct req_exec_ckpt_synchronize_section)
  1950. + req_exec_ckpt_sync_section->id_len,
  1951. req_exec_ckpt_sync_section->data_offset,
  1952. req_exec_ckpt_sync_section->data_size);
  1953. if (retcode != SA_AIS_OK) {
  1954. log_printf(LOG_LEVEL_ERROR, "message_handler_req_exec_ckpt_synchronize_section\n");
  1955. log_printf(LOG_LEVEL_ERROR, "recovery_section_write returned %d\n",retcode);
  1956. }
  1957. }
  1958. unsigned int abstime_to_msec (mar_time_t time)
  1959. {
  1960. struct timeval tv;
  1961. unsigned long long curr_time;
  1962. unsigned long long msec_time;
  1963. gettimeofday (&tv, NULL);
  1964. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1965. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1966. msec_time = (((unsigned long long)time) / 1000000) -
  1967. (unsigned long long)curr_time;
  1968. return ((unsigned int)(msec_time));
  1969. }
  1970. void timer_function_section_expire (void *data)
  1971. {
  1972. struct checkpoint *checkpoint = 0;
  1973. struct checkpoint_section *checkpoint_section = 0;
  1974. struct ckpt_identifier *ckpt_id = 0;
  1975. ckpt_id = (struct ckpt_identifier *)data;
  1976. log_printf (LOG_LEVEL_DEBUG, "timer_function_section_expire data = 0x%p\n",data);
  1977. if (ckpt_id->ckpt_section_id.id_len && ckpt_id->ckpt_section_id.id) {
  1978. log_printf (LOG_LEVEL_DEBUG, "Attempting to expire section %s in ckpt %s\n",
  1979. ckpt_id->ckpt_section_id.id,
  1980. ckpt_id->ckpt_name.value);
  1981. }
  1982. else {
  1983. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire data incorect\n");
  1984. goto free_mem;
  1985. }
  1986. checkpoint = checkpoint_find (&ckpt_id->ckpt_name, ckpt_id->ckpt_id);
  1987. if (checkpoint == 0) {
  1988. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find ckpt %s\n",
  1989. ckpt_id->ckpt_name.value);
  1990. goto free_mem;
  1991. }
  1992. checkpoint_section = checkpoint_section_find (checkpoint,
  1993. (char *)ckpt_id->ckpt_section_id.id,
  1994. (int)ckpt_id->ckpt_section_id.id_len);
  1995. if (checkpoint_section == 0) {
  1996. log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find section %s in ckpt %s\n",
  1997. ckpt_id->ckpt_section_id.id,
  1998. ckpt_id->ckpt_name.value);
  1999. goto free_mem;
  2000. }
  2001. log_printf (LOG_LEVEL_DEBUG, "Expiring section %s in ckpt %s\n",
  2002. ckpt_id->ckpt_section_id.id,
  2003. ckpt_id->ckpt_name.value);
  2004. checkpoint->sectionCount -= 1;
  2005. /*
  2006. * defect id 1112 "memory leak in checkpoint service" Dont try
  2007. * to delete the timer as the timer mechanism takes care of that.
  2008. * Just delete the data after this call
  2009. */
  2010. checkpoint_section_and_associate_timer_cleanup (checkpoint_section, 0);
  2011. free_mem :
  2012. free (ckpt_id);
  2013. }
  2014. void timer_function_retention (void *data)
  2015. {
  2016. struct checkpoint *checkpoint = (struct checkpoint *)data;
  2017. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  2018. struct iovec iovec;
  2019. checkpoint->retention_timer = 0;
  2020. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  2021. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  2022. req_exec_ckpt_checkpointretentiondurationexpire.header.id =
  2023. SERVICE_ID_MAKE (CKPT_SERVICE,
  2024. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE);
  2025. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpoint_name,
  2026. &checkpoint->name,
  2027. sizeof (mar_name_t));
  2028. req_exec_ckpt_checkpointretentiondurationexpire.ckpt_id =
  2029. checkpoint->ckpt_id;
  2030. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  2031. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  2032. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2033. }
  2034. static void message_handler_req_exec_ckpt_checkpointclose (
  2035. void *message,
  2036. unsigned int nodeid)
  2037. {
  2038. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  2039. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2040. struct checkpoint *checkpoint = 0;
  2041. SaAisErrorT error = SA_AIS_OK;
  2042. int proc_index;
  2043. int release_checkpoint = 0;
  2044. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n",
  2045. get_mar_name_t (&req_exec_ckpt_checkpointclose->checkpoint_name));
  2046. checkpoint = checkpoint_find (
  2047. &req_exec_ckpt_checkpointclose->checkpoint_name,
  2048. req_exec_ckpt_checkpointclose->ckpt_id);
  2049. if (checkpoint == 0) {
  2050. error = SA_AIS_ERR_NOT_EXIST;
  2051. goto error_exit;
  2052. }
  2053. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  2054. checkpoint->referenceCount--;
  2055. /*
  2056. * Modify the connection reference information to the Checkpoint to be
  2057. * sent out later as a part of the sync process.
  2058. */
  2059. proc_index = processor_index_find(nodeid, checkpoint->ckpt_refcnt);
  2060. if (proc_index != -1 ) {
  2061. checkpoint->ckpt_refcnt[proc_index].count--;
  2062. }
  2063. else {
  2064. log_printf (LOG_LEVEL_ERROR,
  2065. "Could Not find Processor Info %p info.\n",
  2066. checkpoint);
  2067. }
  2068. assert (checkpoint->referenceCount > 0); /*defect 1192*/
  2069. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  2070. checkpoint->referenceCount);
  2071. /*
  2072. * If checkpoint has been unlinked and this is the last reference, delete it
  2073. */
  2074. if (checkpoint->unlinked && checkpoint->referenceCount == 1) { /*defect 1192*/
  2075. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  2076. release_checkpoint = 1;
  2077. } else
  2078. if (checkpoint->referenceCount == 1) { /*defect 1192*/
  2079. openais_timer_add (
  2080. checkpoint->checkpoint_creation_attributes.retention_duration / 1000000,
  2081. checkpoint,
  2082. timer_function_retention,
  2083. &checkpoint->retention_timer);
  2084. }
  2085. error_exit:
  2086. /*
  2087. * Remove the checkpoint from my connections checkpoint list
  2088. */
  2089. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  2090. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2091. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2092. res_lib_ckpt_checkpointclose.header.error = error;
  2093. openais_conn_send_response (req_exec_ckpt_checkpointclose->source.conn,
  2094. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  2095. if (error == SA_AIS_OK) {
  2096. ckpt_checkpoint_remove_cleanup (
  2097. req_exec_ckpt_checkpointclose->source.conn,
  2098. checkpoint);
  2099. }
  2100. }
  2101. /*
  2102. * Release the checkpoint if instructed to do so.
  2103. */
  2104. if (error == SA_AIS_OK && release_checkpoint) {
  2105. checkpoint_release(checkpoint);
  2106. }
  2107. }
  2108. static void message_handler_req_exec_ckpt_checkpointunlink (
  2109. void *message,
  2110. unsigned int nodeid)
  2111. {
  2112. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  2113. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  2114. struct checkpoint *checkpoint = 0;
  2115. SaAisErrorT error = SA_AIS_OK;
  2116. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  2117. checkpoint = checkpoint_find_linked (
  2118. &req_exec_ckpt_checkpointunlink->checkpoint_name);
  2119. if (checkpoint == 0) {
  2120. error = SA_AIS_ERR_NOT_EXIST;
  2121. goto error_exit;
  2122. }
  2123. assert (checkpoint->unlinked == 0);
  2124. checkpoint->unlinked = 1;
  2125. /*
  2126. * Immediately delete entry if reference count is zero
  2127. */
  2128. if (checkpoint->referenceCount == 1) {
  2129. /*
  2130. * Remove retention timer since this checkpoint was unlinked and is no
  2131. * longer referenced
  2132. */
  2133. checkpoint_release (checkpoint);
  2134. }
  2135. error_exit:
  2136. /*
  2137. * If this node was the source of the message, respond to this node
  2138. */
  2139. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  2140. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  2141. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  2142. res_lib_ckpt_checkpointunlink.header.error = error;
  2143. openais_conn_send_response (
  2144. req_exec_ckpt_checkpointunlink->source.conn,
  2145. &res_lib_ckpt_checkpointunlink,
  2146. sizeof (struct res_lib_ckpt_checkpointunlink));
  2147. }
  2148. }
  2149. static void message_handler_req_exec_ckpt_checkpointretentiondurationset (
  2150. void *message,
  2151. unsigned int nodeid)
  2152. {
  2153. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  2154. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  2155. struct checkpoint *checkpoint;
  2156. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  2157. checkpoint = checkpoint_find (
  2158. &req_exec_ckpt_checkpointretentiondurationset->checkpoint_name,
  2159. req_exec_ckpt_checkpointretentiondurationset->ckpt_id);
  2160. if (checkpoint) {
  2161. log_printf (LOG_LEVEL_DEBUG, "Setting retention duration for checkpoint %s\n",
  2162. get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationset->checkpoint_name));
  2163. if (checkpoint->unlinked == 0) {
  2164. checkpoint->checkpoint_creation_attributes.retention_duration =
  2165. req_exec_ckpt_checkpointretentiondurationset->retention_duration;
  2166. if (checkpoint->expired == 0 && checkpoint->referenceCount == 1) { /*defect 1192*/
  2167. openais_timer_delete (checkpoint->retention_timer);
  2168. openais_timer_add (
  2169. checkpoint->checkpoint_creation_attributes.retention_duration / 1000000,
  2170. checkpoint,
  2171. timer_function_retention,
  2172. &checkpoint->retention_timer);
  2173. }
  2174. error = SA_AIS_OK;
  2175. }
  2176. }
  2177. /*
  2178. * Respond to library if this processor sent the duration set request
  2179. */
  2180. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  2181. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  2182. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  2183. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  2184. openais_conn_send_response (
  2185. req_exec_ckpt_checkpointretentiondurationset->source.conn,
  2186. &res_lib_ckpt_checkpointretentiondurationset,
  2187. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  2188. }
  2189. }
  2190. static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire (
  2191. void *message,
  2192. unsigned int nodeid)
  2193. {
  2194. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  2195. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2196. struct checkpoint *checkpoint;
  2197. struct iovec iovec;
  2198. checkpoint = checkpoint_find (
  2199. &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name,
  2200. req_exec_ckpt_checkpointretentiondurationexpire->ckpt_id);
  2201. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount == 1)) {
  2202. log_printf (LOG_LEVEL_DEBUG, "Expiring checkpoint %s\n",
  2203. get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name));
  2204. checkpoint->expired = 1;
  2205. req_exec_ckpt_checkpointunlink.header.size =
  2206. sizeof (struct req_exec_ckpt_checkpointunlink);
  2207. req_exec_ckpt_checkpointunlink.header.id =
  2208. SERVICE_ID_MAKE (CKPT_SERVICE,
  2209. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  2210. req_exec_ckpt_checkpointunlink.source.conn = 0;
  2211. req_exec_ckpt_checkpointunlink.source.nodeid = 0;
  2212. memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name,
  2213. &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name,
  2214. sizeof (mar_name_t));
  2215. iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2216. iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2217. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2218. }
  2219. }
  2220. static int recovery_section_create (
  2221. mar_ckpt_section_descriptor_t *section_descriptor,
  2222. mar_name_t *checkpoint_name,
  2223. mar_uint32_t ckpt_id,
  2224. char *section_id)
  2225. {
  2226. struct checkpoint *checkpoint;
  2227. struct checkpoint_section *checkpoint_section;
  2228. void *initial_data;
  2229. struct ckpt_identifier *ckpt_identifier = 0;
  2230. SaAisErrorT error = SA_AIS_OK;
  2231. void *section_id_new;
  2232. if ((int)section_descriptor->section_id.id_len) {
  2233. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create for checkpoint %s, section %s.\n",
  2234. checkpoint_name->value, section_id);
  2235. } else {
  2236. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create for checkpoint %s, default section.\n",
  2237. checkpoint_name->value);
  2238. }
  2239. checkpoint = checkpoint_find (checkpoint_name, ckpt_id);
  2240. if (checkpoint == 0) {
  2241. error = SA_AIS_ERR_NOT_EXIST;
  2242. goto error_exit;
  2243. }
  2244. /*
  2245. * Determine if user-specified checkpoint ID already exists
  2246. */
  2247. checkpoint_section = checkpoint_section_find (
  2248. checkpoint,
  2249. section_id,
  2250. (int)section_descriptor->section_id.id_len);
  2251. if (checkpoint_section) {
  2252. /*
  2253. * This use case is mostly for the default section and is not probable for any other
  2254. * sections.
  2255. */
  2256. if (section_descriptor->section_size
  2257. > checkpoint_section->section_descriptor.section_size) {
  2258. void *section_data_tmp;
  2259. log_printf (LOG_LEVEL_NOTICE,
  2260. "recovery_section_create reallocating data. Present Size: %d, New Size: %d\n",
  2261. (int)checkpoint_section->section_descriptor.section_size,
  2262. (int)section_descriptor->section_size);
  2263. section_data_tmp =
  2264. realloc (checkpoint_section->section_data, section_descriptor->section_size);
  2265. if (section_data_tmp == NULL) {
  2266. log_printf (LOG_LEVEL_ERROR,
  2267. "recovery_section_create section_data realloc returned NULL Calling error_exit.\n");
  2268. error = SA_AIS_ERR_NO_MEMORY;
  2269. checkpoint_section_release(checkpoint_section);
  2270. goto error_exit;
  2271. }
  2272. checkpoint_section->section_data = section_data_tmp;
  2273. checkpoint_section->section_descriptor.section_size = section_descriptor->section_size;
  2274. error = SA_AIS_OK;
  2275. }
  2276. else {
  2277. error = SA_AIS_ERR_EXIST;
  2278. }
  2279. goto error_exit;
  2280. }
  2281. /*
  2282. * Allocate checkpoint section
  2283. */
  2284. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  2285. if (checkpoint_section == 0) {
  2286. error = SA_AIS_ERR_NO_MEMORY;
  2287. goto error_exit;
  2288. }
  2289. /*
  2290. * Allocate checkpoint section data
  2291. */
  2292. initial_data = malloc (section_descriptor->section_size);
  2293. if (initial_data == 0) {
  2294. free (checkpoint_section);
  2295. error = SA_AIS_ERR_NO_MEMORY;
  2296. goto error_exit;
  2297. }
  2298. /*
  2299. * Allocate checkpoint section id
  2300. */
  2301. section_id_new = NULL;
  2302. if (section_descriptor->section_id.id_len) {
  2303. section_id_new = malloc ((int)section_descriptor->section_id.id_len);
  2304. if (section_id_new == 0) {
  2305. free (checkpoint_section);
  2306. free (initial_data);
  2307. error = SA_AIS_ERR_NO_MEMORY;
  2308. goto error_exit;
  2309. }
  2310. }
  2311. /*
  2312. * Copy checkpoint section ID and initialize data.
  2313. */
  2314. if (section_id) {
  2315. memcpy ((char*)section_id_new, (char*)section_id,
  2316. (int)section_descriptor->section_id.id_len);
  2317. }
  2318. memset (initial_data, 0, section_descriptor->section_size);
  2319. /*
  2320. * Configure checkpoint section
  2321. */
  2322. memcpy(&checkpoint_section->section_descriptor,
  2323. section_descriptor,
  2324. sizeof(mar_ckpt_section_descriptor_t));
  2325. checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID;
  2326. checkpoint_section->section_data = initial_data;
  2327. checkpoint_section->expiration_timer = 0;
  2328. checkpoint_section->section_descriptor.section_id.id = section_id_new;
  2329. if (section_descriptor->expiration_time != SA_TIME_END) {
  2330. ckpt_identifier = malloc (sizeof(struct ckpt_identifier));
  2331. assert(ckpt_identifier);
  2332. memcpy(&ckpt_identifier->ckpt_name, checkpoint_name,
  2333. sizeof(mar_name_t));
  2334. ckpt_identifier->ckpt_id = ckpt_id;
  2335. memcpy(&ckpt_identifier->ckpt_section_id,
  2336. &checkpoint_section->section_descriptor.section_id,
  2337. sizeof(mar_ckpt_section_id_t));
  2338. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  2339. ckpt_identifier->ckpt_section_id.id,
  2340. ckpt_identifier->ckpt_name.value);
  2341. openais_timer_add (
  2342. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2343. ckpt_identifier,
  2344. timer_function_section_expire,
  2345. &checkpoint_section->expiration_timer);
  2346. log_printf (LOG_LEVEL_DEBUG, "recovery_section_create expiration timer = 0x%p\n",
  2347. checkpoint_section->expiration_timer);
  2348. }
  2349. /*
  2350. * Add checkpoint section to checkpoint
  2351. */
  2352. list_init (&checkpoint_section->list);
  2353. list_add (&checkpoint_section->list,
  2354. &checkpoint->sections_list_head);
  2355. checkpoint->sectionCount += 1;
  2356. error_exit:
  2357. return (error);
  2358. }
  2359. static void message_handler_req_exec_ckpt_sectioncreate (
  2360. void *message,
  2361. unsigned int nodeid)
  2362. {
  2363. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  2364. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2365. struct checkpoint *checkpoint;
  2366. struct checkpoint_section *checkpoint_section;
  2367. void *initial_data;
  2368. void *section_id;
  2369. struct ckpt_identifier *ckpt_id = 0;
  2370. SaAisErrorT error = SA_AIS_OK;
  2371. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  2372. checkpoint = checkpoint_find (
  2373. &req_exec_ckpt_sectioncreate->checkpoint_name,
  2374. req_exec_ckpt_sectioncreate->ckpt_id);
  2375. if (checkpoint == 0) {
  2376. error = SA_AIS_ERR_NOT_EXIST;
  2377. goto error_exit;
  2378. }
  2379. if (checkpoint->sectionCount == checkpoint->checkpoint_creation_attributes.max_sections) {
  2380. error = SA_AIS_ERR_NO_SPACE;
  2381. goto error_exit;
  2382. }
  2383. if (checkpoint->checkpoint_creation_attributes.max_sections == 1) {
  2384. error = SA_AIS_ERR_EXIST;
  2385. goto error_exit;
  2386. }
  2387. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2388. req_exec_ckpt_sectioncreate->initial_data_size) {
  2389. error = SA_AIS_ERR_INVALID_PARAM;
  2390. goto error_exit;
  2391. }
  2392. /*
  2393. * Determine if user-specified checkpoint section already exists
  2394. */
  2395. checkpoint_section = checkpoint_section_find (checkpoint,
  2396. ((char *)req_exec_ckpt_sectioncreate) +
  2397. sizeof (struct req_exec_ckpt_sectioncreate),
  2398. req_exec_ckpt_sectioncreate->id_len);
  2399. if (checkpoint_section) {
  2400. error = SA_AIS_ERR_EXIST;
  2401. goto error_exit;
  2402. }
  2403. /*
  2404. * Allocate checkpoint section
  2405. */
  2406. checkpoint_section = malloc (sizeof (struct checkpoint_section));
  2407. if (checkpoint_section == 0) {
  2408. error = SA_AIS_ERR_NO_MEMORY;
  2409. goto error_exit;
  2410. }
  2411. /*
  2412. * Allocate checkpoint section data
  2413. */
  2414. initial_data = malloc (req_exec_ckpt_sectioncreate->initial_data_size);
  2415. if (initial_data == 0) {
  2416. free (checkpoint_section);
  2417. error = SA_AIS_ERR_NO_MEMORY;
  2418. goto error_exit;
  2419. }
  2420. /*
  2421. * Allocate checkpoint section id
  2422. */
  2423. section_id = malloc (req_exec_ckpt_sectioncreate->id_len + 1);
  2424. if (section_id == 0) {
  2425. free (checkpoint_section);
  2426. free (initial_data);
  2427. error = SA_AIS_ERR_NO_MEMORY;
  2428. goto error_exit;
  2429. }
  2430. /*
  2431. * Copy checkpoint section and section ID
  2432. */
  2433. memcpy (section_id,
  2434. ((char *)req_exec_ckpt_sectioncreate) +
  2435. sizeof (struct req_exec_ckpt_sectioncreate),
  2436. req_exec_ckpt_sectioncreate->id_len);
  2437. /*Must be null terminated if it already isn't*/
  2438. ((char*)(section_id))[req_exec_ckpt_sectioncreate->id_len] = '\0';
  2439. memcpy (initial_data,
  2440. ((char *)req_exec_ckpt_sectioncreate) +
  2441. sizeof (struct req_exec_ckpt_sectioncreate) +
  2442. req_exec_ckpt_sectioncreate->id_len,
  2443. req_exec_ckpt_sectioncreate->initial_data_size);
  2444. /*
  2445. * Configure checkpoint section
  2446. */
  2447. checkpoint_section->section_descriptor.section_id.id = section_id;
  2448. checkpoint_section->section_descriptor.section_id.id_len =
  2449. req_exec_ckpt_sectioncreate->id_len;
  2450. checkpoint_section->section_descriptor.section_size =
  2451. req_exec_ckpt_sectioncreate->initial_data_size;
  2452. checkpoint_section->section_descriptor.expiration_time =
  2453. req_exec_ckpt_sectioncreate->expiration_time;
  2454. checkpoint_section->section_descriptor.section_state =
  2455. SA_CKPT_SECTION_VALID;
  2456. checkpoint_section->section_descriptor.last_update = 0; /* TODO current time */
  2457. checkpoint_section->section_data = initial_data;
  2458. checkpoint_section->expiration_timer = 0;
  2459. if (req_exec_ckpt_sectioncreate->expiration_time != SA_TIME_END) {
  2460. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2461. assert(ckpt_id);
  2462. memcpy(&ckpt_id->ckpt_name,
  2463. &req_exec_ckpt_sectioncreate->checkpoint_name,
  2464. sizeof(mar_name_t));
  2465. ckpt_id->ckpt_id = req_exec_ckpt_sectioncreate->ckpt_id;
  2466. memcpy(&ckpt_id->ckpt_section_id,
  2467. &checkpoint_section->section_descriptor.section_id,
  2468. sizeof(mar_ckpt_section_id_t));
  2469. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  2470. ckpt_id->ckpt_section_id.id,
  2471. ckpt_id->ckpt_name.value);
  2472. openais_timer_add (
  2473. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2474. ckpt_id,
  2475. timer_function_section_expire,
  2476. &checkpoint_section->expiration_timer);
  2477. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionicreate expiration timer = 0x%p\n",
  2478. checkpoint_section->expiration_timer);
  2479. }
  2480. log_printf (LOG_LEVEL_DEBUG,
  2481. "message_handler_req_exec_ckpt_sectioncreate created section with id = %s, id_len = %d\n",
  2482. checkpoint_section->section_descriptor.section_id.id,
  2483. checkpoint_section->section_descriptor.section_id.id_len);
  2484. /*
  2485. * Add checkpoint section to checkpoint
  2486. */
  2487. list_init (&checkpoint_section->list);
  2488. list_add (&checkpoint_section->list,
  2489. &checkpoint->sections_list_head);
  2490. checkpoint->sectionCount += 1;
  2491. error_exit:
  2492. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  2493. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2494. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2495. res_lib_ckpt_sectioncreate.header.error = error;
  2496. openais_conn_send_response (req_exec_ckpt_sectioncreate->source.conn,
  2497. &res_lib_ckpt_sectioncreate,
  2498. sizeof (struct res_lib_ckpt_sectioncreate));
  2499. }
  2500. }
  2501. static void message_handler_req_exec_ckpt_sectiondelete (
  2502. void *message,
  2503. unsigned int nodeid)
  2504. {
  2505. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  2506. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  2507. struct checkpoint *checkpoint;
  2508. struct checkpoint_section *checkpoint_section;
  2509. SaAisErrorT error = SA_AIS_OK;
  2510. checkpoint = checkpoint_find (
  2511. &req_exec_ckpt_sectiondelete->checkpoint_name,
  2512. req_exec_ckpt_sectiondelete->ckpt_id);
  2513. if (checkpoint == 0) {
  2514. error = SA_AIS_ERR_NOT_EXIST;
  2515. goto error_exit;
  2516. }
  2517. if (checkpoint->active_replica_set == 0) {
  2518. log_printf (LOG_LEVEL_DEBUG, "sectiondelete: no active replica, returning error.\n");
  2519. error = SA_AIS_ERR_NOT_EXIST;
  2520. goto error_exit;
  2521. }
  2522. /*
  2523. * Determine if the user is trying to delete the default section
  2524. */
  2525. if (req_exec_ckpt_sectiondelete->id_len == 0) {
  2526. error = SA_AIS_ERR_INVALID_PARAM;
  2527. goto error_exit;
  2528. }
  2529. /*
  2530. * Find checkpoint section to be deleted
  2531. */
  2532. checkpoint_section = checkpoint_section_find (checkpoint,
  2533. ((char *)(req_exec_ckpt_sectiondelete) + sizeof (struct req_exec_ckpt_sectiondelete)),
  2534. req_exec_ckpt_sectiondelete->id_len);
  2535. if (checkpoint_section == 0) {
  2536. error = SA_AIS_ERR_NOT_EXIST;
  2537. goto error_exit;
  2538. }
  2539. /*
  2540. * Delete checkpoint section
  2541. */
  2542. checkpoint->sectionCount -= 1;
  2543. checkpoint_section_release (checkpoint_section);
  2544. /*
  2545. * return result to CKPT library
  2546. */
  2547. error_exit:
  2548. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  2549. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  2550. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  2551. res_lib_ckpt_sectiondelete.header.error = error;
  2552. openais_conn_send_response (
  2553. req_exec_ckpt_sectiondelete->source.conn,
  2554. &res_lib_ckpt_sectiondelete,
  2555. sizeof (struct res_lib_ckpt_sectiondelete));
  2556. }
  2557. }
  2558. static void message_handler_req_exec_ckpt_sectionexpirationtimeset (
  2559. void *message,
  2560. unsigned int nodeid)
  2561. {
  2562. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  2563. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  2564. struct checkpoint *checkpoint;
  2565. struct checkpoint_section *checkpoint_section;
  2566. struct ckpt_identifier *ckpt_id = 0;
  2567. SaAisErrorT error = SA_AIS_OK;
  2568. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiration time\n");
  2569. checkpoint = checkpoint_find (
  2570. &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name,
  2571. req_exec_ckpt_sectionexpirationtimeset->ckpt_id);
  2572. if (checkpoint == 0) {
  2573. error = SA_AIS_ERR_NOT_EXIST;
  2574. goto error_exit;
  2575. }
  2576. if (checkpoint->active_replica_set == 0) {
  2577. log_printf (LOG_LEVEL_DEBUG, "expirationset: no active replica, returning error.\n");
  2578. error = SA_AIS_ERR_NOT_EXIST;
  2579. goto error_exit;
  2580. }
  2581. /*
  2582. * Determine if the user is trying to set expiration time for the default section
  2583. */
  2584. if (req_exec_ckpt_sectionexpirationtimeset->id_len == 0) {
  2585. error = SA_AIS_ERR_INVALID_PARAM;
  2586. goto error_exit;
  2587. }
  2588. /*
  2589. * Find checkpoint section that expiration time should be set for
  2590. */
  2591. checkpoint_section = checkpoint_section_find (checkpoint,
  2592. ((char *)req_exec_ckpt_sectionexpirationtimeset) +
  2593. sizeof (struct req_exec_ckpt_sectionexpirationtimeset),
  2594. req_exec_ckpt_sectionexpirationtimeset->id_len);
  2595. if (checkpoint_section == 0) {
  2596. error = SA_AIS_ERR_NOT_EXIST;
  2597. goto error_exit;
  2598. }
  2599. checkpoint_section->section_descriptor.expiration_time =
  2600. req_exec_ckpt_sectionexpirationtimeset->expiration_time;
  2601. openais_timer_delete (checkpoint_section->expiration_timer);
  2602. checkpoint_section->expiration_timer = 0;
  2603. if (req_exec_ckpt_sectionexpirationtimeset->expiration_time != SA_TIME_END) {
  2604. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2605. assert(ckpt_id);
  2606. memcpy(&ckpt_id->ckpt_name,
  2607. &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name,
  2608. sizeof(mar_name_t));
  2609. ckpt_id->ckpt_id =
  2610. req_exec_ckpt_sectionexpirationtimeset->ckpt_id;
  2611. memcpy(&ckpt_id->ckpt_section_id,
  2612. &checkpoint_section->section_descriptor.section_id,
  2613. sizeof(mar_ckpt_section_id_t));
  2614. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%p\n",
  2615. ckpt_id->ckpt_section_id.id,
  2616. ckpt_id->ckpt_name.value,
  2617. ckpt_id);
  2618. openais_timer_add (
  2619. abstime_to_msec (checkpoint_section->section_descriptor.expiration_time),
  2620. ckpt_id,
  2621. timer_function_section_expire,
  2622. &checkpoint_section->expiration_timer);
  2623. log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%p\n",
  2624. checkpoint_section->expiration_timer);
  2625. }
  2626. error_exit:
  2627. if (message_source_is_local (&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2628. res_lib_ckpt_sectionexpirationtimeset.header.size =
  2629. sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2630. res_lib_ckpt_sectionexpirationtimeset.header.id =
  2631. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2632. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2633. openais_conn_send_response (
  2634. req_exec_ckpt_sectionexpirationtimeset->source.conn,
  2635. &res_lib_ckpt_sectionexpirationtimeset,
  2636. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2637. }
  2638. }
  2639. static int recovery_section_write(
  2640. int section_id_len,
  2641. char* section_id,
  2642. mar_name_t *checkpoint_name,
  2643. mar_uint32_t ckpt_id,
  2644. void *new_data,
  2645. mar_uint32_t data_offset,
  2646. mar_uint32_t data_size)
  2647. {
  2648. struct checkpoint *checkpoint;
  2649. struct checkpoint_section *checkpoint_section;
  2650. int size_required;
  2651. SaAisErrorT error = SA_AIS_OK;
  2652. char *sd;
  2653. log_printf (LOG_LEVEL_DEBUG, "recovery_section_write.\n");
  2654. checkpoint = checkpoint_find (checkpoint_name, ckpt_id);
  2655. if (checkpoint == 0) {
  2656. error = SA_AIS_ERR_NOT_EXIST;
  2657. goto error_exit;
  2658. }
  2659. /*
  2660. * Find checkpoint section to be written
  2661. */
  2662. checkpoint_section = checkpoint_section_find (checkpoint,
  2663. section_id, section_id_len);
  2664. if (checkpoint_section == 0) {
  2665. error = SA_AIS_ERR_NOT_EXIST;
  2666. goto error_exit;
  2667. }
  2668. /*
  2669. * If write would extend past end of section data, return error;
  2670. */
  2671. size_required = data_offset + data_size;
  2672. if (size_required > checkpoint_section->section_descriptor.section_size) {
  2673. log_printf (LOG_LEVEL_ERROR,
  2674. "recovery_section_write. write-past-end size_required:(%d), data_offset:(%d), data_size:(%d), sync-section-size:(%d)\n",
  2675. size_required, data_offset, data_size,
  2676. (int)checkpoint_section->section_descriptor.section_size);
  2677. error = SA_AIS_ERR_ACCESS;
  2678. goto error_exit;
  2679. }
  2680. /*
  2681. * Write checkpoint section to section data
  2682. */
  2683. if (data_size > 0) {
  2684. sd = (char *)checkpoint_section->section_data;
  2685. memcpy (&sd[data_offset], new_data, data_size);
  2686. }
  2687. error_exit:
  2688. return (error);
  2689. }
  2690. static void message_handler_req_exec_ckpt_sectionwrite (
  2691. void *message,
  2692. unsigned int nodeid)
  2693. {
  2694. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2695. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2696. struct checkpoint *checkpoint;
  2697. struct checkpoint_section *checkpoint_section = 0;
  2698. int size_required;
  2699. void *section_data;
  2700. SaAisErrorT error = SA_AIS_OK;
  2701. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2702. checkpoint = checkpoint_find (
  2703. &req_exec_ckpt_sectionwrite->checkpoint_name,
  2704. req_exec_ckpt_sectionwrite->ckpt_id);
  2705. if (checkpoint == 0) {
  2706. log_printf (LOG_LEVEL_ERROR, "checkpoint_find returned 0 Calling error_exit.\n");
  2707. error = SA_AIS_ERR_NOT_EXIST;
  2708. goto error_exit;
  2709. }
  2710. if (checkpoint->active_replica_set == 0) {
  2711. log_printf (LOG_LEVEL_DEBUG, "checkpointwrite: no active replica, returning error.\n");
  2712. error = SA_AIS_ERR_NOT_EXIST;
  2713. goto error_exit;
  2714. }
  2715. if (checkpoint->checkpoint_creation_attributes.max_section_size < req_exec_ckpt_sectionwrite->data_size) {
  2716. error = SA_AIS_ERR_INVALID_PARAM;
  2717. goto error_exit;
  2718. }
  2719. log_printf (LOG_LEVEL_DEBUG, "writing checkpoint section is %s\n",
  2720. ((char *)req_exec_ckpt_sectionwrite) +
  2721. sizeof (struct req_exec_ckpt_sectionwrite));
  2722. /*
  2723. * Find checkpoint section to be written
  2724. */
  2725. checkpoint_section = checkpoint_section_find (checkpoint,
  2726. ((char *)req_exec_ckpt_sectionwrite) +
  2727. sizeof (struct req_exec_ckpt_sectionwrite),
  2728. req_exec_ckpt_sectionwrite->id_len);
  2729. if (checkpoint_section == 0) {
  2730. if (req_exec_ckpt_sectionwrite->id_len == 0) {
  2731. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2732. }
  2733. else {
  2734. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2735. ((char *)req_exec_ckpt_sectionwrite) +
  2736. sizeof (struct req_exec_ckpt_sectionwrite));
  2737. }
  2738. error = SA_AIS_ERR_NOT_EXIST;
  2739. goto error_exit;
  2740. }
  2741. /*
  2742. * If write would extend past end of section data, enlarge section
  2743. */
  2744. size_required = req_exec_ckpt_sectionwrite->data_offset +
  2745. req_exec_ckpt_sectionwrite->data_size;
  2746. if (size_required > checkpoint_section->section_descriptor.section_size) {
  2747. section_data = realloc (checkpoint_section->section_data, size_required);
  2748. if (section_data == NULL) {
  2749. log_printf (LOG_LEVEL_ERROR, "section_data realloc returned NULL Calling error_exit.\n");
  2750. error = SA_AIS_ERR_NO_MEMORY;
  2751. goto error_exit;
  2752. }
  2753. /*
  2754. * Install new section data
  2755. */
  2756. checkpoint_section->section_data = section_data;
  2757. checkpoint_section->section_descriptor.section_size = size_required;
  2758. }
  2759. /*
  2760. * Write checkpoint section to section data
  2761. */
  2762. if (req_exec_ckpt_sectionwrite->data_size > 0) {
  2763. char *sd;
  2764. int *val;
  2765. val = checkpoint_section->section_data;
  2766. sd = (char *)checkpoint_section->section_data;
  2767. memcpy (&sd[req_exec_ckpt_sectionwrite->data_offset],
  2768. ((char *)req_exec_ckpt_sectionwrite) +
  2769. sizeof (struct req_exec_ckpt_sectionwrite) +
  2770. req_exec_ckpt_sectionwrite->id_len,
  2771. req_exec_ckpt_sectionwrite->data_size);
  2772. }
  2773. /*
  2774. * Write sectionwrite response to CKPT library
  2775. */
  2776. error_exit:
  2777. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2778. res_lib_ckpt_sectionwrite.header.size =
  2779. sizeof (struct res_lib_ckpt_sectionwrite);
  2780. res_lib_ckpt_sectionwrite.header.id =
  2781. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2782. res_lib_ckpt_sectionwrite.header.error = error;
  2783. openais_conn_send_response (
  2784. req_exec_ckpt_sectionwrite->source.conn,
  2785. &res_lib_ckpt_sectionwrite,
  2786. sizeof (struct res_lib_ckpt_sectionwrite));
  2787. }
  2788. }
  2789. static void message_handler_req_exec_ckpt_sectionoverwrite (
  2790. void *message,
  2791. unsigned int nodeid)
  2792. {
  2793. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2794. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2795. struct checkpoint *checkpoint;
  2796. struct checkpoint_section *checkpoint_section;
  2797. void *section_data;
  2798. SaAisErrorT error = SA_AIS_OK;
  2799. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2800. checkpoint = checkpoint_find (
  2801. &req_exec_ckpt_sectionoverwrite->checkpoint_name,
  2802. req_exec_ckpt_sectionoverwrite->ckpt_id);
  2803. if (checkpoint == 0) {
  2804. error = SA_AIS_ERR_NOT_EXIST;
  2805. goto error_exit;
  2806. }
  2807. if (checkpoint->active_replica_set == 0) {
  2808. log_printf (LOG_LEVEL_DEBUG, "sectionoverwrite: no active replica, returning error.\n");
  2809. error = SA_AIS_ERR_NOT_EXIST;
  2810. goto error_exit;
  2811. }
  2812. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2813. req_exec_ckpt_sectionoverwrite->data_size) {
  2814. error = SA_AIS_ERR_INVALID_PARAM;
  2815. goto error_exit;
  2816. }
  2817. /*
  2818. * Find checkpoint section to be overwritten
  2819. */
  2820. checkpoint_section = checkpoint_section_find (checkpoint,
  2821. ((char *)req_exec_ckpt_sectionoverwrite) +
  2822. sizeof (struct req_exec_ckpt_sectionoverwrite),
  2823. req_exec_ckpt_sectionoverwrite->id_len);
  2824. if (checkpoint_section == 0) {
  2825. error = SA_AIS_ERR_NOT_EXIST;
  2826. goto error_exit;
  2827. }
  2828. /*
  2829. * Allocate checkpoint section data
  2830. */
  2831. section_data = malloc (req_exec_ckpt_sectionoverwrite->data_size);
  2832. if (section_data == 0) {
  2833. error = SA_AIS_ERR_NO_MEMORY;
  2834. goto error_exit;
  2835. }
  2836. memcpy (section_data,
  2837. ((char *)req_exec_ckpt_sectionoverwrite) +
  2838. sizeof (struct req_exec_ckpt_sectionoverwrite) +
  2839. req_exec_ckpt_sectionoverwrite->id_len,
  2840. req_exec_ckpt_sectionoverwrite->data_size);
  2841. /*
  2842. * release old checkpoint section data
  2843. */
  2844. free (checkpoint_section->section_data);
  2845. /*
  2846. * Install overwritten checkpoint section data
  2847. */
  2848. checkpoint_section->section_descriptor.section_size =
  2849. req_exec_ckpt_sectionoverwrite->data_size;
  2850. checkpoint_section->section_descriptor.section_state =
  2851. SA_CKPT_SECTION_VALID;
  2852. /*
  2853. * TODO current time
  2854. */
  2855. checkpoint_section->section_descriptor.last_update = 0;
  2856. checkpoint_section->section_data = section_data;
  2857. /*
  2858. * return result to CKPT library
  2859. */
  2860. error_exit:
  2861. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2862. res_lib_ckpt_sectionoverwrite.header.size =
  2863. sizeof (struct res_lib_ckpt_sectionoverwrite);
  2864. res_lib_ckpt_sectionoverwrite.header.id =
  2865. MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2866. res_lib_ckpt_sectionoverwrite.header.error = error;
  2867. openais_conn_send_response (
  2868. req_exec_ckpt_sectionoverwrite->source.conn,
  2869. &res_lib_ckpt_sectionoverwrite,
  2870. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2871. }
  2872. }
  2873. static void message_handler_req_exec_ckpt_sectionread (
  2874. void *message,
  2875. unsigned int nodeid)
  2876. {
  2877. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2878. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2879. struct checkpoint *checkpoint;
  2880. struct checkpoint_section *checkpoint_section = 0;
  2881. int section_size = 0;
  2882. SaAisErrorT error = SA_AIS_OK;
  2883. res_lib_ckpt_sectionread.data_read = 0;
  2884. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2885. checkpoint = checkpoint_find (
  2886. &req_exec_ckpt_sectionread->checkpoint_name,
  2887. req_exec_ckpt_sectionread->ckpt_id);
  2888. if (checkpoint == 0) {
  2889. error = SA_AIS_ERR_LIBRARY;
  2890. goto error_exit;
  2891. }
  2892. if (checkpoint->active_replica_set == 0) {
  2893. error = SA_AIS_ERR_NOT_EXIST;
  2894. goto error_exit;
  2895. }
  2896. /*
  2897. * Find checkpoint section to be read
  2898. */
  2899. checkpoint_section = checkpoint_section_find (checkpoint,
  2900. ((char *)req_exec_ckpt_sectionread) +
  2901. sizeof (struct req_exec_ckpt_sectionread),
  2902. req_exec_ckpt_sectionread->id_len);
  2903. if (checkpoint_section == 0) {
  2904. error = SA_AIS_ERR_NOT_EXIST;
  2905. goto error_exit;
  2906. }
  2907. /*
  2908. * If data size is greater then max section size, return INVALID_PARAM
  2909. */
  2910. if (checkpoint->checkpoint_creation_attributes.max_section_size <
  2911. req_exec_ckpt_sectionread->data_size) {
  2912. error = SA_AIS_ERR_INVALID_PARAM;
  2913. goto error_exit;
  2914. }
  2915. /*
  2916. * If data_offset is past end of data, return INVALID_PARAM
  2917. */
  2918. if (req_exec_ckpt_sectionread->data_offset > checkpoint_section->section_descriptor.section_size) {
  2919. error = SA_AIS_ERR_INVALID_PARAM;
  2920. goto error_exit;
  2921. }
  2922. /*
  2923. * Determine the section size
  2924. */
  2925. section_size = checkpoint_section->section_descriptor.section_size -
  2926. req_exec_ckpt_sectionread->data_offset;
  2927. /*
  2928. * If the library has less space available then can be sent from the
  2929. * section, reduce bytes sent to library to max requested
  2930. */
  2931. if (section_size > req_exec_ckpt_sectionread->data_size) {
  2932. section_size = req_exec_ckpt_sectionread->data_size;
  2933. }
  2934. /*
  2935. * Write read response to CKPT library
  2936. */
  2937. error_exit:
  2938. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2939. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + section_size;
  2940. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2941. res_lib_ckpt_sectionread.header.error = error;
  2942. if (section_size != 0) {
  2943. res_lib_ckpt_sectionread.data_read = section_size;
  2944. }
  2945. openais_conn_send_response (
  2946. req_exec_ckpt_sectionread->source.conn,
  2947. &res_lib_ckpt_sectionread,
  2948. sizeof (struct res_lib_ckpt_sectionread));
  2949. /*
  2950. * Write checkpoint to CKPT library section if section has data
  2951. */
  2952. if (error == SA_AIS_OK) {
  2953. char *sd;
  2954. sd = (char *)checkpoint_section->section_data;
  2955. openais_conn_send_response (
  2956. req_exec_ckpt_sectionread->source.conn,
  2957. &sd[req_exec_ckpt_sectionread->data_offset],
  2958. section_size);
  2959. }
  2960. }
  2961. }
  2962. static int ckpt_lib_init_fn (void *conn)
  2963. {
  2964. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2965. hdb_create (&ckpt_pd->iteration_hdb);
  2966. /* TODO
  2967. list_add (&ckpt_pd->sectionIterator.list,
  2968. &checkpoint_iteration_list_head);
  2969. */
  2970. list_init (&ckpt_pd->checkpoint_list);
  2971. return (0);
  2972. }
  2973. static int ckpt_lib_exit_fn (void *conn)
  2974. {
  2975. struct checkpoint_cleanup *checkpoint_cleanup;
  2976. struct list_head *cleanup_list;
  2977. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2978. log_printf (LOG_LEVEL_DEBUG, "checkpoint exit conn %p\n", conn);
  2979. /*
  2980. * close all checkpoints opened on this connection
  2981. */
  2982. cleanup_list = ckpt_pd->checkpoint_list.next;
  2983. while (!list_empty(&ckpt_pd->checkpoint_list)) {
  2984. checkpoint_cleanup = list_entry (cleanup_list,
  2985. struct checkpoint_cleanup, list);
  2986. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  2987. ckpt_checkpoint_close (
  2988. &checkpoint_cleanup->checkpoint);
  2989. }
  2990. list_del (&checkpoint_cleanup->list);
  2991. free (checkpoint_cleanup);
  2992. cleanup_list = ckpt_pd->checkpoint_list.next;
  2993. }
  2994. /* TODO
  2995. if (ckpt_pd->sectionIterator.sectionIteratorEntries) {
  2996. free (ckpt_pd->sectionIterator.sectionIteratorEntries);
  2997. }
  2998. list_del (&ckpt_pd->sectionIterator.list);
  2999. */
  3000. return (0);
  3001. }
  3002. static void message_handler_req_lib_ckpt_checkpointopen (
  3003. void *conn,
  3004. void *msg)
  3005. {
  3006. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)msg;
  3007. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  3008. struct iovec iovec;
  3009. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  3010. req_exec_ckpt_checkpointopen.header.size =
  3011. sizeof (struct req_exec_ckpt_checkpointopen);
  3012. req_exec_ckpt_checkpointopen.header.id =
  3013. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN);
  3014. message_source_set (&req_exec_ckpt_checkpointopen.source, conn);
  3015. memcpy (&req_exec_ckpt_checkpointopen.checkpoint_name,
  3016. &req_lib_ckpt_checkpointopen->checkpoint_name,
  3017. sizeof (mar_name_t));
  3018. req_exec_ckpt_checkpointopen.ckpt_id =
  3019. req_lib_ckpt_checkpointopen->ckpt_id;
  3020. memcpy (&req_exec_ckpt_checkpointopen.checkpoint_creation_attributes,
  3021. &req_lib_ckpt_checkpointopen->checkpoint_creation_attributes,
  3022. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  3023. req_exec_ckpt_checkpointopen.checkpoint_creation_attributes_set =
  3024. req_lib_ckpt_checkpointopen->checkpoint_creation_attributes_set;
  3025. req_exec_ckpt_checkpointopen.checkpoint_open_flags =
  3026. req_lib_ckpt_checkpointopen->checkpoint_open_flags;
  3027. req_exec_ckpt_checkpointopen.invocation =
  3028. req_lib_ckpt_checkpointopen->invocation;
  3029. req_exec_ckpt_checkpointopen.checkpoint_handle =
  3030. req_lib_ckpt_checkpointopen->checkpoint_handle;
  3031. req_exec_ckpt_checkpointopen.fail_with_error =
  3032. req_lib_ckpt_checkpointopen->fail_with_error;
  3033. req_exec_ckpt_checkpointopen.async_call =
  3034. req_lib_ckpt_checkpointopen->async_call;
  3035. iovec.iov_base = (char *)&req_exec_ckpt_checkpointopen;
  3036. iovec.iov_len = sizeof (req_exec_ckpt_checkpointopen);
  3037. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3038. }
  3039. static void message_handler_req_lib_ckpt_checkpointclose (
  3040. void *conn,
  3041. void *msg)
  3042. {
  3043. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)msg;
  3044. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  3045. struct iovec iovec;
  3046. req_exec_ckpt_checkpointclose.header.size =
  3047. sizeof (struct req_exec_ckpt_checkpointclose);
  3048. req_exec_ckpt_checkpointclose.header.id =
  3049. SERVICE_ID_MAKE (CKPT_SERVICE,
  3050. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE);
  3051. message_source_set (&req_exec_ckpt_checkpointclose.source, conn);
  3052. memcpy (&req_exec_ckpt_checkpointclose.checkpoint_name,
  3053. &req_lib_ckpt_checkpointclose->checkpoint_name, sizeof (mar_name_t));
  3054. req_exec_ckpt_checkpointclose.ckpt_id =
  3055. req_lib_ckpt_checkpointclose->ckpt_id;
  3056. iovec.iov_base = (char *)&req_exec_ckpt_checkpointclose;
  3057. iovec.iov_len = sizeof (req_exec_ckpt_checkpointclose);
  3058. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3059. }
  3060. static void message_handler_req_lib_ckpt_checkpointunlink (
  3061. void *conn,
  3062. void *msg)
  3063. {
  3064. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)msg;
  3065. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  3066. struct iovec iovec;
  3067. req_exec_ckpt_checkpointunlink.header.size =
  3068. sizeof (struct req_exec_ckpt_checkpointunlink);
  3069. req_exec_ckpt_checkpointunlink.header.id =
  3070. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  3071. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn);
  3072. memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name,
  3073. &req_lib_ckpt_checkpointunlink->checkpoint_name,
  3074. sizeof (mar_name_t));
  3075. iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  3076. iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  3077. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  3078. TOTEMPG_AGREED) == 0);
  3079. }
  3080. static void message_handler_req_lib_ckpt_checkpointretentiondurationset (
  3081. void *conn,
  3082. void *msg)
  3083. {
  3084. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)msg;
  3085. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  3086. struct iovec iovec;
  3087. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API conn %p\n", conn);
  3088. req_exec_ckpt_checkpointretentiondurationset.header.id =
  3089. SERVICE_ID_MAKE (CKPT_SERVICE,
  3090. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET);
  3091. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  3092. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn);
  3093. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpoint_name,
  3094. &req_lib_ckpt_checkpointretentiondurationset->checkpoint_name,
  3095. sizeof (mar_name_t));
  3096. req_exec_ckpt_checkpointretentiondurationset.ckpt_id =
  3097. req_lib_ckpt_checkpointretentiondurationset->ckpt_id;
  3098. req_exec_ckpt_checkpointretentiondurationset.retention_duration =
  3099. req_lib_ckpt_checkpointretentiondurationset->retention_duration;
  3100. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  3101. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  3102. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  3103. TOTEMPG_AGREED) == 0);
  3104. }
  3105. static void message_handler_req_lib_ckpt_activereplicaset (
  3106. void *conn,
  3107. void *msg)
  3108. {
  3109. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)msg;
  3110. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  3111. struct checkpoint *checkpoint;
  3112. SaAisErrorT error = SA_AIS_OK;
  3113. checkpoint = checkpoint_find (
  3114. &req_lib_ckpt_activereplicaset->checkpoint_name,
  3115. req_lib_ckpt_activereplicaset->ckpt_id);
  3116. /*
  3117. * Make sure checkpoint is collocated and async update option
  3118. */
  3119. if (((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  3120. (checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3121. error = SA_AIS_ERR_BAD_OPERATION;
  3122. }
  3123. checkpoint->active_replica_set = 1;
  3124. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  3125. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  3126. res_lib_ckpt_activereplicaset.header.error = error;
  3127. openais_conn_send_response (
  3128. conn,
  3129. &res_lib_ckpt_activereplicaset,
  3130. sizeof (struct res_lib_ckpt_activereplicaset));
  3131. }
  3132. static void message_handler_req_lib_ckpt_checkpointstatusget (
  3133. void *conn,
  3134. void *msg)
  3135. {
  3136. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)msg;
  3137. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  3138. struct checkpoint *checkpoint;
  3139. int memory_used = 0;
  3140. int number_of_sections = 0;
  3141. struct list_head *checkpoint_section_list;
  3142. struct checkpoint_section *checkpointSection;
  3143. /*
  3144. * Count memory used by checkpoint sections
  3145. */
  3146. checkpoint = checkpoint_find (
  3147. &req_lib_ckpt_checkpointstatusget->checkpoint_name,
  3148. req_lib_ckpt_checkpointstatusget->ckpt_id);
  3149. if (checkpoint && (checkpoint->expired == 0)) {
  3150. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  3151. checkpoint_section_list != &checkpoint->sections_list_head;
  3152. checkpoint_section_list = checkpoint_section_list->next) {
  3153. checkpointSection = list_entry (checkpoint_section_list,
  3154. struct checkpoint_section, list);
  3155. memory_used += checkpointSection->section_descriptor.section_size;
  3156. number_of_sections += 1;
  3157. }
  3158. /*
  3159. * Build checkpoint status get response
  3160. */
  3161. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  3162. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  3163. if (checkpoint->active_replica_set == 1) {
  3164. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  3165. } else {
  3166. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  3167. }
  3168. memcpy (&res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.checkpoint_creation_attributes,
  3169. &checkpoint->checkpoint_creation_attributes,
  3170. sizeof (mar_ckpt_checkpoint_creation_attributes_t));
  3171. res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.number_of_sections = number_of_sections;
  3172. res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.memory_used = memory_used;
  3173. }
  3174. else {
  3175. log_printf (LOG_LEVEL_ERROR, "#### Could Not Find the Checkpoint's status so Returning Error. ####\n");
  3176. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  3177. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  3178. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  3179. }
  3180. openais_conn_send_response (
  3181. conn,
  3182. &res_lib_ckpt_checkpointstatusget,
  3183. sizeof (struct res_lib_ckpt_checkpointstatusget));
  3184. }
  3185. static void message_handler_req_lib_ckpt_sectioncreate (
  3186. void *conn,
  3187. void *msg)
  3188. {
  3189. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)msg;
  3190. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  3191. struct iovec iovecs[2];
  3192. log_printf (LOG_LEVEL_DEBUG, "Section create from conn %p\n", conn);
  3193. req_exec_ckpt_sectioncreate.header.id =
  3194. SERVICE_ID_MAKE (CKPT_SERVICE,
  3195. MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE);
  3196. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  3197. message_source_set (&req_exec_ckpt_sectioncreate.source, conn);
  3198. memcpy (&req_exec_ckpt_sectioncreate.checkpoint_name,
  3199. &req_lib_ckpt_sectioncreate->checkpoint_name,
  3200. sizeof (mar_name_t));
  3201. req_exec_ckpt_sectioncreate.ckpt_id =
  3202. req_lib_ckpt_sectioncreate->ckpt_id;
  3203. req_exec_ckpt_sectioncreate.id_len = req_lib_ckpt_sectioncreate->id_len;
  3204. req_exec_ckpt_sectioncreate.expiration_time =
  3205. req_lib_ckpt_sectioncreate->expiration_time;
  3206. req_exec_ckpt_sectioncreate.initial_data_size =
  3207. req_lib_ckpt_sectioncreate->initial_data_size;
  3208. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  3209. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  3210. /*
  3211. * Send section name and initial data in message
  3212. */
  3213. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  3214. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  3215. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  3216. if (iovecs[1].iov_len) {
  3217. log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_ckpt_sectioncreate Section = %p, id_len = %d\n",
  3218. iovecs[1].iov_base,
  3219. (int)iovecs[1].iov_len);
  3220. }
  3221. if (iovecs[1].iov_len > 0) {
  3222. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  3223. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3224. } else {
  3225. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3226. }
  3227. }
  3228. static void message_handler_req_lib_ckpt_sectiondelete (
  3229. void *conn,
  3230. void *msg)
  3231. {
  3232. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)msg;
  3233. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  3234. struct iovec iovecs[2];
  3235. log_printf (LOG_LEVEL_DEBUG, "section delete from conn %p\n", conn);
  3236. req_exec_ckpt_sectiondelete.header.id =
  3237. SERVICE_ID_MAKE (CKPT_SERVICE,
  3238. MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE);
  3239. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  3240. message_source_set (&req_exec_ckpt_sectiondelete.source, conn);
  3241. memcpy (&req_exec_ckpt_sectiondelete.checkpoint_name,
  3242. &req_lib_ckpt_sectiondelete->checkpoint_name,
  3243. sizeof (mar_name_t));
  3244. req_exec_ckpt_sectiondelete.ckpt_id =
  3245. req_lib_ckpt_sectiondelete->ckpt_id;
  3246. req_exec_ckpt_sectiondelete.id_len = req_lib_ckpt_sectiondelete->id_len;
  3247. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  3248. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  3249. /*
  3250. * Send section name
  3251. */
  3252. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) +
  3253. sizeof (struct req_lib_ckpt_sectiondelete);
  3254. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size -
  3255. sizeof (struct req_lib_ckpt_sectiondelete);
  3256. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  3257. if (iovecs[1].iov_len > 0) {
  3258. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3259. } else {
  3260. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3261. }
  3262. }
  3263. static void message_handler_req_lib_ckpt_sectionexpirationtimeset (
  3264. void *conn,
  3265. void *msg)
  3266. {
  3267. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)msg;
  3268. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  3269. struct iovec iovecs[2];
  3270. log_printf (LOG_LEVEL_DEBUG, "section expiration time set from conn %p\n", conn);
  3271. req_exec_ckpt_sectionexpirationtimeset.header.id =
  3272. SERVICE_ID_MAKE (CKPT_SERVICE,
  3273. MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET);
  3274. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  3275. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn);
  3276. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpoint_name,
  3277. &req_lib_ckpt_sectionexpirationtimeset->checkpoint_name,
  3278. sizeof (mar_name_t));
  3279. req_exec_ckpt_sectionexpirationtimeset.ckpt_id =
  3280. req_lib_ckpt_sectionexpirationtimeset->ckpt_id;
  3281. req_exec_ckpt_sectionexpirationtimeset.id_len =
  3282. req_lib_ckpt_sectionexpirationtimeset->id_len;
  3283. req_exec_ckpt_sectionexpirationtimeset.expiration_time =
  3284. req_lib_ckpt_sectionexpirationtimeset->expiration_time;
  3285. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  3286. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  3287. /*
  3288. * Send section name
  3289. */
  3290. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  3291. sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  3292. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size -
  3293. sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  3294. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  3295. if (iovecs[1].iov_len > 0) {
  3296. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3297. } else {
  3298. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3299. }
  3300. }
  3301. static void message_handler_req_lib_ckpt_sectionwrite (
  3302. void *conn,
  3303. void *msg)
  3304. {
  3305. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)msg;
  3306. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  3307. struct iovec iovecs[2];
  3308. log_printf (LOG_LEVEL_DEBUG, "Received data from lib with len = %d and ref = 0x%lx\n",
  3309. (int)req_lib_ckpt_sectionwrite->data_size,
  3310. (long)req_lib_ckpt_sectionwrite->data_offset);
  3311. log_printf (LOG_LEVEL_DEBUG, "Checkpoint section being written to is %s, id_len = %d\n",
  3312. ((char *)req_lib_ckpt_sectionwrite) +
  3313. sizeof (struct req_lib_ckpt_sectionwrite),
  3314. req_lib_ckpt_sectionwrite->id_len);
  3315. log_printf (LOG_LEVEL_DEBUG, "Section write from conn %p\n", conn);
  3316. /*
  3317. * checkpoint opened is writeable mode so send message to cluster
  3318. */
  3319. req_exec_ckpt_sectionwrite.header.id =
  3320. SERVICE_ID_MAKE (CKPT_SERVICE,
  3321. MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE);
  3322. req_exec_ckpt_sectionwrite.header.size =
  3323. sizeof (struct req_exec_ckpt_sectionwrite);
  3324. message_source_set (&req_exec_ckpt_sectionwrite.source, conn);
  3325. memcpy (&req_exec_ckpt_sectionwrite.checkpoint_name,
  3326. &req_lib_ckpt_sectionwrite->checkpoint_name,
  3327. sizeof (mar_name_t));
  3328. req_exec_ckpt_sectionwrite.ckpt_id =
  3329. req_lib_ckpt_sectionwrite->ckpt_id;
  3330. req_exec_ckpt_sectionwrite.id_len =
  3331. req_lib_ckpt_sectionwrite->id_len;
  3332. req_exec_ckpt_sectionwrite.data_offset =
  3333. req_lib_ckpt_sectionwrite->data_offset;
  3334. req_exec_ckpt_sectionwrite.data_size =
  3335. req_lib_ckpt_sectionwrite->data_size;
  3336. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  3337. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  3338. /*
  3339. * Send section name and data to write in message
  3340. */
  3341. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) +
  3342. sizeof (struct req_lib_ckpt_sectionwrite);
  3343. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size -
  3344. sizeof (struct req_lib_ckpt_sectionwrite);
  3345. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  3346. if (iovecs[1].iov_len > 0) {
  3347. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3348. } else {
  3349. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3350. }
  3351. }
  3352. static void message_handler_req_lib_ckpt_sectionoverwrite (
  3353. void *conn,
  3354. void *msg)
  3355. {
  3356. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)msg;
  3357. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  3358. struct iovec iovecs[2];
  3359. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from conn %p\n", conn);
  3360. req_exec_ckpt_sectionoverwrite.header.id =
  3361. SERVICE_ID_MAKE (CKPT_SERVICE,
  3362. MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE);
  3363. req_exec_ckpt_sectionoverwrite.header.size =
  3364. sizeof (struct req_exec_ckpt_sectionoverwrite);
  3365. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn);
  3366. memcpy (&req_exec_ckpt_sectionoverwrite.checkpoint_name,
  3367. &req_lib_ckpt_sectionoverwrite->checkpoint_name,
  3368. sizeof (mar_name_t));
  3369. req_exec_ckpt_sectionoverwrite.ckpt_id =
  3370. req_lib_ckpt_sectionoverwrite->ckpt_id;
  3371. req_exec_ckpt_sectionoverwrite.id_len =
  3372. req_lib_ckpt_sectionoverwrite->id_len;
  3373. req_exec_ckpt_sectionoverwrite.data_size =
  3374. req_lib_ckpt_sectionoverwrite->data_size;
  3375. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  3376. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  3377. /*
  3378. * Send section name and data to overwrite in message
  3379. */
  3380. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) +
  3381. sizeof (struct req_lib_ckpt_sectionoverwrite);
  3382. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size -
  3383. sizeof (struct req_lib_ckpt_sectionoverwrite);
  3384. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  3385. if (iovecs[1].iov_len > 0) {
  3386. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3387. } else {
  3388. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3389. }
  3390. }
  3391. static void message_handler_req_lib_ckpt_sectionread (
  3392. void *conn,
  3393. void *msg)
  3394. {
  3395. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)msg;
  3396. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  3397. struct iovec iovecs[2];
  3398. log_printf (LOG_LEVEL_DEBUG, "Section read from conn %p\n", conn);
  3399. /*
  3400. * checkpoint opened is writeable mode so send message to cluster
  3401. */
  3402. req_exec_ckpt_sectionread.header.id =
  3403. SERVICE_ID_MAKE (CKPT_SERVICE,
  3404. MESSAGE_REQ_EXEC_CKPT_SECTIONREAD);
  3405. req_exec_ckpt_sectionread.header.size =
  3406. sizeof (struct req_exec_ckpt_sectionread);
  3407. message_source_set (&req_exec_ckpt_sectionread.source, conn);
  3408. memcpy (&req_exec_ckpt_sectionread.checkpoint_name,
  3409. &req_lib_ckpt_sectionread->checkpoint_name,
  3410. sizeof (mar_name_t));
  3411. req_exec_ckpt_sectionread.ckpt_id =
  3412. req_lib_ckpt_sectionread->ckpt_id;
  3413. req_exec_ckpt_sectionread.id_len =
  3414. req_lib_ckpt_sectionread->id_len;
  3415. req_exec_ckpt_sectionread.data_offset =
  3416. req_lib_ckpt_sectionread->data_offset;
  3417. req_exec_ckpt_sectionread.data_size =
  3418. req_lib_ckpt_sectionread->data_size;
  3419. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  3420. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  3421. /*
  3422. * Send section name and data to overwrite in message
  3423. */
  3424. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) +
  3425. sizeof (struct req_lib_ckpt_sectionread);
  3426. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size -
  3427. sizeof (struct req_lib_ckpt_sectionread);
  3428. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  3429. if (iovecs[1].iov_len > 0) {
  3430. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3431. } else {
  3432. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3433. }
  3434. }
  3435. static void message_handler_req_lib_ckpt_checkpointsynchronize (
  3436. void *conn,
  3437. void *msg)
  3438. {
  3439. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)msg;
  3440. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  3441. struct checkpoint *checkpoint;
  3442. checkpoint = checkpoint_find (
  3443. &req_lib_ckpt_checkpointsynchronize->checkpoint_name,
  3444. req_lib_ckpt_checkpointsynchronize->ckpt_id);
  3445. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3446. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  3447. } else
  3448. if (checkpoint->active_replica_set == 1) {
  3449. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  3450. } else {
  3451. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  3452. }
  3453. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  3454. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  3455. openais_conn_send_response (
  3456. conn,
  3457. &res_lib_ckpt_checkpointsynchronize,
  3458. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  3459. }
  3460. static void message_handler_req_lib_ckpt_checkpointsynchronizeasync (
  3461. void *conn,
  3462. void *msg)
  3463. {
  3464. struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)msg;
  3465. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  3466. struct checkpoint *checkpoint;
  3467. checkpoint = checkpoint_find (
  3468. &req_lib_ckpt_checkpointsynchronizeasync->checkpoint_name,
  3469. req_lib_ckpt_checkpointsynchronizeasync->ckpt_id);
  3470. if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3471. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION;
  3472. } else
  3473. if (checkpoint->active_replica_set == 1) {
  3474. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK;
  3475. } else {
  3476. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST;
  3477. }
  3478. res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync);
  3479. res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  3480. res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation;
  3481. openais_conn_send_response (
  3482. conn,
  3483. &res_lib_ckpt_checkpointsynchronizeasync,
  3484. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3485. openais_conn_send_response (
  3486. openais_conn_partner_get (conn),
  3487. &res_lib_ckpt_checkpointsynchronizeasync,
  3488. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3489. }
  3490. static void message_handler_req_lib_ckpt_sectioniterationinitialize (
  3491. void *conn,
  3492. void *msg)
  3493. {
  3494. struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)msg;
  3495. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  3496. struct checkpoint *checkpoint;
  3497. struct checkpoint_section *checkpoint_section;
  3498. struct iteration_entry *iteration_entries;
  3499. struct list_head *section_list;
  3500. struct iteration_instance *iteration_instance;
  3501. void *iteration_instance_p;
  3502. unsigned int iteration_handle = 0;
  3503. int res;
  3504. SaAisErrorT error = SA_AIS_OK;
  3505. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3506. log_printf (LOG_LEVEL_DEBUG, "section iteration initialize\n");
  3507. checkpoint = checkpoint_find (
  3508. &req_lib_ckpt_sectioniterationinitialize->checkpoint_name,
  3509. req_lib_ckpt_sectioniterationinitialize->ckpt_id);
  3510. if (checkpoint == 0) {
  3511. error = SA_AIS_ERR_NOT_EXIST;
  3512. goto error_exit;
  3513. }
  3514. if (checkpoint->active_replica_set == 0) {
  3515. log_printf (LOG_LEVEL_DEBUG, "iterationinitialize: no active replica, returning error.\n");
  3516. error = SA_AIS_ERR_NOT_EXIST;
  3517. goto error_exit;
  3518. }
  3519. res = hdb_handle_create (&ckpt_pd->iteration_hdb, sizeof(struct iteration_instance),
  3520. &iteration_handle);
  3521. if (res != 0) {
  3522. goto error_exit;
  3523. }
  3524. res = hdb_handle_get (&ckpt_pd->iteration_hdb, iteration_handle,
  3525. &iteration_instance_p);
  3526. if (res != 0) {
  3527. hdb_handle_destroy (&ckpt_pd->iteration_hdb, iteration_handle);
  3528. goto error_exit;
  3529. }
  3530. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3531. iteration_instance->iteration_entries = NULL;
  3532. iteration_instance->iteration_entries_count = 0;
  3533. iteration_instance->iteration_pos = 0;
  3534. /*
  3535. * Iterate list of checkpoint sections
  3536. */
  3537. for (section_list = checkpoint->sections_list_head.next;
  3538. section_list != &checkpoint->sections_list_head;
  3539. section_list = section_list->next) {
  3540. checkpoint_section = list_entry (section_list,
  3541. struct checkpoint_section, list);
  3542. switch (req_lib_ckpt_sectioniterationinitialize->sections_chosen) {
  3543. case SA_CKPT_SECTIONS_FOREVER:
  3544. if (checkpoint_section->section_descriptor.expiration_time != SA_TIME_END) {
  3545. continue;
  3546. }
  3547. break;
  3548. case SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME:
  3549. if (checkpoint_section->section_descriptor.expiration_time > req_lib_ckpt_sectioniterationinitialize->expiration_time) {
  3550. continue;
  3551. }
  3552. break;
  3553. case SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME:
  3554. if (checkpoint_section->section_descriptor.expiration_time < req_lib_ckpt_sectioniterationinitialize->expiration_time) {
  3555. continue;
  3556. }
  3557. break;
  3558. case SA_CKPT_SECTIONS_CORRUPTED:
  3559. /* there can be no corrupted sections - do nothing */
  3560. break;
  3561. case SA_CKPT_SECTIONS_ANY:
  3562. /* iterate all sections - do nothing */
  3563. break;
  3564. }
  3565. iteration_instance->iteration_entries_count += 1;
  3566. iteration_entries = realloc (iteration_instance->iteration_entries,
  3567. sizeof (struct iteration_entry) * iteration_instance->iteration_entries_count);
  3568. if (iteration_entries == NULL) {
  3569. error = SA_AIS_ERR_NO_MEMORY;
  3570. goto error_put;
  3571. }
  3572. iteration_instance->iteration_entries = iteration_entries;
  3573. iteration_entries[iteration_instance->iteration_entries_count - 1].active = 1;
  3574. iteration_entries[iteration_instance->iteration_entries_count - 1].checkpoint_section = checkpoint_section;
  3575. }
  3576. error_put:
  3577. hdb_handle_put (&ckpt_pd->iteration_hdb, iteration_handle);
  3578. error_exit:
  3579. res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize);
  3580. res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE;
  3581. res_lib_ckpt_sectioniterationinitialize.header.error = error;
  3582. res_lib_ckpt_sectioniterationinitialize.iteration_handle = iteration_handle;
  3583. res_lib_ckpt_sectioniterationinitialize.max_section_id_size =
  3584. checkpoint->checkpoint_creation_attributes.max_section_id_size;
  3585. openais_conn_send_response (
  3586. conn,
  3587. &res_lib_ckpt_sectioniterationinitialize,
  3588. sizeof (struct res_lib_ckpt_sectioniterationinitialize));
  3589. }
  3590. static void message_handler_req_lib_ckpt_sectioniterationfinalize (
  3591. void *conn,
  3592. void *msg)
  3593. {
  3594. struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)msg;
  3595. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  3596. SaAisErrorT error = SA_AIS_OK;
  3597. struct iteration_instance *iteration_instance;
  3598. void *iteration_instance_p;
  3599. unsigned int res;
  3600. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3601. res = hdb_handle_get (&ckpt_pd->iteration_hdb,
  3602. req_lib_ckpt_sectioniterationfinalize->iteration_handle,
  3603. &iteration_instance_p);
  3604. if (res != 0) {
  3605. error = SA_AIS_ERR_LIBRARY;
  3606. goto error_exit;
  3607. }
  3608. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3609. free (iteration_instance->iteration_entries);
  3610. hdb_handle_put (&ckpt_pd->iteration_hdb,
  3611. req_lib_ckpt_sectioniterationfinalize->iteration_handle);
  3612. hdb_handle_destroy (&ckpt_pd->iteration_hdb,
  3613. req_lib_ckpt_sectioniterationfinalize->iteration_handle);
  3614. hdb_destroy (&ckpt_pd->iteration_hdb);
  3615. error_exit:
  3616. res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize);
  3617. res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE;
  3618. res_lib_ckpt_sectioniterationfinalize.header.error = error;
  3619. openais_conn_send_response (
  3620. conn,
  3621. &res_lib_ckpt_sectioniterationfinalize,
  3622. sizeof (struct res_lib_ckpt_sectioniterationfinalize));
  3623. }
  3624. static void message_handler_req_lib_ckpt_sectioniterationnext (
  3625. void *conn,
  3626. void *msg)
  3627. {
  3628. struct req_lib_ckpt_sectioniterationnext *req_lib_ckpt_sectioniterationnext = (struct req_lib_ckpt_sectioniterationnext *)msg;
  3629. struct res_lib_ckpt_sectioniterationnext res_lib_ckpt_sectioniterationnext;
  3630. SaAisErrorT error = SA_AIS_OK;
  3631. int section_id_size = 0;
  3632. unsigned int res;
  3633. struct iteration_instance *iteration_instance = NULL;
  3634. void *iteration_instance_p;
  3635. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3636. log_printf (LOG_LEVEL_DEBUG, "section iteration next\n");
  3637. res = hdb_handle_get (&ckpt_pd->iteration_hdb,
  3638. req_lib_ckpt_sectioniterationnext->iteration_handle,
  3639. &iteration_instance_p);
  3640. if (res != 0) {
  3641. error = SA_AIS_ERR_LIBRARY;
  3642. goto error_exit;
  3643. }
  3644. iteration_instance = (struct iteration_instance *)iteration_instance_p;
  3645. /*
  3646. * Find active iteration entry
  3647. */
  3648. for (;;) {
  3649. /*
  3650. * No more sections in iteration
  3651. */
  3652. if (iteration_instance->iteration_pos == iteration_instance->iteration_entries_count) {
  3653. error = SA_AIS_ERR_NO_SECTIONS;
  3654. goto error_put;
  3655. }
  3656. /*
  3657. * active iteration entry
  3658. */
  3659. if (iteration_instance->iteration_entries[iteration_instance->iteration_pos].active == 1) {
  3660. break;
  3661. }
  3662. iteration_instance->iteration_pos += 1;
  3663. }
  3664. /*
  3665. * Prepare response to API
  3666. */
  3667. section_id_size = iteration_instance->iteration_entries[iteration_instance->iteration_pos].checkpoint_section->section_descriptor.section_id.id_len;
  3668. memcpy (&res_lib_ckpt_sectioniterationnext.section_descriptor,
  3669. &iteration_instance->iteration_entries[iteration_instance->iteration_pos].checkpoint_section->section_descriptor,
  3670. sizeof (mar_ckpt_section_descriptor_t));
  3671. /*
  3672. * Get to next iteration entry
  3673. */
  3674. iteration_instance->iteration_pos += 1;
  3675. error_put:
  3676. hdb_handle_put (&ckpt_pd->iteration_hdb, req_lib_ckpt_sectioniterationnext->iteration_handle);
  3677. error_exit:
  3678. res_lib_ckpt_sectioniterationnext.header.size = sizeof (struct res_lib_ckpt_sectioniterationnext) + section_id_size;
  3679. res_lib_ckpt_sectioniterationnext.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONNEXT;
  3680. res_lib_ckpt_sectioniterationnext.header.error = error;
  3681. openais_conn_send_response (
  3682. conn,
  3683. &res_lib_ckpt_sectioniterationnext,
  3684. sizeof (struct res_lib_ckpt_sectioniterationnext));
  3685. if (error == SA_AIS_OK) {
  3686. openais_conn_send_response (
  3687. conn,
  3688. iteration_instance->iteration_entries[
  3689. iteration_instance->iteration_pos - 1].
  3690. checkpoint_section->section_descriptor.section_id.id,
  3691. section_id_size);
  3692. }
  3693. }
  3694. static void dump_fn (void)
  3695. {
  3696. #ifdef DEBUG
  3697. struct list_head *checkpoint_list;
  3698. struct checkpoint *checkpoint;
  3699. struct list_head *checkpoint_section_list;
  3700. struct checkpoint_section *section;
  3701. log_printf (LOG_LEVEL_NOTICE,
  3702. "========== Checkpoint Information ===========");
  3703. log_printf (LOG_LEVEL_NOTICE, "global_ckpt_id: %u", global_ckpt_id);
  3704. for (checkpoint_list = checkpoint_list_head.next;
  3705. checkpoint_list != &checkpoint_list_head;
  3706. checkpoint_list = checkpoint_list->next) {
  3707. checkpoint = list_entry (checkpoint_list, struct checkpoint, list);
  3708. if (checkpoint == NULL) {
  3709. return;
  3710. }
  3711. log_printf (LOG_LEVEL_NOTICE, "Checkpoint %s (%d):",
  3712. checkpoint->name.value, checkpoint->name.length);
  3713. log_printf (LOG_LEVEL_NOTICE, " id: %u", checkpoint->ckpt_id);
  3714. log_printf (LOG_LEVEL_NOTICE, " sec cnt: %u", checkpoint->sectionCount);
  3715. log_printf (LOG_LEVEL_NOTICE, " ref cnt: %u", checkpoint->referenceCount);
  3716. log_printf (LOG_LEVEL_NOTICE, " unlinked: %u", checkpoint->unlinked);
  3717. for (checkpoint_section_list = checkpoint->sections_list_head.next;
  3718. checkpoint_section_list != &checkpoint->sections_list_head;
  3719. checkpoint_section_list = checkpoint_section_list->next) {
  3720. section = list_entry (checkpoint_section_list,
  3721. struct checkpoint_section, list);
  3722. log_printf (LOG_LEVEL_NOTICE, " Section %s (%d)",
  3723. section->section_descriptor.section_id.id,
  3724. section->section_descriptor.section_id.id_len);
  3725. log_printf (LOG_LEVEL_NOTICE, " size: %llu",
  3726. section->section_descriptor.section_size);
  3727. log_printf (LOG_LEVEL_NOTICE, " state: %u",
  3728. section->section_descriptor.section_state);
  3729. log_printf (LOG_LEVEL_NOTICE, " exp time: %llu",
  3730. section->section_descriptor.expiration_time);
  3731. }
  3732. }
  3733. #endif
  3734. }