| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985 |
- /*
- * Copyright (c) 2002-2006 MontaVista Software, Inc.
- * Author: Steven Dake (sdake@mvista.com)
- *
- * Copyright (c) 2006 Ericsson AB.
- * Author: Hans Feldt
- * Description: Introduced AMF B.02 information model
- *
- * All rights reserved.
- *
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <sys/types.h>
- #include <sys/uio.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <signal.h>
- #include <string.h>
- #include <pthread.h>
- #include <assert.h>
- #include "../include/saAis.h"
- #include "../include/saAmf.h"
- #include "../include/ipc_gen.h"
- #include "../include/ipc_amf.h"
- #include "../include/list.h"
- #include "../lcr/lcr_comp.h"
- #include "totempg.h"
- #include "aispoll.h"
- #include "mempool.h"
- #include "util.h"
- #include "amfconfig.h"
- #include "main.h"
- #include "service.h"
- #include "objdb.h"
- #include "print.h"
- #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
- #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
- #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
- enum amf_message_req_types {
- MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET = 0,
- MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET = 1,
- MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_CSI_SET = 2,
- MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_UNIT_SET = 3,
- MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_GROUP_SET = 4
- };
- #ifndef HOST_NAME_MAX
- # define HOST_NAME_MAX 255
- #endif
- struct invocation {
- void *data;
- int interface;
- int active;
- };
- static struct invocation *invocation_entries = 0;
- static int invocation_entries_size = 0;
- static int waiting = 0;
- enum amf_response_interfaces {
- AMF_RESPONSE_HEALTHCHECKCALLBACK = 1,
- AMF_RESPONSE_CSISETCALLBACK = 2,
- AMF_RESPONSE_CSIREMOVECALLBACK = 3,
- AMF_RESPONSE_COMPONENTTERMINATECALLBACK = 4
- };
- struct csi_set_callback_data {
- struct amf_comp *comp;
- struct amf_csi *csi;
- struct amf_pg *pg;
- };
- struct csi_remove_callback_data {
- struct amf_csi *csi;
- };
- struct component_terminate_callback_data {
- struct amf_comp *comp;
- };
-
- static void amf_confchg_fn (
- enum totem_configuration_type configuration_type,
- unsigned int *member_list, int member_list_entries,
- unsigned int *left_list, int left_list_entries,
- unsigned int *joined_list, int joined_list_entries,
- struct memb_ring_id *ring_id);
- static int amf_lib_exit_fn (void *conn);
- static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb);
- static int amf_lib_init_fn (void *conn);
- static void message_handler_req_lib_amf_componentregister (void *conn, void *msg);
- static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg);
- static void message_handler_req_lib_amf_pmstart (void *conn, void *msg);
- static void message_handler_req_lib_amf_pmstop (void *conn, void *msg);
- static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg);
- static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg);
- static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg);
- static void message_handler_req_lib_amf_hastateget (void *conn, void *message);
- static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg);
- static void message_handler_req_lib_amf_protectiongrouptrack (void *conn, void *msg);
- static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg);
- static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg);
- static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg);
- static void message_handler_req_lib_amf_response (void *conn, void *msg);
- static void message_handler_req_exec_amf_operational_state_comp_set (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_presence_state_comp_set (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_administrative_state_csi_set (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_administrative_state_unit_set (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_administrative_state_group_set (
- void *message,
- unsigned int nodeid);
- static void presence_state_comp_set (
- struct amf_comp *comp,
- SaAmfPresenceStateT presence_state);
- static void operational_state_comp_set (
- struct amf_comp *comp,
- SaAmfOperationalStateT operational_state);
- static void operational_state_unit_set (
- struct amf_su *unit,
- SaAmfOperationalStateT operational_state);
- static void assign_sis (struct amf_sg *group);
- static void clc_instantiate_all (void *data);
- static int clc_instantiate (struct amf_comp *comp);
- #if 0
- static int clc_terminate (struct amf_comp *comp);
- #endif
- static int clc_cli_instantiate (struct amf_comp *comp);
- static int clc_instantiate_callback (struct amf_comp *comp);
- static int clc_csi_set_callback (struct amf_comp *comp);
- static int clc_cli_terminate (struct amf_comp *comp);
- static int clc_terminate_callback (struct amf_comp *comp);
- static int clc_csi_remove_callback (struct amf_comp *comp);
- static int clc_cli_cleanup (struct amf_comp *comp);
- static int clc_cli_cleanup_local (struct amf_comp *comp);
- static void healthcheck_activate (struct amf_healthcheck *healthcheck_active);
- static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active);
- static void comp_healthcheck_activate (struct amf_comp *comp);
- static void comp_healthcheck_deactivate (struct amf_comp *comp);
- static void escalation_policy_restart (struct amf_comp *comp);
- static void amf_dump(void);
- static char *presence_state_text[] = {
- "unknown",
- "uninstantiated",
- "instantiating",
- "instantiated",
- "terminating",
- "restarting",
- "instantion_failed",
- "terminiation_failed"
- };
- static char *oper_state_text[] = {
- "Unknown",
- "enabled",
- "disabled"
- };
- static char *admin_state_text[] = {
- "Unknown",
- "unlocked",
- "locked",
- "locked_instantiation",
- "shutting_down"
- };
- static char *readiness_state_text[] = {
- "Unknown",
- "out of service",
- "in service",
- };
- static char *ha_state_text[] = {
- "Unknown",
- "active",
- "standby",
- "quiesced",
- "quiescing",
- };
- struct libamf_ci_trackentry {
- int active;
- SaUint8T trackFlags;
- SaAmfProtectionGroupNotificationT *notificationBufferAddress;
- SaNameT csiName;
- };
- struct amf_comp;
- struct amf_pd {
- struct amf_comp *comp;
- struct list_head list;
- /*
- struct libamf_ci_trackentry *tracks;
- int trackEntries;
- int trackActive;
- */
- };
- struct clc_interface {
- int (*instantiate) (struct amf_comp *comp);
- int (*terminate) (struct amf_comp *comp);
- int (*cleanup) (struct amf_comp *comp);
- };
- /*
- * Life cycle functions
- */
- static struct clc_interface clc_interface_sa_aware = {
- clc_cli_instantiate,
- clc_terminate_callback,
- clc_cli_cleanup
- };
- static struct clc_interface clc_interface_proxied_pre = {
- clc_instantiate_callback,
- clc_terminate_callback,
- clc_cli_cleanup
- };
- static struct clc_interface clc_interface_proxied_non_pre = {
- clc_csi_set_callback,
- clc_csi_remove_callback,
- clc_cli_cleanup_local
- };
- static struct clc_interface clc_interface_non_proxied_non_saware = {
- clc_cli_instantiate,
- clc_cli_terminate,
- clc_cli_cleanup_local
- };
- static struct clc_interface *clc_interfaces[4] = {
- &clc_interface_sa_aware,
- &clc_interface_proxied_pre,
- &clc_interface_proxied_non_pre,
- &clc_interface_non_proxied_non_saware
- };
- /*
- * Service Handler Definition
- */
- static struct openais_lib_handler amf_lib_service[] =
- {
- { /* 0 */
- .lib_handler_fn = message_handler_req_lib_amf_componentregister,
- .response_size = sizeof (struct res_lib_amf_componentregister),
- .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
- .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
- },
- { /* 1 */
- .lib_handler_fn = message_handler_req_lib_amf_componentunregister,
- .response_size = sizeof (struct res_lib_amf_componentunregister),
- .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
- .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
- },
- { /* 2 */
- .lib_handler_fn = message_handler_req_lib_amf_pmstart,
- .response_size = sizeof (struct res_lib_amf_pmstart),
- .response_id = MESSAGE_RES_AMF_PMSTART,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 3 */
- .lib_handler_fn = message_handler_req_lib_amf_pmstop,
- .response_size = sizeof (struct res_lib_amf_pmstop),
- .response_id = MESSAGE_RES_AMF_PMSTOP,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 4 */
- .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart,
- .response_size = sizeof (struct res_lib_amf_healthcheckstart),
- .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 5 */
- .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
- .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
- .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 6 */
- .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop,
- .response_size = sizeof (struct res_lib_amf_healthcheckstop),
- .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 7 */
- .lib_handler_fn = message_handler_req_lib_amf_hastateget,
- .response_size = sizeof (struct res_lib_amf_hastateget),
- .response_id = MESSAGE_RES_AMF_HASTATEGET,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 8 */
- .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
- .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
- .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 9 */
- .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrack,
- .response_size = sizeof (struct res_lib_amf_protectiongrouptrack),
- .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 10 */
- .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
- .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
- .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 11 */
- .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport,
- .response_size = sizeof (struct res_lib_amf_componenterrorreport),
- .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
- .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
- },
- { /* 12 */
- .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear,
- .response_size = sizeof (struct res_lib_amf_componenterrorclear),
- .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
- .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
- },
- { /* 13 */
- .lib_handler_fn = message_handler_req_lib_amf_response,
- .response_size = sizeof (struct res_lib_amf_response),
- .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
- .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
- },
- };
- static struct openais_exec_handler amf_exec_service[] = {
- {
- .exec_handler_fn = message_handler_req_exec_amf_operational_state_comp_set,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_presence_state_comp_set,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_administrative_state_csi_set,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_administrative_state_unit_set,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_administrative_state_group_set
- }
- };
- /*
- * Exports the interface for the service
- */
- static struct openais_service_handler amf_service_handler = {
- .name = (unsigned char *)"openais availability management framework B.01.01",
- .id = AMF_SERVICE,
- .private_data_size = sizeof (struct amf_pd),
- .lib_init_fn = amf_lib_init_fn,
- .lib_exit_fn = amf_lib_exit_fn,
- .lib_service = amf_lib_service,
- .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler),
- .exec_init_fn = amf_exec_init_fn,
- .exec_service = amf_exec_service,
- .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler),
- .confchg_fn = amf_confchg_fn,
- .exec_dump_fn = amf_dump
- };
- static struct amf_node *this_amf_node;
- static struct amf_cluster amf_cluster;
- static struct openais_service_handler *amf_get_handler_ver0 (void);
- static struct openais_service_handler_iface_ver0 amf_service_handler_iface = {
- .openais_get_service_handler_ver0 = amf_get_handler_ver0
- };
- static struct lcr_iface openais_amf_ver0[1] = {
- {
- .name = "openais_amf",
- .version = 0,
- .versions_replace = 0,
- .versions_replace_count = 0,
- .dependencies = 0,
- .dependency_count = 0,
- .constructor = NULL,
- .destructor = NULL,
- .interfaces = NULL
- }
- };
- static struct lcr_comp amf_comp_ver0 = {
- .iface_count = 1,
- .ifaces = openais_amf_ver0
- };
- static struct openais_service_handler *amf_get_handler_ver0 (void)
- {
- return (&amf_service_handler);
- }
- __attribute__ ((constructor)) static void register_this_component (void) {
- lcr_interfaces_set (&openais_amf_ver0[0], &amf_service_handler_iface);
- lcr_component_register (&amf_comp_ver0);
- }
- enum clc_command_run_operation_type {
- CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
- CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
- CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
- };
- struct clc_command_run_data {
- struct amf_comp *comp;
- enum clc_command_run_operation_type type;
- void (*completion_callback) (void *context);
- };
- static int invocation_create (
- int interface,
- void *data)
- {
- struct invocation *invocation_addr = 0;
- struct invocation *invocation_temp;
- int i;
- int loc = 0;
- for (i = 0; i < invocation_entries_size; i++) {
- if (invocation_entries[i].active == 0) {
- invocation_addr = &invocation_entries[i];
- loc = i;
- break;
- }
- }
- if (invocation_addr == 0) {
- invocation_temp = (struct invocation *)realloc (invocation_entries,
- (invocation_entries_size + 1) * sizeof (struct invocation));
- if (invocation_temp == 0) {
- return (-1);
- }
- invocation_entries = invocation_temp;
- invocation_addr = &invocation_entries[invocation_entries_size];
- loc = invocation_entries_size;
- invocation_entries_size += 1;
- }
- invocation_addr->interface = interface;
- invocation_addr->data = data;
- invocation_addr->active = 1;
- return (loc);
- }
- static int invocation_get_and_destroy (int invocation, int *interface,
- void **data)
- {
- if (invocation > invocation_entries_size) {
- return (-1);
- }
- if (invocation_entries[invocation].active == 0) {
- return (-1);
- }
- *interface = invocation_entries[invocation].interface;
- *data = invocation_entries[invocation].data;
- memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
-
- return (0);
- }
- static void invocation_destroy_by_data (void *data)
- {
- int i;
- for (i = 0; i < invocation_entries_size; i++) {
- if (invocation_entries[i].data == data) {
- memset (&invocation_entries[i], 0,
- sizeof (struct invocation));
- break;
- }
- }
- }
- static void *clc_command_run (void *context)
- {
- struct clc_command_run_data *clc_command_run_data =
- (struct clc_command_run_data *)context;
- pid_t pid;
- int res;
- char *argv[10];
- char *envp[10];
- int status;
- char path[PATH_MAX];
- char *cmd = 0;
- char *comp_argv = 0;
- char env_comp_name[1024];
- int i;
- ENTER_VOID();
- pid = fork();
- if (pid == -1) {
- dprintf ("Couldn't fork process %s\n", strerror (errno));
- return (0);
- }
- if (pid) {
- waiting = 1;
- dprintf ("waiting for pid %d to finish\n", pid);
- waitpid (pid, &status, 0);
- if (clc_command_run_data->completion_callback) {
- clc_command_run_data->completion_callback (context);
- }
- pthread_exit(0);
- }
- switch (clc_command_run_data->type) {
- case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
- cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd;
- comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv;
- break;
- case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
- cmd = clc_command_run_data->comp->saAmfCompTerminateCmd;
- comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv;
- break;
- case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
- cmd = clc_command_run_data->comp->saAmfCompCleanupCmd;
- comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv;
- break;
- default:
- assert (0 != 1);
- break;
- }
- /* If command is not an absolute path, search for paths in parent objects */
- if (cmd[0] != '/') {
- if (strlen (clc_command_run_data->comp->clccli_path)) {
- sprintf (path, "%s/%s",
- clc_command_run_data->comp->clccli_path, cmd);
- } else if (strlen (clc_command_run_data->comp->su->clccli_path)) {
- sprintf (path, "%s/%s",
- clc_command_run_data->comp->su->clccli_path, cmd);
- } else if (strlen (clc_command_run_data->comp->su->sg->clccli_path)) {
- sprintf (path, "%s/%s",
- clc_command_run_data->comp->su->sg->clccli_path, cmd);
- } else if (strlen (clc_command_run_data->comp->su->sg->application->clccli_path)) {
- sprintf (path, "%s/%s",
- clc_command_run_data->comp->su->sg->application->clccli_path, cmd);
- }
- cmd = path;
- }
- argv[0] = cmd;
- {
- /* make a proper argv array */
- i = 1;
- char *ptrptr;
- char *arg = strtok_r(comp_argv, " ", &ptrptr);
- while (arg) {
- argv[i] = arg;
- arg = strtok_r(NULL, " ", & ptrptr);
- i++;
- }
- }
- argv[i] = NULL;
- envp[0] = env_comp_name;
- strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME=");
- strncat (env_comp_name, (char *)clc_command_run_data->comp->name.value,
- clc_command_run_data->comp->name.length);
- for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv &&
- clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) {
- envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1];
- }
- envp[i] = NULL;
- dprintf ("running command '%s' with environment:\n", cmd);
- for (i = 0; envp[i] != NULL; i++) {
- dprintf (" %s\n", envp[i]);
- }
- dprintf (" and argv:\n", cmd);
- for (i = 0; argv[i] != NULL; i++) {
- dprintf (" %s\n", argv[i]);
- }
-
- res = execve (cmd, argv, envp);
- if (res == -1) {
- log_printf (LOG_LEVEL_ERROR, "Couldn't exec program %s (%s)\n",
- cmd, strerror (errno));
- }
- assert (res != -1);
- return (0);
- }
- struct req_exec_amf_operational_state_comp_set {
- struct req_header header;
- SaNameT name;
- SaAmfOperationalStateT operational_state;
- };
- struct req_exec_amf_presence_state_comp_set {
- struct req_header header;
- SaNameT name;
- SaAmfPresenceStateT presence_state;
- };
- struct req_exec_amf_administrative_state_csi_set {
- struct req_header header;
- SaNameT name;
- SaAmfAdminStateT administrative_state;
- };
- struct req_exec_amf_administrative_state_unit_set {
- struct req_header header;
- SaNameT name;
- SaAmfAdminStateT administrative_state;
- };
- struct req_exec_amf_administrative_state_group_set {
- struct req_header header;
- SaNameT name;
- SaAmfAdminStateT administrative_state;
- };
- struct req_exec_amf_comp_restart {
- struct req_header header;
- SaNameT compName;
- };
- /*
- * Instantiate possible operations
- */
- static int clc_cli_instantiate (struct amf_comp *comp)
- {
- int res;
- pthread_t thread;
- pthread_attr_t thread_attr; /* thread attribute */
- struct clc_command_run_data *clc_command_run_data;
- ENTER("comp %s\n", getSaNameT (&comp->name));
- clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
- clc_command_run_data->comp = comp;
- clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
- clc_command_run_data->completion_callback = NULL;
- pthread_attr_init (&thread_attr);
- pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
- res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data);
- if (res != 0) {
- log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
- }
- // TODO error code from pthread_create
- return (res);
- }
- static int clc_instantiate_callback (struct amf_comp *comp)
- {
- ENTER("comp %s\n", getSaNameT (&comp->name));
- return (0);
- }
- static int clc_csi_set_callback (struct amf_comp *comp)
- {
- ENTER("comp %s\n", getSaNameT (&comp->name));
- return (0);
- }
- /*
- * Terminate possible operations
- */
- static int clc_cli_terminate (struct amf_comp *comp)
- {
- ENTER("comp %s\n", getSaNameT (&comp->name));
- return (0);
- }
- static int clc_terminate_callback (struct amf_comp *comp)
- {
- struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
- struct component_terminate_callback_data *component_terminate_callback_data;
- ENTER("comp %s\n", getSaNameT (&comp->name));
- if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
- dprintf ("component terminated but not instantiated %s - %d\n",
- getSaNameT (&comp->name), comp->saAmfCompPresenceState);
- assert (0);
- return (0);
- }
- dprintf ("component name terminating %s\n", getSaNameT (&comp->name));
- dprintf ("component presence state %d\n", comp->saAmfCompPresenceState);
- res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
- res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
- res_lib_amf_componentterminatecallback.header.error = SA_AIS_OK;
- memcpy (&res_lib_amf_componentterminatecallback.compName,
- &comp->name, sizeof (SaNameT));
- component_terminate_callback_data =
- malloc (sizeof (struct component_terminate_callback_data));
- assert (component_terminate_callback_data); // TODO failure here of malloc
- component_terminate_callback_data->comp = comp;
- res_lib_amf_componentterminatecallback.invocation =
- invocation_create (
- AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
- component_terminate_callback_data);
- dprintf ("Creating invocation %llu",
- (unsigned long long)res_lib_amf_componentterminatecallback.invocation);
-
- openais_conn_send_response (
- openais_conn_partner_get (comp->conn),
- &res_lib_amf_componentterminatecallback,
- sizeof (struct res_lib_amf_componentterminatecallback));
- return (0);
- }
- static int clc_csi_remove_callback (struct amf_comp *comp)
- {
- dprintf ("clc_tcsi_remove_callback\n");
- return (0);
- }
- /*
- * This reinstantiates the cleaned up component
- */
- static void clc_cleanup_completion_callback (void *context) {
- struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
-
- escalation_policy_restart (clc_command_run_data->comp);
- }
-
- /*
- * Cleanup possible operations
- */
- static int clc_cli_cleanup (struct amf_comp *comp)
- {
- int res;
- pthread_t thread;
- pthread_attr_t thread_attr; /* thread attribute */
- struct clc_command_run_data *clc_command_run_data;
- dprintf ("clc_cli_cleanup\n");
- clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
- clc_command_run_data->comp = comp;
- clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
- clc_command_run_data->completion_callback = clc_cleanup_completion_callback;
- pthread_attr_init (&thread_attr);
- pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
- res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data);
- if (res != 0) {
- log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
- }
- // TODO error code from pthread_create
- return (res);
- }
- static int clc_cli_cleanup_local (struct amf_comp *comp)
- {
- dprintf ("clc_cli_cleanup_local\n");
- return (0);
- }
- static int clc_instantiate (struct amf_comp *comp)
- {
- int res;
- dprintf ("clc instantiate for comp %s\n", getSaNameT (&comp->name));
- presence_state_comp_set (comp, SA_AMF_PRESENCE_INSTANTIATING);
- res = clc_interfaces[comp->comptype]->instantiate (comp);
- return (res);
- }
- #if 0
- static int clc_terminate (struct amf_comp *comp)
- {
- int res;
- dprintf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
- assert (0);
- operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
- presence_state_comp_set (comp, SA_AMF_PRESENCE_TERMINATING);
- res = clc_interfaces[comp->comptype]->terminate (comp);
- return (0);
- }
- #endif
- static int clc_cleanup (struct amf_comp *comp)
- {
- int res;
- dprintf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
- comp_healthcheck_deactivate (comp);
- operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
- presence_state_comp_set (comp, SA_AMF_PRESENCE_TERMINATING);
- res = clc_interfaces[comp->comptype]->cleanup (comp);
- return (0);
- }
- /* IMPL */
- static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
- {
- int res;
- char *error_string;
- unsigned int object_service_handle;
- int enabled = 0;
- char *value;
- char hostname[HOST_NAME_MAX + 1];
- struct amf_node *node;
- struct amf_application *app;
- struct amf_sg *sg;
- struct amf_su *su;
- struct amf_comp *comp;
- struct amf_si *si;
- struct amf_csi *csi;
- int i;
- log_init ("AMF");
- objdb->object_find_reset (OBJECT_PARENT_HANDLE);
- if (objdb->object_find (
- OBJECT_PARENT_HANDLE,
- "amf",
- strlen ("amf"),
- &object_service_handle) == 0) {
- value = NULL;
- if ( !objdb->object_key_get (object_service_handle,
- "mode",
- strlen ("mode"),
- (void *)&value,
- NULL) && value) {
- if (strcmp (value, "enabled") == 0) {
- enabled = 1;
- } else
- if (strcmp (value, "disabled") == 0) {
- enabled = 0;
- }
- }
- }
- if (!enabled) {
- return 0;
- }
-
- if (gethostname (hostname, sizeof(hostname)) == -1) {
- log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
- return -1;
- }
- res = amf_config_read (&amf_cluster, &error_string);
- if (res == -1) {
- log_printf (LOG_LEVEL_ERROR, error_string);
- return res;
- }
- dprintf("Cluster: %s", getSaNameT(&amf_cluster.name));
- dprintf(" timeout: %d ms\n", amf_cluster.saAmfClusterStartupTimeout);
- dprintf(" admin state: %s\n", admin_state_text[amf_cluster.saAmfClusterAdminState]);
- for (node = amf_cluster.node_head; node != NULL; node = node->next) {
- dprintf(" Node: %s\n", getSaNameT (&node->name));
- dprintf(" su_fail_over_prob: %u\n", node->saAmfNodeSuFailOverProb);
- dprintf(" su_fail_over_max: %u\n", node->saAmfNodeSuFailoverMax);
- dprintf(" auto repair: %u\n", node->saAmfNodeAutoRepair);
- /* look for this node */
- if (strcmp(hostname, getSaNameT (&node->name)) == 0) {
- this_amf_node = node;
- }
- }
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- dprintf(" Application: %s\n", getSaNameT(&app->name));
- dprintf(" num_sg: %d\n", app->saAmfApplicationCurrNumSG);
- for (sg = app->sg_head; sg != NULL; sg = sg->next) {
- dprintf(" SG: %s\n", getSaNameT(&sg->name));
- dprintf(" red model: %u\n", sg->saAmfSGRedundancyModel);
- dprintf(" auto adjust: %u\n", sg->saAmfSGAutoAdjust);
- for (su = sg->su_head; su != NULL; su = su->next) {
- dprintf(" SU: %s\n", getSaNameT(&su->name));
- dprintf(" rank: %u\n", su->saAmfSURank);
- for (comp = su->comp_head; comp != NULL; comp = comp->next) {
- dprintf(" Comp: %s\n", getSaNameT(&comp->name));
- dprintf(" category: %u\n", comp->saAmfCompCategory);
- dprintf(" env vars:");
- i = 0;
- while (comp->saAmfCompCmdEnv && comp->saAmfCompCmdEnv[i]) {
- dprintf(" %s", comp->saAmfCompCmdEnv[i]);
- i++;
- }
- }
- }
- }
- for (si = app->si_head; si != NULL; si = si->next) {
- dprintf(" SI: %s\n", getSaNameT(&si->name));
- for (csi = si->csi_head; csi != NULL; csi = csi->next) {
- dprintf(" CSI: %s\n", getSaNameT(&csi->name));
- }
- }
- }
- if (this_amf_node != NULL) {
- /* wait a while before instantiating SUs as the AMF spec. says. */
- poll_timer_add(aisexec_poll_handle,
- amf_cluster.saAmfClusterStartupTimeout,
- NULL,
- clc_instantiate_all,
- &amf_cluster.timeout_handle);
- } else {
- log_printf (LOG_LEVEL_INFO, "This CLM node (%s) is not configured as an AMF node, disabling...", hostname);
- }
- return (0);
- }
- static void amf_confchg_fn (
- enum totem_configuration_type configuration_type,
- unsigned int *member_list, int member_list_entries,
- unsigned int *left_list, int left_list_entries,
- unsigned int *joined_list, int joined_list_entries,
- struct memb_ring_id *ring_id)
- {
- #ifdef COMPILE_OUT
- int i;
- 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);
- recovery = 1;
- /*
- * If node join, component register
- */
- if ( joined_list_entries > 0 ) {
- enumerate_components (amf_confchg_njoin, NULL);
- }
- /*
- * If node leave, component unregister
- */
- for (i = 0; i<left_list_entries ; i++) {
- enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
- }
- #ifdef TODO
- if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
- totempg_recovery_plug_unplug (amf_recovery_plug_handle);
- recovery = 0;
- }
- #endif
- #endif
- }
- static int amf_lib_exit_fn (void *conn)
- {
- struct amf_comp *comp;
- struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
- comp = amf_pd->comp;
- TRACE8("amf_lib_exit_fn");
- if (comp) {
- comp->conn = 0;
- dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name));
- }
- return (0);
- }
- static int amf_lib_init_fn (void *conn)
- {
- struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
- list_init (&amf_pd->list);
- return (0);
- }
- #ifdef COMPILE_OUT
- static void amf_synchronize (void *message, struct in_addr source_addr)
- {
- struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
- struct amf_comp *component;
- struct amf_comp *amfProxyComponent;
- log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
- getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
- /* Find Component */
- component = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
- amfProxyComponent = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
- /* If this processor is component owner */
- if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
- /* No Operation */
- return;
- }
- /* If this isn't synchronizing target processor */
- if (!(component->local == 0 && component->registered == 0)){
- /* No Operation */
- return;
- }
- /* Synchronize Status */
- component->local = 0;
- component->registered = 1;
- component->conn_info = req_exec_amf_componentregister->source.conn_info;
- component->source_addr = source_addr;
- component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
- component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
- component->currentHAState = SA_AMF_QUIESCED;
- component->newHAState = SA_AMF_QUIESCED;
- component->probableCause = 0;
- component->enabledUnlockedState = 0;
- component->disabledUnlockedState = 0;
- component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
- component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
- component->currentHAState = req_exec_amf_componentregister->currentHAState;
- component->newHAState = req_exec_amf_componentregister->newHAState;
- if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
- component->saAmfProxyComponent = amfProxyComponent;
- }
- /*
- * Determine if we should enter new state
- */
- dsmSynchronizeStaus (component);
- return;
- }
- #endif
- static DECLARE_LIST_INIT (library_notification_send_listhead);
- // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
- #ifdef COMPILE_OUT
- static void protectiongroup_notifications_send (
- struct amf_comp *changedComponent,
- SaAmfProtectionGroupChangesT changeToComponent)
- {
- int i;
- struct conn_info *conn_info;
- struct list_head *list;
- log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
- /*
- * Iterate all tracked connections
- */
- for (list = library_notification_send_listhead.next;
- list != &library_notification_send_listhead;
- list = list->next) {
- conn_info = list_entry (list, struct conn_info, conn_list);
- for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
- if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
- if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
- != changedComponent->amf_pg->name.length) {
- continue;
- }
- if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
- changedComponent->amf_pg->name.value,
- conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
- continue;
- }
- #ifdef COMPILE_OUT
- protectiongroup_notification_send (conn_info,
- conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
- changedComponent->saAmfProtectionGroup,
- changedComponent,
- changeToComponent,
- conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
- #endif
- } /* if track flags active */
- } /* for all track entries */
- } /* for all connection entries */
- }
- #endif
- #ifdef COMPILE_OUT
- static int make_protectiongroup_notification_allcomponent (
- struct amf_comp *changedComponent,
- SaAmfProtectionGroupChangesT changeToComponent,
- SaAmfProtectionGroupNotificationT **notification )
- {
- SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
- int notifyEntries = 0;
- struct amf_comp *component;
- struct list_head *AmfGroupList;
- struct list_head *AmfUnitList;
- struct list_head *AmfComponentList;
- struct saAmfGroup *saAmfGroup;
- struct saAmfUnit *AmfUnit;
- for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
- saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
- /*
- * Search all units
- */
- for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
- AmfUnitList != &saAmfGroup->saAmfUnitHead;
- AmfUnitList = AmfUnitList->next) {
- AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
- /*
- * Search all components
- */
- for (AmfComponentList = AmfUnit->amf_compHead.next;
- AmfComponentList != &AmfUnit->amf_compHead;
- AmfComponentList = AmfComponentList->next) {
- component = list_entry (AmfComponentList, struct amf_comp, amf_compList);
- protectionGroupNotification =
- (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
- sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
- memset (&protectionGroupNotification[notifyEntries],
- 0,sizeof (SaAmfProtectionGroupNotificationT));
- memcpy (&protectionGroupNotification[notifyEntries].member.compName,
- &component->name, sizeof (SaNameT));
- // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
- // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
- memcpy (&protectionGroupNotification[notifyEntries].member.haState,
- &component->currentHAState, sizeof (SaAmfHAStateT));
- if (component == changedComponent) {
- protectionGroupNotification[notifyEntries].change = changeToComponent;
- } else {
- protectionGroupNotification[notifyEntries].change
- = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
- }
- notifyEntries += 1;
- }
- }
- }
- if (notifyEntries) {
- *notification = protectionGroupNotification;
- }
- return (notifyEntries);
- }
- #endif
- #ifdef COMPILE_OUT
- static int make_protectiongroup_notification (
- struct saAmfProtectionGroup *amfProtectionGroup,
- struct amf_comp *changedComponent,
- SaAmfProtectionGroupChangesT changeToComponent,
- SaAmfProtectionGroupNotificationT **notification )
- {
- struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
- int notifyEntries = 0;
- struct amf_comp *component;
- struct list_head *componentList;
- SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
- memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
- for (componentList = amfProtectionGroup->saAmfMembersHead.next;
- componentList != &amfProtectionGroup->saAmfMembersHead;
- componentList = componentList->next) {
- component = list_entry (componentList, struct amf_comp, saAmfProtectionGroupList);
- protectionGroupNotification =
- (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
- sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
- memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
- memcpy (&protectionGroupNotification[notifyEntries].member.compName,
- &component->name, sizeof (SaNameT));
- // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
- // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
- memcpy (&protectionGroupNotification[notifyEntries].member.haState,
- &component->currentHAState, sizeof (SaAmfHAStateT));
- if (component == changedComponent) {
- protectionGroupNotification[notifyEntries].change = changeToComponent;
- } else {
- protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
- }
- notifyEntries += 1;
- } /* for */
- if (notifyEntries) {
- *notification = protectionGroupNotification;
- }
- return (notifyEntries);
- return (0);
- }
- #endif
- #ifdef COMPILE_OUT
- static void protectiongroup_notification_send (struct conn_info *conn_info,
- SaAmfProtectionGroupNotificationT *notificationBufferAddress,
- struct saAmfProtectionGroup *amfProtectionGroup,
- struct amf_comp *changedComponent,
- SaAmfProtectionGroupChangesT changeToComponent,
- SaUint8T trackFlags)
- {
- //struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
- SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
- int notifyEntries;
- /*
- * Step through all components and generate protection group list for csi
- */
- memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
- if ( trackFlags == SA_TRACK_CHANGES ) {
- notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
- changeToComponent, &protectionGroupNotification);
- }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
- notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
- changedComponent, changeToComponent, &protectionGroupNotification );
- }else{
- notifyEntries = 0;
- }
- /*
- * Send track callback
- */
- if (notifyEntries) {
- res_lib_amf_protectiongrouptrackcallback.header.size =
- sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
- (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
- // res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
- res_lib_amf_protectiongrouptrackcallback.header.error = SA_AIS_OK;
- res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
- res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
- memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
- &amfProtectionGroup->name, sizeof (SaNameT));
- res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
- openais_conn_send_response (conno, &res_lib_amf_protectiongrouptrackcallback,
- sizeof (struct res_lib_amf_protectiongrouptrackcallback));
- openais_conn_send_response (conno, protectionGroupNotification,
- sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
- mempool_free (protectionGroupNotification);
- }
- }
- static void error_report (struct amf_comp *comp)
- {
- struct req_exec_amf_error_report req_exec_amf_error_report;
- struct iovec iovec;
- req_exec_amf_error_report.header.size = sizeof (struct req_exec_amf_error_report);
- req_exec_amf_error_report.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERROR_REPORT);
- memcpy (&req_exec_amf_error_report.compName,
- &comp->name,
- sizeof (SaNameT));
- iovec.iov_base = (char *)&req_exec_amf_error_report;
- iovec.iov_len = sizeof (req_exec_amf_error_report);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp)
- {
- struct req_exec_amf_comp_restart req_exec_amf_comp_restart;
- struct iovec iovec;
- req_exec_amf_comp_restart.header.size = sizeof (struct req_exec_amf_comp_restart);
- req_exec_amf_comp_restart.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_UNIT_RESTART);
- memcpy (&req_exec_amf_comp_restart.compName, &comp->name,
- sizeof (SaNameT));
- iovec.iov_base = (char *)&req_exec_amf_comp_restart;
- iovec.iov_len = sizeof (req_exec_amf_comp_restart);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- #endif
- #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL
- #if 0
- static struct healthcheck_active *find_healthcheck_active (
- struct amf_comp *comp,
- SaAmfHealthcheckKeyT *key,
- SaAmfHealthcheckInvocationT invocation)
- {
- struct list_head *list;
- struct healthcheck_active *ret_healthcheck_active = 0;
- struct healthcheck_active *healthcheck_active;
- for (list = comp->healthcheck_head.next;
- list != &comp->healthcheck_head;
- list = list->next) {
- healthcheck_active = list_entry (list,
- struct healthcheck_active, list);
- if ((memcmp (key, &healthcheck_active->key,
- sizeof (SaAmfHealthcheckKeyT)) == 0) &&
- (invocation == INVOCATION_DONT_COMPARE ||
- healthcheck_active->invocationType == invocation)) {
- ret_healthcheck_active = healthcheck_active;
- break;
- }
- }
- return (ret_healthcheck_active);
- }
- #endif
- static void comp_healthcheck_activate (struct amf_comp *comp)
- {
- struct amf_healthcheck *healthcheck;
- for (healthcheck = comp->healthcheck_head;
- healthcheck != NULL;
- healthcheck = healthcheck->next) {
- if (healthcheck->active == 0) {
- healthcheck_activate (healthcheck);
- }
- }
- }
- static void comp_healthcheck_deactivate (
- struct amf_comp *comp)
- {
- struct amf_healthcheck *healthcheck;
- log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n",
- getSaNameT (&comp->name));
- for (healthcheck = comp->healthcheck_head;
- healthcheck != NULL;
- healthcheck = healthcheck->next) {
- dprintf ("healthcheck deactivating %p\n", healthcheck);
- healthcheck_deactivate (healthcheck);
- }
- }
- static void presence_state_comp_set (
- struct amf_comp *comp,
- SaAmfPresenceStateT presence_state)
- {
- struct req_exec_amf_presence_state_comp_set req_exec_amf_presence_state_comp_set;
- struct iovec iovec;
- req_exec_amf_presence_state_comp_set.header.size = sizeof (struct req_exec_amf_presence_state_comp_set);
- req_exec_amf_presence_state_comp_set.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET);
- req_exec_amf_presence_state_comp_set.presence_state = presence_state;
- memcpy (&req_exec_amf_presence_state_comp_set.name,
- &comp->name,
- sizeof (SaNameT));
- iovec.iov_base = (char *)&req_exec_amf_presence_state_comp_set;
- iovec.iov_len = sizeof (req_exec_amf_presence_state_comp_set);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- static void readiness_state_comp_set (struct amf_comp *comp)
- {
- dprintf ("inputs to readiness_state_comp_set\n");
- dprintf ("\tunit readiness state %s\n",
- readiness_state_text[comp->su->saAmfSUReadinessState]);
- dprintf ("\tcomp operational state %s\n",
- oper_state_text[comp->su->saAmfSUReadinessState]);
- /*
- * Set component readiness state appropriately
- * if unit in service and component is enabled, it is in service
- * otherwise it is out of service page 37
- */
- if (comp->su->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE &&
- comp->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
- comp->saAmfCompReadinessState = SA_AMF_READINESS_IN_SERVICE;
- } else {
- comp->saAmfCompReadinessState = SA_AMF_READINESS_OUT_OF_SERVICE;
- }
- dprintf ("readiness_state_comp_set (%s)\n",
- oper_state_text[comp->saAmfCompOperState]);
- }
- static void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT oper_state)
- {
- struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set;
- struct iovec iovec;
- req_exec_amf_operational_state_comp_set.header.size = sizeof (struct req_exec_amf_operational_state_comp_set);
- req_exec_amf_operational_state_comp_set.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET);
- req_exec_amf_operational_state_comp_set.operational_state = oper_state;
- memcpy (&req_exec_amf_operational_state_comp_set.name,
- &comp->name,
- sizeof (SaNameT));
- iovec.iov_base = (char *)&req_exec_amf_operational_state_comp_set;
- iovec.iov_len = sizeof (req_exec_amf_operational_state_comp_set);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- static void csi_comp_set_callback (
- struct amf_comp *comp,
- struct amf_csi *csi,
- struct amf_pg *pg)
- {
- struct res_lib_amf_csisetcallback* res_lib_amf_csisetcallback;
- void* p;
- struct csi_set_callback_data *csi_set_callback_data;
- struct amf_csi_attribute *attribute;
- size_t char_length_of_csi_attrs=0;
- size_t num_of_csi_attrs=0;
- int i;
- dprintf("\t Assigning CSI %s to component\n", getSaNameT (&csi->name));
- for (attribute = csi->attributes_head;
- attribute != NULL;
- attribute = attribute->next) {
- for (i = 0; attribute->value[i] != NULL; i++) {
- num_of_csi_attrs++;
- char_length_of_csi_attrs += strlen(attribute->name);
- char_length_of_csi_attrs += strlen(attribute->value[i]);
- char_length_of_csi_attrs += 2;
- }
- }
- p = malloc(sizeof(struct res_lib_amf_csisetcallback)+
- char_length_of_csi_attrs);
- assert(p);
- res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback*)p;
-
- /* Address of the buffer containing the Csi name value pair */
- char* csi_attribute_buf = res_lib_amf_csisetcallback->csi_attr_buf;
- /* Byteoffset start at the zero byte */
- unsigned int byte_offset = 0;
- for (attribute = csi->attributes_head;
- attribute != NULL;
- attribute = attribute->next) {
- for (i = 0; attribute->value[i] != NULL; i++) {
- strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->name);
- byte_offset += strlen(attribute->name) + 1;
- strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->value[i]);
- byte_offset += strlen(attribute->value[i]) + 1;
- }
- }
- res_lib_amf_csisetcallback->number = num_of_csi_attrs;
- res_lib_amf_csisetcallback->csiFlags = SA_AMF_CSI_ADD_ONE;
- switch (comp->su->requested_ha_state) {
- case SA_AMF_HA_ACTIVE: {
- res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.activeCompName.length = 0;
- res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.transitionDescriptor =
- SA_AMF_CSI_NEW_ASSIGN;
- break;
- }
- case SA_AMF_HA_STANDBY: {
- res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0;
- res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.standbyRank = 1;
- break;
- }
- case SA_AMF_HA_QUIESCED: {
- /*TODO*/
- break;
- }
- case SA_AMF_HA_QUIESCING: {
- /*TODO*/
- break;
- }
- default: {
- assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED);
- break;
- }
- }
-
- res_lib_amf_csisetcallback->header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
- res_lib_amf_csisetcallback->header.size =
- sizeof (struct res_lib_amf_csisetcallback)+
- char_length_of_csi_attrs;
- res_lib_amf_csisetcallback->header.error = SA_AIS_OK;
- memcpy (&res_lib_amf_csisetcallback->compName,
- &comp->name, sizeof (SaNameT));
- memcpy (&res_lib_amf_csisetcallback->csiName,
- &csi->name, sizeof (SaNameT));
- res_lib_amf_csisetcallback->haState = comp->su->requested_ha_state;
-
- csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data));
- assert (csi_set_callback_data); // TODO failure here of malloc
- csi_set_callback_data->comp = comp;
- csi_set_callback_data->csi = csi;
- csi_set_callback_data->pg = pg;
-
- res_lib_amf_csisetcallback->invocation =
- invocation_create (
- AMF_RESPONSE_CSISETCALLBACK,
- csi_set_callback_data);
-
- openais_conn_send_response (
- openais_conn_partner_get (comp->conn),
- res_lib_amf_csisetcallback,
- res_lib_amf_csisetcallback->header.size);
- free(p);
- }
- #if 0
- static void pg_create (struct amf_si *si, struct amf_pg **pg_out)
- {
- struct amf_pg *pg;
- // struct amf_pg_comp *pg_comp;
- pg = malloc (sizeof (struct amf_pg));
- assert (pg);
- list_init (&pg->pg_comp_head);
- list_init (&pg->pg_list);
- list_add (&pg->pg_list, &si->pg_head);
- *pg_out = pg;
- }
- #endif
- static void csi_unit_set_callback (struct amf_su *unit, struct amf_si *si)
- {
- struct amf_csi *csi;
- struct amf_pg *pg = NULL;
- struct amf_comp *comp;
- SaNameT *cs_type;
- int i;
- // pg_create (csi_in->si, &pg);
- // TODO remove si from csi data structure
- /*
- ** for each component in SU, find a CSI in the SI with the same type
- */
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- dprintf ("\t%s\n", getSaNameT (&comp->name));
- int no_of_csi_types = 0;
- for (i = 0; comp->saAmfCompCsTypes[i]; i++) {
- cs_type = comp->saAmfCompCsTypes[i];
- no_of_csi_types++;
- int no_of_assignments = 0;
- for (csi = si->csi_head; csi != NULL; csi = csi->next) {
- if (!memcmp(csi->saAmfCSTypeName.value, cs_type->value, cs_type->length)) {
- csi_comp_set_callback (comp, csi, pg);
- no_of_assignments++;
- }
- }
- if (no_of_assignments == 0) {
- log_printf (LOG_WARNING, "\t No CSIs of type %s configured?!!\n",
- getSaNameT (cs_type));
- }
- }
- if (no_of_csi_types == 0) {
- log_printf (LOG_LEVEL_ERROR, "\t No CS types configured for comp %s ?!!\n",
- getSaNameT (&comp->name));
- }
- }
- }
- #if 0
- static void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
- {
- struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
- struct csi_remove_callback_data *csi_remove_callback_data;
- dprintf ("\t%s\n",
- getSaNameT (&comp->name));
- res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
- res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
- res_lib_amf_csiremovecallback.header.error = SA_AIS_OK;
- csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
- assert (csi_remove_callback_data); // TODO failure here of malloc
- csi_remove_callback_data->csi = csi;
- res_lib_amf_csiremovecallback.invocation =
- invocation_create (
- AMF_RESPONSE_CSIREMOVECALLBACK,
- csi_remove_callback_data);
- memcpy (&res_lib_amf_csiremovecallback.compName,
- &comp->name, sizeof (SaNameT));
- memcpy (&res_lib_amf_csiremovecallback.csiName,
- &csi->name, sizeof (SaNameT));
- res_lib_amf_csiremovecallback.csiFlags = 0;
-
- openais_conn_send_response (
- openais_conn_partner_get (comp->conn),
- &res_lib_amf_csiremovecallback,
- sizeof (struct res_lib_amf_csiremovecallback));
- }
- #endif
- static void assign_sis_timeout_fn(void *data)
- {
- struct amf_application *app;
- struct amf_sg *group;
- dprintf("2nd Cluster start timer expired, assigning SIs\n");
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- for (group = app->sg_head; group != NULL; group = group->next) {
- assign_sis(group);
- }
- }
- }
- static void clc_instantiate_all (void *data)
- {
- struct amf_application *app;
- struct amf_sg *group;
- struct amf_su *unit;
- struct amf_comp *comp;
- dprintf("1st Cluster start timer expired, instantiating SUs\n");
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- for (group = app->sg_head; group != NULL; group = group->next) {
- for (unit = group->su_head; unit != NULL; unit = unit->next) {
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- if (strlen ((char *)comp->saAmfCompInstantiateCmd)) {
- clc_instantiate (comp);
- }
- }
- }
- }
- }
- /* wait a while before assigning SIs as the AMF spec. says. */
- poll_timer_add(aisexec_poll_handle,
- amf_cluster.saAmfClusterStartupTimeout,
- NULL,
- assign_sis_timeout_fn,
- &amf_cluster.timeout_handle);
- }
- #if 0
- static void comp_terminate (struct amf_comp *comp)
- {
- clc_terminate (comp);
- }
- static void unit_terminate (struct amf_su *unit)
- {
- struct amf_comp *comp;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- clc_terminate (comp);
- }
- }
- #endif
- static void comp_cleanup (struct amf_comp *comp)
- {
- clc_cleanup (comp);
- }
- static void unit_cleanup (struct amf_su *unit)
- {
- struct amf_comp *comp;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- clc_cleanup (comp);
- }
- }
-
- static void comp_restart (struct amf_comp *comp)
- {
- presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
- }
- #if 0
- static void unit_restart (struct amf_su *unit)
- {
- struct amf_comp *comp;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
- }
- }
- static void clc_unit_instantiate (struct amf_su *unit)
- {
- struct amf_comp *comp;
- dprintf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- clc_instantiate (comp);
- }
- }
- #endif
- static void ha_state_unit_set (struct amf_su *unit, struct amf_si *si,
- SaAmfHAStateT ha_state)
- {
- dprintf ("Assigning SI %s to SU %s with hastate %s\n",
- getSaNameT (&si->name), getSaNameT (&unit->name), ha_state_text[ha_state]);
- unit->requested_ha_state = ha_state;
- csi_unit_set_callback (unit, si);
- }
- static int unit_inservice_count (struct amf_sg *group)
- {
- struct amf_su *unit;
- int answer = 0;
- for (unit = group->su_head; unit != NULL; unit = unit->next) {
- if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE) {
- answer += 1;
- }
- }
- return (answer);
- }
- #if 0
- static int comp_inservice_count (struct amf_su *unit)
- {
- struct amf_comp *comp;
- int answer = 0;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) {
- answer += 1;
- }
- }
- return (answer);
- }
- #endif
- static int si_count (struct amf_sg *group)
- {
- struct amf_si *si;
- int answer = 0;
- for (si = group->application->si_head; si != NULL; si = si->next) {
- answer += 1;
- }
- return (answer);
- }
- static inline int div_round (int a, int b)
- {
- int res;
-
- res = a / b;
- if ((a % b) != 0)
- res++;
- return res;
- }
- static void assign_nm_active (struct amf_sg *group, int su_units_assign)
- {
- struct amf_su *unit;
- struct amf_si *si;
- int assigned = 0;
- int assign_per_su = 0;
- int total_assigned = 0;
- assign_per_su = si_count (group);
- assign_per_su = div_round (assign_per_su, su_units_assign);
- if (assign_per_su > group->saAmfSGMaxActiveSIsperSUs) {
- assign_per_su = group->saAmfSGMaxActiveSIsperSUs;
- }
- si = group->application->si_head;
- unit = group->su_head;
- while (unit != NULL) {
- if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) {
- unit = unit->next;
- continue; /* Not in service */
- }
- assigned = 0;
- while (si != NULL &&
- assigned < assign_per_su &&
- total_assigned < si_count (group)) {
- assigned += 1;
- total_assigned += 1;
- ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
- si = si->next;
- }
- unit = unit->next;
- }
- }
- static void assign_nm_standby (struct amf_sg *group, int units_assign_standby)
- {
- struct amf_su *unit;
- struct amf_si *si;
- int assigned = 0;
- int assign_per_su = 0;
- if (units_assign_standby == 0) {
- return;
- }
- assign_per_su = si_count (group);
- assign_per_su = div_round (assign_per_su, units_assign_standby);
- if (assign_per_su > group->saAmfSGMaxStandbySIsperSUs) {
- assign_per_su = group->saAmfSGMaxStandbySIsperSUs;
- }
- si = group->application->si_head;
- unit = group->su_head;
- while (unit != NULL) {
- if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE ||
- unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
- unit = unit->next;
- continue; /* Not available for assignment */
- }
- assigned = 0;
- while (si != NULL && assigned < assign_per_su) {
- assigned += 1;
- ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
- si = si->next;
- }
- unit = unit->next;
- }
- }
- #if 0
- static void assign_nm_spare (struct amf_sg *group)
- {
- struct amf_su *unit;
- for (unit = group->su_head; unit != NULL; unit = unit->next) {
- if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE &&
- (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
- unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
- dprintf ("Assigning to SU %s with SPARE\n",
- getSaNameT (&unit->name));
- }
- }
- }
- #endif
- static void clear_requested_ha_state (struct amf_sg *group)
- {
- struct amf_su *unit;
- for (unit = group->su_head; unit != NULL; unit = unit->next) {
- unit->requested_ha_state = SA_AMF_HA_QUIESCED;
- }
- }
- static void assign_sis (struct amf_sg *group)
- {
- int active_sus_needed;
- int standby_sus_needed;
- int inservice_count;
- int units_for_standby;
- int units_for_active;
- int ii_spare;
- int su_active_assign;
- int su_standby_assign;
- int su_spare_assign;
- clear_requested_ha_state (group);
- /*
- * Number of SUs to assign to active or standby state
- */
- inservice_count = (float)unit_inservice_count (group);
- active_sus_needed = div_round (si_count(group),
- group->saAmfSGMaxActiveSIsperSUs);
- standby_sus_needed = div_round (si_count(group),
- group->saAmfSGMaxStandbySIsperSUs);
- units_for_active = inservice_count - group->saAmfSGNumPrefStandbySUs;
- if (units_for_active < 0) {
- units_for_active = 0;
- }
- units_for_standby = inservice_count - group->saAmfSGNumPrefActiveSUs;
- if (units_for_standby < 0) {
- units_for_standby = 0;
- }
- ii_spare = inservice_count - group->saAmfSGNumPrefActiveSUs - group->saAmfSGNumPrefStandbySUs;
- if (ii_spare < 0) {
- ii_spare = 0;
- }
- /*
- * Determine number of active and standby service units
- * to assign based upon reduction procedure
- */
- if ((inservice_count - active_sus_needed) < 0) {
- dprintf ("assignment VI - partial assignment with SIs drop outs\n");
- su_active_assign = active_sus_needed;
- su_standby_assign = 0;
- su_spare_assign = 0;
- } else
- if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
- dprintf ("assignment V - partial assignment with reduction of standby units\n");
- su_active_assign = active_sus_needed;
- if (standby_sus_needed > units_for_standby) {
- su_standby_assign = units_for_standby;
- } else {
- su_standby_assign = standby_sus_needed;
- }
- su_spare_assign = 0;
- } else
- if ((group->saAmfSGMaxStandbySIsperSUs * units_for_standby) <= si_count (group)) {
- dprintf ("IV: full assignment with reduction of active service units\n");
- su_active_assign = inservice_count - standby_sus_needed;
- su_standby_assign = standby_sus_needed;
- su_spare_assign = 0;
- } else
- if ((group->saAmfSGMaxActiveSIsperSUs * units_for_active) <= si_count (group)) {
- dprintf ("III: full assignment with reduction of standby service units\n");
- su_active_assign = group->saAmfSGNumPrefActiveSUs;
- su_standby_assign = units_for_standby;
- su_spare_assign = 0;
- } else
- if (ii_spare == 0) {
- dprintf ("II: full assignment with spare reduction\n");
- su_active_assign = group->saAmfSGNumPrefActiveSUs;
- su_standby_assign = group->saAmfSGNumPrefStandbySUs;
- su_spare_assign = 0;
- } else {
- dprintf ("I: full assignment with spares\n");
- su_active_assign = group->saAmfSGNumPrefActiveSUs;
- su_standby_assign = group->saAmfSGNumPrefStandbySUs;
- su_spare_assign = ii_spare;
- }
- dprintf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
- inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
- assign_nm_active (group, su_active_assign);
- assign_nm_standby (group, su_standby_assign);
- }
- static int all_sus_in_sg_ready(struct amf_sg *sg)
- {
- struct amf_su *su;
- struct amf_comp *comp;
- int ready = 1;
- for (su = sg->su_head; su != NULL; su = su->next) {
- for (comp = su->comp_head; comp != NULL; comp = comp->next) {
- if (su->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) {
- ready = 0;
- }
- }
- }
- return ready;
- }
- static void readiness_state_unit_set (struct amf_su *unit, SaAmfReadinessStateT readiness_state)
- {
- dprintf ("Assigning unit %s readiness state %s\n",
- getSaNameT (&unit->name), readiness_state_text[readiness_state]);
- unit->saAmfSUReadinessState = readiness_state;
- if (all_sus_in_sg_ready(unit->sg)){
- assign_sis (unit->sg);
- if (amf_cluster.timeout_handle) {
- poll_timer_delete (aisexec_poll_handle, amf_cluster.timeout_handle);
- }
- }
- }
- static void presence_state_unit_set (struct amf_su *unit, SaAmfPresenceStateT presence_state)
- {
- dprintf ("Setting service unit presence state %s\n",
- presence_state_text[presence_state]);
- }
- static void escalation_policy_restart (struct amf_comp *comp)
- {
- dprintf ("escalation_policy_restart %d\n", comp->su->escalation_level);
- dprintf ("escalation policy restart uninsint %p\n", comp);
- presence_state_comp_set (
- comp,
- SA_AMF_PRESENCE_UNINSTANTIATED);
- operational_state_comp_set (
- comp,
- SA_AMF_OPERATIONAL_DISABLED);
- switch (comp->su->escalation_level) {
- case ESCALATION_LEVEL_NO_ESCALATION:
- comp_restart (comp);
- break;
- case ESCALATION_LEVEL_ONE:
- comp_restart (comp);
- break;
- case ESCALATION_LEVEL_TWO:
- break;
- case ESCALATION_LEVEL_THREE:
- break;
- }
- }
- static void escalation_policy_cleanup (struct amf_comp *comp)
- {
-
- // escalation_timer_start (comp);
- switch (comp->su->escalation_level) {
- case ESCALATION_LEVEL_NO_ESCALATION:
- comp->su->saAmfSURestartCount += 1;
- if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGCompRestartMax) {
- comp->su->escalation_level = ESCALATION_LEVEL_ONE;
- escalation_policy_cleanup (comp);
- comp->su->saAmfSURestartCount = 0;
- return;
- }
- dprintf ("Escalation level 0 - restart component\n");
- dprintf ("Cleaning up and restarting component.\n");
- comp_cleanup (comp);
- break;
- case ESCALATION_LEVEL_ONE:
- comp->su->saAmfSURestartCount += 1;
- if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGSuRestartMax) {
- comp->su->escalation_level = ESCALATION_LEVEL_TWO;
- escalation_policy_cleanup (comp);
- return;
- }
- dprintf ("Escalation level 1 - restart unit\n");
- dprintf ("Cleaning up and restarting unit.\n");
- unit_cleanup (comp->su);
- break;
- case ESCALATION_LEVEL_TWO:
- dprintf ("Escalation level TWO\n");
- unit_cleanup (comp->su);
- // unit_terminate_failover (comp);
- break;
- case ESCALATION_LEVEL_THREE:
- //TODO
- break;
- }
- }
- static void timer_function_healthcheck_timeout (
- void *data)
- {
- struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)data;
- dprintf ("timeout occured on healthcheck for component %s.\n",
- getSaNameT (&healthcheck->comp->name));
- escalation_policy_cleanup (healthcheck->comp);
- }
- static void healthcheck_activate (struct amf_healthcheck *healthcheck_active)
- {
- struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
- healthcheck_active->active = 1;
- // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
- res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
- res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
- res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
- TRACE8 ("sending healthcheck to component %s",
- getSaNameT (&healthcheck_active->comp->name));
- res_lib_amf_healthcheckcallback.invocation =
- invocation_create (
- AMF_RESPONSE_HEALTHCHECKCALLBACK,
- (void *)healthcheck_active);
- memcpy (&res_lib_amf_healthcheckcallback.compName,
- &healthcheck_active->comp->name,
- sizeof (SaNameT));
- memcpy (&res_lib_amf_healthcheckcallback.key,
- &healthcheck_active->safHealthcheckKey,
- sizeof (SaAmfHealthcheckKeyT));
- openais_conn_send_response (
- openais_conn_partner_get (healthcheck_active->comp->conn),
- &res_lib_amf_healthcheckcallback,
- sizeof (struct res_lib_amf_healthcheckcallback));
- poll_timer_delete (aisexec_poll_handle,
- healthcheck_active->timer_handle_duration);
- poll_timer_add (aisexec_poll_handle,
- healthcheck_active->saAmfHealthcheckMaxDuration,
- (void *)healthcheck_active,
- timer_function_healthcheck_timeout,
- &healthcheck_active->timer_handle_duration);
- }
- static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active)
- {
- log_printf (LOG_LEVEL_NOTICE,
- "ZZZ deactivating healthcheck for component %s\n",
- getSaNameT (&healthcheck_active->comp->name));
- poll_timer_delete (aisexec_poll_handle,
- healthcheck_active->timer_handle_period);
- poll_timer_delete (aisexec_poll_handle,
- healthcheck_active->timer_handle_duration);
- invocation_destroy_by_data ((void *)healthcheck_active);
- healthcheck_active->active = 0;
- }
- static void timer_function_healthcheck_next (
- void *data)
- {
- healthcheck_activate (data);
- }
- static void operational_state_unit_set (
- struct amf_su *unit,
- SaAmfOperationalStateT oper_state)
- {
- if (oper_state == unit->saAmfSUOperState) {
- dprintf ("Not assigning service unit new operational state - same state\n");
- return;
- }
- unit->saAmfSUOperState = oper_state;
- dprintf ("Service unit operational state set to %s\n",
- oper_state_text[oper_state]);
- if (oper_state == SA_AMF_OPERATIONAL_ENABLED) {
- readiness_state_unit_set (unit,
- SA_AMF_READINESS_IN_SERVICE);
- /*
- * Start healthcheck now
- */
- // TODO healthcheck_unit_activate (unit);
- } else
- if (oper_state == SA_AMF_OPERATIONAL_DISABLED) {
- readiness_state_unit_set (unit,
- SA_AMF_READINESS_OUT_OF_SERVICE);
- // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
- // healthcheck_unit_deactivate (unit);
- }
- }
- static void message_handler_req_exec_amf_operational_state_comp_set (
- void *message,
- unsigned int nodeid)
- {
- struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
- (struct req_exec_amf_operational_state_comp_set *)message;
- struct amf_comp *comp;
- struct amf_comp *comp_compare;
- int all_set = 1;
- comp = amf_find_comp (&amf_cluster, &req_exec_amf_operational_state_comp_set->name);
- comp->saAmfCompOperState = req_exec_amf_operational_state_comp_set->operational_state;
-
- dprintf ("Setting component %s operational state to %s\n",
- getSaNameT (&comp->name),
- oper_state_text[comp->saAmfCompOperState]);
- /*
- * If all operational states are ENABLED, then SU should be ENABLED
- */
- for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp_compare->next) {
- if (comp_compare->saAmfCompOperState != SA_AMF_OPERATIONAL_ENABLED) {
- all_set = 0;
- break;
- }
- }
- if (all_set) {
- operational_state_unit_set (comp->su,
- SA_AMF_OPERATIONAL_ENABLED);
- } else {
- operational_state_unit_set (comp->su,
- SA_AMF_OPERATIONAL_DISABLED);
- }
- readiness_state_comp_set (comp);
- }
- static void message_handler_req_exec_amf_presence_state_comp_set (
- void *message,
- unsigned int nodeid)
- {
- struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
- (struct req_exec_amf_presence_state_comp_set *)message;
- struct amf_comp *comp;
- struct amf_comp *comp_compare;
- int all_set = 1;
- ENTER_VOID();
- comp = amf_find_comp (&amf_cluster, &req_exec_amf_presence_state_comp_set->name);
- assert(comp);
- if (req_exec_amf_presence_state_comp_set->presence_state == comp->saAmfCompPresenceState) {
- dprintf ("duplicate presence state set, not setting presence state\n");
- return;
- }
- if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_UNINSTANTIATED) {
- comp->conn = 0;
- }
- /*
- * The restarting state can only be entered from the uninstantiated state
- */
- if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_RESTARTING &&
- comp->saAmfCompPresenceState != SA_AMF_PRESENCE_UNINSTANTIATED) {
- dprintf ("restart presence state set even though not in terminating state\n");
- return;
- }
- comp->saAmfCompPresenceState = req_exec_amf_presence_state_comp_set->presence_state;
- if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) {
- dprintf ("SET TO RESTARTING instantiating now\n");
- clc_instantiate (comp);
- }
- dprintf ("Setting component %s presence state %s\n",
- getSaNameT (&comp->name),
- presence_state_text[comp->saAmfCompPresenceState]);
-
- /*
- * Restart components that are requested to enter the restarting presence state
- */
- /*
- * If all comp presence states are INSTANTIATED, then SU should be instantated
- */
- for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp->next) {
- if (comp_compare->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
- all_set = 0;
- break;
- }
- }
- if (all_set) {
- presence_state_unit_set (comp->su,
- SA_AMF_PRESENCE_INSTANTIATED);
- }
- }
- static void message_handler_req_exec_amf_administrative_state_csi_set (
- void *message,
- unsigned int nodeid)
- {
- // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
- // (struct req_exec_amf_administrative_state_csi_set *)message;
- // TODO
- }
- static void message_handler_req_exec_amf_administrative_state_unit_set (
- void *message,
- unsigned int nodeid)
- {
- // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
- // (struct req_exec_amf_administrative_state_unit_set *)message;
- // TODO
- }
- static void message_handler_req_exec_amf_administrative_state_group_set (
- void *message,
- unsigned int nodeid)
- {
- // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
- // (struct req_exec_amf_administrative_state_group_set *)message;
- // TODO
- }
- /*
- * Library Interface Implementation
- */
- static void message_handler_req_lib_amf_componentregister (
- void *conn,
- void *msg)
- {
- struct req_lib_amf_componentregister *req_lib_amf_componentregister =
- (struct req_lib_amf_componentregister *)msg;
- struct res_lib_amf_componentregister res_lib_amf_componentregister;
- struct amf_comp *comp;
- struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
- SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
- comp = amf_find_comp (&amf_cluster, &req_lib_amf_componentregister->compName);
- if (comp) {
- presence_state_comp_set (comp,
- SA_AMF_PRESENCE_INSTANTIATED);
- operational_state_comp_set (comp,
- SA_AMF_OPERATIONAL_ENABLED);
- comp->conn = conn;
- amf_pd->comp = comp;
- comp_healthcheck_activate (comp);
- error = SA_AIS_OK;
- }
- res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
- res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
- res_lib_amf_componentregister.header.error = error;
- openais_conn_send_response (conn, &res_lib_amf_componentregister,
- sizeof (struct res_lib_amf_componentregister));
- }
- static void message_handler_req_lib_amf_componentunregister (
- void *conn,
- void *msg)
- {
- #ifdef COMPILE_OUT
- struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
- struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
- struct iovec iovec;
- struct amf_comp *component;
- log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
- req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
- req_exec_amf_componentunregister.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
- message_source_set (&req_exec_amf_componentunregister.source, conn_info);
- memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
- req_lib_amf_componentunregister,
- sizeof (struct req_lib_amf_componentunregister));
- component = amf_find_comp (&amf_cluster, &req_lib_amf_componentunregister->compName);
- if (component && component->registered && component->local) {
- // component->probableCause = SA_AMF_NOT_RESPONDING;
- }
- iovec.iov_base = (char *)&req_exec_amf_componentunregister;
- iovec.iov_len = sizeof (req_exec_amf_componentunregister);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- #endif
- }
- static void message_handler_req_lib_amf_pmstart (
- void *conn,
- void *msg)
- {
- }
- static void message_handler_req_lib_amf_pmstop (
- void *conn,
- void *msg)
- {
- }
- static void message_handler_req_lib_amf_healthcheckstart (
- void *conn, void *msg)
- {
- struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
- (struct req_lib_amf_healthcheckstart *)msg;
- struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
- struct amf_healthcheck *healthcheck;
- struct amf_comp *comp;
- SaAisErrorT error = SA_AIS_OK;
- ENTER();
- comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstart->compName);
- if (comp == 0) {
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck = amf_find_healthcheck (comp, &req_lib_amf_healthcheckstart->healthcheckKey);
- if (healthcheck == 0) {
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- /*
- * Determine if this healthcheck is already active
- */
- if (healthcheck->active) {
- error = SA_AIS_ERR_EXIST;
- goto error_exit;
- }
- /*
- * Initialise
- */
- healthcheck->invocationType = req_lib_amf_healthcheckstart->invocationType;
- healthcheck->timer_handle_duration = 0;
- healthcheck->timer_handle_period = 0;
- healthcheck->active = 0;
- if (comp->conn == NULL) {
- comp->conn = conn;
- }
- healthcheck_activate (healthcheck);
- error_exit:
- res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
- res_lib_amf_healthcheckstart.header.size = sizeof (struct res_lib_amf_healthcheckstart);
- res_lib_amf_healthcheckstart.header.error = error;
- openais_conn_send_response (conn, &res_lib_amf_healthcheckstart,
- sizeof (struct res_lib_amf_healthcheckstart));
- }
- static void message_handler_req_lib_amf_healthcheckconfirm (
- void *conn,
- void *msg)
- {
- }
- static void message_handler_req_lib_amf_healthcheckstop (
- void *conn,
- void *msg)
- {
- struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop =
- (struct req_lib_amf_healthcheckstop *)msg;
- struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
- struct amf_healthcheck *healthcheck;
- struct amf_comp *comp;
- SaAisErrorT error = SA_AIS_OK;
- dprintf ("healthcheck stop\n");
- comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstop->compName);
- if (comp == 0) {
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck = amf_find_healthcheck (
- comp,
- &req_lib_amf_healthcheckstop->healthcheckKey);
- dprintf ("active %p\n", healthcheck);
- if (healthcheck == 0) {
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck_deactivate (healthcheck);
- error_exit:
- dprintf ("healthcheck stop\n");
- res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
- res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop);
- res_lib_amf_healthcheckstop.header.error = error;
- openais_conn_send_response (conn, &res_lib_amf_healthcheckstop,
- sizeof (struct res_lib_amf_healthcheckstop));
- }
- static void message_handler_req_lib_amf_hastateget (
- void *conn,
- void *msg)
- {
- #ifdef COMPILE_OUT
- struct req_lib_amf_hastateget *req_lib_amf_hastateget = (struct req_lib_amf_hastateget *)msg;
- struct res_lib_amf_hastateget res_lib_amf_hastateget;
- struct amf_comp *component;
- log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_hastateget()\n");
- res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
- res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
- res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
- #ifdef COMPILE_OUT
- component = component_in_protectiongroup_find (&req_lib_amf_hastateget->csiName, &req_lib_amf_hastateget->compName);
- #endif
- if (component) {
- memcpy (&res_lib_amf_hastateget.haState,
- &component->currentHAState, sizeof (SaAmfHAStateT));
- res_lib_amf_hastateget.header.error = SA_AIS_OK;
- }
- openais_conn_send_response (conn, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
- #endif
- }
- static void message_handler_req_lib_amf_protectiongrouptrack (
- void *conn,
- void *msg)
- {
- #ifdef COMPILE_OUT
- struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
- struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
- struct libamf_ci_trackentry *track = 0;
- int i;
- struct saAmfProtectionGroup *amfProtectionGroup;
- log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
- amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
- if (amfProtectionGroup) {
- log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
- for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
- if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
- track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
- break;
- }
- }
- if (track == 0) {
- grow_amf_track_table (conn_info, 1);
- track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
- }
- track->active = 1;
- track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
- track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
- memcpy (&track->csiName,
- &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
- conn_info->ais_ci.u.libamf_ci.trackActive += 1;
- list_add (&conn_info->conn_list, &library_notification_send_listhead);
-
- /*
- * If SA_TRACK_CURRENT is specified, write out all current connections
- */
- } else {
- log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
- }
- res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
- res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
- res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
- if (amfProtectionGroup) {
- res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
- }
- openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
- sizeof (struct res_lib_amf_protectiongrouptrack));
- if (amfProtectionGroup &&
- req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
- protectiongroup_notification_send (conn_info,
- track->notificationBufferAddress,
- amfProtectionGroup,
- 0,
- 0,
- SA_TRACK_CHANGES_ONLY);
- track->trackFlags &= ~SA_TRACK_CURRENT;
- }
- #endif
- }
- static void message_handler_req_lib_amf_csiquiescingcomplete (
- void *conn,
- void *msg)
- {
- }
- static void message_handler_req_lib_amf_protectiongrouptrackstop (
- void *conn,
- void *msg)
- {
- #ifdef COMPILE_OUT
- struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
- struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
- struct libamf_ci_trackentry *track = 0;
- int i;
- log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
- for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
- if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
- &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
- track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
- }
- }
- if (track) {
- log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
- memset (track, 0, sizeof (struct libamf_ci_trackentry));
- conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
- if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
- list_del (&conn_info->conn_list);
- }
- }
- res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
- res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
- res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
- if (track) {
- res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
- }
- openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
- sizeof (struct res_lib_amf_protectiongrouptrackstop));
- #endif
- }
- static void message_handler_req_lib_amf_componenterrorreport (
- void *conn,
- void *msg)
- {
- struct req_lib_amf_componenterrorreport *req_lib_amf_componenterrorreport = (struct req_lib_amf_componenterrorreport *)msg;
- struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
- struct amf_comp *comp;
- SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
- ENTER();
- log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n");
- dprintf ("ERROR REPORT\n");
- comp = amf_find_comp (&amf_cluster, &req_lib_amf_componenterrorreport->erroneousComponent);
- if (comp) {
- dprintf ("escalation policy terminate\n");
- escalation_policy_cleanup (comp);
- error = SA_AIS_OK;
- }
- res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
- res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
- res_lib_amf_componenterrorreport.header.error = error;
- openais_conn_send_response (
- conn, &res_lib_amf_componenterrorreport,
- sizeof (struct res_lib_amf_componenterrorreport));
- }
- static void message_handler_req_lib_amf_componenterrorclear (
- void *conn,
- void *msg)
- {
- #ifdef COMPILLE_OUT
- struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
- struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
- struct iovec iovec;
- log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
- req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
- req_exec_amf_componenterrorclear.header.id =
- SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
- message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
- memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
- req_lib_amf_componenterrorclear,
- sizeof (struct req_lib_amf_componenterrorclear));
- iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
- iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- #endif
- }
- #if 0
- static void pg_comp_create (
- struct amf_pg *pg,
- struct amf_csi *csi,
- struct amf_comp *comp)
- {
- struct amf_pg_comp *pg_comp;
- dprintf ("creating component for pg\n");
- pg_comp = malloc (sizeof (struct amf_pg_comp));
- assert (pg_comp);
- pg_comp->comp = comp;
- pg_comp->csi = csi;
- list_init (&pg_comp->list);
- list_add_tail (&pg_comp->list, &pg->pg_comp_head);
- }
- #endif
- static void message_handler_req_lib_amf_response (void *conn, void *msg)
- {
- struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)msg;
- struct res_lib_amf_response res_lib_amf_response;
- struct csi_set_callback_data *csi_set_callback_data;
- struct csi_remove_callback_data *csi_remove_callback_data;
- struct component_terminate_callback_data *component_terminate_callback_data;
- struct amf_healthcheck *healthcheck_active;
- int interface;
- int res;
- void *data;
- SaAisErrorT error = SA_AIS_OK;
- ENTER_VOID();
- res = invocation_get_and_destroy (req_lib_amf_response->invocation,
- &interface, &data);
- if (res == -1) {
- dprintf ("invocation not found\n");
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- switch (interface) {
- case AMF_RESPONSE_HEALTHCHECKCALLBACK:
- dprintf ("healtcheck callback executed from library.\n");
- healthcheck_active = (struct amf_healthcheck*)data;
- poll_timer_delete (aisexec_poll_handle,
- healthcheck_active->timer_handle_duration);
- healthcheck_active->timer_handle_duration = 0;
- poll_timer_add (aisexec_poll_handle,
- healthcheck_active->saAmfHealthcheckPeriod,
- (void *)healthcheck_active,
- timer_function_healthcheck_next,
- &healthcheck_active->timer_handle_period);
- break;
- case AMF_RESPONSE_CSISETCALLBACK:
- csi_set_callback_data = (struct csi_set_callback_data *)data;
- dprintf ("csi set callback executed from library.\n");
- // list_add (&csi_set_callback_data->comp->
- /*
- pg_comp_create (
- csi_set_callback_data->pg,
- csi_set_callback_data->csi,
- csi_set_callback_data->comp);
- */
- free (csi_set_callback_data);
- break;
- case AMF_RESPONSE_CSIREMOVECALLBACK:
- csi_remove_callback_data = (struct csi_remove_callback_data *)data;
- dprintf ("response from removing the CSI\n");
- // AAAA
- // list_del (&csi_remove_callback_data->csi->si->su_list);
- // list_del (&csi_remove_callback_data->csi->si_csi_list);
- free (csi_remove_callback_data);
- break;
- case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
- component_terminate_callback_data = (struct component_terminate_callback_data *)data;
- dprintf ("response from terminating component\n");
- comp_healthcheck_deactivate (component_terminate_callback_data->comp);
- escalation_policy_restart (component_terminate_callback_data->comp);
- break;
- default:
- // TODO
- log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_lib_amf_response->invocation);
- break;
- }
- error_exit:
- res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
- res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
- res_lib_amf_response.header.error = SA_AIS_OK;
- openais_conn_send_response (conn, &res_lib_amf_response,
- sizeof (struct res_lib_amf_response));
- LEAVE_VOID();
- }
- static void amf_dump_comp (struct amf_comp *comp ,void *data)
- {
- #if 0
- int level = LOG_LEVEL_NOTICE;
- data = NULL;
- struct list_head* cs_types;
- struct amf_cs_type* cs_type;
- log_printf (level, "----------------\n" );
- log_printf (level, "source_addr = %s\n",
- inet_ntoa (comp->source_addr));
- log_printf (level, "unit = %s\n",
- comp->su->name.value);
- log_printf (level, "name = %s\n", comp->name.value);
- log_printf (level, "cs types\n");
- for (cs_types = comp->cs_types.next;
- cs_types != &comp->cs_types;
- cs_types = cs_types->next) {
- cs_type = list_entry (cs_types, struct amf_cs_type, comp_cs_type_list);
- log_printf (level, " name = %s\n" , cs_type->attr_name.value);
- }
- log_printf (level, "category = %u\n", comp->category);
- log_printf (level, "capability = %u\n", comp->capability);
- log_printf (level, "num_max_active_csi = %u\n",
- comp->num_max_active_csi);
- log_printf (level, "num_max_standby_csi = %u\n",
- comp->num_max_standby_csi);
- log_printf (level, "default_clc_cli_timeout = %u\n",
- comp->default_clc_cli_timeout);
- log_printf (level, "default_callback_timeout = %u\n",
- comp->default_callback_timeout);
- log_printf (level, "oper state = %s\n",
- oper_state_text[comp->saAmfCompOperState]);
- log_printf (level, "readiness state = %s\n",
- readiness_state_text[comp->saAmfCompReadinessState]);
- log_printf (level, "presence state = %s\n",
- presence_state_text[comp->saAmfCompPresenceState]);
- log_printf (level, "restart_count = %u\n",
- comp->restart_count);
- #endif
- }
- static void enumerate_components (
- void (*function)(struct amf_comp *, void *data),
- void *data)
- {
- #if 0
- struct list_head *AmfGroupList;
- struct list_head *AmfUnitList;
- struct list_head *AmfComponentList;
- struct amf_sg *saAmfGroup;
- struct amf_su *AmfUnit;
- struct amf_comp *AmfComponent;
- /*
- * Search all groups
- */
- for (AmfGroupList = amf_sg_head.next;
- AmfGroupList != &amf_sg_head;
- AmfGroupList = AmfGroupList->next) {
- saAmfGroup = list_entry (AmfGroupList,
- struct amf_sg, application_sg_list);
- /*
- * Search all units
- */
- for (AmfUnitList = saAmfGroup->su_head.next;
- AmfUnitList != &saAmfGroup->su_head;
- AmfUnitList = AmfUnitList->next) {
- AmfUnit = list_entry (AmfUnitList,
- struct amf_su, sg_su_list);
- /*
- * Search all components
- */
- for (AmfComponentList = AmfUnit->comp_head.next;
- AmfComponentList != &AmfUnit->comp_head;
- AmfComponentList = AmfComponentList->next) {
- AmfComponent = list_entry (AmfComponentList,
- struct amf_comp, su_comp_list);
- function (AmfComponent, data);
- }
- }
- }
- #endif
- }
- static void amf_dump ( )
- {
- enumerate_components (amf_dump_comp, NULL);
- }
|