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