ckpt.c 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872
  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. printf ("allocating checkpoint cleanup %p\n", checkpoint_cleanup);
  1338. if (checkpoint_cleanup == 0) {
  1339. error = SA_AIS_ERR_NO_MEMORY;
  1340. goto error_exit;
  1341. }
  1342. }
  1343. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointopen->checkpointName);
  1344. /*
  1345. * If checkpoint doesn't exist, create one
  1346. */
  1347. if (ckptCheckpoint == 0) {
  1348. if ((req_lib_ckpt_checkpointopen->checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) {
  1349. error = SA_AIS_ERR_NOT_EXIST;
  1350. goto error_exit;
  1351. }
  1352. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1353. if (ckptCheckpoint == 0) {
  1354. error = SA_AIS_ERR_NO_MEMORY;
  1355. goto error_exit;
  1356. }
  1357. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1358. if (ckptCheckpointSection == 0) {
  1359. free (ckptCheckpoint);
  1360. error = SA_AIS_ERR_NO_MEMORY;
  1361. goto error_exit;
  1362. }
  1363. memcpy (&ckptCheckpoint->name,
  1364. &req_lib_ckpt_checkpointopen->checkpointName,
  1365. sizeof (SaNameT));
  1366. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1367. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1368. sizeof (SaCkptCheckpointCreationAttributesT));
  1369. ckptCheckpoint->unlinked = 0;
  1370. list_init (&ckptCheckpoint->list);
  1371. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1372. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1373. ckptCheckpoint->referenceCount = 0;
  1374. ckptCheckpoint->retention_timer = 0;
  1375. ckptCheckpoint->expired = 0;
  1376. ckptCheckpoint->sectionCount = 0;
  1377. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1378. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1379. ckptCheckpoint->active_replica_set = 1;
  1380. } else
  1381. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1382. ckptCheckpoint->active_replica_set = 1;
  1383. } else {
  1384. ckptCheckpoint->active_replica_set = 0;
  1385. }
  1386. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1387. /*
  1388. * Add in default checkpoint section
  1389. */
  1390. list_init (&ckptCheckpointSection->list);
  1391. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1392. /*
  1393. * Default section id
  1394. */
  1395. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1396. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1397. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1398. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1399. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1400. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1401. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1402. assert(ckptCheckpointSection->sectionData);
  1403. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1404. ckptCheckpointSection->expiration_timer = 0;
  1405. } else {
  1406. if (req_lib_ckpt_checkpointopen->checkpointCreationAttributesSet &&
  1407. memcmp (&ckptCheckpoint->checkpointCreationAttributes,
  1408. &req_lib_ckpt_checkpointopen->checkpointCreationAttributes,
  1409. sizeof (SaCkptCheckpointCreationAttributesT)) != 0) {
  1410. error = SA_AIS_ERR_EXIST;
  1411. goto error_exit;
  1412. }
  1413. }
  1414. /*
  1415. * If the checkpoint has been unlinked, it is an invalid name
  1416. */
  1417. if (ckptCheckpoint->unlinked) {
  1418. error = SA_AIS_ERR_NOT_EXIST; /* Is this the correct return ? */
  1419. goto error_exit;
  1420. }
  1421. /*
  1422. * Setup connection information and mark checkpoint as referenced
  1423. */
  1424. log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", ckptCheckpoint);
  1425. ckptCheckpoint->referenceCount += 1;
  1426. /*
  1427. * Add the connection reference information to the Checkpoint to be
  1428. * sent out later as a part of the sync process.
  1429. *
  1430. */
  1431. proc_index = processor_index_find(source_addr,ckptCheckpoint->ckpt_refcount);
  1432. if (proc_index == -1) {/* Could not find, lets set the processor to an index.*/
  1433. proc_index = processor_index_set(source_addr,ckptCheckpoint->ckpt_refcount);
  1434. }
  1435. if (proc_index != -1 ) {
  1436. totemip_copy(&ckptCheckpoint->ckpt_refcount[proc_index].addr, source_addr);
  1437. ckptCheckpoint->ckpt_refcount[proc_index].count++;
  1438. }
  1439. else {
  1440. log_printf (LOG_LEVEL_ERROR,
  1441. "CKPT: MAX LIMIT OF PROCESSORS reached. Cannot store new proc %p info.\n",
  1442. ckptCheckpoint);
  1443. }
  1444. /*
  1445. * Reset retention duration since this checkpoint was just opened
  1446. */
  1447. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1448. ckptCheckpoint->retention_timer = 0;
  1449. /*
  1450. * Send error result to CKPT library
  1451. */
  1452. error_exit:
  1453. /*
  1454. * If this node was the source of the message, respond to this node
  1455. */
  1456. if (message_source_is_local(&req_exec_ckpt_checkpointopen->source)) {
  1457. /*
  1458. * If its an async call respond with the invocation and handle
  1459. */
  1460. if (req_exec_ckpt_checkpointopen->async_call) {
  1461. res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync);
  1462. res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC;
  1463. res_lib_ckpt_checkpointopenasync.header.error = error;
  1464. res_lib_ckpt_checkpointopenasync.checkpointHandle = req_exec_ckpt_checkpointopen->checkpointHandle;
  1465. res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation;
  1466. openais_conn_send_response (
  1467. req_exec_ckpt_checkpointopen->source.conn,
  1468. &res_lib_ckpt_checkpointopenasync,
  1469. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1470. openais_conn_send_response (
  1471. openais_conn_partner_get (req_exec_ckpt_checkpointopen->source.conn),
  1472. &res_lib_ckpt_checkpointopenasync,
  1473. sizeof (struct res_lib_ckpt_checkpointopenasync));
  1474. } else {
  1475. /*
  1476. * otherwise respond with the normal checkpointopen response
  1477. */
  1478. res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen);
  1479. res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN;
  1480. res_lib_ckpt_checkpointopen.header.error = error;
  1481. openais_conn_send_response (
  1482. req_exec_ckpt_checkpointopen->source.conn,
  1483. &res_lib_ckpt_checkpointopen,
  1484. sizeof (struct res_lib_ckpt_checkpointopen));
  1485. }
  1486. /*
  1487. * This is the path taken when all goes well and this call was local
  1488. */
  1489. if (error == SA_AIS_OK) {
  1490. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1491. ckpt_pd = openais_conn_private_data_get (req_exec_ckpt_checkpointopen->source.conn);
  1492. list_add (&checkpoint_cleanup->list,
  1493. &ckpt_pd->checkpoint_list);
  1494. } else {
  1495. /*
  1496. * We allocated this in the hope of using it but an error occured
  1497. * so deallocate it.
  1498. */
  1499. free (checkpoint_cleanup);
  1500. }
  1501. }
  1502. }
  1503. static int recovery_checkpoint_open(
  1504. SaNameT *checkpointName,
  1505. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1506. struct ckpt_refcnt *ref_cnt)
  1507. {
  1508. int i;
  1509. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1510. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1511. SaAisErrorT error = SA_AIS_OK;
  1512. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1513. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1514. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1515. if (ref_cnt[i].addr.family == 0) {
  1516. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1517. ref_cnt[i].count);
  1518. }
  1519. else {
  1520. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1521. i,
  1522. totemip_print(&ref_cnt[i].addr),
  1523. ref_cnt[i].count);
  1524. }
  1525. }
  1526. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1527. /*
  1528. * If checkpoint doesn't exist, create one
  1529. */
  1530. if (ckptCheckpoint == 0) {
  1531. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1532. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1533. if (ckptCheckpoint == 0) {
  1534. error = SA_AIS_ERR_NO_MEMORY;
  1535. goto error_exit;
  1536. }
  1537. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1538. if (ckptCheckpointSection == 0) {
  1539. free (ckptCheckpoint);
  1540. error = SA_AIS_ERR_NO_MEMORY;
  1541. goto error_exit;
  1542. }
  1543. memcpy (&ckptCheckpoint->name,
  1544. checkpointName,
  1545. sizeof (SaNameT));
  1546. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1547. ckptAttributes,
  1548. sizeof (SaCkptCheckpointCreationAttributesT));
  1549. ckptCheckpoint->unlinked = 0;
  1550. list_init (&ckptCheckpoint->list);
  1551. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1552. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1553. ckptCheckpoint->retention_timer = 0;
  1554. ckptCheckpoint->expired = 0;
  1555. /*
  1556. * Add in default checkpoint section
  1557. */
  1558. list_init (&ckptCheckpointSection->list);
  1559. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1560. /*
  1561. * Default section id
  1562. */
  1563. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1564. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1565. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1566. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1567. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1568. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1569. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1570. assert(ckptCheckpointSection->sectionData);
  1571. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1572. ckptCheckpointSection->expiration_timer = 0;
  1573. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1574. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1575. ckptCheckpoint->active_replica_set = 1;
  1576. } else
  1577. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1578. ckptCheckpoint->active_replica_set = 1;
  1579. } else {
  1580. ckptCheckpoint->active_replica_set = 0;
  1581. }
  1582. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1583. }
  1584. else {
  1585. /*
  1586. * Setup connection information and mark checkpoint as referenced
  1587. */
  1588. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1589. }
  1590. /*
  1591. * If the checkpoint has been unlinked, it is an invalid name
  1592. */
  1593. if (ckptCheckpoint->unlinked) {
  1594. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1595. goto error_exit;
  1596. }
  1597. /*CHECK to see if there are any existing ckpts*/
  1598. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1599. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1600. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1601. }
  1602. else {
  1603. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1604. }
  1605. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1606. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1607. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1608. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1609. /*
  1610. * Reset retention duration since this checkpoint was just opened
  1611. */
  1612. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1613. ckptCheckpoint->retention_timer = 0;
  1614. /*
  1615. * Send error result to CKPT library
  1616. */
  1617. error_exit:
  1618. return (error);
  1619. }
  1620. static void message_handler_req_exec_ckpt_synchronize_state (
  1621. void *message,
  1622. struct totem_ip_address *source_addr)
  1623. {
  1624. int retcode;
  1625. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1626. = (struct req_exec_ckpt_synchronize_state *)message;
  1627. /*
  1628. * If the Incoming message's previous ring id == saved_ring_id
  1629. * Ignore because we have seen this message before.
  1630. */
  1631. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1632. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1633. return;
  1634. }
  1635. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1636. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1637. req_exec_ckpt_sync_state->ckpt_refcount);
  1638. if (retcode != SA_AIS_OK) {
  1639. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1640. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1641. }
  1642. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1643. &req_exec_ckpt_sync_state->checkpointName,
  1644. (char*)req_exec_ckpt_sync_state
  1645. + sizeof (struct req_exec_ckpt_synchronize_state));
  1646. if (retcode != SA_AIS_OK) {
  1647. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1648. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1649. }
  1650. }
  1651. static void message_handler_req_exec_ckpt_synchronize_section (
  1652. void *message,
  1653. struct totem_ip_address *source_addr)
  1654. {
  1655. int retcode;
  1656. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1657. = (struct req_exec_ckpt_synchronize_section *)message;
  1658. /*
  1659. * If the Incoming message's previous ring id == saved_ring_id
  1660. * Ignore because we have seen this message before.
  1661. */
  1662. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1663. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1664. return;
  1665. }
  1666. /*
  1667. * Write the contents of the section to the checkpoint section.
  1668. */
  1669. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1670. (char*)req_exec_ckpt_sync_section
  1671. + sizeof (struct req_exec_ckpt_synchronize_section),
  1672. &req_exec_ckpt_sync_section->checkpointName,
  1673. (char*)req_exec_ckpt_sync_section
  1674. + sizeof (struct req_exec_ckpt_synchronize_section)
  1675. + req_exec_ckpt_sync_section->sectionId.idLen,
  1676. req_exec_ckpt_sync_section->dataOffSet,
  1677. req_exec_ckpt_sync_section->dataSize);
  1678. if (retcode != SA_AIS_OK) {
  1679. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1680. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1681. }
  1682. }
  1683. unsigned int abstime_to_msec (SaTimeT time)
  1684. {
  1685. struct timeval tv;
  1686. unsigned long long curr_time;
  1687. unsigned long long msec_time;
  1688. gettimeofday (&tv, NULL);
  1689. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1690. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1691. msec_time = (((unsigned long long)time) / 1000000) -
  1692. (unsigned long long)curr_time;
  1693. return ((unsigned int)(msec_time));
  1694. }
  1695. void timer_function_section_expire (void *data)
  1696. {
  1697. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1698. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1699. struct ckpt_identifier *ckpt_id = 0;
  1700. ckpt_id = (struct ckpt_identifier *)data;
  1701. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1702. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1703. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1704. ckpt_id->ckpt_section_id.id,
  1705. (char *)&ckpt_id->ckpt_name.value);
  1706. }
  1707. else {
  1708. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1709. goto free_mem;
  1710. }
  1711. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1712. if (ckptCheckpoint == 0) {
  1713. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1714. (char *)&ckpt_id->ckpt_name.value);
  1715. goto free_mem;
  1716. }
  1717. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1718. (char *)ckpt_id->ckpt_section_id.id,
  1719. (int)ckpt_id->ckpt_section_id.idLen);
  1720. if (ckptCheckpointSection == 0) {
  1721. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1722. ckpt_id->ckpt_section_id.id,
  1723. (char *)&ckpt_id->ckpt_name.value);
  1724. goto free_mem;
  1725. }
  1726. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1727. ckpt_id->ckpt_section_id.id,
  1728. (char *)&ckpt_id->ckpt_name.value);
  1729. ckptCheckpoint->sectionCount -= 1;
  1730. checkpoint_section_release (ckptCheckpointSection);
  1731. free_mem :
  1732. free (ckpt_id);
  1733. }
  1734. void timer_function_retention (void *data)
  1735. {
  1736. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1737. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1738. struct iovec iovec;
  1739. checkpoint->retention_timer = 0;
  1740. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1741. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1742. req_exec_ckpt_checkpointretentiondurationexpire.header.id =
  1743. SERVICE_ID_MAKE (CKPT_SERVICE,
  1744. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE);
  1745. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1746. &checkpoint->name,
  1747. sizeof (SaNameT));
  1748. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1749. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1750. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  1751. }
  1752. static void message_handler_req_exec_ckpt_checkpointclose (
  1753. void *message,
  1754. struct totem_ip_address *source_addr)
  1755. {
  1756. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1757. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1758. struct saCkptCheckpoint *checkpoint = 0;
  1759. SaAisErrorT error = SA_AIS_OK;
  1760. int proc_index;
  1761. int release_checkpoint = 0;
  1762. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1763. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1764. if (checkpoint == 0) {
  1765. goto error_exit;
  1766. }
  1767. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1768. checkpoint->referenceCount--;
  1769. /*
  1770. * Modify the connection reference information to the Checkpoint to be
  1771. * sent out later as a part of the sync process.
  1772. */
  1773. proc_index = processor_index_find(source_addr, checkpoint->ckpt_refcount);
  1774. if (proc_index != -1 ) {
  1775. checkpoint->ckpt_refcount[proc_index].count--;
  1776. }
  1777. else {
  1778. log_printf (LOG_LEVEL_ERROR,
  1779. "CKPT: Could Not find Processor Info %p info.\n",
  1780. checkpoint);
  1781. }
  1782. assert (checkpoint->referenceCount >= 0);
  1783. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1784. checkpoint->referenceCount);
  1785. /*
  1786. * If checkpoint has been unlinked and this is the last reference, delete it
  1787. */
  1788. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1789. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1790. release_checkpoint = 1;
  1791. } else
  1792. if (checkpoint->referenceCount == 0) {
  1793. poll_timer_add (aisexec_poll_handle,
  1794. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1795. checkpoint,
  1796. timer_function_retention,
  1797. &checkpoint->retention_timer);
  1798. }
  1799. error_exit:
  1800. /*Remove the checkpoint from my connections checkpoint list*/
  1801. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1802. ckpt_checkpoint_remove_cleanup (
  1803. req_exec_ckpt_checkpointclose->source.conn,
  1804. checkpoint);
  1805. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1806. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1807. res_lib_ckpt_checkpointclose.header.error = error;
  1808. openais_conn_send_response (req_exec_ckpt_checkpointclose->source.conn,
  1809. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1810. }
  1811. /*Release the checkpoint if instructed to do so.*/
  1812. if (release_checkpoint) {
  1813. checkpoint_release(checkpoint);
  1814. }
  1815. }
  1816. static void message_handler_req_exec_ckpt_checkpointunlink (
  1817. void *message,
  1818. struct totem_ip_address *source_addr)
  1819. {
  1820. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1821. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1822. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1823. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1824. SaAisErrorT error = SA_AIS_OK;
  1825. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1826. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1827. if (ckptCheckpoint == 0) {
  1828. error = SA_AIS_ERR_NOT_EXIST;
  1829. goto error_exit;
  1830. }
  1831. if (ckptCheckpoint->unlinked) {
  1832. error = SA_AIS_ERR_INVALID_PARAM;
  1833. goto error_exit;
  1834. }
  1835. ckptCheckpoint->unlinked = 1;
  1836. /*
  1837. * Immediately delete entry if reference count is zero
  1838. */
  1839. if (ckptCheckpoint->referenceCount == 0) {
  1840. /*
  1841. * Remove retention timer since this checkpoint was unlinked and is no
  1842. * longer referenced
  1843. */
  1844. checkpoint_release (ckptCheckpoint);
  1845. }
  1846. error_exit:
  1847. /*
  1848. * If this node was the source of the message, respond to this node
  1849. */
  1850. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1851. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1852. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1853. res_lib_ckpt_checkpointunlink.header.error = error;
  1854. openais_conn_send_response (
  1855. req_exec_ckpt_checkpointunlink->source.conn,
  1856. &res_lib_ckpt_checkpointunlink,
  1857. sizeof (struct res_lib_ckpt_checkpointunlink));
  1858. }
  1859. }
  1860. static void message_handler_req_exec_ckpt_checkpointretentiondurationset (
  1861. void *message,
  1862. struct totem_ip_address *source_addr)
  1863. {
  1864. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1865. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1866. struct saCkptCheckpoint *checkpoint;
  1867. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  1868. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1869. if (checkpoint) {
  1870. log_printf (LOG_LEVEL_DEBUG, "CKPT: Setting retention duration for checkpoint %s\n",
  1871. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1872. if (checkpoint->unlinked == 0) {
  1873. checkpoint->checkpointCreationAttributes.retentionDuration =
  1874. req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1875. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1876. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1877. poll_timer_add (aisexec_poll_handle,
  1878. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1879. checkpoint,
  1880. timer_function_retention,
  1881. &checkpoint->retention_timer);
  1882. }
  1883. error = SA_AIS_OK;
  1884. }
  1885. }
  1886. /*
  1887. * Respond to library if this processor sent the duration set request
  1888. */
  1889. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1890. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1891. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1892. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  1893. openais_conn_send_response (
  1894. req_exec_ckpt_checkpointretentiondurationset->source.conn,
  1895. &res_lib_ckpt_checkpointretentiondurationset,
  1896. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1897. }
  1898. }
  1899. static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire (
  1900. void *message,
  1901. struct totem_ip_address *source_addr)
  1902. {
  1903. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1904. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1905. struct saCkptCheckpoint *checkpoint;
  1906. struct iovec iovecs[2];
  1907. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1908. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount < 1)) {
  1909. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1910. checkpoint->expired = 1;
  1911. req_exec_ckpt_checkpointunlink.header.size =
  1912. sizeof (struct req_exec_ckpt_checkpointunlink);
  1913. req_exec_ckpt_checkpointunlink.header.id =
  1914. SERVICE_ID_MAKE (CKPT_SERVICE,
  1915. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  1916. req_exec_ckpt_checkpointunlink.source.conn = 0;
  1917. req_exec_ckpt_checkpointunlink.source.addr.family = 0;
  1918. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1919. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1920. sizeof (SaNameT));
  1921. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1922. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1923. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  1924. }
  1925. }
  1926. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1927. SaNameT *checkpointName,
  1928. char* SectionId)
  1929. {
  1930. struct saCkptCheckpoint *ckptCheckpoint;
  1931. struct saCkptCheckpointSection *ckptCheckpointSection;
  1932. void *initialData;
  1933. void *sectionId;
  1934. struct ckpt_identifier *ckpt_id = 0;
  1935. SaAisErrorT error = SA_AIS_OK;
  1936. if ((int)sectionDescriptor->sectionId.idLen) {
  1937. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1938. &checkpointName->value, SectionId);
  1939. } else {
  1940. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1941. &checkpointName->value);
  1942. }
  1943. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1944. if (ckptCheckpoint == 0) {
  1945. error = SA_AIS_ERR_NOT_EXIST;
  1946. goto error_exit;
  1947. }
  1948. /*
  1949. * Determine if user-specified checkpoint ID already exists
  1950. */
  1951. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1952. SectionId,
  1953. (int)sectionDescriptor->sectionId.idLen);
  1954. if (ckptCheckpointSection) {
  1955. /*
  1956. * This use case is mostly for the default section and is not probable for any other
  1957. * sections.
  1958. */
  1959. if (sectionDescriptor->sectionSize
  1960. > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  1961. log_printf (LOG_LEVEL_NOTICE,
  1962. "CKPT: recovery_section_create reallocating data. Present Size: %d, New Size: %d\n",
  1963. ckptCheckpointSection->sectionDescriptor.sectionSize,sectionDescriptor->sectionSize);
  1964. ckptCheckpointSection->sectionData =
  1965. realloc (ckptCheckpointSection->sectionData, sectionDescriptor->sectionSize);
  1966. if (ckptCheckpointSection->sectionData == 0) {
  1967. log_printf (LOG_LEVEL_ERROR,
  1968. "CKPT: recovery_section_create sectionData realloc returned 0 Calling error_exit.\n");
  1969. error = SA_AIS_ERR_NO_MEMORY;
  1970. checkpoint_section_release(ckptCheckpointSection);
  1971. goto error_exit;
  1972. }
  1973. ckptCheckpointSection->sectionDescriptor.sectionSize = sectionDescriptor->sectionSize;
  1974. error = SA_AIS_OK;
  1975. }
  1976. else {
  1977. error = SA_AIS_ERR_EXIST;
  1978. }
  1979. goto error_exit;
  1980. }
  1981. /*
  1982. * Allocate checkpoint section
  1983. */
  1984. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1985. if (ckptCheckpointSection == 0) {
  1986. error = SA_AIS_ERR_NO_MEMORY;
  1987. goto error_exit;
  1988. }
  1989. /*
  1990. * Allocate checkpoint section data
  1991. */
  1992. initialData = malloc (sectionDescriptor->sectionSize);
  1993. if (initialData == 0) {
  1994. free (ckptCheckpointSection);
  1995. error = SA_AIS_ERR_NO_MEMORY;
  1996. goto error_exit;
  1997. }
  1998. /*
  1999. * Allocate checkpoint section id
  2000. */
  2001. if (sectionDescriptor->sectionId.idLen) {
  2002. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  2003. if (sectionId == 0) {
  2004. free (ckptCheckpointSection);
  2005. free (initialData);
  2006. error = SA_AIS_ERR_NO_MEMORY;
  2007. goto error_exit;
  2008. }
  2009. } else {
  2010. sectionId = 0;
  2011. }
  2012. /*
  2013. * Copy checkpoint section ID and initialize data.
  2014. */
  2015. if (SectionId) {
  2016. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  2017. } else {
  2018. sectionId = 0;
  2019. }
  2020. memset (initialData, 0, sectionDescriptor->sectionSize);
  2021. /*
  2022. * Configure checkpoint section
  2023. */
  2024. memcpy(&ckptCheckpointSection->sectionDescriptor,
  2025. sectionDescriptor,
  2026. sizeof(SaCkptSectionDescriptorT));
  2027. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2028. ckptCheckpointSection->sectionData = initialData;
  2029. ckptCheckpointSection->expiration_timer = 0;
  2030. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  2031. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  2032. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2033. assert(ckpt_id);
  2034. memcpy(&ckpt_id->ckpt_name,checkpointName,sizeof(SaNameT));
  2035. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2036. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  2037. ckpt_id->ckpt_section_id.id,
  2038. (char *)&ckpt_id->ckpt_name.value);
  2039. poll_timer_add (aisexec_poll_handle,
  2040. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2041. ckpt_id,
  2042. timer_function_section_expire,
  2043. &ckptCheckpointSection->expiration_timer);
  2044. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create expiration timer = 0x%x\n",
  2045. ckptCheckpointSection->expiration_timer);
  2046. }
  2047. /*
  2048. * Add checkpoint section to checkpoint
  2049. */
  2050. list_init (&ckptCheckpointSection->list);
  2051. list_add (&ckptCheckpointSection->list,
  2052. &ckptCheckpoint->checkpointSectionsListHead);
  2053. error_exit:
  2054. return (error);
  2055. }
  2056. static void message_handler_req_exec_ckpt_sectioncreate (
  2057. void *message,
  2058. struct totem_ip_address *source_addr)
  2059. {
  2060. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  2061. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  2062. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2063. struct saCkptCheckpoint *ckptCheckpoint;
  2064. struct saCkptCheckpointSection *ckptCheckpointSection;
  2065. void *initialData;
  2066. void *sectionId;
  2067. struct ckpt_identifier *ckpt_id = 0;
  2068. SaAisErrorT error = SA_AIS_OK;
  2069. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  2070. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  2071. if (ckptCheckpoint == 0) {
  2072. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  2073. goto error_exit;
  2074. }
  2075. if (ckptCheckpoint->sectionCount == ckptCheckpoint->checkpointCreationAttributes.maxSections) {
  2076. error = SA_AIS_ERR_NO_SPACE;
  2077. goto error_exit;
  2078. }
  2079. if (ckptCheckpoint->checkpointCreationAttributes.maxSections == 1) {
  2080. error = SA_AIS_ERR_EXIST;
  2081. goto error_exit;
  2082. }
  2083. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize <
  2084. req_lib_ckpt_sectioncreate->initialDataSize) {
  2085. error = SA_AIS_ERR_INVALID_PARAM;
  2086. goto error_exit;
  2087. }
  2088. /*
  2089. * Determine if user-specified checkpoint ID already exists
  2090. */
  2091. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2092. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  2093. req_lib_ckpt_sectioncreate->idLen);
  2094. if (ckptCheckpointSection) {
  2095. error = SA_AIS_ERR_EXIST;
  2096. goto error_exit;
  2097. }
  2098. /*
  2099. * Allocate checkpoint section
  2100. */
  2101. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  2102. if (ckptCheckpointSection == 0) {
  2103. error = SA_AIS_ERR_NO_MEMORY;
  2104. goto error_exit;
  2105. }
  2106. /*
  2107. * Allocate checkpoint section data
  2108. */
  2109. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  2110. if (initialData == 0) {
  2111. free (ckptCheckpointSection);
  2112. error = SA_AIS_ERR_NO_MEMORY;
  2113. goto error_exit;
  2114. }
  2115. /*
  2116. * Allocate checkpoint section id
  2117. */
  2118. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  2119. if (sectionId == 0) {
  2120. free (ckptCheckpointSection);
  2121. free (initialData);
  2122. error = SA_AIS_ERR_NO_MEMORY;
  2123. goto error_exit;
  2124. }
  2125. /*
  2126. * Copy checkpoint section and section ID
  2127. */
  2128. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  2129. req_lib_ckpt_sectioncreate->idLen);
  2130. memcpy (initialData,
  2131. ((char *)req_lib_ckpt_sectioncreate) +
  2132. sizeof (struct req_lib_ckpt_sectioncreate) +
  2133. req_lib_ckpt_sectioncreate->idLen,
  2134. req_lib_ckpt_sectioncreate->initialDataSize);
  2135. /*
  2136. * Configure checkpoint section
  2137. */
  2138. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  2139. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  2140. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  2141. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  2142. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2143. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2144. ckptCheckpointSection->sectionData = initialData;
  2145. ckptCheckpointSection->expiration_timer = 0;
  2146. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  2147. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2148. assert(ckpt_id);
  2149. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectioncreate->checkpointName,sizeof(SaNameT));
  2150. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2151. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  2152. ckpt_id->ckpt_section_id.id,
  2153. (char *)&ckpt_id->ckpt_name.value);
  2154. poll_timer_add (aisexec_poll_handle,
  2155. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2156. ckpt_id,
  2157. timer_function_section_expire,
  2158. &ckptCheckpointSection->expiration_timer);
  2159. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionicreate expiration timer = 0x%x\n",
  2160. ckptCheckpointSection->expiration_timer);
  2161. }
  2162. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_sectioncreate created section with id = %s, idLen = %d\n",
  2163. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  2164. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  2165. /*
  2166. * Add checkpoint section to checkpoint
  2167. */
  2168. list_init (&ckptCheckpointSection->list);
  2169. list_add (&ckptCheckpointSection->list,
  2170. &ckptCheckpoint->checkpointSectionsListHead);
  2171. ckptCheckpoint->sectionCount += 1;
  2172. error_exit:
  2173. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  2174. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2175. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2176. res_lib_ckpt_sectioncreate.header.error = error;
  2177. openais_conn_send_response (req_exec_ckpt_sectioncreate->source.conn,
  2178. &res_lib_ckpt_sectioncreate,
  2179. sizeof (struct res_lib_ckpt_sectioncreate));
  2180. }
  2181. }
  2182. static void message_handler_req_exec_ckpt_sectiondelete (
  2183. void *message,
  2184. struct totem_ip_address *source_addr)
  2185. {
  2186. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  2187. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  2188. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  2189. struct saCkptCheckpoint *ckptCheckpoint;
  2190. struct saCkptCheckpointSection *ckptCheckpointSection;
  2191. SaAisErrorT error = SA_AIS_OK;
  2192. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  2193. if (ckptCheckpoint == 0) {
  2194. error = SA_AIS_ERR_NOT_EXIST;
  2195. goto error_exit;
  2196. }
  2197. if (ckptCheckpoint->active_replica_set == 0) {
  2198. log_printf (LOG_LEVEL_NOTICE, "sectiondelete: no active replica, returning error.\n");
  2199. error = SA_AIS_ERR_NOT_EXIST;
  2200. goto error_exit;
  2201. }
  2202. /*
  2203. * Determine if the user is trying to delete the default section
  2204. */
  2205. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  2206. error = SA_AIS_ERR_INVALID_PARAM;
  2207. goto error_exit;
  2208. }
  2209. /*
  2210. * Find checkpoint section to be deleted
  2211. */
  2212. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2213. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  2214. req_lib_ckpt_sectiondelete->idLen);
  2215. if (ckptCheckpointSection == 0) {
  2216. error = SA_AIS_ERR_NOT_EXIST;
  2217. goto error_exit;
  2218. }
  2219. /*
  2220. * Delete checkpoint section
  2221. */
  2222. ckptCheckpoint->sectionCount -= 1;
  2223. checkpoint_section_release (ckptCheckpointSection);
  2224. /*
  2225. * return result to CKPT library
  2226. */
  2227. error_exit:
  2228. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  2229. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  2230. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  2231. res_lib_ckpt_sectiondelete.header.error = error;
  2232. openais_conn_send_response (
  2233. req_exec_ckpt_sectiondelete->source.conn,
  2234. &res_lib_ckpt_sectiondelete,
  2235. sizeof (struct res_lib_ckpt_sectiondelete));
  2236. }
  2237. }
  2238. static void message_handler_req_exec_ckpt_sectionexpirationtimeset (
  2239. void *message,
  2240. struct totem_ip_address *source_addr)
  2241. {
  2242. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  2243. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  2244. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  2245. struct saCkptCheckpoint *ckptCheckpoint;
  2246. struct saCkptCheckpointSection *ckptCheckpointSection;
  2247. struct ckpt_identifier *ckpt_id = 0;
  2248. SaAisErrorT error = SA_AIS_OK;
  2249. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  2250. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  2251. if (ckptCheckpoint == 0) {
  2252. error = SA_AIS_ERR_NOT_EXIST;
  2253. goto error_exit;
  2254. }
  2255. if (ckptCheckpoint->active_replica_set == 0) {
  2256. log_printf (LOG_LEVEL_NOTICE, "expirationset: no active replica, returning error.\n");
  2257. error = SA_AIS_ERR_NOT_EXIST;
  2258. goto error_exit;
  2259. }
  2260. /*
  2261. * Determine if the user is trying to set expiration time for the default section
  2262. */
  2263. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  2264. error = SA_AIS_ERR_INVALID_PARAM;
  2265. goto error_exit;
  2266. }
  2267. /*
  2268. * Find checkpoint section that expiration time should be set for
  2269. */
  2270. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2271. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  2272. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  2273. req_lib_ckpt_sectionexpirationtimeset->idLen);
  2274. if (ckptCheckpointSection == 0) {
  2275. error = SA_AIS_ERR_NOT_EXIST;
  2276. goto error_exit;
  2277. }
  2278. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  2279. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  2280. ckptCheckpointSection->expiration_timer = 0;
  2281. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  2282. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2283. assert(ckpt_id);
  2284. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectionexpirationtimeset->checkpointName,sizeof(SaNameT));
  2285. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2286. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%x\n",
  2287. ckpt_id->ckpt_section_id.id,
  2288. (char *)&ckpt_id->ckpt_name.value,
  2289. ckpt_id);
  2290. poll_timer_add (aisexec_poll_handle,
  2291. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2292. ckpt_id,
  2293. timer_function_section_expire,
  2294. &ckptCheckpointSection->expiration_timer);
  2295. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%x\n",
  2296. ckptCheckpointSection->expiration_timer);
  2297. }
  2298. error_exit:
  2299. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2300. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2301. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2302. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2303. openais_conn_send_response (
  2304. req_exec_ckpt_sectionexpirationtimeset->source.conn,
  2305. &res_lib_ckpt_sectionexpirationtimeset,
  2306. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2307. }
  2308. }
  2309. static int recovery_section_write(int sectionIdLen,
  2310. char* sectionId,
  2311. SaNameT *checkpointName,
  2312. void *newData,
  2313. SaUint32T dataOffSet,
  2314. SaUint32T dataSize)
  2315. {
  2316. struct saCkptCheckpoint *ckptCheckpoint;
  2317. struct saCkptCheckpointSection *ckptCheckpointSection;
  2318. int sizeRequired;
  2319. SaAisErrorT error = SA_AIS_OK;
  2320. char *sd;
  2321. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  2322. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  2323. if (ckptCheckpoint == 0) {
  2324. error = SA_AIS_ERR_NOT_EXIST;
  2325. goto error_exit;
  2326. }
  2327. /*
  2328. * Find checkpoint section to be written
  2329. */
  2330. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2331. sectionId,
  2332. sectionIdLen);
  2333. if (ckptCheckpointSection == 0) {
  2334. error = SA_AIS_ERR_NOT_EXIST;
  2335. goto error_exit;
  2336. }
  2337. /*
  2338. * If write would extend past end of section data, return error;
  2339. */
  2340. sizeRequired = dataOffSet + dataSize;
  2341. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2342. log_printf (LOG_LEVEL_ERROR,
  2343. "recovery_section_write. write-past-end sizeRequired:(%d), dataOffSet:(%d), dataSize:(%d), sync-section-size:(%d)\n",
  2344. sizeRequired, dataOffSet, dataSize,
  2345. (int)ckptCheckpointSection->sectionDescriptor.sectionSize);
  2346. error = SA_AIS_ERR_ACCESS;
  2347. goto error_exit;
  2348. }
  2349. /*
  2350. * Write checkpoint section to section data
  2351. */
  2352. if (dataSize > 0) {
  2353. sd = (char *)ckptCheckpointSection->sectionData;
  2354. memcpy (&sd[dataOffSet],
  2355. newData,
  2356. dataSize);
  2357. }
  2358. error_exit:
  2359. return (error);
  2360. }
  2361. static void message_handler_req_exec_ckpt_sectionwrite (
  2362. void *message,
  2363. struct totem_ip_address *source_addr)
  2364. {
  2365. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2366. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  2367. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2368. struct saCkptCheckpoint *ckptCheckpoint;
  2369. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2370. int sizeRequired;
  2371. void *sectionData;
  2372. SaAisErrorT error = SA_AIS_OK;
  2373. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2374. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  2375. if (ckptCheckpoint == 0) {
  2376. log_printf (LOG_LEVEL_ERROR, "CKPT: ckpt_checkpoint_find_global returned 0 Calling error_exit.\n");
  2377. error = SA_AIS_ERR_NOT_EXIST;
  2378. goto error_exit;
  2379. }
  2380. if (ckptCheckpoint->active_replica_set == 0) {
  2381. log_printf (LOG_LEVEL_NOTICE, "checkpointwrite: no active replica, returning error.\n");
  2382. error = SA_AIS_ERR_NOT_EXIST;
  2383. goto error_exit;
  2384. }
  2385. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionwrite->dataSize) {
  2386. error = SA_AIS_ERR_INVALID_PARAM;
  2387. goto error_exit;
  2388. }
  2389. /*
  2390. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2391. */
  2392. /*
  2393. * Find checkpoint section to be written
  2394. */
  2395. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2396. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2397. req_lib_ckpt_sectionwrite->idLen);
  2398. if (ckptCheckpointSection == 0) {
  2399. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  2400. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2401. }
  2402. else {
  2403. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2404. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2405. }
  2406. error = SA_AIS_ERR_NOT_EXIST;
  2407. goto error_exit;
  2408. }
  2409. /*
  2410. * If write would extend past end of section data, enlarge section
  2411. */
  2412. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  2413. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2414. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  2415. if (sectionData == 0) {
  2416. log_printf (LOG_LEVEL_ERROR, "CKPT: sectionData realloc returned 0 Calling error_exit.\n");
  2417. error = SA_AIS_ERR_NO_MEMORY;
  2418. goto error_exit;
  2419. }
  2420. /*
  2421. * Install new section data
  2422. */
  2423. ckptCheckpointSection->sectionData = sectionData;
  2424. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  2425. }
  2426. /*
  2427. * Write checkpoint section to section data
  2428. */
  2429. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  2430. char *sd;
  2431. int *val;
  2432. val = ckptCheckpointSection->sectionData;
  2433. sd = (char *)ckptCheckpointSection->sectionData;
  2434. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  2435. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  2436. req_lib_ckpt_sectionwrite->idLen,
  2437. req_lib_ckpt_sectionwrite->dataSize);
  2438. }
  2439. /*
  2440. * Write write response to CKPT library
  2441. */
  2442. error_exit:
  2443. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2444. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2445. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2446. res_lib_ckpt_sectionwrite.header.error = error;
  2447. openais_conn_send_response (
  2448. req_exec_ckpt_sectionwrite->source.conn,
  2449. &res_lib_ckpt_sectionwrite,
  2450. sizeof (struct res_lib_ckpt_sectionwrite));
  2451. }
  2452. }
  2453. static void message_handler_req_exec_ckpt_sectionoverwrite (
  2454. void *message,
  2455. struct totem_ip_address *source_addr)
  2456. {
  2457. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2458. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  2459. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2460. struct saCkptCheckpoint *ckptCheckpoint;
  2461. struct saCkptCheckpointSection *ckptCheckpointSection;
  2462. void *sectionData;
  2463. SaAisErrorT error = SA_AIS_OK;
  2464. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2465. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  2466. if (ckptCheckpoint == 0) {
  2467. error = SA_AIS_ERR_NOT_EXIST;
  2468. goto error_exit;
  2469. }
  2470. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionoverwrite->dataSize) {
  2471. error = SA_AIS_ERR_INVALID_PARAM;
  2472. goto error_exit;
  2473. }
  2474. /*
  2475. * Find checkpoint section to be overwritten
  2476. */
  2477. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2478. ((char *)req_lib_ckpt_sectionoverwrite) +
  2479. sizeof (struct req_lib_ckpt_sectionoverwrite),
  2480. req_lib_ckpt_sectionoverwrite->idLen);
  2481. if (ckptCheckpointSection == 0) {
  2482. error = SA_AIS_ERR_NOT_EXIST;
  2483. goto error_exit;
  2484. }
  2485. /*
  2486. * Allocate checkpoint section data
  2487. */
  2488. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  2489. if (sectionData == 0) {
  2490. error = SA_AIS_ERR_NO_MEMORY;
  2491. goto error_exit;
  2492. }
  2493. memcpy (sectionData,
  2494. ((char *)req_lib_ckpt_sectionoverwrite) +
  2495. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  2496. req_lib_ckpt_sectionoverwrite->idLen,
  2497. req_lib_ckpt_sectionoverwrite->dataSize);
  2498. /*
  2499. * release old checkpoint section data
  2500. */
  2501. free (ckptCheckpointSection->sectionData);
  2502. /*
  2503. * Install overwritten checkpoint section data
  2504. */
  2505. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  2506. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2507. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2508. ckptCheckpointSection->sectionData = sectionData;
  2509. /*
  2510. * return result to CKPT library
  2511. */
  2512. error_exit:
  2513. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2514. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  2515. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2516. res_lib_ckpt_sectionoverwrite.header.error = error;
  2517. openais_conn_send_response (
  2518. req_exec_ckpt_sectionoverwrite->source.conn,
  2519. &res_lib_ckpt_sectionoverwrite,
  2520. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2521. }
  2522. }
  2523. static void message_handler_req_exec_ckpt_sectionread (
  2524. void *message,
  2525. struct totem_ip_address *source_addr)
  2526. {
  2527. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2528. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  2529. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2530. struct saCkptCheckpoint *ckptCheckpoint;
  2531. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2532. int sectionSize = 0;
  2533. SaAisErrorT error = SA_AIS_OK;
  2534. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2535. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  2536. if (ckptCheckpoint == 0) {
  2537. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  2538. goto error_exit;
  2539. }
  2540. /*
  2541. * Find checkpoint section to be read
  2542. */
  2543. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2544. ((char *)req_lib_ckpt_sectionread) +
  2545. sizeof (struct req_lib_ckpt_sectionread),
  2546. req_lib_ckpt_sectionread->idLen);
  2547. if (ckptCheckpointSection == 0) {
  2548. error = SA_AIS_ERR_NOT_EXIST;
  2549. goto error_exit;
  2550. }
  2551. /*
  2552. * Determine the section size
  2553. */
  2554. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  2555. req_lib_ckpt_sectionread->dataOffset;
  2556. /*
  2557. * If the library has less space available then can be sent from the
  2558. * section, reduce bytes sent to library to max requested
  2559. */
  2560. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  2561. sectionSize = req_lib_ckpt_sectionread->dataSize;
  2562. }
  2563. /*
  2564. * If dataOffset is past end of data, return INVALID PARAM
  2565. */
  2566. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  2567. sectionSize = 0;
  2568. error = SA_AIS_ERR_INVALID_PARAM;
  2569. goto error_exit;
  2570. }
  2571. /*
  2572. * Write read response to CKPT library
  2573. */
  2574. error_exit:
  2575. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2576. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  2577. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2578. res_lib_ckpt_sectionread.header.error = error;
  2579. openais_conn_send_response (
  2580. req_exec_ckpt_sectionread->source.conn,
  2581. &res_lib_ckpt_sectionread,
  2582. sizeof (struct res_lib_ckpt_sectionread));
  2583. /*
  2584. * Write checkpoint to CKPT library section if section has data
  2585. */
  2586. if (sectionSize) {
  2587. char *sd;
  2588. sd = (char *)ckptCheckpointSection->sectionData;
  2589. openais_conn_send_response (
  2590. req_exec_ckpt_sectionread->source.conn,
  2591. &sd[req_lib_ckpt_sectionread->dataOffset],
  2592. sectionSize);
  2593. }
  2594. }
  2595. }
  2596. static int ckpt_lib_init_fn (void *conn)
  2597. {
  2598. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2599. list_init (&ckpt_pd->sectionIterator.list);
  2600. ckpt_pd->sectionIterator.sectionIteratorEntries = 0;
  2601. ckpt_pd->sectionIterator.iteratorCount = 0;
  2602. ckpt_pd->sectionIterator.iteratorPos = 0;
  2603. list_add (&ckpt_pd->sectionIterator.list,
  2604. &checkpoint_iterator_list_head);
  2605. list_init (&ckpt_pd->checkpoint_list);
  2606. return (0);
  2607. }
  2608. static int ckpt_lib_exit_fn (void *conn)
  2609. {
  2610. struct checkpoint_cleanup *checkpoint_cleanup;
  2611. struct list_head *cleanup_list;
  2612. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  2613. log_printf (LOG_LEVEL_DEBUG, "checkpoint exit conn %p\n", conn);
  2614. /*
  2615. * close all checkpoints opened on this connection
  2616. */
  2617. cleanup_list = ckpt_pd->checkpoint_list.next;
  2618. while (!list_empty(&ckpt_pd->checkpoint_list)) {
  2619. checkpoint_cleanup = list_entry (cleanup_list,
  2620. struct checkpoint_cleanup, list);
  2621. if (checkpoint_cleanup->checkpoint.name.length > 0) {
  2622. ckpt_checkpoint_close (&checkpoint_cleanup->checkpoint);
  2623. }
  2624. list_del (&checkpoint_cleanup->list);
  2625. free (checkpoint_cleanup);
  2626. cleanup_list = ckpt_pd->checkpoint_list.next;
  2627. }
  2628. if (ckpt_pd->sectionIterator.sectionIteratorEntries) {
  2629. free (ckpt_pd->sectionIterator.sectionIteratorEntries);
  2630. }
  2631. list_del (&ckpt_pd->sectionIterator.list);
  2632. return (0);
  2633. }
  2634. static void message_handler_req_lib_ckpt_checkpointopen (
  2635. void *conn,
  2636. void *msg)
  2637. {
  2638. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)msg;
  2639. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2640. struct iovec iovecs[2];
  2641. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  2642. req_exec_ckpt_checkpointopen.header.size =
  2643. sizeof (struct req_exec_ckpt_checkpointopen);
  2644. req_exec_ckpt_checkpointopen.header.id =
  2645. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN);
  2646. message_source_set (&req_exec_ckpt_checkpointopen.source, conn);
  2647. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2648. req_lib_ckpt_checkpointopen,
  2649. sizeof (struct req_lib_ckpt_checkpointopen));
  2650. req_exec_ckpt_checkpointopen.async_call = 0;
  2651. req_exec_ckpt_checkpointopen.invocation = 0;
  2652. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  2653. req_exec_ckpt_checkpointopen.fail_with_error = SA_AIS_OK;
  2654. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2655. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2656. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2657. }
  2658. static void message_handler_req_lib_ckpt_checkpointopenasync (
  2659. void *conn,
  2660. void *msg)
  2661. {
  2662. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)msg;
  2663. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2664. struct iovec iovecs[2];
  2665. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2666. req_exec_ckpt_checkpointopen.header.size =
  2667. sizeof (struct req_exec_ckpt_checkpointopen);
  2668. req_exec_ckpt_checkpointopen.header.id =
  2669. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN);
  2670. message_source_set (&req_exec_ckpt_checkpointopen.source, conn);
  2671. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2672. req_lib_ckpt_checkpointopenasync,
  2673. sizeof (struct req_lib_ckpt_checkpointopen));
  2674. req_exec_ckpt_checkpointopen.async_call = 1;
  2675. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2676. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2677. req_exec_ckpt_checkpointopen.fail_with_error = req_lib_ckpt_checkpointopenasync->fail_with_error;
  2678. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2679. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2680. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2681. }
  2682. static void message_handler_req_lib_ckpt_checkpointclose (
  2683. void *conn,
  2684. void *msg)
  2685. {
  2686. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)msg;
  2687. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2688. struct iovec iovecs[2];
  2689. struct saCkptCheckpoint *checkpoint;
  2690. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2691. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2692. if (checkpoint && (checkpoint->expired == 0)) {
  2693. req_exec_ckpt_checkpointclose.header.size =
  2694. sizeof (struct req_exec_ckpt_checkpointclose);
  2695. req_exec_ckpt_checkpointclose.header.id =
  2696. SERVICE_ID_MAKE (CKPT_SERVICE,
  2697. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE);
  2698. message_source_set (&req_exec_ckpt_checkpointclose.source, conn);
  2699. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2700. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2701. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2702. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2703. if (totempg_groups_send_ok_joined (openais_group_handle, iovecs, 1)) {
  2704. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2705. }
  2706. }
  2707. else {
  2708. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2709. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2710. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2711. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2712. openais_conn_send_response (
  2713. conn,
  2714. &res_lib_ckpt_checkpointclose,
  2715. sizeof (struct res_lib_ckpt_checkpointclose));
  2716. }
  2717. }
  2718. static void message_handler_req_lib_ckpt_checkpointunlink (
  2719. void *conn,
  2720. void *msg)
  2721. {
  2722. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)msg;
  2723. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2724. struct iovec iovecs[2];
  2725. req_exec_ckpt_checkpointunlink.header.size =
  2726. sizeof (struct req_exec_ckpt_checkpointunlink);
  2727. req_exec_ckpt_checkpointunlink.header.id =
  2728. SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK);
  2729. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn);
  2730. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2731. req_lib_ckpt_checkpointunlink,
  2732. sizeof (struct req_lib_ckpt_checkpointunlink));
  2733. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2734. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2735. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2736. }
  2737. static void message_handler_req_lib_ckpt_checkpointretentiondurationset (
  2738. void *conn,
  2739. void *msg)
  2740. {
  2741. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)msg;
  2742. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2743. struct iovec iovecs[2];
  2744. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API conn %p\n", conn);
  2745. req_exec_ckpt_checkpointretentiondurationset.header.id =
  2746. SERVICE_ID_MAKE (CKPT_SERVICE,
  2747. MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET);
  2748. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2749. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn);
  2750. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2751. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2752. sizeof (SaNameT));
  2753. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2754. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2755. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2756. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2757. }
  2758. static void message_handler_req_lib_ckpt_activereplicaset (
  2759. void *conn,
  2760. void *msg)
  2761. {
  2762. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)msg;
  2763. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2764. struct saCkptCheckpoint *checkpoint;
  2765. SaAisErrorT error = SA_AIS_OK;
  2766. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2767. /*
  2768. * Make sure checkpoint is collocated and async update option
  2769. */
  2770. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2771. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2772. error = SA_AIS_ERR_BAD_OPERATION;
  2773. }
  2774. checkpoint->active_replica_set = 1;
  2775. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2776. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2777. res_lib_ckpt_activereplicaset.header.error = error;
  2778. openais_conn_send_response (
  2779. conn,
  2780. &res_lib_ckpt_activereplicaset,
  2781. sizeof (struct res_lib_ckpt_activereplicaset));
  2782. }
  2783. static void message_handler_req_lib_ckpt_checkpointstatusget (
  2784. void *conn,
  2785. void *msg)
  2786. {
  2787. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)msg;
  2788. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2789. struct saCkptCheckpoint *checkpoint;
  2790. int memoryUsed = 0;
  2791. int numberOfSections = 0;
  2792. struct list_head *checkpoint_section_list;
  2793. struct saCkptCheckpointSection *checkpointSection;
  2794. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2795. /*
  2796. * Count memory used by checkpoint sections
  2797. */
  2798. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2799. if (checkpoint && (checkpoint->expired == 0)) {
  2800. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2801. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2802. checkpoint_section_list = checkpoint_section_list->next) {
  2803. checkpointSection = list_entry (checkpoint_section_list,
  2804. struct saCkptCheckpointSection, list);
  2805. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2806. numberOfSections += 1;
  2807. }
  2808. /*
  2809. * Build checkpoint status get response
  2810. */
  2811. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2812. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2813. if (checkpoint->active_replica_set == 1) {
  2814. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2815. } else {
  2816. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2817. }
  2818. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2819. &checkpoint->checkpointCreationAttributes,
  2820. sizeof (SaCkptCheckpointCreationAttributesT));
  2821. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2822. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2823. }
  2824. else {
  2825. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2826. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2827. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2828. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2829. }
  2830. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2831. openais_conn_send_response (
  2832. conn,
  2833. &res_lib_ckpt_checkpointstatusget,
  2834. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2835. }
  2836. static void message_handler_req_lib_ckpt_sectioncreate (
  2837. void *conn,
  2838. void *msg)
  2839. {
  2840. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)msg;
  2841. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2842. struct iovec iovecs[2];
  2843. struct saCkptCheckpoint *checkpoint;
  2844. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2845. log_printf (LOG_LEVEL_DEBUG, "Section create from conn %p\n", conn);
  2846. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2847. if (checkpoint && (checkpoint->expired == 0)) {
  2848. /*
  2849. * checkpoint opened is writeable mode so send message to cluster
  2850. */
  2851. req_exec_ckpt_sectioncreate.header.id =
  2852. SERVICE_ID_MAKE (CKPT_SERVICE,
  2853. MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE);
  2854. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2855. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2856. req_lib_ckpt_sectioncreate,
  2857. sizeof (struct req_lib_ckpt_sectioncreate));
  2858. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2859. &req_lib_ckpt_sectioncreate->checkpointName,
  2860. sizeof (SaNameT));
  2861. message_source_set (&req_exec_ckpt_sectioncreate.source, conn);
  2862. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2863. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2864. /*
  2865. * Send section name and initial data in message
  2866. */
  2867. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2868. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2869. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2870. if (iovecs[1].iov_len) {
  2871. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2872. iovecs[1].iov_base,
  2873. iovecs[1].iov_len);
  2874. }
  2875. #ifdef DEBUG
  2876. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2877. iovecs[1].iov_len);
  2878. printf ("|\n");
  2879. { int i;
  2880. char *abc = iovecs[1].iov_base;
  2881. for (i = 0; i < 14;i++) {
  2882. printf ("%c ", abc[i]);
  2883. }
  2884. }
  2885. printf ("|\n");
  2886. #endif
  2887. if (iovecs[1].iov_len > 0) {
  2888. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2889. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  2890. } else {
  2891. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2892. }
  2893. }
  2894. else {
  2895. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2896. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2897. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2898. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2899. openais_conn_send_response (
  2900. conn,
  2901. &res_lib_ckpt_sectioncreate,
  2902. sizeof (struct res_lib_ckpt_sectioncreate));
  2903. }
  2904. }
  2905. static void message_handler_req_lib_ckpt_sectiondelete (
  2906. void *conn,
  2907. void *msg)
  2908. {
  2909. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)msg;
  2910. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2911. struct iovec iovecs[2];
  2912. log_printf (LOG_LEVEL_DEBUG, "section delete from conn %p\n", conn);
  2913. req_exec_ckpt_sectiondelete.header.id =
  2914. SERVICE_ID_MAKE (CKPT_SERVICE,
  2915. MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE);
  2916. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2917. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2918. &req_lib_ckpt_sectiondelete->checkpointName,
  2919. sizeof (SaNameT));
  2920. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2921. req_lib_ckpt_sectiondelete,
  2922. sizeof (struct req_lib_ckpt_sectiondelete));
  2923. message_source_set (&req_exec_ckpt_sectiondelete.source, conn);
  2924. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2925. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2926. /*
  2927. * Send section name
  2928. */
  2929. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2930. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2931. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2932. if (iovecs[1].iov_len > 0) {
  2933. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  2934. } else {
  2935. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2936. }
  2937. }
  2938. static void message_handler_req_lib_ckpt_sectionexpirationtimeset (
  2939. void *conn,
  2940. void *msg)
  2941. {
  2942. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)msg;
  2943. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2944. struct iovec iovecs[2];
  2945. log_printf (LOG_LEVEL_DEBUG, "section expiration time set from conn %p\n", conn);
  2946. req_exec_ckpt_sectionexpirationtimeset.header.id =
  2947. SERVICE_ID_MAKE (CKPT_SERVICE,
  2948. MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET);
  2949. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2950. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2951. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2952. sizeof (SaNameT));
  2953. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2954. req_lib_ckpt_sectionexpirationtimeset,
  2955. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2956. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn);
  2957. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2958. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2959. /*
  2960. * Send section name
  2961. */
  2962. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2963. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2964. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2965. if (iovecs[1].iov_len > 0) {
  2966. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2967. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  2968. } else {
  2969. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  2970. }
  2971. }
  2972. static void message_handler_req_lib_ckpt_sectionwrite (
  2973. void *conn,
  2974. void *msg)
  2975. {
  2976. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)msg;
  2977. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2978. struct iovec iovecs[2];
  2979. struct saCkptCheckpoint *checkpoint;
  2980. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2981. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2982. req_lib_ckpt_sectionwrite->dataSize,
  2983. req_lib_ckpt_sectionwrite->dataOffset);
  2984. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2985. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2986. req_lib_ckpt_sectionwrite->idLen);
  2987. log_printf (LOG_LEVEL_DEBUG, "Section write from conn %p\n", conn);
  2988. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2989. if (checkpoint && (checkpoint->expired == 0)) {
  2990. /*
  2991. * checkpoint opened is writeable mode so send message to cluster
  2992. */
  2993. req_exec_ckpt_sectionwrite.header.id =
  2994. SERVICE_ID_MAKE (CKPT_SERVICE,
  2995. MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE);
  2996. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2997. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2998. req_lib_ckpt_sectionwrite,
  2999. sizeof (struct req_lib_ckpt_sectionwrite));
  3000. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  3001. &req_lib_ckpt_sectionwrite->checkpointName,
  3002. sizeof (SaNameT));
  3003. message_source_set (&req_exec_ckpt_sectionwrite.source, conn);
  3004. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  3005. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  3006. /*
  3007. * Send section name and data to write in message
  3008. */
  3009. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  3010. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  3011. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  3012. if (iovecs[1].iov_len > 0) {
  3013. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3014. } else {
  3015. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3016. }
  3017. }
  3018. else {
  3019. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  3020. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  3021. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  3022. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  3023. openais_conn_send_response (
  3024. conn,
  3025. &res_lib_ckpt_sectionwrite,
  3026. sizeof (struct res_lib_ckpt_sectionwrite));
  3027. }
  3028. }
  3029. static void message_handler_req_lib_ckpt_sectionoverwrite (
  3030. void *conn,
  3031. void *msg)
  3032. {
  3033. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)msg;
  3034. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  3035. struct iovec iovecs[2];
  3036. struct saCkptCheckpoint *checkpoint;
  3037. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  3038. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from conn %p\n", conn);
  3039. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  3040. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->active_replica_set == 1)) {
  3041. /*
  3042. * checkpoint opened is writeable mode so send message to cluster
  3043. */
  3044. req_exec_ckpt_sectionoverwrite.header.id =
  3045. SERVICE_ID_MAKE (CKPT_SERVICE,
  3046. MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE);
  3047. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  3048. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  3049. req_lib_ckpt_sectionoverwrite,
  3050. sizeof (struct req_lib_ckpt_sectionoverwrite));
  3051. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  3052. &req_lib_ckpt_sectionoverwrite->checkpointName,
  3053. sizeof (SaNameT));
  3054. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn);
  3055. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  3056. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  3057. /*
  3058. * Send section name and data to overwrite in message
  3059. */
  3060. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  3061. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  3062. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  3063. if (iovecs[1].iov_len > 0) {
  3064. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3065. } else {
  3066. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3067. }
  3068. }
  3069. else {
  3070. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  3071. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  3072. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  3073. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  3074. openais_conn_send_response (
  3075. conn,
  3076. &res_lib_ckpt_sectionoverwrite,
  3077. sizeof (struct res_lib_ckpt_sectionoverwrite));
  3078. }
  3079. }
  3080. static void message_handler_req_lib_ckpt_sectionread (
  3081. void *conn,
  3082. void *msg)
  3083. {
  3084. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)msg;
  3085. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  3086. struct iovec iovecs[2];
  3087. struct saCkptCheckpoint *checkpoint;
  3088. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  3089. SaAisErrorT error = SA_AIS_OK;
  3090. log_printf (LOG_LEVEL_DEBUG, "Section read from conn %p\n", conn);
  3091. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  3092. if (checkpoint && (checkpoint->expired == 0) &&
  3093. checkpoint->active_replica_set &&
  3094. req_lib_ckpt_sectionread->dataSize <=
  3095. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  3096. /*
  3097. * checkpoint opened is writeable mode so send message to cluster
  3098. */
  3099. req_exec_ckpt_sectionread.header.id =
  3100. SERVICE_ID_MAKE (CKPT_SERVICE,
  3101. MESSAGE_REQ_EXEC_CKPT_SECTIONREAD);
  3102. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  3103. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  3104. req_lib_ckpt_sectionread,
  3105. sizeof (struct req_lib_ckpt_sectionread));
  3106. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  3107. &req_lib_ckpt_sectionread->checkpointName,
  3108. sizeof (SaNameT));
  3109. message_source_set (&req_exec_ckpt_sectionread.source, conn);
  3110. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  3111. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  3112. /*
  3113. * Send section name and data to overwrite in message
  3114. */
  3115. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  3116. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  3117. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  3118. if (iovecs[1].iov_len > 0) {
  3119. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 2, TOTEMPG_AGREED) == 0);
  3120. } else {
  3121. assert (totempg_groups_mcast_joined (openais_group_handle, iovecs, 1, TOTEMPG_AGREED) == 0);
  3122. }
  3123. return;
  3124. }
  3125. if (checkpoint) {
  3126. if (checkpoint->active_replica_set == 0) {
  3127. log_printf (LOG_LEVEL_DEBUG,
  3128. "sectionread - active replica not set.\n");
  3129. error = SA_AIS_ERR_NOT_EXIST;
  3130. }
  3131. if (req_lib_ckpt_sectionread->dataSize >
  3132. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  3133. log_printf (LOG_LEVEL_DEBUG,
  3134. "sectionread - data size greater then max section size.\n");
  3135. error = SA_AIS_ERR_INVALID_PARAM;
  3136. }
  3137. } else {
  3138. log_printf (LOG_LEVEL_ERROR,
  3139. "sectionread - could not find checkpoint.\n");
  3140. }
  3141. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  3142. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  3143. res_lib_ckpt_sectionread.header.error = error;
  3144. openais_conn_send_response (
  3145. conn,
  3146. &res_lib_ckpt_sectionread,
  3147. sizeof (struct res_lib_ckpt_sectionread));
  3148. }
  3149. static void message_handler_req_lib_ckpt_checkpointsynchronize (
  3150. void *conn,
  3151. void *msg)
  3152. {
  3153. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)msg;
  3154. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  3155. struct saCkptCheckpoint *checkpoint;
  3156. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronize->checkpointName);
  3157. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3158. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  3159. } else
  3160. if (checkpoint->active_replica_set == 1) {
  3161. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  3162. } else {
  3163. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  3164. }
  3165. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  3166. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  3167. openais_conn_send_response (
  3168. conn,
  3169. &res_lib_ckpt_checkpointsynchronize,
  3170. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  3171. }
  3172. static void message_handler_req_lib_ckpt_checkpointsynchronizeasync (
  3173. void *conn,
  3174. void *msg)
  3175. {
  3176. struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)msg;
  3177. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  3178. struct saCkptCheckpoint *checkpoint;
  3179. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronizeasync->checkpointName);
  3180. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  3181. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION;
  3182. } else
  3183. if (checkpoint->active_replica_set == 1) {
  3184. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK;
  3185. } else {
  3186. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST;
  3187. }
  3188. res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync);
  3189. res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  3190. res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation;
  3191. openais_conn_send_response (
  3192. conn,
  3193. &res_lib_ckpt_checkpointsynchronizeasync,
  3194. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3195. openais_conn_send_response (
  3196. openais_conn_partner_get (conn),
  3197. &res_lib_ckpt_checkpointsynchronizeasync,
  3198. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  3199. }
  3200. static void message_handler_req_lib_ckpt_sectioniterationinitialize (
  3201. void *conn,
  3202. void *msg)
  3203. {
  3204. struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)msg;
  3205. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  3206. struct saCkptCheckpoint *ckptCheckpoint;
  3207. struct saCkptCheckpointSection *ckptCheckpointSection;
  3208. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  3209. struct saCkptSectionIterator *ckptSectionIterator;
  3210. struct list_head *checkpoint_section_list;
  3211. int addEntry = 0;
  3212. int iteratorEntries = 0;
  3213. SaAisErrorT error = SA_AIS_OK;
  3214. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3215. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  3216. ckptSectionIterator = &ckpt_pd->sectionIterator;
  3217. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationinitialize->checkpointName);
  3218. if (ckptCheckpoint == 0) {
  3219. error = SA_AIS_ERR_NOT_EXIST;
  3220. goto error_exit;
  3221. }
  3222. if (ckptCheckpoint->active_replica_set == 0) {
  3223. log_printf (LOG_LEVEL_NOTICE, "iterationinitialize: no active replica, returning error.\n");
  3224. error = SA_AIS_ERR_NOT_EXIST;
  3225. goto error_exit;
  3226. }
  3227. /*
  3228. * Iterate list of checkpoint sections
  3229. */
  3230. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  3231. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  3232. checkpoint_section_list = checkpoint_section_list->next) {
  3233. ckptCheckpointSection = list_entry (checkpoint_section_list,
  3234. struct saCkptCheckpointSection, list);
  3235. addEntry = 1;
  3236. /*
  3237. * Item should be added to iterator list
  3238. */
  3239. if (addEntry) {
  3240. iteratorEntries += 1;
  3241. ckptSectionIteratorEntries =
  3242. realloc (ckptSectionIterator->sectionIteratorEntries,
  3243. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  3244. if (ckptSectionIteratorEntries == 0) {
  3245. if (ckptSectionIterator->sectionIteratorEntries) {
  3246. free (ckptSectionIterator->sectionIteratorEntries);
  3247. }
  3248. error = SA_AIS_ERR_NO_MEMORY;
  3249. goto error_exit;
  3250. }
  3251. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  3252. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  3253. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  3254. }
  3255. }
  3256. ckptSectionIterator->iteratorCount = iteratorEntries;
  3257. error_exit:
  3258. res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize);
  3259. res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  3260. res_lib_ckpt_sectioniterationinitialize.header.error = error;
  3261. openais_conn_send_response (
  3262. conn,
  3263. &res_lib_ckpt_sectioniterationinitialize,
  3264. sizeof (struct res_lib_ckpt_sectioniterationinitialize));
  3265. }
  3266. static void message_handler_req_lib_ckpt_sectioniterationfinalize (
  3267. void *conn,
  3268. void *msg)
  3269. {
  3270. struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)msg;
  3271. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  3272. struct saCkptCheckpoint *ckptCheckpoint;
  3273. SaAisErrorT error = SA_AIS_OK;
  3274. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationfinalize->checkpointName);
  3275. if (ckptCheckpoint == 0) {
  3276. error = SA_AIS_ERR_NOT_EXIST;
  3277. goto error_exit;
  3278. }
  3279. if (ckptCheckpoint->active_replica_set == 0) {
  3280. log_printf (LOG_LEVEL_NOTICE, "iterationfinalize: no active replica, returning error.\n");
  3281. error = SA_AIS_ERR_NOT_EXIST;
  3282. goto error_exit;
  3283. }
  3284. error_exit:
  3285. res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize);
  3286. res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  3287. res_lib_ckpt_sectioniterationfinalize.header.error = error;
  3288. openais_conn_send_response (
  3289. conn,
  3290. &res_lib_ckpt_sectioniterationfinalize,
  3291. sizeof (struct res_lib_ckpt_sectioniterationfinalize));
  3292. }
  3293. static void message_handler_req_lib_ckpt_sectioniteratornext (
  3294. void *conn,
  3295. void *msg)
  3296. {
  3297. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)msg;
  3298. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  3299. struct saCkptSectionIterator *ckptSectionIterator;
  3300. SaAisErrorT error = SA_AIS_OK;
  3301. int sectionIdSize = 0;
  3302. int iteratorPos = 0;
  3303. struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)openais_conn_private_data_get (conn);
  3304. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  3305. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  3306. ckptSectionIterator = &ckpt_pd->sectionIterator;
  3307. /*
  3308. * Find active iterator entry
  3309. */
  3310. for (;;) {
  3311. /*
  3312. * No more sections in iterator
  3313. */
  3314. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  3315. error = SA_AIS_ERR_NO_SECTIONS;
  3316. goto error_exit;
  3317. }
  3318. /*
  3319. * active iterator entry
  3320. */
  3321. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  3322. break;
  3323. }
  3324. ckptSectionIterator->iteratorPos += 1;
  3325. }
  3326. /*
  3327. * Prepare response to API
  3328. */
  3329. iteratorPos = ckptSectionIterator->iteratorPos;
  3330. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  3331. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  3332. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  3333. sizeof (SaCkptSectionDescriptorT));
  3334. /*
  3335. * Get to next iterator entry
  3336. */
  3337. ckptSectionIterator->iteratorPos += 1;
  3338. error_exit:
  3339. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  3340. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  3341. res_lib_ckpt_sectioniteratornext.header.error = error;
  3342. openais_conn_send_response (
  3343. conn,
  3344. &res_lib_ckpt_sectioniteratornext,
  3345. sizeof (struct res_lib_ckpt_sectioniteratornext));
  3346. openais_conn_send_response (
  3347. conn,
  3348. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  3349. sectionIdSize);
  3350. }