ckpt.c 137 KB

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