ckpt.c 137 KB

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