amf.c 150 KB

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