ckpt.c 137 KB

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