ckpt.c 139 KB

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