amf.c 144 KB

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