ckpt.c 137 KB

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