| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016 |
- /*
- * 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
- * - Use DN in API and multicast messages
- * - (Re-)Introduction of event based multicast messages
- *
- * 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 "mempool.h"
- #include "util.h"
- #include "amfconfig.h"
- #include "main.h"
- #include "timer.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_COMPONENT_REGISTER = 0,
- MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT = 1,
- MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED = 2,
- MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO = 3,
- MESSAGE_REQ_EXEC_AMF_RESPONSE = 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 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_comp_register (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_comp_error_report (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_clc_cleanup_completed (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_healthcheck_tmo (
- void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_amf_response (
- void *message,
- unsigned int nodeid);
- static void comp_presence_state_set (
- struct amf_comp *comp,
- SaAmfPresenceStateT presence_state);
- static void comp_operational_state_set (
- struct amf_comp *comp,
- SaAmfOperationalStateT operational_state);
- static void su_operational_state_set (
- struct amf_su *unit,
- SaAmfOperationalStateT operational_state);
- static void su_presence_state_set (
- struct amf_su *su,
- SaAmfPresenceStateT presence_state);
- static void sg_assign_si (struct amf_sg *group);
- 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_runtime_attributes_print (void);
- static void clc_su_instantiate (struct amf_su *unit);
- static void cluster_start_applications (void *data);
- 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",
- };
- static char *assignment_state_text[] = {
- "UNKNOWN",
- "UNASSIGNED",
- "FULLY-ASSIGNED",
- "PARTIALLY-ASSIGNED"
- };
- 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_comp_register,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_comp_error_report,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_clc_cleanup_completed,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_healthcheck_tmo,
- },
- {
- .exec_handler_fn = message_handler_req_exec_amf_response,
- }
- };
- /*
- * 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_runtime_attributes_print
- };
- 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);
- };
- struct req_exec_amf_comp_register {
- struct req_header header;
- SaNameT compName;
- SaNameT proxyCompName;
- };
- struct req_exec_amf_comp_error_report {
- struct req_header header;
- SaNameT reportingComponent;
- SaNameT erroneousComponent;
- SaTimeT errorDetectionTime;
- SaAmfRecommendedRecoveryT recommendedRecovery;
- SaNtfIdentifierT ntfIdentifier;
- };
- struct req_exec_amf_clc_cleanup_completed {
- struct req_header header;
- SaNameT compName;
- };
- struct req_exec_amf_healthcheck_tmo {
- struct req_header header;
- SaNameT compName;
- };
- struct req_exec_amf_response {
- struct req_header header;
- SaNameT compName;
- SaNameT csiName;
- unsigned int interface;
- SaAisErrorT error;
- };
- static char *comp_dn_make (struct amf_comp *comp, SaNameT *name)
- {
- int i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH,
- "safComp=%s,safSu=%s,safSg=%s,safApp=%s",
- comp->name.value, comp->su->name.value,
- comp->su->sg->name.value, comp->su->sg->application->name.value);
- assert (i <= SA_MAX_NAME_LENGTH);
- name->length = i;
- return (char *)name->value;
- }
- static char *csi_dn_make (struct amf_csi *csi, SaNameT *name)
- {
- int i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH,
- "safCsi=%s,safSi=%s,safApp=%s",
- csi->name.value, csi->si->name.value,
- csi->si->application->name.value);
- assert (i <= SA_MAX_NAME_LENGTH);
- name->length = i;
- return (char *)name->value;
- }
- 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 comp_name[SA_MAX_NAME_LENGTH];
- 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);
- dprintf ("process (%d) finished with %d\n", pid, status);
- 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] = comp_name;
- i = snprintf(comp_name, SA_MAX_NAME_LENGTH,
- "SA_AMF_COMPONENT_NAME=safComp=%s,safSu=%s,safSg=%s,safApp=%s",
- clc_command_run_data->comp->name.value,
- clc_command_run_data->comp->su->name.value,
- clc_command_run_data->comp->su->sg->name.value,
- clc_command_run_data->comp->su->sg->application->name.value);
- assert (i <= SA_MAX_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);
- }
- /*
- * 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));
- if (clc_command_run_data == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- 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));
- if (component_terminate_callback_data == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- 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);
- }
- /*
- * Clean up completed
- */
- static void clc_cleanup_completion_callback (void *context) {
- struct clc_command_run_data *clc_command_run_data =
- (struct clc_command_run_data *)context;
- struct req_exec_amf_clc_cleanup_completed req;
- struct iovec iovec;
- TRACE2("CLC cleanup done for '%s'", clc_command_run_data->comp->name.value);
- req.header.size = sizeof (struct req_exec_amf_clc_cleanup_completed);
- req.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
- MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED);
- comp_dn_make (clc_command_run_data->comp, &req.compName);
- iovec.iov_base = (char *)&req;
- iovec.iov_len = sizeof (req);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
-
- /*
- * 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));
- if (clc_command_run_data == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- 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 = 0;
- dprintf ("clc instantiate for comp '%s'\n", getSaNameT (&comp->name));
- if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_RESTARTING) {
- comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATING);
- }
- if (comp->su->is_local) {
- 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);
- comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
- res = clc_interfaces[comp->comptype]->terminate (comp);
- return (0);
- }
- #endif
- static int presence_state_all_comps_in_su_are_set (struct amf_su *su, SaAmfPresenceStateT state)
- {
- int all_set = 1;
- struct amf_comp *comp;
- for (comp = su->comp_head; comp != NULL; comp = comp->next) {
- if (comp->saAmfCompPresenceState != state) {
- all_set = 0;
- }
- }
- return all_set;
- }
- static int clc_cleanup (struct amf_comp *comp)
- {
- int res = 0;
- dprintf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
- comp_healthcheck_deactivate (comp);
- comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
- /* when all components in su are restarting, the SU becomes restarting */
- if (presence_state_all_comps_in_su_are_set(comp->su, SA_AMF_PRESENCE_RESTARTING)) {
- su_presence_state_set (comp->su, SA_AMF_PRESENCE_RESTARTING);
- }
- if (comp->su->is_local) {
- res = clc_interfaces[comp->comptype]->cleanup (comp);
- }
- return res;
- }
- /* IMPL */
- static void amf_runtime_attributes_print (void)
- {
- 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;
- struct amf_si_assignment *si_assignment;
- struct amf_csi_assignment *csi_assignment;
- dprintf("AMF runtime attributes:");
- dprintf("===================================================");
- dprintf("safCluster=%s", getSaNameT(&amf_cluster.name));
- dprintf(" admin state: %s\n", admin_state_text[amf_cluster.saAmfClusterAdminState]);
- for (node = amf_cluster.node_head; node != NULL; node = node->next) {
- dprintf(" safNode=%s\n", getSaNameT (&node->name));
- dprintf(" admin state: %s\n", admin_state_text[node->saAmfNodeAdminState]);
- dprintf(" oper state: %s\n", oper_state_text[node->saAmfNodeOperState]);
- }
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- dprintf(" safApp=%s\n", getSaNameT(&app->name));
- dprintf(" admin state: %s\n", admin_state_text[app->saAmfApplicationAdminState]);
- dprintf(" num_sg: %d\n", app->saAmfApplicationCurrNumSG);
- for (sg = app->sg_head; sg != NULL; sg = sg->next) {
- dprintf(" safSG=%s\n", getSaNameT(&sg->name));
- dprintf(" admin state: %s\n", admin_state_text[sg->saAmfSGAdminState]);
- dprintf(" assigned SUs %d\n", sg->saAmfSGNumCurrAssignedSUs);
- dprintf(" non inst. spare SUs %d\n", sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
- dprintf(" inst. spare SUs %d\n", sg->saAmfSGNumCurrInstantiatedSpareSUs);
- for (su = sg->su_head; su != NULL; su = su->next) {
- dprintf(" safSU=%s\n", getSaNameT(&su->name));
- dprintf(" oper state: %s\n", oper_state_text[su->saAmfSUOperState]);
- dprintf(" admin state: %s\n", admin_state_text[su->saAmfSUAdminState]);
- dprintf(" readiness state: %s\n", readiness_state_text[su->saAmfSUReadinessState]);
- dprintf(" presence state: %s\n", presence_state_text[su->saAmfSUPresenceState]);
- dprintf(" hosted by node %s\n", su->saAmfSUHostedByNode.value);
- dprintf(" num active SIs %d\n", su->saAmfSUNumCurrActiveSIs);
- dprintf(" num standby SIs %d\n", su->saAmfSUNumCurrStandbySIs);
- dprintf(" restart count %d\n", su->saAmfSURestartCount);
- dprintf(" escalation level %d\n", su->escalation_level);
- dprintf(" SU failover cnt %d\n", su->su_failover_cnt);
- dprintf(" assigned SIs:");
- for (si_assignment = su->assigned_sis; si_assignment != NULL;
- si_assignment = si_assignment->next) {
- dprintf(" safSi=%s\n", si_assignment->si->name.value);
- dprintf(" HA state: %s\n",
- ha_state_text[si_assignment->saAmfSISUHAState]);
- }
- for (comp = su->comp_head; comp != NULL; comp = comp->next) {
- dprintf(" safComp=%s\n", getSaNameT(&comp->name));
- dprintf(" oper state: %s\n",
- oper_state_text[comp->saAmfCompOperState]);
- dprintf(" readiness state: %s\n",
- readiness_state_text[comp->saAmfCompReadinessState]);
- dprintf(" presence state: %s\n",
- presence_state_text[comp->saAmfCompPresenceState]);
- dprintf(" num active CSIs %d\n",
- comp->saAmfCompNumCurrActiveCsi);
- dprintf(" num standby CSIs %d\n",
- comp->saAmfCompNumCurrStandbyCsi);
- dprintf(" restart count %d\n", comp->saAmfCompRestartCount);
- dprintf(" assigned CSIs:");
- for (csi_assignment = comp->assigned_csis; csi_assignment != NULL;
- csi_assignment = csi_assignment->comp_next) {
- dprintf(" safCSI=%s\n", csi_assignment->csi->name.value);
- dprintf(" HA state: %s\n",
- ha_state_text[csi_assignment->saAmfCSICompHASate]);
- }
- }
- }
- }
- for (si = app->si_head; si != NULL; si = si->next) {
- dprintf(" safSi=%s\n", getSaNameT(&si->name));
- dprintf(" admin state: %s\n", admin_state_text[si->saAmfSIAdminState]);
- dprintf(" assignm. state: %s\n", assignment_state_text[si->saAmfSIAssignmentState]);
- dprintf(" active assignments: %d\n", si->saAmfSINumCurrActiveAssignments);
- dprintf(" standby assignments: %d\n", si->saAmfSINumCurrStandbyAssignments);
- for (csi = si->csi_head; csi != NULL; csi = csi->next) {
- dprintf(" safCsi=%s\n", getSaNameT(&csi->name));
- }
- }
- }
- dprintf("===================================================");
- }
- /* to be removed... */
- static int amf_enabled (struct objdb_iface_ver0 *objdb)
- {
- unsigned int object_service_handle;
- char *value;
- int enabled = 0;
- 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;
- }
- }
- }
- return enabled;
- }
- static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
- {
- int res;
- char *error_string;
- char hostname[HOST_NAME_MAX + 1];
- struct amf_node *node;
- log_init ("AMF");
- if (!amf_enabled (objdb)) {
- return 0;
- }
-
- res = amf_config_read (&amf_cluster, &error_string);
- if (res == -1) {
- log_printf (LOG_LEVEL_ERROR, error_string);
- return res;
- }
- if (gethostname (hostname, sizeof(hostname)) == -1) {
- log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
- return -1;
- }
- /* look for this node */
- for (node = amf_cluster.node_head; node != NULL; node = node->next) {
- if (strcmp(hostname, getSaNameT (&node->name)) == 0) {
- this_amf_node = node;
- }
- }
- if (this_amf_node != NULL) {
- this_amf_node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED;
- /* wait a while before starting applications as the AMF spec. says. */
- openais_timer_add(
- amf_cluster.saAmfClusterStartupTimeout,
- NULL,
- cluster_start_applications,
- &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);
- assert (amf_pd != NULL);
- comp = amf_pd->comp;
- assert (comp != NULL);
- comp->conn = NULL;
- 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);
- }
- 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);
- }
- }
- #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);
- }
- static void comp_healthcheck_activate (struct amf_comp *comp)
- {
- struct amf_healthcheck *healthcheck;
- if (!comp->is_local)
- return;
- for (healthcheck = comp->healthcheck_head;
- healthcheck != NULL;
- healthcheck = healthcheck->next) {
- if (healthcheck->active == 0) {
- healthcheck_activate (healthcheck);
- }
- }
- }
- #endif
- static void comp_healthcheck_deactivate (
- struct amf_comp *comp)
- {
- struct amf_healthcheck *healthcheck;
- if (!comp->su->is_local)
- return;
- ENTER ("'%s'\n", getSaNameT (&comp->name));
- for (healthcheck = comp->healthcheck_head;
- healthcheck != NULL;
- healthcheck = healthcheck->next) {
- if (healthcheck->active) {
- healthcheck_deactivate (healthcheck);
- }
- }
- }
- static void comp_presence_state_set (struct amf_comp *comp,
- SaAmfPresenceStateT presence_state)
- {
- comp->saAmfCompPresenceState = presence_state;
- TRACE1 ("Setting comp '%s' presence state: %s\n",
- comp->name.value, presence_state_text[comp->saAmfCompPresenceState]);
- /*
- * If all comp presence states are INSTANTIATED, then SU should be instantated
- */
- if ((presence_state == SA_AMF_PRESENCE_INSTANTIATED) &&
- presence_state_all_comps_in_su_are_set (comp->su, SA_AMF_PRESENCE_INSTANTIATED)) {
- su_presence_state_set (comp->su, SA_AMF_PRESENCE_INSTANTIATED);
- }
- }
- static void comp_readiness_state_set (struct amf_comp *comp)
- {
- /*
- * Set component readiness state appropriately
- * if unit in service and component is enabled, it is in service
- * otherwise it is out of service page 50 B.02.01
- */
- if (comp->su->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE &&
- comp->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
- comp->saAmfCompReadinessState = SA_AMF_READINESS_IN_SERVICE;
- } else if (comp->su->saAmfSUReadinessState == SA_AMF_READINESS_STOPPING &&
- comp->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
- comp->saAmfCompReadinessState = SA_AMF_READINESS_STOPPING;
- } else {
- comp->saAmfCompReadinessState = SA_AMF_READINESS_OUT_OF_SERVICE;
- }
- TRACE1 ("Setting comp '%s' readiness state: %s\n",
- comp->name.value, readiness_state_text[comp->saAmfCompReadinessState]);
- }
- static void comp_operational_state_set (struct amf_comp *comp,
- SaAmfOperationalStateT oper_state)
- {
- struct amf_comp *comp_compare;
- int all_set;
- comp->saAmfCompOperState = oper_state;
- TRACE1 ("Setting comp '%s' operational state: %s\n",
- comp->name.value, oper_state_text[comp->saAmfCompOperState]);
- /*
- * If all operational states are ENABLED, then SU should be ENABLED
- */
- if (oper_state == SA_AMF_OPERATIONAL_ENABLED) {
- all_set = 1;
- for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp->next) {
- if (comp_compare->saAmfCompOperState != SA_AMF_OPERATIONAL_ENABLED) {
- all_set = 0;
- break;
- }
- }
- if (all_set) {
- su_operational_state_set (comp->su, SA_AMF_OPERATIONAL_ENABLED);
- } else {
- su_operational_state_set (comp->su, SA_AMF_OPERATIONAL_DISABLED);
- }
- }
- }
- static void comp_csi_set_callback (
- struct amf_comp *comp,
- struct amf_csi_assignment *csi_assignment)
- {
- struct res_lib_amf_csisetcallback* res_lib_amf_csisetcallback;
- void* p;
- struct amf_csi_attribute *attribute;
- size_t char_length_of_csi_attrs=0;
- size_t num_of_csi_attrs=0;
- int i;
- struct amf_csi *csi = csi_assignment->csi;
- int ha_state = csi_assignment->saAmfCSICompHASate;
- if (!comp->su->is_local)
- return;
- dprintf("\t Assigning CSI '%s' state %s to comp '%s'\n",
- getSaNameT (&csi->name), ha_state_text[ha_state], comp->name.value);
- 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);
- if (p == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- 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 (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;
- comp_dn_make (comp, &res_lib_amf_csisetcallback->compName);
- csi_dn_make (csi, &res_lib_amf_csisetcallback->csiName);
- res_lib_amf_csisetcallback->haState = ha_state;
- res_lib_amf_csisetcallback->invocation =
- invocation_create (AMF_RESPONSE_CSISETCALLBACK, csi_assignment);
- 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
- #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 cluster_assign_workload (void *data)
- {
- struct amf_application *app;
- struct amf_sg *sg;
- dprintf("2nd Cluster start timer expired, assigning SIs\n");
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- for (sg = app->sg_head; sg != NULL; sg = sg->next) {
- sg_assign_si (sg);
- }
- }
- }
- static void cluster_start_applications (void *data)
- {
- struct amf_application *app;
- struct amf_sg *sg;
- struct amf_su *su;
- dprintf("1st Cluster start timer expired, instantiating SUs");
- for (app = amf_cluster.application_head; app != NULL; app = app->next) {
- for (sg = app->sg_head; sg != NULL; sg = sg->next) {
- for (su = sg->su_head; su != NULL; su = su->next) {
- /* Only start SUs configured to this node */
- if (name_match (&this_amf_node->name,
- &su->saAmfSUHostedByNode )) {
- su->is_local = 1;
- clc_su_instantiate (su);
- }
- }
- }
- }
- /* wait a while before assigning SIs as the AMF spec. says. */
- openais_timer_add(
- amf_cluster.saAmfClusterStartupTimeout,
- NULL,
- cluster_assign_workload,
- &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 su_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)
- {
- comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
- }
- static void comp_reassign_csis (struct amf_comp *comp)
- {
- struct amf_csi_assignment *csi_assignment = comp->assigned_csis;
- ENTER ("'%s'", comp->name.value);
- for (; csi_assignment; csi_assignment = csi_assignment->comp_next) {
- comp_csi_set_callback (comp, csi_assignment);
- }
- }
- #if 0
- static void unit_restart (struct amf_su *unit)
- {
- struct amf_comp *comp;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
- }
- }
- #endif
- static void clc_su_instantiate (struct amf_su *unit)
- {
- struct amf_comp *comp;
- for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
- clc_instantiate (comp);
- }
- }
- static void comp_assign_csi (struct amf_comp *comp, struct amf_csi *csi,
- SaAmfHAStateT ha_state)
- {
- struct amf_csi_assignment *csi_assignment;
- dprintf (" Assigning CSI '%s' to comp '%s' with hastate %s\n",
- getSaNameT (&csi->name), getSaNameT (&comp->name),
- ha_state_text[ha_state]);
- csi_assignment = malloc (sizeof (struct amf_csi_assignment));
- if (csi_assignment == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- csi_assignment->comp_next = comp->assigned_csis;
- comp->assigned_csis = csi_assignment;
- setSaNameT (&csi_assignment->name, (char*)comp->name.value);
- csi_assignment->saAmfCSICompHASate = ha_state;
- csi_assignment->csi = csi;
- csi_assignment->comp = comp;
- csi_assignment->saAmfCSICompHASate = ha_state;
- if (ha_state == SA_AMF_HA_ACTIVE)
- comp->saAmfCompNumCurrActiveCsi++;
- else if (ha_state == SA_AMF_HA_STANDBY)
- comp->saAmfCompNumCurrStandbyCsi++;
- else
- assert (0);
- comp_csi_set_callback (comp, csi_assignment);
- }
- static void su_assign_si (struct amf_su *su, struct amf_si *si,
- SaAmfHAStateT ha_state)
- {
- struct amf_si_assignment *si_assignment;
- dprintf ("Assigning SI '%s' to SU '%s' with hastate %s\n",
- getSaNameT (&si->name), getSaNameT (&su->name),
- ha_state_text[ha_state]);
- si_assignment = malloc (sizeof (struct amf_si_assignment));
- if (si_assignment == NULL) {
- openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
- }
- setSaNameT (&si_assignment->name, (char*)su->name.value);
- si_assignment->saAmfSISUHAState = ha_state;
- si_assignment->next = su->assigned_sis;
- su->assigned_sis = si_assignment;
- si_assignment->si = si;
- if (ha_state == SA_AMF_HA_ACTIVE) {
- si->saAmfSINumCurrActiveAssignments++;
- su->saAmfSUNumCurrActiveSIs++;
- } else if (ha_state == SA_AMF_HA_STANDBY) {
- su->saAmfSUNumCurrStandbySIs++;
- si->saAmfSINumCurrStandbyAssignments++;
- } else
- assert(0);
- if ((si->saAmfSINumCurrActiveAssignments == si->saAmfSIPrefActiveAssignments) &&
- (si->saAmfSINumCurrStandbyAssignments == si->saAmfSIPrefStandbyAssignments)) {
- si->saAmfSIAssignmentState = SA_AMF_ASSIGNMENT_FULLY_ASSIGNED;
- } else if ((si->saAmfSINumCurrActiveAssignments < si->saAmfSIPrefActiveAssignments) ||
- (si->saAmfSINumCurrStandbyAssignments < si->saAmfSIPrefStandbyAssignments)) {
- si->saAmfSIAssignmentState = SA_AMF_ASSIGNMENT_PARTIALLY_ASSIGNED;
- }
- {
- struct amf_csi *csi;
- struct amf_comp *comp;
- SaNameT *cs_type;
- int i;
- /*
- ** for each component in SU, find a CSI in the SI with the same type
- */
- for (comp = su->comp_head; comp != NULL; comp = comp->next) {
- int no_of_cs_types = 0;
- for (i = 0; comp->saAmfCompCsTypes[i]; i++) {
- cs_type = comp->saAmfCompCsTypes[i];
- no_of_cs_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)) {
- comp_assign_csi (comp, csi, ha_state);
- 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_cs_types == 0) {
- log_printf (LOG_LEVEL_ERROR, "\t No CS types configured for comp %s ?!!\n",
- getSaNameT (&comp->name));
- }
- }
- }
- }
- static int su_inservice_count_get (struct amf_sg *sg)
- {
- struct amf_su *unit;
- int answer = 0;
- for (unit = sg->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 application_si_count_get (struct amf_application *app)
- {
- struct amf_si *si;
- int answer = 0;
- for (si = app->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 sg_assign_nm_active (struct amf_sg *sg, 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 = application_si_count_get (sg->application);
- assign_per_su = div_round (assign_per_su, su_units_assign);
- if (assign_per_su > sg->saAmfSGMaxActiveSIsperSUs) {
- assign_per_su = sg->saAmfSGMaxActiveSIsperSUs;
- }
- si = sg->application->si_head;
- unit = sg->su_head;
- while (unit != NULL) {
- if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE ||
- unit->saAmfSUNumCurrActiveSIs == sg->saAmfSGMaxActiveSIsperSUs ||
- unit->saAmfSUNumCurrStandbySIs > 0) {
- unit = unit->next;
- continue; /* Not in service */
- }
- assigned = 0;
- while (si != NULL &&
- assigned < assign_per_su &&
- total_assigned < application_si_count_get (sg->application)) {
- assigned += 1;
- total_assigned += 1;
- su_assign_si (unit, si, SA_AMF_HA_ACTIVE);
- si = si->next;
- }
- unit = unit->next;
- }
-
- if (total_assigned == 0) {
- dprintf ("Error: No SIs assigned!");
- }
- }
- static void sg_assign_nm_standby (struct amf_sg *sg, int units_assign_standby)
- {
- struct amf_su *unit;
- struct amf_si *si;
- int assigned = 0;
- int assign_per_su = 0;
- int total_assigned = 0;
- if (units_assign_standby == 0) {
- return;
- }
- assign_per_su = application_si_count_get (sg->application);
- assign_per_su = div_round (assign_per_su, units_assign_standby);
- if (assign_per_su > sg->saAmfSGMaxStandbySIsperSUs) {
- assign_per_su = sg->saAmfSGMaxStandbySIsperSUs;
- }
- si = sg->application->si_head;
- unit = sg->su_head;
- while (unit != NULL) {
- if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE ||
- unit->saAmfSUNumCurrActiveSIs > 0 ||
- unit->saAmfSUNumCurrStandbySIs == sg->saAmfSGMaxStandbySIsperSUs) {
- unit = unit->next;
- continue; /* Not available for assignment */
- }
- assigned = 0;
- while (si != NULL && assigned < assign_per_su) {
- assigned += 1;
- total_assigned += 1;
- su_assign_si (unit, si, SA_AMF_HA_STANDBY);
- si = si->next;
- }
- unit = unit->next;
- }
- if (total_assigned == 0) {
- dprintf ("Error: No SIs assigned!");
- }
- }
- #if 0
- static void assign_nm_spare (struct amf_sg *sg)
- {
- struct amf_su *unit;
- for (unit = sg->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 sg_assign_si (struct amf_sg *sg)
- {
- 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;
- ENTER ("'%s'", sg->name.value);
- /*
- * Number of SUs to assign to active or standby state
- */
- inservice_count = (float)su_inservice_count_get (sg);
- active_sus_needed = div_round (application_si_count_get (sg->application),
- sg->saAmfSGMaxActiveSIsperSUs);
- standby_sus_needed = div_round (application_si_count_get (sg->application),
- sg->saAmfSGMaxStandbySIsperSUs);
- units_for_active = inservice_count - sg->saAmfSGNumPrefStandbySUs;
- if (units_for_active < 0) {
- units_for_active = 0;
- }
- units_for_standby = inservice_count - sg->saAmfSGNumPrefActiveSUs;
- if (units_for_standby < 0) {
- units_for_standby = 0;
- }
- ii_spare = inservice_count - sg->saAmfSGNumPrefActiveSUs - sg->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 ((sg->saAmfSGMaxStandbySIsperSUs * units_for_standby) <= application_si_count_get (sg->application)) {
- 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 ((sg->saAmfSGMaxActiveSIsperSUs * units_for_active) <= application_si_count_get (sg->application)) {
- dprintf ("III: full assignment with reduction of standby service units\n");
- su_active_assign = sg->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 = sg->saAmfSGNumPrefActiveSUs;
- su_standby_assign = sg->saAmfSGNumPrefStandbySUs;
- su_spare_assign = 0;
- } else {
- dprintf ("I: full assignment with spares\n");
- su_active_assign = sg->saAmfSGNumPrefActiveSUs;
- su_standby_assign = sg->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);
- sg_assign_nm_active (sg, su_active_assign);
- sg_assign_nm_standby (sg, su_standby_assign);
- LEAVE ("'%s'", sg->name.value);
- }
- static int sg_all_su_in_service(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 su_readiness_state_set (struct amf_su *su,
- SaAmfReadinessStateT readiness_state)
- {
- su->saAmfSUReadinessState = readiness_state;
- TRACE1 ("Setting SU '%s' readiness state: %s\n",
- &su->name.value, readiness_state_text[readiness_state]);
- }
- static void su_presence_state_set (struct amf_su *su,
- SaAmfPresenceStateT presence_state)
- {
- su->saAmfSUPresenceState = presence_state;
- TRACE1 ("Setting SU '%s' presence state: %s\n",
- su->name.value, 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);
- // comp_presence_state_set (comp, SA_AMF_PRESENCE_UNINSTANTIATED);
- // comp_operational_state_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->saAmfCompRestartCount += 1;
- if (comp->saAmfCompRestartCount >= comp->su->sg->saAmfSGCompRestartMax) {
- comp->su->escalation_level = ESCALATION_LEVEL_ONE;
- escalation_policy_cleanup (comp);
- comp->saAmfCompRestartCount = 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);
- comp->saAmfCompRestartCount = 0;
- comp->su->saAmfSURestartCount = 0;
- return;
- }
- dprintf ("Escalation level 1 - restart unit\n");
- dprintf ("Cleaning up and restarting unit.\n");
- su_cleanup (comp->su);
- break;
- case ESCALATION_LEVEL_TWO:
- dprintf ("Escalation level TWO\n");
- su_cleanup (comp->su);
- // unit_terminate_failover (comp);
- break;
- case ESCALATION_LEVEL_THREE:
- //TODO
- break;
- }
- }
- static void timer_function_healthcheck_timeout (
- void *data)
- {
- struct req_exec_amf_healthcheck_tmo req_exec;
- struct iovec iovec;
- struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)data;
- TRACE2 ("timeout occured on healthcheck for component %s.\n",
- getSaNameT (&healthcheck->comp->name));
- req_exec.header.size = sizeof (struct req_exec_amf_healthcheck_tmo);
- req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
- MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO);
- comp_dn_make (healthcheck->comp, &req_exec.compName);
- iovec.iov_base = (char *)&req_exec;
- iovec.iov_len = sizeof (req_exec);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- 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;
- res_lib_amf_healthcheckcallback.invocation =
- invocation_create (
- AMF_RESPONSE_HEALTHCHECKCALLBACK,
- (void *)healthcheck_active);
- comp_dn_make (healthcheck_active->comp, &res_lib_amf_healthcheckcallback.compName);
- memcpy (&res_lib_amf_healthcheckcallback.key,
- &healthcheck_active->safHealthcheckKey,
- sizeof (SaAmfHealthcheckKeyT));
- TRACE8 ("sending healthcheck to component %s",
- res_lib_amf_healthcheckcallback.compName.value);
- openais_conn_send_response (
- openais_conn_partner_get (healthcheck_active->comp->conn),
- &res_lib_amf_healthcheckcallback,
- sizeof (struct res_lib_amf_healthcheckcallback));
- openais_timer_delete (healthcheck_active->timer_handle_duration);
- openais_timer_add (
- healthcheck_active->saAmfHealthcheckMaxDuration,
- (void *)healthcheck_active,
- timer_function_healthcheck_timeout,
- &healthcheck_active->timer_handle_duration);
- }
- static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active)
- {
- dprintf ("deactivating healthcheck for component %s\n",
- getSaNameT (&healthcheck_active->comp->name));
- openais_timer_delete (healthcheck_active->timer_handle_period);
- openais_timer_delete (healthcheck_active->timer_handle_duration);
- invocation_destroy_by_data ((void *)healthcheck_active);
- healthcheck_active->active = 0;
- }
- static void timer_function_healthcheck_next_fn (void *data)
- {
- healthcheck_activate (data);
- }
- static void su_operational_state_set (
- struct amf_su *unit,
- SaAmfOperationalStateT oper_state)
- {
- struct amf_comp* comp;
- if (oper_state == unit->saAmfSUOperState) {
- log_printf (LOG_INFO,
- "Not assigning service unit new operational state - same state\n");
- return;
- }
- unit->saAmfSUOperState = oper_state;
- TRACE1 ("Setting SU '%s' operational state: %s\n",
- unit->name.value, oper_state_text[oper_state]);
- if (oper_state == SA_AMF_OPERATIONAL_ENABLED) {
- su_readiness_state_set (unit, SA_AMF_READINESS_IN_SERVICE);
- for (comp = unit->comp_head; comp; comp = comp->next) {
- comp_readiness_state_set (comp);
- }
- if (sg_all_su_in_service(unit->sg)) {
- TRACE1 ("All SUs in SG '%s' in service, assigning SIs\n", unit->sg->name.value);
- sg_assign_si (unit->sg);
- if (amf_cluster.timeout_handle) {
- openais_timer_delete (amf_cluster.timeout_handle);
- }
- }
- } else if (oper_state == SA_AMF_OPERATIONAL_DISABLED) {
- su_readiness_state_set (unit, SA_AMF_READINESS_OUT_OF_SERVICE);
- }
- }
- /*
- * Executive Message Implementation
- */
- static void message_handler_req_exec_amf_comp_register (
- void *message, unsigned int nodeid)
- {
- struct res_lib_amf_componentregister res_lib;
- struct req_exec_amf_comp_register *req_exec = message;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_exec->compName);
- if (comp == NULL) {
- log_printf (LOG_ERR, "Component '%s' not found", &req_exec->compName.value);
- return;
- }
- TRACE2("Exec comp register '%s'", &req_exec->compName.value);
- if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) {
- comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
- comp_readiness_state_set (comp);
- if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) {
- comp_reassign_csis (comp);
- }
- } else if ((comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING) ||
- (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_UNINSTANTIATED)){
- comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
- comp_operational_state_set (comp, SA_AMF_OPERATIONAL_ENABLED);
- }
- else {
- assert (0);
- }
- if (comp->su->is_local) {
- res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
- res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
- res_lib.header.error = SA_AIS_OK;
- openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
- }
- }
- static void message_handler_req_exec_amf_comp_error_report (
- void *message, unsigned int nodeid)
- {
- struct res_lib_amf_componenterrorreport res_lib;
- struct req_exec_amf_comp_error_report *req_exec = message;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_exec->erroneousComponent);
- if (comp == NULL) {
- log_printf (LOG_ERR, "Component '%s' not found", &req_exec->erroneousComponent);
- return;
- }
- TRACE2("Exec comp error report '%s'", &req_exec->reportingComponent.value);
- if (comp->su->is_local) {
- res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
- res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
- res_lib.header.error = SA_AIS_OK;
- openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
- }
- escalation_policy_cleanup (comp);
- }
- static void message_handler_req_exec_amf_clc_cleanup_completed (
- void *message, unsigned int nodeid)
- {
- struct req_exec_amf_clc_cleanup_completed *req_exec = message;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_exec->compName);
- if (comp == NULL) {
- log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
- return;
- }
- TRACE2("Exec CLC cleanup completed for '%s'", &req_exec->compName.value);
- clc_instantiate (comp);
- }
- static void message_handler_req_exec_amf_healthcheck_tmo (
- void *message, unsigned int nodeid)
- {
- struct req_exec_amf_healthcheck_tmo *req_exec = message;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_exec->compName);
- if (comp == NULL) {
- log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
- return;
- }
- TRACE2("Exec healthcheck tmo for '%s'", &comp->name.value);
- escalation_policy_cleanup (comp);
- }
- static void message_handler_req_exec_amf_response (
- void *message, unsigned int nodeid)
- {
- struct req_exec_amf_response *req_exec = message;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_exec->compName);
- assert (comp != NULL);
- switch (req_exec->interface) {
- case AMF_RESPONSE_CSISETCALLBACK:
- dprintf ("Exec csi set callback response from '%s', error: %d",
- &req_exec->compName.value, req_exec->error);
- break;
- case AMF_RESPONSE_CSIREMOVECALLBACK:
- dprintf ("Exec csi remove callback response from '%s', error: %d",
- &req_exec->compName.value, req_exec->error);
- break;
- case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
- dprintf ("Exec component terminate callback response from '%s', error: %s",
- &req_exec->compName.value, req_exec->error);
- break;
- default:
- assert (0);
- break;
- }
- }
- /*
- * Library Interface Implementation
- */
- static void message_handler_req_lib_amf_componentregister (
- void *conn,
- void *msg)
- {
- struct req_lib_amf_componentregister *req_lib = msg;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_lib->compName);
- if (comp) {
- struct req_exec_amf_comp_register req_exec;
- struct iovec iovec;
- struct amf_pd *amf_pd = openais_conn_private_data_get (conn);
- TRACE2("Lib comp register '%s'", &req_lib->compName.value);
- comp->conn = conn;
- amf_pd->comp = comp;
- req_exec.header.size = sizeof (struct req_exec_amf_comp_register);
- req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
- MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER);
- memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT));
- memcpy (&req_exec.proxyCompName,
- &req_lib->proxyCompName, sizeof (SaNameT));
- iovec.iov_base = (char *)&req_exec;
- iovec.iov_len = sizeof (req_exec);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- } else {
- struct res_lib_amf_componentregister res_lib;
- log_printf (LOG_ERR, "Lib comp register: comp '%s' not found", &req_lib->compName.value);
- res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
- res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
- res_lib.header.error = SA_AIS_ERR_INVALID_PARAM;
- openais_conn_send_response (
- conn, &res_lib, 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 = msg;
- struct res_lib_amf_healthcheckstart res_lib;
- struct amf_healthcheck *healthcheck;
- struct amf_comp *comp;
- SaAisErrorT error = SA_AIS_OK;
- comp = amf_find_comp (&amf_cluster, &req_lib->compName);
- if (comp == 0) {
- log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found",
- req_lib->compName.value);
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck = amf_find_healthcheck (comp, &req_lib->healthcheckKey);
- if (healthcheck == 0) {
- log_printf (LOG_ERR, "Healthcheckstart: Healthcheck '%s' not found",
- req_lib->healthcheckKey.key);
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- dprintf ("Healthcheckstart: '%s', key '%s'",
- req_lib->compName.value, req_lib->healthcheckKey.key);
- /*
- * Determine if this healthcheck is already active
- */
- if (healthcheck->active) {
- error = SA_AIS_ERR_EXIST;
- goto error_exit;
- }
- /*
- * Initialise
- */
- healthcheck->invocationType = req_lib->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.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
- res_lib.header.size = sizeof (res_lib);
- res_lib.header.error = error;
- openais_conn_send_response (conn, &res_lib,
- 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 = msg;
- struct res_lib_amf_healthcheckstop res_lib;
- 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->compName);
- if (comp == 0) {
- log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found",
- req_lib->compName.value);
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck = amf_find_healthcheck (comp, &req_lib->healthcheckKey);
- if (healthcheck == 0) {
- log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
- req_lib->healthcheckKey.key);
- error = SA_AIS_ERR_NOT_EXIST;
- goto error_exit;
- }
- healthcheck_deactivate (healthcheck);
- error_exit:
- res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
- res_lib.header.size = sizeof (res_lib);
- res_lib.header.error = error;
- openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
- }
- 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 = msg;
- struct amf_comp *comp;
- comp = amf_find_comp (&amf_cluster, &req_lib->erroneousComponent);
- if (comp != NULL) {
- struct req_exec_amf_comp_error_report req_exec;
- struct iovec iovec;
- TRACE2("Lib comp error report for '%s'", &comp->name.value);
- req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
- req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
- MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
- memcpy (&req_exec.reportingComponent, &req_lib->reportingComponent,
- sizeof (SaNameT));
- memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent,
- sizeof (SaNameT));
- memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime,
- sizeof (SaTimeT));
- memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery,
- sizeof (SaAmfRecommendedRecoveryT));
- memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier,
- sizeof (SaNtfIdentifierT));
- iovec.iov_base = (char *)&req_exec;
- iovec.iov_len = sizeof (req_exec);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- } else {
- struct res_lib_amf_componenterrorreport res_lib;
- log_printf (LOG_ERR, "Component %s not found",
- &req_lib->erroneousComponent.value);
- res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
- res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
- res_lib.header.error = SA_AIS_ERR_NOT_EXIST;
- openais_conn_send_response (conn, &res_lib,
- 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 res_lib_amf_response res_lib;
- struct req_lib_amf_response *req_lib = msg;
- struct req_exec_amf_response req_exec;
- struct iovec iovec;
- struct amf_pd *pd = openais_conn_private_data_get (conn);
- int res;
- int interface;
- void *data;
- int error = SA_AIS_OK;
- res = invocation_get_and_destroy (req_lib->invocation, &interface, &data);
- if (res == -1) {
- log_printf (LOG_ERR, "Lib response: invocation not found\n");
- error = SA_AIS_ERR_INVALID_PARAM;
- goto end;
- }
- switch (interface) {
- case AMF_RESPONSE_HEALTHCHECKCALLBACK: {
- struct amf_healthcheck *healthcheck = data;
- SaNameT name;
- TRACE3 ("Lib healthcheck response from '%s'",
- comp_dn_make (healthcheck->comp, &name));
- openais_timer_delete (healthcheck->timer_handle_duration);
- healthcheck->timer_handle_duration = 0;
- openais_timer_add (
- healthcheck->saAmfHealthcheckPeriod,
- (void *)healthcheck,
- timer_function_healthcheck_next_fn,
- &healthcheck->timer_handle_period);
- break;
- }
- case AMF_RESPONSE_CSISETCALLBACK: {
- struct amf_csi_assignment *csi_assignment = data;
- dprintf ("Lib csi '%s' set callback response from '%s', error: %d",
- csi_assignment->csi->name.value, csi_assignment->comp->name.value, req_lib->error);
- memcpy (&req_exec.csiName, &csi_assignment->name, sizeof (SaNameT));
- break;
- }
- case AMF_RESPONSE_CSIREMOVECALLBACK: {
- struct amf_csi_assignment *csi_assignment = data;
- dprintf ("Lib csi '%s' remove callback response from '%s', error: %d",
- csi_assignment->csi->name.value, csi_assignment->comp->name.value, req_lib->error);
- memcpy (&req_exec.csiName, &csi_assignment->name, sizeof (SaNameT));
- break;
- }
- case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
- struct component_terminate_callback_data *component_terminate_callback_data;
- component_terminate_callback_data = data;
- dprintf ("Lib component terminate callback response, error: %d", req_lib->error);
- comp_healthcheck_deactivate (component_terminate_callback_data->comp);
- escalation_policy_restart (component_terminate_callback_data->comp);
- break;
- }
- default:
- assert (0);
- break;
- }
- /* Keep healthcheck responses node local */
- if (interface != AMF_RESPONSE_HEALTHCHECKCALLBACK) {
- assert (pd && pd->comp);
- req_exec.header.size = sizeof (struct req_exec_amf_response);
- req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
- MESSAGE_REQ_EXEC_AMF_RESPONSE);
- comp_dn_make (pd->comp, &req_exec.compName);
- req_exec.interface = interface;
- req_exec.error = req_lib->error;
- iovec.iov_base = (char *)&req_exec;
- iovec.iov_len = sizeof (req_exec);
- assert (totempg_groups_mcast_joined (openais_group_handle,
- &iovec, 1, TOTEMPG_AGREED) == 0);
- }
- end:
- res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
- res_lib.header.size = sizeof (struct res_lib_amf_response);
- res_lib.header.error = error;
- openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
- }
|