amf.c 145 KB

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