ckpt.c 99 KB

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