ckpt.c 130 KB

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