4
0

ckpt.c 130 KB

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