ckpt.c 131 KB

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