ckpt.c 131 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554
  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 totem_ip_address *source_addr, int endian_conversion_required);
  81. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  82. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  83. static int message_handler_req_exec_ckpt_checkpointclose (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  84. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  85. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  86. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  87. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  88. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  89. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  90. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  91. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct totem_ip_address *source_addr, int endian_conversion_required);
  92. static int message_handler_req_exec_ckpt_sectionread (void *message, struct totem_ip_address *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 totem_ip_address *left_list,
  117. int left_list_entries);
  118. static void ckpt_replace_localhost_ip (struct totem_ip_address *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 totem_ip_address *member_list, int member_list_entries,
  142. struct totem_ip_address *left_list, int left_list_entries,
  143. struct totem_ip_address *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 totem_ip_address *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 totem_ip_address *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 totem_ip_address *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.family == 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. totemip_copy(&ckpt_refcount[i].addr, proc_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 (totemip_equal(&ckpt_refcount[i].addr, proc_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.family == 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. totemip_print(&ckpt_refcount[i].addr),
  411. ckpt_refcount[i].count);
  412. }
  413. }
  414. return -1;
  415. }
  416. static int processor_add (struct totem_ip_address *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.family == 0) {
  421. log_printf (LOG_LEVEL_DEBUG,"processor_add found empty slot to insert new item\n");
  422. totemip_copy(&ckpt_refcount[i].addr, proc_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 (totemip_equal(&ckpt_refcount[i].addr, proc_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. totemip_print(&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.family == 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. totemip_print(&ckpt_refcount[i].addr),
  448. ckpt_refcount[i].count);
  449. }
  450. }
  451. return -1;
  452. }
  453. static int processor_index_find(struct totem_ip_address *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 (totemip_equal(&ckpt_refcount[i].addr, proc_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.family == 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. totemip_print(&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. totemip_print(&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, sizeof(struct totem_ip_address));
  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.family == 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. totemip_print(&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 totem_ip_address *joined_list) {
  848. struct list_head *checkpoint_list;
  849. struct saCkptCheckpoint *checkpoint;
  850. struct totem_ip_address local_ip;
  851. int index;
  852. assert(joined_list);
  853. totemip_localhost(AF_INET, &local_ip);
  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. totemip_print(joined_list));
  866. }
  867. process_localhost_transition = 0;
  868. }
  869. static void ckpt_recovery_process_members_exit(struct totem_ip_address *left_list,
  870. int left_list_entries)
  871. {
  872. struct list_head *checkpoint_list;
  873. struct saCkptCheckpoint *checkpoint;
  874. struct totem_ip_address *member;
  875. struct totem_ip_address local_ip;
  876. int index;
  877. int i;
  878. totemip_localhost(AF_INET, &local_ip);
  879. if (left_list_entries == 0) {
  880. return;
  881. }
  882. if ((left_list_entries == 1) &&
  883. (totemip_equal(left_list, &local_ip))) {
  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 totem_ip_address *member_list, int member_list_entries,
  966. struct totem_ip_address *left_list, int left_list_entries,
  967. struct totem_ip_address *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. totemip_copy(&saved_ring_id.rep, this_ip);
  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 totem_ip_address *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. totemip_copy(&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. list_del (&ckptCheckpoint->list);
  1329. list_del (&ckptCheckpointSection->list);
  1330. free (ckptCheckpointSection);
  1331. free (ckptCheckpoint);
  1332. error = SA_AIS_ERR_NO_MEMORY;
  1333. } else {
  1334. memcpy(&checkpoint_cleanup->checkpoint,ckptCheckpoint,sizeof(struct saCkptCheckpoint));
  1335. list_add (&checkpoint_cleanup->list,
  1336. &req_exec_ckpt_checkpointopen->source.conn_info->ais_ci.u.libckpt_ci.checkpoint_list);
  1337. }
  1338. }
  1339. }
  1340. return (0);
  1341. }
  1342. static int recovery_checkpoint_open(SaNameT *checkpointName,
  1343. SaCkptCheckpointCreationAttributesT *ckptAttributes,
  1344. struct ckpt_refcnt *ref_cnt)
  1345. {
  1346. int i;
  1347. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1348. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1349. SaErrorT error = SA_AIS_OK;
  1350. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open %s\n", &checkpointName->value);
  1351. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open refcount Values\n");
  1352. for (i = 0; i < PROCESSOR_COUNT_MAX; i ++) {
  1353. if (ref_cnt[i].addr.family == 0) {
  1354. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc 0 and count %d\n", i,
  1355. ref_cnt[i].count);
  1356. }
  1357. else {
  1358. log_printf (LOG_LEVEL_DEBUG,"Index %d has proc %s and count %d\n",
  1359. i,
  1360. totemip_print(&ref_cnt[i].addr),
  1361. ref_cnt[i].count);
  1362. }
  1363. }
  1364. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1365. /*
  1366. * If checkpoint doesn't exist, create one
  1367. */
  1368. if (ckptCheckpoint == 0) {
  1369. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open Allocating new Checkpoint %s\n", &checkpointName->value);
  1370. ckptCheckpoint = malloc (sizeof (struct saCkptCheckpoint));
  1371. if (ckptCheckpoint == 0) {
  1372. error = SA_AIS_ERR_NO_MEMORY;
  1373. goto error_exit;
  1374. }
  1375. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1376. if (ckptCheckpointSection == 0) {
  1377. free (ckptCheckpoint);
  1378. error = SA_AIS_ERR_NO_MEMORY;
  1379. goto error_exit;
  1380. }
  1381. memcpy (&ckptCheckpoint->name,
  1382. checkpointName,
  1383. sizeof (SaNameT));
  1384. memcpy (&ckptCheckpoint->checkpointCreationAttributes,
  1385. ckptAttributes,
  1386. sizeof (SaCkptCheckpointCreationAttributesT));
  1387. ckptCheckpoint->unlinked = 0;
  1388. list_init (&ckptCheckpoint->list);
  1389. list_init (&ckptCheckpoint->checkpointSectionsListHead);
  1390. list_add (&ckptCheckpoint->list, &checkpoint_list_head);
  1391. ckptCheckpoint->retention_timer = 0;
  1392. ckptCheckpoint->expired = 0;
  1393. /*
  1394. * Add in default checkpoint section
  1395. */
  1396. list_init (&ckptCheckpointSection->list);
  1397. list_add (&ckptCheckpointSection->list, &ckptCheckpoint->checkpointSectionsListHead);
  1398. /*
  1399. * Default section id
  1400. */
  1401. ckptCheckpointSection->sectionDescriptor.sectionId.id = 0;
  1402. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = 0;
  1403. ckptCheckpointSection->sectionDescriptor.expirationTime = SA_TIME_END;
  1404. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1405. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /*current time*/
  1406. ckptCheckpointSection->sectionDescriptor.sectionSize = strlen("Factory installed data\0")+1;
  1407. ckptCheckpointSection->sectionData = malloc(strlen("Factory installed data\0")+1);
  1408. assert(ckptCheckpointSection->sectionData);
  1409. memcpy(ckptCheckpointSection->sectionData, "Factory installed data\0", strlen("Factory installed data\0")+1);
  1410. ckptCheckpointSection->expiration_timer = 0;
  1411. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) &&
  1412. (ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) {
  1413. ckptCheckpoint->active_replica_set = 1;
  1414. } else
  1415. if ((ckptCheckpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) == 1) {
  1416. ckptCheckpoint->active_replica_set = 1;
  1417. } else {
  1418. ckptCheckpoint->active_replica_set = 0;
  1419. }
  1420. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1421. }
  1422. else {
  1423. /*
  1424. * Setup connection information and mark checkpoint as referenced
  1425. */
  1426. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery CHECKPOINT reopened is %p\n", ckptCheckpoint);
  1427. }
  1428. /*
  1429. * If the checkpoint has been unlinked, it is an invalid name
  1430. */
  1431. if (ckptCheckpoint->unlinked) {
  1432. error = SA_AIS_ERR_BAD_OPERATION; /* Is this the correct return ? */
  1433. goto error_exit;
  1434. }
  1435. /*CHECK to see if there are any existing ckpts*/
  1436. if ((ckptCheckpoint->ckpt_refcount) && (ckpt_refcount_total(ckptCheckpoint->ckpt_refcount) > 0)) {
  1437. log_printf (LOG_LEVEL_DEBUG,"calling merge_ckpt_refcounts\n");
  1438. merge_ckpt_refcounts(ckptCheckpoint->ckpt_refcount, ref_cnt);
  1439. }
  1440. else {
  1441. initialize_ckpt_refcount_array(ckptCheckpoint->ckpt_refcount);
  1442. }
  1443. /*No Existing ckpts. Lets assign what we got over the network or the merged with network values*/
  1444. ckptCheckpoint->referenceCount = ckpt_refcount_total(ref_cnt);
  1445. log_printf (LOG_LEVEL_DEBUG, "CKPT: OPEN ckptCheckpoint->referenceCount %d\n",ckptCheckpoint->referenceCount);
  1446. memcpy(ckptCheckpoint->ckpt_refcount,ref_cnt,sizeof(struct ckpt_refcnt)*PROCESSOR_COUNT_MAX);
  1447. /*
  1448. * Reset retention duration since this checkpoint was just opened
  1449. */
  1450. poll_timer_delete (aisexec_poll_handle, ckptCheckpoint->retention_timer);
  1451. ckptCheckpoint->retention_timer = 0;
  1452. /*
  1453. * Send error result to CKPT library
  1454. */
  1455. error_exit:
  1456. return (error);
  1457. }
  1458. static int message_handler_req_exec_ckpt_synchronize_state (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1459. {
  1460. int retcode;
  1461. struct req_exec_ckpt_synchronize_state *req_exec_ckpt_sync_state
  1462. = (struct req_exec_ckpt_synchronize_state *)message;
  1463. /*
  1464. * If the Incoming message's previous ring id == saved_ring_id
  1465. * Ignore because we have seen this message before.
  1466. */
  1467. if (memcmp (&req_exec_ckpt_sync_state->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1468. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state ignoring ...\n");
  1469. return(0);
  1470. }
  1471. retcode = recovery_checkpoint_open(&req_exec_ckpt_sync_state->checkpointName,
  1472. &req_exec_ckpt_sync_state->checkpointCreationAttributes,
  1473. req_exec_ckpt_sync_state->ckpt_refcount);
  1474. if (retcode != SA_AIS_OK) {
  1475. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1476. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_checkpoint_open returned %d\n",retcode);
  1477. }
  1478. retcode = recovery_section_create (&req_exec_ckpt_sync_state->sectionDescriptor,
  1479. &req_exec_ckpt_sync_state->checkpointName,
  1480. (char*)req_exec_ckpt_sync_state
  1481. + sizeof (struct req_exec_ckpt_synchronize_state));
  1482. if (retcode != SA_AIS_OK) {
  1483. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_state\n");
  1484. log_printf(LOG_LEVEL_DEBUG, "CKPT: recovery_section_create returned %d\n",retcode);
  1485. }
  1486. return (0);
  1487. }
  1488. static int message_handler_req_exec_ckpt_synchronize_section (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1489. {
  1490. int retcode;
  1491. struct req_exec_ckpt_synchronize_section *req_exec_ckpt_sync_section
  1492. = (struct req_exec_ckpt_synchronize_section *)message;
  1493. /*
  1494. * If the Incoming message's previous ring id == saved_ring_id
  1495. * Ignore because we have seen this message before.
  1496. */
  1497. if (memcmp (&req_exec_ckpt_sync_section->previous_ring_id, &saved_ring_id,sizeof (struct memb_ring_id)) == 0) {
  1498. log_printf(LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_synchronize_section ignoring ...\n");
  1499. return(0);
  1500. }
  1501. /*
  1502. * Write the contents of the section to the checkpoint section.
  1503. */
  1504. retcode = recovery_section_write(req_exec_ckpt_sync_section->sectionId.idLen,
  1505. (char*)req_exec_ckpt_sync_section
  1506. + sizeof (struct req_exec_ckpt_synchronize_section),
  1507. &req_exec_ckpt_sync_section->checkpointName,
  1508. (char*)req_exec_ckpt_sync_section
  1509. + sizeof (struct req_exec_ckpt_synchronize_section)
  1510. + req_exec_ckpt_sync_section->sectionId.idLen,
  1511. req_exec_ckpt_sync_section->dataOffSet,
  1512. req_exec_ckpt_sync_section->dataSize);
  1513. if (retcode != SA_AIS_OK) {
  1514. log_printf(LOG_LEVEL_ERROR, "CKPT: message_handler_req_exec_ckpt_synchronize_section\n");
  1515. log_printf(LOG_LEVEL_ERROR, "CKPT: recovery_section_write returned %d\n",retcode);
  1516. }
  1517. return (0);
  1518. }
  1519. unsigned int abstime_to_msec (SaTimeT time)
  1520. {
  1521. struct timeval tv;
  1522. unsigned long long curr_time;
  1523. unsigned long long msec_time;
  1524. gettimeofday (&tv, NULL);
  1525. curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) +
  1526. (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000)));
  1527. msec_time = (((unsigned long long)time) / 1000000) -
  1528. (unsigned long long)curr_time;
  1529. return ((unsigned int)(msec_time));
  1530. }
  1531. void timer_function_section_expire (void *data)
  1532. {
  1533. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1534. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  1535. struct ckpt_identifier *ckpt_id = 0;
  1536. ckpt_id = (struct ckpt_identifier *)data;
  1537. log_printf (LOG_LEVEL_DEBUG, "CKPT: timer_function_section_expire data = 0x%x \n",data);
  1538. if (ckpt_id->ckpt_section_id.idLen && ckpt_id->ckpt_section_id.id) {
  1539. log_printf (LOG_LEVEL_DEBUG, "CKPT: Attempting to Expire section %s in ckpt %s\n",
  1540. ckpt_id->ckpt_section_id.id,
  1541. (char *)&ckpt_id->ckpt_name.value);
  1542. }
  1543. else {
  1544. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire data incorect\n");
  1545. goto free_mem;
  1546. }
  1547. ckptCheckpoint = ckpt_checkpoint_find_global (&ckpt_id->ckpt_name);
  1548. if (ckptCheckpoint == 0) {
  1549. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find ckpt %s\n",
  1550. (char *)&ckpt_id->ckpt_name.value);
  1551. goto free_mem;
  1552. }
  1553. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1554. (char *)ckpt_id->ckpt_section_id.id,
  1555. (int)ckpt_id->ckpt_section_id.idLen);
  1556. if (ckptCheckpointSection == 0) {
  1557. log_printf (LOG_LEVEL_ERROR, "CKPT: timer_function_section_expire could not find section %s in ckpt %s\n",
  1558. ckpt_id->ckpt_section_id.id,
  1559. (char *)&ckpt_id->ckpt_name.value);
  1560. goto free_mem;
  1561. }
  1562. log_printf (LOG_LEVEL_DEBUG, "CKPT: Expiring section %s in ckpt %s\n",
  1563. ckpt_id->ckpt_section_id.id,
  1564. (char *)&ckpt_id->ckpt_name.value);
  1565. ckptCheckpoint->sectionCount -= 1;
  1566. checkpoint_section_release (ckptCheckpointSection);
  1567. free_mem :
  1568. free (ckpt_id);
  1569. }
  1570. void timer_function_retention (void *data)
  1571. {
  1572. struct saCkptCheckpoint *checkpoint = (struct saCkptCheckpoint *)data;
  1573. struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire;
  1574. struct iovec iovec;
  1575. checkpoint->retention_timer = 0;
  1576. req_exec_ckpt_checkpointretentiondurationexpire.header.size =
  1577. sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire);
  1578. req_exec_ckpt_checkpointretentiondurationexpire.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE;
  1579. memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpointName,
  1580. &checkpoint->name,
  1581. sizeof (SaNameT));
  1582. iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire;
  1583. iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire);
  1584. assert (totempg_mcast (&iovec, 1, TOTEMPG_AGREED) == 0);
  1585. }
  1586. extern int message_handler_req_exec_ckpt_checkpointclose (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1587. {
  1588. struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message;
  1589. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  1590. struct saCkptCheckpoint *checkpoint = 0;
  1591. SaAisErrorT error = SA_AIS_OK;
  1592. int proc_index;
  1593. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointclose->checkpointName));
  1594. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointclose->checkpointName);
  1595. if (checkpoint == 0) {
  1596. goto error_exit;
  1597. }
  1598. log_printf (LOG_LEVEL_DEBUG, "CKPT:CLOSE checkpoint->referenceCount %d\n",checkpoint->referenceCount);
  1599. checkpoint->referenceCount--;
  1600. /*
  1601. * Modify the connection reference information to the Checkpoint to be
  1602. * sent out later as a part of the sync process.
  1603. */
  1604. proc_index = processor_index_find(source_addr, checkpoint->ckpt_refcount);
  1605. if (proc_index != -1 ) {
  1606. checkpoint->ckpt_refcount[proc_index].count--;
  1607. }
  1608. else {
  1609. log_printf (LOG_LEVEL_ERROR,
  1610. "CKPT: Could Not find Processor Info %p info.\n",
  1611. checkpoint);
  1612. }
  1613. assert (checkpoint->referenceCount >= 0);
  1614. log_printf (LOG_LEVEL_DEBUG, "disconnect called, new CKPT ref count is %d\n",
  1615. checkpoint->referenceCount);
  1616. /*
  1617. * If checkpoint has been unlinked and this is the last reference, delete it
  1618. */
  1619. if (checkpoint->unlinked && checkpoint->referenceCount == 0) {
  1620. log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n");
  1621. checkpoint_release (checkpoint);
  1622. } else
  1623. if (checkpoint->referenceCount == 0) {
  1624. poll_timer_add (aisexec_poll_handle,
  1625. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1626. checkpoint,
  1627. timer_function_retention,
  1628. &checkpoint->retention_timer);
  1629. }
  1630. error_exit:
  1631. if (message_source_is_local(&req_exec_ckpt_checkpointclose->source)) {
  1632. ckpt_checkpoint_remove_cleanup (req_exec_ckpt_checkpointclose->source.conn_info,
  1633. checkpoint);
  1634. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  1635. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  1636. res_lib_ckpt_checkpointclose.header.error = error;
  1637. libais_send_response (req_exec_ckpt_checkpointclose->source.conn_info,
  1638. &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose));
  1639. }
  1640. return (0);
  1641. }
  1642. static int message_handler_req_exec_ckpt_checkpointunlink (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1643. {
  1644. struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message;
  1645. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)&req_exec_ckpt_checkpointunlink->req_lib_ckpt_checkpointunlink;
  1646. struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink;
  1647. struct saCkptCheckpoint *ckptCheckpoint = 0;
  1648. SaErrorT error = SA_AIS_OK;
  1649. log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink);
  1650. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointunlink->checkpointName);
  1651. if (ckptCheckpoint == 0) {
  1652. error = SA_AIS_ERR_NOT_EXIST;
  1653. goto error_exit;
  1654. }
  1655. if (ckptCheckpoint->unlinked) {
  1656. error = SA_AIS_ERR_INVALID_PARAM;
  1657. goto error_exit;
  1658. }
  1659. ckptCheckpoint->unlinked = 1;
  1660. /*
  1661. * Immediately delete entry if reference count is zero
  1662. */
  1663. if (ckptCheckpoint->referenceCount == 0) {
  1664. /*
  1665. * Remove retention timer since this checkpoint was unlinked and is no
  1666. * longer referenced
  1667. */
  1668. checkpoint_release (ckptCheckpoint);
  1669. }
  1670. error_exit:
  1671. /*
  1672. * If this node was the source of the message, respond to this node
  1673. */
  1674. if (message_source_is_local(&req_exec_ckpt_checkpointunlink->source)) {
  1675. res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink);
  1676. res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK;
  1677. res_lib_ckpt_checkpointunlink.header.error = error;
  1678. libais_send_response (req_exec_ckpt_checkpointunlink->source.conn_info, &res_lib_ckpt_checkpointunlink,
  1679. sizeof (struct res_lib_ckpt_checkpointunlink));
  1680. }
  1681. return (0);
  1682. }
  1683. static int message_handler_req_exec_ckpt_checkpointretentiondurationset (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1684. {
  1685. struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message;
  1686. struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset;
  1687. struct saCkptCheckpoint *checkpoint;
  1688. SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION;
  1689. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationset->checkpointName);
  1690. if (checkpoint) {
  1691. log_printf (LOG_LEVEL_DEBUG, "CKPT: Setting retention duration for checkpoint %s\n",
  1692. getSaNameT (&req_exec_ckpt_checkpointretentiondurationset->checkpointName));
  1693. if (checkpoint->unlinked == 0) {
  1694. checkpoint->checkpointCreationAttributes.retentionDuration =
  1695. req_exec_ckpt_checkpointretentiondurationset->retentionDuration;
  1696. if (checkpoint->expired == 0 && checkpoint->referenceCount == 0) {
  1697. poll_timer_delete (aisexec_poll_handle, checkpoint->retention_timer);
  1698. poll_timer_add (aisexec_poll_handle,
  1699. checkpoint->checkpointCreationAttributes.retentionDuration / 1000000,
  1700. checkpoint,
  1701. timer_function_retention,
  1702. &checkpoint->retention_timer);
  1703. }
  1704. error = SA_AIS_OK;
  1705. }
  1706. }
  1707. /*
  1708. * Respond to library if this processor sent the duration set request
  1709. */
  1710. if (message_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) {
  1711. res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset);
  1712. res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET;
  1713. res_lib_ckpt_checkpointretentiondurationset.header.error = error;
  1714. libais_send_response (req_exec_ckpt_checkpointretentiondurationset->source.conn_info,
  1715. &res_lib_ckpt_checkpointretentiondurationset,
  1716. sizeof (struct res_lib_ckpt_checkpointretentiondurationset));
  1717. }
  1718. return (0);
  1719. }
  1720. static int message_handler_req_exec_ckpt_checkpointretentiondurationexpire (void *message, struct totem_ip_address *source_addr, int endian_conversion_required)
  1721. {
  1722. struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message;
  1723. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  1724. struct saCkptCheckpoint *checkpoint;
  1725. struct iovec iovecs[2];
  1726. checkpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName);
  1727. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->referenceCount < 1)) {
  1728. log_printf (LOG_LEVEL_NOTICE, "CKPT: Expiring checkpoint %s\n", getSaNameT (&req_exec_ckpt_checkpointretentiondurationexpire->checkpointName));
  1729. checkpoint->expired = 1;
  1730. req_exec_ckpt_checkpointunlink.header.size =
  1731. sizeof (struct req_exec_ckpt_checkpointunlink);
  1732. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  1733. req_exec_ckpt_checkpointunlink.source.conn_info = 0;
  1734. req_exec_ckpt_checkpointunlink.source.addr.family = 0;
  1735. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink.checkpointName,
  1736. &req_exec_ckpt_checkpointretentiondurationexpire->checkpointName,
  1737. sizeof (SaNameT));
  1738. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  1739. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  1740. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1741. }
  1742. return (0);
  1743. }
  1744. static int recovery_section_create (SaCkptSectionDescriptorT *sectionDescriptor,
  1745. SaNameT *checkpointName,
  1746. char* SectionId)
  1747. {
  1748. struct saCkptCheckpoint *ckptCheckpoint;
  1749. struct saCkptCheckpointSection *ckptCheckpointSection;
  1750. void *initialData;
  1751. void *sectionId;
  1752. struct ckpt_identifier *ckpt_id = 0;
  1753. SaErrorT error = SA_AIS_OK;
  1754. if ((int)sectionDescriptor->sectionId.idLen) {
  1755. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, section %s.\n",
  1756. &checkpointName->value, SectionId);
  1757. } else {
  1758. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create for checkpoint %s, default section.\n",
  1759. &checkpointName->value);
  1760. }
  1761. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  1762. if (ckptCheckpoint == 0) {
  1763. error = SA_AIS_ERR_NOT_EXIST;
  1764. goto error_exit;
  1765. }
  1766. /*
  1767. * Determine if user-specified checkpoint ID already exists
  1768. */
  1769. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1770. SectionId,
  1771. (int)sectionDescriptor->sectionId.idLen);
  1772. if (ckptCheckpointSection) {
  1773. error = SA_AIS_ERR_EXIST;
  1774. goto error_exit;
  1775. }
  1776. /*
  1777. * Allocate checkpoint section
  1778. */
  1779. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1780. if (ckptCheckpointSection == 0) {
  1781. error = SA_AIS_ERR_NO_MEMORY;
  1782. goto error_exit;
  1783. }
  1784. /*
  1785. * Allocate checkpoint section data
  1786. */
  1787. initialData = malloc (sectionDescriptor->sectionSize);
  1788. if (initialData == 0) {
  1789. free (ckptCheckpointSection);
  1790. error = SA_AIS_ERR_NO_MEMORY;
  1791. goto error_exit;
  1792. }
  1793. /*
  1794. * Allocate checkpoint section id
  1795. */
  1796. if (sectionDescriptor->sectionId.idLen) {
  1797. sectionId = malloc ((int)sectionDescriptor->sectionId.idLen);
  1798. if (sectionId == 0) {
  1799. free (ckptCheckpointSection);
  1800. free (initialData);
  1801. error = SA_AIS_ERR_NO_MEMORY;
  1802. goto error_exit;
  1803. }
  1804. } else {
  1805. sectionId = 0;
  1806. }
  1807. /*
  1808. * Copy checkpoint section ID and initialize data.
  1809. */
  1810. if (SectionId) {
  1811. memcpy ((char*)sectionId, (char*)SectionId, (int)sectionDescriptor->sectionId.idLen);
  1812. } else {
  1813. sectionId = 0;
  1814. }
  1815. memset (initialData, 0, sectionDescriptor->sectionSize);
  1816. /*
  1817. * Configure checkpoint section
  1818. */
  1819. memcpy(&ckptCheckpointSection->sectionDescriptor,
  1820. sectionDescriptor,
  1821. sizeof(SaCkptSectionDescriptorT));
  1822. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1823. ckptCheckpointSection->sectionData = initialData;
  1824. ckptCheckpointSection->expiration_timer = 0;
  1825. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1826. if (sectionDescriptor->expirationTime != SA_TIME_END) {
  1827. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1828. assert(ckpt_id);
  1829. memcpy(&ckpt_id->ckpt_name,checkpointName,sizeof(SaNameT));
  1830. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1831. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create Enqueuing Timer to Expire section %s in ckpt %s\n",
  1832. ckpt_id->ckpt_section_id.id,
  1833. (char *)&ckpt_id->ckpt_name.value);
  1834. poll_timer_add (aisexec_poll_handle,
  1835. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1836. ckpt_id,
  1837. timer_function_section_expire,
  1838. &ckptCheckpointSection->expiration_timer);
  1839. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_create expiration timer = 0x%x\n",
  1840. ckptCheckpointSection->expiration_timer);
  1841. }
  1842. /*
  1843. * Add checkpoint section to checkpoint
  1844. */
  1845. list_init (&ckptCheckpointSection->list);
  1846. list_add (&ckptCheckpointSection->list,
  1847. &ckptCheckpoint->checkpointSectionsListHead);
  1848. error_exit:
  1849. return (error);
  1850. }
  1851. static int message_handler_req_exec_ckpt_sectioncreate (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  1852. struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message;
  1853. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)&req_exec_ckpt_sectioncreate->req_lib_ckpt_sectioncreate;
  1854. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  1855. struct saCkptCheckpoint *ckptCheckpoint;
  1856. struct saCkptCheckpointSection *ckptCheckpointSection;
  1857. void *initialData;
  1858. void *sectionId;
  1859. struct ckpt_identifier *ckpt_id = 0;
  1860. SaErrorT error = SA_AIS_OK;
  1861. log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n");
  1862. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectioncreate->checkpointName);
  1863. if (ckptCheckpoint == 0) {
  1864. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this*/
  1865. goto error_exit;
  1866. }
  1867. if (ckptCheckpoint->sectionCount == ckptCheckpoint->checkpointCreationAttributes.maxSections) {
  1868. error = SA_AIS_ERR_NO_SPACE;
  1869. goto error_exit;
  1870. }
  1871. if (ckptCheckpoint->checkpointCreationAttributes.maxSections == 1) {
  1872. error = SA_AIS_ERR_EXIST;
  1873. goto error_exit;
  1874. }
  1875. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize <
  1876. req_lib_ckpt_sectioncreate->initialDataSize) {
  1877. error = SA_AIS_ERR_INVALID_PARAM;
  1878. goto error_exit;
  1879. }
  1880. /*
  1881. * Determine if user-specified checkpoint ID already exists
  1882. */
  1883. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  1884. ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1885. req_lib_ckpt_sectioncreate->idLen);
  1886. if (ckptCheckpointSection) {
  1887. error = SA_AIS_ERR_EXIST;
  1888. goto error_exit;
  1889. }
  1890. /*
  1891. * Allocate checkpoint section
  1892. */
  1893. ckptCheckpointSection = malloc (sizeof (struct saCkptCheckpointSection));
  1894. if (ckptCheckpointSection == 0) {
  1895. error = SA_AIS_ERR_NO_MEMORY;
  1896. goto error_exit;
  1897. }
  1898. /*
  1899. * Allocate checkpoint section data
  1900. */
  1901. initialData = malloc (req_lib_ckpt_sectioncreate->initialDataSize);
  1902. if (initialData == 0) {
  1903. free (ckptCheckpointSection);
  1904. error = SA_AIS_ERR_NO_MEMORY;
  1905. goto error_exit;
  1906. }
  1907. /*
  1908. * Allocate checkpoint section id
  1909. */
  1910. sectionId = malloc (req_lib_ckpt_sectioncreate->idLen);
  1911. if (sectionId == 0) {
  1912. free (ckptCheckpointSection);
  1913. free (initialData);
  1914. error = SA_AIS_ERR_NO_MEMORY;
  1915. goto error_exit;
  1916. }
  1917. /*
  1918. * Copy checkpoint section and section ID
  1919. */
  1920. memcpy (sectionId, ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate),
  1921. req_lib_ckpt_sectioncreate->idLen);
  1922. memcpy (initialData,
  1923. ((char *)req_lib_ckpt_sectioncreate) +
  1924. sizeof (struct req_lib_ckpt_sectioncreate) +
  1925. req_lib_ckpt_sectioncreate->idLen,
  1926. req_lib_ckpt_sectioncreate->initialDataSize);
  1927. /*
  1928. * Configure checkpoint section
  1929. */
  1930. ckptCheckpointSection->sectionDescriptor.sectionId.id = sectionId;
  1931. ckptCheckpointSection->sectionDescriptor.sectionId.idLen = req_lib_ckpt_sectioncreate->idLen;
  1932. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectioncreate->initialDataSize;
  1933. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectioncreate->expirationTime;
  1934. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  1935. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  1936. ckptCheckpointSection->sectionData = initialData;
  1937. ckptCheckpointSection->expiration_timer = 0;
  1938. if (req_lib_ckpt_sectioncreate->expirationTime != SA_TIME_END) {
  1939. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  1940. assert(ckpt_id);
  1941. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectioncreate->checkpointName,sizeof(SaNameT));
  1942. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  1943. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n",
  1944. ckpt_id->ckpt_section_id.id,
  1945. (char *)&ckpt_id->ckpt_name.value);
  1946. poll_timer_add (aisexec_poll_handle,
  1947. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  1948. ckpt_id,
  1949. timer_function_section_expire,
  1950. &ckptCheckpointSection->expiration_timer);
  1951. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionicreate expiration timer = 0x%x\n",
  1952. ckptCheckpointSection->expiration_timer);
  1953. }
  1954. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_exec_ckpt_sectioncreate created section with id = %s, idLen = %d\n",
  1955. ckptCheckpointSection->sectionDescriptor.sectionId.id,
  1956. ckptCheckpointSection->sectionDescriptor.sectionId.idLen);
  1957. /*
  1958. * Add checkpoint section to checkpoint
  1959. */
  1960. list_init (&ckptCheckpointSection->list);
  1961. list_add (&ckptCheckpointSection->list,
  1962. &ckptCheckpoint->checkpointSectionsListHead);
  1963. ckptCheckpoint->sectionCount += 1;
  1964. error_exit:
  1965. if (message_source_is_local(&req_exec_ckpt_sectioncreate->source)) {
  1966. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  1967. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  1968. res_lib_ckpt_sectioncreate.header.error = error;
  1969. libais_send_response (req_exec_ckpt_sectioncreate->source.conn_info,
  1970. &res_lib_ckpt_sectioncreate,
  1971. sizeof (struct res_lib_ckpt_sectioncreate));
  1972. }
  1973. return (0);
  1974. }
  1975. static int message_handler_req_exec_ckpt_sectiondelete (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  1976. struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message;
  1977. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)&req_exec_ckpt_sectiondelete->req_lib_ckpt_sectiondelete;
  1978. struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete;
  1979. struct saCkptCheckpoint *ckptCheckpoint;
  1980. struct saCkptCheckpointSection *ckptCheckpointSection;
  1981. SaErrorT error = SA_AIS_OK;
  1982. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectiondelete->checkpointName);
  1983. if (ckptCheckpoint == 0) {
  1984. error = SA_AIS_ERR_NOT_EXIST;
  1985. goto error_exit;
  1986. }
  1987. if (ckptCheckpoint->active_replica_set == 0) {
  1988. log_printf (LOG_LEVEL_NOTICE, "sectiondelete: no active replica, returning error.\n");
  1989. error = SA_AIS_ERR_NOT_EXIST;
  1990. goto error_exit;
  1991. }
  1992. /*
  1993. * Determine if the user is trying to delete the default section
  1994. */
  1995. if (req_lib_ckpt_sectiondelete->idLen == 0) {
  1996. error = SA_AIS_ERR_INVALID_PARAM;
  1997. goto error_exit;
  1998. }
  1999. /*
  2000. * Find checkpoint section to be deleted
  2001. */
  2002. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2003. ((char *)(req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete)),
  2004. req_lib_ckpt_sectiondelete->idLen);
  2005. if (ckptCheckpointSection == 0) {
  2006. error = SA_AIS_ERR_NOT_EXIST;
  2007. goto error_exit;
  2008. }
  2009. printf ("delete ckptCheckpointSection name %s\n",
  2010. ckptCheckpointSection->sectionDescriptor.sectionId.id);
  2011. /*
  2012. * Delete checkpoint section
  2013. */
  2014. ckptCheckpoint->sectionCount -= 1;
  2015. checkpoint_section_release (ckptCheckpointSection);
  2016. /*
  2017. * return result to CKPT library
  2018. */
  2019. error_exit:
  2020. if (message_source_is_local(&req_exec_ckpt_sectiondelete->source)) {
  2021. res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete);
  2022. res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE;
  2023. res_lib_ckpt_sectiondelete.header.error = error;
  2024. libais_send_response (req_exec_ckpt_sectiondelete->source.conn_info,
  2025. &res_lib_ckpt_sectiondelete,
  2026. sizeof (struct res_lib_ckpt_sectiondelete));
  2027. }
  2028. return (0);
  2029. }
  2030. static int message_handler_req_exec_ckpt_sectionexpirationtimeset (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  2031. struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message;
  2032. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)&req_exec_ckpt_sectionexpirationtimeset->req_lib_ckpt_sectionexpirationtimeset;
  2033. struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset;
  2034. struct saCkptCheckpoint *ckptCheckpoint;
  2035. struct saCkptCheckpointSection *ckptCheckpointSection;
  2036. struct ckpt_identifier *ckpt_id = 0;
  2037. SaErrorT error = SA_AIS_OK;
  2038. log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiratoin time\n");
  2039. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionexpirationtimeset->checkpointName);
  2040. if (ckptCheckpoint == 0) {
  2041. error = SA_AIS_ERR_NOT_EXIST;
  2042. goto error_exit;
  2043. }
  2044. if (ckptCheckpoint->active_replica_set == 0) {
  2045. log_printf (LOG_LEVEL_NOTICE, "expirationset: no active replica, returning error.\n");
  2046. error = SA_AIS_ERR_NOT_EXIST;
  2047. goto error_exit;
  2048. }
  2049. /*
  2050. * Determine if the user is trying to set expiration time for the default section
  2051. */
  2052. if (req_lib_ckpt_sectionexpirationtimeset->idLen == 0) {
  2053. error = SA_AIS_ERR_INVALID_PARAM;
  2054. goto error_exit;
  2055. }
  2056. /*
  2057. * Find checkpoint section that expiration time should be set for
  2058. */
  2059. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2060. ((char *)req_lib_ckpt_sectionexpirationtimeset) +
  2061. sizeof (struct req_lib_ckpt_sectionexpirationtimeset),
  2062. req_lib_ckpt_sectionexpirationtimeset->idLen);
  2063. if (ckptCheckpointSection == 0) {
  2064. error = SA_AIS_ERR_NOT_EXIST;
  2065. goto error_exit;
  2066. }
  2067. ckptCheckpointSection->sectionDescriptor.expirationTime = req_lib_ckpt_sectionexpirationtimeset->expirationTime;
  2068. poll_timer_delete (aisexec_poll_handle, ckptCheckpointSection->expiration_timer);
  2069. ckptCheckpointSection->expiration_timer = 0;
  2070. if (req_lib_ckpt_sectionexpirationtimeset->expirationTime != SA_TIME_END) {
  2071. ckpt_id = malloc (sizeof(struct ckpt_identifier));
  2072. assert(ckpt_id);
  2073. memcpy(&ckpt_id->ckpt_name,&req_exec_ckpt_sectionexpirationtimeset->checkpointName,sizeof(SaNameT));
  2074. memcpy(&ckpt_id->ckpt_section_id, &ckptCheckpointSection->sectionDescriptor.sectionId,sizeof(SaCkptSectionIdT));
  2075. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%x\n",
  2076. ckpt_id->ckpt_section_id.id,
  2077. (char *)&ckpt_id->ckpt_name.value,
  2078. ckpt_id);
  2079. poll_timer_add (aisexec_poll_handle,
  2080. abstime_to_msec (ckptCheckpointSection->sectionDescriptor.expirationTime),
  2081. ckpt_id,
  2082. timer_function_section_expire,
  2083. &ckptCheckpointSection->expiration_timer);
  2084. log_printf (LOG_LEVEL_DEBUG, "CKPT: req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%x\n",
  2085. ckptCheckpointSection->expiration_timer);
  2086. }
  2087. error_exit:
  2088. if (message_source_is_local(&req_exec_ckpt_sectionexpirationtimeset->source)) {
  2089. res_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset);
  2090. res_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET;
  2091. res_lib_ckpt_sectionexpirationtimeset.header.error = error;
  2092. libais_send_response (req_exec_ckpt_sectionexpirationtimeset->source.conn_info,
  2093. &res_lib_ckpt_sectionexpirationtimeset,
  2094. sizeof (struct res_lib_ckpt_sectionexpirationtimeset));
  2095. }
  2096. return (0);
  2097. }
  2098. static int recovery_section_write(int sectionIdLen,
  2099. char* sectionId,
  2100. SaNameT *checkpointName,
  2101. void *newData,
  2102. SaUint32T dataOffSet,
  2103. SaUint32T dataSize)
  2104. {
  2105. struct saCkptCheckpoint *ckptCheckpoint;
  2106. struct saCkptCheckpointSection *ckptCheckpointSection;
  2107. int sizeRequired;
  2108. SaErrorT error = SA_AIS_OK;
  2109. char *sd;
  2110. log_printf (LOG_LEVEL_DEBUG, "CKPT: recovery_section_write.\n");
  2111. ckptCheckpoint = ckpt_checkpoint_find_global (checkpointName);
  2112. if (ckptCheckpoint == 0) {
  2113. error = SA_AIS_ERR_NOT_EXIST;
  2114. goto error_exit;
  2115. }
  2116. /*
  2117. * Find checkpoint section to be written
  2118. */
  2119. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2120. sectionId,
  2121. sectionIdLen);
  2122. if (ckptCheckpointSection == 0) {
  2123. error = SA_AIS_ERR_NOT_EXIST;
  2124. goto error_exit;
  2125. }
  2126. /*
  2127. * If write would extend past end of section data, return error;
  2128. */
  2129. sizeRequired = dataOffSet + dataSize;
  2130. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2131. error = SA_AIS_ERR_ACCESS;
  2132. goto error_exit;
  2133. }
  2134. /*
  2135. * Write checkpoint section to section data
  2136. */
  2137. if (dataSize > 0) {
  2138. sd = (char *)ckptCheckpointSection->sectionData;
  2139. memcpy (&sd[dataOffSet],
  2140. newData,
  2141. dataSize);
  2142. }
  2143. error_exit:
  2144. return (error);
  2145. }
  2146. static int message_handler_req_exec_ckpt_sectionwrite (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  2147. struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message;
  2148. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)&req_exec_ckpt_sectionwrite->req_lib_ckpt_sectionwrite;
  2149. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2150. struct saCkptCheckpoint *ckptCheckpoint;
  2151. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2152. int sizeRequired;
  2153. void *sectionData;
  2154. SaErrorT error = SA_AIS_OK;
  2155. log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n");
  2156. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionwrite->checkpointName);
  2157. if (ckptCheckpoint == 0) {
  2158. log_printf (LOG_LEVEL_ERROR, "CKPT: ckpt_checkpoint_find_global returned 0 Calling error_exit.\n");
  2159. error = SA_AIS_ERR_NOT_EXIST;
  2160. goto error_exit;
  2161. }
  2162. if (ckptCheckpoint->active_replica_set == 0) {
  2163. log_printf (LOG_LEVEL_NOTICE, "checkpointwrite: no active replica, returning error.\n");
  2164. error = SA_AIS_ERR_NOT_EXIST;
  2165. goto error_exit;
  2166. }
  2167. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionwrite->dataSize) {
  2168. error = SA_AIS_ERR_INVALID_PARAM;
  2169. goto error_exit;
  2170. }
  2171. /*
  2172. printf ("writing checkpoint section is %s\n", ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2173. */
  2174. /*
  2175. * Find checkpoint section to be written
  2176. */
  2177. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2178. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2179. req_lib_ckpt_sectionwrite->idLen);
  2180. if (ckptCheckpointSection == 0) {
  2181. if (req_lib_ckpt_sectionwrite->idLen == 0) {
  2182. log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n");
  2183. }
  2184. else {
  2185. log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n",
  2186. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite));
  2187. }
  2188. error = SA_AIS_ERR_NOT_EXIST;
  2189. goto error_exit;
  2190. }
  2191. /*
  2192. * If write would extend past end of section data, enlarge section
  2193. */
  2194. sizeRequired = req_lib_ckpt_sectionwrite->dataOffset + req_lib_ckpt_sectionwrite->dataSize;
  2195. if (sizeRequired > ckptCheckpointSection->sectionDescriptor.sectionSize) {
  2196. sectionData = realloc (ckptCheckpointSection->sectionData, sizeRequired);
  2197. if (sectionData == 0) {
  2198. log_printf (LOG_LEVEL_ERROR, "CKPT: sectionData realloc returned 0 Calling error_exit.\n");
  2199. error = SA_AIS_ERR_NO_MEMORY;
  2200. goto error_exit;
  2201. }
  2202. /*
  2203. * Install new section data
  2204. */
  2205. ckptCheckpointSection->sectionData = sectionData;
  2206. ckptCheckpointSection->sectionDescriptor.sectionSize = sizeRequired;
  2207. }
  2208. /*
  2209. * Write checkpoint section to section data
  2210. */
  2211. if (req_lib_ckpt_sectionwrite->dataSize > 0) {
  2212. char *sd;
  2213. int *val;
  2214. val = ckptCheckpointSection->sectionData;
  2215. sd = (char *)ckptCheckpointSection->sectionData;
  2216. memcpy (&sd[req_lib_ckpt_sectionwrite->dataOffset],
  2217. ((char *)req_exec_ckpt_sectionwrite) + sizeof (struct req_exec_ckpt_sectionwrite) +
  2218. req_lib_ckpt_sectionwrite->idLen,
  2219. req_lib_ckpt_sectionwrite->dataSize);
  2220. }
  2221. /*
  2222. * Write write response to CKPT library
  2223. */
  2224. error_exit:
  2225. if (message_source_is_local(&req_exec_ckpt_sectionwrite->source)) {
  2226. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2227. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2228. res_lib_ckpt_sectionwrite.header.error = error;
  2229. libais_send_response (req_exec_ckpt_sectionwrite->source.conn_info,
  2230. &res_lib_ckpt_sectionwrite,
  2231. sizeof (struct res_lib_ckpt_sectionwrite));
  2232. }
  2233. return (0);
  2234. }
  2235. static int message_handler_req_exec_ckpt_sectionoverwrite (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  2236. struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message;
  2237. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)&req_exec_ckpt_sectionoverwrite->req_lib_ckpt_sectionoverwrite;
  2238. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2239. struct saCkptCheckpoint *ckptCheckpoint;
  2240. struct saCkptCheckpointSection *ckptCheckpointSection;
  2241. void *sectionData;
  2242. SaErrorT error = SA_AIS_OK;
  2243. log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n");
  2244. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionoverwrite->checkpointName);
  2245. if (ckptCheckpoint == 0) {
  2246. error = SA_AIS_ERR_NOT_EXIST;
  2247. goto error_exit;
  2248. }
  2249. if (ckptCheckpoint->checkpointCreationAttributes.maxSectionSize < req_lib_ckpt_sectionoverwrite->dataSize) {
  2250. error = SA_AIS_ERR_INVALID_PARAM;
  2251. goto error_exit;
  2252. }
  2253. /*
  2254. * Find checkpoint section to be overwritten
  2255. */
  2256. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2257. ((char *)req_lib_ckpt_sectionoverwrite) +
  2258. sizeof (struct req_lib_ckpt_sectionoverwrite),
  2259. req_lib_ckpt_sectionoverwrite->idLen);
  2260. if (ckptCheckpointSection == 0) {
  2261. error = SA_AIS_ERR_NOT_EXIST;
  2262. goto error_exit;
  2263. }
  2264. /*
  2265. * Allocate checkpoint section data
  2266. */
  2267. sectionData = malloc (req_lib_ckpt_sectionoverwrite->dataSize);
  2268. if (sectionData == 0) {
  2269. error = SA_AIS_ERR_NO_MEMORY;
  2270. goto error_exit;
  2271. }
  2272. memcpy (sectionData,
  2273. ((char *)req_lib_ckpt_sectionoverwrite) +
  2274. sizeof (struct req_lib_ckpt_sectionoverwrite) +
  2275. req_lib_ckpt_sectionoverwrite->idLen,
  2276. req_lib_ckpt_sectionoverwrite->dataSize);
  2277. /*
  2278. * release old checkpoint section data
  2279. */
  2280. free (ckptCheckpointSection->sectionData);
  2281. /*
  2282. * Install overwritten checkpoint section data
  2283. */
  2284. ckptCheckpointSection->sectionDescriptor.sectionSize = req_lib_ckpt_sectionoverwrite->dataSize;
  2285. ckptCheckpointSection->sectionDescriptor.sectionState = SA_CKPT_SECTION_VALID;
  2286. ckptCheckpointSection->sectionDescriptor.lastUpdate = 0; /* TODO current time */
  2287. ckptCheckpointSection->sectionData = sectionData;
  2288. /*
  2289. * return result to CKPT library
  2290. */
  2291. error_exit:
  2292. if (message_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) {
  2293. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionoverwrite);
  2294. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2295. res_lib_ckpt_sectionoverwrite.header.error = error;
  2296. libais_send_response (req_exec_ckpt_sectionoverwrite->source.conn_info,
  2297. &res_lib_ckpt_sectionoverwrite,
  2298. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2299. }
  2300. return (0);
  2301. }
  2302. static int message_handler_req_exec_ckpt_sectionread (void *message, struct totem_ip_address *source_addr, int endian_conversion_required) {
  2303. struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message;
  2304. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)&req_exec_ckpt_sectionread->req_lib_ckpt_sectionread;
  2305. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2306. struct saCkptCheckpoint *ckptCheckpoint;
  2307. struct saCkptCheckpointSection *ckptCheckpointSection = 0;
  2308. int sectionSize = 0;
  2309. SaErrorT error = SA_AIS_OK;
  2310. log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n");
  2311. ckptCheckpoint = ckpt_checkpoint_find_global (&req_exec_ckpt_sectionread->checkpointName);
  2312. if (ckptCheckpoint == 0) {
  2313. error = SA_AIS_ERR_LIBRARY; /* TODO find the right error for this */
  2314. goto error_exit;
  2315. }
  2316. /*
  2317. * Find checkpoint section to be read
  2318. */
  2319. ckptCheckpointSection = ckpt_checkpoint_find_globalSection (ckptCheckpoint,
  2320. ((char *)req_lib_ckpt_sectionread) +
  2321. sizeof (struct req_lib_ckpt_sectionread),
  2322. req_lib_ckpt_sectionread->idLen);
  2323. if (ckptCheckpointSection == 0) {
  2324. error = SA_AIS_ERR_NOT_EXIST;
  2325. goto error_exit;
  2326. }
  2327. /*
  2328. * Determine the section size
  2329. */
  2330. sectionSize = ckptCheckpointSection->sectionDescriptor.sectionSize -
  2331. req_lib_ckpt_sectionread->dataOffset;
  2332. /*
  2333. * If the library has less space available then can be sent from the
  2334. * section, reduce bytes sent to library to max requested
  2335. */
  2336. if (sectionSize > req_lib_ckpt_sectionread->dataSize) {
  2337. sectionSize = req_lib_ckpt_sectionread->dataSize;
  2338. }
  2339. /*
  2340. * If dataOffset is past end of data, return INVALID PARAM
  2341. */
  2342. if (req_lib_ckpt_sectionread->dataOffset > sectionSize) {
  2343. sectionSize = 0;
  2344. error = SA_AIS_ERR_INVALID_PARAM;
  2345. goto error_exit;
  2346. }
  2347. /*
  2348. * Write read response to CKPT library
  2349. */
  2350. error_exit:
  2351. if (message_source_is_local(&req_exec_ckpt_sectionread->source)) {
  2352. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + sectionSize;
  2353. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2354. res_lib_ckpt_sectionread.header.error = error;
  2355. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2356. &res_lib_ckpt_sectionread,
  2357. sizeof (struct res_lib_ckpt_sectionread));
  2358. /*
  2359. * Write checkpoint to CKPT library section if section has data
  2360. */
  2361. if (sectionSize) {
  2362. char *sd;
  2363. sd = (char *)ckptCheckpointSection->sectionData;
  2364. libais_send_response (req_exec_ckpt_sectionread->source.conn_info,
  2365. &sd[req_lib_ckpt_sectionread->dataOffset],
  2366. sectionSize);
  2367. }
  2368. }
  2369. return (0);
  2370. }
  2371. static int ckpt_init_two_fn (struct conn_info *conn_info)
  2372. {
  2373. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator
  2374. .list);
  2375. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.sectionIteratorEntries = 0;
  2376. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorCount = 0;
  2377. conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.iteratorPos = 0;
  2378. list_add (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.sectionIterator.list,
  2379. &checkpoint_iterator_list_head);
  2380. list_init (&conn_info->conn_info_partner->ais_ci.u.libckpt_ci.checkpoint_list);
  2381. return (0);
  2382. }
  2383. static int message_handler_req_lib_ckpt_checkpointopen (struct conn_info *conn_info, void *message)
  2384. {
  2385. struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)message;
  2386. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2387. struct iovec iovecs[2];
  2388. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n");
  2389. req_exec_ckpt_checkpointopen.header.size =
  2390. sizeof (struct req_exec_ckpt_checkpointopen);
  2391. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2392. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2393. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2394. req_lib_ckpt_checkpointopen,
  2395. sizeof (struct req_lib_ckpt_checkpointopen));
  2396. req_exec_ckpt_checkpointopen.async_call = 0;
  2397. req_exec_ckpt_checkpointopen.invocation = 0;
  2398. req_exec_ckpt_checkpointopen.checkpointHandle = 0;
  2399. req_exec_ckpt_checkpointopen.fail_with_error = SA_AIS_OK;
  2400. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2401. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2402. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2403. return (0);
  2404. }
  2405. static int message_handler_req_lib_ckpt_checkpointopenasync (struct conn_info *conn_info, void *message)
  2406. {
  2407. struct req_lib_ckpt_checkpointopenasync *req_lib_ckpt_checkpointopenasync = (struct req_lib_ckpt_checkpointopenasync *)message;
  2408. struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen;
  2409. struct iovec iovecs[2];
  2410. log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint async.\n");
  2411. req_exec_ckpt_checkpointopen.header.size =
  2412. sizeof (struct req_exec_ckpt_checkpointopen);
  2413. req_exec_ckpt_checkpointopen.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN;
  2414. message_source_set (&req_exec_ckpt_checkpointopen.source, conn_info);
  2415. memcpy (&req_exec_ckpt_checkpointopen.req_lib_ckpt_checkpointopen,
  2416. req_lib_ckpt_checkpointopenasync,
  2417. sizeof (struct req_lib_ckpt_checkpointopen));
  2418. req_exec_ckpt_checkpointopen.async_call = 1;
  2419. req_exec_ckpt_checkpointopen.invocation = req_lib_ckpt_checkpointopenasync->invocation;
  2420. req_exec_ckpt_checkpointopen.checkpointHandle = req_lib_ckpt_checkpointopenasync->checkpointHandle;
  2421. req_exec_ckpt_checkpointopen.fail_with_error = req_lib_ckpt_checkpointopenasync->fail_with_error;
  2422. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointopen;
  2423. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointopen);
  2424. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2425. return (0);
  2426. }
  2427. static int message_handler_req_lib_ckpt_checkpointclose (struct conn_info *conn_info, void *message) {
  2428. struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)message;
  2429. struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose;
  2430. struct iovec iovecs[2];
  2431. struct saCkptCheckpoint *checkpoint;
  2432. struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose;
  2433. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointclose->checkpointName);
  2434. if (checkpoint && (checkpoint->expired == 0)) {
  2435. req_exec_ckpt_checkpointclose.header.size =
  2436. sizeof (struct req_exec_ckpt_checkpointclose);
  2437. req_exec_ckpt_checkpointclose.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE;
  2438. message_source_set (&req_exec_ckpt_checkpointclose.source, conn_info);
  2439. memcpy (&req_exec_ckpt_checkpointclose.checkpointName,
  2440. &req_lib_ckpt_checkpointclose->checkpointName, sizeof (SaNameT));
  2441. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointclose;
  2442. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointclose);
  2443. if (totempg_send_ok (sizeof (struct req_exec_ckpt_checkpointclose))) {
  2444. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2445. }
  2446. }
  2447. else {
  2448. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to close so Returning Error. ####\n");
  2449. res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose);
  2450. res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE;
  2451. res_lib_ckpt_checkpointclose.header.error = SA_AIS_ERR_NOT_EXIST;
  2452. libais_send_response (conn_info,
  2453. &res_lib_ckpt_checkpointclose,
  2454. sizeof (struct res_lib_ckpt_checkpointclose));
  2455. }
  2456. return (0);
  2457. }
  2458. static int message_handler_req_lib_ckpt_checkpointunlink (struct conn_info *conn_info, void *message)
  2459. {
  2460. struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)message;
  2461. struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink;
  2462. struct iovec iovecs[2];
  2463. req_exec_ckpt_checkpointunlink.header.size =
  2464. sizeof (struct req_exec_ckpt_checkpointunlink);
  2465. req_exec_ckpt_checkpointunlink.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK;
  2466. message_source_set (&req_exec_ckpt_checkpointunlink.source, conn_info);
  2467. memcpy (&req_exec_ckpt_checkpointunlink.req_lib_ckpt_checkpointunlink,
  2468. req_lib_ckpt_checkpointunlink,
  2469. sizeof (struct req_lib_ckpt_checkpointunlink));
  2470. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointunlink;
  2471. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointunlink);
  2472. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2473. return (0);
  2474. }
  2475. static int message_handler_req_lib_ckpt_checkpointretentiondurationset (struct conn_info *conn_info, void *message)
  2476. {
  2477. struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)message;
  2478. struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset;
  2479. struct iovec iovecs[2];
  2480. log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API fd %d\n", conn_info->fd);
  2481. req_exec_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET;
  2482. req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset);
  2483. message_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn_info);
  2484. memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpointName,
  2485. &req_lib_ckpt_checkpointretentiondurationset->checkpointName,
  2486. sizeof (SaNameT));
  2487. req_exec_ckpt_checkpointretentiondurationset.retentionDuration = req_lib_ckpt_checkpointretentiondurationset->retentionDuration;
  2488. iovecs[0].iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset;
  2489. iovecs[0].iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset);
  2490. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2491. return (0);
  2492. }
  2493. static int message_handler_req_lib_ckpt_activereplicaset (struct conn_info *conn_info, void *message)
  2494. {
  2495. struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)message;
  2496. struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset;
  2497. struct saCkptCheckpoint *checkpoint;
  2498. SaAisErrorT error = SA_AIS_OK;
  2499. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_activereplicaset->checkpointName);
  2500. /*
  2501. * Make sure checkpoint is collocated and async update option
  2502. */
  2503. if (((checkpoint->checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) ||
  2504. (checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2505. error = SA_AIS_ERR_BAD_OPERATION;
  2506. }
  2507. checkpoint->active_replica_set = 1;
  2508. res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset);
  2509. res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET;
  2510. res_lib_ckpt_activereplicaset.header.error = error;
  2511. libais_send_response (conn_info, &res_lib_ckpt_activereplicaset,
  2512. sizeof (struct res_lib_ckpt_activereplicaset));
  2513. return (0);
  2514. }
  2515. static int message_handler_req_lib_ckpt_checkpointstatusget (struct conn_info *conn_info, void *message)
  2516. {
  2517. struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)message;
  2518. struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget;
  2519. struct saCkptCheckpoint *checkpoint;
  2520. int memoryUsed = 0;
  2521. int numberOfSections = 0;
  2522. struct list_head *checkpoint_section_list;
  2523. struct saCkptCheckpointSection *checkpointSection;
  2524. log_printf (LOG_LEVEL_DEBUG, "in status get\n");
  2525. /*
  2526. * Count memory used by checkpoint sections
  2527. */
  2528. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointstatusget->checkpointName);
  2529. if (checkpoint && (checkpoint->expired == 0)) {
  2530. for (checkpoint_section_list = checkpoint->checkpointSectionsListHead.next;
  2531. checkpoint_section_list != &checkpoint->checkpointSectionsListHead;
  2532. checkpoint_section_list = checkpoint_section_list->next) {
  2533. checkpointSection = list_entry (checkpoint_section_list,
  2534. struct saCkptCheckpointSection, list);
  2535. memoryUsed += checkpointSection->sectionDescriptor.sectionSize;
  2536. numberOfSections += 1;
  2537. }
  2538. /*
  2539. * Build checkpoint status get response
  2540. */
  2541. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2542. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2543. if (checkpoint->active_replica_set == 1) {
  2544. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK;
  2545. } else {
  2546. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2547. }
  2548. memcpy (&res_lib_ckpt_checkpointstatusget.checkpointDescriptor.checkpointCreationAttributes,
  2549. &checkpoint->checkpointCreationAttributes,
  2550. sizeof (SaCkptCheckpointCreationAttributesT));
  2551. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.numberOfSections = numberOfSections;
  2552. res_lib_ckpt_checkpointstatusget.checkpointDescriptor.memoryUsed = memoryUsed;
  2553. }
  2554. else {
  2555. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint's status so Returning Error. ####\n");
  2556. res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget);
  2557. res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET;
  2558. res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST;
  2559. }
  2560. log_printf (LOG_LEVEL_DEBUG, "before sending message\n");
  2561. libais_send_response (conn_info, &res_lib_ckpt_checkpointstatusget,
  2562. sizeof (struct res_lib_ckpt_checkpointstatusget));
  2563. return (0);
  2564. }
  2565. static int message_handler_req_lib_ckpt_sectioncreate (struct conn_info *conn_info, void *message)
  2566. {
  2567. struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)message;
  2568. struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate;
  2569. struct iovec iovecs[2];
  2570. struct saCkptCheckpoint *checkpoint;
  2571. struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate;
  2572. log_printf (LOG_LEVEL_DEBUG, "Section create from API fd %d\n", conn_info->fd);
  2573. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioncreate->checkpointName);
  2574. if (checkpoint && (checkpoint->expired == 0)) {
  2575. /*
  2576. * checkpoint opened is writeable mode so send message to cluster
  2577. */
  2578. req_exec_ckpt_sectioncreate.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE;
  2579. req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate);
  2580. memcpy (&req_exec_ckpt_sectioncreate.req_lib_ckpt_sectioncreate,
  2581. req_lib_ckpt_sectioncreate,
  2582. sizeof (struct req_lib_ckpt_sectioncreate));
  2583. memcpy (&req_exec_ckpt_sectioncreate.checkpointName,
  2584. &req_lib_ckpt_sectioncreate->checkpointName,
  2585. sizeof (SaNameT));
  2586. message_source_set (&req_exec_ckpt_sectioncreate.source, conn_info);
  2587. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate;
  2588. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate);
  2589. /*
  2590. * Send section name and initial data in message
  2591. */
  2592. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate);
  2593. iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate);
  2594. req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len;
  2595. if (iovecs[1].iov_len) {
  2596. log_printf (LOG_LEVEL_DEBUG, "CKPT: message_handler_req_lib_ckpt_sectioncreate Section = %s, idLen = %d\n",
  2597. iovecs[1].iov_base,
  2598. iovecs[1].iov_len);
  2599. }
  2600. #ifdef DEBUG
  2601. printf ("LIBRARY SECTIONCREATE string is %s len is %d\n", (unsigned char *)iovecs[1].iov_base,
  2602. iovecs[1].iov_len);
  2603. printf ("|\n");
  2604. { int i;
  2605. char *abc = iovecs[1].iov_base;
  2606. for (i = 0; i < 14;i++) {
  2607. printf ("%c ", abc[i]);
  2608. }
  2609. }
  2610. printf ("|\n");
  2611. #endif
  2612. if (iovecs[1].iov_len > 0) {
  2613. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2614. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2615. } else {
  2616. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2617. }
  2618. }
  2619. else {
  2620. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to create a section in so Returning Error. ####\n");
  2621. res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate);
  2622. res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE;
  2623. res_lib_ckpt_sectioncreate.header.error = SA_AIS_ERR_NOT_EXIST;
  2624. libais_send_response (conn_info,
  2625. &res_lib_ckpt_sectioncreate,
  2626. sizeof (struct res_lib_ckpt_sectioncreate));
  2627. }
  2628. return (0);
  2629. }
  2630. static int message_handler_req_lib_ckpt_sectiondelete (struct conn_info *conn_info, void *message)
  2631. {
  2632. struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)message;
  2633. struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete;
  2634. struct iovec iovecs[2];
  2635. log_printf (LOG_LEVEL_DEBUG, "section delete from API fd %d\n", conn_info->fd);
  2636. req_exec_ckpt_sectiondelete.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE;
  2637. req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete);
  2638. memcpy (&req_exec_ckpt_sectiondelete.checkpointName,
  2639. &req_lib_ckpt_sectiondelete->checkpointName,
  2640. sizeof (SaNameT));
  2641. memcpy (&req_exec_ckpt_sectiondelete.req_lib_ckpt_sectiondelete,
  2642. req_lib_ckpt_sectiondelete,
  2643. sizeof (struct req_lib_ckpt_sectiondelete));
  2644. message_source_set (&req_exec_ckpt_sectiondelete.source, conn_info);
  2645. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete;
  2646. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete);
  2647. /*
  2648. * Send section name
  2649. */
  2650. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + sizeof (struct req_lib_ckpt_sectiondelete);
  2651. iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - sizeof (struct req_lib_ckpt_sectiondelete);
  2652. req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len;
  2653. if (iovecs[1].iov_len > 0) {
  2654. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2655. } else {
  2656. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2657. }
  2658. return (0);
  2659. }
  2660. static int message_handler_req_lib_ckpt_sectionexpirationtimeset (struct conn_info *conn_info, void *message)
  2661. {
  2662. struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)message;
  2663. struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset;
  2664. struct iovec iovecs[2];
  2665. log_printf (LOG_LEVEL_DEBUG, "section expiration time set fd=%d\n", conn_info->fd);
  2666. req_exec_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET;
  2667. req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset);
  2668. memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpointName,
  2669. &req_lib_ckpt_sectionexpirationtimeset->checkpointName,
  2670. sizeof (SaNameT));
  2671. memcpy (&req_exec_ckpt_sectionexpirationtimeset.req_lib_ckpt_sectionexpirationtimeset,
  2672. req_lib_ckpt_sectionexpirationtimeset,
  2673. sizeof (struct req_lib_ckpt_sectionexpirationtimeset));
  2674. message_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn_info);
  2675. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset;
  2676. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset);
  2677. /*
  2678. * Send section name
  2679. */
  2680. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2681. iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - sizeof (struct req_lib_ckpt_sectionexpirationtimeset);
  2682. req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len;
  2683. if (iovecs[1].iov_len > 0) {
  2684. log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base);
  2685. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2686. } else {
  2687. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2688. }
  2689. return (0);
  2690. }
  2691. int write_inv = 0;
  2692. static int message_handler_req_lib_ckpt_sectionwrite (struct conn_info *conn_info, void *message)
  2693. {
  2694. struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)message;
  2695. struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite;
  2696. struct iovec iovecs[2];
  2697. struct saCkptCheckpoint *checkpoint;
  2698. struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite;
  2699. log_printf (LOG_LEVEL_DEBUG, "CKPT: Received data from lib with len = %d and ref = 0x%x\n",
  2700. req_lib_ckpt_sectionwrite->dataSize,
  2701. req_lib_ckpt_sectionwrite->dataOffset);
  2702. log_printf (LOG_LEVEL_DEBUG, "CKPT: Checkpoint section being written to is %s, idLen = %d\n",
  2703. ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite),
  2704. req_lib_ckpt_sectionwrite->idLen);
  2705. log_printf (LOG_LEVEL_DEBUG, "Section write from API fd %d\n", conn_info->fd);
  2706. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionwrite->checkpointName);
  2707. if (checkpoint && (checkpoint->expired == 0)) {
  2708. /*
  2709. * checkpoint opened is writeable mode so send message to cluster
  2710. */
  2711. req_exec_ckpt_sectionwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE;
  2712. req_exec_ckpt_sectionwrite.header.size = sizeof (struct req_exec_ckpt_sectionwrite);
  2713. memcpy (&req_exec_ckpt_sectionwrite.req_lib_ckpt_sectionwrite,
  2714. req_lib_ckpt_sectionwrite,
  2715. sizeof (struct req_lib_ckpt_sectionwrite));
  2716. memcpy (&req_exec_ckpt_sectionwrite.checkpointName,
  2717. &req_lib_ckpt_sectionwrite->checkpointName,
  2718. sizeof (SaNameT));
  2719. message_source_set (&req_exec_ckpt_sectionwrite.source, conn_info);
  2720. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite;
  2721. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite);
  2722. /*
  2723. * Send section name and data to write in message
  2724. */
  2725. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + sizeof (struct req_lib_ckpt_sectionwrite);
  2726. iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - sizeof (struct req_lib_ckpt_sectionwrite);
  2727. req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len;
  2728. if (iovecs[1].iov_len > 0) {
  2729. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2730. } else {
  2731. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2732. }
  2733. }
  2734. else {
  2735. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to write to Returning Error. ####\n");
  2736. res_lib_ckpt_sectionwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2737. res_lib_ckpt_sectionwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE;
  2738. res_lib_ckpt_sectionwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2739. libais_send_response (conn_info,
  2740. &res_lib_ckpt_sectionwrite,
  2741. sizeof (struct res_lib_ckpt_sectionwrite));
  2742. }
  2743. return (0);
  2744. }
  2745. static int message_handler_req_lib_ckpt_sectionoverwrite (struct conn_info *conn_info, void *message)
  2746. {
  2747. struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)message;
  2748. struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite;
  2749. struct iovec iovecs[2];
  2750. struct saCkptCheckpoint *checkpoint;
  2751. struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite;
  2752. log_printf (LOG_LEVEL_DEBUG, "Section overwrite from API fd %d\n", conn_info->fd);
  2753. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionoverwrite->checkpointName);
  2754. if (checkpoint && (checkpoint->expired == 0) && (checkpoint->active_replica_set == 1)) {
  2755. /*
  2756. * checkpoint opened is writeable mode so send message to cluster
  2757. */
  2758. req_exec_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE;
  2759. req_exec_ckpt_sectionoverwrite.header.size = sizeof (struct req_exec_ckpt_sectionoverwrite);
  2760. memcpy (&req_exec_ckpt_sectionoverwrite.req_lib_ckpt_sectionoverwrite,
  2761. req_lib_ckpt_sectionoverwrite,
  2762. sizeof (struct req_lib_ckpt_sectionoverwrite));
  2763. memcpy (&req_exec_ckpt_sectionoverwrite.checkpointName,
  2764. &req_lib_ckpt_sectionoverwrite->checkpointName,
  2765. sizeof (SaNameT));
  2766. message_source_set (&req_exec_ckpt_sectionoverwrite.source, conn_info);
  2767. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite;
  2768. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite);
  2769. /*
  2770. * Send section name and data to overwrite in message
  2771. */
  2772. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + sizeof (struct req_lib_ckpt_sectionoverwrite);
  2773. iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - sizeof (struct req_lib_ckpt_sectionoverwrite);
  2774. req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len;
  2775. if (iovecs[1].iov_len > 0) {
  2776. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2777. } else {
  2778. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2779. }
  2780. }
  2781. else {
  2782. log_printf (LOG_LEVEL_ERROR, "#### CKPT: Could Not Find the Checkpoint to over write so Returning Error. ####\n");
  2783. res_lib_ckpt_sectionoverwrite.header.size = sizeof (struct res_lib_ckpt_sectionwrite);
  2784. res_lib_ckpt_sectionoverwrite.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE;
  2785. res_lib_ckpt_sectionoverwrite.header.error = SA_AIS_ERR_NOT_EXIST;
  2786. libais_send_response (conn_info,
  2787. &res_lib_ckpt_sectionoverwrite,
  2788. sizeof (struct res_lib_ckpt_sectionoverwrite));
  2789. }
  2790. return (0);
  2791. }
  2792. static int message_handler_req_lib_ckpt_sectionread (struct conn_info *conn_info, void *message)
  2793. {
  2794. struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)message;
  2795. struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread;
  2796. struct iovec iovecs[2];
  2797. struct saCkptCheckpoint *checkpoint;
  2798. struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread;
  2799. SaAisErrorT error = SA_AIS_OK;
  2800. log_printf (LOG_LEVEL_DEBUG, "Section read from API fd %d\n", conn_info->fd);
  2801. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectionread->checkpointName);
  2802. if (checkpoint && (checkpoint->expired == 0) &&
  2803. checkpoint->active_replica_set &&
  2804. req_lib_ckpt_sectionread->dataSize <=
  2805. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2806. /*
  2807. * checkpoint opened is writeable mode so send message to cluster
  2808. */
  2809. req_exec_ckpt_sectionread.header.id = MESSAGE_REQ_EXEC_CKPT_SECTIONREAD;
  2810. req_exec_ckpt_sectionread.header.size = sizeof (struct req_exec_ckpt_sectionread);
  2811. memcpy (&req_exec_ckpt_sectionread.req_lib_ckpt_sectionread,
  2812. req_lib_ckpt_sectionread,
  2813. sizeof (struct req_lib_ckpt_sectionread));
  2814. memcpy (&req_exec_ckpt_sectionread.checkpointName,
  2815. &req_lib_ckpt_sectionread->checkpointName,
  2816. sizeof (SaNameT));
  2817. message_source_set (&req_exec_ckpt_sectionread.source, conn_info);
  2818. iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread;
  2819. iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread);
  2820. /*
  2821. * Send section name and data to overwrite in message
  2822. */
  2823. iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + sizeof (struct req_lib_ckpt_sectionread);
  2824. iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - sizeof (struct req_lib_ckpt_sectionread);
  2825. req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len;
  2826. if (iovecs[1].iov_len > 0) {
  2827. assert (totempg_mcast (iovecs, 2, TOTEMPG_AGREED) == 0);
  2828. } else {
  2829. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2830. }
  2831. return (0); /* DO NOT REMOVE */
  2832. }
  2833. if (checkpoint) {
  2834. if (checkpoint->active_replica_set == 0) {
  2835. log_printf (LOG_LEVEL_DEBUG,
  2836. "sectionread - active replica not set.\n");
  2837. error = SA_AIS_ERR_NOT_EXIST;
  2838. }
  2839. if (req_lib_ckpt_sectionread->dataSize >
  2840. checkpoint->checkpointCreationAttributes.maxSectionSize) {
  2841. log_printf (LOG_LEVEL_DEBUG,
  2842. "sectionread - data size greater then max section size.\n");
  2843. error = SA_AIS_ERR_INVALID_PARAM;
  2844. }
  2845. } else {
  2846. log_printf (LOG_LEVEL_ERROR,
  2847. "sectionread - could not find checkpoint.\n");
  2848. }
  2849. res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread);
  2850. res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD;
  2851. res_lib_ckpt_sectionread.header.error = error;
  2852. libais_send_response (conn_info,
  2853. &res_lib_ckpt_sectionread,
  2854. sizeof (struct res_lib_ckpt_sectionread));
  2855. return (0);
  2856. }
  2857. static int message_handler_req_lib_ckpt_checkpointsynchronize (struct conn_info *conn_info, void *message)
  2858. {
  2859. struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)message;
  2860. struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize;
  2861. struct saCkptCheckpoint *checkpoint;
  2862. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronize->checkpointName);
  2863. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2864. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION;
  2865. } else
  2866. if (checkpoint->active_replica_set == 1) {
  2867. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK;
  2868. } else {
  2869. res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST;
  2870. }
  2871. res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize);
  2872. res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE;
  2873. libais_send_response (conn_info,
  2874. &res_lib_ckpt_checkpointsynchronize,
  2875. sizeof (struct res_lib_ckpt_checkpointsynchronize));
  2876. return (0);
  2877. }
  2878. static int message_handler_req_lib_ckpt_checkpointsynchronizeasync (struct conn_info *conn_info, void *message)
  2879. {
  2880. struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)message;
  2881. struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync;
  2882. struct saCkptCheckpoint *checkpoint;
  2883. checkpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_checkpointsynchronizeasync->checkpointName);
  2884. if ((checkpoint->checkpointCreationAttributes.creationFlags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) {
  2885. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION;
  2886. } else
  2887. if (checkpoint->active_replica_set == 1) {
  2888. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK;
  2889. } else {
  2890. res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST;
  2891. }
  2892. res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync);
  2893. res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC;
  2894. res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation;
  2895. libais_send_response (conn_info,
  2896. &res_lib_ckpt_checkpointsynchronizeasync,
  2897. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  2898. libais_send_response (conn_info->conn_info_partner,
  2899. &res_lib_ckpt_checkpointsynchronizeasync,
  2900. sizeof (struct res_lib_ckpt_checkpointsynchronizeasync));
  2901. return (0);
  2902. }
  2903. static int message_handler_req_lib_ckpt_sectioniterationinitialize (struct conn_info *conn_info, void *message)
  2904. {
  2905. struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)message;
  2906. struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize;
  2907. struct saCkptCheckpoint *ckptCheckpoint;
  2908. struct saCkptCheckpointSection *ckptCheckpointSection;
  2909. struct saCkptSectionIteratorEntry *ckptSectionIteratorEntries;
  2910. struct saCkptSectionIterator *ckptSectionIterator;
  2911. struct list_head *checkpoint_section_list;
  2912. int addEntry = 0;
  2913. int iteratorEntries = 0;
  2914. SaErrorT error = SA_AIS_OK;
  2915. log_printf (LOG_LEVEL_DEBUG, "section iterator initialize\n");
  2916. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  2917. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationinitialize->checkpointName);
  2918. if (ckptCheckpoint == 0) {
  2919. error = SA_AIS_ERR_NOT_EXIST;
  2920. goto error_exit;
  2921. }
  2922. if (ckptCheckpoint->active_replica_set == 0) {
  2923. log_printf (LOG_LEVEL_NOTICE, "iterationinitialize: no active replica, returning error.\n");
  2924. error = SA_AIS_ERR_NOT_EXIST;
  2925. goto error_exit;
  2926. }
  2927. /*
  2928. * Iterate list of checkpoint sections
  2929. */
  2930. for (checkpoint_section_list = ckptCheckpoint->checkpointSectionsListHead.next;
  2931. checkpoint_section_list != &ckptCheckpoint->checkpointSectionsListHead;
  2932. checkpoint_section_list = checkpoint_section_list->next) {
  2933. ckptCheckpointSection = list_entry (checkpoint_section_list,
  2934. struct saCkptCheckpointSection, list);
  2935. addEntry = 1;
  2936. /*
  2937. * Item should be added to iterator list
  2938. */
  2939. if (addEntry) {
  2940. iteratorEntries += 1;
  2941. ckptSectionIteratorEntries =
  2942. realloc (ckptSectionIterator->sectionIteratorEntries,
  2943. sizeof (struct saCkptSectionIteratorEntry) * iteratorEntries);
  2944. if (ckptSectionIteratorEntries == 0) {
  2945. if (ckptSectionIterator->sectionIteratorEntries) {
  2946. free (ckptSectionIterator->sectionIteratorEntries);
  2947. }
  2948. error = SA_AIS_ERR_NO_MEMORY;
  2949. goto error_exit;
  2950. }
  2951. ckptSectionIteratorEntries[iteratorEntries - 1].active = 1;
  2952. ckptSectionIteratorEntries[iteratorEntries - 1].checkpointSection = ckptCheckpointSection;
  2953. ckptSectionIterator->sectionIteratorEntries = ckptSectionIteratorEntries;
  2954. }
  2955. }
  2956. ckptSectionIterator->iteratorCount = iteratorEntries;
  2957. error_exit:
  2958. res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize);
  2959. res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORINITIALIZE;
  2960. res_lib_ckpt_sectioniterationinitialize.header.error = error;
  2961. libais_send_response (conn_info, &res_lib_ckpt_sectioniterationinitialize,
  2962. sizeof (struct res_lib_ckpt_sectioniterationinitialize));
  2963. return (0);
  2964. }
  2965. static int message_handler_req_lib_ckpt_sectioniterationfinalize (struct conn_info *conn_info, void *message)
  2966. {
  2967. struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)message;
  2968. struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize;
  2969. struct saCkptCheckpoint *ckptCheckpoint;
  2970. SaErrorT error = SA_AIS_OK;
  2971. ckptCheckpoint = ckpt_checkpoint_find_global (&req_lib_ckpt_sectioniterationfinalize->checkpointName);
  2972. if (ckptCheckpoint == 0) {
  2973. error = SA_AIS_ERR_NOT_EXIST;
  2974. goto error_exit;
  2975. }
  2976. if (ckptCheckpoint->active_replica_set == 0) {
  2977. log_printf (LOG_LEVEL_NOTICE, "iterationfinalize: no active replica, returning error.\n");
  2978. error = SA_AIS_ERR_NOT_EXIST;
  2979. goto error_exit;
  2980. }
  2981. error_exit:
  2982. res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize);
  2983. res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORFINALIZE;
  2984. res_lib_ckpt_sectioniterationfinalize.header.error = error;
  2985. libais_send_response (conn_info, &res_lib_ckpt_sectioniterationfinalize,
  2986. sizeof (struct res_lib_ckpt_sectioniterationfinalize));
  2987. return (0);
  2988. }
  2989. static int message_handler_req_lib_ckpt_sectioniteratornext (struct conn_info *conn_info, void *message)
  2990. {
  2991. struct req_lib_ckpt_sectioniteratornext *req_lib_ckpt_sectioniteratornext = (struct req_lib_ckpt_sectioniteratornext *)message;
  2992. struct res_lib_ckpt_sectioniteratornext res_lib_ckpt_sectioniteratornext;
  2993. struct saCkptSectionIterator *ckptSectionIterator;
  2994. SaErrorT error = SA_AIS_OK;
  2995. int sectionIdSize = 0;
  2996. int iteratorPos = 0;
  2997. req_lib_ckpt_sectioniteratornext = 0; /* this variable not used */
  2998. log_printf (LOG_LEVEL_DEBUG, "section iterator next\n");
  2999. ckptSectionIterator = &conn_info->ais_ci.u.libckpt_ci.sectionIterator;
  3000. /*
  3001. * Find active iterator entry
  3002. */
  3003. for (;;) {
  3004. /*
  3005. * No more sections in iterator
  3006. */
  3007. if (ckptSectionIterator->iteratorPos + 1 >= ckptSectionIterator->iteratorCount) {
  3008. error = SA_AIS_ERR_NO_SECTIONS;
  3009. goto error_exit;
  3010. }
  3011. /*
  3012. * active iterator entry
  3013. */
  3014. if (ckptSectionIterator->sectionIteratorEntries[ckptSectionIterator->iteratorPos].active == 1) {
  3015. break;
  3016. }
  3017. ckptSectionIterator->iteratorPos += 1;
  3018. }
  3019. /*
  3020. * Prepare response to API
  3021. */
  3022. iteratorPos = ckptSectionIterator->iteratorPos;
  3023. sectionIdSize = ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.idLen;
  3024. memcpy (&res_lib_ckpt_sectioniteratornext.sectionDescriptor,
  3025. &ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor,
  3026. sizeof (SaCkptSectionDescriptorT));
  3027. /*
  3028. * Get to next iterator entry
  3029. */
  3030. ckptSectionIterator->iteratorPos += 1;
  3031. error_exit:
  3032. res_lib_ckpt_sectioniteratornext.header.size = sizeof (struct res_lib_ckpt_sectioniteratornext) + sectionIdSize;
  3033. res_lib_ckpt_sectioniteratornext.header.id = MESSAGE_RES_CKPT_SECTIONITERATOR_SECTIONITERATORNEXT;
  3034. res_lib_ckpt_sectioniteratornext.header.error = error;
  3035. libais_send_response (conn_info, &res_lib_ckpt_sectioniteratornext,
  3036. sizeof (struct res_lib_ckpt_sectioniteratornext));
  3037. libais_send_response (conn_info,
  3038. ckptSectionIterator->sectionIteratorEntries[iteratorPos].checkpointSection->sectionDescriptor.sectionId.id,
  3039. sectionIdSize);
  3040. return (0);
  3041. }