ckpt.c 143 KB

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