amf.c 145 KB

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