ckpt.c 139 KB

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