ckpt.c 143 KB

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