ckpt.c 136 KB

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