amf.c 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785
  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. static void register_this_component (void) {
  380. lcr_component_register (&amf_comp_ver0);
  381. }
  382. static void (*const __init_this_component[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component };
  383. enum clc_command_run_operation_type {
  384. CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
  385. CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
  386. CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
  387. };
  388. struct clc_command_run_data {
  389. struct amf_comp *comp;
  390. enum clc_command_run_operation_type type;
  391. void (*completion_callback) (void *context);
  392. };
  393. int invocation_create (
  394. int interface,
  395. void *data)
  396. {
  397. struct invocation *invocation_addr = 0;
  398. struct invocation *invocation_temp;
  399. int i;
  400. int loc = 0;
  401. for (i = 0; i < invocation_entries_size; i++) {
  402. if (invocation_entries[i].active == 0) {
  403. invocation_addr = &invocation_entries[i];
  404. loc = i;
  405. break;
  406. }
  407. }
  408. if (invocation_addr == 0) {
  409. invocation_temp = (struct invocation *)realloc (invocation_entries,
  410. (invocation_entries_size + 1) * sizeof (struct invocation));
  411. if (invocation_temp == 0) {
  412. return (-1);
  413. }
  414. invocation_entries = invocation_temp;
  415. invocation_addr = &invocation_entries[invocation_entries_size];
  416. loc = invocation_entries_size;
  417. invocation_entries_size += 1;
  418. }
  419. invocation_addr->interface = interface;
  420. invocation_addr->data = data;
  421. invocation_addr->active = 1;
  422. return (loc);
  423. }
  424. int invocation_get_and_destroy (int invocation, int *interface,
  425. void **data)
  426. {
  427. if (invocation > invocation_entries_size) {
  428. return (-1);
  429. }
  430. if (invocation_entries[invocation].active == 0) {
  431. return (-1);
  432. }
  433. *interface = invocation_entries[invocation].interface;
  434. *data = invocation_entries[invocation].data;
  435. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  436. return (0);
  437. }
  438. void invocation_destroy_by_data (void *data)
  439. {
  440. int i;
  441. for (i = 0; i < invocation_entries_size; i++) {
  442. if (invocation_entries[i].data == data) {
  443. memset (&invocation_entries[i], 0,
  444. sizeof (struct invocation));
  445. break;
  446. }
  447. }
  448. }
  449. void *clc_command_run (void *context)
  450. {
  451. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  452. pid_t pid;
  453. int res;
  454. char *argv[10];
  455. char *envp[10];
  456. int status;
  457. unsigned char cmd[1024];
  458. unsigned char env_comp_binary_name[1024];
  459. unsigned char env_comp_binary_path[1024];
  460. unsigned char env_comp_name[1024];
  461. unsigned char *binary_to_run = 0;
  462. unsigned char *binary_path = 0;
  463. char *clc_cli_interface;
  464. sleep (1);
  465. printf ("clc_command_run()\n");
  466. pid = fork();
  467. if (pid == -1) {
  468. printf ("Couldn't fork process %s\n", strerror (errno));
  469. return (0);
  470. }
  471. if (pid) {
  472. waiting = 1;
  473. printf ("waiting for pid %d to finish\n", pid);
  474. waitpid (pid, &status, 0);
  475. if (clc_command_run_data->completion_callback) {
  476. clc_command_run_data->completion_callback (context);
  477. }
  478. pthread_exit(0);
  479. }
  480. switch (clc_command_run_data->type) {
  481. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  482. binary_to_run = clc_command_run_data->comp->instantiate_cmd;
  483. clc_cli_interface = "CLC_CLI_INTERFACE=instantiate";
  484. break;
  485. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  486. binary_to_run = clc_command_run_data->comp->terminate_cmd;
  487. clc_cli_interface = "CLC_CLI_INTERFACE=terminate";
  488. break;
  489. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  490. binary_to_run = clc_command_run_data->comp->cleanup_cmd;
  491. clc_cli_interface = "CLC_CLI_INTERFACE=cleanup";
  492. break;
  493. default:
  494. assert (0 != 1);
  495. break;
  496. }
  497. if (strlen (clc_command_run_data->comp->clccli_path)) {
  498. sprintf (cmd, "%s/%s",
  499. clc_command_run_data->comp->clccli_path,
  500. binary_to_run);
  501. } else
  502. if (strlen (clc_command_run_data->comp->unit->clccli_path)) {
  503. sprintf (cmd, "%s/%s",
  504. clc_command_run_data->comp->unit->clccli_path,
  505. binary_to_run);
  506. } else {
  507. sprintf (cmd, "%s/%s",
  508. clc_command_run_data->comp->unit->amf_group->clccli_path,
  509. binary_to_run);
  510. }
  511. if (strlen (clc_command_run_data->comp->binary_path)) {
  512. binary_path = clc_command_run_data->comp->binary_path;
  513. } else
  514. if (strlen (clc_command_run_data->comp->unit->binary_path)) {
  515. binary_path = clc_command_run_data->comp->unit->binary_path;
  516. } else {
  517. binary_path = clc_command_run_data->comp->unit->amf_group->binary_path;
  518. }
  519. argv[0] = cmd;
  520. argv[1] = '\0';
  521. envp[0] = cmd;
  522. envp[1] = clc_cli_interface;
  523. envp[2] = env_comp_binary_name;
  524. envp[3] = env_comp_binary_path;
  525. envp[4] = env_comp_name;
  526. envp[5] = '\0';
  527. sprintf (env_comp_binary_name, "COMP_BINARY_NAME=%s",
  528. clc_command_run_data->comp->binary_name);
  529. sprintf (env_comp_binary_path, "COMP_BINARY_PATH=%s",
  530. binary_path);
  531. strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME=");
  532. strncat (env_comp_name, clc_command_run_data->comp->name.value,
  533. clc_command_run_data->comp->name.length);
  534. if (cmd[0] == '\0') {
  535. return (0);
  536. }
  537. printf ("running command '%s' with environment:\n", cmd);
  538. printf ("0 %s\n", envp[0]);
  539. printf ("1 %s\n", envp[1]);
  540. printf ("2 %s\n", envp[2]);
  541. printf ("3 %s\n", envp[3]);
  542. printf ("4 %s\n", envp[4]);
  543. res = execve (cmd, argv, envp);
  544. if (res == -1) {
  545. printf ("Couldn't exec process %d=%s\n", errno, strerror (errno));
  546. }
  547. assert (res != -1);
  548. return (0);
  549. }
  550. struct req_exec_amf_operational_state_comp_set {
  551. struct req_header header;
  552. SaNameT name;
  553. OpenaisCfgOperationalStateT operational_state;
  554. };
  555. struct req_exec_amf_presence_state_comp_set {
  556. struct req_header header;
  557. SaNameT name;
  558. OpenaisCfgPresenceStateT presence_state;
  559. };
  560. struct req_exec_amf_administrative_state_csi_set {
  561. struct req_header header;
  562. SaNameT name;
  563. OpenaisCfgAdministrativeStateT presence_state;
  564. };
  565. struct req_exec_amf_administrative_state_unit_set {
  566. struct req_header header;
  567. SaNameT name;
  568. OpenaisCfgAdministrativeStateT presence_state;
  569. };
  570. struct req_exec_amf_administrative_state_group_set {
  571. struct req_header header;
  572. SaNameT name;
  573. OpenaisCfgAdministrativeStateT presence_state;
  574. };
  575. struct req_exec_amf_comp_restart {
  576. struct req_header header;
  577. SaNameT compName;
  578. };
  579. /*
  580. * Instantiate possible operations
  581. */
  582. int clc_cli_instantiate (struct amf_comp *comp)
  583. {
  584. int res;
  585. pthread_t thread;
  586. struct clc_command_run_data *clc_command_run_data;
  587. printf ("clc_cli_instaniate\n");
  588. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  589. clc_command_run_data->comp = comp;
  590. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  591. clc_command_run_data->completion_callback = NULL;
  592. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  593. pthread_detach (thread);
  594. // TODO error code from pthread_create
  595. return (res);
  596. }
  597. int clc_instantiate_callback (struct amf_comp *comp)
  598. {
  599. printf ("clc_instantiate_callback\n");
  600. return (0);
  601. }
  602. int clc_csi_set_callback (struct amf_comp *comp)
  603. {
  604. printf ("clc_csi_set_callback\n");
  605. return (0);
  606. }
  607. /*
  608. * Terminate possible operations
  609. */
  610. int clc_cli_terminate (struct amf_comp *comp)
  611. {
  612. printf ("clc_cli_terminate\n");
  613. return (0);
  614. }
  615. int clc_terminate_callback (struct amf_comp *comp)
  616. {
  617. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  618. struct component_terminate_callback_data *component_terminate_callback_data;
  619. printf ("clc_terminate_callback %p\n", comp->conn);
  620. if (comp->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  621. printf ("component terminated but not instantiated %s - %d\n",
  622. getSaNameT (&comp->name), comp->presence_state);
  623. assert (0);
  624. return (0);
  625. }
  626. printf ("component name terminating %s\n", getSaNameT (&comp->name));
  627. printf ("component presence state %d\n", comp->presence_state);
  628. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  629. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  630. res_lib_amf_componentterminatecallback.header.error = SA_AIS_OK;
  631. memcpy (&res_lib_amf_componentterminatecallback.compName,
  632. &comp->name, sizeof (SaNameT));
  633. component_terminate_callback_data =
  634. malloc (sizeof (struct component_terminate_callback_data));
  635. assert (component_terminate_callback_data); // TODO failure here of malloc
  636. component_terminate_callback_data->comp = comp;
  637. res_lib_amf_componentterminatecallback.invocation =
  638. invocation_create (
  639. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  640. component_terminate_callback_data);
  641. printf ("Creating invocation %llu",
  642. (unsigned long long)res_lib_amf_componentterminatecallback.invocation);
  643. openais_conn_send_response (
  644. openais_conn_partner_get (comp->conn),
  645. &res_lib_amf_componentterminatecallback,
  646. sizeof (struct res_lib_amf_componentterminatecallback));
  647. return (0);
  648. }
  649. int clc_csi_remove_callback (struct amf_comp *comp)
  650. {
  651. printf ("clc_tcsi_remove_callback\n");
  652. return (0);
  653. }
  654. /*
  655. * This reinstantiates the cleaned up component
  656. */
  657. void clc_cleanup_completion_callback (void *context) {
  658. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  659. escalation_policy_restart (clc_command_run_data->comp);
  660. }
  661. /*
  662. * Cleanup possible operations
  663. */
  664. int clc_cli_cleanup (struct amf_comp *comp)
  665. {
  666. int res;
  667. pthread_t thread;
  668. struct clc_command_run_data *clc_command_run_data;
  669. printf ("clc_cli_instaniate\n");
  670. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  671. clc_command_run_data->comp = comp;
  672. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  673. clc_command_run_data->completion_callback = clc_cleanup_completion_callback;
  674. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  675. pthread_detach (thread);
  676. // TODO error code from pthread_create
  677. return (res);
  678. return (0);
  679. }
  680. int clc_cli_cleanup_local (struct amf_comp *comp)
  681. {
  682. printf ("clc_cli_cleanup_local\n");
  683. return (0);
  684. }
  685. int clc_instantiate (struct amf_comp *comp)
  686. {
  687. int res;
  688. printf ("clc instantiate for comp %s\n", getSaNameT (&comp->name));
  689. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_INSTANTIATING);
  690. res = clc_interfaces[comp->comptype]->instantiate (comp);
  691. return (res);
  692. }
  693. int clc_terminate (struct amf_comp *comp)
  694. {
  695. int res;
  696. printf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  697. assert (0);
  698. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  699. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  700. res = clc_interfaces[comp->comptype]->terminate (comp);
  701. return (0);
  702. }
  703. int clc_cleanup (struct amf_comp *comp)
  704. {
  705. int res;
  706. printf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
  707. comp_healthcheck_deactivate (comp);
  708. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  709. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  710. res = clc_interfaces[comp->comptype]->cleanup (comp);
  711. return (0);
  712. }
  713. /* IMPL */
  714. static int amf_exec_init_fn (struct openais_config *openais_config)
  715. {
  716. if (openais_config->amf_enabled) {
  717. clc_instantiate_all ();
  718. }
  719. return (0);
  720. }
  721. static void amf_confchg_fn (
  722. enum totem_configuration_type configuration_type,
  723. struct totem_ip_address *member_list, int member_list_entries,
  724. struct totem_ip_address *left_list, int left_list_entries,
  725. struct totem_ip_address *joined_list, int joined_list_entries,
  726. struct memb_ring_id *ring_id)
  727. {
  728. #ifdef COMPILE_OUT
  729. int i;
  730. 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);
  731. recovery = 1;
  732. /*
  733. * If node join, component register
  734. */
  735. if ( joined_list_entries > 0 ) {
  736. enumerate_components (amf_confchg_njoin, NULL);
  737. }
  738. /*
  739. * If node leave, component unregister
  740. */
  741. for (i = 0; i<left_list_entries ; i++) {
  742. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  743. }
  744. #ifdef TODO
  745. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  746. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  747. recovery = 0;
  748. }
  749. #endif
  750. #endif
  751. }
  752. int amf_lib_exit_fn (void *conn)
  753. {
  754. struct amf_comp *comp;
  755. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  756. comp = amf_pd->comp;
  757. if (comp) {
  758. comp->conn = 0;
  759. printf ("setting in exit fn to uninst for comp %p\n", comp);
  760. presence_state_comp_set (
  761. comp,
  762. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  763. operational_state_comp_set (
  764. comp,
  765. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  766. comp_healthcheck_deactivate (comp);
  767. }
  768. return (0);
  769. }
  770. static int amf_lib_init_fn (void *conn)
  771. {
  772. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize availability management framework service.\n");
  773. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  774. list_init (&amf_pd->list);
  775. return (0);
  776. }
  777. #ifdef COMPILE_OUT
  778. static void amf_synchronize (void *message, struct in_addr source_addr)
  779. {
  780. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  781. struct amf_comp *component;
  782. struct amf_comp *amfProxyComponent;
  783. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  784. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  785. /* Find Component */
  786. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  787. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  788. /* If this processor is component owner */
  789. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  790. /* No Operation */
  791. return;
  792. }
  793. /* If this isn't synchronizing target processor */
  794. if (!(component->local == 0 && component->registered == 0)){
  795. /* No Operation */
  796. return;
  797. }
  798. /* Synchronize Status */
  799. component->local = 0;
  800. component->registered = 1;
  801. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  802. component->source_addr = source_addr;
  803. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  804. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  805. component->currentHAState = SA_AMF_QUIESCED;
  806. component->newHAState = SA_AMF_QUIESCED;
  807. component->probableCause = 0;
  808. component->enabledUnlockedState = 0;
  809. component->disabledUnlockedState = 0;
  810. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  811. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  812. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  813. component->newHAState = req_exec_amf_componentregister->newHAState;
  814. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  815. component->saAmfProxyComponent = amfProxyComponent;
  816. }
  817. /*
  818. * Determine if we should enter new state
  819. */
  820. dsmSynchronizeStaus (component);
  821. return;
  822. }
  823. #endif
  824. DECLARE_LIST_INIT (library_notification_send_listhead);
  825. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  826. static void protectiongroup_notifications_send (
  827. struct amf_comp *changedComponent,
  828. SaAmfProtectionGroupChangesT changeToComponent)
  829. {
  830. #ifdef COMPILE_OUT
  831. int i;
  832. struct conn_info *conn_info;
  833. struct list_head *list;
  834. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  835. /*
  836. * Iterate all tracked connections
  837. */
  838. for (list = library_notification_send_listhead.next;
  839. list != &library_notification_send_listhead;
  840. list = list->next) {
  841. conn_info = list_entry (list, struct conn_info, conn_list);
  842. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  843. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  844. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  845. != changedComponent->amf_pg->name.length) {
  846. continue;
  847. }
  848. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  849. changedComponent->amf_pg->name.value,
  850. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  851. continue;
  852. }
  853. #ifdef COMPILE_OUT
  854. protectiongroup_notification_send (conn_info,
  855. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  856. changedComponent->saAmfProtectionGroup,
  857. changedComponent,
  858. changeToComponent,
  859. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  860. #endif
  861. } /* if track flags active */
  862. } /* for all track entries */
  863. } /* for all connection entries */
  864. #endif
  865. }
  866. static int make_protectiongroup_notification_allcomponent (
  867. struct amf_comp *changedComponent,
  868. SaAmfProtectionGroupChangesT changeToComponent,
  869. SaAmfProtectionGroupNotificationT **notification )
  870. {
  871. #ifdef COMPILE_OUT
  872. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  873. int notifyEntries = 0;
  874. struct amf_comp *component;
  875. struct list_head *AmfGroupList;
  876. struct list_head *AmfUnitList;
  877. struct list_head *AmfComponentList;
  878. struct saAmfGroup *saAmfGroup;
  879. struct saAmfUnit *AmfUnit;
  880. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  881. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  882. /*
  883. * Search all units
  884. */
  885. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  886. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  887. AmfUnitList = AmfUnitList->next) {
  888. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  889. /*
  890. * Search all components
  891. */
  892. for (AmfComponentList = AmfUnit->amf_compHead.next;
  893. AmfComponentList != &AmfUnit->amf_compHead;
  894. AmfComponentList = AmfComponentList->next) {
  895. component = list_entry (AmfComponentList, struct amf_comp, amf_compList);
  896. protectionGroupNotification =
  897. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  898. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  899. memset (&protectionGroupNotification[notifyEntries],
  900. 0,sizeof (SaAmfProtectionGroupNotificationT));
  901. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  902. &component->name, sizeof (SaNameT));
  903. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  904. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  905. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  906. &component->currentHAState, sizeof (SaAmfHAStateT));
  907. if (component == changedComponent) {
  908. protectionGroupNotification[notifyEntries].change = changeToComponent;
  909. } else {
  910. protectionGroupNotification[notifyEntries].change
  911. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  912. }
  913. notifyEntries += 1;
  914. }
  915. }
  916. }
  917. if (notifyEntries) {
  918. *notification = protectionGroupNotification;
  919. }
  920. return (notifyEntries);
  921. #endif
  922. return (0);
  923. }
  924. #ifdef COMPILE_OUT
  925. static int make_protectiongroup_notification (
  926. struct saAmfProtectionGroup *amfProtectionGroup,
  927. struct amf_comp *changedComponent,
  928. SaAmfProtectionGroupChangesT changeToComponent,
  929. SaAmfProtectionGroupNotificationT **notification )
  930. {
  931. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  932. int notifyEntries = 0;
  933. struct amf_comp *component;
  934. struct list_head *componentList;
  935. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  936. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  937. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  938. componentList != &amfProtectionGroup->saAmfMembersHead;
  939. componentList = componentList->next) {
  940. component = list_entry (componentList, struct amf_comp, saAmfProtectionGroupList);
  941. protectionGroupNotification =
  942. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  943. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  944. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  945. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  946. &component->name, sizeof (SaNameT));
  947. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  948. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  949. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  950. &component->currentHAState, sizeof (SaAmfHAStateT));
  951. if (component == changedComponent) {
  952. protectionGroupNotification[notifyEntries].change = changeToComponent;
  953. } else {
  954. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  955. }
  956. notifyEntries += 1;
  957. } /* for */
  958. if (notifyEntries) {
  959. *notification = protectionGroupNotification;
  960. }
  961. return (notifyEntries);
  962. return (0);
  963. }
  964. #endif
  965. #ifdef COMPILE_OUT
  966. static void protectiongroup_notification_send (struct conn_info *conn_info,
  967. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  968. struct saAmfProtectionGroup *amfProtectionGroup,
  969. struct amf_comp *changedComponent,
  970. SaAmfProtectionGroupChangesT changeToComponent,
  971. SaUint8T trackFlags)
  972. {
  973. //struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  974. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  975. int notifyEntries;
  976. /*
  977. * Step through all components and generate protection group list for csi
  978. */
  979. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  980. if ( trackFlags == SA_TRACK_CHANGES ) {
  981. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  982. changeToComponent, &protectionGroupNotification);
  983. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  984. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  985. changedComponent, changeToComponent, &protectionGroupNotification );
  986. }else{
  987. notifyEntries = 0;
  988. }
  989. /*
  990. * Send track callback
  991. */
  992. if (notifyEntries) {
  993. res_lib_amf_protectiongrouptrackcallback.header.size =
  994. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  995. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  996. // res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  997. res_lib_amf_protectiongrouptrackcallback.header.error = SA_AIS_OK;
  998. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  999. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1000. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1001. &amfProtectionGroup->name, sizeof (SaNameT));
  1002. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1003. openais_conn_send_response (conno, &res_lib_amf_protectiongrouptrackcallback,
  1004. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1005. openais_conn_send_response (conno, protectionGroupNotification,
  1006. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1007. mempool_free (protectionGroupNotification);
  1008. }
  1009. }
  1010. static void error_report (struct amf_comp *comp)
  1011. {
  1012. struct req_exec_amf_error_report req_exec_amf_error_report;
  1013. struct iovec iovec;
  1014. req_exec_amf_error_report.header.size = sizeof (struct req_exec_amf_error_report);
  1015. req_exec_amf_error_report.header.id =
  1016. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERROR_REPORT);
  1017. memcpy (&req_exec_amf_error_report.compName,
  1018. &comp->name,
  1019. sizeof (SaNameT));
  1020. iovec.iov_base = (char *)&req_exec_amf_error_report;
  1021. iovec.iov_len = sizeof (req_exec_amf_error_report);
  1022. assert (totempg_groups_mcast_joined (openais_group_handle,
  1023. &iovec, 1, TOTEMPG_AGREED) == 0);
  1024. }
  1025. static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp)
  1026. {
  1027. struct req_exec_amf_comp_restart req_exec_amf_comp_restart;
  1028. struct iovec iovec;
  1029. req_exec_amf_comp_restart.header.size = sizeof (struct req_exec_amf_comp_restart);
  1030. req_exec_amf_comp_restart.header.id =
  1031. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_UNIT_RESTART);
  1032. memcpy (&req_exec_amf_comp_restart.compName, &comp->name,
  1033. sizeof (SaNameT));
  1034. iovec.iov_base = (char *)&req_exec_amf_comp_restart;
  1035. iovec.iov_len = sizeof (req_exec_amf_comp_restart);
  1036. assert (totempg_groups_mcast_joined (openais_group_handle,
  1037. &iovec, 1, TOTEMPG_AGREED) == 0);
  1038. }
  1039. #endif
  1040. #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL
  1041. struct healthcheck_active *find_healthcheck_active (
  1042. struct amf_comp *comp,
  1043. SaAmfHealthcheckKeyT *key,
  1044. SaAmfHealthcheckInvocationT invocation)
  1045. {
  1046. struct list_head *list;
  1047. struct healthcheck_active *ret_healthcheck_active = 0;
  1048. struct healthcheck_active *healthcheck_active;
  1049. for (list = comp->healthcheck_list.next;
  1050. list != &comp->healthcheck_list;
  1051. list = list->next) {
  1052. healthcheck_active = list_entry (list,
  1053. struct healthcheck_active, list);
  1054. if ((memcmp (key, &healthcheck_active->key,
  1055. sizeof (SaAmfHealthcheckKeyT)) == 0) &&
  1056. (invocation == INVOCATION_DONT_COMPARE ||
  1057. healthcheck_active->invocationType == invocation)) {
  1058. ret_healthcheck_active = healthcheck_active;
  1059. break;
  1060. }
  1061. }
  1062. return (ret_healthcheck_active);
  1063. }
  1064. void comp_healthcheck_activate (
  1065. struct amf_comp *comp)
  1066. {
  1067. struct list_head *key_list;
  1068. struct healthcheck_active *healthcheck_active;
  1069. for (key_list = comp->healthcheck_list.next;
  1070. key_list != &comp->healthcheck_list;
  1071. key_list = key_list->next) {
  1072. healthcheck_active = list_entry (key_list,
  1073. struct healthcheck_active, list);
  1074. if (healthcheck_active->active == 0) {
  1075. healthcheck_activate (healthcheck_active);
  1076. }
  1077. }
  1078. }
  1079. void comp_healthcheck_deactivate (
  1080. struct amf_comp *comp)
  1081. {
  1082. struct list_head *list;
  1083. struct list_head *next;
  1084. struct healthcheck_active *healthcheck_active;
  1085. log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n",
  1086. getSaNameT (&comp->name));
  1087. for (list = comp->healthcheck_list.next, next = list->next;
  1088. list != &comp->healthcheck_list;
  1089. list = next, next = list->next) {
  1090. healthcheck_active = list_entry (list,
  1091. struct healthcheck_active, list);
  1092. printf ("healthcheck deactivating %p\n", healthcheck_active);
  1093. healthcheck_deactivate (healthcheck_active);
  1094. }
  1095. }
  1096. void presence_state_comp_set (
  1097. struct amf_comp *comp,
  1098. OpenaisCfgPresenceStateT presence_state)
  1099. {
  1100. struct req_exec_amf_presence_state_comp_set req_exec_amf_presence_state_comp_set;
  1101. struct iovec iovec;
  1102. req_exec_amf_presence_state_comp_set.header.size = sizeof (struct req_exec_amf_presence_state_comp_set);
  1103. req_exec_amf_presence_state_comp_set.header.id =
  1104. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET);
  1105. req_exec_amf_presence_state_comp_set.presence_state = presence_state;
  1106. memcpy (&req_exec_amf_presence_state_comp_set.name,
  1107. &comp->name,
  1108. sizeof (SaNameT));
  1109. iovec.iov_base = (char *)&req_exec_amf_presence_state_comp_set;
  1110. iovec.iov_len = sizeof (req_exec_amf_presence_state_comp_set);
  1111. assert (totempg_groups_mcast_joined (openais_group_handle,
  1112. &iovec, 1, TOTEMPG_AGREED) == 0);
  1113. }
  1114. void readiness_state_comp_set (struct amf_comp *comp)
  1115. {
  1116. printf ("inputs to readiness_state_comp_set\n");
  1117. printf ("\tunit readiness state %s\n",
  1118. readinessstate_ntoa (comp->unit->readiness_state));
  1119. printf ("\tcomp operational state %s\n",
  1120. operationalstate_ntoa (comp->unit->readiness_state));
  1121. /*
  1122. * Set component readiness state appropriately
  1123. * if unit in service and component is enabled, it is in service
  1124. * otherwise it is out of service page 37
  1125. */
  1126. if (comp->unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1127. comp->operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1128. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_INSERVICE;
  1129. } else {
  1130. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE;
  1131. }
  1132. printf ("readiness_state_comp_set (%s)\n",
  1133. operationalstate_ntoa (comp->operational_state));
  1134. }
  1135. void operational_state_comp_set (struct amf_comp *comp, OpenaisCfgOperationalStateT operational_state)
  1136. {
  1137. struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set;
  1138. struct iovec iovec;
  1139. req_exec_amf_operational_state_comp_set.header.size = sizeof (struct req_exec_amf_operational_state_comp_set);
  1140. req_exec_amf_operational_state_comp_set.header.id =
  1141. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET);
  1142. req_exec_amf_operational_state_comp_set.operational_state = operational_state;
  1143. memcpy (&req_exec_amf_operational_state_comp_set.name,
  1144. &comp->name,
  1145. sizeof (SaNameT));
  1146. iovec.iov_base = (char *)&req_exec_amf_operational_state_comp_set;
  1147. iovec.iov_len = sizeof (req_exec_amf_operational_state_comp_set);
  1148. assert (totempg_groups_mcast_joined (openais_group_handle,
  1149. &iovec, 1, TOTEMPG_AGREED) == 0);
  1150. }
  1151. void csi_comp_set_callback (
  1152. struct amf_comp *comp,
  1153. struct amf_csi *csi,
  1154. struct amf_pg *pg)
  1155. {
  1156. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  1157. struct csi_set_callback_data *csi_set_callback_data;
  1158. printf ("\t%s\n",
  1159. getSaNameT (&comp->name));
  1160. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1161. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  1162. res_lib_amf_csisetcallback.header.error = SA_AIS_OK;
  1163. memcpy (&res_lib_amf_csisetcallback.compName,
  1164. &comp->name, sizeof (SaNameT));
  1165. memcpy (&res_lib_amf_csisetcallback.csiDescriptor.csiName,
  1166. &csi->name, sizeof (SaNameT));
  1167. res_lib_amf_csisetcallback.haState = comp->unit->requested_ha_state;
  1168. csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data));
  1169. assert (csi_set_callback_data); // TODO failure here of malloc
  1170. csi_set_callback_data->comp = comp;
  1171. csi_set_callback_data->csi = csi;
  1172. csi_set_callback_data->pg = pg;
  1173. printf ("pg is %p\n", pg);
  1174. res_lib_amf_csisetcallback.invocation =
  1175. invocation_create (
  1176. AMF_RESPONSE_CSISETCALLBACK,
  1177. csi_set_callback_data);
  1178. openais_conn_send_response (
  1179. openais_conn_partner_get (comp->conn),
  1180. &res_lib_amf_csisetcallback,
  1181. sizeof (struct res_lib_amf_csisetcallback));
  1182. }
  1183. void pg_create (struct amf_si *si, struct amf_pg **pg_out)
  1184. {
  1185. struct amf_pg *pg;
  1186. // struct amf_pg_comp *pg_comp;
  1187. pg = malloc (sizeof (struct amf_pg));
  1188. assert (pg);
  1189. list_init (&pg->pg_comp_head);
  1190. list_init (&pg->pg_list);
  1191. list_add (&pg->pg_list, &si->pg_head);
  1192. *pg_out = pg;
  1193. }
  1194. void csi_unit_set_callback (struct amf_csi *csi_in)
  1195. {
  1196. struct list_head *list;
  1197. struct amf_comp *comp;
  1198. struct amf_pg *pg;
  1199. pg_create (csi_in->si, &pg);
  1200. // TODO remove si from csi data structure
  1201. printf ("assigning CSI %s to ",
  1202. getSaNameT (&csi_in->name));
  1203. printf ("SU %s for components:\n",
  1204. getSaNameT (&csi_in->unit->name));
  1205. for (list = csi_in->unit->comp_head.next;
  1206. list != &csi_in->unit->comp_head;
  1207. list = list->next) {
  1208. comp = list_entry (list,
  1209. struct amf_comp, comp_list);
  1210. csi_comp_set_callback (comp, csi_in, pg);
  1211. }
  1212. }
  1213. void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
  1214. {
  1215. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  1216. struct csi_remove_callback_data *csi_remove_callback_data;
  1217. printf ("\t%s\n",
  1218. getSaNameT (&comp->name));
  1219. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1220. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1221. res_lib_amf_csiremovecallback.header.error = SA_AIS_OK;
  1222. csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
  1223. assert (csi_remove_callback_data); // TODO failure here of malloc
  1224. csi_remove_callback_data->csi = csi;
  1225. res_lib_amf_csiremovecallback.invocation =
  1226. invocation_create (
  1227. AMF_RESPONSE_CSIREMOVECALLBACK,
  1228. csi_remove_callback_data);
  1229. memcpy (&res_lib_amf_csiremovecallback.compName,
  1230. &comp->name, sizeof (SaNameT));
  1231. memcpy (&res_lib_amf_csiremovecallback.csiName,
  1232. &csi->name, sizeof (SaNameT));
  1233. res_lib_amf_csiremovecallback.csiFlags = 0;
  1234. openais_conn_send_response (
  1235. openais_conn_partner_get (comp->conn),
  1236. &res_lib_amf_csiremovecallback,
  1237. sizeof (struct res_lib_amf_csiremovecallback));
  1238. }
  1239. extern struct list_head amf_groupHead;
  1240. int clc_instantiate_all (void) {
  1241. struct list_head *list_group;
  1242. struct amf_group *group;
  1243. struct list_head *list_unit;
  1244. struct amf_unit *unit;
  1245. struct list_head *list_comp;
  1246. struct amf_comp *comp;
  1247. for (list_group = amf_groupHead.next;
  1248. list_group != &amf_groupHead;
  1249. list_group = list_group->next) {
  1250. group = list_entry (list_group,
  1251. struct amf_group, group_list);
  1252. for (list_unit = group->unit_head.next;
  1253. list_unit != &group->unit_head;
  1254. list_unit = list_unit->next) {
  1255. unit = list_entry (list_unit,
  1256. struct amf_unit, unit_list);
  1257. for (list_comp = unit->comp_head.next;
  1258. list_comp != &unit->comp_head;
  1259. list_comp = list_comp->next) {
  1260. comp = list_entry (list_comp,
  1261. struct amf_comp, comp_list);
  1262. if (strlen ((char *)comp->instantiate_cmd)) {
  1263. clc_instantiate (comp);
  1264. }
  1265. }
  1266. }
  1267. }
  1268. return (0);
  1269. }
  1270. void comp_terminate (struct amf_comp *comp)
  1271. {
  1272. clc_terminate (comp);
  1273. }
  1274. void unit_terminate (struct amf_unit *unit)
  1275. {
  1276. struct list_head *list_comp;
  1277. struct amf_comp *comp;
  1278. for (list_comp = unit->comp_head.next;
  1279. list_comp != &unit->comp_head;
  1280. list_comp = list_comp->next) {
  1281. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1282. clc_terminate (comp);
  1283. }
  1284. }
  1285. void comp_cleanup (struct amf_comp *comp)
  1286. {
  1287. clc_cleanup (comp);
  1288. }
  1289. void unit_cleanup (struct amf_unit *unit)
  1290. {
  1291. struct list_head *list_comp;
  1292. struct amf_comp *comp;
  1293. for (list_comp = unit->comp_head.next;
  1294. list_comp != &unit->comp_head;
  1295. list_comp = list_comp->next) {
  1296. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1297. clc_cleanup (comp);
  1298. }
  1299. }
  1300. void comp_restart (struct amf_comp *comp)
  1301. {
  1302. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1303. }
  1304. void unit_restart (struct amf_unit *unit)
  1305. {
  1306. struct list_head *list_comp;
  1307. struct amf_comp *comp;
  1308. for (list_comp = unit->comp_head.next;
  1309. list_comp != &unit->comp_head;
  1310. list_comp = list_comp->next) {
  1311. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1312. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1313. }
  1314. }
  1315. void clc_unit_instantiate (struct amf_unit *unit)
  1316. {
  1317. struct list_head *list_comp;
  1318. struct amf_comp *comp;
  1319. printf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
  1320. for (list_comp = unit->comp_head.next;
  1321. list_comp != &unit->comp_head;
  1322. list_comp = list_comp->next) {
  1323. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1324. clc_instantiate (comp);
  1325. }
  1326. }
  1327. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1328. {
  1329. struct list_head *list_si;
  1330. struct list_head *list_csi;
  1331. struct list_head *list_comp;
  1332. struct amf_si *si;
  1333. struct amf_csi *csi;
  1334. struct amf_comp *comp;
  1335. for (list_si = unit->si_head.next;
  1336. list_si != &unit->si_head;
  1337. list_si = list_si->next) {
  1338. si = list_entry (list_si, struct amf_si, unit_list);
  1339. for (list_csi = si->csi_head.next;
  1340. list_csi != &si->csi_head;
  1341. list_csi = list_csi->next) {
  1342. csi = list_entry (list_csi, struct amf_csi, list);
  1343. for (list_comp = csi->unit->comp_head.next;
  1344. list_comp != &csi->unit->comp_head;
  1345. list_comp = list_comp->next) {
  1346. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1347. }
  1348. }
  1349. }
  1350. }
  1351. // THIS MIGHT BE GOOD FOR SOMEPTHING ELSE
  1352. #ifdef COMPILE_OUT
  1353. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1354. {
  1355. struct list_head *list_comp;
  1356. struct list_head *list_si;
  1357. struct list_head *list_csi;
  1358. struct list_head *list_pg;
  1359. struct list_head *list_pg_comp;
  1360. struct amf_comp *comp;
  1361. struct amf_csi *csi;
  1362. struct amf_si *si;
  1363. struct amf_pg *pg;
  1364. struct amf_pg_comp *pg_comp;
  1365. for (list_si = unit->si_head.next;
  1366. list_si != &unit->si_head;
  1367. list_si = list_si->next) {
  1368. si = list_entry (list_si, struct amf_si, unit_list);
  1369. for (list_pg = si->pg_head.next;
  1370. list_pg != &si->pg_head;
  1371. list_pg = list_pg->next) {
  1372. pg = list_entry (list_pg, struct amf_pg, pg_list);
  1373. printf ("pg %x\n", pg);
  1374. for (list_pg_comp = pg->pg_comp_head.next;
  1375. list_pg_comp != &pg->pg_comp_head;
  1376. list_pg_comp = list_pg_comp->next) {
  1377. pg_comp = list_entry (list_pg_comp,
  1378. struct amf_pg_comp, list);
  1379. printf ("pg_comp %x\n", pg_comp);
  1380. printf ("remove component callback\n");
  1381. csi_comp_remove_callback (
  1382. pg_comp->comp,
  1383. pg_comp->csi);
  1384. }
  1385. }
  1386. }
  1387. }
  1388. #endif
  1389. char csi_number = 0;
  1390. void csi_unit_create (struct amf_unit *unit, struct amf_si *si,
  1391. struct amf_csi **csi_out)
  1392. {
  1393. struct amf_csi *csi;
  1394. printf ("creating csi for si %p unit %p\n", si, unit);
  1395. si->csi_count += 1;
  1396. csi = malloc (sizeof (struct amf_csi));
  1397. list_init (&csi->list);
  1398. list_init (&csi->csi_list);
  1399. list_add (&csi->list, &si->csi_head);
  1400. list_add (&si->unit_list, &unit->si_head);
  1401. csi->si = si;
  1402. csi->unit = unit;
  1403. csi->pg_set = 0;
  1404. sprintf ((char *)csi->name.value, "CSI %d", csi_number);
  1405. csi->name.length = strlen ((char *)csi->name.value);
  1406. csi_number += 1;
  1407. *csi_out = csi;
  1408. }
  1409. void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si,
  1410. SaAmfHAStateT ha_state)
  1411. {
  1412. struct amf_csi *csi;
  1413. printf ("Assigning SI %s ", getSaNameT (&si->name));
  1414. printf ("to SU %s ", getSaNameT (&unit->name));
  1415. printf ("with hastate %s\n", hastate_ntoa (ha_state));
  1416. unit->requested_ha_state = ha_state;
  1417. csi_unit_create (unit, si, &csi);
  1418. csi_unit_set_callback (csi);
  1419. }
  1420. int unit_inservice_count (struct amf_group *group)
  1421. {
  1422. struct list_head *list;
  1423. struct amf_unit *unit;
  1424. int answer = 0;
  1425. for (list = group->unit_head.next;
  1426. list != &group->unit_head;
  1427. list = list->next) {
  1428. unit = list_entry (list,
  1429. struct amf_unit, unit_list);
  1430. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1431. answer += 1;
  1432. }
  1433. }
  1434. return (answer);
  1435. }
  1436. int comp_inservice_count (struct amf_unit *unit)
  1437. {
  1438. struct list_head *list;
  1439. struct amf_comp *comp;
  1440. int answer = 0;
  1441. for (list = unit->comp_head.next;
  1442. list != &unit->comp_head;
  1443. list = list->next) {
  1444. comp = list_entry (list, struct amf_comp, comp_list);
  1445. if (comp->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1446. answer += 1;
  1447. }
  1448. }
  1449. return (answer);
  1450. }
  1451. int si_count (struct amf_group *group)
  1452. {
  1453. struct list_head *list_si;
  1454. struct amf_si *si;
  1455. int answer = 0;
  1456. for (list_si = group->si_head.next;
  1457. list_si != &group->si_head;
  1458. list_si = list_si->next) {
  1459. si = list_entry (list_si,
  1460. struct amf_si, list);
  1461. answer += 1;
  1462. }
  1463. return (answer);
  1464. }
  1465. static inline int div_round (int a, int b)
  1466. {
  1467. int res;
  1468. res = a / b;
  1469. if ((a % b) != 0)
  1470. res++;
  1471. return res;
  1472. }
  1473. void assign_nm_active (struct amf_group *group, int su_units_assign)
  1474. {
  1475. struct amf_unit *unit;
  1476. struct amf_si *si;
  1477. struct list_head *list_si;
  1478. struct list_head *list_unit;
  1479. int assigned = 0;
  1480. int assign_per_su = 0;
  1481. int total_assigned = 0;
  1482. assign_per_su = si_count (group);
  1483. assign_per_su = div_round (assign_per_su, su_units_assign);
  1484. if (assign_per_su > group->maximum_active_instances) {
  1485. assign_per_su = group->maximum_active_instances;
  1486. }
  1487. list_si = group->si_head.next;
  1488. list_unit = group->unit_head.next;
  1489. while (list_unit != &group->unit_head) {
  1490. unit = list_entry (list_unit,
  1491. struct amf_unit, unit_list);
  1492. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1493. list_unit = list_unit->next;
  1494. continue; /* Not in service */
  1495. }
  1496. assigned = 0;
  1497. while (list_si != &group->si_head &&
  1498. assigned < assign_per_su &&
  1499. total_assigned < si_count (group)) {
  1500. si = list_entry (list_si, struct amf_si, list);
  1501. assigned += 1;
  1502. total_assigned += 1;
  1503. ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
  1504. list_si = list_si->next;
  1505. }
  1506. list_unit = list_unit->next;
  1507. }
  1508. }
  1509. void assign_nm_standby (struct amf_group *group, int units_assign_standby)
  1510. {
  1511. struct amf_unit *unit;
  1512. struct amf_si *si;
  1513. struct list_head *list_si;
  1514. struct list_head *list_unit;
  1515. int assigned = 0;
  1516. int assign_per_su = 0;
  1517. if (units_assign_standby == 0) {
  1518. return;
  1519. }
  1520. assign_per_su = si_count (group);
  1521. assign_per_su = div_round (assign_per_su, units_assign_standby);
  1522. if (assign_per_su > group->maximum_standby_instances) {
  1523. assign_per_su = group->maximum_standby_instances;
  1524. }
  1525. list_si = group->si_head.next;
  1526. list_unit = group->unit_head.next;
  1527. while (list_unit != &group->unit_head) {
  1528. unit = list_entry (list_unit,
  1529. struct amf_unit, unit_list);
  1530. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE ||
  1531. unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1532. list_unit = list_unit->next;
  1533. continue; /* Not available for assignment */
  1534. }
  1535. assigned = 0;
  1536. while (list_si != &group->si_head && assigned < assign_per_su) {
  1537. si = list_entry (list_si, struct amf_si, list);
  1538. assigned += 1;
  1539. ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1540. list_si = list_si->next;
  1541. }
  1542. list_unit = list_unit->next;
  1543. }
  1544. }
  1545. void assign_nm_spare (struct amf_group *group)
  1546. {
  1547. struct amf_unit *unit;
  1548. struct list_head *list;
  1549. for (list = group->unit_head.next;
  1550. list != &group->unit_head;
  1551. list = list->next) {
  1552. unit = list_entry (list,
  1553. struct amf_unit, unit_list);
  1554. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1555. (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
  1556. unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
  1557. printf ("Assigning to SU %s with SPARE\n",
  1558. getSaNameT (&unit->name));
  1559. }
  1560. }
  1561. }
  1562. void clear_requested_ha_state (struct amf_group *group)
  1563. {
  1564. struct list_head *list;
  1565. struct amf_unit *unit;
  1566. for (list = group->unit_head.next;
  1567. list != &group->unit_head;
  1568. list = list->next) {
  1569. unit = list_entry (list,
  1570. struct amf_unit, unit_list);
  1571. unit->requested_ha_state = 0;
  1572. }
  1573. csi_number = 0;
  1574. }
  1575. void assign_sis (struct amf_group *group)
  1576. {
  1577. int active_sus_needed;
  1578. int standby_sus_needed;
  1579. int inservice_count;
  1580. int units_for_standby;
  1581. int units_for_active;
  1582. int ii_spare;
  1583. int su_active_assign;
  1584. int su_standby_assign;
  1585. int su_spare_assign;
  1586. clear_requested_ha_state (group);
  1587. /*
  1588. * Number of SUs to assign to active or standby state
  1589. */
  1590. inservice_count = (float)unit_inservice_count (group);
  1591. active_sus_needed = div_round (si_count(group),
  1592. group->maximum_active_instances);
  1593. standby_sus_needed = div_round (si_count(group),
  1594. group->maximum_standby_instances);
  1595. units_for_active = inservice_count - group->preferred_standby_units;
  1596. if (units_for_active < 0) {
  1597. units_for_active = 0;
  1598. }
  1599. units_for_standby = inservice_count - group->preferred_active_units;
  1600. if (units_for_standby < 0) {
  1601. units_for_standby = 0;
  1602. }
  1603. ii_spare = inservice_count - group->preferred_active_units - group->preferred_standby_units;
  1604. if (ii_spare < 0) {
  1605. ii_spare = 0;
  1606. }
  1607. /*
  1608. * Determine number of active and standby service units
  1609. * to assign based upon reduction procedure
  1610. */
  1611. if ((inservice_count - active_sus_needed) < 0) {
  1612. printf ("assignment VI - partial assignment with SIs drop outs\n");
  1613. su_active_assign = active_sus_needed;
  1614. su_standby_assign = 0;
  1615. su_spare_assign = 0;
  1616. } else
  1617. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  1618. printf ("assignment V - partial assignment with reduction of standby units\n");
  1619. su_active_assign = active_sus_needed;
  1620. if (standby_sus_needed > units_for_standby) {
  1621. su_standby_assign = units_for_standby;
  1622. } else {
  1623. su_standby_assign = standby_sus_needed;
  1624. }
  1625. su_spare_assign = 0;
  1626. } else
  1627. if ((group->maximum_standby_instances * units_for_standby) <= si_count (group)) {
  1628. printf ("IV: full assignment with reduction of active service units\n");
  1629. su_active_assign = inservice_count - standby_sus_needed;
  1630. su_standby_assign = standby_sus_needed;
  1631. su_spare_assign = 0;
  1632. } else
  1633. if ((group->maximum_active_instances * units_for_active) <= si_count (group)) {
  1634. printf ("III: full assignment with reduction of standby service units\n");
  1635. su_active_assign = group->preferred_active_units;
  1636. su_standby_assign = units_for_standby;
  1637. su_spare_assign = 0;
  1638. } else
  1639. if (ii_spare == 0) {
  1640. printf ("II: full assignment with spare reduction\n");
  1641. su_active_assign = group->preferred_active_units;
  1642. su_standby_assign = group->preferred_standby_units;
  1643. su_spare_assign = 0;
  1644. } else {
  1645. printf ("I: full assignment with spares\n");
  1646. su_active_assign = group->preferred_active_units;
  1647. su_standby_assign = group->preferred_standby_units;
  1648. su_spare_assign = ii_spare;
  1649. }
  1650. printf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
  1651. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1652. assign_nm_active (group, su_active_assign);
  1653. assign_nm_standby (group, su_standby_assign);
  1654. }
  1655. void readiness_state_unit_set (struct amf_unit *unit, OpenaisCfgReadinessStateT readiness_state)
  1656. {
  1657. printf ("Assigning unit %s ",
  1658. getSaNameT (&unit->name));
  1659. printf ("readiness state %s\n",
  1660. readinessstate_ntoa (readiness_state));
  1661. unit->readiness_state = readiness_state;
  1662. assign_sis (unit->amf_group);
  1663. }
  1664. void presence_state_unit_set (struct amf_unit *unit, OpenaisCfgPresenceStateT presence_state)
  1665. {
  1666. printf ("Setting service unit presence state %s\n",
  1667. presencestate_ntoa (presence_state));
  1668. }
  1669. static void escalation_policy_restart (struct amf_comp *comp)
  1670. {
  1671. printf ("escalation_policy_restart %d\n", comp->unit->escalation_level);
  1672. printf ("escalation policy restart uninsint %p\n", comp);
  1673. presence_state_comp_set (
  1674. comp,
  1675. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  1676. operational_state_comp_set (
  1677. comp,
  1678. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1679. switch (comp->unit->escalation_level) {
  1680. case ESCALATION_LEVEL_NO_ESCALATION:
  1681. comp_restart (comp);
  1682. break;
  1683. case ESCALATION_LEVEL_ONE:
  1684. comp_restart (comp);
  1685. break;
  1686. case ESCALATION_LEVEL_TWO:
  1687. break;
  1688. case ESCALATION_LEVEL_THREE:
  1689. break;
  1690. }
  1691. }
  1692. static void escalation_policy_cleanup (struct amf_comp *comp)
  1693. {
  1694. // escalation_timer_start (comp);
  1695. switch (comp->unit->escalation_level) {
  1696. case ESCALATION_LEVEL_NO_ESCALATION:
  1697. comp->unit->restart_count += 1;
  1698. if (comp->unit->restart_count >= comp->unit->amf_group->component_restart_max) {
  1699. comp->unit->escalation_level = ESCALATION_LEVEL_ONE;
  1700. escalation_policy_cleanup (comp);
  1701. comp->unit->restart_count = 0;
  1702. return;
  1703. }
  1704. printf ("Escalation level 0 - restart component\n");
  1705. printf ("Cleaning up and restarting component.\n");
  1706. comp_cleanup (comp);
  1707. break;
  1708. case ESCALATION_LEVEL_ONE:
  1709. comp->unit->restart_count += 1;
  1710. if (comp->unit->restart_count >= comp->unit->amf_group->unit_restart_max) {
  1711. comp->unit->escalation_level = ESCALATION_LEVEL_TWO;
  1712. escalation_policy_cleanup (comp);
  1713. return;
  1714. }
  1715. printf ("Escalation level 1 - restart unit\n");
  1716. printf ("Cleaning up and restarting unit.\n");
  1717. unit_cleanup (comp->unit);
  1718. break;
  1719. case ESCALATION_LEVEL_TWO:
  1720. printf ("Escalation level TWO\n");
  1721. unit_cleanup (comp->unit);
  1722. // unit_terminate_failover (comp);
  1723. break;
  1724. case ESCALATION_LEVEL_THREE:
  1725. //TODO
  1726. break;
  1727. }
  1728. }
  1729. static void timer_function_healthcheck_timeout (
  1730. void *data)
  1731. {
  1732. struct healthcheck_active *healthcheck_active =
  1733. (struct healthcheck_active *)data;
  1734. printf ("timeout occured on healthcheck for component %s.\n",
  1735. getSaNameT (&healthcheck_active->comp->name));
  1736. escalation_policy_cleanup (healthcheck_active->comp);
  1737. }
  1738. void healthcheck_activate (struct healthcheck_active *healthcheck_active)
  1739. {
  1740. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1741. healthcheck_active->active = 1;
  1742. // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1743. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1744. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1745. res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
  1746. log_printf (LOG_LEVEL_NOTICE, "sending healthcheck to component %s\n",
  1747. getSaNameT (&healthcheck_active->comp->name));
  1748. res_lib_amf_healthcheckcallback.invocation =
  1749. invocation_create (
  1750. AMF_RESPONSE_HEALTHCHECKCALLBACK,
  1751. (void *)healthcheck_active);
  1752. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1753. &healthcheck_active->comp->name,
  1754. sizeof (SaNameT));
  1755. memcpy (&res_lib_amf_healthcheckcallback.key,
  1756. &healthcheck_active->key,
  1757. sizeof (SaAmfHealthcheckKeyT));
  1758. openais_conn_send_response (
  1759. openais_conn_partner_get (healthcheck_active->comp->conn),
  1760. &res_lib_amf_healthcheckcallback,
  1761. sizeof (struct res_lib_amf_healthcheckcallback));
  1762. poll_timer_delete (aisexec_poll_handle,
  1763. healthcheck_active->timer_healthcheck_duration);
  1764. poll_timer_add (aisexec_poll_handle,
  1765. healthcheck_active->healthcheck->maximum_duration,
  1766. (void *)healthcheck_active,
  1767. timer_function_healthcheck_timeout,
  1768. &healthcheck_active->timer_healthcheck_duration);
  1769. }
  1770. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active)
  1771. {
  1772. log_printf (LOG_LEVEL_NOTICE, "ZZZ deactivating healthcheck for component %s\n",
  1773. getSaNameT (&healthcheck_active->comp->name));
  1774. poll_timer_delete (aisexec_poll_handle,
  1775. healthcheck_active->timer_healthcheck_period);
  1776. poll_timer_delete (aisexec_poll_handle,
  1777. healthcheck_active->timer_healthcheck_duration);
  1778. invocation_destroy_by_data ((void *)healthcheck_active);
  1779. list_del (&healthcheck_active->list);
  1780. free (healthcheck_active);
  1781. }
  1782. static void timer_function_healthcheck_next (
  1783. void *data)
  1784. {
  1785. healthcheck_activate (data);
  1786. }
  1787. void healthcheck_unit_deactivate (
  1788. struct amf_unit *unit)
  1789. {
  1790. struct list_head *list;
  1791. struct list_head *key_list;
  1792. struct healthcheck_active *healthcheck_active;
  1793. struct amf_comp *comp;
  1794. for (list = unit->comp_head.next;
  1795. list != &unit->comp_head;
  1796. list = list->next) {
  1797. comp = list_entry (list, struct amf_comp, comp_list);
  1798. for (key_list = comp->healthcheck_list.next;
  1799. key_list != &comp->healthcheck_list;
  1800. key_list = key_list->next) {
  1801. healthcheck_active = list_entry (key_list,
  1802. struct healthcheck_active, list);
  1803. healthcheck_deactivate (healthcheck_active);
  1804. }
  1805. }
  1806. }
  1807. void healthcheck_unit_activate (
  1808. struct amf_unit *unit)
  1809. {
  1810. struct list_head *list;
  1811. struct list_head *key_list;
  1812. struct healthcheck_active *healthcheck_active;
  1813. struct amf_comp *comp;
  1814. for (list = unit->comp_head.next;
  1815. list != &unit->comp_head;
  1816. list = list->next) {
  1817. comp = list_entry (list, struct amf_comp, comp_list);
  1818. for (key_list = comp->healthcheck_list.next;
  1819. key_list != &comp->healthcheck_list;
  1820. key_list = key_list->next) {
  1821. healthcheck_active = list_entry (key_list,
  1822. struct healthcheck_active, list);
  1823. healthcheck_activate (healthcheck_active);
  1824. }
  1825. }
  1826. }
  1827. void operational_state_unit_set (
  1828. struct amf_unit *unit,
  1829. OpenaisCfgOperationalStateT operational_state)
  1830. {
  1831. if (operational_state == unit->operational_state) {
  1832. printf ("Not assigning service unit new operational state - same state\n");
  1833. return;
  1834. }
  1835. unit->operational_state = operational_state;
  1836. printf ("Service unit operational state set to %s\n",
  1837. operationalstate_ntoa (operational_state));
  1838. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1839. readiness_state_unit_set (unit,
  1840. OPENAIS_CFG_READINESSSTATE_INSERVICE);
  1841. /*
  1842. * Start healthcheck now
  1843. */
  1844. // TODO healthcheck_unit_activate (unit);
  1845. } else
  1846. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_DISABLED) {
  1847. readiness_state_unit_set (unit,
  1848. OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE);
  1849. // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1850. // healthcheck_unit_deactivate (unit);
  1851. }
  1852. }
  1853. static void message_handler_req_exec_amf_operational_state_comp_set (
  1854. void *message,
  1855. struct totem_ip_address *address)
  1856. {
  1857. struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
  1858. (struct req_exec_amf_operational_state_comp_set *)message;
  1859. struct amf_comp *comp;
  1860. struct amf_comp *comp_compare;
  1861. struct list_head *list;
  1862. int all_set = 1;
  1863. comp = find_comp (&req_exec_amf_operational_state_comp_set->name);
  1864. comp->operational_state = req_exec_amf_operational_state_comp_set->operational_state;
  1865. printf ("Setting component %s operational state to %s\n",
  1866. getSaNameT (&comp->name),
  1867. operationalstate_ntoa (comp->operational_state));
  1868. /*
  1869. * If all operational states are ENABLED, then SU should be ENABLED
  1870. */
  1871. for (list = comp->unit->comp_head.next;
  1872. list != &comp->unit->comp_head;
  1873. list = list->next) {
  1874. comp_compare = list_entry (list,
  1875. struct amf_comp, comp_list);
  1876. if (comp_compare->operational_state != OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1877. all_set = 0;
  1878. break;
  1879. }
  1880. }
  1881. if (all_set) {
  1882. operational_state_unit_set (comp->unit,
  1883. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1884. } else {
  1885. operational_state_unit_set (comp->unit,
  1886. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1887. }
  1888. readiness_state_comp_set (comp);
  1889. }
  1890. static void message_handler_req_exec_amf_presence_state_comp_set (
  1891. void *message,
  1892. struct totem_ip_address *address)
  1893. {
  1894. struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
  1895. (struct req_exec_amf_presence_state_comp_set *)message;
  1896. struct amf_comp *comp;
  1897. struct amf_comp *comp_compare;
  1898. struct list_head *list;
  1899. int all_set = 1;
  1900. comp = find_comp (&req_exec_amf_presence_state_comp_set->name);
  1901. if (req_exec_amf_presence_state_comp_set->presence_state == comp->presence_state) {
  1902. printf ("duplicate presence state set, not setting presence state\n");
  1903. return;
  1904. }
  1905. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1906. comp->conn = 0;
  1907. }
  1908. /*
  1909. * The restarting state can only be entered from the uninstantiated state
  1910. */
  1911. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING &&
  1912. comp->presence_state != OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1913. printf ("restart presence state set even though not in terminating state\n");
  1914. return;
  1915. }
  1916. comp->presence_state = req_exec_amf_presence_state_comp_set->presence_state;
  1917. if (comp->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING) {
  1918. printf ("SET TO RESTARTING instantiating now\n");
  1919. clc_instantiate (comp);
  1920. }
  1921. printf ("Setting component %s presence state %s\n",
  1922. getSaNameT (&comp->name),
  1923. presencestate_ntoa (comp->presence_state));
  1924. /*
  1925. * Restart components that are requested to enter the restarting presence state
  1926. */
  1927. /*
  1928. * If all comp presence states are INSTANTIATED, then SU should be instantated
  1929. */
  1930. for (list = comp->unit->comp_head.next;
  1931. list != &comp->unit->comp_head;
  1932. list = list->next) {
  1933. comp_compare = list_entry (list,
  1934. struct amf_comp, comp_list);
  1935. if (comp_compare->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  1936. all_set = 0;
  1937. break;
  1938. }
  1939. }
  1940. if (all_set) {
  1941. presence_state_unit_set (comp->unit,
  1942. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1943. }
  1944. }
  1945. static void message_handler_req_exec_amf_administrative_state_csi_set (
  1946. void *message,
  1947. struct totem_ip_address *address)
  1948. {
  1949. // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
  1950. // (struct req_exec_amf_administrative_state_csi_set *)message;
  1951. // TODO
  1952. }
  1953. static void message_handler_req_exec_amf_administrative_state_unit_set (
  1954. void *message,
  1955. struct totem_ip_address *address)
  1956. {
  1957. // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
  1958. // (struct req_exec_amf_administrative_state_unit_set *)message;
  1959. // TODO
  1960. }
  1961. static void message_handler_req_exec_amf_administrative_state_group_set (
  1962. void *message,
  1963. struct totem_ip_address *source)
  1964. {
  1965. // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
  1966. // (struct req_exec_amf_administrative_state_group_set *)message;
  1967. // TODO
  1968. }
  1969. /*
  1970. * Library Interface Implementation
  1971. */
  1972. static void message_handler_req_lib_amf_componentregister (
  1973. void *conn,
  1974. void *msg)
  1975. {
  1976. struct req_lib_amf_componentregister *req_lib_amf_componentregister =
  1977. (struct req_lib_amf_componentregister *)msg;
  1978. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1979. struct amf_comp *comp;
  1980. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  1981. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  1982. comp = find_comp (&req_lib_amf_componentregister->compName);
  1983. if (comp) {
  1984. presence_state_comp_set (comp,
  1985. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1986. operational_state_comp_set (comp,
  1987. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1988. comp->conn = conn;
  1989. amf_pd->comp = comp;
  1990. comp_healthcheck_activate (comp);
  1991. error = SA_AIS_OK;
  1992. }
  1993. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1994. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1995. res_lib_amf_componentregister.header.error = error;
  1996. openais_conn_send_response (conn, &res_lib_amf_componentregister,
  1997. sizeof (struct res_lib_amf_componentregister));
  1998. }
  1999. static void message_handler_req_lib_amf_componentunregister (
  2000. void *conn,
  2001. void *msg)
  2002. {
  2003. #ifdef COMPILE_OUT
  2004. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2005. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2006. struct iovec iovec;
  2007. struct amf_comp *component;
  2008. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  2009. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2010. req_exec_amf_componentunregister.header.id =
  2011. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2012. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2013. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2014. req_lib_amf_componentunregister,
  2015. sizeof (struct req_lib_amf_componentunregister));
  2016. component = find_comp (&req_lib_amf_componentunregister->compName);
  2017. if (component && component->registered && component->local) {
  2018. // component->probableCause = SA_AMF_NOT_RESPONDING;
  2019. }
  2020. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2021. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2022. assert (totempg_groups_mcast_joined (openais_group_handle,
  2023. &iovec, 1, TOTEMPG_AGREED) == 0);
  2024. #endif
  2025. }
  2026. static void message_handler_req_lib_amf_pmstart (
  2027. void *conn,
  2028. void *msg)
  2029. {
  2030. }
  2031. static void message_handler_req_lib_amf_pmstop (
  2032. void *conn,
  2033. void *msg)
  2034. {
  2035. }
  2036. static void message_handler_req_lib_amf_healthcheckstart (
  2037. void *conn, void *msg)
  2038. {
  2039. struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
  2040. (struct req_lib_amf_healthcheckstart *)msg;
  2041. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  2042. struct amf_healthcheck *healthcheck;
  2043. struct healthcheck_active *healthcheck_active;
  2044. struct amf_comp *comp;
  2045. SaAisErrorT error = SA_AIS_OK;
  2046. printf ("healthcheck start\n");
  2047. fflush (stdout);
  2048. healthcheck = find_healthcheck (&req_lib_amf_healthcheckstart->healthcheckKey);
  2049. if (healthcheck == 0) {
  2050. error = SA_AIS_ERR_NOT_EXIST;
  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. <<<<<<< .mine
  3567. struct req_lib_amf_readinessstateget *req_lib_amf_readinessstateget = (struct req_lib_amf_readinessstateget *)message;
  3568. =======
  3569. struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message;
  3570. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  3571. struct iovec iovec;
  3572. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  3573. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  3574. req_exec_amf_componentregister.header.id =
  3575. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER);
  3576. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  3577. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  3578. req_lib_amf_componentregister,
  3579. sizeof (struct req_lib_amf_componentregister));
  3580. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  3581. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  3582. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3583. return (0);
  3584. }
  3585. static void message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  3586. {
  3587. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  3588. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  3589. struct iovec iovec;
  3590. struct saAmfComponent *component;
  3591. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  3592. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  3593. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  3594. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  3595. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  3596. req_lib_amf_componentunregister,
  3597. sizeof (struct req_lib_amf_componentunregister));
  3598. component = findComponent (&req_lib_amf_componentunregister->compName);
  3599. if (component && component->registered && component->local) {
  3600. component->probableCause = SA_AMF_NOT_RESPONDING;
  3601. }
  3602. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  3603. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  3604. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3605. return (0);
  3606. }
  3607. static void message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3608. {
  3609. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  3610. >>>>>>> .r872
  3611. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  3612. struct amf_comp *component;
  3613. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_readinessstateget()\n");
  3614. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  3615. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  3616. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  3617. component = find_comp (&req_lib_amf_readinessstateget->compName);
  3618. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  3619. if (component) {
  3620. memcpy (&res_lib_amf_readinessstateget.readinessState,
  3621. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  3622. res_lib_amf_readinessstateget.header.error = SA_AIS_OK;
  3623. }
  3624. openais_conn_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  3625. return (0);
  3626. }
  3627. static void message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3628. void *message)
  3629. {
  3630. struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message;
  3631. <<<<<<< .mine
  3632. struct conn_info *inv_conn_info;
  3633. =======
  3634. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  3635. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  3636. if (amfProtectionGroup) {
  3637. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  3638. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3639. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  3640. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3641. break;
  3642. }
  3643. }
  3644. if (track == 0) {
  3645. grow_amf_track_table (conn_info, 1);
  3646. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3647. }
  3648. track->active = 1;
  3649. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  3650. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  3651. memcpy (&track->csiName,
  3652. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  3653. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  3654. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  3655. /*
  3656. * If SA_TRACK_CURRENT is specified, write out all current connections
  3657. */
  3658. } else {
  3659. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  3660. }
  3661. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  3662. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  3663. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  3664. if (amfProtectionGroup) {
  3665. res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK;
  3666. }
  3667. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  3668. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  3669. if (amfProtectionGroup &&
  3670. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  3671. protectiongroup_notification_send (conn_info,
  3672. track->notificationBufferAddress,
  3673. amfProtectionGroup,
  3674. 0,
  3675. 0,
  3676. SA_TRACK_CHANGES_ONLY);
  3677. track->trackFlags &= ~SA_TRACK_CURRENT;
  3678. }
  3679. return (0);
  3680. }
  3681. static void message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  3682. {
  3683. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  3684. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  3685. struct libamf_ci_trackentry *track = 0;
  3686. int i;
  3687. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  3688. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3689. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  3690. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  3691. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3692. }
  3693. }
  3694. if (track) {
  3695. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  3696. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  3697. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  3698. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  3699. list_del (&conn_info->conn_list);
  3700. }
  3701. }
  3702. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  3703. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  3704. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  3705. if (track) {
  3706. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  3707. }
  3708. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  3709. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  3710. return (0);
  3711. }
  3712. static void message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  3713. {
  3714. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  3715. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  3716. struct iovec iovec;
  3717. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  3718. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  3719. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  3720. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  3721. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  3722. req_lib_amf_errorreport,
  3723. sizeof (struct req_lib_amf_errorreport));
  3724. iovec.iov_base = (char *)&req_exec_amf_errorreport;
  3725. iovec.iov_len = sizeof (req_exec_amf_errorreport);
  3726. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3727. return (0);
  3728. }
  3729. static void message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  3730. {
  3731. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  3732. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  3733. struct iovec iovec;
  3734. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  3735. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  3736. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  3737. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  3738. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  3739. req_lib_amf_errorcancelall,
  3740. sizeof (struct req_lib_amf_errorcancelall));
  3741. iovec.iov_base = (char *)&req_exec_amf_errorcancelall;
  3742. iovec.iov_len = sizeof (req_exec_amf_errorcancelall);
  3743. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  3744. return (0);
  3745. }
  3746. static void message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3747. void *message)
  3748. {
  3749. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  3750. struct conn_info *inv_conn_info = NULL;
  3751. >>>>>>> .r872
  3752. int interface;
  3753. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_stoppingcomplete()\n");
  3754. req_lib_amf_invocation_get_and_destroy (req_lib_amf_stoppingcomplete->invocation,
  3755. &interface, &inv_conn_info);
  3756. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  3757. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  3758. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  3759. return (0);
  3760. }
  3761. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  3762. struct req_lib_amf_response *req_lib_amf_response) {
  3763. if (req_lib_amf_response->error == SA_AIS_OK) {
  3764. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  3765. conn_info->component->healthcheck_outstanding = 0;
  3766. }
  3767. }
  3768. static void message_handler_req_lib_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  3769. {
  3770. struct req_lib_amf_componentcapabilitymodelget *req_lib_amf_componentcapabilitymodelget = (struct req_lib_amf_componentcapabilitymodelget *)message;
  3771. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  3772. struct amf_comp *component;
  3773. SaAisErrorT error = SA_AIS_OK;
  3774. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentcapabilitymodelget()\n");
  3775. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  3776. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_lib_amf_componentcapabilitymodelget->compName));
  3777. component = find_comp (&req_lib_amf_componentcapabilitymodelget->compName);
  3778. if (component && component->registered) {
  3779. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  3780. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  3781. } else {
  3782. error = SA_ERR_NOT_EXIST;
  3783. }
  3784. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  3785. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  3786. res_lib_amf_componentcapabilitymodelget.header.error = error;
  3787. openais_conn_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  3788. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  3789. return (0);
  3790. }
  3791. static char disabled_unlocked_state_text[6][64] = {
  3792. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  3793. "AMF_DISABLED_UNLOCKED_FAILED",
  3794. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  3795. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  3796. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  3797. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  3798. };
  3799. static char *disabledunlockedstate_ntoa (int state)
  3800. {
  3801. static char str[64];
  3802. if (state >= 0 && state < 6) {
  3803. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  3804. }else{
  3805. sprintf (str, "Unknown(%d)", state);
  3806. }
  3807. return (str);
  3808. }
  3809. static char enabled_unlocked_state_text[7][64] = {
  3810. "AMF_ENABLED_UNLOCKED_INITIAL",
  3811. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  3812. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  3813. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  3814. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  3815. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  3816. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  3817. };
  3818. static char *enabledunlockedstate_ntoa (int state)
  3819. {
  3820. static char str[64];
  3821. if (state >= 0 && state < 7) {
  3822. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  3823. }else{
  3824. sprintf (str, "Unknown(%d)", state);
  3825. }
  3826. return (str);
  3827. }
  3828. #endif
  3829. static char presence_state_text[8][32] = {
  3830. "unknown",
  3831. "uninstantiated",
  3832. "instantiating",
  3833. "instantiated",
  3834. "terminating",
  3835. "restarting",
  3836. "instantion_failed",
  3837. "terminiation_failed"
  3838. };
  3839. static char *presencestate_ntoa (OpenaisCfgPresenceStateT state)
  3840. {
  3841. static char str[32];
  3842. if (state > 0 && state < 9) {
  3843. sprintf (str, "%s(%d)", presence_state_text[state], state);
  3844. }else{
  3845. sprintf (str, "Unknown(%d)", state);
  3846. }
  3847. return (str);
  3848. }
  3849. static char operational_state_text[4][64] = {
  3850. "Unknown",
  3851. "enabled",
  3852. "disabled"
  3853. };
  3854. static char *operationalstate_ntoa (OpenaisCfgOperationalStateT state)
  3855. {
  3856. static char str[32];
  3857. if (state > 0 && state < 3) {
  3858. sprintf (str, "%s(%d)", operational_state_text[state], state);
  3859. }else{
  3860. sprintf (str, "Unknown(%d)", state);
  3861. }
  3862. return (str);
  3863. }
  3864. static char readiness_state_text[4][32] = {
  3865. "Unknown",
  3866. "out of service",
  3867. "in service",
  3868. "quiesced",
  3869. };
  3870. static char *readinessstate_ntoa (int state)
  3871. {
  3872. static char str[32];
  3873. if (state > 0 && state < 4) {
  3874. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  3875. }else{
  3876. sprintf (str, "Unknown(%d)", state);
  3877. }
  3878. return (str);
  3879. }
  3880. static char ha_state_text[4][32] = {
  3881. "Unknown",
  3882. "active",
  3883. "standby",
  3884. "quiesced",
  3885. };
  3886. static char *hastate_ntoa (SaAmfHAStateT state)
  3887. {
  3888. static char str[32];
  3889. if (state > 0 && state < 4) {
  3890. sprintf (str, "%s(%d)", ha_state_text[state], state);
  3891. }else{
  3892. sprintf (str, "Unknown(%d)", state);
  3893. }
  3894. return (str);
  3895. }
  3896. #ifdef COMPILE_OUT
  3897. static void amf_dump_comp (struct amf_comp *component ,void *data)
  3898. {
  3899. char name[64];
  3900. int level = LOG_LEVEL_NOTICE;
  3901. data = NULL;
  3902. log_printf (level, "----------------\n" );
  3903. log_printf (level, "registered = %d\n" ,component->registered);
  3904. log_printf (level, "local = %d\n" ,component->local );
  3905. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  3906. memset (name, 0 , sizeof(name));
  3907. memcpy (name, component->name.value, component->name.length);
  3908. log_printf (level, "name = %s\n" ,name );
  3909. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  3910. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  3911. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  3912. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  3913. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  3914. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  3915. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  3916. }
  3917. void amf_dump ( )
  3918. {
  3919. enumerate_components (amf_dump_comp, NULL);
  3920. fflush (stderr);
  3921. return;
  3922. }
  3923. #endif