ckpt.c 136 KB

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