ckpt.c 120 KB

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