ckpt.c 99 KB

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