amf.c 150 KB

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