ckpt.c 136 KB

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