ckpt.c 137 KB

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