ckpt.c 128 KB

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