ckpt.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399
  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_section_release (section);
  1068. }
  1069. list_del (&checkpoint->list);
  1070. free (checkpoint);
  1071. }
  1072. int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
  1073. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1074. struct iovec iovecs[2];
  1075. if (checkpoint->expired == 1) {
  1076. return (0);
  1077. }
  1078. req_exec_ckpt_checkpointclose.header.size =
  1079. sizeof (struct req_exec_ckpt_checkpointclose);
  1080. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1081. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1082. &checkpoint->name, sizeof (SaNameT));
  1083. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1084. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1085. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1086. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1087. return (0);
  1088. }
  1089. return (-1);
  1090. }
  1091. static int ckpt_exec_init_fn (struct openais_config *openais_config)
  1092. {
  1093. /*
  1094. * Initialize the saved ring ID.
  1095. */
  1096. saved_ring_id.seq = 0;
  1097. saved_ring_id.rep.s_addr = this_ip->sin_addr.s_addr;
  1098. #ifdef TODO
  1099. int res;
  1100. res = totempg_recovery_plug_create (&ckpt_checkpoint_recovery_plug_handle);
  1101. if (res != 0) {
  1102. log_printf(LOG_LEVEL_ERROR,
  1103. "Could not create recovery plug for clm service.\n");
  1104. return (-1);
  1105. }
  1106. #endif
  1107. return (0);
  1108. }
  1109. static int ckpt_exit_fn (struct conn_info *conn_info)
  1110. {
  1111. struct checkpoint_cleanup *checkpoint_cleanup;
  1112. struct list_head *cleanup_list;
  1113. if (conn_info->conn_info_partner->service != CKPT_SERVICE) {
  1114. return 0;
  1115. }
  1116. log_printf(LOG_LEVEL_DEBUG, "ckpt_exit_fn conn_info = %#x, with fd = %d\n", conn_info, conn_info->fd);
  1117. /*
  1118. * close all checkpoints opened on this fd
  1119. */
  1120. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1121. while (!list_empty(&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list)) {
  1122. checkpoint_cleanup = list_entry (cleanup_list,
  1123. struct checkpoint_cleanup, list);
  1124. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  1125. ckpt_checkpoint_close (&checkpoint_cleanup->checkpoint);
  1126. }
  1127. list_del (&checkpoint_cleanup->list);
  1128. free (checkpoint_cleanup);
  1129. cleanup_list = conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list.next;
  1130. }
  1131. if (conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  1132. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  1133. }
  1134. list_del (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list);
  1135. return (0);
  1136. }
  1137. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  1138. {
  1139. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  1140. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  1141. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  1142. struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync;
  1143. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1144. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1145. struct checkpoint_cleanup *checkpoint_cleanup;
  1146. SaErrorT error = SA_AIS_OK;
  1147. int proc_index;
  1148. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  1149. if (req_exec_ckpt_checkpointopen->fail_with_error != SA_AIS_OK) {
  1150. error = req_exec_ckpt_checkpointopen->fail_with_error;
  1151. goto error_exit;
  1152. }
  1153. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  1154. /*
  1155. * If checkpoint doesn't exist, create one
  1156. */
  1157. if (ckptCheckpoint == 0) {
  1158. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1159. error = SA_AIS_ERR_NOT_EXIST;
  1160. goto error_exit;
  1161. }
  1162. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1163. if (ckptCheckpoint == 0) {
  1164. error = SA_AIS_ERR_NO_MEMORY;
  1165. goto error_exit;
  1166. }
  1167. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1168. if (ckptCheckpointSection == 0) {
  1169. free (ckptCheckpoint);
  1170. error = SA_AIS_ERR_NO_MEMORY;
  1171. goto error_exit;
  1172. }
  1173. memcpy (&ckptCheckpoint->name,
  1174. &req_lib_ckpt_checkpointopen->checkpointName,
  1175. sizeof (SaNameT));
  1176. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1177. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1178. sizeof (SaCkptCheckpointCreationAttributesT));
  1179. ckptCheckpoint->unlinked = 0;
  1180. list_init (&ckptCheckpoint->list);
  1181. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1182. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1183. ckptCheckpoint->referenceCount = 0;
  1184. ckptCheckpoint->retention_timer = 0;
  1185. ckptCheckpoint->expired = 0;
  1186. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1187. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1188. ckptCheckpoint->active_replica_set = 1;
  1189. } else
  1190. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1191. ckptCheckpoint->active_replica_set = 1;
  1192. } else {
  1193. ckptCheckpoint->active_replica_set = 0;
  1194. }
  1195. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1196. /*
  1197. * Add in default checkpoint section
  1198. */
  1199. list_init (&ckptCheckpointSection->list);
  1200. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1201. /*
  1202. * Default section id
  1203. */
  1204. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1205. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1206. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1207. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1208. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1209. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1210. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1211. assert(ckptCheckpointSection->sectionData);
  1212. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1213. ckptCheckpointSection->expiration_timer = 0;
  1214. } else {
  1215. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  1216. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  1217. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1218. sizeof (SaCkptCheckpointCreationAttributesT)) != 0) {
  1219. error = SA_AIS_ERR_EXIST;
  1220. goto error_exit;
  1221. }
  1222. }
  1223. /*
  1224. * If the checkpoint has been unlinked, it is an invalid name
  1225. */
  1226. if (ckptCheckpoint->unlinked) {
  1227. error = SA_AIS_ERR_NOT_EXIST; /* Is this the correct return ? */
  1228. goto error_exit;
  1229. }
  1230. /*
  1231. * Setup connection information and mark checkpoint as referenced
  1232. */
  1233. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  1234. ckptCheckpoint->referenceCount += 1;
  1235. /*
  1236. * Add the connection reference information to the Checkpoint to be
  1237. * sent out later as a part of the sync process.
  1238. *
  1239. */
  1240. proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  1241. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1242. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  1243. }
  1244. if (proc_index != -1 ) {
  1245. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  1246. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  1247. }
  1248. else {
  1249. log_printf (LOG_LEVEL_ERROR,
  1250. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1251. ckptCheckpoint);
  1252. }
  1253. /*
  1254. * Reset retention duration since this checkpoint was just opened
  1255. */
  1256. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1257. ckptCheckpoint->retention_timer = 0;
  1258. /*
  1259. * Send error result to CKPT library
  1260. */
  1261. error_exit:
  1262. /*
  1263. * If this node was the source of the message, respond to this node
  1264. */
  1265. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1266. /*
  1267. * If its an async call respond with the invocation and handle
  1268. */
  1269. if (req_exec_ckpt_checkpointopen->async_call) {
  1270. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1271. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1272. res_lib_ckpt_checkpointopenasync.header.error = error;
  1273. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  1274. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1275. libais_send_response (
  1276. req_exec_ckpt_checkpointopen->source.conn_info,
  1277. &res_lib_ckpt_checkpointopenasync,
  1278. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1279. libais_send_response (
  1280. req_exec_ckpt_checkpointopen->source.conn_info->conn_info_partner,
  1281. &res_lib_ckpt_checkpointopenasync,
  1282. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1283. } else {
  1284. /*
  1285. * otherwise respond with the normal checkpointopen response
  1286. */
  1287. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1288. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1289. res_lib_ckpt_checkpointopen.header.error = error;
  1290. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  1291. sizeof (struct res_lib_ckpt_checkpointopen));
  1292. }
  1293. if (error == SA_AIS_OK) {
  1294. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  1295. if (checkpoint_cleanup == 0) {
  1296. free (ckptCheckpoint);
  1297. error = SA_AIS_ERR_NO_MEMORY;
  1298. } else {
  1299. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1300. list_add (&checkpoint_cleanup->list,
  1301. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1302. }
  1303. }
  1304. }
  1305. return (0);
  1306. }
  1307. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1308. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1309. struct ckpt_refcnt *ref_cnt)
  1310. {
  1311. int i;
  1312. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1313. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1314. SaErrorT error = SA_AIS_OK;
  1315. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1316. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1317. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1318. if (ref_cnt[i].addr.s_addr == 0) {
  1319. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1320. ref_cnt[i].count);
  1321. }
  1322. else {
  1323. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1324. i,
  1325. inet_ntoa(ref_cnt[i].addr),
  1326. ref_cnt[i].count);
  1327. }
  1328. }
  1329. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1330. /*
  1331. * If checkpoint doesn't exist, create one
  1332. */
  1333. if (ckptCheckpoint == 0) {
  1334. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1335. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1336. if (ckptCheckpoint == 0) {
  1337. error = SA_AIS_ERR_NO_MEMORY;
  1338. goto error_exit;
  1339. }
  1340. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1341. if (ckptCheckpointSection == 0) {
  1342. free (ckptCheckpoint);
  1343. error = SA_AIS_ERR_NO_MEMORY;
  1344. goto error_exit;
  1345. }
  1346. memcpy (&ckptCheckpoint->name,
  1347. checkpointName,
  1348. sizeof (SaNameT));
  1349. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1350. ckptAttributes,
  1351. sizeof (SaCkptCheckpointCreationAttributesT));
  1352. ckptCheckpoint->unlinked = 0;
  1353. list_init (&ckptCheckpoint->list);
  1354. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1355. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1356. ckptCheckpoint->retention_timer = 0;
  1357. ckptCheckpoint->expired = 0;
  1358. /*
  1359. * Add in default checkpoint section
  1360. */
  1361. list_init (&ckptCheckpointSection->list);
  1362. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1363. /*
  1364. * Default section id
  1365. */
  1366. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1367. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1368. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1369. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1370. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1371. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1372. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1373. assert(ckptCheckpointSection->sectionData);
  1374. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1375. ckptCheckpointSection->expiration_timer = 0;
  1376. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1377. }
  1378. else {
  1379. /*
  1380. * Setup connection information and mark checkpoint as referenced
  1381. */
  1382. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1383. }
  1384. /*
  1385. * If the checkpoint has been unlinked, it is an invalid name
  1386. */
  1387. if (ckptCheckpoint->unlinked) {
  1388. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1389. goto error_exit;
  1390. }
  1391. /*CHECK to see if there are any existing ckpts*/
  1392. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1393. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1394. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1395. }
  1396. else {
  1397. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1398. }
  1399. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1400. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1401. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1402. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1403. /*
  1404. * Reset retention duration since this checkpoint was just opened
  1405. */
  1406. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1407. ckptCheckpoint->retention_timer = 0;
  1408. /*
  1409. * Send error result to CKPT library
  1410. */
  1411. error_exit:
  1412. return (error);
  1413. }
  1414. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1415. {
  1416. int retcode;
  1417. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1418. = (struct req_exec_ckpt_synchronize_state *)message;
  1419. /*
  1420. * If the Incoming message's previous ring id == saved_ring_id
  1421. * Ignore because we have seen this message before.
  1422. */
  1423. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1424. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1425. return(0);
  1426. }
  1427. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1428. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1429. req_exec_ckpt_sync_state->ckpt_refcount);
  1430. if (retcode != SA_AIS_OK) {
  1431. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1432. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1433. }
  1434. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1435. &req_exec_ckpt_sync_state->checkpointName,
  1436. (char*)req_exec_ckpt_sync_state
  1437. + sizeof (struct req_exec_ckpt_synchronize_state));
  1438. if (retcode != SA_AIS_OK) {
  1439. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1440. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1441. }
  1442. return (0);
  1443. }
  1444. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1445. {
  1446. int retcode;
  1447. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1448. = (struct req_exec_ckpt_synchronize_section *)message;
  1449. /*
  1450. * If the Incoming message's previous ring id == saved_ring_id
  1451. * Ignore because we have seen this message before.
  1452. */
  1453. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1454. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1455. return(0);
  1456. }
  1457. /*
  1458. * Write the contents of the section to the checkpoint section.
  1459. */
  1460. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1461. (char*)req_exec_ckpt_sync_section
  1462. + sizeof (struct req_exec_ckpt_synchronize_section),
  1463. &req_exec_ckpt_sync_section->checkpointName,
  1464. (char*)req_exec_ckpt_sync_section
  1465. + sizeof (struct req_exec_ckpt_synchronize_section)
  1466. + req_exec_ckpt_sync_section->sectionId.idLen,
  1467. req_exec_ckpt_sync_section->dataOffSet,
  1468. req_exec_ckpt_sync_section->dataSize);
  1469. if (retcode != SA_AIS_OK) {
  1470. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1471. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1472. }
  1473. return (0);
  1474. }
  1475. unsigned int abstime_to_msec (SaTimeT time)
  1476. {
  1477. struct timeval tv;
  1478. unsigned long long curr_time;
  1479. unsigned long long msec_time;
  1480. gettimeofday (&tv, NULL);
  1481. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1482. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1483. msec_time = (((unsigned long long)time) / 1000000) -
  1484. (unsigned long long)curr_time;
  1485. return ((unsigned int)(msec_time));
  1486. }
  1487. void timer_function_section_expire (void *data)
  1488. {
  1489. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1490. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1491. struct ckpt_identifier *ckpt_id = 0;
  1492. ckpt_id = (struct ckpt_identifier *)data;
  1493. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1494. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1495. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1496. ckpt_id->ckpt_section_id.id,
  1497. (char *)&ckpt_id->ckpt_name.value);
  1498. }
  1499. else {
  1500. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1501. goto free_mem;
  1502. }
  1503. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1504. if (ckptCheckpoint == 0) {
  1505. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1506. (char *)&ckpt_id->ckpt_name.value);
  1507. goto free_mem;
  1508. }
  1509. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1510. ckpt_id->ckpt_section_id.id,
  1511. (int)ckpt_id->ckpt_section_id.idLen);
  1512. if (ckptCheckpointSection == 0) {
  1513. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1514. ckpt_id->ckpt_section_id.id,
  1515. (char *)&ckpt_id->ckpt_name.value);
  1516. goto free_mem;
  1517. }
  1518. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1519. ckpt_id->ckpt_section_id.id,
  1520. (char *)&ckpt_id->ckpt_name.value);
  1521. checkpoint_section_release (ckptCheckpointSection);
  1522. free_mem :
  1523. free (ckpt_id);
  1524. }
  1525. void timer_function_retention (void *data)
  1526. {
  1527. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1528. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1529. struct iovec iovec;
  1530. checkpoint->retention_timer = 0;
  1531. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1532. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1533. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1534. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1535. &checkpoint->name,
  1536. sizeof (SaNameT));
  1537. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1538. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1539. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1540. }
  1541. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1542. {
  1543. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1544. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1545. struct saCkptCheckpoint *checkpoint = 0;
  1546. SaAisErrorT error = SA_AIS_OK;
  1547. int proc_index;
  1548. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1549. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1550. if (checkpoint == 0) {
  1551. goto error_exit;
  1552. }
  1553. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1554. checkpoint->referenceCount--;
  1555. /*
  1556. * Modify the connection reference information to the Checkpoint to be
  1557. * sent out later as a part of the sync process.
  1558. */
  1559. proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1560. if (proc_index != -1 ) {
  1561. checkpoint->ckpt_refcount[proc_index].count--;
  1562. }
  1563. else {
  1564. log_printf (LOG_LEVEL_ERROR,
  1565. "CKPT: Could Not find Processor Info %p info.\n",
  1566. checkpoint);
  1567. }
  1568. assert (checkpoint->referenceCount >= 0);
  1569. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1570. checkpoint->referenceCount);
  1571. /*
  1572. * If checkpoint has been unlinked and this is the last reference, delete it
  1573. */
  1574. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1575. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1576. checkpoint_release (checkpoint);
  1577. } else
  1578. if (checkpoint->referenceCount == 0) {
  1579. poll_timer_add (aisexec_poll_handle,
  1580. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1581. checkpoint,
  1582. timer_function_retention,
  1583. &checkpoint->retention_timer);
  1584. }
  1585. error_exit:
  1586. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1587. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1588. checkpoint);
  1589. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1590. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1591. res_lib_ckpt_checkpointclose.header.error = error;
  1592. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1593. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1594. }
  1595. return (0);
  1596. }
  1597. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1598. {
  1599. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1600. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1601. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1602. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1603. SaErrorT error = SA_AIS_OK;
  1604. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1605. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1606. if (ckptCheckpoint == 0) {
  1607. error = SA_AIS_ERR_NOT_EXIST;
  1608. goto error_exit;
  1609. }
  1610. if (ckptCheckpoint->unlinked) {
  1611. error = SA_AIS_ERR_INVALID_PARAM;
  1612. goto error_exit;
  1613. }
  1614. ckptCheckpoint->unlinked = 1;
  1615. /*
  1616. * Immediately delete entry if reference count is zero
  1617. */
  1618. if (ckptCheckpoint->referenceCount == 0) {
  1619. /*
  1620. * Remove retention timer since this checkpoint was unlinked and is no
  1621. * longer referenced
  1622. */
  1623. checkpoint_release (ckptCheckpoint);
  1624. }
  1625. error_exit:
  1626. /*
  1627. * If this node was the source of the message, respond to this node
  1628. */
  1629. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1630. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1631. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1632. res_lib_ckpt_checkpointunlink.header.error = error;
  1633. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1634. sizeof (struct res_lib_ckpt_checkpointunlink));
  1635. }
  1636. return (0);
  1637. }
  1638. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1639. {
  1640. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1641. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1642. struct saCkptCheckpoint *checkpoint;
  1643. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  1644. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1645. if (checkpoint) {
  1646. log_printf (LOG_LEVEL_DEBUG, "CKPT: Setting retention duration for checkpoint %s\n",
  1647. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1648. if (checkpoint->unlinked == 0) {
  1649. checkpoint->checkpointCreationAttributes.retentionDuration =
  1650. req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1651. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1652. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1653. poll_timer_add (aisexec_poll_handle,
  1654. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1655. checkpoint,
  1656. timer_function_retention,
  1657. &checkpoint->retention_timer);
  1658. }
  1659. error = SA_AIS_OK;
  1660. }
  1661. }
  1662. /*
  1663. * Respond to library if this processor sent the duration set request
  1664. */
  1665. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1666. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1667. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1668. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  1669. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1670. &res_lib_ckpt_checkpointretentiondurationset,
  1671. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1672. }
  1673. return (0);
  1674. }
  1675. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1676. {
  1677. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1678. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1679. struct saCkptCheckpoint *checkpoint;
  1680. struct iovec iovecs[2];
  1681. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1682. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount < 1)) {
  1683. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1684. checkpoint->expired = 1;
  1685. req_exec_ckpt_checkpointunlink.header.size =
  1686. sizeof (struct req_exec_ckpt_checkpointunlink);
  1687. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1688. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1689. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1690. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1691. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1692. sizeof (SaNameT));
  1693. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1694. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1695. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1696. }
  1697. return (0);
  1698. }
  1699. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1700. SaNameT *checkpointName,
  1701. char* SectionId)
  1702. {
  1703. struct saCkptCheckpoint *ckptCheckpoint;
  1704. struct saCkptCheckpointSection *ckptCheckpointSection;
  1705. void *initialData;
  1706. void *sectionId;
  1707. struct ckpt_identifier *ckpt_id = 0;
  1708. SaErrorT error = SA_AIS_OK;
  1709. if ((int)sectionDescriptor->sectionId.idLen) {
  1710. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1711. &checkpointName->value, SectionId);
  1712. } else {
  1713. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1714. &checkpointName->value);
  1715. }
  1716. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1717. if (ckptCheckpoint == 0) {
  1718. error = SA_AIS_ERR_NOT_EXIST;
  1719. goto error_exit;
  1720. }
  1721. /*
  1722. * Determine if user-specified checkpoint ID already exists
  1723. */
  1724. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1725. SectionId,
  1726. (int)sectionDescriptor->sectionId.idLen);
  1727. if (ckptCheckpointSection) {
  1728. error = SA_AIS_ERR_EXIST;
  1729. goto error_exit;
  1730. }
  1731. /*
  1732. * Allocate checkpoint section
  1733. */
  1734. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1735. if (ckptCheckpointSection == 0) {
  1736. error = SA_AIS_ERR_NO_MEMORY;
  1737. goto error_exit;
  1738. }
  1739. /*
  1740. * Allocate checkpoint section data
  1741. */
  1742. initialData = malloc (sectionDescriptor->sectionSize);
  1743. if (initialData == 0) {
  1744. free (ckptCheckpointSection);
  1745. error = SA_AIS_ERR_NO_MEMORY;
  1746. goto error_exit;
  1747. }
  1748. /*
  1749. * Allocate checkpoint section id
  1750. */
  1751. if (sectionDescriptor->sectionId.idLen) {
  1752. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1753. if (sectionId == 0) {
  1754. free (ckptCheckpointSection);
  1755. free (initialData);
  1756. error = SA_AIS_ERR_NO_MEMORY;
  1757. goto error_exit;
  1758. }
  1759. } else {
  1760. sectionId = 0;
  1761. }
  1762. /*
  1763. * Copy checkpoint section ID and initialize data.
  1764. */
  1765. if (SectionId) {
  1766. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  1767. } else {
  1768. sectionId = 0;
  1769. }
  1770. memset (initialData, 0, sectionDescriptor->sectionSize);
  1771. /*
  1772. * Configure checkpoint section
  1773. */
  1774. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1775. sectionDescriptor,
  1776. sizeof(SaCkptSectionDescriptorT));
  1777. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1778. ckptCheckpointSection->sectionData = initialData;
  1779. ckptCheckpointSection->expiration_timer = 0;
  1780. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1781. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1782. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1783. assert(ckpt_id);
  1784. memcpy(&ckpt_id->ckpt_name,checkpointName,sizeof(SaNameT));
  1785. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1786. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  1787. ckpt_id->ckpt_section_id.id,
  1788. (char *)&ckpt_id->ckpt_name.value);
  1789. poll_timer_add (aisexec_poll_handle,
  1790. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1791. ckpt_id,
  1792. timer_function_section_expire,
  1793. &ckptCheckpointSection->expiration_timer);
  1794. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create expiration timer = 0x%x\n",
  1795. ckptCheckpointSection->expiration_timer);
  1796. }
  1797. /*
  1798. * Add checkpoint section to checkpoint
  1799. */
  1800. list_init (&ckptCheckpointSection->list);
  1801. list_add (&ckptCheckpointSection->list,
  1802. &ckptCheckpoint->checkpointSectionsListHead);
  1803. error_exit:
  1804. return (error);
  1805. }
  1806. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1807. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1808. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1809. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1810. struct saCkptCheckpoint *ckptCheckpoint;
  1811. struct saCkptCheckpointSection *ckptCheckpointSection;
  1812. void *initialData;
  1813. void *sectionId;
  1814. struct ckpt_identifier *ckpt_id = 0;
  1815. SaErrorT error = SA_AIS_OK;
  1816. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1817. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1818. if (ckptCheckpoint == 0) {
  1819. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1820. goto error_exit;
  1821. }
  1822. /*
  1823. * Determine if user-specified checkpoint ID already exists
  1824. */
  1825. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1826. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1827. req_lib_ckpt_sectioncreate->idLen);
  1828. if (ckptCheckpointSection) {
  1829. error = SA_AIS_ERR_EXIST;
  1830. goto error_exit;
  1831. }
  1832. /*
  1833. * Allocate checkpoint section
  1834. */
  1835. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1836. if (ckptCheckpointSection == 0) {
  1837. error = SA_AIS_ERR_NO_MEMORY;
  1838. goto error_exit;
  1839. }
  1840. /*
  1841. * Allocate checkpoint section data
  1842. */
  1843. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1844. if (initialData == 0) {
  1845. free (ckptCheckpointSection);
  1846. error = SA_AIS_ERR_NO_MEMORY;
  1847. goto error_exit;
  1848. }
  1849. /*
  1850. * Allocate checkpoint section id
  1851. */
  1852. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1853. if (sectionId == 0) {
  1854. free (ckptCheckpointSection);
  1855. free (initialData);
  1856. error = SA_AIS_ERR_NO_MEMORY;
  1857. goto error_exit;
  1858. }
  1859. /*
  1860. * Copy checkpoint section and section ID
  1861. */
  1862. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1863. req_lib_ckpt_sectioncreate->idLen);
  1864. memcpy (initialData,
  1865. ((char *)req_lib_ckpt_sectioncreate) +
  1866. sizeof (struct req_lib_ckpt_sectioncreate) +
  1867. req_lib_ckpt_sectioncreate->idLen,
  1868. req_lib_ckpt_sectioncreate->initialDataSize);
  1869. /*
  1870. * Configure checkpoint section
  1871. */
  1872. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1873. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1874. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1875. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1876. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1877. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1878. ckptCheckpointSection->sectionData = initialData;
  1879. ckptCheckpointSection->expiration_timer = 0;
  1880. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1881. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1882. assert(ckpt_id);
  1883. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectioncreate->checkpointName,sizeof(SaNameT));
  1884. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1885. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  1886. ckpt_id->ckpt_section_id.id,
  1887. (char *)&ckpt_id->ckpt_name.value);
  1888. poll_timer_add (aisexec_poll_handle,
  1889. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1890. ckpt_id,
  1891. timer_function_section_expire,
  1892. &ckptCheckpointSection->expiration_timer);
  1893. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionicreate expiration timer = 0x%x\n",
  1894. ckptCheckpointSection->expiration_timer);
  1895. }
  1896. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_sectioncreate created section with id = %s, idLen = %d\n",
  1897. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1898. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  1899. /*
  1900. * Add checkpoint section to checkpoint
  1901. */
  1902. list_init (&ckptCheckpointSection->list);
  1903. list_add (&ckptCheckpointSection->list,
  1904. &ckptCheckpoint->checkpointSectionsListHead);
  1905. error_exit:
  1906. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1907. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1908. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1909. res_lib_ckpt_sectioncreate.header.error = error;
  1910. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1911. &res_lib_ckpt_sectioncreate,
  1912. sizeof (struct res_lib_ckpt_sectioncreate));
  1913. }
  1914. return (0);
  1915. }
  1916. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1917. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1918. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1919. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1920. struct saCkptCheckpoint *ckptCheckpoint;
  1921. struct saCkptCheckpointSection *ckptCheckpointSection;
  1922. SaErrorT error = SA_AIS_OK;
  1923. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1924. if (ckptCheckpoint == 0) {
  1925. error = SA_AIS_ERR_NOT_EXIST;
  1926. goto error_exit;
  1927. }
  1928. /*
  1929. * Determine if the user is trying to delete the default section
  1930. */
  1931. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1932. error = SA_AIS_ERR_INVALID_PARAM;
  1933. goto error_exit;
  1934. }
  1935. /*
  1936. * Find checkpoint section to be deleted
  1937. */
  1938. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1939. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1940. req_lib_ckpt_sectiondelete->idLen);
  1941. if (ckptCheckpointSection == 0) {
  1942. error = SA_AIS_ERR_NOT_EXIST;
  1943. goto error_exit;
  1944. }
  1945. /*
  1946. * Delete checkpoint section
  1947. */
  1948. checkpoint_section_release (ckptCheckpointSection);
  1949. /*
  1950. * return result to CKPT library
  1951. */
  1952. error_exit:
  1953. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  1954. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1955. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1956. res_lib_ckpt_sectiondelete.header.error = error;
  1957. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1958. &res_lib_ckpt_sectiondelete,
  1959. sizeof (struct res_lib_ckpt_sectiondelete));
  1960. }
  1961. return (0);
  1962. }
  1963. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1964. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1965. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1966. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1967. struct saCkptCheckpoint *ckptCheckpoint;
  1968. struct saCkptCheckpointSection *ckptCheckpointSection;
  1969. struct ckpt_identifier *ckpt_id = 0;
  1970. SaErrorT error = SA_AIS_OK;
  1971. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  1972. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  1973. if (ckptCheckpoint == 0) {
  1974. error = SA_AIS_ERR_NOT_EXIST;
  1975. goto error_exit;
  1976. }
  1977. /*
  1978. * Determine if the user is trying to set expiration time for the default section
  1979. */
  1980. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  1981. error = SA_AIS_ERR_INVALID_PARAM;
  1982. goto error_exit;
  1983. }
  1984. /*
  1985. * Find checkpoint section that expiration time should be set for
  1986. */
  1987. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1988. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  1989. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  1990. req_lib_ckpt_sectionexpirationtimeset->idLen);
  1991. if (ckptCheckpointSection == 0) {
  1992. error = SA_AIS_ERR_NOT_EXIST;
  1993. goto error_exit;
  1994. }
  1995. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  1996. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  1997. ckptCheckpointSection->expiration_timer = 0;
  1998. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  1999. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2000. assert(ckpt_id);
  2001. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectionexpirationtimeset->checkpointName,sizeof(SaNameT));
  2002. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2003. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%x\n",
  2004. ckpt_id->ckpt_section_id.id,
  2005. (char *)&ckpt_id->ckpt_name.value,
  2006. ckpt_id);
  2007. poll_timer_add (aisexec_poll_handle,
  2008. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2009. ckpt_id,
  2010. timer_function_section_expire,
  2011. &ckptCheckpointSection->expiration_timer);
  2012. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%x\n",
  2013. ckptCheckpointSection->expiration_timer);
  2014. }
  2015. error_exit:
  2016. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2017. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2018. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2019. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2020. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  2021. &res_lib_ckpt_sectionexpirationtimeset,
  2022. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2023. }
  2024. return (0);
  2025. }
  2026. static int recovery_section_write(int sectionIdLen,
  2027. char* sectionId,
  2028. SaNameT *checkpointName,
  2029. void *newData,
  2030. SaUint32T dataOffSet,
  2031. SaUint32T dataSize)
  2032. {
  2033. struct saCkptCheckpoint *ckptCheckpoint;
  2034. struct saCkptCheckpointSection *ckptCheckpointSection;
  2035. int sizeRequired;
  2036. SaErrorT error = SA_AIS_OK;
  2037. char *sd;
  2038. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  2039. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  2040. if (ckptCheckpoint == 0) {
  2041. error = SA_AIS_ERR_NOT_EXIST;
  2042. goto error_exit;
  2043. }
  2044. /*
  2045. * Find checkpoint section to be written
  2046. */
  2047. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2048. sectionId,
  2049. sectionIdLen);
  2050. if (ckptCheckpointSection == 0) {
  2051. error = SA_AIS_ERR_NOT_EXIST;
  2052. goto error_exit;
  2053. }
  2054. /*
  2055. * If write would extend past end of section data, return error;
  2056. */
  2057. sizeRequired = dataOffSet + dataSize;
  2058. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2059. error = SA_AIS_ERR_ACCESS;
  2060. goto error_exit;
  2061. }
  2062. /*
  2063. * Write checkpoint section to section data
  2064. */
  2065. if (dataSize > 0) {
  2066. sd = (char *)ckptCheckpointSection->sectionData;
  2067. memcpy (&sd[dataOffSet],
  2068. newData,
  2069. dataSize);
  2070. }
  2071. error_exit:
  2072. return (error);
  2073. }
  2074. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2075. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2076. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  2077. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2078. struct saCkptCheckpoint *ckptCheckpoint;
  2079. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2080. int sizeRequired;
  2081. void *sectionData;
  2082. SaErrorT error = SA_AIS_OK;
  2083. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2084. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  2085. if (ckptCheckpoint == 0) {
  2086. log_printf (LOG_LEVEL_ERROR, "CKPT: ckpt_checkpoint_find_global returned 0 Calling error_exit.\n");
  2087. error = SA_AIS_ERR_NOT_EXIST;
  2088. goto error_exit;
  2089. }
  2090. /*
  2091. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2092. */
  2093. /*
  2094. * Find checkpoint section to be written
  2095. */
  2096. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2097. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2098. req_lib_ckpt_sectionwrite->idLen);
  2099. if (ckptCheckpointSection == 0) {
  2100. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  2101. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2102. }
  2103. else {
  2104. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2105. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2106. }
  2107. error = SA_AIS_ERR_NOT_EXIST;
  2108. goto error_exit;
  2109. }
  2110. /*
  2111. * If write would extend past end of section data, enlarge section
  2112. */
  2113. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  2114. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2115. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  2116. if (sectionData == 0) {
  2117. log_printf (LOG_LEVEL_ERROR, "CKPT: sectionData realloc returned 0 Calling error_exit.\n");
  2118. error = SA_AIS_ERR_NO_MEMORY;
  2119. goto error_exit;
  2120. }
  2121. /*
  2122. * Install new section data
  2123. */
  2124. ckptCheckpointSection->sectionData = sectionData;
  2125. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  2126. }
  2127. /*
  2128. * Write checkpoint section to section data
  2129. */
  2130. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  2131. char *sd;
  2132. int *val;
  2133. val = ckptCheckpointSection->sectionData;
  2134. sd = (char *)ckptCheckpointSection->sectionData;
  2135. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  2136. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  2137. req_lib_ckpt_sectionwrite->idLen,
  2138. req_lib_ckpt_sectionwrite->dataSize);
  2139. }
  2140. /*
  2141. * Write write response to CKPT library
  2142. */
  2143. error_exit:
  2144. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2145. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2146. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2147. res_lib_ckpt_sectionwrite.header.error = error;
  2148. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  2149. &res_lib_ckpt_sectionwrite,
  2150. sizeof (struct res_lib_ckpt_sectionwrite));
  2151. }
  2152. return (0);
  2153. }
  2154. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2155. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2156. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  2157. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2158. struct saCkptCheckpoint *ckptCheckpoint;
  2159. struct saCkptCheckpointSection *ckptCheckpointSection;
  2160. void *sectionData;
  2161. SaErrorT error = SA_AIS_OK;
  2162. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2163. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  2164. if (ckptCheckpoint == 0) {
  2165. error = SA_AIS_ERR_NOT_EXIST;
  2166. goto error_exit;
  2167. }
  2168. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionoverwrite->dataSize) {
  2169. error = SA_AIS_ERR_INVALID_PARAM;
  2170. goto error_exit;
  2171. }
  2172. /*
  2173. * Find checkpoint section to be overwritten
  2174. */
  2175. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2176. ((char *)req_lib_ckpt_sectionoverwrite) +
  2177. sizeof (struct req_lib_ckpt_sectionoverwrite),
  2178. req_lib_ckpt_sectionoverwrite->idLen);
  2179. if (ckptCheckpointSection == 0) {
  2180. error = SA_AIS_ERR_NOT_EXIST;
  2181. goto error_exit;
  2182. }
  2183. /*
  2184. * Allocate checkpoint section data
  2185. */
  2186. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  2187. if (sectionData == 0) {
  2188. error = SA_AIS_ERR_NO_MEMORY;
  2189. goto error_exit;
  2190. }
  2191. memcpy (sectionData,
  2192. ((char *)req_lib_ckpt_sectionoverwrite) +
  2193. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  2194. req_lib_ckpt_sectionoverwrite->idLen,
  2195. req_lib_ckpt_sectionoverwrite->dataSize);
  2196. /*
  2197. * release old checkpoint section data
  2198. */
  2199. free (ckptCheckpointSection->sectionData);
  2200. /*
  2201. * Install overwritten checkpoint section data
  2202. */
  2203. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  2204. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2205. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2206. ckptCheckpointSection->sectionData = sectionData;
  2207. /*
  2208. * return result to CKPT library
  2209. */
  2210. error_exit:
  2211. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2212. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  2213. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2214. res_lib_ckpt_sectionoverwrite.header.error = error;
  2215. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  2216. &res_lib_ckpt_sectionoverwrite,
  2217. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2218. }
  2219. return (0);
  2220. }
  2221. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  2222. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2223. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  2224. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2225. struct saCkptCheckpoint *ckptCheckpoint;
  2226. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2227. int sectionSize = 0;
  2228. SaErrorT error = SA_AIS_OK;
  2229. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2230. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  2231. if (ckptCheckpoint == 0) {
  2232. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  2233. goto error_exit;
  2234. }
  2235. /*
  2236. * Find checkpoint section to be read
  2237. */
  2238. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2239. ((char *)req_lib_ckpt_sectionread) +
  2240. sizeof (struct req_lib_ckpt_sectionread),
  2241. req_lib_ckpt_sectionread->idLen);
  2242. if (ckptCheckpointSection == 0) {
  2243. error = SA_AIS_ERR_NOT_EXIST;
  2244. goto error_exit;
  2245. }
  2246. /*
  2247. * Determine the section size
  2248. */
  2249. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  2250. req_lib_ckpt_sectionread->dataOffset;
  2251. /*
  2252. * If the library has less space available then can be sent from the
  2253. * section, reduce bytes sent to library to max requested
  2254. */
  2255. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  2256. sectionSize = req_lib_ckpt_sectionread->dataSize;
  2257. }
  2258. /*
  2259. * If dataOffset is past end of data, return INVALID PARAM
  2260. */
  2261. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  2262. sectionSize = 0;
  2263. error = SA_AIS_ERR_INVALID_PARAM;
  2264. goto error_exit;
  2265. }
  2266. /*
  2267. * Write read response to CKPT library
  2268. */
  2269. error_exit:
  2270. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2271. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  2272. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2273. res_lib_ckpt_sectionread.header.error = error;
  2274. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2275. &res_lib_ckpt_sectionread,
  2276. sizeof (struct res_lib_ckpt_sectionread));
  2277. /*
  2278. * Write checkpoint to CKPT library section if section has data
  2279. */
  2280. if (sectionSize) {
  2281. char *sd;
  2282. sd = (char *)ckptCheckpointSection->sectionData;
  2283. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2284. &sd[req_lib_ckpt_sectionread->dataOffset],
  2285. sectionSize);
  2286. }
  2287. }
  2288. return (0);
  2289. }
  2290. static int ckpt_init_two_fn (struct conn_info *conn_info)
  2291. {
  2292. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator
  2293. .list);
  2294. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  2295. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  2296. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  2297. list_add (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list,
  2298. &checkpoint_iterator_list_head);
  2299. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list);
  2300. return (0);
  2301. }
  2302. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  2303. {
  2304. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  2305. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2306. struct iovec iovecs[2];
  2307. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  2308. req_exec_ckpt_checkpointopen.header.size =
  2309. sizeof (struct req_exec_ckpt_checkpointopen);
  2310. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2311. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2312. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2313. req_lib_ckpt_checkpointopen,
  2314. sizeof (struct req_lib_ckpt_checkpointopen));
  2315. req_exec_ckpt_checkpointopen.async_call = 0;
  2316. req_exec_ckpt_checkpointopen.invocation = 0;
  2317. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  2318. req_exec_ckpt_checkpointopen.fail_with_error = SA_AIS_OK;
  2319. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2320. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2321. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2322. return (0);
  2323. }
  2324. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  2325. {
  2326. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  2327. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2328. struct iovec iovecs[2];
  2329. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2330. req_exec_ckpt_checkpointopen.header.size =
  2331. sizeof (struct req_exec_ckpt_checkpointopen);
  2332. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2333. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2334. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2335. req_lib_ckpt_checkpointopenasync,
  2336. sizeof (struct req_lib_ckpt_checkpointopen));
  2337. req_exec_ckpt_checkpointopen.async_call = 1;
  2338. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2339. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2340. req_exec_ckpt_checkpointopen.fail_with_error = req_lib_ckpt_checkpointopenasync->fail_with_error;
  2341. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2342. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2343. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2344. return (0);
  2345. }
  2346. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  2347. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  2348. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2349. struct iovec iovecs[2];
  2350. struct saCkptCheckpoint *checkpoint;
  2351. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2352. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2353. if (checkpoint && (checkpoint->expired == 0)) {
  2354. req_exec_ckpt_checkpointclose.header.size =
  2355. sizeof (struct req_exec_ckpt_checkpointclose);
  2356. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  2357. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  2358. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2359. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2360. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2361. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2362. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  2363. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2364. }
  2365. }
  2366. else {
  2367. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2368. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2369. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2370. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2371. libais_send_response (conn_info,
  2372. &res_lib_ckpt_checkpointclose,
  2373. sizeof (struct res_lib_ckpt_checkpointclose));
  2374. }
  2375. return (0);
  2376. }
  2377. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  2378. {
  2379. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  2380. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2381. struct iovec iovecs[2];
  2382. req_exec_ckpt_checkpointunlink.header.size =
  2383. sizeof (struct req_exec_ckpt_checkpointunlink);
  2384. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  2385. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  2386. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2387. req_lib_ckpt_checkpointunlink,
  2388. sizeof (struct req_lib_ckpt_checkpointunlink));
  2389. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2390. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2391. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2392. return (0);
  2393. }
  2394. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  2395. {
  2396. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  2397. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2398. struct iovec iovecs[2];
  2399. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  2400. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2401. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2402. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2403. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2404. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2405. sizeof (SaNameT));
  2406. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2407. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2408. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2409. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2410. return (0);
  2411. }
  2412. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2413. {
  2414. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2415. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2416. struct saCkptCheckpoint *checkpoint;
  2417. SaAisErrorT error = SA_AIS_OK;
  2418. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2419. /*
  2420. * Make sure checkpoint is collocated and async update option
  2421. */
  2422. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2423. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2424. error = SA_AIS_ERR_BAD_OPERATION;
  2425. }
  2426. checkpoint->active_replica_set = 1;
  2427. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2428. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2429. res_lib_ckpt_activereplicaset.header.error = error;
  2430. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2431. sizeof (struct res_lib_ckpt_activereplicaset));
  2432. return (0);
  2433. }
  2434. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2435. {
  2436. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2437. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2438. struct saCkptCheckpoint *checkpoint;
  2439. int memoryUsed = 0;
  2440. int numberOfSections = 0;
  2441. struct list_head *checkpoint_section_list;
  2442. struct saCkptCheckpointSection *checkpointSection;
  2443. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2444. /*
  2445. * Count memory used by checkpoint sections
  2446. */
  2447. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2448. if (checkpoint && (checkpoint->expired == 0)) {
  2449. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2450. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2451. checkpoint_section_list = checkpoint_section_list->next) {
  2452. checkpointSection = list_entry (checkpoint_section_list,
  2453. struct saCkptCheckpointSection, list);
  2454. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2455. numberOfSections += 1;
  2456. }
  2457. /*
  2458. * Build checkpoint status get response
  2459. */
  2460. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2461. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2462. if (checkpoint->active_replica_set == 1) {
  2463. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2464. } else {
  2465. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2466. }
  2467. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2468. &checkpoint->checkpointCreationAttributes,
  2469. sizeof (SaCkptCheckpointCreationAttributesT));
  2470. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2471. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2472. }
  2473. else {
  2474. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2475. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2476. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2477. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2478. }
  2479. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2480. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2481. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2482. return (0);
  2483. }
  2484. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2485. {
  2486. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2487. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2488. struct iovec iovecs[2];
  2489. struct saCkptCheckpoint *checkpoint;
  2490. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2491. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2492. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2493. if (checkpoint && (checkpoint->expired == 0)) {
  2494. /*
  2495. * checkpoint opened is writeable mode so send message to cluster
  2496. */
  2497. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2498. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2499. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2500. req_lib_ckpt_sectioncreate,
  2501. sizeof (struct req_lib_ckpt_sectioncreate));
  2502. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2503. &req_lib_ckpt_sectioncreate->checkpointName,
  2504. sizeof (SaNameT));
  2505. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2506. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2507. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2508. /*
  2509. * Send section name and initial data in message
  2510. */
  2511. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2512. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2513. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2514. if (iovecs[1].iov_len) {
  2515. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2516. iovecs[1].iov_base,
  2517. iovecs[1].iov_len);
  2518. }
  2519. #ifdef DEBUG
  2520. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2521. iovecs[1].iov_len);
  2522. printf ("|\n");
  2523. { int i;
  2524. char *abc = iovecs[1].iov_base;
  2525. for (i = 0; i < 14;i++) {
  2526. printf ("%c ", abc[i]);
  2527. }
  2528. }
  2529. printf ("|\n");
  2530. #endif
  2531. if (iovecs[1].iov_len > 0) {
  2532. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2533. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2534. } else {
  2535. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2536. }
  2537. }
  2538. else {
  2539. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2540. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2541. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2542. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2543. libais_send_response (conn_info,
  2544. &res_lib_ckpt_sectioncreate,
  2545. sizeof (struct res_lib_ckpt_sectioncreate));
  2546. }
  2547. return (0);
  2548. }
  2549. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2550. {
  2551. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2552. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2553. struct iovec iovecs[2];
  2554. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2555. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2556. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2557. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2558. &req_lib_ckpt_sectiondelete->checkpointName,
  2559. sizeof (SaNameT));
  2560. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2561. req_lib_ckpt_sectiondelete,
  2562. sizeof (struct req_lib_ckpt_sectiondelete));
  2563. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2564. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2565. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2566. /*
  2567. * Send section name
  2568. */
  2569. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2570. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2571. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2572. if (iovecs[1].iov_len > 0) {
  2573. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2574. } else {
  2575. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2576. }
  2577. return (0);
  2578. }
  2579. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2580. {
  2581. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2582. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2583. struct iovec iovecs[2];
  2584. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2585. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2586. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2587. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2588. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2589. sizeof (SaNameT));
  2590. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2591. req_lib_ckpt_sectionexpirationtimeset,
  2592. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2593. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2594. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2595. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2596. /*
  2597. * Send section name
  2598. */
  2599. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2600. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2601. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2602. if (iovecs[1].iov_len > 0) {
  2603. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2604. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2605. } else {
  2606. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2607. }
  2608. return (0);
  2609. }
  2610. int write_inv = 0;
  2611. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2612. {
  2613. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2614. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2615. struct iovec iovecs[2];
  2616. struct saCkptCheckpoint *checkpoint;
  2617. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2618. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2619. req_lib_ckpt_sectionwrite->dataSize,
  2620. req_lib_ckpt_sectionwrite->dataOffset);
  2621. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2622. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2623. req_lib_ckpt_sectionwrite->idLen);
  2624. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2625. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2626. if (checkpoint && (checkpoint->expired == 0)) {
  2627. /*
  2628. * checkpoint opened is writeable mode so send message to cluster
  2629. */
  2630. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2631. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2632. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2633. req_lib_ckpt_sectionwrite,
  2634. sizeof (struct req_lib_ckpt_sectionwrite));
  2635. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2636. &req_lib_ckpt_sectionwrite->checkpointName,
  2637. sizeof (SaNameT));
  2638. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2639. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2640. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2641. /*
  2642. * Send section name and data to write in message
  2643. */
  2644. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2645. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2646. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2647. if (iovecs[1].iov_len > 0) {
  2648. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2649. } else {
  2650. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2651. }
  2652. }
  2653. else {
  2654. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  2655. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2656. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2657. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2658. libais_send_response (conn_info,
  2659. &res_lib_ckpt_sectionwrite,
  2660. sizeof (struct res_lib_ckpt_sectionwrite));
  2661. }
  2662. return (0);
  2663. }
  2664. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2665. {
  2666. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2667. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2668. struct iovec iovecs[2];
  2669. struct saCkptCheckpoint *checkpoint;
  2670. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2671. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2672. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2673. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2674. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->active_replica_set == 1)) {
  2675. /*
  2676. * checkpoint opened is writeable mode so send message to cluster
  2677. */
  2678. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2679. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2680. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2681. req_lib_ckpt_sectionoverwrite,
  2682. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2683. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2684. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2685. sizeof (SaNameT));
  2686. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2687. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2688. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2689. /*
  2690. * Send section name and data to overwrite in message
  2691. */
  2692. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2693. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2694. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2695. if (iovecs[1].iov_len > 0) {
  2696. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2697. } else {
  2698. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2699. }
  2700. }
  2701. else {
  2702. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  2703. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2704. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2705. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2706. libais_send_response (conn_info,
  2707. &res_lib_ckpt_sectionoverwrite,
  2708. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2709. }
  2710. return (0);
  2711. }
  2712. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2713. {
  2714. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2715. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2716. struct iovec iovecs[2];
  2717. struct saCkptCheckpoint *checkpoint;
  2718. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2719. SaAisErrorT error = SA_AIS_OK;
  2720. log_printf (LOG_LEVEL_DEBUG, "Section read from API fd %d\n", conn_info->fd);
  2721. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2722. if (checkpoint && (checkpoint->expired == 0) &&
  2723. checkpoint->active_replica_set &&
  2724. req_lib_ckpt_sectionread->dataSize <=
  2725. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2726. /*
  2727. * checkpoint opened is writeable mode so send message to cluster
  2728. */
  2729. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2730. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2731. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2732. req_lib_ckpt_sectionread,
  2733. sizeof (struct req_lib_ckpt_sectionread));
  2734. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2735. &req_lib_ckpt_sectionread->checkpointName,
  2736. sizeof (SaNameT));
  2737. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2738. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2739. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2740. /*
  2741. * Send section name and data to overwrite in message
  2742. */
  2743. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2744. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2745. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2746. if (iovecs[1].iov_len > 0) {
  2747. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2748. } else {
  2749. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2750. }
  2751. return (0); /* DO NOT REMOVE */
  2752. }
  2753. if (checkpoint) {
  2754. if (checkpoint->active_replica_set == 0) {
  2755. log_printf (LOG_LEVEL_DEBUG,
  2756. "sectionread - active replica not set.\n");
  2757. error = SA_AIS_ERR_NOT_EXIST;
  2758. }
  2759. if (req_lib_ckpt_sectionread->dataSize >
  2760. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2761. log_printf (LOG_LEVEL_DEBUG,
  2762. "sectionread - data size greater then max section size.\n");
  2763. error = SA_AIS_ERR_INVALID_PARAM;
  2764. }
  2765. } else {
  2766. log_printf (LOG_LEVEL_ERROR,
  2767. "sectionread - could not find checkpoint.\n");
  2768. }
  2769. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  2770. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2771. res_lib_ckpt_sectionread.header.error = error;
  2772. libais_send_response (conn_info,
  2773. &res_lib_ckpt_sectionread,
  2774. sizeof (struct res_lib_ckpt_sectionread));
  2775. return (0);
  2776. }
  2777. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2778. {
  2779. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)message;
  2780. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  2781. struct saCkptCheckpoint *checkpoint;
  2782. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronize->checkpointName);
  2783. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2784. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  2785. } else
  2786. if (checkpoint->active_replica_set == 1) {
  2787. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  2788. } else {
  2789. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  2790. }
  2791. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  2792. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  2793. libais_send_response (conn_info,
  2794. &res_lib_ckpt_checkpointsynchronize,
  2795. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  2796. return (0);
  2797. }
  2798. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2799. {
  2800. return (0);
  2801. }
  2802. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2803. {
  2804. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2805. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2806. struct saCkptCheckpoint *ckptCheckpoint;
  2807. struct saCkptCheckpointSection *ckptCheckpointSection;
  2808. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2809. struct saCkptSectionIterator *ckptSectionIterator;
  2810. struct list_head *checkpoint_section_list;
  2811. int addEntry = 0;
  2812. int iteratorEntries = 0;
  2813. SaErrorT error = SA_AIS_OK;
  2814. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2815. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2816. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2817. if (ckptCheckpoint == 0) {
  2818. error = SA_AIS_ERR_NOT_EXIST;
  2819. goto error_exit;
  2820. }
  2821. /*
  2822. * Iterate list of checkpoint sections
  2823. */
  2824. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2825. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2826. checkpoint_section_list = checkpoint_section_list->next) {
  2827. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2828. struct saCkptCheckpointSection, list);
  2829. addEntry = 1;
  2830. /*
  2831. * Item should be added to iterator list
  2832. */
  2833. if (addEntry) {
  2834. iteratorEntries += 1;
  2835. ckptSectionIteratorEntries =
  2836. realloc (ckptSectionIterator->sectionIteratorEntries,
  2837. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2838. if (ckptSectionIteratorEntries == 0) {
  2839. if (ckptSectionIterator->sectionIteratorEntries) {
  2840. free (ckptSectionIterator->sectionIteratorEntries);
  2841. }
  2842. error = SA_AIS_ERR_NO_MEMORY;
  2843. goto error_exit;
  2844. }
  2845. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2846. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2847. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2848. }
  2849. }
  2850. ckptSectionIterator->iteratorCount = iteratorEntries;
  2851. error_exit:
  2852. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2853. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2854. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2855. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2856. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2857. return (0);
  2858. }
  2859. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2860. {
  2861. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2862. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2863. struct saCkptSectionIterator *ckptSectionIterator;
  2864. SaErrorT error = SA_AIS_OK;
  2865. int sectionIdSize = 0;
  2866. int iteratorPos = 0;
  2867. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2868. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2869. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2870. /*
  2871. * Find active iterator entry
  2872. */
  2873. for (;;) {
  2874. /*
  2875. * No more sections in iterator
  2876. */
  2877. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2878. error = SA_AIS_ERR_NOT_EXIST;
  2879. goto error_exit;
  2880. }
  2881. /*
  2882. * active iterator entry
  2883. */
  2884. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2885. break;
  2886. }
  2887. ckptSectionIterator->iteratorPos += 1;
  2888. }
  2889. /*
  2890. * Prepare response to API
  2891. */
  2892. iteratorPos = ckptSectionIterator->iteratorPos;
  2893. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2894. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2895. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2896. sizeof (SaCkptSectionDescriptorT));
  2897. /*
  2898. * Get to next iterator entry
  2899. */
  2900. ckptSectionIterator->iteratorPos += 1;
  2901. error_exit:
  2902. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2903. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2904. res_lib_ckpt_sectioniteratornext.header.error = error;
  2905. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2906. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2907. libais_send_response (conn_info,
  2908. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2909. sectionIdSize);
  2910. return (0);
  2911. }