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