amf.c 145 KB

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