ckpt.c 143 KB

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