ckpt.c 136 KB

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