4
0

ckpt.c 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739
  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. if (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries) {
  846. free (conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries);
  847. }
  848. list_del (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  849. return (0);
  850. }
  851. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  852. {
  853. struct res_lib_activatepoll res_lib_activatepoll;
  854. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  855. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  856. res_lib_activatepoll.header.error = SA_AIS_OK;
  857. libais_send_response (conn_info, &res_lib_activatepoll,
  858. sizeof (struct res_lib_activatepoll));
  859. return (0);
  860. }
  861. static int message_handler_req_exec_ckpt_checkpointopen (void *message, struct in_addr source_addr, int endian_conversion_required)
  862. {
  863. struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message;
  864. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)&req_exec_ckpt_checkpointopen->req_lib_ckpt_checkpointopen;
  865. struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen;
  866. struct saCkptCheckpoint *ckptCheckpoint = 0;
  867. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  868. struct checkpoint_cleanup *checkpoint_cleanup;
  869. SaErrorT error = SA_AIS_OK;
  870. log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen);
  871. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  872. /*
  873. * If checkpoint doesn't exist, create one
  874. */
  875. if (ckptCheckpoint == 0) {
  876. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  877. if (ckptCheckpoint == 0) {
  878. error = SA_AIS_ERR_NO_MEMORY;
  879. goto error_exit;
  880. }
  881. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  882. if (ckptCheckpointSection == 0) {
  883. free (ckptCheckpoint);
  884. error = SA_AIS_ERR_NO_MEMORY;
  885. goto error_exit;
  886. }
  887. memcpy (&ckptCheckpoint->name,
  888. &req_lib_ckpt_checkpointopen->checkpointName,
  889. sizeof (SaNameT));
  890. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  891. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  892. sizeof (SaCkptCheckpointCreationAttributesT));
  893. ckptCheckpoint->unlinked = 0;
  894. list_init (&ckptCheckpoint->list);
  895. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  896. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  897. ckptCheckpoint->referenceCount = 0;
  898. ckptCheckpoint->retention_timer = 0;
  899. ckptCheckpoint->expired = 0;
  900. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  901. /*
  902. * Add in default checkpoint section
  903. */
  904. list_init (&ckptCheckpointSection->list);
  905. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  906. /*
  907. * Default section id
  908. */
  909. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  910. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  911. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  912. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  913. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  914. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  915. ckptCheckpointSection->sectionData = 0;
  916. ckptCheckpointSection->expiration_timer = 0;
  917. }
  918. /*
  919. * If the checkpoint has been unlinked, it is an invalid name
  920. */
  921. if (ckptCheckpoint->unlinked) {
  922. error = SA_AIS_ERR_INVALID_PARAM; /* Is this the correct return ? */
  923. goto error_exit;
  924. }
  925. /*
  926. * Setup connection information and mark checkpoint as referenced
  927. */
  928. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  929. ckptCheckpoint->referenceCount += 1;
  930. /*
  931. * Add the connection reference information to the Checkpoint to be
  932. * sent out later as a part of the sync process.
  933. *
  934. */
  935. int proc_index = processor_index_find(&source_addr,ckptCheckpoint->ckpt_refcount);
  936. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  937. proc_index = processor_index_set(&source_addr,ckptCheckpoint->ckpt_refcount);
  938. }
  939. if (proc_index != -1 ) {
  940. ckptCheckpoint->ckpt_refcount[proc_index].addr = source_addr;
  941. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  942. }
  943. else {
  944. log_printf (LOG_LEVEL_ERROR,
  945. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  946. ckptCheckpoint);
  947. }
  948. /*
  949. * Reset retention duration since this checkpoint was just opened
  950. */
  951. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  952. ckptCheckpoint->retention_timer = 0;
  953. /*
  954. * Send error result to CKPT library
  955. */
  956. error_exit:
  957. /*
  958. * If this node was the source of the message, respond to this node
  959. */
  960. if (req_exec_ckpt_checkpointopen->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  961. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  962. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  963. res_lib_ckpt_checkpointopen.header.error = error;
  964. if (error == SA_AIS_OK) {
  965. checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup));
  966. if (checkpoint_cleanup == 0) {
  967. free (ckptCheckpoint);
  968. error = SA_AIS_ERR_NO_MEMORY;
  969. } else {
  970. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  971. list_add (&checkpoint_cleanup->list,
  972. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  973. }
  974. }
  975. libais_send_response (req_exec_ckpt_checkpointopen->source.conn_info, &res_lib_ckpt_checkpointopen,
  976. sizeof (struct res_lib_ckpt_checkpointopen));
  977. }
  978. /* return (error == SA_AIS_OK ? 0 : -1); */
  979. return (0);
  980. }
  981. static int recovery_checkpoint_open(SaNameT *checkpointName,
  982. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  983. struct ckpt_refcnt *ref_cnt)
  984. {
  985. struct saCkptCheckpoint *ckptCheckpoint = 0;
  986. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  987. SaErrorT error = SA_AIS_OK;
  988. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  989. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  990. /*
  991. * If checkpoint doesn't exist, create one
  992. */
  993. if (ckptCheckpoint == 0) {
  994. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  995. if (ckptCheckpoint == 0) {
  996. error = SA_AIS_ERR_NO_MEMORY;
  997. goto error_exit;
  998. }
  999. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1000. if (ckptCheckpointSection == 0) {
  1001. free (ckptCheckpoint);
  1002. error = SA_AIS_ERR_NO_MEMORY;
  1003. goto error_exit;
  1004. }
  1005. memcpy (&ckptCheckpoint->name,
  1006. checkpointName,
  1007. sizeof (SaNameT));
  1008. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1009. ckptAttributes,
  1010. sizeof (SaCkptCheckpointCreationAttributesT));
  1011. ckptCheckpoint->unlinked = 0;
  1012. list_init (&ckptCheckpoint->list);
  1013. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1014. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1015. ckptCheckpoint->retention_timer = 0;
  1016. ckptCheckpoint->expired = 0;
  1017. /*
  1018. * Add in default checkpoint section
  1019. */
  1020. list_init (&ckptCheckpointSection->list);
  1021. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1022. /*
  1023. * Default section id
  1024. */
  1025. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1026. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1027. ckptCheckpointSection->sectionDescriptor.sectionSize = 0;
  1028. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1029. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1030. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1031. ckptCheckpointSection->sectionData = 0;
  1032. ckptCheckpointSection->expiration_timer = 0;
  1033. }
  1034. /*
  1035. * If the checkpoint has been unlinked, it is an invalid name
  1036. */
  1037. if (ckptCheckpoint->unlinked) {
  1038. error = SA_AIS_ERR_BAD_CHECKPOINT; /* Is this the correct return ? */
  1039. goto error_exit;
  1040. }
  1041. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1042. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1043. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1044. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1045. /*
  1046. * Setup connection information and mark checkpoint as referenced
  1047. */
  1048. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1049. /*
  1050. * Reset retention duration since this checkpoint was just opened
  1051. */
  1052. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1053. ckptCheckpoint->retention_timer = 0;
  1054. /*
  1055. * Send error result to CKPT library
  1056. */
  1057. error_exit:
  1058. return (error);
  1059. }
  1060. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct in_addr source_addr, int endian_conversion_required)
  1061. {
  1062. int retcode;
  1063. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1064. = (struct req_exec_ckpt_synchronize_state *)message;
  1065. /*
  1066. * If the Incoming message's previous ring id == saved_ring_id
  1067. * Ignore because we have seen this message before.
  1068. */
  1069. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1070. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1071. return(0);
  1072. }
  1073. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1074. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1075. req_exec_ckpt_sync_state->ckpt_refcount);
  1076. if (retcode != SA_AIS_OK) {
  1077. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1078. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1079. }
  1080. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1081. &req_exec_ckpt_sync_state->checkpointName,
  1082. (char*)req_exec_ckpt_sync_state
  1083. + sizeof (struct req_exec_ckpt_synchronize_state));
  1084. if (retcode != SA_AIS_OK) {
  1085. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1086. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1087. }
  1088. return (0);
  1089. }
  1090. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct in_addr source_addr, int endian_conversion_required)
  1091. {
  1092. int retcode;
  1093. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1094. = (struct req_exec_ckpt_synchronize_section *)message;
  1095. /*
  1096. * If the Incoming message's previous ring id == saved_ring_id
  1097. * Ignore because we have seen this message before.
  1098. */
  1099. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1100. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1101. return(0);
  1102. }
  1103. /*
  1104. * Write the contents of the section to the checkpoint section.
  1105. */
  1106. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1107. (char*)req_exec_ckpt_sync_section
  1108. + sizeof (struct req_exec_ckpt_synchronize_section),
  1109. &req_exec_ckpt_sync_section->checkpointName,
  1110. (char*)req_exec_ckpt_sync_section
  1111. + sizeof (struct req_exec_ckpt_synchronize_section)
  1112. + req_exec_ckpt_sync_section->sectionId.idLen,
  1113. req_exec_ckpt_sync_section->dataOffSet,
  1114. req_exec_ckpt_sync_section->dataSize);
  1115. if (retcode != SA_AIS_OK) {
  1116. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1117. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1118. }
  1119. return (0);
  1120. }
  1121. unsigned int abstime_to_msec (SaTimeT time)
  1122. {
  1123. struct timeval tv;
  1124. unsigned long long curr_time;
  1125. unsigned long long msec_time;
  1126. gettimeofday (&tv, NULL);
  1127. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1128. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1129. msec_time = (((unsigned long long)time) / 1000000) -
  1130. (unsigned long long)curr_time;
  1131. return ((unsigned int)(msec_time));
  1132. }
  1133. void timer_function_section_expire (void *data)
  1134. {
  1135. struct saCkptCheckpointSection *section = (struct saCkptCheckpointSection *)data;
  1136. if (section->sectionDescriptor.sectionId.id) {
  1137. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring section %s\n", section->sectionDescriptor.sectionId.id);
  1138. }
  1139. checkpoint_section_release (section);
  1140. }
  1141. void timer_function_retention (void *data)
  1142. {
  1143. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1144. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1145. struct iovec iovec;
  1146. checkpoint->retention_timer = 0;
  1147. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1148. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1149. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1150. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1151. &checkpoint->name,
  1152. sizeof (SaNameT));
  1153. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1154. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1155. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1156. }
  1157. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct in_addr source_addr, int endian_conversion_required)
  1158. {
  1159. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1160. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1161. struct saCkptCheckpoint *checkpoint = 0;
  1162. SaAisErrorT error = SA_AIS_OK;
  1163. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1164. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1165. if (checkpoint == 0) {
  1166. goto error_exit;
  1167. }
  1168. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1169. checkpoint->referenceCount--;
  1170. /*
  1171. * Modify the connection reference information to the Checkpoint to be
  1172. * sent out later as a part of the sync process.
  1173. */
  1174. int proc_index = processor_index_find(&source_addr, checkpoint->ckpt_refcount);
  1175. if (proc_index != -1 ) {
  1176. checkpoint->ckpt_refcount[proc_index].count--;
  1177. }
  1178. else {
  1179. log_printf (LOG_LEVEL_ERROR,
  1180. "CKPT: Could Not find Processor Info %p info.\n",
  1181. checkpoint);
  1182. }
  1183. assert (checkpoint->referenceCount >= 0);
  1184. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1185. checkpoint->referenceCount);
  1186. /*
  1187. * If checkpoint has been unlinked and this is the last reference, delete it
  1188. */
  1189. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1190. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1191. checkpoint_release (checkpoint);
  1192. } else
  1193. if (checkpoint->referenceCount == 0) {
  1194. poll_timer_add (aisexec_poll_handle,
  1195. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1196. checkpoint,
  1197. timer_function_retention,
  1198. &checkpoint->retention_timer);
  1199. }
  1200. error_exit:
  1201. if (req_exec_ckpt_checkpointclose->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1202. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1203. checkpoint);
  1204. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1205. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1206. res_lib_ckpt_checkpointclose.header.error = error;
  1207. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1208. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1209. }
  1210. return (0);
  1211. }
  1212. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct in_addr source_addr, int endian_conversion_required)
  1213. {
  1214. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1215. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1216. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1217. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1218. SaErrorT error = SA_AIS_OK;
  1219. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1220. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1221. if (ckptCheckpoint == 0) {
  1222. error = SA_AIS_ERR_NOT_EXIST;
  1223. goto error_exit;
  1224. }
  1225. if (ckptCheckpoint->unlinked) {
  1226. error = SA_AIS_ERR_INVALID_PARAM;
  1227. goto error_exit;
  1228. }
  1229. ckptCheckpoint->unlinked = 1;
  1230. /*
  1231. * Immediately delete entry if reference count is zero
  1232. */
  1233. if (ckptCheckpoint->referenceCount == 0) {
  1234. /*
  1235. * Remove retention timer since this checkpoint was unlinked and is no
  1236. * longer referenced
  1237. */
  1238. checkpoint_release (ckptCheckpoint);
  1239. }
  1240. error_exit:
  1241. /*
  1242. * If this node was the source of the message, respond to this node
  1243. */
  1244. if (req_exec_ckpt_checkpointunlink->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1245. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1246. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1247. res_lib_ckpt_checkpointunlink.header.error = error;
  1248. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1249. sizeof (struct res_lib_ckpt_checkpointunlink));
  1250. }
  1251. return (0);
  1252. }
  1253. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1254. {
  1255. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1256. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1257. struct saCkptCheckpoint *checkpoint;
  1258. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1259. if (checkpoint) {
  1260. log_printf (LOG_LEVEL_NOTICE, "CKPT: Setting retention duration for checkpoint %s\n",
  1261. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1262. checkpoint->checkpointCreationAttributes.retentionDuration = req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1263. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1264. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1265. poll_timer_add (aisexec_poll_handle,
  1266. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1267. checkpoint,
  1268. timer_function_retention,
  1269. &checkpoint->retention_timer);
  1270. }
  1271. }
  1272. /*
  1273. * Respond to library if this processor sent the duration set request
  1274. */
  1275. if (req_exec_ckpt_checkpointretentiondurationset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1276. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1277. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1278. res_lib_ckpt_checkpointretentiondurationset.header.error = SA_AIS_OK;
  1279. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1280. &res_lib_ckpt_checkpointretentiondurationset,
  1281. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1282. }
  1283. return (0);
  1284. }
  1285. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct in_addr source_addr, int endian_conversion_required)
  1286. {
  1287. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1288. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1289. struct saCkptCheckpoint *checkpoint;
  1290. struct iovec iovecs[2];
  1291. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1292. if (checkpoint && checkpoint->expired == 0) {
  1293. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1294. checkpoint->expired = 1;
  1295. req_exec_ckpt_checkpointunlink.header.size =
  1296. sizeof (struct req_exec_ckpt_checkpointunlink);
  1297. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1298. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1299. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = 0;
  1300. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1301. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1302. sizeof (SaNameT));
  1303. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1304. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1305. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1306. }
  1307. return (0);
  1308. }
  1309. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1310. SaNameT *checkpointName,
  1311. char* SectionId)
  1312. {
  1313. struct saCkptCheckpoint *ckptCheckpoint;
  1314. struct saCkptCheckpointSection *ckptCheckpointSection;
  1315. void *initialData;
  1316. void *sectionId;
  1317. SaErrorT error = SA_AIS_OK;
  1318. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1319. &checkpointName->value, SectionId);
  1320. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1321. if (ckptCheckpoint == 0) {
  1322. error = SA_AIS_ERR_NOT_EXIST;
  1323. goto error_exit;
  1324. }
  1325. /*
  1326. * Determine if user-specified checkpoint ID already exists
  1327. */
  1328. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1329. SectionId,
  1330. (int)sectionDescriptor->sectionId.idLen);
  1331. if (ckptCheckpointSection) {
  1332. error = SA_AIS_ERR_EXIST;
  1333. goto error_exit;
  1334. }
  1335. /*
  1336. * Allocate checkpoint section
  1337. */
  1338. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1339. if (ckptCheckpointSection == 0) {
  1340. error = SA_AIS_ERR_NO_MEMORY;
  1341. goto error_exit;
  1342. }
  1343. /*
  1344. * Allocate checkpoint section data
  1345. */
  1346. initialData = malloc (sectionDescriptor->sectionSize);
  1347. if (initialData == 0) {
  1348. free (ckptCheckpointSection);
  1349. error = SA_AIS_ERR_NO_MEMORY;
  1350. goto error_exit;
  1351. }
  1352. /*
  1353. * Allocate checkpoint section id
  1354. */
  1355. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1356. if (sectionId == 0) {
  1357. free (ckptCheckpointSection);
  1358. free (initialData);
  1359. error = SA_AIS_ERR_NO_MEMORY;
  1360. goto error_exit;
  1361. }
  1362. /*
  1363. * Copy checkpoint section ID and initialize data.
  1364. */
  1365. memcpy ((char*)sectionId, SectionId,
  1366. (int)sectionDescriptor->sectionId.idLen);
  1367. memset (initialData, 0, sectionDescriptor->sectionSize);
  1368. /*
  1369. * Configure checkpoint section
  1370. */
  1371. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1372. sectionDescriptor,
  1373. sizeof(SaCkptSectionDescriptorT));
  1374. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1375. ckptCheckpointSection->sectionData = initialData;
  1376. ckptCheckpointSection->expiration_timer = 0;
  1377. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1378. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1379. poll_timer_add (aisexec_poll_handle,
  1380. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1381. ckptCheckpointSection,
  1382. timer_function_section_expire,
  1383. &ckptCheckpointSection->expiration_timer);
  1384. }
  1385. /*
  1386. * Add checkpoint section to checkpoint
  1387. */
  1388. list_init (&ckptCheckpointSection->list);
  1389. list_add (&ckptCheckpointSection->list,
  1390. &ckptCheckpoint->checkpointSectionsListHead);
  1391. error_exit:
  1392. return (error);
  1393. }
  1394. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1395. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1396. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1397. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1398. struct saCkptCheckpoint *ckptCheckpoint;
  1399. struct saCkptCheckpointSection *ckptCheckpointSection;
  1400. void *initialData;
  1401. void *sectionId;
  1402. SaErrorT error = SA_AIS_OK;
  1403. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1404. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1405. if (ckptCheckpoint == 0) {
  1406. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1407. goto error_exit;
  1408. }
  1409. /*
  1410. * Determine if user-specified checkpoint ID already exists
  1411. */
  1412. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1413. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1414. req_lib_ckpt_sectioncreate->idLen);
  1415. if (ckptCheckpointSection) {
  1416. error = SA_AIS_ERR_EXIST;
  1417. goto error_exit;
  1418. }
  1419. /*
  1420. * Allocate checkpoint section
  1421. */
  1422. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1423. if (ckptCheckpointSection == 0) {
  1424. error = SA_AIS_ERR_NO_MEMORY;
  1425. goto error_exit;
  1426. }
  1427. /*
  1428. * Allocate checkpoint section data
  1429. */
  1430. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1431. if (initialData == 0) {
  1432. free (ckptCheckpointSection);
  1433. error = SA_AIS_ERR_NO_MEMORY;
  1434. goto error_exit;
  1435. }
  1436. /*
  1437. * Allocate checkpoint section id
  1438. */
  1439. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1440. if (sectionId == 0) {
  1441. free (ckptCheckpointSection);
  1442. free (initialData);
  1443. error = SA_AIS_ERR_NO_MEMORY;
  1444. goto error_exit;
  1445. }
  1446. /*
  1447. * Copy checkpoint section and section ID
  1448. */
  1449. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1450. req_lib_ckpt_sectioncreate->idLen);
  1451. memcpy (initialData,
  1452. ((char *)req_lib_ckpt_sectioncreate) +
  1453. sizeof (struct req_lib_ckpt_sectioncreate) +
  1454. req_lib_ckpt_sectioncreate->idLen,
  1455. req_lib_ckpt_sectioncreate->initialDataSize);
  1456. /*
  1457. * Configure checkpoint section
  1458. */
  1459. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1460. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1461. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1462. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1463. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1464. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1465. ckptCheckpointSection->sectionData = initialData;
  1466. ckptCheckpointSection->expiration_timer = 0;
  1467. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1468. poll_timer_add (aisexec_poll_handle,
  1469. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1470. ckptCheckpointSection,
  1471. timer_function_section_expire,
  1472. &ckptCheckpointSection->expiration_timer);
  1473. }
  1474. /*
  1475. * Add checkpoint section to checkpoint
  1476. */
  1477. list_init (&ckptCheckpointSection->list);
  1478. list_add (&ckptCheckpointSection->list,
  1479. &ckptCheckpoint->checkpointSectionsListHead);
  1480. error_exit:
  1481. if (req_exec_ckpt_sectioncreate->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1482. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1483. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1484. res_lib_ckpt_sectioncreate.header.error = error;
  1485. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1486. &res_lib_ckpt_sectioncreate,
  1487. sizeof (struct res_lib_ckpt_sectioncreate));
  1488. }
  1489. return (0);
  1490. }
  1491. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1492. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1493. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1494. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1495. struct saCkptCheckpoint *ckptCheckpoint;
  1496. struct saCkptCheckpointSection *ckptCheckpointSection;
  1497. SaErrorT error = SA_AIS_OK;
  1498. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1499. if (ckptCheckpoint == 0) {
  1500. error = SA_AIS_ERR_NOT_EXIST;
  1501. goto error_exit;
  1502. }
  1503. /*
  1504. * Determine if the user is trying to delete the default section
  1505. */
  1506. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1507. error = SA_AIS_ERR_INVALID_PARAM;
  1508. goto error_exit;
  1509. }
  1510. /*
  1511. * Find checkpoint section to be deleted
  1512. */
  1513. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1514. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  1515. req_lib_ckpt_sectiondelete->idLen);
  1516. if (ckptCheckpointSection == 0) {
  1517. error = SA_AIS_ERR_NOT_EXIST;
  1518. goto error_exit;
  1519. }
  1520. /*
  1521. * Delete checkpoint section
  1522. */
  1523. checkpoint_section_release (ckptCheckpointSection);
  1524. /*
  1525. * return result to CKPT library
  1526. */
  1527. error_exit:
  1528. if (req_exec_ckpt_sectiondelete->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1529. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  1530. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  1531. res_lib_ckpt_sectiondelete.header.error = error;
  1532. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  1533. &res_lib_ckpt_sectiondelete,
  1534. sizeof (struct res_lib_ckpt_sectiondelete));
  1535. }
  1536. return (0);
  1537. }
  1538. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1539. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  1540. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  1541. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  1542. struct saCkptCheckpoint *ckptCheckpoint;
  1543. struct saCkptCheckpointSection *ckptCheckpointSection;
  1544. SaErrorT error = SA_AIS_OK;
  1545. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  1546. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  1547. if (ckptCheckpoint == 0) {
  1548. error = SA_AIS_ERR_NOT_EXIST;
  1549. goto error_exit;
  1550. }
  1551. /*
  1552. * Determine if the user is trying to set expiration time for the default section
  1553. */
  1554. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  1555. error = SA_AIS_ERR_INVALID_PARAM;
  1556. goto error_exit;
  1557. }
  1558. /*
  1559. * Find checkpoint section that expiration time should be set for
  1560. */
  1561. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1562. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  1563. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  1564. req_lib_ckpt_sectionexpirationtimeset->idLen);
  1565. if (ckptCheckpointSection == 0) {
  1566. error = SA_AIS_ERR_NOT_EXIST;
  1567. goto error_exit;
  1568. }
  1569. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  1570. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  1571. ckptCheckpointSection->expiration_timer = 0;
  1572. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  1573. poll_timer_add (aisexec_poll_handle,
  1574. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1575. ckptCheckpointSection,
  1576. timer_function_section_expire,
  1577. &ckptCheckpointSection->expiration_timer);
  1578. }
  1579. error_exit:
  1580. if (req_exec_ckpt_sectionexpirationtimeset->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1581. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  1582. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  1583. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  1584. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  1585. &res_lib_ckpt_sectionexpirationtimeset,
  1586. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  1587. }
  1588. return (0);
  1589. }
  1590. static int recovery_section_write(int sectionIdLen,
  1591. char* sectionId,
  1592. SaNameT *checkpointName,
  1593. void *newData,
  1594. SaUint32T dataOffSet,
  1595. SaUint32T dataSize)
  1596. {
  1597. struct saCkptCheckpoint *ckptCheckpoint;
  1598. struct saCkptCheckpointSection *ckptCheckpointSection;
  1599. int sizeRequired;
  1600. SaErrorT error = SA_AIS_OK;
  1601. char *sd;
  1602. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  1603. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1604. if (ckptCheckpoint == 0) {
  1605. error = SA_AIS_ERR_NOT_EXIST;
  1606. goto error_exit;
  1607. }
  1608. /*
  1609. * Find checkpoint section to be written
  1610. */
  1611. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1612. sectionId,
  1613. sectionIdLen);
  1614. if (ckptCheckpointSection == 0) {
  1615. error = SA_AIS_ERR_NOT_EXIST;
  1616. goto error_exit;
  1617. }
  1618. /*
  1619. * If write would extend past end of section data, return error;
  1620. */
  1621. sizeRequired = dataOffSet + dataSize;
  1622. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1623. error = SA_AIS_ERR_ACCESS;
  1624. goto error_exit;
  1625. }
  1626. /*
  1627. * Write checkpoint section to section data
  1628. */
  1629. if (dataSize > 0) {
  1630. sd = (char *)ckptCheckpointSection->sectionData;
  1631. memcpy (&sd[dataOffSet],
  1632. newData,
  1633. dataSize);
  1634. }
  1635. error_exit:
  1636. return (error);
  1637. }
  1638. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1639. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  1640. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  1641. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  1642. struct saCkptCheckpoint *ckptCheckpoint;
  1643. struct saCkptCheckpointSection *ckptCheckpointSection;
  1644. int sizeRequired;
  1645. void *sectionData;
  1646. SaErrorT error = SA_AIS_OK;
  1647. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  1648. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  1649. if (ckptCheckpoint == 0) {
  1650. error = SA_AIS_ERR_NOT_EXIST;
  1651. goto error_exit;
  1652. }
  1653. /*
  1654. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1655. */
  1656. /*
  1657. * Find checkpoint section to be written
  1658. */
  1659. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1660. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  1661. req_lib_ckpt_sectionwrite->idLen);
  1662. if (ckptCheckpointSection == 0) {
  1663. printf ("CANT FIND SECTION '%s'\n",
  1664. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  1665. error = SA_AIS_ERR_NOT_EXIST;
  1666. goto error_exit;
  1667. }
  1668. /*
  1669. * If write would extend past end of section data, enlarge section
  1670. */
  1671. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  1672. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1673. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  1674. if (sectionData == 0) {
  1675. error = SA_AIS_ERR_NO_MEMORY;
  1676. goto error_exit;
  1677. }
  1678. /*
  1679. * Install new section data
  1680. */
  1681. ckptCheckpointSection->sectionData = sectionData;
  1682. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  1683. }
  1684. /*
  1685. * Write checkpoint section to section data
  1686. */
  1687. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  1688. char *sd;
  1689. int *val;
  1690. val = ckptCheckpointSection->sectionData;
  1691. sd = (char *)ckptCheckpointSection->sectionData;
  1692. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  1693. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  1694. req_lib_ckpt_sectionwrite->idLen,
  1695. req_lib_ckpt_sectionwrite->dataSize);
  1696. }
  1697. /*
  1698. * Write write response to CKPT library
  1699. */
  1700. error_exit:
  1701. if (req_exec_ckpt_sectionwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1702. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  1703. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  1704. res_lib_ckpt_sectionwrite.header.error = error;
  1705. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  1706. &res_lib_ckpt_sectionwrite,
  1707. sizeof (struct res_lib_ckpt_sectionwrite));
  1708. }
  1709. return (0);
  1710. }
  1711. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1712. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  1713. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  1714. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  1715. struct saCkptCheckpoint *ckptCheckpoint;
  1716. struct saCkptCheckpointSection *ckptCheckpointSection;
  1717. void *sectionData;
  1718. SaErrorT error = SA_AIS_OK;
  1719. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  1720. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  1721. if (ckptCheckpoint == 0) {
  1722. error = SA_AIS_ERR_NOT_EXIST;
  1723. goto error_exit;
  1724. }
  1725. /*
  1726. * Find checkpoint section to be overwritten
  1727. */
  1728. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1729. ((char *)req_lib_ckpt_sectionoverwrite) +
  1730. sizeof (struct req_lib_ckpt_sectionoverwrite),
  1731. req_lib_ckpt_sectionoverwrite->idLen);
  1732. if (ckptCheckpointSection == 0) {
  1733. error = SA_AIS_ERR_NOT_EXIST;
  1734. goto error_exit;
  1735. }
  1736. /*
  1737. * Allocate checkpoint section data
  1738. */
  1739. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  1740. if (sectionData == 0) {
  1741. error = SA_AIS_ERR_NO_MEMORY;
  1742. goto error_exit;
  1743. }
  1744. memcpy (sectionData,
  1745. ((char *)req_lib_ckpt_sectionoverwrite) +
  1746. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  1747. req_lib_ckpt_sectionoverwrite->idLen,
  1748. req_lib_ckpt_sectionoverwrite->dataSize);
  1749. /*
  1750. * release old checkpoint section data
  1751. */
  1752. free (ckptCheckpointSection->sectionData);
  1753. /*
  1754. * Install overwritten checkpoint section data
  1755. */
  1756. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  1757. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1758. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1759. ckptCheckpointSection->sectionData = sectionData;
  1760. /*
  1761. * return result to CKPT library
  1762. */
  1763. error_exit:
  1764. if (req_exec_ckpt_sectionoverwrite->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1765. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  1766. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  1767. res_lib_ckpt_sectionoverwrite.header.error = error;
  1768. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  1769. &res_lib_ckpt_sectionoverwrite,
  1770. sizeof (struct res_lib_ckpt_sectionoverwrite));
  1771. }
  1772. return (0);
  1773. }
  1774. static int message_handler_req_exec_ckpt_sectionread (void *message, struct in_addr source_addr, int endian_conversion_required) {
  1775. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  1776. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  1777. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  1778. struct saCkptCheckpoint *ckptCheckpoint;
  1779. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1780. int sectionSize = 0;
  1781. SaErrorT error = SA_AIS_OK;
  1782. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  1783. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  1784. if (ckptCheckpoint == 0) {
  1785. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  1786. goto error_exit;
  1787. }
  1788. /*
  1789. * Find checkpoint section to be read
  1790. */
  1791. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1792. ((char *)req_lib_ckpt_sectionread) +
  1793. sizeof (struct req_lib_ckpt_sectionread),
  1794. req_lib_ckpt_sectionread->idLen);
  1795. if (ckptCheckpointSection == 0) {
  1796. error = SA_AIS_ERR_NOT_EXIST;
  1797. goto error_exit;
  1798. }
  1799. /*
  1800. * Determine the section size
  1801. */
  1802. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  1803. req_lib_ckpt_sectionread->dataOffset;
  1804. /*
  1805. * If the library has less space available then can be sent from the
  1806. * section, reduce bytes sent to library to max requested
  1807. */
  1808. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  1809. sectionSize = req_lib_ckpt_sectionread->dataSize;
  1810. }
  1811. /*
  1812. * If dataOffset is past end of data, return INVALID PARAM
  1813. */
  1814. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  1815. sectionSize = 0;
  1816. error = SA_AIS_ERR_INVALID_PARAM;
  1817. goto error_exit;
  1818. }
  1819. /*
  1820. * Write read response to CKPT library
  1821. */
  1822. error_exit:
  1823. if (req_exec_ckpt_sectionread->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1824. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  1825. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  1826. res_lib_ckpt_sectionread.header.error = error;
  1827. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1828. &res_lib_ckpt_sectionread,
  1829. sizeof (struct res_lib_ckpt_sectionread));
  1830. /*
  1831. * Write checkpoint to CKPT library section if section has data
  1832. */
  1833. if (sectionSize) {
  1834. char *sd;
  1835. sd = (char *)ckptCheckpointSection->sectionData;
  1836. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  1837. &sd[req_lib_ckpt_sectionread->dataOffset],
  1838. sectionSize);
  1839. }
  1840. }
  1841. return (0);
  1842. }
  1843. static int message_handler_req_lib_ckpt_init (struct conn_info *conn_info, void *message)
  1844. {
  1845. struct res_lib_init res_lib_init;
  1846. SaErrorT error = SA_AIS_ERR_ACCESS;
  1847. log_printf (LOG_LEVEL_DEBUG, "Got request to initialize CKPT checkpoint.\n");
  1848. if (conn_info->authenticated) {
  1849. conn_info->service = SOCKET_SERVICE_CKPT;
  1850. list_init (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list);
  1851. conn_info->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  1852. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  1853. conn_info->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  1854. list_add (&conn_info->ais_ci.u.libckpt_ci.sectionIterator.list,
  1855. &checkpoint_iterator_list_head);
  1856. list_init (&conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1857. error = SA_AIS_OK;
  1858. }
  1859. res_lib_init.header.size = sizeof (struct res_lib_init);
  1860. res_lib_init.header.id = MESSAGE_RES_INIT;
  1861. res_lib_init.header.error = error;
  1862. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1863. if (conn_info->authenticated) {
  1864. return (0);
  1865. }
  1866. return (-1);
  1867. }
  1868. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  1869. {
  1870. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  1871. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  1872. struct iovec iovecs[2];
  1873. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  1874. req_exec_ckpt_checkpointopen.header.size =
  1875. sizeof (struct req_exec_ckpt_checkpointopen);
  1876. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  1877. req_exec_ckpt_checkpointopen.source.conn_info = conn_info;
  1878. req_exec_ckpt_checkpointopen.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1879. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  1880. req_lib_ckpt_checkpointopen,
  1881. sizeof (struct req_lib_ckpt_checkpointopen));
  1882. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  1883. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  1884. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1885. return (0);
  1886. }
  1887. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  1888. {
  1889. return (0);
  1890. }
  1891. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  1892. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  1893. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  1894. struct saCkptCheckpoint *checkpoint;
  1895. struct iovec iovecs[2];
  1896. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  1897. if (checkpoint->expired == 1) {
  1898. return (0);
  1899. }
  1900. req_exec_ckpt_checkpointclose.header.size =
  1901. sizeof (struct req_exec_ckpt_checkpointclose);
  1902. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  1903. req_exec_ckpt_checkpointclose.source.conn_info = conn_info;
  1904. req_exec_ckpt_checkpointclose.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1905. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  1906. &checkpoint->name, sizeof (SaNameT));
  1907. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  1908. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  1909. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  1910. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1911. }
  1912. return (0);
  1913. }
  1914. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  1915. {
  1916. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  1917. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1918. struct iovec iovecs[2];
  1919. req_exec_ckpt_checkpointunlink.header.size =
  1920. sizeof (struct req_exec_ckpt_checkpointunlink);
  1921. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1922. req_exec_ckpt_checkpointunlink.source.conn_info = conn_info;
  1923. req_exec_ckpt_checkpointunlink.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1924. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  1925. req_lib_ckpt_checkpointunlink,
  1926. sizeof (struct req_lib_ckpt_checkpointunlink));
  1927. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1928. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1929. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1930. return (0);
  1931. }
  1932. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  1933. {
  1934. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  1935. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  1936. struct iovec iovecs[2];
  1937. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  1938. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  1939. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  1940. req_exec_ckpt_checkpointretentiondurationset.source.conn_info = conn_info;
  1941. req_exec_ckpt_checkpointretentiondurationset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1942. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  1943. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  1944. sizeof (SaNameT));
  1945. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  1946. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  1947. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  1948. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1949. return (0);
  1950. }
  1951. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  1952. {
  1953. return (0);
  1954. }
  1955. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  1956. {
  1957. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  1958. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  1959. struct saCkptCheckpoint *checkpoint;
  1960. int memoryUsed = 0;
  1961. int numberOfSections = 0;
  1962. struct list_head *checkpoint_section_list;
  1963. struct saCkptCheckpointSection *checkpointSection;
  1964. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  1965. /*
  1966. * Count memory used by checkpoint sections
  1967. */
  1968. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  1969. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  1970. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  1971. checkpoint_section_list = checkpoint_section_list->next) {
  1972. checkpointSection = list_entry (checkpoint_section_list,
  1973. struct saCkptCheckpointSection, list);
  1974. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  1975. numberOfSections += 1;
  1976. }
  1977. /*
  1978. * Build checkpoint status get response
  1979. */
  1980. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  1981. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  1982. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  1983. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  1984. &checkpoint->checkpointCreationAttributes,
  1985. sizeof (SaCkptCheckpointCreationAttributesT));
  1986. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  1987. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  1988. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  1989. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  1990. sizeof (struct res_lib_ckpt_checkpointstatusget));
  1991. return (0);
  1992. }
  1993. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  1994. {
  1995. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  1996. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  1997. struct iovec iovecs[2];
  1998. struct saCkptCheckpoint *checkpoint;
  1999. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2000. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2001. /*
  2002. * checkpoint opened is writeable mode so send message to cluster
  2003. */
  2004. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2005. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2006. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2007. req_lib_ckpt_sectioncreate,
  2008. sizeof (struct req_lib_ckpt_sectioncreate));
  2009. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2010. &req_lib_ckpt_sectioncreate->checkpointName,
  2011. sizeof (SaNameT));
  2012. req_exec_ckpt_sectioncreate.source.conn_info = conn_info;
  2013. req_exec_ckpt_sectioncreate.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2014. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2015. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2016. /*
  2017. * Send section name and initial data in message
  2018. */
  2019. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2020. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2021. #ifdef DEBUG
  2022. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2023. iovecs[1].iov_len);
  2024. printf ("|\n");
  2025. { int i;
  2026. char *abc = iovecs[1].iov_base;
  2027. for (i = 0; i < 14;i++) {
  2028. printf ("%c ", abc[i]);
  2029. }
  2030. }
  2031. printf ("|\n");
  2032. #endif
  2033. if (iovecs[1].iov_len > 0) {
  2034. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2035. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2036. } else {
  2037. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2038. }
  2039. return (0);
  2040. }
  2041. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2042. {
  2043. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2044. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2045. struct iovec iovecs[2];
  2046. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2047. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2048. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2049. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2050. &req_lib_ckpt_sectiondelete->checkpointName,
  2051. sizeof (SaNameT));
  2052. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2053. req_lib_ckpt_sectiondelete,
  2054. sizeof (struct req_lib_ckpt_sectiondelete));
  2055. req_exec_ckpt_sectiondelete.source.conn_info = conn_info;
  2056. req_exec_ckpt_sectiondelete.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2057. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2058. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2059. /*
  2060. * Send section name
  2061. */
  2062. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2063. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2064. if (iovecs[1].iov_len > 0) {
  2065. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2066. } else {
  2067. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2068. }
  2069. return (0);
  2070. }
  2071. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2072. {
  2073. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2074. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2075. struct iovec iovecs[2];
  2076. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2077. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2078. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2079. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2080. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2081. sizeof (SaNameT));
  2082. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2083. req_lib_ckpt_sectionexpirationtimeset,
  2084. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2085. req_exec_ckpt_sectionexpirationtimeset.source.conn_info = conn_info;
  2086. req_exec_ckpt_sectionexpirationtimeset.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2087. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2088. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2089. /*
  2090. * Send section name
  2091. */
  2092. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2093. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2094. if (iovecs[1].iov_len > 0) {
  2095. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2096. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2097. } else {
  2098. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2099. }
  2100. return (0);
  2101. }
  2102. int write_inv = 0;
  2103. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2104. {
  2105. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2106. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2107. struct iovec iovecs[2];
  2108. struct saCkptCheckpoint *checkpoint;
  2109. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2110. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2111. /*
  2112. * checkpoint opened is writeable mode so send message to cluster
  2113. */
  2114. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2115. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2116. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2117. req_lib_ckpt_sectionwrite,
  2118. sizeof (struct req_lib_ckpt_sectionwrite));
  2119. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2120. &req_lib_ckpt_sectionwrite->checkpointName,
  2121. sizeof (SaNameT));
  2122. req_exec_ckpt_sectionwrite.source.conn_info = conn_info;
  2123. req_exec_ckpt_sectionwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2124. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2125. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2126. /*
  2127. * Send section name and data to write in message
  2128. */
  2129. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2130. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2131. /*
  2132. printf ("LIB writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2133. */
  2134. if (iovecs[1].iov_len > 0) {
  2135. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2136. } else {
  2137. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2138. }
  2139. return (0);
  2140. }
  2141. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2142. {
  2143. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2144. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2145. struct iovec iovecs[2];
  2146. struct saCkptCheckpoint *checkpoint;
  2147. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2148. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2149. /*
  2150. * checkpoint opened is writeable mode so send message to cluster
  2151. */
  2152. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2153. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2154. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2155. req_lib_ckpt_sectionoverwrite,
  2156. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2157. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2158. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2159. sizeof (SaNameT));
  2160. req_exec_ckpt_sectionoverwrite.source.conn_info = conn_info;
  2161. req_exec_ckpt_sectionoverwrite.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2162. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2163. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2164. /*
  2165. * Send section name and data to overwrite in message
  2166. */
  2167. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2168. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2169. if (iovecs[1].iov_len > 0) {
  2170. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2171. } else {
  2172. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2173. }
  2174. return (0);
  2175. }
  2176. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2177. {
  2178. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2179. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2180. struct iovec iovecs[2];
  2181. struct saCkptCheckpoint *checkpoint;
  2182. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2183. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2184. /*
  2185. * checkpoint opened is writeable mode so send message to cluster
  2186. */
  2187. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2188. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2189. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2190. req_lib_ckpt_sectionread,
  2191. sizeof (struct req_lib_ckpt_sectionread));
  2192. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2193. &req_lib_ckpt_sectionread->checkpointName,
  2194. sizeof (SaNameT));
  2195. req_exec_ckpt_sectionread.source.conn_info = conn_info;
  2196. req_exec_ckpt_sectionread.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2197. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2198. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2199. /*
  2200. * Send section name and data to overwrite in message
  2201. */
  2202. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2203. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2204. if (iovecs[1].iov_len > 0) {
  2205. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2206. } else {
  2207. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2208. }
  2209. return (0);
  2210. }
  2211. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2212. {
  2213. return (0);
  2214. }
  2215. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2216. {
  2217. return (0);
  2218. }
  2219. static int message_handler_req_lib_ckpt_sectioniteratorinitialize (struct conn_info *conn_info, void *message)
  2220. {
  2221. struct req_lib_ckpt_sectioniteratorinitialize *req_lib_ckpt_sectioniteratorinitialize = (struct req_lib_ckpt_sectioniteratorinitialize *)message;
  2222. struct res_lib_ckpt_sectioniteratorinitialize res_lib_ckpt_sectioniteratorinitialize;
  2223. struct saCkptCheckpoint *ckptCheckpoint;
  2224. struct saCkptCheckpointSection *ckptCheckpointSection;
  2225. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2226. struct saCkptSectionIterator *ckptSectionIterator;
  2227. struct list_head *checkpoint_section_list;
  2228. int addEntry = 0;
  2229. int iteratorEntries = 0;
  2230. SaErrorT error = SA_AIS_OK;
  2231. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2232. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2233. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniteratorinitialize->checkpointName);
  2234. if (ckptCheckpoint == 0) {
  2235. error = SA_AIS_ERR_NOT_EXIST;
  2236. goto error_exit;
  2237. }
  2238. /*
  2239. * Iterate list of checkpoint sections
  2240. */
  2241. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2242. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2243. checkpoint_section_list = checkpoint_section_list->next) {
  2244. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2245. struct saCkptCheckpointSection, list);
  2246. addEntry = 1;
  2247. /*
  2248. * Item should be added to iterator list
  2249. */
  2250. if (addEntry) {
  2251. iteratorEntries += 1;
  2252. ckptSectionIteratorEntries =
  2253. realloc (ckptSectionIterator->sectionIteratorEntries,
  2254. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2255. if (ckptSectionIteratorEntries == 0) {
  2256. if (ckptSectionIterator->sectionIteratorEntries) {
  2257. free (ckptSectionIterator->sectionIteratorEntries);
  2258. }
  2259. error = SA_AIS_ERR_NO_MEMORY;
  2260. goto error_exit;
  2261. }
  2262. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2263. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2264. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2265. }
  2266. }
  2267. ckptSectionIterator->iteratorCount = iteratorEntries;
  2268. error_exit:
  2269. res_lib_ckpt_sectioniteratorinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniteratorinitialize);
  2270. res_lib_ckpt_sectioniteratorinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2271. res_lib_ckpt_sectioniteratorinitialize.header.error = error;
  2272. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratorinitialize,
  2273. sizeof (struct res_lib_ckpt_sectioniteratorinitialize));
  2274. return (0);
  2275. }
  2276. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2277. {
  2278. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2279. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2280. struct saCkptSectionIterator *ckptSectionIterator;
  2281. SaErrorT error = SA_AIS_OK;
  2282. int sectionIdSize = 0;
  2283. int iteratorPos = 0;
  2284. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2285. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2286. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2287. /*
  2288. * Find active iterator entry
  2289. */
  2290. for (;;) {
  2291. /*
  2292. * No more sections in iterator
  2293. */
  2294. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  2295. error = SA_AIS_ERR_NOT_EXIST;
  2296. goto error_exit;
  2297. }
  2298. /*
  2299. * active iterator entry
  2300. */
  2301. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  2302. break;
  2303. }
  2304. ckptSectionIterator->iteratorPos += 1;
  2305. }
  2306. /*
  2307. * Prepare response to API
  2308. */
  2309. iteratorPos = ckptSectionIterator->iteratorPos;
  2310. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  2311. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  2312. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  2313. sizeof (SaCkptSectionDescriptorT));
  2314. /*
  2315. * Get to next iterator entry
  2316. */
  2317. ckptSectionIterator->iteratorPos += 1;
  2318. error_exit:
  2319. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  2320. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  2321. res_lib_ckpt_sectioniteratornext.header.error = error;
  2322. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  2323. sizeof (struct res_lib_ckpt_sectioniteratornext));
  2324. libais_send_response (conn_info,
  2325. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  2326. sectionIdSize);
  2327. return (0);
  2328. }