amf.c 150 KB

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