ckpt.c 143 KB

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