4
0

ckpt.c 137 KB

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