ckpt.c 145 KB

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