ckpt.c 137 KB

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