amf.c 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778
  1. int waiting = 0;
  2. /*
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <sys/types.h>
  36. #include <sys/uio.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <sys/types.h>
  40. #include <sys/wait.h>
  41. #include <netinet/in.h>
  42. #include <arpa/inet.h>
  43. #include <unistd.h>
  44. #include <fcntl.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <errno.h>
  48. #include <signal.h>
  49. #include <string.h>
  50. #include <pthread.h>
  51. #include <assert.h>
  52. #include "../include/saAis.h"
  53. #include "../include/saAmf.h"
  54. #include "../include/ipc_gen.h"
  55. #include "../include/ipc_amf.h"
  56. #include "../include/list.h"
  57. #include "../include/queue.h"
  58. #include "../lcr/lcr_comp.h"
  59. #include "totempg.h"
  60. #include "aispoll.h"
  61. #include "mempool.h"
  62. #include "util.h"
  63. #include "amfconfig.h"
  64. #include "main.h"
  65. #include "handlers.h"
  66. #define LOG_SERVICE LOG_SERVICE_AMF
  67. #include "print.h"
  68. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  69. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  70. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  71. enum amf_message_req_types {
  72. MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET = 0,
  73. MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET = 1,
  74. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_CSI_SET = 2,
  75. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_UNIT_SET = 3,
  76. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_GROUP_SET = 4
  77. };
  78. struct invocation {
  79. void *data;
  80. int interface;
  81. int active;
  82. };
  83. struct invocation *invocation_entries = 0;
  84. int invocation_entries_size = 0;
  85. enum amf_response_interfaces {
  86. AMF_RESPONSE_HEALTHCHECKCALLBACK = 1,
  87. AMF_RESPONSE_CSISETCALLBACK = 2,
  88. AMF_RESPONSE_CSIREMOVECALLBACK = 3,
  89. AMF_RESPONSE_COMPONENTTERMINATECALLBACK = 4
  90. };
  91. struct csi_set_callback_data {
  92. struct amf_comp *comp;
  93. struct amf_csi *csi;
  94. struct amf_pg *pg;
  95. };
  96. struct csi_remove_callback_data {
  97. struct amf_csi *csi;
  98. };
  99. struct component_terminate_callback_data {
  100. struct amf_comp *comp;
  101. };
  102. struct healthcheck_active {
  103. SaAmfHealthcheckKeyT key;
  104. SaAmfHealthcheckInvocationT invocationType;
  105. SaAmfRecommendedRecoveryT recommendedRecovery;
  106. struct amf_comp *comp;
  107. struct amf_healthcheck *healthcheck;
  108. poll_timer_handle timer_healthcheck_duration;
  109. poll_timer_handle timer_healthcheck_period;
  110. struct list_head list;
  111. int active;
  112. };
  113. static char *presencestate_ntoa (OpenaisCfgPresenceStateT state);
  114. static char *operationalstate_ntoa (OpenaisCfgOperationalStateT state);
  115. static char *hastate_ntoa (SaAmfHAStateT state);
  116. static char *readinessstate_ntoa (int state);
  117. static void amf_confchg_fn (
  118. enum totem_configuration_type configuration_type,
  119. struct totem_ip_address *member_list, int member_list_entries,
  120. struct totem_ip_address *left_list, int left_list_entries,
  121. struct totem_ip_address *joined_list, int joined_list_entries,
  122. struct memb_ring_id *ring_id);
  123. static int amf_lib_exit_fn (void *conn);
  124. static int amf_exec_init_fn (struct openais_config *);
  125. static int amf_lib_init_fn (void *conn);
  126. static void message_handler_req_lib_amf_componentregister (void *conn, void *msg);
  127. static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg);
  128. static void message_handler_req_lib_amf_pmstart (void *conn, void *msg);
  129. static void message_handler_req_lib_amf_pmstop (void *conn, void *msg);
  130. static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg);
  131. static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg);
  132. static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg);
  133. static void message_handler_req_lib_amf_hastateget (void *conn, void *message);
  134. static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg);
  135. static void message_handler_req_lib_amf_protectiongrouptrackstart (void *conn, void *msg);
  136. static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg);
  137. static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg);
  138. static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg);
  139. static void message_handler_req_lib_amf_response (void *conn, void *msg);
  140. static void message_handler_req_exec_amf_operational_state_comp_set (
  141. void *message,
  142. struct totem_ip_address *source);
  143. static void message_handler_req_exec_amf_presence_state_comp_set (
  144. void *message,
  145. struct totem_ip_address *source);
  146. static void message_handler_req_exec_amf_administrative_state_csi_set (
  147. void *message,
  148. struct totem_ip_address *source);
  149. static void message_handler_req_exec_amf_administrative_state_unit_set (
  150. void *message,
  151. struct totem_ip_address *source);
  152. static void message_handler_req_exec_amf_administrative_state_group_set (
  153. void *message,
  154. struct totem_ip_address *source);
  155. void presence_state_comp_set (
  156. struct amf_comp *comp,
  157. OpenaisCfgPresenceStateT presence_state);
  158. void operational_state_comp_set (
  159. struct amf_comp *comp,
  160. OpenaisCfgOperationalStateT operational_state);
  161. void operational_state_unit_set (
  162. struct amf_unit *unit,
  163. OpenaisCfgOperationalStateT operational_state);
  164. int clc_instantiate_all (void);
  165. int clc_instantiate (struct amf_comp *comp);
  166. int clc_terminate (struct amf_comp *comp);
  167. int clc_cli_instantiate (struct amf_comp *comp);
  168. int clc_instantiate_callback (struct amf_comp *comp);
  169. int clc_csi_set_callback (struct amf_comp *comp);
  170. int clc_cli_terminate (struct amf_comp *comp);
  171. int clc_terminate_callback (struct amf_comp *comp);
  172. int clc_csi_remove_callback (struct amf_comp *comp);
  173. int clc_cli_cleanup (struct amf_comp *comp);
  174. int clc_cli_cleanup_local (struct amf_comp *comp);
  175. void healthcheck_activate (struct healthcheck_active *healthcheck_active);
  176. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active);
  177. void comp_healthcheck_activate (struct amf_comp *comp);
  178. void comp_healthcheck_deactivate (struct amf_comp *comp);
  179. static void escalation_policy_restart (struct amf_comp *comp);
  180. struct libamf_ci_trackentry {
  181. int active;
  182. SaUint8T trackFlags;
  183. SaAmfProtectionGroupNotificationT *notificationBufferAddress;
  184. SaNameT csiName;
  185. };
  186. struct amf_comp;
  187. struct amf_pd {
  188. struct amf_comp *comp;
  189. struct list_head list;
  190. /*
  191. struct libamf_ci_trackentry *tracks;
  192. int trackEntries;
  193. int trackActive;
  194. */
  195. };
  196. struct clc_interface {
  197. int (*instantiate) (struct amf_comp *comp);
  198. int (*terminate) (struct amf_comp *comp);
  199. int (*cleanup) (struct amf_comp *comp);
  200. };
  201. /*
  202. * Life cycle functions
  203. */
  204. struct clc_interface clc_interface_sa_aware = {
  205. clc_cli_instantiate,
  206. clc_terminate_callback,
  207. clc_cli_cleanup
  208. };
  209. struct clc_interface clc_interface_proxied_pre = {
  210. clc_instantiate_callback,
  211. clc_terminate_callback,
  212. clc_cli_cleanup
  213. };
  214. struct clc_interface clc_interface_proxied_non_pre = {
  215. clc_csi_set_callback,
  216. clc_csi_remove_callback,
  217. clc_cli_cleanup_local
  218. };
  219. struct clc_interface clc_interface_non_proxied_non_saware = {
  220. clc_cli_instantiate,
  221. clc_cli_terminate,
  222. clc_cli_cleanup_local
  223. };
  224. struct clc_interface *clc_interfaces[4] = {
  225. &clc_interface_sa_aware,
  226. &clc_interface_proxied_pre,
  227. &clc_interface_proxied_non_pre,
  228. &clc_interface_non_proxied_non_saware
  229. };
  230. /*
  231. * Service Handler Definition
  232. */
  233. static struct openais_lib_handler amf_lib_handlers[] =
  234. {
  235. { /* 0 */
  236. .lib_handler_fn = message_handler_req_lib_amf_componentregister,
  237. .response_size = sizeof (struct res_lib_amf_componentregister),
  238. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  239. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  240. },
  241. { /* 1 */
  242. .lib_handler_fn = message_handler_req_lib_amf_componentunregister,
  243. .response_size = sizeof (struct res_lib_amf_componentunregister),
  244. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  245. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  246. },
  247. { /* 2 */
  248. .lib_handler_fn = message_handler_req_lib_amf_pmstart,
  249. .response_size = sizeof (struct res_lib_amf_pmstart),
  250. .response_id = MESSAGE_RES_AMF_PMSTART,
  251. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  252. },
  253. { /* 3 */
  254. .lib_handler_fn = message_handler_req_lib_amf_pmstop,
  255. .response_size = sizeof (struct res_lib_amf_pmstop),
  256. .response_id = MESSAGE_RES_AMF_PMSTOP,
  257. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  258. },
  259. { /* 4 */
  260. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart,
  261. .response_size = sizeof (struct res_lib_amf_healthcheckstart),
  262. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
  263. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  264. },
  265. { /* 5 */
  266. .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
  267. .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
  268. .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
  269. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  270. },
  271. { /* 6 */
  272. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop,
  273. .response_size = sizeof (struct res_lib_amf_healthcheckstop),
  274. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
  275. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  276. },
  277. { /* 7 */
  278. .lib_handler_fn = message_handler_req_lib_amf_hastateget,
  279. .response_size = sizeof (struct res_lib_amf_hastateget),
  280. .response_id = MESSAGE_RES_AMF_HASTATEGET,
  281. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  282. },
  283. { /* 8 */
  284. .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
  285. .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
  286. .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
  287. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  288. },
  289. { /* 9 */
  290. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstart,
  291. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart),
  292. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART,
  293. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  294. },
  295. { /* 10 */
  296. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
  297. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  298. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  299. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  300. },
  301. { /* 11 */
  302. .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport,
  303. .response_size = sizeof (struct res_lib_amf_componenterrorreport),
  304. .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
  305. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  306. },
  307. { /* 12 */
  308. .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear,
  309. .response_size = sizeof (struct res_lib_amf_componenterrorclear),
  310. .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
  311. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  312. },
  313. { /* 13 */
  314. .lib_handler_fn = message_handler_req_lib_amf_response,
  315. .response_size = sizeof (struct res_lib_amf_response),
  316. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  317. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  318. },
  319. };
  320. static struct openais_exec_handler amf_exec_handlers[] = {
  321. {
  322. .exec_handler_fn = message_handler_req_exec_amf_operational_state_comp_set,
  323. },
  324. {
  325. .exec_handler_fn = message_handler_req_exec_amf_presence_state_comp_set,
  326. },
  327. {
  328. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_csi_set,
  329. },
  330. {
  331. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_unit_set,
  332. },
  333. {
  334. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_group_set
  335. }
  336. };
  337. /*
  338. * Exports the interface for the service
  339. */
  340. struct openais_service_handler amf_service_handler = {
  341. .name = (unsigned char *)"openais availability management framework B.01.01",
  342. .id = AMF_SERVICE,
  343. .private_data_size = sizeof (struct amf_pd),
  344. .lib_init_fn = amf_lib_init_fn,
  345. .lib_exit_fn = amf_lib_exit_fn,
  346. .lib_handlers = amf_lib_handlers,
  347. .lib_handlers_count = sizeof (amf_lib_handlers) / sizeof (struct openais_lib_handler),
  348. .exec_init_fn = amf_exec_init_fn,
  349. .exec_handlers = amf_exec_handlers,
  350. .exec_handlers_count = sizeof (amf_exec_handlers) / sizeof (struct openais_exec_handler),
  351. .confchg_fn = amf_confchg_fn,
  352. };
  353. struct openais_service_handler *amf_get_handler_ver0 (void);
  354. struct openais_service_handler_iface_ver0 amf_service_handler_iface = {
  355. .test = NULL,
  356. .openais_get_service_handler_ver0 = amf_get_handler_ver0
  357. };
  358. struct lcr_iface openais_amf_ver0[1] = {
  359. {
  360. .name = "openais_amf",
  361. .version = 0,
  362. .versions_replace = 0,
  363. .versions_replace_count = 0,
  364. .dependencies = 0,
  365. .dependency_count = 0,
  366. .constructor = NULL,
  367. .destructor = NULL,
  368. .interfaces = (void **)&amf_service_handler_iface,
  369. }
  370. };
  371. struct lcr_comp amf_comp_ver0 = {
  372. .iface_count = 1,
  373. .ifaces = openais_amf_ver0
  374. };
  375. struct openais_service_handler *amf_get_handler_ver0 (void)
  376. {
  377. return (&amf_service_handler);
  378. }
  379. __attribute__ ((constructor)) static void register_this_component (void) {
  380. lcr_component_register (&amf_comp_ver0);
  381. }
  382. enum clc_command_run_operation_type {
  383. CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
  384. CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
  385. CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
  386. };
  387. struct clc_command_run_data {
  388. struct amf_comp *comp;
  389. enum clc_command_run_operation_type type;
  390. void (*completion_callback) (void *context);
  391. };
  392. int invocation_create (
  393. int interface,
  394. void *data)
  395. {
  396. struct invocation *invocation_addr = 0;
  397. struct invocation *invocation_temp;
  398. int i;
  399. int loc = 0;
  400. for (i = 0; i < invocation_entries_size; i++) {
  401. if (invocation_entries[i].active == 0) {
  402. invocation_addr = &invocation_entries[i];
  403. loc = i;
  404. break;
  405. }
  406. }
  407. if (invocation_addr == 0) {
  408. invocation_temp = (struct invocation *)realloc (invocation_entries,
  409. (invocation_entries_size + 1) * sizeof (struct invocation));
  410. if (invocation_temp == 0) {
  411. return (-1);
  412. }
  413. invocation_entries = invocation_temp;
  414. invocation_addr = &invocation_entries[invocation_entries_size];
  415. loc = invocation_entries_size;
  416. invocation_entries_size += 1;
  417. }
  418. invocation_addr->interface = interface;
  419. invocation_addr->data = data;
  420. invocation_addr->active = 1;
  421. return (loc);
  422. }
  423. int invocation_get_and_destroy (int invocation, int *interface,
  424. void **data)
  425. {
  426. if (invocation > invocation_entries_size) {
  427. return (-1);
  428. }
  429. if (invocation_entries[invocation].active == 0) {
  430. return (-1);
  431. }
  432. *interface = invocation_entries[invocation].interface;
  433. *data = invocation_entries[invocation].data;
  434. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  435. return (0);
  436. }
  437. void invocation_destroy_by_data (void *data)
  438. {
  439. int i;
  440. for (i = 0; i < invocation_entries_size; i++) {
  441. if (invocation_entries[i].data == data) {
  442. memset (&invocation_entries[i], 0,
  443. sizeof (struct invocation));
  444. break;
  445. }
  446. }
  447. }
  448. void *clc_command_run (void *context)
  449. {
  450. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  451. pid_t pid;
  452. int res;
  453. char *argv[10];
  454. char *envp[10];
  455. int status;
  456. unsigned char cmd[1024];
  457. unsigned char env_comp_binary_name[1024];
  458. unsigned char env_comp_binary_path[1024];
  459. unsigned char env_comp_name[1024];
  460. unsigned char *binary_to_run = 0;
  461. unsigned char *binary_path = 0;
  462. char *clc_cli_interface;
  463. sleep (1);
  464. printf ("clc_command_run()\n");
  465. pid = fork();
  466. if (pid == -1) {
  467. printf ("Couldn't fork process %s\n", strerror (errno));
  468. return (0);
  469. }
  470. if (pid) {
  471. waiting = 1;
  472. printf ("waiting for pid %d to finish\n", pid);
  473. waitpid (pid, &status, 0);
  474. if (clc_command_run_data->completion_callback) {
  475. clc_command_run_data->completion_callback (context);
  476. }
  477. pthread_exit(0);
  478. }
  479. switch (clc_command_run_data->type) {
  480. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  481. binary_to_run = clc_command_run_data->comp->instantiate_cmd;
  482. clc_cli_interface = "CLC_CLI_INTERFACE=instantiate";
  483. break;
  484. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  485. binary_to_run = clc_command_run_data->comp->terminate_cmd;
  486. clc_cli_interface = "CLC_CLI_INTERFACE=terminate";
  487. break;
  488. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  489. binary_to_run = clc_command_run_data->comp->cleanup_cmd;
  490. clc_cli_interface = "CLC_CLI_INTERFACE=cleanup";
  491. break;
  492. default:
  493. assert (0 != 1);
  494. break;
  495. }
  496. if (strlen (clc_command_run_data->comp->clccli_path)) {
  497. sprintf (cmd, "%s/%s",
  498. clc_command_run_data->comp->clccli_path,
  499. binary_to_run);
  500. } else
  501. if (strlen (clc_command_run_data->comp->unit->clccli_path)) {
  502. sprintf (cmd, "%s/%s",
  503. clc_command_run_data->comp->unit->clccli_path,
  504. binary_to_run);
  505. } else {
  506. sprintf (cmd, "%s/%s",
  507. clc_command_run_data->comp->unit->amf_group->clccli_path,
  508. binary_to_run);
  509. }
  510. if (strlen (clc_command_run_data->comp->binary_path)) {
  511. binary_path = clc_command_run_data->comp->binary_path;
  512. } else
  513. if (strlen (clc_command_run_data->comp->unit->binary_path)) {
  514. binary_path = clc_command_run_data->comp->unit->binary_path;
  515. } else {
  516. binary_path = clc_command_run_data->comp->unit->amf_group->binary_path;
  517. }
  518. argv[0] = cmd;
  519. argv[1] = '\0';
  520. envp[0] = cmd;
  521. envp[1] = clc_cli_interface;
  522. envp[2] = env_comp_binary_name;
  523. envp[3] = env_comp_binary_path;
  524. envp[4] = env_comp_name;
  525. envp[5] = '\0';
  526. sprintf (env_comp_binary_name, "COMP_BINARY_NAME=%s",
  527. clc_command_run_data->comp->binary_name);
  528. sprintf (env_comp_binary_path, "COMP_BINARY_PATH=%s",
  529. binary_path);
  530. strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME=");
  531. strncat (env_comp_name, clc_command_run_data->comp->name.value,
  532. clc_command_run_data->comp->name.length);
  533. if (cmd[0] == '\0') {
  534. return (0);
  535. }
  536. printf ("running command '%s' with environment:\n", cmd);
  537. printf ("0 %s\n", envp[0]);
  538. printf ("1 %s\n", envp[1]);
  539. printf ("2 %s\n", envp[2]);
  540. printf ("3 %s\n", envp[3]);
  541. printf ("4 %s\n", envp[4]);
  542. res = execve (cmd, argv, envp);
  543. if (res == -1) {
  544. printf ("Couldn't exec process %d=%s\n", errno, strerror (errno));
  545. }
  546. assert (res != -1);
  547. return (0);
  548. }
  549. struct req_exec_amf_operational_state_comp_set {
  550. struct req_header header;
  551. SaNameT name;
  552. OpenaisCfgOperationalStateT operational_state;
  553. };
  554. struct req_exec_amf_presence_state_comp_set {
  555. struct req_header header;
  556. SaNameT name;
  557. OpenaisCfgPresenceStateT presence_state;
  558. };
  559. struct req_exec_amf_administrative_state_csi_set {
  560. struct req_header header;
  561. SaNameT name;
  562. OpenaisCfgAdministrativeStateT presence_state;
  563. };
  564. struct req_exec_amf_administrative_state_unit_set {
  565. struct req_header header;
  566. SaNameT name;
  567. OpenaisCfgAdministrativeStateT presence_state;
  568. };
  569. struct req_exec_amf_administrative_state_group_set {
  570. struct req_header header;
  571. SaNameT name;
  572. OpenaisCfgAdministrativeStateT presence_state;
  573. };
  574. struct req_exec_amf_comp_restart {
  575. struct req_header header;
  576. SaNameT compName;
  577. };
  578. /*
  579. * Instantiate possible operations
  580. */
  581. int clc_cli_instantiate (struct amf_comp *comp)
  582. {
  583. int res;
  584. pthread_t thread;
  585. struct clc_command_run_data *clc_command_run_data;
  586. printf ("clc_cli_instaniate\n");
  587. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  588. clc_command_run_data->comp = comp;
  589. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  590. clc_command_run_data->completion_callback = NULL;
  591. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  592. pthread_detach (thread);
  593. // TODO error code from pthread_create
  594. return (res);
  595. }
  596. int clc_instantiate_callback (struct amf_comp *comp)
  597. {
  598. printf ("clc_instantiate_callback\n");
  599. return (0);
  600. }
  601. int clc_csi_set_callback (struct amf_comp *comp)
  602. {
  603. printf ("clc_csi_set_callback\n");
  604. return (0);
  605. }
  606. /*
  607. * Terminate possible operations
  608. */
  609. int clc_cli_terminate (struct amf_comp *comp)
  610. {
  611. printf ("clc_cli_terminate\n");
  612. return (0);
  613. }
  614. int clc_terminate_callback (struct amf_comp *comp)
  615. {
  616. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  617. struct component_terminate_callback_data *component_terminate_callback_data;
  618. printf ("clc_terminate_callback %p\n", comp->conn);
  619. if (comp->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  620. printf ("component terminated but not instantiated %s - %d\n",
  621. getSaNameT (&comp->name), comp->presence_state);
  622. assert (0);
  623. return (0);
  624. }
  625. printf ("component name terminating %s\n", getSaNameT (&comp->name));
  626. printf ("component presence state %d\n", comp->presence_state);
  627. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  628. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  629. res_lib_amf_componentterminatecallback.header.error = SA_AIS_OK;
  630. memcpy (&res_lib_amf_componentterminatecallback.compName,
  631. &comp->name, sizeof (SaNameT));
  632. component_terminate_callback_data =
  633. malloc (sizeof (struct component_terminate_callback_data));
  634. assert (component_terminate_callback_data); // TODO failure here of malloc
  635. component_terminate_callback_data->comp = comp;
  636. res_lib_amf_componentterminatecallback.invocation =
  637. invocation_create (
  638. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  639. component_terminate_callback_data);
  640. printf ("Creating invocation %llu",
  641. (unsigned long long)res_lib_amf_componentterminatecallback.invocation);
  642. openais_conn_send_response (
  643. openais_conn_partner_get (comp->conn),
  644. &res_lib_amf_componentterminatecallback,
  645. sizeof (struct res_lib_amf_componentterminatecallback));
  646. return (0);
  647. }
  648. int clc_csi_remove_callback (struct amf_comp *comp)
  649. {
  650. printf ("clc_tcsi_remove_callback\n");
  651. return (0);
  652. }
  653. /*
  654. * This reinstantiates the cleaned up component
  655. */
  656. void clc_cleanup_completion_callback (void *context) {
  657. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  658. escalation_policy_restart (clc_command_run_data->comp);
  659. }
  660. /*
  661. * Cleanup possible operations
  662. */
  663. int clc_cli_cleanup (struct amf_comp *comp)
  664. {
  665. int res;
  666. pthread_t thread;
  667. struct clc_command_run_data *clc_command_run_data;
  668. printf ("clc_cli_instaniate\n");
  669. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  670. clc_command_run_data->comp = comp;
  671. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  672. clc_command_run_data->completion_callback = clc_cleanup_completion_callback;
  673. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  674. pthread_detach (thread);
  675. // TODO error code from pthread_create
  676. return (res);
  677. return (0);
  678. }
  679. int clc_cli_cleanup_local (struct amf_comp *comp)
  680. {
  681. printf ("clc_cli_cleanup_local\n");
  682. return (0);
  683. }
  684. int clc_instantiate (struct amf_comp *comp)
  685. {
  686. int res;
  687. printf ("clc instantiate for comp %s\n", getSaNameT (&comp->name));
  688. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_INSTANTIATING);
  689. res = clc_interfaces[comp->comptype]->instantiate (comp);
  690. return (res);
  691. }
  692. int clc_terminate (struct amf_comp *comp)
  693. {
  694. int res;
  695. printf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  696. assert (0);
  697. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  698. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  699. res = clc_interfaces[comp->comptype]->terminate (comp);
  700. return (0);
  701. }
  702. int clc_cleanup (struct amf_comp *comp)
  703. {
  704. int res;
  705. printf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
  706. comp_healthcheck_deactivate (comp);
  707. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  708. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  709. res = clc_interfaces[comp->comptype]->cleanup (comp);
  710. return (0);
  711. }
  712. /* IMPL */
  713. static int amf_exec_init_fn (struct openais_config *openais_config)
  714. {
  715. if (openais_config->amf_enabled) {
  716. clc_instantiate_all ();
  717. }
  718. return (0);
  719. }
  720. static void amf_confchg_fn (
  721. enum totem_configuration_type configuration_type,
  722. struct totem_ip_address *member_list, int member_list_entries,
  723. struct totem_ip_address *left_list, int left_list_entries,
  724. struct totem_ip_address *joined_list, int joined_list_entries,
  725. struct memb_ring_id *ring_id)
  726. {
  727. #ifdef COMPILE_OUT
  728. int i;
  729. log_printf (LOG_LEVEL_FROM_GMI, "Executive: amf_confchg_fn : type = %d,mnum = %d,jnum = %d,lnum = %d\n", configuration_type,member_list_entries,joined_list_entries,left_list_entries);
  730. recovery = 1;
  731. /*
  732. * If node join, component register
  733. */
  734. if ( joined_list_entries > 0 ) {
  735. enumerate_components (amf_confchg_njoin, NULL);
  736. }
  737. /*
  738. * If node leave, component unregister
  739. */
  740. for (i = 0; i<left_list_entries ; i++) {
  741. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  742. }
  743. #ifdef TODO
  744. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  745. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  746. recovery = 0;
  747. }
  748. #endif
  749. #endif
  750. }
  751. int amf_lib_exit_fn (void *conn)
  752. {
  753. struct amf_comp *comp;
  754. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  755. comp = amf_pd->comp;
  756. if (comp) {
  757. comp->conn = 0;
  758. printf ("setting in exit fn to uninst for comp %p\n", comp);
  759. presence_state_comp_set (
  760. comp,
  761. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  762. operational_state_comp_set (
  763. comp,
  764. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  765. comp_healthcheck_deactivate (comp);
  766. }
  767. return (0);
  768. }
  769. static int amf_lib_init_fn (void *conn)
  770. {
  771. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize availability management framework service.\n");
  772. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  773. list_init (&amf_pd->list);
  774. return (0);
  775. }
  776. #ifdef COMPILE_OUT
  777. static void amf_synchronize (void *message, struct in_addr source_addr)
  778. {
  779. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  780. struct amf_comp *component;
  781. struct amf_comp *amfProxyComponent;
  782. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  783. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  784. /* Find Component */
  785. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  786. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  787. /* If this processor is component owner */
  788. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  789. /* No Operation */
  790. return;
  791. }
  792. /* If this isn't synchronizing target processor */
  793. if (!(component->local == 0 && component->registered == 0)){
  794. /* No Operation */
  795. return;
  796. }
  797. /* Synchronize Status */
  798. component->local = 0;
  799. component->registered = 1;
  800. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  801. component->source_addr = source_addr;
  802. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  803. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  804. component->currentHAState = SA_AMF_QUIESCED;
  805. component->newHAState = SA_AMF_QUIESCED;
  806. component->probableCause = 0;
  807. component->enabledUnlockedState = 0;
  808. component->disabledUnlockedState = 0;
  809. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  810. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  811. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  812. component->newHAState = req_exec_amf_componentregister->newHAState;
  813. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  814. component->saAmfProxyComponent = amfProxyComponent;
  815. }
  816. /*
  817. * Determine if we should enter new state
  818. */
  819. dsmSynchronizeStaus (component);
  820. return;
  821. }
  822. #endif
  823. DECLARE_LIST_INIT (library_notification_send_listhead);
  824. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  825. static void protectiongroup_notifications_send (
  826. struct amf_comp *changedComponent,
  827. SaAmfProtectionGroupChangesT changeToComponent)
  828. {
  829. #ifdef COMPILE_OUT
  830. int i;
  831. struct conn_info *conn_info;
  832. struct list_head *list;
  833. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  834. /*
  835. * Iterate all tracked connections
  836. */
  837. for (list = library_notification_send_listhead.next;
  838. list != &library_notification_send_listhead;
  839. list = list->next) {
  840. conn_info = list_entry (list, struct conn_info, conn_list);
  841. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  842. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  843. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  844. != changedComponent->amf_pg->name.length) {
  845. continue;
  846. }
  847. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  848. changedComponent->amf_pg->name.value,
  849. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  850. continue;
  851. }
  852. #ifdef COMPILE_OUT
  853. protectiongroup_notification_send (conn_info,
  854. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  855. changedComponent->saAmfProtectionGroup,
  856. changedComponent,
  857. changeToComponent,
  858. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  859. #endif
  860. } /* if track flags active */
  861. } /* for all track entries */
  862. } /* for all connection entries */
  863. #endif
  864. }
  865. static int make_protectiongroup_notification_allcomponent (
  866. struct amf_comp *changedComponent,
  867. SaAmfProtectionGroupChangesT changeToComponent,
  868. SaAmfProtectionGroupNotificationT **notification )
  869. {
  870. #ifdef COMPILE_OUT
  871. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  872. int notifyEntries = 0;
  873. struct amf_comp *component;
  874. struct list_head *AmfGroupList;
  875. struct list_head *AmfUnitList;
  876. struct list_head *AmfComponentList;
  877. struct saAmfGroup *saAmfGroup;
  878. struct saAmfUnit *AmfUnit;
  879. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  880. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  881. /*
  882. * Search all units
  883. */
  884. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  885. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  886. AmfUnitList = AmfUnitList->next) {
  887. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  888. /*
  889. * Search all components
  890. */
  891. for (AmfComponentList = AmfUnit->amf_compHead.next;
  892. AmfComponentList != &AmfUnit->amf_compHead;
  893. AmfComponentList = AmfComponentList->next) {
  894. component = list_entry (AmfComponentList, struct amf_comp, amf_compList);
  895. protectionGroupNotification =
  896. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  897. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  898. memset (&protectionGroupNotification[notifyEntries],
  899. 0,sizeof (SaAmfProtectionGroupNotificationT));
  900. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  901. &component->name, sizeof (SaNameT));
  902. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  903. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  904. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  905. &component->currentHAState, sizeof (SaAmfHAStateT));
  906. if (component == changedComponent) {
  907. protectionGroupNotification[notifyEntries].change = changeToComponent;
  908. } else {
  909. protectionGroupNotification[notifyEntries].change
  910. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  911. }
  912. notifyEntries += 1;
  913. }
  914. }
  915. }
  916. if (notifyEntries) {
  917. *notification = protectionGroupNotification;
  918. }
  919. return (notifyEntries);
  920. #endif
  921. return (0);
  922. }
  923. #ifdef COMPILE_OUT
  924. static int make_protectiongroup_notification (
  925. struct saAmfProtectionGroup *amfProtectionGroup,
  926. struct amf_comp *changedComponent,
  927. SaAmfProtectionGroupChangesT changeToComponent,
  928. SaAmfProtectionGroupNotificationT **notification )
  929. {
  930. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  931. int notifyEntries = 0;
  932. struct amf_comp *component;
  933. struct list_head *componentList;
  934. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  935. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  936. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  937. componentList != &amfProtectionGroup->saAmfMembersHead;
  938. componentList = componentList->next) {
  939. component = list_entry (componentList, struct amf_comp, saAmfProtectionGroupList);
  940. protectionGroupNotification =
  941. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  942. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  943. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  944. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  945. &component->name, sizeof (SaNameT));
  946. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  947. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  948. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  949. &component->currentHAState, sizeof (SaAmfHAStateT));
  950. if (component == changedComponent) {
  951. protectionGroupNotification[notifyEntries].change = changeToComponent;
  952. } else {
  953. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  954. }
  955. notifyEntries += 1;
  956. } /* for */
  957. if (notifyEntries) {
  958. *notification = protectionGroupNotification;
  959. }
  960. return (notifyEntries);
  961. return (0);
  962. }
  963. #endif
  964. #ifdef COMPILE_OUT
  965. static void protectiongroup_notification_send (struct conn_info *conn_info,
  966. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  967. struct saAmfProtectionGroup *amfProtectionGroup,
  968. struct amf_comp *changedComponent,
  969. SaAmfProtectionGroupChangesT changeToComponent,
  970. SaUint8T trackFlags)
  971. {
  972. //struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  973. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  974. int notifyEntries;
  975. /*
  976. * Step through all components and generate protection group list for csi
  977. */
  978. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  979. if ( trackFlags == SA_TRACK_CHANGES ) {
  980. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  981. changeToComponent, &protectionGroupNotification);
  982. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  983. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  984. changedComponent, changeToComponent, &protectionGroupNotification );
  985. }else{
  986. notifyEntries = 0;
  987. }
  988. /*
  989. * Send track callback
  990. */
  991. if (notifyEntries) {
  992. res_lib_amf_protectiongrouptrackcallback.header.size =
  993. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  994. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  995. // res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  996. res_lib_amf_protectiongrouptrackcallback.header.error = SA_AIS_OK;
  997. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  998. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  999. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1000. &amfProtectionGroup->name, sizeof (SaNameT));
  1001. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1002. openais_conn_send_response (conno, &res_lib_amf_protectiongrouptrackcallback,
  1003. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1004. openais_conn_send_response (conno, protectionGroupNotification,
  1005. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1006. mempool_free (protectionGroupNotification);
  1007. }
  1008. }
  1009. static void error_report (struct amf_comp *comp)
  1010. {
  1011. struct req_exec_amf_error_report req_exec_amf_error_report;
  1012. struct iovec iovec;
  1013. req_exec_amf_error_report.header.size = sizeof (struct req_exec_amf_error_report);
  1014. req_exec_amf_error_report.header.id =
  1015. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERROR_REPORT);
  1016. memcpy (&req_exec_amf_error_report.compName,
  1017. &comp->name,
  1018. sizeof (SaNameT));
  1019. iovec.iov_base = (char *)&req_exec_amf_error_report;
  1020. iovec.iov_len = sizeof (req_exec_amf_error_report);
  1021. assert (totempg_groups_mcast_joined (openais_group_handle,
  1022. &iovec, 1, TOTEMPG_AGREED) == 0);
  1023. }
  1024. static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp)
  1025. {
  1026. struct req_exec_amf_comp_restart req_exec_amf_comp_restart;
  1027. struct iovec iovec;
  1028. req_exec_amf_comp_restart.header.size = sizeof (struct req_exec_amf_comp_restart);
  1029. req_exec_amf_comp_restart.header.id =
  1030. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_UNIT_RESTART);
  1031. memcpy (&req_exec_amf_comp_restart.compName, &comp->name,
  1032. sizeof (SaNameT));
  1033. iovec.iov_base = (char *)&req_exec_amf_comp_restart;
  1034. iovec.iov_len = sizeof (req_exec_amf_comp_restart);
  1035. assert (totempg_groups_mcast_joined (openais_group_handle,
  1036. &iovec, 1, TOTEMPG_AGREED) == 0);
  1037. }
  1038. #endif
  1039. #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL
  1040. struct healthcheck_active *find_healthcheck_active (
  1041. struct amf_comp *comp,
  1042. SaAmfHealthcheckKeyT *key,
  1043. SaAmfHealthcheckInvocationT invocation)
  1044. {
  1045. struct list_head *list;
  1046. struct healthcheck_active *ret_healthcheck_active = 0;
  1047. struct healthcheck_active *healthcheck_active;
  1048. for (list = comp->healthcheck_list.next;
  1049. list != &comp->healthcheck_list;
  1050. list = list->next) {
  1051. healthcheck_active = list_entry (list,
  1052. struct healthcheck_active, list);
  1053. if ((memcmp (key, &healthcheck_active->key,
  1054. sizeof (SaAmfHealthcheckKeyT)) == 0) &&
  1055. (invocation == INVOCATION_DONT_COMPARE ||
  1056. healthcheck_active->invocationType == invocation)) {
  1057. ret_healthcheck_active = healthcheck_active;
  1058. break;
  1059. }
  1060. }
  1061. return (ret_healthcheck_active);
  1062. }
  1063. void comp_healthcheck_activate (
  1064. struct amf_comp *comp)
  1065. {
  1066. struct list_head *key_list;
  1067. struct healthcheck_active *healthcheck_active;
  1068. for (key_list = comp->healthcheck_list.next;
  1069. key_list != &comp->healthcheck_list;
  1070. key_list = key_list->next) {
  1071. healthcheck_active = list_entry (key_list,
  1072. struct healthcheck_active, list);
  1073. if (healthcheck_active->active == 0) {
  1074. healthcheck_activate (healthcheck_active);
  1075. }
  1076. }
  1077. }
  1078. void comp_healthcheck_deactivate (
  1079. struct amf_comp *comp)
  1080. {
  1081. struct list_head *list;
  1082. struct list_head *next;
  1083. struct healthcheck_active *healthcheck_active;
  1084. log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n",
  1085. getSaNameT (&comp->name));
  1086. for (list = comp->healthcheck_list.next, next = list->next;
  1087. list != &comp->healthcheck_list;
  1088. list = next, next = list->next) {
  1089. healthcheck_active = list_entry (list,
  1090. struct healthcheck_active, list);
  1091. printf ("healthcheck deactivating %p\n", healthcheck_active);
  1092. healthcheck_deactivate (healthcheck_active);
  1093. }
  1094. }
  1095. void presence_state_comp_set (
  1096. struct amf_comp *comp,
  1097. OpenaisCfgPresenceStateT presence_state)
  1098. {
  1099. struct req_exec_amf_presence_state_comp_set req_exec_amf_presence_state_comp_set;
  1100. struct iovec iovec;
  1101. req_exec_amf_presence_state_comp_set.header.size = sizeof (struct req_exec_amf_presence_state_comp_set);
  1102. req_exec_amf_presence_state_comp_set.header.id =
  1103. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET);
  1104. req_exec_amf_presence_state_comp_set.presence_state = presence_state;
  1105. memcpy (&req_exec_amf_presence_state_comp_set.name,
  1106. &comp->name,
  1107. sizeof (SaNameT));
  1108. iovec.iov_base = (char *)&req_exec_amf_presence_state_comp_set;
  1109. iovec.iov_len = sizeof (req_exec_amf_presence_state_comp_set);
  1110. assert (totempg_groups_mcast_joined (openais_group_handle,
  1111. &iovec, 1, TOTEMPG_AGREED) == 0);
  1112. }
  1113. void readiness_state_comp_set (struct amf_comp *comp)
  1114. {
  1115. printf ("inputs to readiness_state_comp_set\n");
  1116. printf ("\tunit readiness state %s\n",
  1117. readinessstate_ntoa (comp->unit->readiness_state));
  1118. printf ("\tcomp operational state %s\n",
  1119. operationalstate_ntoa (comp->unit->readiness_state));
  1120. /*
  1121. * Set component readiness state appropriately
  1122. * if unit in service and component is enabled, it is in service
  1123. * otherwise it is out of service page 37
  1124. */
  1125. if (comp->unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1126. comp->operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1127. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_INSERVICE;
  1128. } else {
  1129. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE;
  1130. }
  1131. printf ("readiness_state_comp_set (%s)\n",
  1132. operationalstate_ntoa (comp->operational_state));
  1133. }
  1134. void operational_state_comp_set (struct amf_comp *comp, OpenaisCfgOperationalStateT operational_state)
  1135. {
  1136. struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set;
  1137. struct iovec iovec;
  1138. req_exec_amf_operational_state_comp_set.header.size = sizeof (struct req_exec_amf_operational_state_comp_set);
  1139. req_exec_amf_operational_state_comp_set.header.id =
  1140. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET);
  1141. req_exec_amf_operational_state_comp_set.operational_state = operational_state;
  1142. memcpy (&req_exec_amf_operational_state_comp_set.name,
  1143. &comp->name,
  1144. sizeof (SaNameT));
  1145. iovec.iov_base = (char *)&req_exec_amf_operational_state_comp_set;
  1146. iovec.iov_len = sizeof (req_exec_amf_operational_state_comp_set);
  1147. assert (totempg_groups_mcast_joined (openais_group_handle,
  1148. &iovec, 1, TOTEMPG_AGREED) == 0);
  1149. }
  1150. void csi_comp_set_callback (
  1151. struct amf_comp *comp,
  1152. struct amf_csi *csi,
  1153. struct amf_pg *pg)
  1154. {
  1155. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  1156. struct csi_set_callback_data *csi_set_callback_data;
  1157. printf ("\t%s\n",
  1158. getSaNameT (&comp->name));
  1159. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1160. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  1161. res_lib_amf_csisetcallback.header.error = SA_AIS_OK;
  1162. memcpy (&res_lib_amf_csisetcallback.compName,
  1163. &comp->name, sizeof (SaNameT));
  1164. memcpy (&res_lib_amf_csisetcallback.csiDescriptor.csiName,
  1165. &csi->name, sizeof (SaNameT));
  1166. res_lib_amf_csisetcallback.haState = comp->unit->requested_ha_state;
  1167. csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data));
  1168. assert (csi_set_callback_data); // TODO failure here of malloc
  1169. csi_set_callback_data->comp = comp;
  1170. csi_set_callback_data->csi = csi;
  1171. csi_set_callback_data->pg = pg;
  1172. printf ("pg is %p\n", pg);
  1173. res_lib_amf_csisetcallback.invocation =
  1174. invocation_create (
  1175. AMF_RESPONSE_CSISETCALLBACK,
  1176. csi_set_callback_data);
  1177. openais_conn_send_response (
  1178. openais_conn_partner_get (comp->conn),
  1179. &res_lib_amf_csisetcallback,
  1180. sizeof (struct res_lib_amf_csisetcallback));
  1181. }
  1182. void pg_create (struct amf_si *si, struct amf_pg **pg_out)
  1183. {
  1184. struct amf_pg *pg;
  1185. // struct amf_pg_comp *pg_comp;
  1186. pg = malloc (sizeof (struct amf_pg));
  1187. assert (pg);
  1188. list_init (&pg->pg_comp_head);
  1189. list_init (&pg->pg_list);
  1190. list_add (&pg->pg_list, &si->pg_head);
  1191. *pg_out = pg;
  1192. }
  1193. void csi_unit_set_callback (struct amf_csi *csi_in)
  1194. {
  1195. struct list_head *list;
  1196. struct amf_comp *comp;
  1197. struct amf_pg *pg;
  1198. pg_create (csi_in->si, &pg);
  1199. // TODO remove si from csi data structure
  1200. printf ("assigning CSI %s to ",
  1201. getSaNameT (&csi_in->name));
  1202. printf ("SU %s for components:\n",
  1203. getSaNameT (&csi_in->unit->name));
  1204. for (list = csi_in->unit->comp_head.next;
  1205. list != &csi_in->unit->comp_head;
  1206. list = list->next) {
  1207. comp = list_entry (list,
  1208. struct amf_comp, comp_list);
  1209. csi_comp_set_callback (comp, csi_in, pg);
  1210. }
  1211. }
  1212. void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
  1213. {
  1214. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  1215. struct csi_remove_callback_data *csi_remove_callback_data;
  1216. printf ("\t%s\n",
  1217. getSaNameT (&comp->name));
  1218. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1219. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1220. res_lib_amf_csiremovecallback.header.error = SA_AIS_OK;
  1221. csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
  1222. assert (csi_remove_callback_data); // TODO failure here of malloc
  1223. csi_remove_callback_data->csi = csi;
  1224. res_lib_amf_csiremovecallback.invocation =
  1225. invocation_create (
  1226. AMF_RESPONSE_CSIREMOVECALLBACK,
  1227. csi_remove_callback_data);
  1228. memcpy (&res_lib_amf_csiremovecallback.compName,
  1229. &comp->name, sizeof (SaNameT));
  1230. memcpy (&res_lib_amf_csiremovecallback.csiName,
  1231. &csi->name, sizeof (SaNameT));
  1232. res_lib_amf_csiremovecallback.csiFlags = 0;
  1233. openais_conn_send_response (
  1234. openais_conn_partner_get (comp->conn),
  1235. &res_lib_amf_csiremovecallback,
  1236. sizeof (struct res_lib_amf_csiremovecallback));
  1237. }
  1238. extern struct list_head amf_groupHead;
  1239. int clc_instantiate_all (void) {
  1240. struct list_head *list_group;
  1241. struct amf_group *group;
  1242. struct list_head *list_unit;
  1243. struct amf_unit *unit;
  1244. struct list_head *list_comp;
  1245. struct amf_comp *comp;
  1246. for (list_group = amf_groupHead.next;
  1247. list_group != &amf_groupHead;
  1248. list_group = list_group->next) {
  1249. group = list_entry (list_group,
  1250. struct amf_group, group_list);
  1251. for (list_unit = group->unit_head.next;
  1252. list_unit != &group->unit_head;
  1253. list_unit = list_unit->next) {
  1254. unit = list_entry (list_unit,
  1255. struct amf_unit, unit_list);
  1256. for (list_comp = unit->comp_head.next;
  1257. list_comp != &unit->comp_head;
  1258. list_comp = list_comp->next) {
  1259. comp = list_entry (list_comp,
  1260. struct amf_comp, comp_list);
  1261. if (strlen ((char *)comp->instantiate_cmd)) {
  1262. clc_instantiate (comp);
  1263. }
  1264. }
  1265. }
  1266. }
  1267. return (0);
  1268. }
  1269. void comp_terminate (struct amf_comp *comp)
  1270. {
  1271. clc_terminate (comp);
  1272. }
  1273. void unit_terminate (struct amf_unit *unit)
  1274. {
  1275. struct list_head *list_comp;
  1276. struct amf_comp *comp;
  1277. for (list_comp = unit->comp_head.next;
  1278. list_comp != &unit->comp_head;
  1279. list_comp = list_comp->next) {
  1280. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1281. clc_terminate (comp);
  1282. }
  1283. }
  1284. void comp_cleanup (struct amf_comp *comp)
  1285. {
  1286. clc_cleanup (comp);
  1287. }
  1288. void unit_cleanup (struct amf_unit *unit)
  1289. {
  1290. struct list_head *list_comp;
  1291. struct amf_comp *comp;
  1292. for (list_comp = unit->comp_head.next;
  1293. list_comp != &unit->comp_head;
  1294. list_comp = list_comp->next) {
  1295. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1296. clc_cleanup (comp);
  1297. }
  1298. }
  1299. void comp_restart (struct amf_comp *comp)
  1300. {
  1301. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1302. }
  1303. void unit_restart (struct amf_unit *unit)
  1304. {
  1305. struct list_head *list_comp;
  1306. struct amf_comp *comp;
  1307. for (list_comp = unit->comp_head.next;
  1308. list_comp != &unit->comp_head;
  1309. list_comp = list_comp->next) {
  1310. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1311. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1312. }
  1313. }
  1314. void clc_unit_instantiate (struct amf_unit *unit)
  1315. {
  1316. struct list_head *list_comp;
  1317. struct amf_comp *comp;
  1318. printf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
  1319. for (list_comp = unit->comp_head.next;
  1320. list_comp != &unit->comp_head;
  1321. list_comp = list_comp->next) {
  1322. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1323. clc_instantiate (comp);
  1324. }
  1325. }
  1326. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1327. {
  1328. struct list_head *list_si;
  1329. struct list_head *list_csi;
  1330. struct list_head *list_comp;
  1331. struct amf_si *si;
  1332. struct amf_csi *csi;
  1333. struct amf_comp *comp;
  1334. for (list_si = unit->si_head.next;
  1335. list_si != &unit->si_head;
  1336. list_si = list_si->next) {
  1337. si = list_entry (list_si, struct amf_si, unit_list);
  1338. for (list_csi = si->csi_head.next;
  1339. list_csi != &si->csi_head;
  1340. list_csi = list_csi->next) {
  1341. csi = list_entry (list_csi, struct amf_csi, list);
  1342. for (list_comp = csi->unit->comp_head.next;
  1343. list_comp != &csi->unit->comp_head;
  1344. list_comp = list_comp->next) {
  1345. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1346. }
  1347. }
  1348. }
  1349. }
  1350. // THIS MIGHT BE GOOD FOR SOMEPTHING ELSE
  1351. #ifdef COMPILE_OUT
  1352. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1353. {
  1354. struct list_head *list_comp;
  1355. struct list_head *list_si;
  1356. struct list_head *list_csi;
  1357. struct list_head *list_pg;
  1358. struct list_head *list_pg_comp;
  1359. struct amf_comp *comp;
  1360. struct amf_csi *csi;
  1361. struct amf_si *si;
  1362. struct amf_pg *pg;
  1363. struct amf_pg_comp *pg_comp;
  1364. for (list_si = unit->si_head.next;
  1365. list_si != &unit->si_head;
  1366. list_si = list_si->next) {
  1367. si = list_entry (list_si, struct amf_si, unit_list);
  1368. for (list_pg = si->pg_head.next;
  1369. list_pg != &si->pg_head;
  1370. list_pg = list_pg->next) {
  1371. pg = list_entry (list_pg, struct amf_pg, pg_list);
  1372. printf ("pg %x\n", pg);
  1373. for (list_pg_comp = pg->pg_comp_head.next;
  1374. list_pg_comp != &pg->pg_comp_head;
  1375. list_pg_comp = list_pg_comp->next) {
  1376. pg_comp = list_entry (list_pg_comp,
  1377. struct amf_pg_comp, list);
  1378. printf ("pg_comp %x\n", pg_comp);
  1379. printf ("remove component callback\n");
  1380. csi_comp_remove_callback (
  1381. pg_comp->comp,
  1382. pg_comp->csi);
  1383. }
  1384. }
  1385. }
  1386. }
  1387. #endif
  1388. char csi_number = 0;
  1389. void csi_unit_create (struct amf_unit *unit, struct amf_si *si,
  1390. struct amf_csi **csi_out)
  1391. {
  1392. struct amf_csi *csi;
  1393. printf ("creating csi for si %p unit %p\n", si, unit);
  1394. si->csi_count += 1;
  1395. csi = malloc (sizeof (struct amf_csi));
  1396. list_init (&csi->list);
  1397. list_init (&csi->csi_list);
  1398. list_add (&csi->list, &si->csi_head);
  1399. list_add (&si->unit_list, &unit->si_head);
  1400. csi->si = si;
  1401. csi->unit = unit;
  1402. csi->pg_set = 0;
  1403. sprintf ((char *)csi->name.value, "CSI %d", csi_number);
  1404. csi->name.length = strlen ((char *)csi->name.value);
  1405. csi_number += 1;
  1406. *csi_out = csi;
  1407. }
  1408. void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si,
  1409. SaAmfHAStateT ha_state)
  1410. {
  1411. struct amf_csi *csi;
  1412. printf ("Assigning SI %s ", getSaNameT (&si->name));
  1413. printf ("to SU %s ", getSaNameT (&unit->name));
  1414. printf ("with hastate %s\n", hastate_ntoa (ha_state));
  1415. unit->requested_ha_state = ha_state;
  1416. csi_unit_create (unit, si, &csi);
  1417. csi_unit_set_callback (csi);
  1418. }
  1419. int unit_inservice_count (struct amf_group *group)
  1420. {
  1421. struct list_head *list;
  1422. struct amf_unit *unit;
  1423. int answer = 0;
  1424. for (list = group->unit_head.next;
  1425. list != &group->unit_head;
  1426. list = list->next) {
  1427. unit = list_entry (list,
  1428. struct amf_unit, unit_list);
  1429. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1430. answer += 1;
  1431. }
  1432. }
  1433. return (answer);
  1434. }
  1435. int comp_inservice_count (struct amf_unit *unit)
  1436. {
  1437. struct list_head *list;
  1438. struct amf_comp *comp;
  1439. int answer = 0;
  1440. for (list = unit->comp_head.next;
  1441. list != &unit->comp_head;
  1442. list = list->next) {
  1443. comp = list_entry (list, struct amf_comp, comp_list);
  1444. if (comp->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1445. answer += 1;
  1446. }
  1447. }
  1448. return (answer);
  1449. }
  1450. int si_count (struct amf_group *group)
  1451. {
  1452. struct list_head *list_si;
  1453. struct amf_si *si;
  1454. int answer = 0;
  1455. for (list_si = group->si_head.next;
  1456. list_si != &group->si_head;
  1457. list_si = list_si->next) {
  1458. si = list_entry (list_si,
  1459. struct amf_si, list);
  1460. answer += 1;
  1461. }
  1462. return (answer);
  1463. }
  1464. static inline int div_round (int a, int b)
  1465. {
  1466. int res;
  1467. res = a / b;
  1468. if ((a % b) != 0)
  1469. res++;
  1470. return res;
  1471. }
  1472. void assign_nm_active (struct amf_group *group, int su_units_assign)
  1473. {
  1474. struct amf_unit *unit;
  1475. struct amf_si *si;
  1476. struct list_head *list_si;
  1477. struct list_head *list_unit;
  1478. int assigned = 0;
  1479. int assign_per_su = 0;
  1480. int total_assigned = 0;
  1481. assign_per_su = si_count (group);
  1482. assign_per_su = div_round (assign_per_su, su_units_assign);
  1483. if (assign_per_su > group->maximum_active_instances) {
  1484. assign_per_su = group->maximum_active_instances;
  1485. }
  1486. list_si = group->si_head.next;
  1487. list_unit = group->unit_head.next;
  1488. while (list_unit != &group->unit_head) {
  1489. unit = list_entry (list_unit,
  1490. struct amf_unit, unit_list);
  1491. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1492. list_unit = list_unit->next;
  1493. continue; /* Not in service */
  1494. }
  1495. assigned = 0;
  1496. while (list_si != &group->si_head &&
  1497. assigned < assign_per_su &&
  1498. total_assigned < si_count (group)) {
  1499. si = list_entry (list_si, struct amf_si, list);
  1500. assigned += 1;
  1501. total_assigned += 1;
  1502. ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
  1503. list_si = list_si->next;
  1504. }
  1505. list_unit = list_unit->next;
  1506. }
  1507. }
  1508. void assign_nm_standby (struct amf_group *group, int units_assign_standby)
  1509. {
  1510. struct amf_unit *unit;
  1511. struct amf_si *si;
  1512. struct list_head *list_si;
  1513. struct list_head *list_unit;
  1514. int assigned = 0;
  1515. int assign_per_su = 0;
  1516. if (units_assign_standby == 0) {
  1517. return;
  1518. }
  1519. assign_per_su = si_count (group);
  1520. assign_per_su = div_round (assign_per_su, units_assign_standby);
  1521. if (assign_per_su > group->maximum_standby_instances) {
  1522. assign_per_su = group->maximum_standby_instances;
  1523. }
  1524. list_si = group->si_head.next;
  1525. list_unit = group->unit_head.next;
  1526. while (list_unit != &group->unit_head) {
  1527. unit = list_entry (list_unit,
  1528. struct amf_unit, unit_list);
  1529. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE ||
  1530. unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1531. list_unit = list_unit->next;
  1532. continue; /* Not available for assignment */
  1533. }
  1534. assigned = 0;
  1535. while (list_si != &group->si_head && assigned < assign_per_su) {
  1536. si = list_entry (list_si, struct amf_si, list);
  1537. assigned += 1;
  1538. ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1539. list_si = list_si->next;
  1540. }
  1541. list_unit = list_unit->next;
  1542. }
  1543. }
  1544. void assign_nm_spare (struct amf_group *group)
  1545. {
  1546. struct amf_unit *unit;
  1547. struct list_head *list;
  1548. for (list = group->unit_head.next;
  1549. list != &group->unit_head;
  1550. list = list->next) {
  1551. unit = list_entry (list,
  1552. struct amf_unit, unit_list);
  1553. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1554. (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
  1555. unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
  1556. printf ("Assigning to SU %s with SPARE\n",
  1557. getSaNameT (&unit->name));
  1558. }
  1559. }
  1560. }
  1561. void clear_requested_ha_state (struct amf_group *group)
  1562. {
  1563. struct list_head *list;
  1564. struct amf_unit *unit;
  1565. for (list = group->unit_head.next;
  1566. list != &group->unit_head;
  1567. list = list->next) {
  1568. unit = list_entry (list,
  1569. struct amf_unit, unit_list);
  1570. unit->requested_ha_state = 0;
  1571. }
  1572. csi_number = 0;
  1573. }
  1574. void assign_sis (struct amf_group *group)
  1575. {
  1576. int active_sus_needed;
  1577. int standby_sus_needed;
  1578. int inservice_count;
  1579. int units_for_standby;
  1580. int units_for_active;
  1581. int ii_spare;
  1582. int su_active_assign;
  1583. int su_standby_assign;
  1584. int su_spare_assign;
  1585. clear_requested_ha_state (group);
  1586. /*
  1587. * Number of SUs to assign to active or standby state
  1588. */
  1589. inservice_count = (float)unit_inservice_count (group);
  1590. active_sus_needed = div_round (si_count(group),
  1591. group->maximum_active_instances);
  1592. standby_sus_needed = div_round (si_count(group),
  1593. group->maximum_standby_instances);
  1594. units_for_active = inservice_count - group->preferred_standby_units;
  1595. if (units_for_active < 0) {
  1596. units_for_active = 0;
  1597. }
  1598. units_for_standby = inservice_count - group->preferred_active_units;
  1599. if (units_for_standby < 0) {
  1600. units_for_standby = 0;
  1601. }
  1602. ii_spare = inservice_count - group->preferred_active_units - group->preferred_standby_units;
  1603. if (ii_spare < 0) {
  1604. ii_spare = 0;
  1605. }
  1606. /*
  1607. * Determine number of active and standby service units
  1608. * to assign based upon reduction procedure
  1609. */
  1610. if ((inservice_count - active_sus_needed) < 0) {
  1611. printf ("assignment VI - partial assignment with SIs drop outs\n");
  1612. su_active_assign = active_sus_needed;
  1613. su_standby_assign = 0;
  1614. su_spare_assign = 0;
  1615. } else
  1616. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  1617. printf ("assignment V - partial assignment with reduction of standby units\n");
  1618. su_active_assign = active_sus_needed;
  1619. if (standby_sus_needed > units_for_standby) {
  1620. su_standby_assign = units_for_standby;
  1621. } else {
  1622. su_standby_assign = standby_sus_needed;
  1623. }
  1624. su_spare_assign = 0;
  1625. } else
  1626. if ((group->maximum_standby_instances * units_for_standby) <= si_count (group)) {
  1627. printf ("IV: full assignment with reduction of active service units\n");
  1628. su_active_assign = inservice_count - standby_sus_needed;
  1629. su_standby_assign = standby_sus_needed;
  1630. su_spare_assign = 0;
  1631. } else
  1632. if ((group->maximum_active_instances * units_for_active) <= si_count (group)) {
  1633. printf ("III: full assignment with reduction of standby service units\n");
  1634. su_active_assign = group->preferred_active_units;
  1635. su_standby_assign = units_for_standby;
  1636. su_spare_assign = 0;
  1637. } else
  1638. if (ii_spare == 0) {
  1639. printf ("II: full assignment with spare reduction\n");
  1640. su_active_assign = group->preferred_active_units;
  1641. su_standby_assign = group->preferred_standby_units;
  1642. su_spare_assign = 0;
  1643. } else {
  1644. printf ("I: full assignment with spares\n");
  1645. su_active_assign = group->preferred_active_units;
  1646. su_standby_assign = group->preferred_standby_units;
  1647. su_spare_assign = ii_spare;
  1648. }
  1649. printf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
  1650. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1651. assign_nm_active (group, su_active_assign);
  1652. assign_nm_standby (group, su_standby_assign);
  1653. }
  1654. void readiness_state_unit_set (struct amf_unit *unit, OpenaisCfgReadinessStateT readiness_state)
  1655. {
  1656. printf ("Assigning unit %s ",
  1657. getSaNameT (&unit->name));
  1658. printf ("readiness state %s\n",
  1659. readinessstate_ntoa (readiness_state));
  1660. unit->readiness_state = readiness_state;
  1661. assign_sis (unit->amf_group);
  1662. }
  1663. void presence_state_unit_set (struct amf_unit *unit, OpenaisCfgPresenceStateT presence_state)
  1664. {
  1665. printf ("Setting service unit presence state %s\n",
  1666. presencestate_ntoa (presence_state));
  1667. }
  1668. static void escalation_policy_restart (struct amf_comp *comp)
  1669. {
  1670. printf ("escalation_policy_restart %d\n", comp->unit->escalation_level);
  1671. printf ("escalation policy restart uninsint %p\n", comp);
  1672. presence_state_comp_set (
  1673. comp,
  1674. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  1675. operational_state_comp_set (
  1676. comp,
  1677. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1678. switch (comp->unit->escalation_level) {
  1679. case ESCALATION_LEVEL_NO_ESCALATION:
  1680. comp_restart (comp);
  1681. break;
  1682. case ESCALATION_LEVEL_ONE:
  1683. comp_restart (comp);
  1684. break;
  1685. case ESCALATION_LEVEL_TWO:
  1686. break;
  1687. case ESCALATION_LEVEL_THREE:
  1688. break;
  1689. }
  1690. }
  1691. static void escalation_policy_cleanup (struct amf_comp *comp)
  1692. {
  1693. // escalation_timer_start (comp);
  1694. switch (comp->unit->escalation_level) {
  1695. case ESCALATION_LEVEL_NO_ESCALATION:
  1696. comp->unit->restart_count += 1;
  1697. if (comp->unit->restart_count >= comp->unit->amf_group->component_restart_max) {
  1698. comp->unit->escalation_level = ESCALATION_LEVEL_ONE;
  1699. escalation_policy_cleanup (comp);
  1700. comp->unit->restart_count = 0;
  1701. return;
  1702. }
  1703. printf ("Escalation level 0 - restart component\n");
  1704. printf ("Cleaning up and restarting component.\n");
  1705. comp_cleanup (comp);
  1706. break;
  1707. case ESCALATION_LEVEL_ONE:
  1708. comp->unit->restart_count += 1;
  1709. if (comp->unit->restart_count >= comp->unit->amf_group->unit_restart_max) {
  1710. comp->unit->escalation_level = ESCALATION_LEVEL_TWO;
  1711. escalation_policy_cleanup (comp);
  1712. return;
  1713. }
  1714. printf ("Escalation level 1 - restart unit\n");
  1715. printf ("Cleaning up and restarting unit.\n");
  1716. unit_cleanup (comp->unit);
  1717. break;
  1718. case ESCALATION_LEVEL_TWO:
  1719. printf ("Escalation level TWO\n");
  1720. unit_cleanup (comp->unit);
  1721. // unit_terminate_failover (comp);
  1722. break;
  1723. case ESCALATION_LEVEL_THREE:
  1724. //TODO
  1725. break;
  1726. }
  1727. }
  1728. static void timer_function_healthcheck_timeout (
  1729. void *data)
  1730. {
  1731. struct healthcheck_active *healthcheck_active =
  1732. (struct healthcheck_active *)data;
  1733. printf ("timeout occured on healthcheck for component %s.\n",
  1734. getSaNameT (&healthcheck_active->comp->name));
  1735. escalation_policy_cleanup (healthcheck_active->comp);
  1736. }
  1737. void healthcheck_activate (struct healthcheck_active *healthcheck_active)
  1738. {
  1739. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1740. healthcheck_active->active = 1;
  1741. // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1742. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1743. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1744. res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
  1745. log_printf (LOG_LEVEL_NOTICE, "sending healthcheck to component %s\n",
  1746. getSaNameT (&healthcheck_active->comp->name));
  1747. res_lib_amf_healthcheckcallback.invocation =
  1748. invocation_create (
  1749. AMF_RESPONSE_HEALTHCHECKCALLBACK,
  1750. (void *)healthcheck_active);
  1751. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1752. &healthcheck_active->comp->name,
  1753. sizeof (SaNameT));
  1754. memcpy (&res_lib_amf_healthcheckcallback.key,
  1755. &healthcheck_active->key,
  1756. sizeof (SaAmfHealthcheckKeyT));
  1757. openais_conn_send_response (
  1758. openais_conn_partner_get (healthcheck_active->comp->conn),
  1759. &res_lib_amf_healthcheckcallback,
  1760. sizeof (struct res_lib_amf_healthcheckcallback));
  1761. poll_timer_delete (aisexec_poll_handle,
  1762. healthcheck_active->timer_healthcheck_duration);
  1763. poll_timer_add (aisexec_poll_handle,
  1764. healthcheck_active->healthcheck->maximum_duration,
  1765. (void *)healthcheck_active,
  1766. timer_function_healthcheck_timeout,
  1767. &healthcheck_active->timer_healthcheck_duration);
  1768. }
  1769. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active)
  1770. {
  1771. log_printf (LOG_LEVEL_NOTICE, "ZZZ deactivating healthcheck for component %s\n",
  1772. getSaNameT (&healthcheck_active->comp->name));
  1773. poll_timer_delete (aisexec_poll_handle,
  1774. healthcheck_active->timer_healthcheck_period);
  1775. poll_timer_delete (aisexec_poll_handle,
  1776. healthcheck_active->timer_healthcheck_duration);
  1777. invocation_destroy_by_data ((void *)healthcheck_active);
  1778. list_del (&healthcheck_active->list);
  1779. free (healthcheck_active);
  1780. }
  1781. static void timer_function_healthcheck_next (
  1782. void *data)
  1783. {
  1784. healthcheck_activate (data);
  1785. }
  1786. void healthcheck_unit_deactivate (
  1787. struct amf_unit *unit)
  1788. {
  1789. struct list_head *list;
  1790. struct list_head *key_list;
  1791. struct healthcheck_active *healthcheck_active;
  1792. struct amf_comp *comp;
  1793. for (list = unit->comp_head.next;
  1794. list != &unit->comp_head;
  1795. list = list->next) {
  1796. comp = list_entry (list, struct amf_comp, comp_list);
  1797. for (key_list = comp->healthcheck_list.next;
  1798. key_list != &comp->healthcheck_list;
  1799. key_list = key_list->next) {
  1800. healthcheck_active = list_entry (key_list,
  1801. struct healthcheck_active, list);
  1802. healthcheck_deactivate (healthcheck_active);
  1803. }
  1804. }
  1805. }
  1806. void healthcheck_unit_activate (
  1807. struct amf_unit *unit)
  1808. {
  1809. struct list_head *list;
  1810. struct list_head *key_list;
  1811. struct healthcheck_active *healthcheck_active;
  1812. struct amf_comp *comp;
  1813. for (list = unit->comp_head.next;
  1814. list != &unit->comp_head;
  1815. list = list->next) {
  1816. comp = list_entry (list, struct amf_comp, comp_list);
  1817. for (key_list = comp->healthcheck_list.next;
  1818. key_list != &comp->healthcheck_list;
  1819. key_list = key_list->next) {
  1820. healthcheck_active = list_entry (key_list,
  1821. struct healthcheck_active, list);
  1822. healthcheck_activate (healthcheck_active);
  1823. }
  1824. }
  1825. }
  1826. void operational_state_unit_set (
  1827. struct amf_unit *unit,
  1828. OpenaisCfgOperationalStateT operational_state)
  1829. {
  1830. if (operational_state == unit->operational_state) {
  1831. printf ("Not assigning service unit new operational state - same state\n");
  1832. return;
  1833. }
  1834. unit->operational_state = operational_state;
  1835. printf ("Service unit operational state set to %s\n",
  1836. operationalstate_ntoa (operational_state));
  1837. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1838. readiness_state_unit_set (unit,
  1839. OPENAIS_CFG_READINESSSTATE_INSERVICE);
  1840. /*
  1841. * Start healthcheck now
  1842. */
  1843. // TODO healthcheck_unit_activate (unit);
  1844. } else
  1845. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_DISABLED) {
  1846. readiness_state_unit_set (unit,
  1847. OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE);
  1848. // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1849. // healthcheck_unit_deactivate (unit);
  1850. }
  1851. }
  1852. static void message_handler_req_exec_amf_operational_state_comp_set (
  1853. void *message,
  1854. struct totem_ip_address *address)
  1855. {
  1856. struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
  1857. (struct req_exec_amf_operational_state_comp_set *)message;
  1858. struct amf_comp *comp;
  1859. struct amf_comp *comp_compare;
  1860. struct list_head *list;
  1861. int all_set = 1;
  1862. comp = find_comp (&req_exec_amf_operational_state_comp_set->name);
  1863. comp->operational_state = req_exec_amf_operational_state_comp_set->operational_state;
  1864. printf ("Setting component %s operational state to %s\n",
  1865. getSaNameT (&comp->name),
  1866. operationalstate_ntoa (comp->operational_state));
  1867. /*
  1868. * If all operational states are ENABLED, then SU should be ENABLED
  1869. */
  1870. for (list = comp->unit->comp_head.next;
  1871. list != &comp->unit->comp_head;
  1872. list = list->next) {
  1873. comp_compare = list_entry (list,
  1874. struct amf_comp, comp_list);
  1875. if (comp_compare->operational_state != OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1876. all_set = 0;
  1877. break;
  1878. }
  1879. }
  1880. if (all_set) {
  1881. operational_state_unit_set (comp->unit,
  1882. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1883. } else {
  1884. operational_state_unit_set (comp->unit,
  1885. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1886. }
  1887. readiness_state_comp_set (comp);
  1888. }
  1889. static void message_handler_req_exec_amf_presence_state_comp_set (
  1890. void *message,
  1891. struct totem_ip_address *address)
  1892. {
  1893. struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
  1894. (struct req_exec_amf_presence_state_comp_set *)message;
  1895. struct amf_comp *comp;
  1896. struct amf_comp *comp_compare;
  1897. struct list_head *list;
  1898. int all_set = 1;
  1899. comp = find_comp (&req_exec_amf_presence_state_comp_set->name);
  1900. if (req_exec_amf_presence_state_comp_set->presence_state == comp->presence_state) {
  1901. printf ("duplicate presence state set, not setting presence state\n");
  1902. return;
  1903. }
  1904. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1905. comp->conn = 0;
  1906. }
  1907. /*
  1908. * The restarting state can only be entered from the uninstantiated state
  1909. */
  1910. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING &&
  1911. comp->presence_state != OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1912. printf ("restart presence state set even though not in terminating state\n");
  1913. return;
  1914. }
  1915. comp->presence_state = req_exec_amf_presence_state_comp_set->presence_state;
  1916. if (comp->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING) {
  1917. printf ("SET TO RESTARTING instantiating now\n");
  1918. clc_instantiate (comp);
  1919. }
  1920. printf ("Setting component %s presence state %s\n",
  1921. getSaNameT (&comp->name),
  1922. presencestate_ntoa (comp->presence_state));
  1923. /*
  1924. * Restart components that are requested to enter the restarting presence state
  1925. */
  1926. /*
  1927. * If all comp presence states are INSTANTIATED, then SU should be instantated
  1928. */
  1929. for (list = comp->unit->comp_head.next;
  1930. list != &comp->unit->comp_head;
  1931. list = list->next) {
  1932. comp_compare = list_entry (list,
  1933. struct amf_comp, comp_list);
  1934. if (comp_compare->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  1935. all_set = 0;
  1936. break;
  1937. }
  1938. }
  1939. if (all_set) {
  1940. presence_state_unit_set (comp->unit,
  1941. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1942. }
  1943. }
  1944. static void message_handler_req_exec_amf_administrative_state_csi_set (
  1945. void *message,
  1946. struct totem_ip_address *address)
  1947. {
  1948. // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
  1949. // (struct req_exec_amf_administrative_state_csi_set *)message;
  1950. // TODO
  1951. }
  1952. static void message_handler_req_exec_amf_administrative_state_unit_set (
  1953. void *message,
  1954. struct totem_ip_address *address)
  1955. {
  1956. // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
  1957. // (struct req_exec_amf_administrative_state_unit_set *)message;
  1958. // TODO
  1959. }
  1960. static void message_handler_req_exec_amf_administrative_state_group_set (
  1961. void *message,
  1962. struct totem_ip_address *source)
  1963. {
  1964. // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
  1965. // (struct req_exec_amf_administrative_state_group_set *)message;
  1966. // TODO
  1967. }
  1968. /*
  1969. * Library Interface Implementation
  1970. */
  1971. static void message_handler_req_lib_amf_componentregister (
  1972. void *conn,
  1973. void *msg)
  1974. {
  1975. struct req_lib_amf_componentregister *req_lib_amf_componentregister =
  1976. (struct req_lib_amf_componentregister *)msg;
  1977. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1978. struct amf_comp *comp;
  1979. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  1980. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  1981. comp = find_comp (&req_lib_amf_componentregister->compName);
  1982. if (comp) {
  1983. presence_state_comp_set (comp,
  1984. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1985. operational_state_comp_set (comp,
  1986. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1987. comp->conn = conn;
  1988. amf_pd->comp = comp;
  1989. comp_healthcheck_activate (comp);
  1990. error = SA_AIS_OK;
  1991. }
  1992. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1993. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1994. res_lib_amf_componentregister.header.error = error;
  1995. openais_conn_send_response (conn, &res_lib_amf_componentregister,
  1996. sizeof (struct res_lib_amf_componentregister));
  1997. }
  1998. static void message_handler_req_lib_amf_componentunregister (
  1999. void *conn,
  2000. void *msg)
  2001. {
  2002. #ifdef COMPILE_OUT
  2003. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2004. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2005. struct iovec iovec;
  2006. struct amf_comp *component;
  2007. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  2008. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2009. req_exec_amf_componentunregister.header.id =
  2010. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2011. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2012. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2013. req_lib_amf_componentunregister,
  2014. sizeof (struct req_lib_amf_componentunregister));
  2015. component = find_comp (&req_lib_amf_componentunregister->compName);
  2016. if (component && component->registered && component->local) {
  2017. // component->probableCause = SA_AMF_NOT_RESPONDING;
  2018. }
  2019. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2020. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2021. assert (totempg_groups_mcast_joined (openais_group_handle,
  2022. &iovec, 1, TOTEMPG_AGREED) == 0);
  2023. #endif
  2024. }
  2025. static void message_handler_req_lib_amf_pmstart (
  2026. void *conn,
  2027. void *msg)
  2028. {
  2029. }
  2030. static void message_handler_req_lib_amf_pmstop (
  2031. void *conn,
  2032. void *msg)
  2033. {
  2034. }
  2035. static void message_handler_req_lib_amf_healthcheckstart (
  2036. void *conn, void *msg)
  2037. {
  2038. struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
  2039. (struct req_lib_amf_healthcheckstart *)msg;
  2040. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  2041. struct amf_healthcheck *healthcheck;
  2042. struct healthcheck_active *healthcheck_active;
  2043. struct amf_comp *comp;
  2044. SaAisErrorT error = SA_AIS_OK;
  2045. printf ("healthcheck start\n");
  2046. fflush (stdout);
  2047. healthcheck = find_healthcheck (&req_lib_amf_healthcheckstart->healthcheckKey);
  2048. if (healthcheck == 0) {
  2049. error = SA_AIS_ERR_NOT_EXIST;
  2050. }
  2051. comp = find_comp (&req_lib_amf_healthcheckstart->compName);
  2052. if (comp == 0) {
  2053. error = SA_AIS_ERR_NOT_EXIST;
  2054. goto error_exit;
  2055. }
  2056. /*
  2057. * Determine if this healthcheck is already active
  2058. */
  2059. healthcheck_active = find_healthcheck_active (
  2060. comp,
  2061. &req_lib_amf_healthcheckstart->healthcheckKey,
  2062. req_lib_amf_healthcheckstart->invocationType);
  2063. if (healthcheck_active) {
  2064. error = SA_AIS_ERR_EXIST;
  2065. goto error_exit;
  2066. }
  2067. healthcheck_active = malloc (sizeof (struct healthcheck_active));
  2068. if (healthcheck_active == 0) {
  2069. error = SA_AIS_ERR_NO_MEMORY;
  2070. goto error_exit;
  2071. }
  2072. /*
  2073. * Make new instance of healthcheck key
  2074. */
  2075. list_init (&healthcheck_active->list);
  2076. memcpy (&healthcheck_active->key,
  2077. &req_lib_amf_healthcheckstart->healthcheckKey,
  2078. sizeof (SaAmfHealthcheckKeyT));
  2079. healthcheck_active->comp = comp;
  2080. healthcheck_active->invocationType = req_lib_amf_healthcheckstart->invocationType;
  2081. healthcheck_active->healthcheck = healthcheck;
  2082. healthcheck_active->timer_healthcheck_duration = 0;
  2083. healthcheck_active->timer_healthcheck_period = 0;
  2084. healthcheck_active->active = 0;
  2085. list_add_tail (&healthcheck_active->list, &comp->healthcheck_list);
  2086. if (comp->conn != 0) {
  2087. printf ("Activating healthcheck for the first time %p\n", healthcheck_active);
  2088. healthcheck_activate (healthcheck_active);
  2089. }
  2090. #ifdef TODO
  2091. do we want to do healtchecking only when full su has registered or also of non-fully registered sus
  2092. if (comp->unit->operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  2093. /*
  2094. * Start healthcheck now
  2095. */
  2096. healthcheck_unit_activate (comp->unit);
  2097. }
  2098. #endif
  2099. error_exit:
  2100. res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  2101. res_lib_amf_healthcheckstart.header.size = sizeof (struct res_lib_amf_healthcheckstart);
  2102. res_lib_amf_healthcheckstart.header.error = error;
  2103. openais_conn_send_response (conn, &res_lib_amf_healthcheckstart,
  2104. sizeof (struct res_lib_amf_healthcheckstart));
  2105. }
  2106. static void message_handler_req_lib_amf_healthcheckconfirm (
  2107. void *conn,
  2108. void *msg)
  2109. {
  2110. }
  2111. static void message_handler_req_lib_amf_healthcheckstop (
  2112. void *conn,
  2113. void *msg)
  2114. {
  2115. struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop =
  2116. (struct req_lib_amf_healthcheckstop *)msg;
  2117. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  2118. struct healthcheck_active *healthcheck_active;
  2119. struct amf_comp *comp;
  2120. SaAisErrorT error = SA_AIS_OK;
  2121. printf ("healthcheck stop\n");
  2122. comp = find_comp (&req_lib_amf_healthcheckstop->compName);
  2123. if (comp == 0) {
  2124. error = SA_AIS_ERR_NOT_EXIST;
  2125. goto error_exit;
  2126. }
  2127. healthcheck_active = find_healthcheck_active (
  2128. comp,
  2129. &req_lib_amf_healthcheckstop->healthcheckKey,
  2130. INVOCATION_DONT_COMPARE);
  2131. printf ("active %p\n", healthcheck_active);
  2132. if (healthcheck_active == 0) {
  2133. error = SA_AIS_ERR_NOT_EXIST;
  2134. goto error_exit;
  2135. }
  2136. healthcheck_deactivate (healthcheck_active);
  2137. error_exit:
  2138. printf ("healthcheck stop\n");
  2139. res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  2140. res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop);
  2141. res_lib_amf_healthcheckstop.header.error = error;
  2142. openais_conn_send_response (conn, &res_lib_amf_healthcheckstop,
  2143. sizeof (struct res_lib_amf_healthcheckstop));
  2144. }
  2145. static void message_handler_req_lib_amf_hastateget (
  2146. void *conn,
  2147. void *msg)
  2148. {
  2149. #ifdef COMPILE_OUT
  2150. struct req_lib_amf_hastateget *req_lib_amf_hastateget = (struct req_lib_amf_hastateget *)msg;
  2151. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2152. struct amf_comp *component;
  2153. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_hastateget()\n");
  2154. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2155. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2156. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2157. #ifdef COMPILE_OUT
  2158. component = component_in_protectiongroup_find (&req_lib_amf_hastateget->csiName, &req_lib_amf_hastateget->compName);
  2159. #endif
  2160. if (component) {
  2161. memcpy (&res_lib_amf_hastateget.haState,
  2162. &component->currentHAState, sizeof (SaAmfHAStateT));
  2163. res_lib_amf_hastateget.header.error = SA_AIS_OK;
  2164. }
  2165. openais_conn_send_response (conn, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2166. #endif
  2167. }
  2168. static void message_handler_req_lib_amf_protectiongrouptrackstart (
  2169. void *conn,
  2170. void *msg)
  2171. {
  2172. #ifdef COMPILE_OUT
  2173. struct req_lib_amf_protectiongrouptrackstart *req_lib_amf_protectiongrouptrackstart = (struct req_lib_amf_protectiongrouptrackstart *)message;
  2174. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2175. struct libamf_ci_trackentry *track = 0;
  2176. int i;
  2177. struct saAmfProtectionGroup *amfProtectionGroup;
  2178. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstart()\n");
  2179. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrackstart->csiName);
  2180. if (amfProtectionGroup) {
  2181. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrackstart->csiName));
  2182. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2183. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2184. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2185. break;
  2186. }
  2187. }
  2188. if (track == 0) {
  2189. grow_amf_track_table (conn_info, 1);
  2190. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2191. }
  2192. track->active = 1;
  2193. track->trackFlags = req_lib_amf_protectiongrouptrackstart->trackFlags;
  2194. track->notificationBufferAddress = req_lib_amf_protectiongrouptrackstart->notificationBufferAddress;
  2195. memcpy (&track->csiName,
  2196. &req_lib_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2197. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2198. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2199. /*
  2200. * If SA_TRACK_CURRENT is specified, write out all current connections
  2201. */
  2202. } else {
  2203. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2204. }
  2205. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2206. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2207. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2208. if (amfProtectionGroup) {
  2209. res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK;
  2210. }
  2211. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstart,
  2212. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2213. if (amfProtectionGroup &&
  2214. req_lib_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2215. protectiongroup_notification_send (conn_info,
  2216. track->notificationBufferAddress,
  2217. amfProtectionGroup,
  2218. 0,
  2219. 0,
  2220. SA_TRACK_CHANGES_ONLY);
  2221. track->trackFlags &= ~SA_TRACK_CURRENT;
  2222. }
  2223. #endif
  2224. }
  2225. static void message_handler_req_lib_amf_csiquiescingcomplete (
  2226. void *conn,
  2227. void *msg)
  2228. {
  2229. }
  2230. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  2231. void *conn,
  2232. void *msg)
  2233. {
  2234. #ifdef COMPILE_OUT
  2235. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  2236. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2237. struct libamf_ci_trackentry *track = 0;
  2238. int i;
  2239. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  2240. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2241. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  2242. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2243. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2244. }
  2245. }
  2246. if (track) {
  2247. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  2248. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2249. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2250. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2251. list_del (&conn_info->conn_list);
  2252. }
  2253. }
  2254. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2255. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2256. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2257. if (track) {
  2258. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  2259. }
  2260. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  2261. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2262. #endif
  2263. }
  2264. static void message_handler_req_lib_amf_componenterrorreport (
  2265. void *conn,
  2266. void *msg)
  2267. {
  2268. struct req_lib_amf_componenterrorreport *req_lib_amf_componenterrorreport = (struct req_lib_amf_componenterrorreport *)msg;
  2269. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2270. struct amf_comp *comp;
  2271. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2272. log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n");
  2273. printf ("ERROR REPORT\n");
  2274. comp = find_comp (&req_lib_amf_componenterrorreport->erroneousComponent);
  2275. if (comp) {
  2276. printf ("escalation policy terminate\n");
  2277. escalation_policy_cleanup (comp);
  2278. error = SA_AIS_OK;
  2279. }
  2280. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2281. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2282. res_lib_amf_componenterrorreport.header.error = error;
  2283. openais_conn_send_response (
  2284. conn, &res_lib_amf_componenterrorreport,
  2285. sizeof (struct res_lib_amf_componenterrorreport));
  2286. }
  2287. static void message_handler_req_lib_amf_componenterrorclear (
  2288. void *conn,
  2289. void *msg)
  2290. {
  2291. #ifdef COMPILLE_OUT
  2292. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  2293. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  2294. struct iovec iovec;
  2295. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  2296. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  2297. req_exec_amf_componenterrorclear.header.id =
  2298. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  2299. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  2300. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  2301. req_lib_amf_componenterrorclear,
  2302. sizeof (struct req_lib_amf_componenterrorclear));
  2303. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  2304. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  2305. assert (totempg_groups_mcast_joined (openais_group_handle,
  2306. &iovec, 1, TOTEMPG_AGREED) == 0);
  2307. #endif
  2308. }
  2309. void pg_comp_create (
  2310. struct amf_pg *pg,
  2311. struct amf_csi *csi,
  2312. struct amf_comp *comp)
  2313. {
  2314. struct amf_pg_comp *pg_comp;
  2315. printf ("creating component for pg\n");
  2316. pg_comp = malloc (sizeof (struct amf_pg_comp));
  2317. assert (pg_comp);
  2318. pg_comp->comp = comp;
  2319. pg_comp->csi = csi;
  2320. list_init (&pg_comp->list);
  2321. list_add_tail (&pg_comp->list, &pg->pg_comp_head);
  2322. }
  2323. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  2324. {
  2325. struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)msg;
  2326. struct res_lib_amf_response res_lib_amf_response;
  2327. struct conn_info *conn_info;
  2328. struct csi_set_callback_data *csi_set_callback_data;
  2329. struct csi_remove_callback_data *csi_remove_callback_data;
  2330. struct component_terminate_callback_data *component_terminate_callback_data;
  2331. struct healthcheck_active *healthcheck_active;
  2332. int interface;
  2333. int res;
  2334. void *data;
  2335. SaAisErrorT error = SA_AIS_OK;
  2336. log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_amf_response()\n");
  2337. res = invocation_get_and_destroy (req_lib_amf_response->invocation,
  2338. &interface, &data);
  2339. if (res == -1) {
  2340. printf ("invocation not found\n");
  2341. error = SA_AIS_ERR_NOT_EXIST;
  2342. goto error_exit;
  2343. }
  2344. log_printf (LOG_LEVEL_DEBUG, "handling response connection %p interface %x\n", conn_info, interface);
  2345. switch (interface) {
  2346. case AMF_RESPONSE_HEALTHCHECKCALLBACK:
  2347. healthcheck_active = (struct healthcheck_active *)data;
  2348. poll_timer_delete (aisexec_poll_handle,
  2349. healthcheck_active->timer_healthcheck_duration);
  2350. healthcheck_active->timer_healthcheck_duration = 0;
  2351. poll_timer_add (aisexec_poll_handle,
  2352. healthcheck_active->healthcheck->period,
  2353. (void *)healthcheck_active,
  2354. timer_function_healthcheck_next,
  2355. &healthcheck_active->timer_healthcheck_period);
  2356. break;
  2357. case AMF_RESPONSE_CSISETCALLBACK:
  2358. csi_set_callback_data = (struct csi_set_callback_data *)data;
  2359. printf ("csi callback executed from library.\n");
  2360. csi_set_callback_data->comp->ha_state =
  2361. csi_set_callback_data->comp->unit->requested_ha_state;
  2362. // list_add (&csi_set_callback_data->comp->
  2363. /*
  2364. pg_comp_create (
  2365. csi_set_callback_data->pg,
  2366. csi_set_callback_data->csi,
  2367. csi_set_callback_data->comp);
  2368. */
  2369. free (csi_set_callback_data);
  2370. break;
  2371. case AMF_RESPONSE_CSIREMOVECALLBACK:
  2372. csi_remove_callback_data = (struct csi_remove_callback_data *)data;
  2373. printf ("response from removing the CSI\n");
  2374. // AAAA
  2375. list_del (&csi_remove_callback_data->csi->si->unit_list);
  2376. list_del (&csi_remove_callback_data->csi->list);
  2377. free (csi_remove_callback_data);
  2378. break;
  2379. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
  2380. component_terminate_callback_data = (struct component_terminate_callback_data *)data;
  2381. printf ("response from terminating component\n");
  2382. comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  2383. escalation_policy_restart (component_terminate_callback_data->comp);
  2384. break;
  2385. default:
  2386. // TODO
  2387. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_lib_amf_response->invocation);
  2388. break;
  2389. }
  2390. error_exit:
  2391. res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
  2392. res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
  2393. res_lib_amf_response.header.error = SA_AIS_OK;
  2394. openais_conn_send_response (conn, &res_lib_amf_response,
  2395. sizeof (struct res_lib_amf_response));
  2396. }
  2397. #ifdef COMPILE_OUT
  2398. /*
  2399. * Executive Message Implementation
  2400. */
  2401. static void message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2402. {
  2403. #ifdef COMPILE_OUT
  2404. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  2405. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  2406. struct amf_comp *component;
  2407. struct amf_comp *amfProxyComponent;
  2408. SaAisErrorT error;
  2409. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  2410. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  2411. /*
  2412. * Determine if proxy isn't registered
  2413. */
  2414. error = SA_AIS_OK;
  2415. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  2416. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  2417. /*
  2418. * If a node is joining menber ship ,Component States Synchronize
  2419. */
  2420. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  2421. amf_synchronize (message, source_addr);
  2422. return;
  2423. }
  2424. /*
  2425. * If component not in configuration files, return error
  2426. */
  2427. if (component == 0) {
  2428. error = SA_ERR_NOT_EXIST;
  2429. }
  2430. /*
  2431. * If proxy doesn't exist and isn't registered, return error
  2432. */
  2433. if ((amfProxyComponent == 0 &&
  2434. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  2435. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  2436. error = SA_ERR_NOT_EXIST;
  2437. }
  2438. /*
  2439. * If component already registered, return error
  2440. */
  2441. if (error == SA_AIS_OK) {
  2442. if (component->registered) {
  2443. error = SA_ERR_EXIST;
  2444. }
  2445. }
  2446. /*
  2447. * Finally register component and setup links for proxy if
  2448. * proxy present
  2449. */
  2450. if (error == SA_AIS_OK) {
  2451. component->local = 0;
  2452. component->registered = 1;
  2453. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  2454. component->source_addr = source_addr;
  2455. // component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  2456. // component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  2457. component->currentHAState = 0;
  2458. component->newHAState = 0;
  2459. component->probableCause = 0;
  2460. component->enabledUnlockedState = 0;
  2461. component->disabledUnlockedState = 0;
  2462. component->healthcheck_outstanding = 0;
  2463. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  2464. component->saAmfProxyComponent = amfProxyComponent;
  2465. }
  2466. }
  2467. /*
  2468. * If this node originated the request to the cluster, respond back
  2469. * to the AMF library
  2470. */
  2471. if (message_source_is_local(&req_exec_amf_componentregister->source)) {
  2472. if (error == SA_AIS_OK) {
  2473. component->local = 1;
  2474. req_exec_amf_componentregister->source.conn_info->component = component;
  2475. }
  2476. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  2477. req_exec_amf_componentregister->source.conn_info->fd);
  2478. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  2479. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  2480. res_lib_amf_componentregister.header.error = error;
  2481. openais_conn_send_response (req_exec_amf_componentregister->source.conn_info,
  2482. &res_lib_amf_componentregister,
  2483. sizeof (struct res_lib_amf_componentregister));
  2484. }
  2485. /*
  2486. * If no error on registration, determine if we should enter new state
  2487. */
  2488. if (error == SA_AIS_OK) {
  2489. dsm (component);
  2490. }
  2491. #endif
  2492. }
  2493. static void message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2494. {
  2495. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  2496. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  2497. struct amf_comp *component;
  2498. struct amf_comp *amfProxyComponent;
  2499. SaAisErrorT error;
  2500. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  2501. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  2502. component = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  2503. amfProxyComponent = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  2504. /*
  2505. * Check for proxy and component not existing in system
  2506. */
  2507. error = SA_AIS_OK;
  2508. if (component == 0) {
  2509. error = SA_ERR_NOT_EXIST;
  2510. }
  2511. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  2512. if (amfProxyComponent) {
  2513. if (amfProxyComponent->registered == 0) {
  2514. error = SA_ERR_NOT_EXIST;
  2515. }
  2516. } else {
  2517. error = SA_ERR_NOT_EXIST;
  2518. }
  2519. }
  2520. /*
  2521. * If there is a proxycompname, make sure it is the proxy
  2522. * of compName
  2523. */
  2524. if (error == SA_AIS_OK && amfProxyComponent) {
  2525. if (component->saAmfProxyComponent != amfProxyComponent) {
  2526. error = SA_ERR_BAD_OPERATION;
  2527. }
  2528. }
  2529. /*
  2530. * Finally unregister the component
  2531. */
  2532. if (error == SA_AIS_OK) {
  2533. component->registered = 0;
  2534. // dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  2535. }
  2536. /*
  2537. * If this node originated the request to the cluster, respond back
  2538. * to the AMF library
  2539. */
  2540. if (message_source_is_local (&req_exec_amf_componentunregister->source)) {
  2541. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  2542. req_exec_amf_componentunregister->source.conn_info->fd);
  2543. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  2544. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  2545. res_lib_amf_componentunregister.header.error = error;
  2546. openais_conn_send_response (req_exec_amf_componentunregister->source.conn_info,
  2547. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  2548. }
  2549. return;
  2550. }
  2551. static void message_handler_req_exec_amf_componenterrorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  2552. {
  2553. struct req_exec_amf_componenterrorreport *req_exec_amf_componenterrorreport = (struct req_exec_amf_componenterrorreport *)message;
  2554. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2555. struct amf_comp *comp;
  2556. SaAisErrorT error = SA_AIS_OK;
  2557. log_printf (LOG_LEVEL_NOTICE, "Executive: ErrorReport for %s\n",
  2558. getSaNameT (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent));
  2559. comp = find_comp (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent);
  2560. if (comp == 0) {
  2561. error = SA_AIS_ERR_NOT_EXIST;
  2562. }
  2563. /*
  2564. * If this node originated the request to the cluster, respond back
  2565. * to the AMF library
  2566. */
  2567. if (message_source_is_local (&req_exec_amf_componenterrorreport->source)) {
  2568. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2569. req_exec_amf_componenterrorreport->source.conn_info->fd);
  2570. if (comp) {
  2571. }
  2572. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2573. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2574. res_lib_amf_componenterrorreport.header.error = error;
  2575. openais_conn_send_response (req_exec_amf_componenterrorreport->source.conn_info,
  2576. &res_lib_amf_componenterrorreport, sizeof (struct res_lib_amf_componenterrorreport));
  2577. }
  2578. return (0);
  2579. }
  2580. static void message_handler_req_exec_amf_componenterrorclear (void *message, struct in_addr source_addr, int endian_conversion_required)
  2581. {
  2582. struct req_exec_amf_componenterrorclear *req_exec_amf_componenterrorclear = (struct req_exec_amf_componenterrorclear *)message;
  2583. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  2584. struct amf_comp *component;
  2585. SaAisErrorT error = SA_ERR_BAD_OPERATION;
  2586. #ifdef COMPILE_OUT
  2587. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  2588. getSaNameT (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName));
  2589. component = find_comp (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName);
  2590. if (component && component->registered) {
  2591. /*
  2592. * Mark component in service if its a AMF service
  2593. * connected to this aisexec
  2594. */
  2595. if (component->probableCause) {
  2596. component->probableCause = 0;
  2597. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  2598. dsm (component);
  2599. }
  2600. error = SA_AIS_OK;
  2601. }
  2602. /*
  2603. * If this node originated the request to the cluster, respond back
  2604. * to the AMF library
  2605. */
  2606. if (message_source_is_local (&req_exec_amf_componenterrorclear->source)) {
  2607. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2608. req_exec_amf_componenterrorclear->source.conn_info->fd);
  2609. res_lib_amf_componenterrorclear.header.size = sizeof (struct res_lib_amf_componenterrorclear);
  2610. res_lib_amf_componenterrorclear.header.id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR;
  2611. res_lib_amf_componenterrorclear.header.error = error;
  2612. openais_conn_send_response (req_exec_amf_componenterrorclear->source.conn_info,
  2613. &res_lib_amf_componenterrorclear, sizeof (struct res_lib_amf_componenterrorclear));
  2614. }
  2615. #endif
  2616. return (0);
  2617. }
  2618. #endif
  2619. #ifdef COMPILE_OUT
  2620. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  2621. {
  2622. struct libamf_ci_trackentry *tracks;
  2623. int newsize;
  2624. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  2625. newsize = growby + currsize;
  2626. if (newsize > currsize) {
  2627. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  2628. (newsize) * sizeof (struct libamf_ci_trackentry));
  2629. if (tracks == 0) {
  2630. #ifdef DEBUG
  2631. printf ("grow_amf_track_table: out of memory, woops\n");
  2632. #endif
  2633. // TODO
  2634. exit (1);
  2635. }
  2636. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  2637. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  2638. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  2639. }
  2640. }
  2641. static void component_unregister (
  2642. struct amf_comp *component)
  2643. {
  2644. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2645. struct iovec iovec;
  2646. /*
  2647. * This only works on local components
  2648. */
  2649. if (component == 0 || component->local != 1) {
  2650. return;
  2651. }
  2652. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  2653. getSaNameT (&component->name));
  2654. component->probableCause = SA_AMF_NOT_RESPONDING;
  2655. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2656. req_exec_amf_componentunregister.header.id =
  2657. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2658. req_exec_amf_componentunregister.source.conn_info = 0;
  2659. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  2660. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2661. 0, sizeof (struct req_lib_amf_componentunregister));
  2662. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  2663. &component->name,
  2664. sizeof (SaNameT));
  2665. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2666. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2667. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2668. }
  2669. static void component_register (
  2670. struct amf_comp *component)
  2671. {
  2672. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  2673. struct iovec iovec;
  2674. /*
  2675. * This only works on local components
  2676. */
  2677. if (component == 0 || component->local != 1) {
  2678. return;
  2679. }
  2680. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  2681. getSaNameT (&component->name));
  2682. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  2683. req_exec_amf_componentregister.header.id =
  2684. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER);
  2685. req_exec_amf_componentregister.source.conn_info = 0;
  2686. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  2687. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  2688. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  2689. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  2690. req_exec_amf_componentregister.newHAState = component->newHAState;
  2691. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  2692. 0, sizeof (struct req_lib_amf_componentregister));
  2693. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  2694. &component->name,
  2695. sizeof (SaNameT));
  2696. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  2697. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  2698. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2699. }
  2700. /***
  2701. This should be used for a partition I think
  2702. **/
  2703. void enumerate_components (
  2704. void (*function)(struct amf_comp *, void *data),
  2705. void *data)
  2706. {
  2707. struct list_head *AmfGroupList;
  2708. struct list_head *AmfUnitList;
  2709. struct list_head *AmfComponentList;
  2710. struct saAmfGroup *saAmfGroup;
  2711. struct saAmfUnit *AmfUnit;
  2712. struct amf_comp *AmfComponent;
  2713. /*
  2714. * Search all groups
  2715. */
  2716. for (AmfGroupList = saAmfGroupHead.next;
  2717. AmfGroupList != &saAmfGroupHead;
  2718. AmfGroupList = AmfGroupList->next) {
  2719. saAmfGroup = list_entry (AmfGroupList,
  2720. struct saAmfGroup, saAmfGroupList);
  2721. /*
  2722. * Search all units
  2723. */
  2724. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  2725. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  2726. AmfUnitList = AmfUnitList->next) {
  2727. AmfUnit = list_entry (AmfUnitList,
  2728. struct saAmfUnit, saAmfUnitList);
  2729. /*
  2730. * Search all components
  2731. */
  2732. for (AmfComponentList = AmfUnit->amf_compHead.next;
  2733. AmfComponentList != &AmfUnit->amf_compHead;
  2734. AmfComponentList = AmfComponentList->next) {
  2735. AmfComponent = list_entry (AmfComponentList,
  2736. struct amf_comp, amf_compList);
  2737. function (AmfComponent, data);
  2738. }
  2739. }
  2740. }
  2741. }
  2742. void ha_state_api_set (struct amf_comp *component, SaAmfHAStateT haState)
  2743. {
  2744. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  2745. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  2746. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  2747. if (component->local != 1) {
  2748. return;
  2749. }
  2750. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2751. return;
  2752. }
  2753. /*
  2754. * this should be an assertion
  2755. */
  2756. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2757. component->conn_info->service != AMF_SERVICE) {
  2758. return;
  2759. }
  2760. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  2761. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  2762. res_lib_amf_csisetcallback.header.error = SA_AIS_OK;
  2763. if (res_lib_amf_csisetcallback.invocation == -1) {
  2764. printf ("TODO set callback\n");
  2765. }
  2766. memcpy (&res_lib_amf_csisetcallback.compName,
  2767. &component->name, sizeof (SaNameT));
  2768. memcpy (&res_lib_amf_csisetcallback.csiName,
  2769. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  2770. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  2771. res_lib_amf_csisetcallback.haState = haState;
  2772. // TODO set activeCompName to correct component name
  2773. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  2774. &component->name, sizeof (SaNameT));
  2775. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  2776. component->newHAState = haState;
  2777. openais_conn_send_response (component->conn_info->conn_info_partner,
  2778. &res_lib_amf_csisetcallback,
  2779. sizeof (struct res_lib_amf_csisetcallback));
  2780. }
  2781. static void ha_state_group_set (
  2782. struct amf_comp *component,
  2783. SaAmfHAStateT haState)
  2784. {
  2785. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  2786. struct iovec iovec;
  2787. req_exec_amf_hastateset.header.id =
  2788. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_HASTATESET);
  2789. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  2790. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  2791. req_exec_amf_hastateset.haState = haState;
  2792. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  2793. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  2794. iovec.iov_base = (char *)&req_exec_amf_hastateset;
  2795. iovec.iov_len = sizeof (req_exec_amf_hastateset);
  2796. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  2797. }
  2798. void readiness_state_api_set (struct amf_comp *component,
  2799. SaAmfReadinessStateT readinessState)
  2800. {
  2801. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  2802. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  2803. /*
  2804. * If component is local, don't request service from API
  2805. */
  2806. if (component->local != 1) {
  2807. return;
  2808. }
  2809. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2810. return;
  2811. }
  2812. /*
  2813. * this should be an assertion
  2814. */
  2815. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2816. component->conn_info->service != AMF_SERVICE) {
  2817. return;
  2818. }
  2819. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  2820. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  2821. res_lib_amf_readinessstatesetcallback.header.error = SA_AIS_OK;
  2822. res_lib_amf_readinessstatesetcallback.invocation =
  2823. req_lib_amf_invocation_create (
  2824. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  2825. comp);
  2826. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  2827. printf ("TODO readiness set callback\n");
  2828. }
  2829. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  2830. &component->name, sizeof (SaNameT));
  2831. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  2832. component->newReadinessState = readinessState;
  2833. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  2834. openais_conn_send_response (component->conn_info->conn_info_partner,
  2835. &res_lib_amf_readinessstatesetcallback,
  2836. sizeof (struct res_lib_amf_readinessstatesetcallback));
  2837. }
  2838. static void readiness_state_group_set (
  2839. struct amf_comp *component,
  2840. SaAmfReadinessStateT readinessState)
  2841. {
  2842. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  2843. struct iovec iovec;
  2844. req_exec_amf_readinessstateset.header.id =
  2845. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_READINESSSTATESET);
  2846. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  2847. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  2848. req_exec_amf_readinessstateset.readinessState = readinessState;
  2849. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  2850. getSaNameT (&component->name));
  2851. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  2852. iovec.iov_base = (char *)&req_exec_amf_readinessstateset;
  2853. iovec.iov_len = sizeof (req_exec_amf_readinessstateset);
  2854. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2855. }
  2856. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  2857. struct amf_comp *component)
  2858. {
  2859. struct saAmfUnit *unit;
  2860. struct list_head *list;
  2861. int serviceUnitEnabled;
  2862. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  2863. getSaNameT (&component->name));
  2864. unit = component->saAmfUnit;
  2865. for (serviceUnitEnabled = 1, list = unit->amf_compHead.next;
  2866. list != &unit->amf_compHead;
  2867. list = list->next) {
  2868. component = list_entry (list,
  2869. struct amf_comp, amf_compList);
  2870. if (component->registered == 0 ||
  2871. component->probableCause) {
  2872. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  2873. serviceUnitEnabled = 0;
  2874. break;
  2875. }
  2876. }
  2877. if (serviceUnitEnabled == 1) {
  2878. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  2879. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  2880. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  2881. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  2882. dsm (component);
  2883. }
  2884. }
  2885. static void dsmDisabledUnlockedFailedComponent (
  2886. struct amf_comp *component)
  2887. {
  2888. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  2889. getSaNameT (&component->name));
  2890. switch (component->enabledUnlockedState) {
  2891. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  2892. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  2893. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  2894. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2895. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  2896. } else {
  2897. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  2898. }
  2899. break;
  2900. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  2901. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  2902. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  2903. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  2904. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  2905. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2906. ha_state_group_set (component, SA_AMF_QUIESCED);
  2907. } else {
  2908. ha_state_api_set (component, SA_AMF_QUIESCED);
  2909. }
  2910. poll_timer_delete (aisexec_poll_handle,
  2911. component->timer_healthcheck);
  2912. component->timer_healthcheck = 0;
  2913. break;
  2914. default:
  2915. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  2916. break;
  2917. }
  2918. }
  2919. static void dsmDisabledUnlockedFailed (
  2920. struct amf_comp *component)
  2921. {
  2922. struct saAmfUnit *unit;
  2923. struct list_head *list;
  2924. unit = component->saAmfUnit;
  2925. for (list = unit->amf_compHead.next;
  2926. list != &unit->amf_compHead;
  2927. list = list->next) {
  2928. component = list_entry (list, struct amf_comp, amf_compList);
  2929. dsmDisabledUnlockedFailedComponent (component);
  2930. }
  2931. return;
  2932. }
  2933. static void dsmDisabledUnlockedQuiescedRequested (
  2934. struct amf_comp *component)
  2935. {
  2936. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  2937. dsm (component);
  2938. }
  2939. static void dsmDisabledUnlockedQuiescedCompleted (
  2940. struct amf_comp *component)
  2941. {
  2942. struct saAmfUnit *unit;
  2943. struct list_head *list;
  2944. int serviceUnitQuiesced;
  2945. unit = component->saAmfUnit;
  2946. for (serviceUnitQuiesced = 1, list = unit->amf_compHead.next;
  2947. list != &unit->amf_compHead;
  2948. list = list->next) {
  2949. component = list_entry (list, struct amf_comp, amf_compList);
  2950. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  2951. if (component->currentHAState != SA_AMF_QUIESCED) {
  2952. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  2953. serviceUnitQuiesced = 0;
  2954. break;
  2955. }
  2956. }
  2957. }
  2958. if (serviceUnitQuiesced == 1) {
  2959. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  2960. for (list = unit->amf_compHead.next;
  2961. list != &unit->amf_compHead;
  2962. list = list->next) {
  2963. component = list_entry (list, struct amf_comp, amf_compList);
  2964. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  2965. getSaNameT (&component->name));
  2966. if ( component->probableCause == SA_AMF_NOT_RESPONDING ) {
  2967. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  2968. } else {
  2969. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  2970. }
  2971. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  2972. }
  2973. }
  2974. }
  2975. static void dsmDisabledUnlockedOutOfServiceRequested (
  2976. struct amf_comp *component)
  2977. {
  2978. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  2979. dsm (component);
  2980. }
  2981. static void dsmDisabledUnlockedOutOfServiceCompleted (
  2982. struct amf_comp *component)
  2983. {
  2984. struct saAmfUnit *unit;
  2985. struct list_head *list;
  2986. int serviceUnitOutOfService;
  2987. struct saAmfGroup *group = 0;
  2988. struct list_head *comp_list = 0;
  2989. struct list_head *unit_list = 0;
  2990. int serviceUnitInStandby = 0;
  2991. int activeServiceUnits = 0;
  2992. /*
  2993. * Once all components of a service unit are out of service,
  2994. * activate another service unit in standby
  2995. */
  2996. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  2997. /*
  2998. * Determine if all components have responded to going out of service
  2999. */
  3000. unit = component->saAmfUnit;
  3001. for (serviceUnitOutOfService = 1, list = unit->amf_compHead.next;
  3002. list != &unit->amf_compHead;
  3003. list = list->next) {
  3004. component = list_entry (list, struct amf_comp, amf_compList);
  3005. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  3006. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  3007. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  3008. serviceUnitOutOfService = 0;
  3009. break;
  3010. }
  3011. }
  3012. if ( component->registered == 0 ) {
  3013. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  3014. }
  3015. }
  3016. group = unit->saAmfGroup;
  3017. activeServiceUnits = activeServiceUnitsCount(group);
  3018. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  3019. return;
  3020. }
  3021. if (serviceUnitOutOfService == 1) {
  3022. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  3023. /*
  3024. * Search all units
  3025. */
  3026. for (unit_list = group->saAmfUnitHead.next;
  3027. unit_list != &group->saAmfUnitHead;
  3028. unit_list = unit_list->next) {
  3029. unit = list_entry (unit_list,
  3030. struct saAmfUnit, saAmfUnitList);
  3031. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  3032. /*
  3033. * Search all components
  3034. */
  3035. for (serviceUnitInStandby = 1,
  3036. comp_list = unit->amf_compHead.next;
  3037. comp_list != &unit->amf_compHead;
  3038. comp_list = comp_list->next) {
  3039. component = list_entry (comp_list,
  3040. struct amf_comp, amf_compList);
  3041. if (component->currentHAState != SA_AMF_STANDBY) {
  3042. serviceUnitInStandby = 0;
  3043. break; /* for iteration of service unit components */
  3044. }
  3045. }
  3046. if (serviceUnitInStandby) {
  3047. break; /* for iteration of service group's service units */
  3048. }
  3049. }
  3050. /*
  3051. * All components in service unit are standby, activate standby service unit
  3052. */
  3053. if (serviceUnitInStandby) {
  3054. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  3055. for (list = unit->amf_compHead.next;
  3056. list != &unit->amf_compHead;
  3057. list = list->next) {
  3058. component = list_entry (list,
  3059. struct amf_comp, amf_compList);
  3060. ha_state_api_set (component, SA_AMF_ACTIVE);
  3061. }
  3062. } else {
  3063. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  3064. }
  3065. }
  3066. }
  3067. static void dsmEnabledUnlockedInitial (
  3068. struct amf_comp *component)
  3069. {
  3070. struct saAmfUnit *unit;
  3071. struct list_head *list;
  3072. unit = component->saAmfUnit;
  3073. for (list = unit->amf_compHead.next;
  3074. list != &unit->amf_compHead;
  3075. list = list->next) {
  3076. component = list_entry (list, struct amf_comp, amf_compList);
  3077. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  3078. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  3079. getSaNameT (&component->name));
  3080. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3081. }
  3082. }
  3083. static void dsmEnabledUnlockedInServiceRequested (
  3084. struct amf_comp *component)
  3085. {
  3086. struct saAmfUnit *unit;
  3087. struct list_head *list;
  3088. int in_service;
  3089. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  3090. unit = component->saAmfUnit;
  3091. for (in_service = 1, list = unit->amf_compHead.next;
  3092. list != &unit->amf_compHead;
  3093. list = list->next) {
  3094. component = list_entry (list, struct amf_comp, amf_compList);
  3095. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  3096. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  3097. in_service = 0;
  3098. break;
  3099. }
  3100. }
  3101. if (in_service) {
  3102. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  3103. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3104. dsm (component);
  3105. }
  3106. }
  3107. static void dsmEnabledUnlockedInServiceCompleted (
  3108. struct amf_comp *component)
  3109. {
  3110. struct saAmfUnit *unit;
  3111. struct list_head *list;
  3112. SaAmfHAStateT newHaState;
  3113. int activeServiceUnits;
  3114. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  3115. unit = component->saAmfUnit;
  3116. for (list = unit->amf_compHead.next;
  3117. list != &unit->amf_compHead;
  3118. list = list->next) {
  3119. component = list_entry (list,
  3120. struct amf_comp, amf_compList);
  3121. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  3122. /*
  3123. * Count number of active service units
  3124. */
  3125. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  3126. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  3127. newHaState = SA_AMF_ACTIVE;
  3128. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  3129. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3130. } else {
  3131. newHaState = SA_AMF_STANDBY;
  3132. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  3133. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3134. }
  3135. ha_state_api_set (component, newHaState);
  3136. }
  3137. }
  3138. static void dsmEnabledUnlockedActiveRequested (
  3139. struct amf_comp *component)
  3140. {
  3141. if (component->local == 1) {
  3142. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer1\n");
  3143. poll_timer_add (aisexec_poll_handle,
  3144. component->healthcheckInterval,
  3145. (void *)component->conn_info,
  3146. timer_function_libamf_healthcheck,
  3147. &component->timer_healthcheck);
  3148. }
  3149. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3150. }
  3151. static void dsmEnabledUnlockedStandbyRequested (
  3152. struct amf_comp *component)
  3153. {
  3154. if (component->local == 1) {
  3155. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer2\n");
  3156. poll_timer_add (aisexec_poll_handle,
  3157. component->healthcheckInterval,
  3158. (void *)component->conn_info,
  3159. timer_function_libamf_healthcheck,
  3160. &component->timer_healthcheck);
  3161. }
  3162. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3163. }
  3164. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  3165. struct amf_comp *component)
  3166. {
  3167. struct saAmfUnit *unit;
  3168. struct list_head *list;
  3169. unit = component->saAmfUnit;
  3170. for (list = unit->amf_compHead.next;
  3171. list != &unit->amf_compHead;
  3172. list = list->next) {
  3173. component = list_entry (list, struct amf_comp, amf_compList);
  3174. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  3175. getSaNameT (&component->name));
  3176. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  3177. }
  3178. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3179. dsm (component);
  3180. }
  3181. static void dsmSynchronizeStaus (
  3182. struct amf_comp *component)
  3183. {
  3184. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  3185. struct saAmfUnit *unit;
  3186. struct saAmfGroup *group;
  3187. struct list_head *list;
  3188. int activeServiceUnits;
  3189. if (component->currentReadinessState == component->newReadinessState) {
  3190. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3191. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3192. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3193. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  3194. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3195. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3196. unit_status = AMF_ENABLED_UNLOCKED;
  3197. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  3198. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  3199. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3200. }
  3201. } else {
  3202. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3203. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  3204. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3205. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  3206. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3207. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3208. unit_status = AMF_ENABLED_UNLOCKED;
  3209. } else {
  3210. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3211. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3212. }
  3213. }
  3214. if (component->currentHAState == component->newHAState) {
  3215. if (component->currentHAState == SA_AMF_ACTIVE) {
  3216. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3217. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3218. unit_status = AMF_ENABLED_UNLOCKED;
  3219. } else if (component->currentHAState == SA_AMF_STANDBY) {
  3220. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3221. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3222. unit_status = AMF_ENABLED_UNLOCKED;
  3223. } else {
  3224. /* depend on readiness status */
  3225. }
  3226. } else {
  3227. if (component->newHAState == SA_AMF_ACTIVE) {
  3228. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3229. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3230. unit_status = AMF_ENABLED_UNLOCKED;
  3231. } else if (component->newHAState == SA_AMF_STANDBY) {
  3232. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3233. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3234. unit_status = AMF_ENABLED_UNLOCKED;
  3235. } else {
  3236. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3237. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3238. }
  3239. }
  3240. /* Syncronize Operational AdministrativeState */
  3241. component->saAmfUnit->operationalAdministrativeState = unit_status;
  3242. unit = component->saAmfUnit;
  3243. group = unit->saAmfGroup;
  3244. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3245. activeServiceUnits = activeServiceUnitsCount(group);
  3246. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  3247. break;
  3248. }
  3249. if (component->currentHAState != SA_AMF_ACTIVE) {
  3250. continue;
  3251. }
  3252. ha_state_api_set (component, SA_AMF_STANDBY);
  3253. }
  3254. return;
  3255. }
  3256. static void dsmEnabledUnlocked (
  3257. struct amf_comp *component)
  3258. {
  3259. switch (component->enabledUnlockedState) {
  3260. case AMF_ENABLED_UNLOCKED_INITIAL:
  3261. dsmEnabledUnlockedInitial (component);
  3262. break;
  3263. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  3264. dsmEnabledUnlockedInServiceRequested (component);
  3265. break;
  3266. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  3267. dsmEnabledUnlockedInServiceCompleted (component);
  3268. break;
  3269. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  3270. dsmEnabledUnlockedActiveRequested (component);
  3271. break;
  3272. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  3273. /* noop - operational state */
  3274. break;
  3275. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  3276. dsmEnabledUnlockedStandbyRequested (component);
  3277. break;
  3278. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  3279. /* noop - operational state */
  3280. break;
  3281. default:
  3282. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  3283. }
  3284. }
  3285. static void dsmDisabledUnlocked (
  3286. struct amf_comp *component)
  3287. {
  3288. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  3289. getSaNameT (&component->name),
  3290. component->disabledUnlockedState);
  3291. switch (component->disabledUnlockedState) {
  3292. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  3293. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  3294. break;
  3295. case AMF_DISABLED_UNLOCKED_FAILED:
  3296. dsmDisabledUnlockedFailed (component);
  3297. break;
  3298. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  3299. dsmDisabledUnlockedQuiescedRequested (component);
  3300. break;
  3301. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  3302. dsmDisabledUnlockedQuiescedCompleted (component);
  3303. break;
  3304. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  3305. dsmDisabledUnlockedOutOfServiceRequested (component);
  3306. break;
  3307. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  3308. dsmDisabledUnlockedOutOfServiceCompleted (component);
  3309. break;
  3310. default:
  3311. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  3312. }
  3313. }
  3314. static void dsm (
  3315. struct amf_comp *component)
  3316. {
  3317. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  3318. switch (component->saAmfUnit->operationalAdministrativeState) {
  3319. case AMF_DISABLED_UNLOCKED:
  3320. dsmDisabledUnlocked (component);
  3321. break;
  3322. case AMF_ENABLED_UNLOCKED:
  3323. dsmEnabledUnlocked (component);
  3324. break;
  3325. /*
  3326. AMF_DISABLED_LOCKED,
  3327. AMF_ENABLED_STOPPING
  3328. */
  3329. default:
  3330. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  3331. }
  3332. }
  3333. void error_report (
  3334. struct amf_comp *component,
  3335. SaAmfProbableCauseT probableCause)
  3336. {
  3337. struct req_exec_amf_componenterrorreport req_exec_amf_componenterrorreport;
  3338. struct iovec iovec;
  3339. req_exec_amf_componenterrorreport.header.size = sizeof (struct req_exec_amf_componenterrorreport);
  3340. req_exec_amf_componenterrorreport.header.id =
  3341. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERRORREPORT);
  3342. req_exec_amf_componenterrorreport.source.conn_info = 0;
  3343. req_exec_amf_componenterrorreport.source.in_addr.s_addr = 0;
  3344. memcpy (&req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.erroneousComponent,
  3345. &component->name,
  3346. sizeof (SaNameT));
  3347. req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.errorDescriptor.probableCause = probableCause;
  3348. iovec.iov_base = (char *)&req_exec_amf_componenterrorreport;
  3349. iovec.iov_len = sizeof (req_exec_amf_componenterrorreport);
  3350. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 2, TOTEMPG_AGREED) == 0);
  3351. }
  3352. int healthcheck_instance = 0;
  3353. struct saAmfProtectionGroup *protectiongroup_find (
  3354. SaNameT *csiName)
  3355. {
  3356. struct list_head *AmfGroupList;
  3357. struct list_head *AmfProtectionGroupList;
  3358. struct saAmfGroup *saAmfGroup;
  3359. struct saAmfProtectionGroup *AmfProtectionGroup;
  3360. /*
  3361. * Search all groups
  3362. */
  3363. for (AmfGroupList = saAmfGroupHead.next;
  3364. AmfGroupList != &saAmfGroupHead;
  3365. AmfGroupList = AmfGroupList->next) {
  3366. saAmfGroup = list_entry (AmfGroupList,
  3367. struct saAmfGroup, saAmfGroupList);
  3368. /*
  3369. * Search all protection groups
  3370. */
  3371. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3372. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3373. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3374. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3375. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3376. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3377. return (AmfProtectionGroup);
  3378. }
  3379. }
  3380. }
  3381. return (0);
  3382. }
  3383. struct amf_comp *component_in_protectiongroup_find (
  3384. SaNameT *csiName,
  3385. SaNameT *compName)
  3386. {
  3387. struct list_head *AmfGroupList = 0;
  3388. struct list_head *AmfProtectionGroupList = 0;
  3389. struct list_head *AmfComponentList = 0;
  3390. struct saAmfGroup *saAmfGroup = 0;
  3391. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  3392. struct amf_comp *AmfComponent = 0;
  3393. int found = 0;
  3394. /*
  3395. * Search all groups
  3396. */
  3397. for (AmfGroupList = saAmfGroupHead.next;
  3398. AmfGroupList != &saAmfGroupHead;
  3399. AmfGroupList = AmfGroupList->next) {
  3400. saAmfGroup = list_entry (AmfGroupList,
  3401. struct saAmfGroup, saAmfGroupList);
  3402. /*
  3403. * Search all protection groups
  3404. */
  3405. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3406. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3407. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3408. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3409. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3410. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3411. /*
  3412. * Search all components
  3413. */
  3414. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  3415. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  3416. AmfComponentList = AmfComponentList->next) {
  3417. AmfComponent = list_entry (AmfComponentList,
  3418. struct amf_comp, saAmfProtectionGroupList);
  3419. if (name_match (compName, &AmfComponent->name)) {
  3420. found = 1;
  3421. }
  3422. }
  3423. }
  3424. }
  3425. }
  3426. if (found) {
  3427. return (AmfComponent);
  3428. } else {
  3429. return (0);
  3430. }
  3431. }
  3432. /*
  3433. * The response handler for readiness state set callback
  3434. */
  3435. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  3436. struct req_lib_amf_response *req_lib_amf_response)
  3437. {
  3438. if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) {
  3439. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  3440. getSaNameT (&conn_info->component->name));
  3441. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  3442. }
  3443. }
  3444. /*
  3445. * iterate service unit components
  3446. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  3447. */
  3448. static void response_handler_csisetcallback (struct conn_info *conn_info,
  3449. struct req_lib_amf_response *req_lib_amf_response)
  3450. {
  3451. if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) {
  3452. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  3453. }
  3454. }
  3455. void amf_confchg_njoin (struct amf_comp *component ,void *data)
  3456. {
  3457. if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) {
  3458. return;
  3459. }
  3460. component_register (component);
  3461. return;
  3462. }
  3463. void amf_confchg_nleave (struct amf_comp *component ,void *data)
  3464. {
  3465. struct in_addr *source_addr = (struct in_addr *)data;
  3466. struct saAmfUnit *unit;
  3467. struct list_head *list;
  3468. struct amf_comp *leave_component = NULL;
  3469. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  3470. if (component->source_addr.s_addr != source_addr->s_addr) {
  3471. return;
  3472. }
  3473. if (!component->registered) {
  3474. return;
  3475. }
  3476. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  3477. /* Component status Initialize */
  3478. unit = component->saAmfUnit;
  3479. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3480. component = list_entry (list,
  3481. struct amf_comp, amf_compList);
  3482. if (component->source_addr.s_addr != source_addr->s_addr) {
  3483. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  3484. continue;
  3485. }
  3486. component->registered = 0;
  3487. component->local = 0;
  3488. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3489. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3490. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  3491. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  3492. component->newHAState = SA_AMF_QUIESCED;
  3493. component->currentHAState = SA_AMF_QUIESCED;
  3494. component->source_addr.s_addr = 0;
  3495. leave_component = component;
  3496. }
  3497. if (leave_component == NULL) {
  3498. return;
  3499. }
  3500. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3501. leave_component->disabledUnlockedState = disablestate;
  3502. dsm (leave_component);
  3503. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3504. return;
  3505. }
  3506. /*
  3507. * If receiving this message from another cluster node, another cluster node
  3508. * has selected a readiness state for a component connected to _that_ cluster
  3509. * node. That cluster node API has verified the readiness state, so its time to let
  3510. * the rest of the cluster nodes know about the readiness state change.
  3511. */
  3512. static void message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3513. {
  3514. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  3515. struct amf_comp *component;
  3516. component = find_comp (&req_exec_amf_readinessstateset->compName);
  3517. if (component) {
  3518. log_printf (LOG_LEVEL_FROM_GMI,
  3519. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  3520. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  3521. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  3522. component->newReadinessState = component->currentReadinessState;
  3523. dsm (component);
  3524. }
  3525. return (0);
  3526. }
  3527. /*
  3528. * If receiving this message from another cluster node, another cluster node
  3529. * has selected a ha state for a component connected to _that_ cluster
  3530. * node. That cluster node API has verified the ha state, so its time to let
  3531. * the rest of the cluster nodes know about the HA state change.
  3532. */
  3533. static void message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3534. {
  3535. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  3536. struct amf_comp *component;
  3537. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  3538. component = find_comp (&req_exec_amf_hastateset->compName);
  3539. if (!component) {
  3540. return (0);
  3541. }
  3542. log_printf (LOG_LEVEL_FROM_GMI,
  3543. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  3544. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  3545. if ( component->currentHAState == 0 ) {
  3546. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  3547. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  3548. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  3549. }
  3550. } else {
  3551. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  3552. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  3553. }
  3554. }
  3555. component->currentHAState = req_exec_amf_hastateset->haState;
  3556. component->newHAState = component->currentHAState;
  3557. dsm (component);
  3558. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  3559. protectiongroup_notifications_send (component, changeToComponent);
  3560. }
  3561. return (0);
  3562. }
  3563. static void message_handler_req_lib_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3564. {
  3565. struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message;
  3566. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  3567. struct iovec iovec;
  3568. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  3569. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  3570. req_exec_amf_componentregister.header.id =
  3571. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER);
  3572. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  3573. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  3574. req_lib_amf_componentregister,
  3575. sizeof (struct req_lib_amf_componentregister));
  3576. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  3577. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  3578. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3579. return (0);
  3580. }
  3581. static void message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  3582. {
  3583. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  3584. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  3585. struct iovec iovec;
  3586. struct saAmfComponent *component;
  3587. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  3588. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  3589. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  3590. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  3591. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  3592. req_lib_amf_componentunregister,
  3593. sizeof (struct req_lib_amf_componentunregister));
  3594. component = findComponent (&req_lib_amf_componentunregister->compName);
  3595. if (component && component->registered && component->local) {
  3596. component->probableCause = SA_AMF_NOT_RESPONDING;
  3597. }
  3598. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  3599. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  3600. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3601. return (0);
  3602. }
  3603. static void message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3604. {
  3605. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  3606. >>>>>>> .r872
  3607. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  3608. struct amf_comp *component;
  3609. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_readinessstateget()\n");
  3610. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  3611. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  3612. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  3613. component = find_comp (&req_lib_amf_readinessstateget->compName);
  3614. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  3615. if (component) {
  3616. memcpy (&res_lib_amf_readinessstateget.readinessState,
  3617. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  3618. res_lib_amf_readinessstateget.header.error = SA_AIS_OK;
  3619. }
  3620. openais_conn_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  3621. return (0);
  3622. }
  3623. static void message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3624. void *message)
  3625. {
  3626. struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message;
  3627. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  3628. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  3629. if (amfProtectionGroup) {
  3630. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  3631. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3632. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  3633. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3634. break;
  3635. }
  3636. }
  3637. if (track == 0) {
  3638. grow_amf_track_table (conn_info, 1);
  3639. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3640. }
  3641. track->active = 1;
  3642. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  3643. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  3644. memcpy (&track->csiName,
  3645. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  3646. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  3647. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  3648. /*
  3649. * If SA_TRACK_CURRENT is specified, write out all current connections
  3650. */
  3651. } else {
  3652. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  3653. }
  3654. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  3655. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  3656. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  3657. if (amfProtectionGroup) {
  3658. res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK;
  3659. }
  3660. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  3661. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  3662. if (amfProtectionGroup &&
  3663. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  3664. protectiongroup_notification_send (conn_info,
  3665. track->notificationBufferAddress,
  3666. amfProtectionGroup,
  3667. 0,
  3668. 0,
  3669. SA_TRACK_CHANGES_ONLY);
  3670. track->trackFlags &= ~SA_TRACK_CURRENT;
  3671. }
  3672. return (0);
  3673. }
  3674. static void message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  3675. {
  3676. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  3677. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  3678. struct libamf_ci_trackentry *track = 0;
  3679. int i;
  3680. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  3681. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3682. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  3683. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  3684. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3685. }
  3686. }
  3687. if (track) {
  3688. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  3689. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  3690. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  3691. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  3692. list_del (&conn_info->conn_list);
  3693. }
  3694. }
  3695. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  3696. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  3697. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  3698. if (track) {
  3699. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  3700. }
  3701. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  3702. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  3703. return (0);
  3704. }
  3705. static void message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  3706. {
  3707. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  3708. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  3709. struct iovec iovec;
  3710. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  3711. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  3712. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  3713. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  3714. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  3715. req_lib_amf_errorreport,
  3716. sizeof (struct req_lib_amf_errorreport));
  3717. iovec.iov_base = (char *)&req_exec_amf_errorreport;
  3718. iovec.iov_len = sizeof (req_exec_amf_errorreport);
  3719. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3720. return (0);
  3721. }
  3722. static void message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  3723. {
  3724. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  3725. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  3726. struct iovec iovec;
  3727. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  3728. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  3729. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  3730. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  3731. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  3732. req_lib_amf_errorcancelall,
  3733. sizeof (struct req_lib_amf_errorcancelall));
  3734. iovec.iov_base = (char *)&req_exec_amf_errorcancelall;
  3735. iovec.iov_len = sizeof (req_exec_amf_errorcancelall);
  3736. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  3737. return (0);
  3738. }
  3739. static void message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3740. void *message)
  3741. {
  3742. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  3743. struct conn_info *inv_conn_info = NULL;
  3744. >>>>>>> .r872
  3745. int interface;
  3746. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_stoppingcomplete()\n");
  3747. req_lib_amf_invocation_get_and_destroy (req_lib_amf_stoppingcomplete->invocation,
  3748. &interface, &inv_conn_info);
  3749. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  3750. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  3751. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  3752. return (0);
  3753. }
  3754. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  3755. struct req_lib_amf_response *req_lib_amf_response) {
  3756. if (req_lib_amf_response->error == SA_AIS_OK) {
  3757. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  3758. conn_info->component->healthcheck_outstanding = 0;
  3759. }
  3760. }
  3761. static void message_handler_req_lib_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  3762. {
  3763. struct req_lib_amf_componentcapabilitymodelget *req_lib_amf_componentcapabilitymodelget = (struct req_lib_amf_componentcapabilitymodelget *)message;
  3764. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  3765. struct amf_comp *component;
  3766. SaAisErrorT error = SA_AIS_OK;
  3767. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentcapabilitymodelget()\n");
  3768. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  3769. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_lib_amf_componentcapabilitymodelget->compName));
  3770. component = find_comp (&req_lib_amf_componentcapabilitymodelget->compName);
  3771. if (component && component->registered) {
  3772. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  3773. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  3774. } else {
  3775. error = SA_ERR_NOT_EXIST;
  3776. }
  3777. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  3778. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  3779. res_lib_amf_componentcapabilitymodelget.header.error = error;
  3780. openais_conn_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  3781. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  3782. return (0);
  3783. }
  3784. static char disabled_unlocked_state_text[6][64] = {
  3785. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  3786. "AMF_DISABLED_UNLOCKED_FAILED",
  3787. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  3788. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  3789. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  3790. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  3791. };
  3792. static char *disabledunlockedstate_ntoa (int state)
  3793. {
  3794. static char str[64];
  3795. if (state >= 0 && state < 6) {
  3796. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  3797. }else{
  3798. sprintf (str, "Unknown(%d)", state);
  3799. }
  3800. return (str);
  3801. }
  3802. static char enabled_unlocked_state_text[7][64] = {
  3803. "AMF_ENABLED_UNLOCKED_INITIAL",
  3804. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  3805. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  3806. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  3807. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  3808. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  3809. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  3810. };
  3811. static char *enabledunlockedstate_ntoa (int state)
  3812. {
  3813. static char str[64];
  3814. if (state >= 0 && state < 7) {
  3815. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  3816. }else{
  3817. sprintf (str, "Unknown(%d)", state);
  3818. }
  3819. return (str);
  3820. }
  3821. #endif
  3822. static char presence_state_text[8][32] = {
  3823. "unknown",
  3824. "uninstantiated",
  3825. "instantiating",
  3826. "instantiated",
  3827. "terminating",
  3828. "restarting",
  3829. "instantion_failed",
  3830. "terminiation_failed"
  3831. };
  3832. static char *presencestate_ntoa (OpenaisCfgPresenceStateT state)
  3833. {
  3834. static char str[32];
  3835. if (state > 0 && state < 9) {
  3836. sprintf (str, "%s(%d)", presence_state_text[state], state);
  3837. }else{
  3838. sprintf (str, "Unknown(%d)", state);
  3839. }
  3840. return (str);
  3841. }
  3842. static char operational_state_text[4][64] = {
  3843. "Unknown",
  3844. "enabled",
  3845. "disabled"
  3846. };
  3847. static char *operationalstate_ntoa (OpenaisCfgOperationalStateT state)
  3848. {
  3849. static char str[32];
  3850. if (state > 0 && state < 3) {
  3851. sprintf (str, "%s(%d)", operational_state_text[state], state);
  3852. }else{
  3853. sprintf (str, "Unknown(%d)", state);
  3854. }
  3855. return (str);
  3856. }
  3857. static char readiness_state_text[4][32] = {
  3858. "Unknown",
  3859. "out of service",
  3860. "in service",
  3861. "quiesced",
  3862. };
  3863. static char *readinessstate_ntoa (int state)
  3864. {
  3865. static char str[32];
  3866. if (state > 0 && state < 4) {
  3867. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  3868. }else{
  3869. sprintf (str, "Unknown(%d)", state);
  3870. }
  3871. return (str);
  3872. }
  3873. static char ha_state_text[4][32] = {
  3874. "Unknown",
  3875. "active",
  3876. "standby",
  3877. "quiesced",
  3878. };
  3879. static char *hastate_ntoa (SaAmfHAStateT state)
  3880. {
  3881. static char str[32];
  3882. if (state > 0 && state < 4) {
  3883. sprintf (str, "%s(%d)", ha_state_text[state], state);
  3884. }else{
  3885. sprintf (str, "Unknown(%d)", state);
  3886. }
  3887. return (str);
  3888. }
  3889. #ifdef COMPILE_OUT
  3890. static void amf_dump_comp (struct amf_comp *component ,void *data)
  3891. {
  3892. char name[64];
  3893. int level = LOG_LEVEL_NOTICE;
  3894. data = NULL;
  3895. log_printf (level, "----------------\n" );
  3896. log_printf (level, "registered = %d\n" ,component->registered);
  3897. log_printf (level, "local = %d\n" ,component->local );
  3898. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  3899. memset (name, 0 , sizeof(name));
  3900. memcpy (name, component->name.value, component->name.length);
  3901. log_printf (level, "name = %s\n" ,name );
  3902. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  3903. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  3904. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  3905. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  3906. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  3907. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  3908. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  3909. }
  3910. void amf_dump ( )
  3911. {
  3912. enumerate_components (amf_dump_comp, NULL);
  3913. fflush (stderr);
  3914. return;
  3915. }
  3916. #endif