amf.c 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020
  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. printf ("clc_command_run()\n");
  468. pid = fork();
  469. if (pid == -1) {
  470. printf ("Couldn't fork process %s\n", strerror (errno));
  471. return (0);
  472. }
  473. if (pid) {
  474. waiting = 1;
  475. printf ("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. printf ("running command '%s' with environment:\n", cmd);
  540. printf ("0 %s\n", envp[0]);
  541. printf ("1 %s\n", envp[1]);
  542. printf ("2 %s\n", envp[2]);
  543. printf ("3 %s\n", envp[3]);
  544. printf ("4 %s\n", envp[4]);
  545. res = execve (cmd, argv, envp);
  546. if (res == -1) {
  547. printf ("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. printf ("clc_cli_instaniate\n");
  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. printf ("clc_instantiate_callback\n");
  602. return (0);
  603. }
  604. int clc_csi_set_callback (struct amf_comp *comp)
  605. {
  606. printf ("clc_csi_set_callback\n");
  607. return (0);
  608. }
  609. /*
  610. * Terminate possible operations
  611. */
  612. int clc_cli_terminate (struct amf_comp *comp)
  613. {
  614. printf ("clc_cli_terminate\n");
  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. printf ("clc_terminate_callback %p\n", comp->conn);
  622. if (comp->presence_state != SA_AMF_PRESENCE_INSTANTIATED) {
  623. printf ("component terminated but not instantiated %s - %d\n",
  624. getSaNameT (&comp->name), comp->presence_state);
  625. assert (0);
  626. return (0);
  627. }
  628. printf ("component name terminating %s\n", getSaNameT (&comp->name));
  629. printf ("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. printf ("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. printf ("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. printf ("clc_cli_instaniate\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. printf ("clc_cli_cleanup_local\n");
  685. return (0);
  686. }
  687. int clc_instantiate (struct amf_comp *comp)
  688. {
  689. int res;
  690. printf ("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. printf ("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. printf ("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. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  724. if (objdb->object_find (
  725. OBJECT_PARENT_HANDLE,
  726. "amf",
  727. strlen ("amf"),
  728. &object_service_handle) == 0) {
  729. value = NULL;
  730. if ( !objdb->object_key_get (object_service_handle,
  731. "mode",
  732. strlen ("mode"),
  733. (void *)&value,
  734. NULL) && value) {
  735. if (strcmp (value, "enabled") == 0) {
  736. enabled = 1;
  737. } else
  738. if (strcmp (value, "disabled") == 0) {
  739. enabled = 0;
  740. }
  741. }
  742. }
  743. if (enabled) {
  744. res = openais_amf_config_read (&error_string);
  745. if (res == -1) {
  746. log_printf (LOG_LEVEL_ERROR, error_string);
  747. return res;
  748. }
  749. clc_instantiate_all ();
  750. }
  751. return (0);
  752. }
  753. static void amf_confchg_fn (
  754. enum totem_configuration_type configuration_type,
  755. struct totem_ip_address *member_list, int member_list_entries,
  756. struct totem_ip_address *left_list, int left_list_entries,
  757. struct totem_ip_address *joined_list, int joined_list_entries,
  758. struct memb_ring_id *ring_id)
  759. {
  760. #ifdef COMPILE_OUT
  761. int i;
  762. 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);
  763. recovery = 1;
  764. /*
  765. * If node join, component register
  766. */
  767. if ( joined_list_entries > 0 ) {
  768. enumerate_components (amf_confchg_njoin, NULL);
  769. }
  770. /*
  771. * If node leave, component unregister
  772. */
  773. for (i = 0; i<left_list_entries ; i++) {
  774. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  775. }
  776. #ifdef TODO
  777. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  778. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  779. recovery = 0;
  780. }
  781. #endif
  782. #endif
  783. }
  784. int amf_lib_exit_fn (void *conn)
  785. {
  786. struct amf_comp *comp;
  787. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  788. comp = amf_pd->comp;
  789. if (comp) {
  790. comp->conn = 0;
  791. printf ("setting in exit fn to uninst for comp %p\n", comp);
  792. presence_state_comp_set (
  793. comp,
  794. SA_AMF_PRESENCE_UNINSTANTIATED);
  795. operational_state_comp_set (
  796. comp,
  797. SA_AMF_OPERATIONAL_DISABLED);
  798. comp_healthcheck_deactivate (comp);
  799. }
  800. return (0);
  801. }
  802. static int amf_lib_init_fn (void *conn)
  803. {
  804. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize availability management framework service.\n");
  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. printf ("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. printf ("inputs to readiness_state_comp_set\n");
  1148. printf ("\tunit readiness state %s\n",
  1149. readinessstate_ntoa (comp->unit->readiness_state));
  1150. printf ("\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. printf ("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. printf("\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. printf("\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;
  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. printf ("assigning SI %s to ",
  1305. getSaNameT (&si->name));
  1306. printf ("SU %s for components:\n",
  1307. getSaNameT (&unit->name));
  1308. /*
  1309. ** for each component in SU, find a CSI in the SI with the same type
  1310. */
  1311. for (complist = unit->comp_head.next;
  1312. complist != &unit->comp_head;
  1313. complist = complist->next) {
  1314. comp = list_entry (complist, struct amf_comp, comp_list);
  1315. printf ("\t%s\n", getSaNameT (&comp->name));
  1316. int no_of_csi_types = 0;
  1317. for (typenamelist = comp->csi_type_name_head.next;
  1318. typenamelist != &comp->csi_type_name_head;
  1319. typenamelist = typenamelist->next) {
  1320. type_name = list_entry (typenamelist, struct amf_comp_csi_type_name, list);
  1321. no_of_csi_types++;
  1322. int no_of_assignments = 0;
  1323. for (csilist = si->csi_head.next;
  1324. csilist != &si->csi_head;
  1325. csilist = csilist->next) {
  1326. csi = list_entry (csilist, struct amf_csi, csi_list);
  1327. if (!memcmp(csi->type_name.value, type_name->name.value, type_name->name.length)) {
  1328. csi_comp_set_callback (comp, csi, pg);
  1329. no_of_assignments++;
  1330. }
  1331. }
  1332. if (no_of_assignments == 0) {
  1333. printf ("\t No CSIs of type %s configured?!!\n",
  1334. getSaNameT (&type_name->name));
  1335. }
  1336. }
  1337. if (no_of_csi_types == 0) {
  1338. printf ("\t No CSI types configured for %s ?!!\n",
  1339. getSaNameT (&comp->name));
  1340. }
  1341. }
  1342. }
  1343. void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
  1344. {
  1345. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  1346. struct csi_remove_callback_data *csi_remove_callback_data;
  1347. printf ("\t%s\n",
  1348. getSaNameT (&comp->name));
  1349. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1350. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1351. res_lib_amf_csiremovecallback.header.error = SA_AIS_OK;
  1352. csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
  1353. assert (csi_remove_callback_data); // TODO failure here of malloc
  1354. csi_remove_callback_data->csi = csi;
  1355. res_lib_amf_csiremovecallback.invocation =
  1356. invocation_create (
  1357. AMF_RESPONSE_CSIREMOVECALLBACK,
  1358. csi_remove_callback_data);
  1359. memcpy (&res_lib_amf_csiremovecallback.compName,
  1360. &comp->name, sizeof (SaNameT));
  1361. memcpy (&res_lib_amf_csiremovecallback.csiName,
  1362. &csi->name, sizeof (SaNameT));
  1363. res_lib_amf_csiremovecallback.csiFlags = 0;
  1364. openais_conn_send_response (
  1365. openais_conn_partner_get (comp->conn),
  1366. &res_lib_amf_csiremovecallback,
  1367. sizeof (struct res_lib_amf_csiremovecallback));
  1368. }
  1369. extern struct list_head amf_groupHead;
  1370. int clc_instantiate_all (void) {
  1371. struct list_head *list_group;
  1372. struct amf_group *group;
  1373. struct list_head *list_unit;
  1374. struct amf_unit *unit;
  1375. struct list_head *list_comp;
  1376. struct amf_comp *comp;
  1377. for (list_group = amf_groupHead.next;
  1378. list_group != &amf_groupHead;
  1379. list_group = list_group->next) {
  1380. group = list_entry (list_group,
  1381. struct amf_group, group_list);
  1382. for (list_unit = group->unit_head.next;
  1383. list_unit != &group->unit_head;
  1384. list_unit = list_unit->next) {
  1385. unit = list_entry (list_unit,
  1386. struct amf_unit, unit_list);
  1387. for (list_comp = unit->comp_head.next;
  1388. list_comp != &unit->comp_head;
  1389. list_comp = list_comp->next) {
  1390. comp = list_entry (list_comp,
  1391. struct amf_comp, comp_list);
  1392. if (strlen ((char *)comp->instantiate_cmd)) {
  1393. clc_instantiate (comp);
  1394. }
  1395. }
  1396. }
  1397. }
  1398. return (0);
  1399. }
  1400. void comp_terminate (struct amf_comp *comp)
  1401. {
  1402. clc_terminate (comp);
  1403. }
  1404. void unit_terminate (struct amf_unit *unit)
  1405. {
  1406. struct list_head *list_comp;
  1407. struct amf_comp *comp;
  1408. for (list_comp = unit->comp_head.next;
  1409. list_comp != &unit->comp_head;
  1410. list_comp = list_comp->next) {
  1411. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1412. clc_terminate (comp);
  1413. }
  1414. }
  1415. void comp_cleanup (struct amf_comp *comp)
  1416. {
  1417. clc_cleanup (comp);
  1418. }
  1419. void unit_cleanup (struct amf_unit *unit)
  1420. {
  1421. struct list_head *list_comp;
  1422. struct amf_comp *comp;
  1423. for (list_comp = unit->comp_head.next;
  1424. list_comp != &unit->comp_head;
  1425. list_comp = list_comp->next) {
  1426. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1427. clc_cleanup (comp);
  1428. }
  1429. }
  1430. void comp_restart (struct amf_comp *comp)
  1431. {
  1432. presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1433. }
  1434. void unit_restart (struct amf_unit *unit)
  1435. {
  1436. struct list_head *list_comp;
  1437. struct amf_comp *comp;
  1438. for (list_comp = unit->comp_head.next;
  1439. list_comp != &unit->comp_head;
  1440. list_comp = list_comp->next) {
  1441. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1442. presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1443. }
  1444. }
  1445. void clc_unit_instantiate (struct amf_unit *unit)
  1446. {
  1447. struct list_head *list_comp;
  1448. struct amf_comp *comp;
  1449. printf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
  1450. for (list_comp = unit->comp_head.next;
  1451. list_comp != &unit->comp_head;
  1452. list_comp = list_comp->next) {
  1453. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1454. clc_instantiate (comp);
  1455. }
  1456. }
  1457. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1458. {
  1459. struct list_head *list_si;
  1460. struct list_head *list_csi;
  1461. struct list_head *list_comp;
  1462. struct amf_si *si;
  1463. struct amf_csi *csi;
  1464. struct amf_comp *comp;
  1465. for (list_si = unit->si_head.next;
  1466. list_si != &unit->si_head;
  1467. list_si = list_si->next) {
  1468. si = list_entry (list_si, struct amf_si, unit_list);
  1469. for (list_csi = si->csi_head.next;
  1470. list_csi != &si->csi_head;
  1471. list_csi = list_csi->next) {
  1472. csi = list_entry (list_csi, struct amf_csi, csi_list);
  1473. for (list_comp = csi->unit->comp_head.next;
  1474. list_comp != &csi->unit->comp_head;
  1475. list_comp = list_comp->next) {
  1476. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1477. }
  1478. }
  1479. }
  1480. }
  1481. // THIS MIGHT BE GOOD FOR SOMEPTHING ELSE
  1482. #ifdef COMPILE_OUT
  1483. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1484. {
  1485. struct list_head *list_comp;
  1486. struct list_head *list_si;
  1487. struct list_head *list_csi;
  1488. struct list_head *list_pg;
  1489. struct list_head *list_pg_comp;
  1490. struct amf_comp *comp;
  1491. struct amf_csi *csi;
  1492. struct amf_si *si;
  1493. struct amf_pg *pg;
  1494. struct amf_pg_comp *pg_comp;
  1495. for (list_si = unit->si_head.next;
  1496. list_si != &unit->si_head;
  1497. list_si = list_si->next) {
  1498. si = list_entry (list_si, struct amf_si, unit_list);
  1499. for (list_pg = si->pg_head.next;
  1500. list_pg != &si->pg_head;
  1501. list_pg = list_pg->next) {
  1502. pg = list_entry (list_pg, struct amf_pg, pg_list);
  1503. printf ("pg %x\n", pg);
  1504. for (list_pg_comp = pg->pg_comp_head.next;
  1505. list_pg_comp != &pg->pg_comp_head;
  1506. list_pg_comp = list_pg_comp->next) {
  1507. pg_comp = list_entry (list_pg_comp,
  1508. struct amf_pg_comp, list);
  1509. printf ("pg_comp %x\n", pg_comp);
  1510. printf ("remove component callback\n");
  1511. csi_comp_remove_callback (
  1512. pg_comp->comp,
  1513. pg_comp->csi);
  1514. }
  1515. }
  1516. }
  1517. }
  1518. #endif
  1519. char csi_number = 0;
  1520. void csi_unit_create (struct amf_unit *unit, struct amf_si *si,
  1521. struct amf_csi **csi_out)
  1522. {
  1523. struct amf_csi *csi;
  1524. printf ("creating csi for si %p unit %p\n", si, unit);
  1525. si->csi_count += 1;
  1526. csi = malloc (sizeof (struct amf_csi));
  1527. list_init (&csi->csi_list);
  1528. list_add (&csi->csi_list, &si->csi_head);
  1529. list_add (&si->unit_list, &unit->si_head);
  1530. csi->si = si;
  1531. csi->unit = unit;
  1532. csi->pg_set = 0;
  1533. sprintf ((char *)csi->name.value, "CSI %d", csi_number);
  1534. csi->name.length = strlen ((char *)csi->name.value);
  1535. csi_number += 1;
  1536. *csi_out = csi;
  1537. }
  1538. void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si,
  1539. SaAmfHAStateT ha_state)
  1540. {
  1541. printf ("Assigning SI %s ", getSaNameT (&si->name));
  1542. printf ("to SU %s ", getSaNameT (&unit->name));
  1543. printf ("with hastate %s\n", hastate_ntoa (ha_state));
  1544. unit->requested_ha_state = ha_state;
  1545. csi_unit_set_callback (unit, si);
  1546. }
  1547. int unit_inservice_count (struct amf_group *group)
  1548. {
  1549. struct list_head *list;
  1550. struct amf_unit *unit;
  1551. int answer = 0;
  1552. for (list = group->unit_head.next;
  1553. list != &group->unit_head;
  1554. list = list->next) {
  1555. unit = list_entry (list,
  1556. struct amf_unit, unit_list);
  1557. if (unit->readiness_state == SA_AMF_READINESS_IN_SERVICE) {
  1558. answer += 1;
  1559. }
  1560. }
  1561. return (answer);
  1562. }
  1563. int comp_inservice_count (struct amf_unit *unit)
  1564. {
  1565. struct list_head *list;
  1566. struct amf_comp *comp;
  1567. int answer = 0;
  1568. for (list = unit->comp_head.next;
  1569. list != &unit->comp_head;
  1570. list = list->next) {
  1571. comp = list_entry (list, struct amf_comp, comp_list);
  1572. if (comp->readiness_state == SA_AMF_READINESS_IN_SERVICE) {
  1573. answer += 1;
  1574. }
  1575. }
  1576. return (answer);
  1577. }
  1578. int si_count (struct amf_group *group)
  1579. {
  1580. struct list_head *list_si;
  1581. struct amf_si *si;
  1582. int answer = 0;
  1583. for (list_si = group->si_head.next;
  1584. list_si != &group->si_head;
  1585. list_si = list_si->next) {
  1586. si = list_entry (list_si, struct amf_si, si_list);
  1587. answer += 1;
  1588. }
  1589. return (answer);
  1590. }
  1591. static inline int div_round (int a, int b)
  1592. {
  1593. int res;
  1594. res = a / b;
  1595. if ((a % b) != 0)
  1596. res++;
  1597. return res;
  1598. }
  1599. void assign_nm_active (struct amf_group *group, int su_units_assign)
  1600. {
  1601. struct amf_unit *unit;
  1602. struct amf_si *si;
  1603. struct list_head *list_si;
  1604. struct list_head *list_unit;
  1605. int assigned = 0;
  1606. int assign_per_su = 0;
  1607. int total_assigned = 0;
  1608. assign_per_su = si_count (group);
  1609. assign_per_su = div_round (assign_per_su, su_units_assign);
  1610. if (assign_per_su > group->maximum_active_instances) {
  1611. assign_per_su = group->maximum_active_instances;
  1612. }
  1613. list_si = group->si_head.next;
  1614. list_unit = group->unit_head.next;
  1615. while (list_unit != &group->unit_head) {
  1616. unit = list_entry (list_unit,
  1617. struct amf_unit, unit_list);
  1618. if (unit->readiness_state != SA_AMF_READINESS_IN_SERVICE) {
  1619. list_unit = list_unit->next;
  1620. continue; /* Not in service */
  1621. }
  1622. assigned = 0;
  1623. while (list_si != &group->si_head &&
  1624. assigned < assign_per_su &&
  1625. total_assigned < si_count (group)) {
  1626. si = list_entry (list_si, struct amf_si, si_list);
  1627. assigned += 1;
  1628. total_assigned += 1;
  1629. ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
  1630. list_si = list_si->next;
  1631. }
  1632. list_unit = list_unit->next;
  1633. }
  1634. }
  1635. void assign_nm_standby (struct amf_group *group, int units_assign_standby)
  1636. {
  1637. struct amf_unit *unit;
  1638. struct amf_si *si;
  1639. struct list_head *list_si;
  1640. struct list_head *list_unit;
  1641. int assigned = 0;
  1642. int assign_per_su = 0;
  1643. if (units_assign_standby == 0) {
  1644. return;
  1645. }
  1646. assign_per_su = si_count (group);
  1647. assign_per_su = div_round (assign_per_su, units_assign_standby);
  1648. if (assign_per_su > group->maximum_standby_instances) {
  1649. assign_per_su = group->maximum_standby_instances;
  1650. }
  1651. list_si = group->si_head.next;
  1652. list_unit = group->unit_head.next;
  1653. while (list_unit != &group->unit_head) {
  1654. unit = list_entry (list_unit,
  1655. struct amf_unit, unit_list);
  1656. if (unit->readiness_state != SA_AMF_READINESS_IN_SERVICE ||
  1657. unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1658. list_unit = list_unit->next;
  1659. continue; /* Not available for assignment */
  1660. }
  1661. assigned = 0;
  1662. while (list_si != &group->si_head && assigned < assign_per_su) {
  1663. si = list_entry (list_si, struct amf_si, si_list);
  1664. assigned += 1;
  1665. ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1666. list_si = list_si->next;
  1667. }
  1668. list_unit = list_unit->next;
  1669. }
  1670. }
  1671. void assign_nm_spare (struct amf_group *group)
  1672. {
  1673. struct amf_unit *unit;
  1674. struct list_head *list;
  1675. for (list = group->unit_head.next;
  1676. list != &group->unit_head;
  1677. list = list->next) {
  1678. unit = list_entry (list,
  1679. struct amf_unit, unit_list);
  1680. if (unit->readiness_state == SA_AMF_READINESS_IN_SERVICE &&
  1681. (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
  1682. unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
  1683. printf ("Assigning to SU %s with SPARE\n",
  1684. getSaNameT (&unit->name));
  1685. }
  1686. }
  1687. }
  1688. void clear_requested_ha_state (struct amf_group *group)
  1689. {
  1690. struct list_head *list;
  1691. struct amf_unit *unit;
  1692. for (list = group->unit_head.next;
  1693. list != &group->unit_head;
  1694. list = list->next) {
  1695. unit = list_entry (list,
  1696. struct amf_unit, unit_list);
  1697. unit->requested_ha_state = 0;
  1698. }
  1699. csi_number = 0;
  1700. }
  1701. void assign_sis (struct amf_group *group)
  1702. {
  1703. int active_sus_needed;
  1704. int standby_sus_needed;
  1705. int inservice_count;
  1706. int units_for_standby;
  1707. int units_for_active;
  1708. int ii_spare;
  1709. int su_active_assign;
  1710. int su_standby_assign;
  1711. int su_spare_assign;
  1712. clear_requested_ha_state (group);
  1713. /*
  1714. * Number of SUs to assign to active or standby state
  1715. */
  1716. inservice_count = (float)unit_inservice_count (group);
  1717. active_sus_needed = div_round (si_count(group),
  1718. group->maximum_active_instances);
  1719. standby_sus_needed = div_round (si_count(group),
  1720. group->maximum_standby_instances);
  1721. units_for_active = inservice_count - group->preferred_standby_units;
  1722. if (units_for_active < 0) {
  1723. units_for_active = 0;
  1724. }
  1725. units_for_standby = inservice_count - group->preferred_active_units;
  1726. if (units_for_standby < 0) {
  1727. units_for_standby = 0;
  1728. }
  1729. ii_spare = inservice_count - group->preferred_active_units - group->preferred_standby_units;
  1730. if (ii_spare < 0) {
  1731. ii_spare = 0;
  1732. }
  1733. /*
  1734. * Determine number of active and standby service units
  1735. * to assign based upon reduction procedure
  1736. */
  1737. if ((inservice_count - active_sus_needed) < 0) {
  1738. printf ("assignment VI - partial assignment with SIs drop outs\n");
  1739. su_active_assign = active_sus_needed;
  1740. su_standby_assign = 0;
  1741. su_spare_assign = 0;
  1742. } else
  1743. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  1744. printf ("assignment V - partial assignment with reduction of standby units\n");
  1745. su_active_assign = active_sus_needed;
  1746. if (standby_sus_needed > units_for_standby) {
  1747. su_standby_assign = units_for_standby;
  1748. } else {
  1749. su_standby_assign = standby_sus_needed;
  1750. }
  1751. su_spare_assign = 0;
  1752. } else
  1753. if ((group->maximum_standby_instances * units_for_standby) <= si_count (group)) {
  1754. printf ("IV: full assignment with reduction of active service units\n");
  1755. su_active_assign = inservice_count - standby_sus_needed;
  1756. su_standby_assign = standby_sus_needed;
  1757. su_spare_assign = 0;
  1758. } else
  1759. if ((group->maximum_active_instances * units_for_active) <= si_count (group)) {
  1760. printf ("III: full assignment with reduction of standby service units\n");
  1761. su_active_assign = group->preferred_active_units;
  1762. su_standby_assign = units_for_standby;
  1763. su_spare_assign = 0;
  1764. } else
  1765. if (ii_spare == 0) {
  1766. printf ("II: full assignment with spare reduction\n");
  1767. su_active_assign = group->preferred_active_units;
  1768. su_standby_assign = group->preferred_standby_units;
  1769. su_spare_assign = 0;
  1770. } else {
  1771. printf ("I: full assignment with spares\n");
  1772. su_active_assign = group->preferred_active_units;
  1773. su_standby_assign = group->preferred_standby_units;
  1774. su_spare_assign = ii_spare;
  1775. }
  1776. printf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
  1777. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1778. assign_nm_active (group, su_active_assign);
  1779. assign_nm_standby (group, su_standby_assign);
  1780. }
  1781. void readiness_state_unit_set (struct amf_unit *unit, SaAmfReadinessStateT readiness_state)
  1782. {
  1783. printf ("Assigning unit %s ",
  1784. getSaNameT (&unit->name));
  1785. printf ("readiness state %s\n",
  1786. readinessstate_ntoa (readiness_state));
  1787. unit->readiness_state = readiness_state;
  1788. assign_sis (unit->amf_group);
  1789. }
  1790. void presence_state_unit_set (struct amf_unit *unit, SaAmfPresenceStateT presence_state)
  1791. {
  1792. printf ("Setting service unit presence state %s\n",
  1793. presencestate_ntoa (presence_state));
  1794. }
  1795. static void escalation_policy_restart (struct amf_comp *comp)
  1796. {
  1797. printf ("escalation_policy_restart %d\n", comp->unit->escalation_level);
  1798. printf ("escalation policy restart uninsint %p\n", comp);
  1799. presence_state_comp_set (
  1800. comp,
  1801. SA_AMF_PRESENCE_UNINSTANTIATED);
  1802. operational_state_comp_set (
  1803. comp,
  1804. SA_AMF_OPERATIONAL_DISABLED);
  1805. switch (comp->unit->escalation_level) {
  1806. case ESCALATION_LEVEL_NO_ESCALATION:
  1807. comp_restart (comp);
  1808. break;
  1809. case ESCALATION_LEVEL_ONE:
  1810. comp_restart (comp);
  1811. break;
  1812. case ESCALATION_LEVEL_TWO:
  1813. break;
  1814. case ESCALATION_LEVEL_THREE:
  1815. break;
  1816. }
  1817. }
  1818. static void escalation_policy_cleanup (struct amf_comp *comp)
  1819. {
  1820. // escalation_timer_start (comp);
  1821. switch (comp->unit->escalation_level) {
  1822. case ESCALATION_LEVEL_NO_ESCALATION:
  1823. comp->unit->restart_count += 1;
  1824. if (comp->unit->restart_count >= comp->unit->amf_group->component_restart_max) {
  1825. comp->unit->escalation_level = ESCALATION_LEVEL_ONE;
  1826. escalation_policy_cleanup (comp);
  1827. comp->unit->restart_count = 0;
  1828. return;
  1829. }
  1830. printf ("Escalation level 0 - restart component\n");
  1831. printf ("Cleaning up and restarting component.\n");
  1832. comp_cleanup (comp);
  1833. break;
  1834. case ESCALATION_LEVEL_ONE:
  1835. comp->unit->restart_count += 1;
  1836. if (comp->unit->restart_count >= comp->unit->amf_group->unit_restart_max) {
  1837. comp->unit->escalation_level = ESCALATION_LEVEL_TWO;
  1838. escalation_policy_cleanup (comp);
  1839. return;
  1840. }
  1841. printf ("Escalation level 1 - restart unit\n");
  1842. printf ("Cleaning up and restarting unit.\n");
  1843. unit_cleanup (comp->unit);
  1844. break;
  1845. case ESCALATION_LEVEL_TWO:
  1846. printf ("Escalation level TWO\n");
  1847. unit_cleanup (comp->unit);
  1848. // unit_terminate_failover (comp);
  1849. break;
  1850. case ESCALATION_LEVEL_THREE:
  1851. //TODO
  1852. break;
  1853. }
  1854. }
  1855. static void timer_function_healthcheck_timeout (
  1856. void *data)
  1857. {
  1858. struct healthcheck_active *healthcheck_active =
  1859. (struct healthcheck_active *)data;
  1860. printf ("timeout occured on healthcheck for component %s.\n",
  1861. getSaNameT (&healthcheck_active->comp->name));
  1862. escalation_policy_cleanup (healthcheck_active->comp);
  1863. }
  1864. void healthcheck_activate (struct healthcheck_active *healthcheck_active)
  1865. {
  1866. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1867. healthcheck_active->active = 1;
  1868. // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1869. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1870. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1871. res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
  1872. log_printf (LOG_LEVEL_NOTICE, "sending healthcheck to component %s\n",
  1873. getSaNameT (&healthcheck_active->comp->name));
  1874. res_lib_amf_healthcheckcallback.invocation =
  1875. invocation_create (
  1876. AMF_RESPONSE_HEALTHCHECKCALLBACK,
  1877. (void *)healthcheck_active);
  1878. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1879. &healthcheck_active->comp->name,
  1880. sizeof (SaNameT));
  1881. memcpy (&res_lib_amf_healthcheckcallback.key,
  1882. &healthcheck_active->key,
  1883. sizeof (SaAmfHealthcheckKeyT));
  1884. openais_conn_send_response (
  1885. openais_conn_partner_get (healthcheck_active->comp->conn),
  1886. &res_lib_amf_healthcheckcallback,
  1887. sizeof (struct res_lib_amf_healthcheckcallback));
  1888. poll_timer_delete (aisexec_poll_handle,
  1889. healthcheck_active->timer_healthcheck_duration);
  1890. poll_timer_add (aisexec_poll_handle,
  1891. healthcheck_active->healthcheck->maximum_duration,
  1892. (void *)healthcheck_active,
  1893. timer_function_healthcheck_timeout,
  1894. &healthcheck_active->timer_healthcheck_duration);
  1895. }
  1896. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active)
  1897. {
  1898. log_printf (LOG_LEVEL_NOTICE, "ZZZ deactivating healthcheck for component %s\n",
  1899. getSaNameT (&healthcheck_active->comp->name));
  1900. poll_timer_delete (aisexec_poll_handle,
  1901. healthcheck_active->timer_healthcheck_period);
  1902. poll_timer_delete (aisexec_poll_handle,
  1903. healthcheck_active->timer_healthcheck_duration);
  1904. invocation_destroy_by_data ((void *)healthcheck_active);
  1905. list_del (&healthcheck_active->list);
  1906. free (healthcheck_active);
  1907. }
  1908. static void timer_function_healthcheck_next (
  1909. void *data)
  1910. {
  1911. healthcheck_activate (data);
  1912. }
  1913. void healthcheck_unit_deactivate (
  1914. struct amf_unit *unit)
  1915. {
  1916. struct list_head *list;
  1917. struct list_head *key_list;
  1918. struct healthcheck_active *healthcheck_active;
  1919. struct amf_comp *comp;
  1920. for (list = unit->comp_head.next;
  1921. list != &unit->comp_head;
  1922. list = list->next) {
  1923. comp = list_entry (list, struct amf_comp, comp_list);
  1924. for (key_list = comp->healthcheck_list.next;
  1925. key_list != &comp->healthcheck_list;
  1926. key_list = key_list->next) {
  1927. healthcheck_active = list_entry (key_list,
  1928. struct healthcheck_active, list);
  1929. healthcheck_deactivate (healthcheck_active);
  1930. }
  1931. }
  1932. }
  1933. void healthcheck_unit_activate (
  1934. struct amf_unit *unit)
  1935. {
  1936. struct list_head *list;
  1937. struct list_head *key_list;
  1938. struct healthcheck_active *healthcheck_active;
  1939. struct amf_comp *comp;
  1940. for (list = unit->comp_head.next;
  1941. list != &unit->comp_head;
  1942. list = list->next) {
  1943. comp = list_entry (list, struct amf_comp, comp_list);
  1944. for (key_list = comp->healthcheck_list.next;
  1945. key_list != &comp->healthcheck_list;
  1946. key_list = key_list->next) {
  1947. healthcheck_active = list_entry (key_list,
  1948. struct healthcheck_active, list);
  1949. healthcheck_activate (healthcheck_active);
  1950. }
  1951. }
  1952. }
  1953. void operational_state_unit_set (
  1954. struct amf_unit *unit,
  1955. SaAmfOperationalStateT operational_state)
  1956. {
  1957. if (operational_state == unit->operational_state) {
  1958. printf ("Not assigning service unit new operational state - same state\n");
  1959. return;
  1960. }
  1961. unit->operational_state = operational_state;
  1962. printf ("Service unit operational state set to %s\n",
  1963. operationalstate_ntoa (operational_state));
  1964. if (operational_state == SA_AMF_OPERATIONAL_ENABLED) {
  1965. readiness_state_unit_set (unit,
  1966. SA_AMF_READINESS_IN_SERVICE);
  1967. /*
  1968. * Start healthcheck now
  1969. */
  1970. // TODO healthcheck_unit_activate (unit);
  1971. } else
  1972. if (operational_state == SA_AMF_OPERATIONAL_DISABLED) {
  1973. readiness_state_unit_set (unit,
  1974. SA_AMF_READINESS_OUT_OF_SERVICE);
  1975. // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1976. // healthcheck_unit_deactivate (unit);
  1977. }
  1978. }
  1979. static void message_handler_req_exec_amf_operational_state_comp_set (
  1980. void *message,
  1981. struct totem_ip_address *address)
  1982. {
  1983. struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
  1984. (struct req_exec_amf_operational_state_comp_set *)message;
  1985. struct amf_comp *comp;
  1986. struct amf_comp *comp_compare;
  1987. struct list_head *list;
  1988. int all_set = 1;
  1989. comp = find_comp (&req_exec_amf_operational_state_comp_set->name);
  1990. comp->operational_state = req_exec_amf_operational_state_comp_set->operational_state;
  1991. printf ("Setting component %s operational state to %s\n",
  1992. getSaNameT (&comp->name),
  1993. operationalstate_ntoa (comp->operational_state));
  1994. /*
  1995. * If all operational states are ENABLED, then SU should be ENABLED
  1996. */
  1997. for (list = comp->unit->comp_head.next;
  1998. list != &comp->unit->comp_head;
  1999. list = list->next) {
  2000. comp_compare = list_entry (list,
  2001. struct amf_comp, comp_list);
  2002. if (comp_compare->operational_state != SA_AMF_OPERATIONAL_ENABLED) {
  2003. all_set = 0;
  2004. break;
  2005. }
  2006. }
  2007. if (all_set) {
  2008. operational_state_unit_set (comp->unit,
  2009. SA_AMF_OPERATIONAL_ENABLED);
  2010. } else {
  2011. operational_state_unit_set (comp->unit,
  2012. SA_AMF_OPERATIONAL_DISABLED);
  2013. }
  2014. readiness_state_comp_set (comp);
  2015. }
  2016. static void message_handler_req_exec_amf_presence_state_comp_set (
  2017. void *message,
  2018. struct totem_ip_address *address)
  2019. {
  2020. struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
  2021. (struct req_exec_amf_presence_state_comp_set *)message;
  2022. struct amf_comp *comp;
  2023. struct amf_comp *comp_compare;
  2024. struct list_head *list;
  2025. int all_set = 1;
  2026. comp = find_comp (&req_exec_amf_presence_state_comp_set->name);
  2027. if (req_exec_amf_presence_state_comp_set->presence_state == comp->presence_state) {
  2028. printf ("duplicate presence state set, not setting presence state\n");
  2029. return;
  2030. }
  2031. if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_UNINSTANTIATED) {
  2032. comp->conn = 0;
  2033. }
  2034. /*
  2035. * The restarting state can only be entered from the uninstantiated state
  2036. */
  2037. if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_RESTARTING &&
  2038. comp->presence_state != SA_AMF_PRESENCE_UNINSTANTIATED) {
  2039. printf ("restart presence state set even though not in terminating state\n");
  2040. return;
  2041. }
  2042. comp->presence_state = req_exec_amf_presence_state_comp_set->presence_state;
  2043. if (comp->presence_state == SA_AMF_PRESENCE_RESTARTING) {
  2044. printf ("SET TO RESTARTING instantiating now\n");
  2045. clc_instantiate (comp);
  2046. }
  2047. printf ("Setting component %s presence state %s\n",
  2048. getSaNameT (&comp->name),
  2049. presencestate_ntoa (comp->presence_state));
  2050. /*
  2051. * Restart components that are requested to enter the restarting presence state
  2052. */
  2053. /*
  2054. * If all comp presence states are INSTANTIATED, then SU should be instantated
  2055. */
  2056. for (list = comp->unit->comp_head.next;
  2057. list != &comp->unit->comp_head;
  2058. list = list->next) {
  2059. comp_compare = list_entry (list,
  2060. struct amf_comp, comp_list);
  2061. if (comp_compare->presence_state != SA_AMF_PRESENCE_INSTANTIATED) {
  2062. all_set = 0;
  2063. break;
  2064. }
  2065. }
  2066. if (all_set) {
  2067. presence_state_unit_set (comp->unit,
  2068. SA_AMF_PRESENCE_INSTANTIATED);
  2069. }
  2070. }
  2071. static void message_handler_req_exec_amf_administrative_state_csi_set (
  2072. void *message,
  2073. struct totem_ip_address *address)
  2074. {
  2075. // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
  2076. // (struct req_exec_amf_administrative_state_csi_set *)message;
  2077. // TODO
  2078. }
  2079. static void message_handler_req_exec_amf_administrative_state_unit_set (
  2080. void *message,
  2081. struct totem_ip_address *address)
  2082. {
  2083. // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
  2084. // (struct req_exec_amf_administrative_state_unit_set *)message;
  2085. // TODO
  2086. }
  2087. static void message_handler_req_exec_amf_administrative_state_group_set (
  2088. void *message,
  2089. struct totem_ip_address *source)
  2090. {
  2091. // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
  2092. // (struct req_exec_amf_administrative_state_group_set *)message;
  2093. // TODO
  2094. }
  2095. /*
  2096. * Library Interface Implementation
  2097. */
  2098. static void message_handler_req_lib_amf_componentregister (
  2099. void *conn,
  2100. void *msg)
  2101. {
  2102. struct req_lib_amf_componentregister *req_lib_amf_componentregister =
  2103. (struct req_lib_amf_componentregister *)msg;
  2104. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  2105. struct amf_comp *comp;
  2106. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  2107. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2108. comp = find_comp (&req_lib_amf_componentregister->compName);
  2109. if (comp) {
  2110. presence_state_comp_set (comp,
  2111. SA_AMF_PRESENCE_INSTANTIATED);
  2112. operational_state_comp_set (comp,
  2113. SA_AMF_OPERATIONAL_ENABLED);
  2114. comp->conn = conn;
  2115. amf_pd->comp = comp;
  2116. comp_healthcheck_activate (comp);
  2117. error = SA_AIS_OK;
  2118. }
  2119. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  2120. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  2121. res_lib_amf_componentregister.header.error = error;
  2122. openais_conn_send_response (conn, &res_lib_amf_componentregister,
  2123. sizeof (struct res_lib_amf_componentregister));
  2124. }
  2125. static void message_handler_req_lib_amf_componentunregister (
  2126. void *conn,
  2127. void *msg)
  2128. {
  2129. #ifdef COMPILE_OUT
  2130. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2131. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2132. struct iovec iovec;
  2133. struct amf_comp *component;
  2134. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  2135. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2136. req_exec_amf_componentunregister.header.id =
  2137. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2138. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2139. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2140. req_lib_amf_componentunregister,
  2141. sizeof (struct req_lib_amf_componentunregister));
  2142. component = find_comp (&req_lib_amf_componentunregister->compName);
  2143. if (component && component->registered && component->local) {
  2144. // component->probableCause = SA_AMF_NOT_RESPONDING;
  2145. }
  2146. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2147. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2148. assert (totempg_groups_mcast_joined (openais_group_handle,
  2149. &iovec, 1, TOTEMPG_AGREED) == 0);
  2150. #endif
  2151. }
  2152. static void message_handler_req_lib_amf_pmstart (
  2153. void *conn,
  2154. void *msg)
  2155. {
  2156. }
  2157. static void message_handler_req_lib_amf_pmstop (
  2158. void *conn,
  2159. void *msg)
  2160. {
  2161. }
  2162. static void message_handler_req_lib_amf_healthcheckstart (
  2163. void *conn, void *msg)
  2164. {
  2165. struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
  2166. (struct req_lib_amf_healthcheckstart *)msg;
  2167. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  2168. struct amf_healthcheck *healthcheck;
  2169. struct healthcheck_active *healthcheck_active;
  2170. struct amf_comp *comp;
  2171. SaAisErrorT error = SA_AIS_OK;
  2172. printf ("healthcheck start\n");
  2173. fflush (stdout);
  2174. healthcheck = find_healthcheck (&req_lib_amf_healthcheckstart->healthcheckKey);
  2175. if (healthcheck == 0) {
  2176. error = SA_AIS_ERR_NOT_EXIST;
  2177. goto error_exit;
  2178. }
  2179. comp = find_comp (&req_lib_amf_healthcheckstart->compName);
  2180. if (comp == 0) {
  2181. error = SA_AIS_ERR_NOT_EXIST;
  2182. goto error_exit;
  2183. }
  2184. /*
  2185. * Determine if this healthcheck is already active
  2186. */
  2187. healthcheck_active = find_healthcheck_active (
  2188. comp,
  2189. &req_lib_amf_healthcheckstart->healthcheckKey,
  2190. req_lib_amf_healthcheckstart->invocationType);
  2191. if (healthcheck_active) {
  2192. error = SA_AIS_ERR_EXIST;
  2193. goto error_exit;
  2194. }
  2195. healthcheck_active = malloc (sizeof (struct healthcheck_active));
  2196. if (healthcheck_active == 0) {
  2197. error = SA_AIS_ERR_NO_MEMORY;
  2198. goto error_exit;
  2199. }
  2200. /*
  2201. * Make new instance of healthcheck key
  2202. */
  2203. list_init (&healthcheck_active->list);
  2204. memcpy (&healthcheck_active->key,
  2205. &req_lib_amf_healthcheckstart->healthcheckKey,
  2206. sizeof (SaAmfHealthcheckKeyT));
  2207. healthcheck_active->comp = comp;
  2208. healthcheck_active->invocationType = req_lib_amf_healthcheckstart->invocationType;
  2209. healthcheck_active->healthcheck = healthcheck;
  2210. healthcheck_active->timer_healthcheck_duration = 0;
  2211. healthcheck_active->timer_healthcheck_period = 0;
  2212. healthcheck_active->active = 0;
  2213. list_add_tail (&healthcheck_active->list, &comp->healthcheck_list);
  2214. if (comp->conn != 0) {
  2215. printf ("Activating healthcheck for the first time %p\n", healthcheck_active);
  2216. healthcheck_activate (healthcheck_active);
  2217. }
  2218. #ifdef TODO
  2219. do we want to do healtchecking only when full su has registered or also of non-fully registered sus
  2220. if (comp->unit->operational_state == SA_AMF_OPERATIONAL_ENABLED) {
  2221. /*
  2222. * Start healthcheck now
  2223. */
  2224. healthcheck_unit_activate (comp->unit);
  2225. }
  2226. #endif
  2227. error_exit:
  2228. res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  2229. res_lib_amf_healthcheckstart.header.size = sizeof (struct res_lib_amf_healthcheckstart);
  2230. res_lib_amf_healthcheckstart.header.error = error;
  2231. openais_conn_send_response (conn, &res_lib_amf_healthcheckstart,
  2232. sizeof (struct res_lib_amf_healthcheckstart));
  2233. }
  2234. static void message_handler_req_lib_amf_healthcheckconfirm (
  2235. void *conn,
  2236. void *msg)
  2237. {
  2238. }
  2239. static void message_handler_req_lib_amf_healthcheckstop (
  2240. void *conn,
  2241. void *msg)
  2242. {
  2243. struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop =
  2244. (struct req_lib_amf_healthcheckstop *)msg;
  2245. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  2246. struct healthcheck_active *healthcheck_active;
  2247. struct amf_comp *comp;
  2248. SaAisErrorT error = SA_AIS_OK;
  2249. printf ("healthcheck stop\n");
  2250. comp = find_comp (&req_lib_amf_healthcheckstop->compName);
  2251. if (comp == 0) {
  2252. error = SA_AIS_ERR_NOT_EXIST;
  2253. goto error_exit;
  2254. }
  2255. healthcheck_active = find_healthcheck_active (
  2256. comp,
  2257. &req_lib_amf_healthcheckstop->healthcheckKey,
  2258. INVOCATION_DONT_COMPARE);
  2259. printf ("active %p\n", healthcheck_active);
  2260. if (healthcheck_active == 0) {
  2261. error = SA_AIS_ERR_NOT_EXIST;
  2262. goto error_exit;
  2263. }
  2264. healthcheck_deactivate (healthcheck_active);
  2265. error_exit:
  2266. printf ("healthcheck stop\n");
  2267. res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  2268. res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop);
  2269. res_lib_amf_healthcheckstop.header.error = error;
  2270. openais_conn_send_response (conn, &res_lib_amf_healthcheckstop,
  2271. sizeof (struct res_lib_amf_healthcheckstop));
  2272. }
  2273. static void message_handler_req_lib_amf_hastateget (
  2274. void *conn,
  2275. void *msg)
  2276. {
  2277. #ifdef COMPILE_OUT
  2278. struct req_lib_amf_hastateget *req_lib_amf_hastateget = (struct req_lib_amf_hastateget *)msg;
  2279. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2280. struct amf_comp *component;
  2281. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_hastateget()\n");
  2282. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2283. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2284. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2285. #ifdef COMPILE_OUT
  2286. component = component_in_protectiongroup_find (&req_lib_amf_hastateget->csiName, &req_lib_amf_hastateget->compName);
  2287. #endif
  2288. if (component) {
  2289. memcpy (&res_lib_amf_hastateget.haState,
  2290. &component->currentHAState, sizeof (SaAmfHAStateT));
  2291. res_lib_amf_hastateget.header.error = SA_AIS_OK;
  2292. }
  2293. openais_conn_send_response (conn, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2294. #endif
  2295. }
  2296. static void message_handler_req_lib_amf_protectiongrouptrackstart (
  2297. void *conn,
  2298. void *msg)
  2299. {
  2300. #ifdef COMPILE_OUT
  2301. struct req_lib_amf_protectiongrouptrackstart *req_lib_amf_protectiongrouptrackstart = (struct req_lib_amf_protectiongrouptrackstart *)message;
  2302. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2303. struct libamf_ci_trackentry *track = 0;
  2304. int i;
  2305. struct saAmfProtectionGroup *amfProtectionGroup;
  2306. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstart()\n");
  2307. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrackstart->csiName);
  2308. if (amfProtectionGroup) {
  2309. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrackstart->csiName));
  2310. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2311. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2312. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2313. break;
  2314. }
  2315. }
  2316. if (track == 0) {
  2317. grow_amf_track_table (conn_info, 1);
  2318. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2319. }
  2320. track->active = 1;
  2321. track->trackFlags = req_lib_amf_protectiongrouptrackstart->trackFlags;
  2322. track->notificationBufferAddress = req_lib_amf_protectiongrouptrackstart->notificationBufferAddress;
  2323. memcpy (&track->csiName,
  2324. &req_lib_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2325. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2326. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2327. /*
  2328. * If SA_TRACK_CURRENT is specified, write out all current connections
  2329. */
  2330. } else {
  2331. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2332. }
  2333. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2334. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2335. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2336. if (amfProtectionGroup) {
  2337. res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK;
  2338. }
  2339. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstart,
  2340. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2341. if (amfProtectionGroup &&
  2342. req_lib_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2343. protectiongroup_notification_send (conn_info,
  2344. track->notificationBufferAddress,
  2345. amfProtectionGroup,
  2346. 0,
  2347. 0,
  2348. SA_TRACK_CHANGES_ONLY);
  2349. track->trackFlags &= ~SA_TRACK_CURRENT;
  2350. }
  2351. #endif
  2352. }
  2353. static void message_handler_req_lib_amf_csiquiescingcomplete (
  2354. void *conn,
  2355. void *msg)
  2356. {
  2357. }
  2358. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  2359. void *conn,
  2360. void *msg)
  2361. {
  2362. #ifdef COMPILE_OUT
  2363. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  2364. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2365. struct libamf_ci_trackentry *track = 0;
  2366. int i;
  2367. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  2368. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2369. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  2370. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2371. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2372. }
  2373. }
  2374. if (track) {
  2375. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  2376. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2377. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2378. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2379. list_del (&conn_info->conn_list);
  2380. }
  2381. }
  2382. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2383. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2384. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2385. if (track) {
  2386. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  2387. }
  2388. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  2389. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2390. #endif
  2391. }
  2392. static void message_handler_req_lib_amf_componenterrorreport (
  2393. void *conn,
  2394. void *msg)
  2395. {
  2396. struct req_lib_amf_componenterrorreport *req_lib_amf_componenterrorreport = (struct req_lib_amf_componenterrorreport *)msg;
  2397. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2398. struct amf_comp *comp;
  2399. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2400. log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n");
  2401. printf ("ERROR REPORT\n");
  2402. comp = find_comp (&req_lib_amf_componenterrorreport->erroneousComponent);
  2403. if (comp) {
  2404. printf ("escalation policy terminate\n");
  2405. escalation_policy_cleanup (comp);
  2406. error = SA_AIS_OK;
  2407. }
  2408. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2409. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2410. res_lib_amf_componenterrorreport.header.error = error;
  2411. openais_conn_send_response (
  2412. conn, &res_lib_amf_componenterrorreport,
  2413. sizeof (struct res_lib_amf_componenterrorreport));
  2414. }
  2415. static void message_handler_req_lib_amf_componenterrorclear (
  2416. void *conn,
  2417. void *msg)
  2418. {
  2419. #ifdef COMPILLE_OUT
  2420. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  2421. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  2422. struct iovec iovec;
  2423. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  2424. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  2425. req_exec_amf_componenterrorclear.header.id =
  2426. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  2427. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  2428. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  2429. req_lib_amf_componenterrorclear,
  2430. sizeof (struct req_lib_amf_componenterrorclear));
  2431. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  2432. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  2433. assert (totempg_groups_mcast_joined (openais_group_handle,
  2434. &iovec, 1, TOTEMPG_AGREED) == 0);
  2435. #endif
  2436. }
  2437. void pg_comp_create (
  2438. struct amf_pg *pg,
  2439. struct amf_csi *csi,
  2440. struct amf_comp *comp)
  2441. {
  2442. struct amf_pg_comp *pg_comp;
  2443. printf ("creating component for pg\n");
  2444. pg_comp = malloc (sizeof (struct amf_pg_comp));
  2445. assert (pg_comp);
  2446. pg_comp->comp = comp;
  2447. pg_comp->csi = csi;
  2448. list_init (&pg_comp->list);
  2449. list_add_tail (&pg_comp->list, &pg->pg_comp_head);
  2450. }
  2451. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  2452. {
  2453. struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)msg;
  2454. struct res_lib_amf_response res_lib_amf_response;
  2455. struct csi_set_callback_data *csi_set_callback_data;
  2456. struct csi_remove_callback_data *csi_remove_callback_data;
  2457. struct component_terminate_callback_data *component_terminate_callback_data;
  2458. struct healthcheck_active *healthcheck_active;
  2459. int interface;
  2460. int res;
  2461. void *data;
  2462. SaAisErrorT error = SA_AIS_OK;
  2463. log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_amf_response()\n");
  2464. res = invocation_get_and_destroy (req_lib_amf_response->invocation,
  2465. &interface, &data);
  2466. if (res == -1) {
  2467. printf ("invocation not found\n");
  2468. error = SA_AIS_ERR_NOT_EXIST;
  2469. goto error_exit;
  2470. }
  2471. log_printf (LOG_LEVEL_DEBUG, "handling response connection interface %x\n", interface);
  2472. switch (interface) {
  2473. case AMF_RESPONSE_HEALTHCHECKCALLBACK:
  2474. healthcheck_active = (struct healthcheck_active *)data;
  2475. poll_timer_delete (aisexec_poll_handle,
  2476. healthcheck_active->timer_healthcheck_duration);
  2477. healthcheck_active->timer_healthcheck_duration = 0;
  2478. poll_timer_add (aisexec_poll_handle,
  2479. healthcheck_active->healthcheck->period,
  2480. (void *)healthcheck_active,
  2481. timer_function_healthcheck_next,
  2482. &healthcheck_active->timer_healthcheck_period);
  2483. break;
  2484. case AMF_RESPONSE_CSISETCALLBACK:
  2485. csi_set_callback_data = (struct csi_set_callback_data *)data;
  2486. printf ("csi callback executed from library.\n");
  2487. csi_set_callback_data->comp->ha_state =
  2488. csi_set_callback_data->comp->unit->requested_ha_state;
  2489. // list_add (&csi_set_callback_data->comp->
  2490. /*
  2491. pg_comp_create (
  2492. csi_set_callback_data->pg,
  2493. csi_set_callback_data->csi,
  2494. csi_set_callback_data->comp);
  2495. */
  2496. free (csi_set_callback_data);
  2497. break;
  2498. case AMF_RESPONSE_CSIREMOVECALLBACK:
  2499. csi_remove_callback_data = (struct csi_remove_callback_data *)data;
  2500. printf ("response from removing the CSI\n");
  2501. // AAAA
  2502. list_del (&csi_remove_callback_data->csi->si->unit_list);
  2503. list_del (&csi_remove_callback_data->csi->csi_list);
  2504. free (csi_remove_callback_data);
  2505. break;
  2506. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
  2507. component_terminate_callback_data = (struct component_terminate_callback_data *)data;
  2508. printf ("response from terminating component\n");
  2509. comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  2510. escalation_policy_restart (component_terminate_callback_data->comp);
  2511. break;
  2512. default:
  2513. // TODO
  2514. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_lib_amf_response->invocation);
  2515. break;
  2516. }
  2517. error_exit:
  2518. res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
  2519. res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
  2520. res_lib_amf_response.header.error = SA_AIS_OK;
  2521. openais_conn_send_response (conn, &res_lib_amf_response,
  2522. sizeof (struct res_lib_amf_response));
  2523. }
  2524. #ifdef COMPILE_OUT
  2525. /*
  2526. * Executive Message Implementation
  2527. */
  2528. static void message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2529. {
  2530. #ifdef COMPILE_OUT
  2531. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  2532. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  2533. struct amf_comp *component;
  2534. struct amf_comp *amfProxyComponent;
  2535. SaAisErrorT error;
  2536. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  2537. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  2538. /*
  2539. * Determine if proxy isn't registered
  2540. */
  2541. error = SA_AIS_OK;
  2542. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  2543. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  2544. /*
  2545. * If a node is joining menber ship ,Component States Synchronize
  2546. */
  2547. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  2548. amf_synchronize (message, source_addr);
  2549. return;
  2550. }
  2551. /*
  2552. * If component not in configuration files, return error
  2553. */
  2554. if (component == 0) {
  2555. error = SA_ERR_NOT_EXIST;
  2556. }
  2557. /*
  2558. * If proxy doesn't exist and isn't registered, return error
  2559. */
  2560. if ((amfProxyComponent == 0 &&
  2561. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  2562. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  2563. error = SA_ERR_NOT_EXIST;
  2564. }
  2565. /*
  2566. * If component already registered, return error
  2567. */
  2568. if (error == SA_AIS_OK) {
  2569. if (component->registered) {
  2570. error = SA_ERR_EXIST;
  2571. }
  2572. }
  2573. /*
  2574. * Finally register component and setup links for proxy if
  2575. * proxy present
  2576. */
  2577. if (error == SA_AIS_OK) {
  2578. component->local = 0;
  2579. component->registered = 1;
  2580. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  2581. component->source_addr = source_addr;
  2582. // component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  2583. // component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  2584. component->currentHAState = 0;
  2585. component->newHAState = 0;
  2586. component->probableCause = 0;
  2587. component->enabledUnlockedState = 0;
  2588. component->disabledUnlockedState = 0;
  2589. component->healthcheck_outstanding = 0;
  2590. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  2591. component->saAmfProxyComponent = amfProxyComponent;
  2592. }
  2593. }
  2594. /*
  2595. * If this node originated the request to the cluster, respond back
  2596. * to the AMF library
  2597. */
  2598. if (message_source_is_local(&req_exec_amf_componentregister->source)) {
  2599. if (error == SA_AIS_OK) {
  2600. component->local = 1;
  2601. req_exec_amf_componentregister->source.conn_info->component = component;
  2602. }
  2603. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  2604. req_exec_amf_componentregister->source.conn_info->fd);
  2605. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  2606. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  2607. res_lib_amf_componentregister.header.error = error;
  2608. openais_conn_send_response (req_exec_amf_componentregister->source.conn_info,
  2609. &res_lib_amf_componentregister,
  2610. sizeof (struct res_lib_amf_componentregister));
  2611. }
  2612. /*
  2613. * If no error on registration, determine if we should enter new state
  2614. */
  2615. if (error == SA_AIS_OK) {
  2616. dsm (component);
  2617. }
  2618. #endif
  2619. }
  2620. static void message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2621. {
  2622. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  2623. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  2624. struct amf_comp *component;
  2625. struct amf_comp *amfProxyComponent;
  2626. SaAisErrorT error;
  2627. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  2628. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  2629. component = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  2630. amfProxyComponent = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  2631. /*
  2632. * Check for proxy and component not existing in system
  2633. */
  2634. error = SA_AIS_OK;
  2635. if (component == 0) {
  2636. error = SA_ERR_NOT_EXIST;
  2637. }
  2638. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  2639. if (amfProxyComponent) {
  2640. if (amfProxyComponent->registered == 0) {
  2641. error = SA_ERR_NOT_EXIST;
  2642. }
  2643. } else {
  2644. error = SA_ERR_NOT_EXIST;
  2645. }
  2646. }
  2647. /*
  2648. * If there is a proxycompname, make sure it is the proxy
  2649. * of compName
  2650. */
  2651. if (error == SA_AIS_OK && amfProxyComponent) {
  2652. if (component->saAmfProxyComponent != amfProxyComponent) {
  2653. error = SA_ERR_BAD_OPERATION;
  2654. }
  2655. }
  2656. /*
  2657. * Finally unregister the component
  2658. */
  2659. if (error == SA_AIS_OK) {
  2660. component->registered = 0;
  2661. // dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  2662. }
  2663. /*
  2664. * If this node originated the request to the cluster, respond back
  2665. * to the AMF library
  2666. */
  2667. if (message_source_is_local (&req_exec_amf_componentunregister->source)) {
  2668. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  2669. req_exec_amf_componentunregister->source.conn_info->fd);
  2670. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  2671. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  2672. res_lib_amf_componentunregister.header.error = error;
  2673. openais_conn_send_response (req_exec_amf_componentunregister->source.conn_info,
  2674. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  2675. }
  2676. return;
  2677. }
  2678. static void message_handler_req_exec_amf_componenterrorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  2679. {
  2680. struct req_exec_amf_componenterrorreport *req_exec_amf_componenterrorreport = (struct req_exec_amf_componenterrorreport *)message;
  2681. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2682. struct amf_comp *comp;
  2683. SaAisErrorT error = SA_AIS_OK;
  2684. log_printf (LOG_LEVEL_NOTICE, "Executive: ErrorReport for %s\n",
  2685. getSaNameT (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent));
  2686. comp = find_comp (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent);
  2687. if (comp == 0) {
  2688. error = SA_AIS_ERR_NOT_EXIST;
  2689. }
  2690. /*
  2691. * If this node originated the request to the cluster, respond back
  2692. * to the AMF library
  2693. */
  2694. if (message_source_is_local (&req_exec_amf_componenterrorreport->source)) {
  2695. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2696. req_exec_amf_componenterrorreport->source.conn_info->fd);
  2697. if (comp) {
  2698. }
  2699. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2700. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2701. res_lib_amf_componenterrorreport.header.error = error;
  2702. openais_conn_send_response (req_exec_amf_componenterrorreport->source.conn_info,
  2703. &res_lib_amf_componenterrorreport, sizeof (struct res_lib_amf_componenterrorreport));
  2704. }
  2705. return (0);
  2706. }
  2707. static void message_handler_req_exec_amf_componenterrorclear (void *message, struct in_addr source_addr, int endian_conversion_required)
  2708. {
  2709. struct req_exec_amf_componenterrorclear *req_exec_amf_componenterrorclear = (struct req_exec_amf_componenterrorclear *)message;
  2710. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  2711. struct amf_comp *component;
  2712. SaAisErrorT error = SA_ERR_BAD_OPERATION;
  2713. #ifdef COMPILE_OUT
  2714. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  2715. getSaNameT (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName));
  2716. component = find_comp (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName);
  2717. if (component && component->registered) {
  2718. /*
  2719. * Mark component in service if its a AMF service
  2720. * connected to this aisexec
  2721. */
  2722. if (component->probableCause) {
  2723. component->probableCause = 0;
  2724. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  2725. dsm (component);
  2726. }
  2727. error = SA_AIS_OK;
  2728. }
  2729. /*
  2730. * If this node originated the request to the cluster, respond back
  2731. * to the AMF library
  2732. */
  2733. if (message_source_is_local (&req_exec_amf_componenterrorclear->source)) {
  2734. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2735. req_exec_amf_componenterrorclear->source.conn_info->fd);
  2736. res_lib_amf_componenterrorclear.header.size = sizeof (struct res_lib_amf_componenterrorclear);
  2737. res_lib_amf_componenterrorclear.header.id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR;
  2738. res_lib_amf_componenterrorclear.header.error = error;
  2739. openais_conn_send_response (req_exec_amf_componenterrorclear->source.conn_info,
  2740. &res_lib_amf_componenterrorclear, sizeof (struct res_lib_amf_componenterrorclear));
  2741. }
  2742. #endif
  2743. return (0);
  2744. }
  2745. #endif
  2746. #ifdef COMPILE_OUT
  2747. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  2748. {
  2749. struct libamf_ci_trackentry *tracks;
  2750. int newsize;
  2751. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  2752. newsize = growby + currsize;
  2753. if (newsize > currsize) {
  2754. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  2755. (newsize) * sizeof (struct libamf_ci_trackentry));
  2756. if (tracks == 0) {
  2757. #ifdef DEBUG
  2758. printf ("grow_amf_track_table: out of memory, woops\n");
  2759. #endif
  2760. // TODO
  2761. exit (1);
  2762. }
  2763. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  2764. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  2765. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  2766. }
  2767. }
  2768. static void component_unregister (
  2769. struct amf_comp *component)
  2770. {
  2771. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2772. struct iovec iovec;
  2773. /*
  2774. * This only works on local components
  2775. */
  2776. if (component == 0 || component->local != 1) {
  2777. return;
  2778. }
  2779. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  2780. getSaNameT (&component->name));
  2781. component->probableCause = SA_AMF_NOT_RESPONDING;
  2782. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2783. req_exec_amf_componentunregister.header.id =
  2784. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2785. req_exec_amf_componentunregister.source.conn_info = 0;
  2786. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  2787. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2788. 0, sizeof (struct req_lib_amf_componentunregister));
  2789. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  2790. &component->name,
  2791. sizeof (SaNameT));
  2792. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2793. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2794. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2795. }
  2796. static void component_register (
  2797. struct amf_comp *component)
  2798. {
  2799. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  2800. struct iovec iovec;
  2801. /*
  2802. * This only works on local components
  2803. */
  2804. if (component == 0 || component->local != 1) {
  2805. return;
  2806. }
  2807. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  2808. getSaNameT (&component->name));
  2809. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  2810. req_exec_amf_componentregister.header.id =
  2811. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER);
  2812. req_exec_amf_componentregister.source.conn_info = 0;
  2813. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  2814. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  2815. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  2816. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  2817. req_exec_amf_componentregister.newHAState = component->newHAState;
  2818. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  2819. 0, sizeof (struct req_lib_amf_componentregister));
  2820. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  2821. &component->name,
  2822. sizeof (SaNameT));
  2823. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  2824. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  2825. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2826. }
  2827. /***
  2828. This should be used for a partition I think
  2829. **/
  2830. void enumerate_components (
  2831. void (*function)(struct amf_comp *, void *data),
  2832. void *data)
  2833. {
  2834. struct list_head *AmfGroupList;
  2835. struct list_head *AmfUnitList;
  2836. struct list_head *AmfComponentList;
  2837. struct saAmfGroup *saAmfGroup;
  2838. struct saAmfUnit *AmfUnit;
  2839. struct amf_comp *AmfComponent;
  2840. /*
  2841. * Search all groups
  2842. */
  2843. for (AmfGroupList = saAmfGroupHead.next;
  2844. AmfGroupList != &saAmfGroupHead;
  2845. AmfGroupList = AmfGroupList->next) {
  2846. saAmfGroup = list_entry (AmfGroupList,
  2847. struct saAmfGroup, saAmfGroupList);
  2848. /*
  2849. * Search all units
  2850. */
  2851. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  2852. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  2853. AmfUnitList = AmfUnitList->next) {
  2854. AmfUnit = list_entry (AmfUnitList,
  2855. struct saAmfUnit, saAmfUnitList);
  2856. /*
  2857. * Search all components
  2858. */
  2859. for (AmfComponentList = AmfUnit->amf_compHead.next;
  2860. AmfComponentList != &AmfUnit->amf_compHead;
  2861. AmfComponentList = AmfComponentList->next) {
  2862. AmfComponent = list_entry (AmfComponentList,
  2863. struct amf_comp, amf_compList);
  2864. function (AmfComponent, data);
  2865. }
  2866. }
  2867. }
  2868. }
  2869. void ha_state_api_set (struct amf_comp *component, SaAmfHAStateT haState)
  2870. {
  2871. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  2872. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  2873. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  2874. if (component->local != 1) {
  2875. return;
  2876. }
  2877. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2878. return;
  2879. }
  2880. /*
  2881. * this should be an assertion
  2882. */
  2883. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2884. component->conn_info->service != AMF_SERVICE) {
  2885. return;
  2886. }
  2887. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  2888. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  2889. res_lib_amf_csisetcallback.header.error = SA_AIS_OK;
  2890. if (res_lib_amf_csisetcallback.invocation == -1) {
  2891. printf ("TODO set callback\n");
  2892. }
  2893. memcpy (&res_lib_amf_csisetcallback.compName,
  2894. &component->name, sizeof (SaNameT));
  2895. memcpy (&res_lib_amf_csisetcallback.csiName,
  2896. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  2897. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  2898. res_lib_amf_csisetcallback.haState = haState;
  2899. // TODO set activeCompName to correct component name
  2900. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  2901. &component->name, sizeof (SaNameT));
  2902. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  2903. component->newHAState = haState;
  2904. openais_conn_send_response (component->conn_info->conn_info_partner,
  2905. &res_lib_amf_csisetcallback,
  2906. sizeof (struct res_lib_amf_csisetcallback));
  2907. }
  2908. static void ha_state_group_set (
  2909. struct amf_comp *component,
  2910. SaAmfHAStateT haState)
  2911. {
  2912. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  2913. struct iovec iovec;
  2914. req_exec_amf_hastateset.header.id =
  2915. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_HASTATESET);
  2916. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  2917. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  2918. req_exec_amf_hastateset.haState = haState;
  2919. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  2920. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  2921. iovec.iov_base = (char *)&req_exec_amf_hastateset;
  2922. iovec.iov_len = sizeof (req_exec_amf_hastateset);
  2923. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  2924. }
  2925. void readiness_state_api_set (struct amf_comp *component,
  2926. SaAmfReadinessStateT readinessState)
  2927. {
  2928. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  2929. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  2930. /*
  2931. * If component is local, don't request service from API
  2932. */
  2933. if (component->local != 1) {
  2934. return;
  2935. }
  2936. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2937. return;
  2938. }
  2939. /*
  2940. * this should be an assertion
  2941. */
  2942. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2943. component->conn_info->service != AMF_SERVICE) {
  2944. return;
  2945. }
  2946. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  2947. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  2948. res_lib_amf_readinessstatesetcallback.header.error = SA_AIS_OK;
  2949. res_lib_amf_readinessstatesetcallback.invocation =
  2950. req_lib_amf_invocation_create (
  2951. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  2952. comp);
  2953. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  2954. printf ("TODO readiness set callback\n");
  2955. }
  2956. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  2957. &component->name, sizeof (SaNameT));
  2958. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  2959. component->newReadinessState = readinessState;
  2960. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  2961. openais_conn_send_response (component->conn_info->conn_info_partner,
  2962. &res_lib_amf_readinessstatesetcallback,
  2963. sizeof (struct res_lib_amf_readinessstatesetcallback));
  2964. }
  2965. static void readiness_state_group_set (
  2966. struct amf_comp *component,
  2967. SaAmfReadinessStateT readinessState)
  2968. {
  2969. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  2970. struct iovec iovec;
  2971. req_exec_amf_readinessstateset.header.id =
  2972. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_READINESSSTATESET);
  2973. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  2974. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  2975. req_exec_amf_readinessstateset.readinessState = readinessState;
  2976. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  2977. getSaNameT (&component->name));
  2978. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  2979. iovec.iov_base = (char *)&req_exec_amf_readinessstateset;
  2980. iovec.iov_len = sizeof (req_exec_amf_readinessstateset);
  2981. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2982. }
  2983. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  2984. struct amf_comp *component)
  2985. {
  2986. struct saAmfUnit *unit;
  2987. struct list_head *list;
  2988. int serviceUnitEnabled;
  2989. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  2990. getSaNameT (&component->name));
  2991. unit = component->saAmfUnit;
  2992. for (serviceUnitEnabled = 1, list = unit->amf_compHead.next;
  2993. list != &unit->amf_compHead;
  2994. list = list->next) {
  2995. component = list_entry (list,
  2996. struct amf_comp, amf_compList);
  2997. if (component->registered == 0 ||
  2998. component->probableCause) {
  2999. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  3000. serviceUnitEnabled = 0;
  3001. break;
  3002. }
  3003. }
  3004. if (serviceUnitEnabled == 1) {
  3005. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  3006. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  3007. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  3008. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3009. dsm (component);
  3010. }
  3011. }
  3012. static void dsmDisabledUnlockedFailedComponent (
  3013. struct amf_comp *component)
  3014. {
  3015. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  3016. getSaNameT (&component->name));
  3017. switch (component->enabledUnlockedState) {
  3018. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  3019. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  3020. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  3021. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  3022. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  3023. } else {
  3024. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  3025. }
  3026. break;
  3027. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  3028. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  3029. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  3030. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  3031. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3032. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  3033. ha_state_group_set (component, SA_AMF_QUIESCED);
  3034. } else {
  3035. ha_state_api_set (component, SA_AMF_QUIESCED);
  3036. }
  3037. poll_timer_delete (aisexec_poll_handle,
  3038. component->timer_healthcheck);
  3039. component->timer_healthcheck = 0;
  3040. break;
  3041. default:
  3042. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  3043. break;
  3044. }
  3045. }
  3046. static void dsmDisabledUnlockedFailed (
  3047. struct amf_comp *component)
  3048. {
  3049. struct saAmfUnit *unit;
  3050. struct list_head *list;
  3051. unit = component->saAmfUnit;
  3052. for (list = unit->amf_compHead.next;
  3053. list != &unit->amf_compHead;
  3054. list = list->next) {
  3055. component = list_entry (list, struct amf_comp, amf_compList);
  3056. dsmDisabledUnlockedFailedComponent (component);
  3057. }
  3058. return;
  3059. }
  3060. static void dsmDisabledUnlockedQuiescedRequested (
  3061. struct amf_comp *component)
  3062. {
  3063. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  3064. dsm (component);
  3065. }
  3066. static void dsmDisabledUnlockedQuiescedCompleted (
  3067. struct amf_comp *component)
  3068. {
  3069. struct saAmfUnit *unit;
  3070. struct list_head *list;
  3071. int serviceUnitQuiesced;
  3072. unit = component->saAmfUnit;
  3073. for (serviceUnitQuiesced = 1, list = unit->amf_compHead.next;
  3074. list != &unit->amf_compHead;
  3075. list = list->next) {
  3076. component = list_entry (list, struct amf_comp, amf_compList);
  3077. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  3078. if (component->currentHAState != SA_AMF_QUIESCED) {
  3079. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  3080. serviceUnitQuiesced = 0;
  3081. break;
  3082. }
  3083. }
  3084. }
  3085. if (serviceUnitQuiesced == 1) {
  3086. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  3087. for (list = unit->amf_compHead.next;
  3088. list != &unit->amf_compHead;
  3089. list = list->next) {
  3090. component = list_entry (list, struct amf_comp, amf_compList);
  3091. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  3092. getSaNameT (&component->name));
  3093. if ( component->probableCause == SA_AMF_NOT_RESPONDING ) {
  3094. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  3095. } else {
  3096. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  3097. }
  3098. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  3099. }
  3100. }
  3101. }
  3102. static void dsmDisabledUnlockedOutOfServiceRequested (
  3103. struct amf_comp *component)
  3104. {
  3105. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  3106. dsm (component);
  3107. }
  3108. static void dsmDisabledUnlockedOutOfServiceCompleted (
  3109. struct amf_comp *component)
  3110. {
  3111. struct saAmfUnit *unit;
  3112. struct list_head *list;
  3113. int serviceUnitOutOfService;
  3114. struct saAmfGroup *group = 0;
  3115. struct list_head *comp_list = 0;
  3116. struct list_head *unit_list = 0;
  3117. int serviceUnitInStandby = 0;
  3118. int activeServiceUnits = 0;
  3119. /*
  3120. * Once all components of a service unit are out of service,
  3121. * activate another service unit in standby
  3122. */
  3123. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  3124. /*
  3125. * Determine if all components have responded to going out of service
  3126. */
  3127. unit = component->saAmfUnit;
  3128. for (serviceUnitOutOfService = 1, list = unit->amf_compHead.next;
  3129. list != &unit->amf_compHead;
  3130. list = list->next) {
  3131. component = list_entry (list, struct amf_comp, amf_compList);
  3132. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  3133. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  3134. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  3135. serviceUnitOutOfService = 0;
  3136. break;
  3137. }
  3138. }
  3139. if ( component->registered == 0 ) {
  3140. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  3141. }
  3142. }
  3143. group = unit->saAmfGroup;
  3144. activeServiceUnits = activeServiceUnitsCount(group);
  3145. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  3146. return;
  3147. }
  3148. if (serviceUnitOutOfService == 1) {
  3149. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  3150. /*
  3151. * Search all units
  3152. */
  3153. for (unit_list = group->saAmfUnitHead.next;
  3154. unit_list != &group->saAmfUnitHead;
  3155. unit_list = unit_list->next) {
  3156. unit = list_entry (unit_list,
  3157. struct saAmfUnit, saAmfUnitList);
  3158. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  3159. /*
  3160. * Search all components
  3161. */
  3162. for (serviceUnitInStandby = 1,
  3163. comp_list = unit->amf_compHead.next;
  3164. comp_list != &unit->amf_compHead;
  3165. comp_list = comp_list->next) {
  3166. component = list_entry (comp_list,
  3167. struct amf_comp, amf_compList);
  3168. if (component->currentHAState != SA_AMF_STANDBY) {
  3169. serviceUnitInStandby = 0;
  3170. break; /* for iteration of service unit components */
  3171. }
  3172. }
  3173. if (serviceUnitInStandby) {
  3174. break; /* for iteration of service group's service units */
  3175. }
  3176. }
  3177. /*
  3178. * All components in service unit are standby, activate standby service unit
  3179. */
  3180. if (serviceUnitInStandby) {
  3181. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  3182. for (list = unit->amf_compHead.next;
  3183. list != &unit->amf_compHead;
  3184. list = list->next) {
  3185. component = list_entry (list,
  3186. struct amf_comp, amf_compList);
  3187. ha_state_api_set (component, SA_AMF_ACTIVE);
  3188. }
  3189. } else {
  3190. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  3191. }
  3192. }
  3193. }
  3194. static void dsmEnabledUnlockedInitial (
  3195. struct amf_comp *component)
  3196. {
  3197. struct saAmfUnit *unit;
  3198. struct list_head *list;
  3199. unit = component->saAmfUnit;
  3200. for (list = unit->amf_compHead.next;
  3201. list != &unit->amf_compHead;
  3202. list = list->next) {
  3203. component = list_entry (list, struct amf_comp, amf_compList);
  3204. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  3205. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  3206. getSaNameT (&component->name));
  3207. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3208. }
  3209. }
  3210. static void dsmEnabledUnlockedInServiceRequested (
  3211. struct amf_comp *component)
  3212. {
  3213. struct saAmfUnit *unit;
  3214. struct list_head *list;
  3215. int in_service;
  3216. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  3217. unit = component->saAmfUnit;
  3218. for (in_service = 1, list = unit->amf_compHead.next;
  3219. list != &unit->amf_compHead;
  3220. list = list->next) {
  3221. component = list_entry (list, struct amf_comp, amf_compList);
  3222. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  3223. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  3224. in_service = 0;
  3225. break;
  3226. }
  3227. }
  3228. if (in_service) {
  3229. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  3230. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3231. dsm (component);
  3232. }
  3233. }
  3234. static void dsmEnabledUnlockedInServiceCompleted (
  3235. struct amf_comp *component)
  3236. {
  3237. struct saAmfUnit *unit;
  3238. struct list_head *list;
  3239. SaAmfHAStateT newHaState;
  3240. int activeServiceUnits;
  3241. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  3242. unit = component->saAmfUnit;
  3243. for (list = unit->amf_compHead.next;
  3244. list != &unit->amf_compHead;
  3245. list = list->next) {
  3246. component = list_entry (list,
  3247. struct amf_comp, amf_compList);
  3248. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  3249. /*
  3250. * Count number of active service units
  3251. */
  3252. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  3253. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  3254. newHaState = SA_AMF_ACTIVE;
  3255. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  3256. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3257. } else {
  3258. newHaState = SA_AMF_STANDBY;
  3259. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  3260. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3261. }
  3262. ha_state_api_set (component, newHaState);
  3263. }
  3264. }
  3265. static void dsmEnabledUnlockedActiveRequested (
  3266. struct amf_comp *component)
  3267. {
  3268. if (component->local == 1) {
  3269. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer1\n");
  3270. poll_timer_add (aisexec_poll_handle,
  3271. component->healthcheckInterval,
  3272. (void *)component->conn_info,
  3273. timer_function_libamf_healthcheck,
  3274. &component->timer_healthcheck);
  3275. }
  3276. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3277. }
  3278. static void dsmEnabledUnlockedStandbyRequested (
  3279. struct amf_comp *component)
  3280. {
  3281. if (component->local == 1) {
  3282. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer2\n");
  3283. poll_timer_add (aisexec_poll_handle,
  3284. component->healthcheckInterval,
  3285. (void *)component->conn_info,
  3286. timer_function_libamf_healthcheck,
  3287. &component->timer_healthcheck);
  3288. }
  3289. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3290. }
  3291. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  3292. struct amf_comp *component)
  3293. {
  3294. struct saAmfUnit *unit;
  3295. struct list_head *list;
  3296. unit = component->saAmfUnit;
  3297. for (list = unit->amf_compHead.next;
  3298. list != &unit->amf_compHead;
  3299. list = list->next) {
  3300. component = list_entry (list, struct amf_comp, amf_compList);
  3301. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  3302. getSaNameT (&component->name));
  3303. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  3304. }
  3305. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3306. dsm (component);
  3307. }
  3308. static void dsmSynchronizeStaus (
  3309. struct amf_comp *component)
  3310. {
  3311. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  3312. struct saAmfUnit *unit;
  3313. struct saAmfGroup *group;
  3314. struct list_head *list;
  3315. int activeServiceUnits;
  3316. if (component->currentReadinessState == component->newReadinessState) {
  3317. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3318. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3319. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3320. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  3321. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3322. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3323. unit_status = AMF_ENABLED_UNLOCKED;
  3324. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  3325. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  3326. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3327. }
  3328. } else {
  3329. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3330. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  3331. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3332. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  3333. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3334. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3335. unit_status = AMF_ENABLED_UNLOCKED;
  3336. } else {
  3337. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3338. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3339. }
  3340. }
  3341. if (component->currentHAState == component->newHAState) {
  3342. if (component->currentHAState == SA_AMF_ACTIVE) {
  3343. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3344. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3345. unit_status = AMF_ENABLED_UNLOCKED;
  3346. } else if (component->currentHAState == SA_AMF_STANDBY) {
  3347. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3348. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3349. unit_status = AMF_ENABLED_UNLOCKED;
  3350. } else {
  3351. /* depend on readiness status */
  3352. }
  3353. } else {
  3354. if (component->newHAState == SA_AMF_ACTIVE) {
  3355. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3356. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3357. unit_status = AMF_ENABLED_UNLOCKED;
  3358. } else if (component->newHAState == SA_AMF_STANDBY) {
  3359. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3360. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3361. unit_status = AMF_ENABLED_UNLOCKED;
  3362. } else {
  3363. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3364. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3365. }
  3366. }
  3367. /* Syncronize Operational AdministrativeState */
  3368. component->saAmfUnit->operationalAdministrativeState = unit_status;
  3369. unit = component->saAmfUnit;
  3370. group = unit->saAmfGroup;
  3371. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3372. activeServiceUnits = activeServiceUnitsCount(group);
  3373. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  3374. break;
  3375. }
  3376. if (component->currentHAState != SA_AMF_ACTIVE) {
  3377. continue;
  3378. }
  3379. ha_state_api_set (component, SA_AMF_STANDBY);
  3380. }
  3381. return;
  3382. }
  3383. static void dsmEnabledUnlocked (
  3384. struct amf_comp *component)
  3385. {
  3386. switch (component->enabledUnlockedState) {
  3387. case AMF_ENABLED_UNLOCKED_INITIAL:
  3388. dsmEnabledUnlockedInitial (component);
  3389. break;
  3390. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  3391. dsmEnabledUnlockedInServiceRequested (component);
  3392. break;
  3393. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  3394. dsmEnabledUnlockedInServiceCompleted (component);
  3395. break;
  3396. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  3397. dsmEnabledUnlockedActiveRequested (component);
  3398. break;
  3399. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  3400. /* noop - operational state */
  3401. break;
  3402. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  3403. dsmEnabledUnlockedStandbyRequested (component);
  3404. break;
  3405. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  3406. /* noop - operational state */
  3407. break;
  3408. default:
  3409. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  3410. }
  3411. }
  3412. static void dsmDisabledUnlocked (
  3413. struct amf_comp *component)
  3414. {
  3415. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  3416. getSaNameT (&component->name),
  3417. component->disabledUnlockedState);
  3418. switch (component->disabledUnlockedState) {
  3419. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  3420. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  3421. break;
  3422. case AMF_DISABLED_UNLOCKED_FAILED:
  3423. dsmDisabledUnlockedFailed (component);
  3424. break;
  3425. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  3426. dsmDisabledUnlockedQuiescedRequested (component);
  3427. break;
  3428. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  3429. dsmDisabledUnlockedQuiescedCompleted (component);
  3430. break;
  3431. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  3432. dsmDisabledUnlockedOutOfServiceRequested (component);
  3433. break;
  3434. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  3435. dsmDisabledUnlockedOutOfServiceCompleted (component);
  3436. break;
  3437. default:
  3438. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  3439. }
  3440. }
  3441. static void dsm (
  3442. struct amf_comp *component)
  3443. {
  3444. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  3445. switch (component->saAmfUnit->operationalAdministrativeState) {
  3446. case AMF_DISABLED_UNLOCKED:
  3447. dsmDisabledUnlocked (component);
  3448. break;
  3449. case AMF_ENABLED_UNLOCKED:
  3450. dsmEnabledUnlocked (component);
  3451. break;
  3452. /*
  3453. AMF_DISABLED_LOCKED,
  3454. AMF_ENABLED_STOPPING
  3455. */
  3456. default:
  3457. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  3458. }
  3459. }
  3460. void error_report (
  3461. struct amf_comp *component,
  3462. SaAmfProbableCauseT probableCause)
  3463. {
  3464. struct req_exec_amf_componenterrorreport req_exec_amf_componenterrorreport;
  3465. struct iovec iovec;
  3466. req_exec_amf_componenterrorreport.header.size = sizeof (struct req_exec_amf_componenterrorreport);
  3467. req_exec_amf_componenterrorreport.header.id =
  3468. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERRORREPORT);
  3469. req_exec_amf_componenterrorreport.source.conn_info = 0;
  3470. req_exec_amf_componenterrorreport.source.in_addr.s_addr = 0;
  3471. memcpy (&req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.erroneousComponent,
  3472. &component->name,
  3473. sizeof (SaNameT));
  3474. req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.errorDescriptor.probableCause = probableCause;
  3475. iovec.iov_base = (char *)&req_exec_amf_componenterrorreport;
  3476. iovec.iov_len = sizeof (req_exec_amf_componenterrorreport);
  3477. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 2, TOTEMPG_AGREED) == 0);
  3478. }
  3479. int healthcheck_instance = 0;
  3480. struct saAmfProtectionGroup *protectiongroup_find (
  3481. SaNameT *csiName)
  3482. {
  3483. struct list_head *AmfGroupList;
  3484. struct list_head *AmfProtectionGroupList;
  3485. struct saAmfGroup *saAmfGroup;
  3486. struct saAmfProtectionGroup *AmfProtectionGroup;
  3487. /*
  3488. * Search all groups
  3489. */
  3490. for (AmfGroupList = saAmfGroupHead.next;
  3491. AmfGroupList != &saAmfGroupHead;
  3492. AmfGroupList = AmfGroupList->next) {
  3493. saAmfGroup = list_entry (AmfGroupList,
  3494. struct saAmfGroup, saAmfGroupList);
  3495. /*
  3496. * Search all protection groups
  3497. */
  3498. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3499. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3500. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3501. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3502. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3503. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3504. return (AmfProtectionGroup);
  3505. }
  3506. }
  3507. }
  3508. return (0);
  3509. }
  3510. struct amf_comp *component_in_protectiongroup_find (
  3511. SaNameT *csiName,
  3512. SaNameT *compName)
  3513. {
  3514. struct list_head *AmfGroupList = 0;
  3515. struct list_head *AmfProtectionGroupList = 0;
  3516. struct list_head *AmfComponentList = 0;
  3517. struct saAmfGroup *saAmfGroup = 0;
  3518. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  3519. struct amf_comp *AmfComponent = 0;
  3520. int found = 0;
  3521. /*
  3522. * Search all groups
  3523. */
  3524. for (AmfGroupList = saAmfGroupHead.next;
  3525. AmfGroupList != &saAmfGroupHead;
  3526. AmfGroupList = AmfGroupList->next) {
  3527. saAmfGroup = list_entry (AmfGroupList,
  3528. struct saAmfGroup, saAmfGroupList);
  3529. /*
  3530. * Search all protection groups
  3531. */
  3532. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3533. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3534. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3535. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3536. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3537. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3538. /*
  3539. * Search all components
  3540. */
  3541. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  3542. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  3543. AmfComponentList = AmfComponentList->next) {
  3544. AmfComponent = list_entry (AmfComponentList,
  3545. struct amf_comp, saAmfProtectionGroupList);
  3546. if (name_match (compName, &AmfComponent->name)) {
  3547. found = 1;
  3548. }
  3549. }
  3550. }
  3551. }
  3552. }
  3553. if (found) {
  3554. return (AmfComponent);
  3555. } else {
  3556. return (0);
  3557. }
  3558. }
  3559. /*
  3560. * The response handler for readiness state set callback
  3561. */
  3562. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  3563. struct req_lib_amf_response *req_lib_amf_response)
  3564. {
  3565. if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) {
  3566. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  3567. getSaNameT (&conn_info->component->name));
  3568. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  3569. }
  3570. }
  3571. /*
  3572. * iterate service unit components
  3573. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  3574. */
  3575. static void response_handler_csisetcallback (struct conn_info *conn_info,
  3576. struct req_lib_amf_response *req_lib_amf_response)
  3577. {
  3578. if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) {
  3579. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  3580. }
  3581. }
  3582. void amf_confchg_njoin (struct amf_comp *component ,void *data)
  3583. {
  3584. if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) {
  3585. return;
  3586. }
  3587. component_register (component);
  3588. return;
  3589. }
  3590. void amf_confchg_nleave (struct amf_comp *component ,void *data)
  3591. {
  3592. struct in_addr *source_addr = (struct in_addr *)data;
  3593. struct saAmfUnit *unit;
  3594. struct list_head *list;
  3595. struct amf_comp *leave_component = NULL;
  3596. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  3597. if (component->source_addr.s_addr != source_addr->s_addr) {
  3598. return;
  3599. }
  3600. if (!component->registered) {
  3601. return;
  3602. }
  3603. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  3604. /* Component status Initialize */
  3605. unit = component->saAmfUnit;
  3606. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3607. component = list_entry (list,
  3608. struct amf_comp, amf_compList);
  3609. if (component->source_addr.s_addr != source_addr->s_addr) {
  3610. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  3611. continue;
  3612. }
  3613. component->registered = 0;
  3614. component->local = 0;
  3615. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3616. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3617. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  3618. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  3619. component->newHAState = SA_AMF_QUIESCED;
  3620. component->currentHAState = SA_AMF_QUIESCED;
  3621. component->source_addr.s_addr = 0;
  3622. leave_component = component;
  3623. }
  3624. if (leave_component == NULL) {
  3625. return;
  3626. }
  3627. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3628. leave_component->disabledUnlockedState = disablestate;
  3629. dsm (leave_component);
  3630. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3631. return;
  3632. }
  3633. /*
  3634. * If receiving this message from another cluster node, another cluster node
  3635. * has selected a readiness state for a component connected to _that_ cluster
  3636. * node. That cluster node API has verified the readiness state, so its time to let
  3637. * the rest of the cluster nodes know about the readiness state change.
  3638. */
  3639. static void message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3640. {
  3641. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  3642. struct amf_comp *component;
  3643. component = find_comp (&req_exec_amf_readinessstateset->compName);
  3644. if (component) {
  3645. log_printf (LOG_LEVEL_FROM_GMI,
  3646. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  3647. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  3648. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  3649. component->newReadinessState = component->currentReadinessState;
  3650. dsm (component);
  3651. }
  3652. return (0);
  3653. }
  3654. /*
  3655. * If receiving this message from another cluster node, another cluster node
  3656. * has selected a ha state for a component connected to _that_ cluster
  3657. * node. That cluster node API has verified the ha state, so its time to let
  3658. * the rest of the cluster nodes know about the HA state change.
  3659. */
  3660. static void message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3661. {
  3662. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  3663. struct amf_comp *component;
  3664. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  3665. component = find_comp (&req_exec_amf_hastateset->compName);
  3666. if (!component) {
  3667. return (0);
  3668. }
  3669. log_printf (LOG_LEVEL_FROM_GMI,
  3670. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  3671. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  3672. if ( component->currentHAState == 0 ) {
  3673. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  3674. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  3675. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  3676. }
  3677. } else {
  3678. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  3679. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  3680. }
  3681. }
  3682. component->currentHAState = req_exec_amf_hastateset->haState;
  3683. component->newHAState = component->currentHAState;
  3684. dsm (component);
  3685. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  3686. protectiongroup_notifications_send (component, changeToComponent);
  3687. }
  3688. return (0);
  3689. }
  3690. static void message_handler_req_lib_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3691. {
  3692. struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message;
  3693. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  3694. struct iovec iovec;
  3695. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  3696. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  3697. req_exec_amf_componentregister.header.id =
  3698. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER);
  3699. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  3700. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  3701. req_lib_amf_componentregister,
  3702. sizeof (struct req_lib_amf_componentregister));
  3703. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  3704. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  3705. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3706. return (0);
  3707. }
  3708. static void message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  3709. {
  3710. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  3711. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  3712. struct iovec iovec;
  3713. struct saAmfComponent *component;
  3714. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  3715. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  3716. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  3717. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  3718. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  3719. req_lib_amf_componentunregister,
  3720. sizeof (struct req_lib_amf_componentunregister));
  3721. component = findComponent (&req_lib_amf_componentunregister->compName);
  3722. if (component && component->registered && component->local) {
  3723. component->probableCause = SA_AMF_NOT_RESPONDING;
  3724. }
  3725. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  3726. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  3727. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3728. return (0);
  3729. }
  3730. static void message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3731. {
  3732. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  3733. >>>>>>> .r872
  3734. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  3735. struct amf_comp *component;
  3736. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_readinessstateget()\n");
  3737. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  3738. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  3739. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  3740. component = find_comp (&req_lib_amf_readinessstateget->compName);
  3741. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  3742. if (component) {
  3743. memcpy (&res_lib_amf_readinessstateget.readinessState,
  3744. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  3745. res_lib_amf_readinessstateget.header.error = SA_AIS_OK;
  3746. }
  3747. openais_conn_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  3748. return (0);
  3749. }
  3750. static void message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3751. void *message)
  3752. {
  3753. struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message;
  3754. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  3755. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  3756. if (amfProtectionGroup) {
  3757. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  3758. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3759. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  3760. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3761. break;
  3762. }
  3763. }
  3764. if (track == 0) {
  3765. grow_amf_track_table (conn_info, 1);
  3766. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3767. }
  3768. track->active = 1;
  3769. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  3770. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  3771. memcpy (&track->csiName,
  3772. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  3773. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  3774. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  3775. /*
  3776. * If SA_TRACK_CURRENT is specified, write out all current connections
  3777. */
  3778. } else {
  3779. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  3780. }
  3781. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  3782. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  3783. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  3784. if (amfProtectionGroup) {
  3785. res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK;
  3786. }
  3787. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  3788. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  3789. if (amfProtectionGroup &&
  3790. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  3791. protectiongroup_notification_send (conn_info,
  3792. track->notificationBufferAddress,
  3793. amfProtectionGroup,
  3794. 0,
  3795. 0,
  3796. SA_TRACK_CHANGES_ONLY);
  3797. track->trackFlags &= ~SA_TRACK_CURRENT;
  3798. }
  3799. return (0);
  3800. }
  3801. static void message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  3802. {
  3803. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  3804. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  3805. struct libamf_ci_trackentry *track = 0;
  3806. int i;
  3807. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  3808. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3809. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  3810. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  3811. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3812. }
  3813. }
  3814. if (track) {
  3815. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  3816. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  3817. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  3818. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  3819. list_del (&conn_info->conn_list);
  3820. }
  3821. }
  3822. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  3823. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  3824. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  3825. if (track) {
  3826. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  3827. }
  3828. openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  3829. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  3830. return (0);
  3831. }
  3832. static void message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  3833. {
  3834. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  3835. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  3836. struct iovec iovec;
  3837. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  3838. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  3839. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  3840. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  3841. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  3842. req_lib_amf_errorreport,
  3843. sizeof (struct req_lib_amf_errorreport));
  3844. iovec.iov_base = (char *)&req_exec_amf_errorreport;
  3845. iovec.iov_len = sizeof (req_exec_amf_errorreport);
  3846. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3847. return (0);
  3848. }
  3849. static void message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  3850. {
  3851. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  3852. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  3853. struct iovec iovec;
  3854. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  3855. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  3856. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  3857. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  3858. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  3859. req_lib_amf_errorcancelall,
  3860. sizeof (struct req_lib_amf_errorcancelall));
  3861. iovec.iov_base = (char *)&req_exec_amf_errorcancelall;
  3862. iovec.iov_len = sizeof (req_exec_amf_errorcancelall);
  3863. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  3864. return (0);
  3865. }
  3866. static void message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3867. void *message)
  3868. {
  3869. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  3870. struct conn_info *inv_conn_info = NULL;
  3871. >>>>>>> .r872
  3872. int interface;
  3873. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_stoppingcomplete()\n");
  3874. req_lib_amf_invocation_get_and_destroy (req_lib_amf_stoppingcomplete->invocation,
  3875. &interface, &inv_conn_info);
  3876. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  3877. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  3878. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  3879. return (0);
  3880. }
  3881. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  3882. struct req_lib_amf_response *req_lib_amf_response) {
  3883. if (req_lib_amf_response->error == SA_AIS_OK) {
  3884. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  3885. conn_info->component->healthcheck_outstanding = 0;
  3886. }
  3887. }
  3888. static void message_handler_req_lib_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  3889. {
  3890. struct req_lib_amf_componentcapabilitymodelget *req_lib_amf_componentcapabilitymodelget = (struct req_lib_amf_componentcapabilitymodelget *)message;
  3891. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  3892. struct amf_comp *component;
  3893. SaAisErrorT error = SA_AIS_OK;
  3894. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentcapabilitymodelget()\n");
  3895. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  3896. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_lib_amf_componentcapabilitymodelget->compName));
  3897. component = find_comp (&req_lib_amf_componentcapabilitymodelget->compName);
  3898. if (component && component->registered) {
  3899. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  3900. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  3901. } else {
  3902. error = SA_ERR_NOT_EXIST;
  3903. }
  3904. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  3905. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  3906. res_lib_amf_componentcapabilitymodelget.header.error = error;
  3907. openais_conn_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  3908. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  3909. return (0);
  3910. }
  3911. static char disabled_unlocked_state_text[6][64] = {
  3912. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  3913. "AMF_DISABLED_UNLOCKED_FAILED",
  3914. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  3915. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  3916. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  3917. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  3918. };
  3919. static char *disabledunlockedstate_ntoa (int state)
  3920. {
  3921. static char str[64];
  3922. if (state >= 0 && state < 6) {
  3923. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  3924. }else{
  3925. sprintf (str, "Unknown(%d)", state);
  3926. }
  3927. return (str);
  3928. }
  3929. static char enabled_unlocked_state_text[7][64] = {
  3930. "AMF_ENABLED_UNLOCKED_INITIAL",
  3931. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  3932. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  3933. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  3934. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  3935. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  3936. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  3937. };
  3938. static char *enabledunlockedstate_ntoa (int state)
  3939. {
  3940. static char str[64];
  3941. if (state >= 0 && state < 7) {
  3942. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  3943. }else{
  3944. sprintf (str, "Unknown(%d)", state);
  3945. }
  3946. return (str);
  3947. }
  3948. #endif
  3949. static char presence_state_text[8][32] = {
  3950. "unknown",
  3951. "uninstantiated",
  3952. "instantiating",
  3953. "instantiated",
  3954. "terminating",
  3955. "restarting",
  3956. "instantion_failed",
  3957. "terminiation_failed"
  3958. };
  3959. static char *presencestate_ntoa (SaAmfPresenceStateT state)
  3960. {
  3961. static char str[32];
  3962. if (state > 0 && state < 9) {
  3963. sprintf (str, "%s(%d)", presence_state_text[state], state);
  3964. }else{
  3965. sprintf (str, "Unknown(%d)", state);
  3966. }
  3967. return (str);
  3968. }
  3969. static char operational_state_text[4][64] = {
  3970. "Unknown",
  3971. "enabled",
  3972. "disabled"
  3973. };
  3974. static char *operationalstate_ntoa (SaAmfOperationalStateT state)
  3975. {
  3976. static char str[32];
  3977. if (state > 0 && state < 3) {
  3978. sprintf (str, "%s(%d)", operational_state_text[state], state);
  3979. }else{
  3980. sprintf (str, "Unknown(%d)", state);
  3981. }
  3982. return (str);
  3983. }
  3984. static char readiness_state_text[4][32] = {
  3985. "Unknown",
  3986. "out of service",
  3987. "in service",
  3988. "quiesced",
  3989. };
  3990. static char *readinessstate_ntoa (int state)
  3991. {
  3992. static char str[32];
  3993. if (state > 0 && state < 4) {
  3994. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  3995. }else{
  3996. sprintf (str, "Unknown(%d)", state);
  3997. }
  3998. return (str);
  3999. }
  4000. static char ha_state_text[4][32] = {
  4001. "Unknown",
  4002. "active",
  4003. "standby",
  4004. "quiesced",
  4005. };
  4006. static char *hastate_ntoa (SaAmfHAStateT state)
  4007. {
  4008. static char str[32];
  4009. if (state > 0 && state < 4) {
  4010. sprintf (str, "%s(%d)", ha_state_text[state], state);
  4011. }else{
  4012. sprintf (str, "Unknown(%d)", state);
  4013. }
  4014. return (str);
  4015. }
  4016. static void amf_dump_comp (struct amf_comp *component ,void *data)
  4017. {
  4018. char name[64];
  4019. int level = LOG_LEVEL_NOTICE;
  4020. data = NULL;
  4021. struct list_head* type_name_list;
  4022. struct amf_comp_csi_type_name* type_name;
  4023. log_printf (level, "----------------\n" );
  4024. log_printf (level, "registered = %d\n" ,component->registered);
  4025. log_printf (level, "local = %d\n" ,component->local );
  4026. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  4027. memset (name, 0 , sizeof(name));
  4028. memcpy (name, component->name.value, component->name.length);
  4029. log_printf (level, "name = %s\n" ,name );
  4030. #if 1
  4031. log_printf (level, "csi type names\n");
  4032. for (type_name_list = component->csi_type_name_head.next;
  4033. type_name_list != &component->csi_type_name_head;
  4034. type_name_list = type_name_list->next) {
  4035. type_name = list_entry (type_name_list,
  4036. struct amf_comp_csi_type_name, list);
  4037. log_printf (level, " name = %s\n" , type_name->name);
  4038. }
  4039. #endif
  4040. #if COMPILE_OUT
  4041. /*
  4042. * TODO Change to correct state syntax and implement new ...state_ntoa
  4043. */
  4044. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  4045. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  4046. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  4047. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  4048. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  4049. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  4050. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  4051. #endif
  4052. }
  4053. void enumerate_components (
  4054. void (*function)(struct amf_comp *, void *data),
  4055. void *data)
  4056. {
  4057. struct list_head *AmfGroupList;
  4058. struct list_head *AmfUnitList;
  4059. struct list_head *AmfComponentList;
  4060. struct amf_group *saAmfGroup;
  4061. struct amf_unit *AmfUnit;
  4062. struct amf_comp *AmfComponent;
  4063. /*
  4064. * Search all groups
  4065. */
  4066. for (AmfGroupList = amf_groupHead.next;
  4067. AmfGroupList != &amf_groupHead;
  4068. AmfGroupList = AmfGroupList->next) {
  4069. saAmfGroup = list_entry (AmfGroupList,
  4070. struct amf_group, group_list);
  4071. /*
  4072. * Search all units
  4073. */
  4074. for (AmfUnitList = saAmfGroup->unit_head.next;
  4075. AmfUnitList != &saAmfGroup->unit_head;
  4076. AmfUnitList = AmfUnitList->next) {
  4077. AmfUnit = list_entry (AmfUnitList,
  4078. struct amf_unit, unit_list);
  4079. /*
  4080. * Search all components
  4081. */
  4082. for (AmfComponentList = AmfUnit->comp_head.next;
  4083. AmfComponentList != &AmfUnit->comp_head;
  4084. AmfComponentList = AmfComponentList->next) {
  4085. AmfComponent = list_entry (AmfComponentList,
  4086. struct amf_comp, comp_list);
  4087. function (AmfComponent, data);
  4088. }
  4089. }
  4090. }
  4091. }
  4092. void amf_dump ( )
  4093. {
  4094. enumerate_components (amf_dump_comp, NULL);
  4095. fflush (stderr);
  4096. return;
  4097. }