ckpt.c 136 KB

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