ckpt.c 104 KB

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