ckpt.c 135 KB

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