amf.c 145 KB

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