ckpt.c 143 KB

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