amf.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Author: Steven Dake (sdake@mvista.com)
  4. *
  5. * Copyright (c) 2006 Ericsson AB.
  6. * Author: Hans Feldt
  7. * Description: Introduced AMF B.02 information model
  8. *
  9. * All rights reserved.
  10. *
  11. *
  12. * This software licensed under BSD license, the text of which follows:
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  23. * contributors may be used to endorse or promote products derived from this
  24. * software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  36. * THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #include <sys/types.h>
  39. #include <sys/uio.h>
  40. #include <sys/socket.h>
  41. #include <sys/un.h>
  42. #include <sys/types.h>
  43. #include <sys/wait.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <unistd.h>
  47. #include <fcntl.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <signal.h>
  52. #include <string.h>
  53. #include <pthread.h>
  54. #include <assert.h>
  55. #include "../include/saAis.h"
  56. #include "../include/saAmf.h"
  57. #include "../include/ipc_gen.h"
  58. #include "../include/ipc_amf.h"
  59. #include "../include/list.h"
  60. #include "../lcr/lcr_comp.h"
  61. #include "totempg.h"
  62. #include "aispoll.h"
  63. #include "mempool.h"
  64. #include "util.h"
  65. #include "amfconfig.h"
  66. #include "main.h"
  67. #include "service.h"
  68. #include "objdb.h"
  69. #include "print.h"
  70. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  71. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  72. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  73. enum amf_message_req_types {
  74. MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET = 0,
  75. MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET = 1,
  76. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_CSI_SET = 2,
  77. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_UNIT_SET = 3,
  78. MESSAGE_REQ_EXEC_AMF_ADMINISTRATIVE_STATE_GROUP_SET = 4
  79. };
  80. #ifndef HOST_NAME_MAX
  81. # define HOST_NAME_MAX 255
  82. #endif
  83. struct invocation {
  84. void *data;
  85. int interface;
  86. int active;
  87. };
  88. static struct invocation *invocation_entries = 0;
  89. static int invocation_entries_size = 0;
  90. static int waiting = 0;
  91. enum amf_response_interfaces {
  92. AMF_RESPONSE_HEALTHCHECKCALLBACK = 1,
  93. AMF_RESPONSE_CSISETCALLBACK = 2,
  94. AMF_RESPONSE_CSIREMOVECALLBACK = 3,
  95. AMF_RESPONSE_COMPONENTTERMINATECALLBACK = 4
  96. };
  97. struct csi_set_callback_data {
  98. struct amf_comp *comp;
  99. struct amf_csi *csi;
  100. struct amf_pg *pg;
  101. };
  102. struct csi_remove_callback_data {
  103. struct amf_csi *csi;
  104. };
  105. struct component_terminate_callback_data {
  106. struct amf_comp *comp;
  107. };
  108. static void amf_confchg_fn (
  109. enum totem_configuration_type configuration_type,
  110. unsigned int *member_list, int member_list_entries,
  111. unsigned int *left_list, int left_list_entries,
  112. unsigned int *joined_list, int joined_list_entries,
  113. struct memb_ring_id *ring_id);
  114. static int amf_lib_exit_fn (void *conn);
  115. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb);
  116. static int amf_lib_init_fn (void *conn);
  117. static void message_handler_req_lib_amf_componentregister (void *conn, void *msg);
  118. static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg);
  119. static void message_handler_req_lib_amf_pmstart (void *conn, void *msg);
  120. static void message_handler_req_lib_amf_pmstop (void *conn, void *msg);
  121. static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg);
  122. static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg);
  123. static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg);
  124. static void message_handler_req_lib_amf_hastateget (void *conn, void *message);
  125. static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg);
  126. static void message_handler_req_lib_amf_protectiongrouptrack (void *conn, void *msg);
  127. static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg);
  128. static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg);
  129. static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg);
  130. static void message_handler_req_lib_amf_response (void *conn, void *msg);
  131. static void message_handler_req_exec_amf_operational_state_comp_set (
  132. void *message,
  133. unsigned int nodeid);
  134. static void message_handler_req_exec_amf_presence_state_comp_set (
  135. void *message,
  136. unsigned int nodeid);
  137. static void message_handler_req_exec_amf_administrative_state_csi_set (
  138. void *message,
  139. unsigned int nodeid);
  140. static void message_handler_req_exec_amf_administrative_state_unit_set (
  141. void *message,
  142. unsigned int nodeid);
  143. static void message_handler_req_exec_amf_administrative_state_group_set (
  144. void *message,
  145. unsigned int nodeid);
  146. static void presence_state_comp_set (
  147. struct amf_comp *comp,
  148. SaAmfPresenceStateT presence_state);
  149. static void operational_state_comp_set (
  150. struct amf_comp *comp,
  151. SaAmfOperationalStateT operational_state);
  152. static void operational_state_unit_set (
  153. struct amf_su *unit,
  154. SaAmfOperationalStateT operational_state);
  155. static void assign_sis (struct amf_sg *group);
  156. static void clc_instantiate_all (void *data);
  157. static int clc_instantiate (struct amf_comp *comp);
  158. #if 0
  159. static int clc_terminate (struct amf_comp *comp);
  160. #endif
  161. static int clc_cli_instantiate (struct amf_comp *comp);
  162. static int clc_instantiate_callback (struct amf_comp *comp);
  163. static int clc_csi_set_callback (struct amf_comp *comp);
  164. static int clc_cli_terminate (struct amf_comp *comp);
  165. static int clc_terminate_callback (struct amf_comp *comp);
  166. static int clc_csi_remove_callback (struct amf_comp *comp);
  167. static int clc_cli_cleanup (struct amf_comp *comp);
  168. static int clc_cli_cleanup_local (struct amf_comp *comp);
  169. static void healthcheck_activate (struct amf_healthcheck *healthcheck_active);
  170. static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active);
  171. static void comp_healthcheck_activate (struct amf_comp *comp);
  172. static void comp_healthcheck_deactivate (struct amf_comp *comp);
  173. static void escalation_policy_restart (struct amf_comp *comp);
  174. static void amf_dump(void);
  175. static char *presence_state_text[] = {
  176. "unknown",
  177. "uninstantiated",
  178. "instantiating",
  179. "instantiated",
  180. "terminating",
  181. "restarting",
  182. "instantion_failed",
  183. "terminiation_failed"
  184. };
  185. static char *oper_state_text[] = {
  186. "Unknown",
  187. "enabled",
  188. "disabled"
  189. };
  190. static char *admin_state_text[] = {
  191. "Unknown",
  192. "unlocked",
  193. "locked",
  194. "locked_instantiation",
  195. "shutting_down"
  196. };
  197. static char *readiness_state_text[] = {
  198. "Unknown",
  199. "out of service",
  200. "in service",
  201. };
  202. static char *ha_state_text[] = {
  203. "Unknown",
  204. "active",
  205. "standby",
  206. "quiesced",
  207. "quiescing",
  208. };
  209. struct libamf_ci_trackentry {
  210. int active;
  211. SaUint8T trackFlags;
  212. SaAmfProtectionGroupNotificationT *notificationBufferAddress;
  213. SaNameT csiName;
  214. };
  215. struct amf_comp;
  216. struct amf_pd {
  217. struct amf_comp *comp;
  218. struct list_head list;
  219. /*
  220. struct libamf_ci_trackentry *tracks;
  221. int trackEntries;
  222. int trackActive;
  223. */
  224. };
  225. struct clc_interface {
  226. int (*instantiate) (struct amf_comp *comp);
  227. int (*terminate) (struct amf_comp *comp);
  228. int (*cleanup) (struct amf_comp *comp);
  229. };
  230. /*
  231. * Life cycle functions
  232. */
  233. static struct clc_interface clc_interface_sa_aware = {
  234. clc_cli_instantiate,
  235. clc_terminate_callback,
  236. clc_cli_cleanup
  237. };
  238. static struct clc_interface clc_interface_proxied_pre = {
  239. clc_instantiate_callback,
  240. clc_terminate_callback,
  241. clc_cli_cleanup
  242. };
  243. static struct clc_interface clc_interface_proxied_non_pre = {
  244. clc_csi_set_callback,
  245. clc_csi_remove_callback,
  246. clc_cli_cleanup_local
  247. };
  248. static struct clc_interface clc_interface_non_proxied_non_saware = {
  249. clc_cli_instantiate,
  250. clc_cli_terminate,
  251. clc_cli_cleanup_local
  252. };
  253. static struct clc_interface *clc_interfaces[4] = {
  254. &clc_interface_sa_aware,
  255. &clc_interface_proxied_pre,
  256. &clc_interface_proxied_non_pre,
  257. &clc_interface_non_proxied_non_saware
  258. };
  259. /*
  260. * Service Handler Definition
  261. */
  262. static struct openais_lib_handler amf_lib_service[] =
  263. {
  264. { /* 0 */
  265. .lib_handler_fn = message_handler_req_lib_amf_componentregister,
  266. .response_size = sizeof (struct res_lib_amf_componentregister),
  267. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  268. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  269. },
  270. { /* 1 */
  271. .lib_handler_fn = message_handler_req_lib_amf_componentunregister,
  272. .response_size = sizeof (struct res_lib_amf_componentunregister),
  273. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  274. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  275. },
  276. { /* 2 */
  277. .lib_handler_fn = message_handler_req_lib_amf_pmstart,
  278. .response_size = sizeof (struct res_lib_amf_pmstart),
  279. .response_id = MESSAGE_RES_AMF_PMSTART,
  280. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  281. },
  282. { /* 3 */
  283. .lib_handler_fn = message_handler_req_lib_amf_pmstop,
  284. .response_size = sizeof (struct res_lib_amf_pmstop),
  285. .response_id = MESSAGE_RES_AMF_PMSTOP,
  286. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  287. },
  288. { /* 4 */
  289. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart,
  290. .response_size = sizeof (struct res_lib_amf_healthcheckstart),
  291. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
  292. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  293. },
  294. { /* 5 */
  295. .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
  296. .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
  297. .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
  298. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  299. },
  300. { /* 6 */
  301. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop,
  302. .response_size = sizeof (struct res_lib_amf_healthcheckstop),
  303. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
  304. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  305. },
  306. { /* 7 */
  307. .lib_handler_fn = message_handler_req_lib_amf_hastateget,
  308. .response_size = sizeof (struct res_lib_amf_hastateget),
  309. .response_id = MESSAGE_RES_AMF_HASTATEGET,
  310. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  311. },
  312. { /* 8 */
  313. .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
  314. .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
  315. .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
  316. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  317. },
  318. { /* 9 */
  319. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrack,
  320. .response_size = sizeof (struct res_lib_amf_protectiongrouptrack),
  321. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK,
  322. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  323. },
  324. { /* 10 */
  325. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
  326. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  327. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  328. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  329. },
  330. { /* 11 */
  331. .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport,
  332. .response_size = sizeof (struct res_lib_amf_componenterrorreport),
  333. .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
  334. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  335. },
  336. { /* 12 */
  337. .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear,
  338. .response_size = sizeof (struct res_lib_amf_componenterrorclear),
  339. .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
  340. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  341. },
  342. { /* 13 */
  343. .lib_handler_fn = message_handler_req_lib_amf_response,
  344. .response_size = sizeof (struct res_lib_amf_response),
  345. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  346. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  347. },
  348. };
  349. static struct openais_exec_handler amf_exec_service[] = {
  350. {
  351. .exec_handler_fn = message_handler_req_exec_amf_operational_state_comp_set,
  352. },
  353. {
  354. .exec_handler_fn = message_handler_req_exec_amf_presence_state_comp_set,
  355. },
  356. {
  357. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_csi_set,
  358. },
  359. {
  360. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_unit_set,
  361. },
  362. {
  363. .exec_handler_fn = message_handler_req_exec_amf_administrative_state_group_set
  364. }
  365. };
  366. /*
  367. * Exports the interface for the service
  368. */
  369. static struct openais_service_handler amf_service_handler = {
  370. .name = (unsigned char *)"openais availability management framework B.01.01",
  371. .id = AMF_SERVICE,
  372. .private_data_size = sizeof (struct amf_pd),
  373. .lib_init_fn = amf_lib_init_fn,
  374. .lib_exit_fn = amf_lib_exit_fn,
  375. .lib_service = amf_lib_service,
  376. .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler),
  377. .exec_init_fn = amf_exec_init_fn,
  378. .exec_service = amf_exec_service,
  379. .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler),
  380. .confchg_fn = amf_confchg_fn,
  381. .exec_dump_fn = amf_dump
  382. };
  383. static struct amf_node *this_amf_node;
  384. static struct amf_cluster amf_cluster;
  385. static struct openais_service_handler *amf_get_handler_ver0 (void);
  386. static struct openais_service_handler_iface_ver0 amf_service_handler_iface = {
  387. .openais_get_service_handler_ver0 = amf_get_handler_ver0
  388. };
  389. static struct lcr_iface openais_amf_ver0[1] = {
  390. {
  391. .name = "openais_amf",
  392. .version = 0,
  393. .versions_replace = 0,
  394. .versions_replace_count = 0,
  395. .dependencies = 0,
  396. .dependency_count = 0,
  397. .constructor = NULL,
  398. .destructor = NULL,
  399. .interfaces = NULL
  400. }
  401. };
  402. static struct lcr_comp amf_comp_ver0 = {
  403. .iface_count = 1,
  404. .ifaces = openais_amf_ver0
  405. };
  406. static struct openais_service_handler *amf_get_handler_ver0 (void)
  407. {
  408. return (&amf_service_handler);
  409. }
  410. __attribute__ ((constructor)) static void register_this_component (void) {
  411. lcr_interfaces_set (&openais_amf_ver0[0], &amf_service_handler_iface);
  412. lcr_component_register (&amf_comp_ver0);
  413. }
  414. enum clc_command_run_operation_type {
  415. CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
  416. CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
  417. CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
  418. };
  419. struct clc_command_run_data {
  420. struct amf_comp *comp;
  421. enum clc_command_run_operation_type type;
  422. void (*completion_callback) (void *context);
  423. };
  424. static int invocation_create (
  425. int interface,
  426. void *data)
  427. {
  428. struct invocation *invocation_addr = 0;
  429. struct invocation *invocation_temp;
  430. int i;
  431. int loc = 0;
  432. for (i = 0; i < invocation_entries_size; i++) {
  433. if (invocation_entries[i].active == 0) {
  434. invocation_addr = &invocation_entries[i];
  435. loc = i;
  436. break;
  437. }
  438. }
  439. if (invocation_addr == 0) {
  440. invocation_temp = (struct invocation *)realloc (invocation_entries,
  441. (invocation_entries_size + 1) * sizeof (struct invocation));
  442. if (invocation_temp == 0) {
  443. return (-1);
  444. }
  445. invocation_entries = invocation_temp;
  446. invocation_addr = &invocation_entries[invocation_entries_size];
  447. loc = invocation_entries_size;
  448. invocation_entries_size += 1;
  449. }
  450. invocation_addr->interface = interface;
  451. invocation_addr->data = data;
  452. invocation_addr->active = 1;
  453. return (loc);
  454. }
  455. static int invocation_get_and_destroy (int invocation, int *interface,
  456. void **data)
  457. {
  458. if (invocation > invocation_entries_size) {
  459. return (-1);
  460. }
  461. if (invocation_entries[invocation].active == 0) {
  462. return (-1);
  463. }
  464. *interface = invocation_entries[invocation].interface;
  465. *data = invocation_entries[invocation].data;
  466. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  467. return (0);
  468. }
  469. static void invocation_destroy_by_data (void *data)
  470. {
  471. int i;
  472. for (i = 0; i < invocation_entries_size; i++) {
  473. if (invocation_entries[i].data == data) {
  474. memset (&invocation_entries[i], 0,
  475. sizeof (struct invocation));
  476. break;
  477. }
  478. }
  479. }
  480. static void *clc_command_run (void *context)
  481. {
  482. struct clc_command_run_data *clc_command_run_data =
  483. (struct clc_command_run_data *)context;
  484. pid_t pid;
  485. int res;
  486. char *argv[10];
  487. char *envp[10];
  488. int status;
  489. char path[PATH_MAX];
  490. char *cmd = 0;
  491. char *comp_argv = 0;
  492. char env_comp_name[1024];
  493. int i;
  494. ENTER_VOID();
  495. pid = fork();
  496. if (pid == -1) {
  497. dprintf ("Couldn't fork process %s\n", strerror (errno));
  498. return (0);
  499. }
  500. if (pid) {
  501. waiting = 1;
  502. dprintf ("waiting for pid %d to finish\n", pid);
  503. waitpid (pid, &status, 0);
  504. if (clc_command_run_data->completion_callback) {
  505. clc_command_run_data->completion_callback (context);
  506. }
  507. pthread_exit(0);
  508. }
  509. switch (clc_command_run_data->type) {
  510. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  511. cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd;
  512. comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv;
  513. break;
  514. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  515. cmd = clc_command_run_data->comp->saAmfCompTerminateCmd;
  516. comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv;
  517. break;
  518. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  519. cmd = clc_command_run_data->comp->saAmfCompCleanupCmd;
  520. comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv;
  521. break;
  522. default:
  523. assert (0 != 1);
  524. break;
  525. }
  526. /* If command is not an absolute path, search for paths in parent objects */
  527. if (cmd[0] != '/') {
  528. if (strlen (clc_command_run_data->comp->clccli_path)) {
  529. sprintf (path, "%s/%s",
  530. clc_command_run_data->comp->clccli_path, cmd);
  531. } else if (strlen (clc_command_run_data->comp->su->clccli_path)) {
  532. sprintf (path, "%s/%s",
  533. clc_command_run_data->comp->su->clccli_path, cmd);
  534. } else if (strlen (clc_command_run_data->comp->su->sg->clccli_path)) {
  535. sprintf (path, "%s/%s",
  536. clc_command_run_data->comp->su->sg->clccli_path, cmd);
  537. } else if (strlen (clc_command_run_data->comp->su->sg->application->clccli_path)) {
  538. sprintf (path, "%s/%s",
  539. clc_command_run_data->comp->su->sg->application->clccli_path, cmd);
  540. }
  541. cmd = path;
  542. }
  543. argv[0] = cmd;
  544. {
  545. /* make a proper argv array */
  546. i = 1;
  547. char *ptrptr;
  548. char *arg = strtok_r(comp_argv, " ", &ptrptr);
  549. while (arg) {
  550. argv[i] = arg;
  551. arg = strtok_r(NULL, " ", & ptrptr);
  552. i++;
  553. }
  554. }
  555. argv[i] = NULL;
  556. envp[0] = env_comp_name;
  557. strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME=");
  558. strncat (env_comp_name, (char *)clc_command_run_data->comp->name.value,
  559. clc_command_run_data->comp->name.length);
  560. for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv &&
  561. clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) {
  562. envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1];
  563. }
  564. envp[i] = NULL;
  565. dprintf ("running command '%s' with environment:\n", cmd);
  566. for (i = 0; envp[i] != NULL; i++) {
  567. dprintf (" %s\n", envp[i]);
  568. }
  569. dprintf (" and argv:\n", cmd);
  570. for (i = 0; argv[i] != NULL; i++) {
  571. dprintf (" %s\n", argv[i]);
  572. }
  573. res = execve (cmd, argv, envp);
  574. if (res == -1) {
  575. log_printf (LOG_LEVEL_ERROR, "Couldn't exec program %s (%s)\n",
  576. cmd, strerror (errno));
  577. }
  578. assert (res != -1);
  579. return (0);
  580. }
  581. struct req_exec_amf_operational_state_comp_set {
  582. struct req_header header;
  583. SaNameT name;
  584. SaAmfOperationalStateT operational_state;
  585. };
  586. struct req_exec_amf_presence_state_comp_set {
  587. struct req_header header;
  588. SaNameT name;
  589. SaAmfPresenceStateT presence_state;
  590. };
  591. struct req_exec_amf_administrative_state_csi_set {
  592. struct req_header header;
  593. SaNameT name;
  594. SaAmfAdminStateT administrative_state;
  595. };
  596. struct req_exec_amf_administrative_state_unit_set {
  597. struct req_header header;
  598. SaNameT name;
  599. SaAmfAdminStateT administrative_state;
  600. };
  601. struct req_exec_amf_administrative_state_group_set {
  602. struct req_header header;
  603. SaNameT name;
  604. SaAmfAdminStateT administrative_state;
  605. };
  606. struct req_exec_amf_comp_restart {
  607. struct req_header header;
  608. SaNameT compName;
  609. };
  610. /*
  611. * Instantiate possible operations
  612. */
  613. static int clc_cli_instantiate (struct amf_comp *comp)
  614. {
  615. int res;
  616. pthread_t thread;
  617. pthread_attr_t thread_attr; /* thread attribute */
  618. struct clc_command_run_data *clc_command_run_data;
  619. ENTER("comp %s\n", getSaNameT (&comp->name));
  620. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  621. clc_command_run_data->comp = comp;
  622. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  623. clc_command_run_data->completion_callback = NULL;
  624. pthread_attr_init (&thread_attr);
  625. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  626. res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data);
  627. if (res != 0) {
  628. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  629. }
  630. // TODO error code from pthread_create
  631. return (res);
  632. }
  633. static int clc_instantiate_callback (struct amf_comp *comp)
  634. {
  635. ENTER("comp %s\n", getSaNameT (&comp->name));
  636. return (0);
  637. }
  638. static int clc_csi_set_callback (struct amf_comp *comp)
  639. {
  640. ENTER("comp %s\n", getSaNameT (&comp->name));
  641. return (0);
  642. }
  643. /*
  644. * Terminate possible operations
  645. */
  646. static int clc_cli_terminate (struct amf_comp *comp)
  647. {
  648. ENTER("comp %s\n", getSaNameT (&comp->name));
  649. return (0);
  650. }
  651. static int clc_terminate_callback (struct amf_comp *comp)
  652. {
  653. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  654. struct component_terminate_callback_data *component_terminate_callback_data;
  655. ENTER("comp %s\n", getSaNameT (&comp->name));
  656. if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
  657. dprintf ("component terminated but not instantiated %s - %d\n",
  658. getSaNameT (&comp->name), comp->saAmfCompPresenceState);
  659. assert (0);
  660. return (0);
  661. }
  662. dprintf ("component name terminating %s\n", getSaNameT (&comp->name));
  663. dprintf ("component presence state %d\n", comp->saAmfCompPresenceState);
  664. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  665. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  666. res_lib_amf_componentterminatecallback.header.error = SA_AIS_OK;
  667. memcpy (&res_lib_amf_componentterminatecallback.compName,
  668. &comp->name, sizeof (SaNameT));
  669. component_terminate_callback_data =
  670. malloc (sizeof (struct component_terminate_callback_data));
  671. assert (component_terminate_callback_data); // TODO failure here of malloc
  672. component_terminate_callback_data->comp = comp;
  673. res_lib_amf_componentterminatecallback.invocation =
  674. invocation_create (
  675. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  676. component_terminate_callback_data);
  677. dprintf ("Creating invocation %llu",
  678. (unsigned long long)res_lib_amf_componentterminatecallback.invocation);
  679. openais_conn_send_response (
  680. openais_conn_partner_get (comp->conn),
  681. &res_lib_amf_componentterminatecallback,
  682. sizeof (struct res_lib_amf_componentterminatecallback));
  683. return (0);
  684. }
  685. static int clc_csi_remove_callback (struct amf_comp *comp)
  686. {
  687. dprintf ("clc_tcsi_remove_callback\n");
  688. return (0);
  689. }
  690. /*
  691. * This reinstantiates the cleaned up component
  692. */
  693. static void clc_cleanup_completion_callback (void *context) {
  694. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  695. escalation_policy_restart (clc_command_run_data->comp);
  696. }
  697. /*
  698. * Cleanup possible operations
  699. */
  700. static int clc_cli_cleanup (struct amf_comp *comp)
  701. {
  702. int res;
  703. pthread_t thread;
  704. pthread_attr_t thread_attr; /* thread attribute */
  705. struct clc_command_run_data *clc_command_run_data;
  706. dprintf ("clc_cli_cleanup\n");
  707. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  708. clc_command_run_data->comp = comp;
  709. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  710. clc_command_run_data->completion_callback = clc_cleanup_completion_callback;
  711. pthread_attr_init (&thread_attr);
  712. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  713. res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data);
  714. if (res != 0) {
  715. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  716. }
  717. // TODO error code from pthread_create
  718. return (res);
  719. }
  720. static int clc_cli_cleanup_local (struct amf_comp *comp)
  721. {
  722. dprintf ("clc_cli_cleanup_local\n");
  723. return (0);
  724. }
  725. static int clc_instantiate (struct amf_comp *comp)
  726. {
  727. int res;
  728. dprintf ("clc instantiate for comp %s\n", getSaNameT (&comp->name));
  729. presence_state_comp_set (comp, SA_AMF_PRESENCE_INSTANTIATING);
  730. res = clc_interfaces[comp->comptype]->instantiate (comp);
  731. return (res);
  732. }
  733. #if 0
  734. static int clc_terminate (struct amf_comp *comp)
  735. {
  736. int res;
  737. dprintf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  738. assert (0);
  739. operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  740. presence_state_comp_set (comp, SA_AMF_PRESENCE_TERMINATING);
  741. res = clc_interfaces[comp->comptype]->terminate (comp);
  742. return (0);
  743. }
  744. #endif
  745. static int clc_cleanup (struct amf_comp *comp)
  746. {
  747. int res;
  748. dprintf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
  749. comp_healthcheck_deactivate (comp);
  750. operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  751. presence_state_comp_set (comp, SA_AMF_PRESENCE_TERMINATING);
  752. res = clc_interfaces[comp->comptype]->cleanup (comp);
  753. return (0);
  754. }
  755. /* IMPL */
  756. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
  757. {
  758. int res;
  759. char *error_string;
  760. unsigned int object_service_handle;
  761. int enabled = 0;
  762. char *value;
  763. char hostname[HOST_NAME_MAX + 1];
  764. struct amf_node *node;
  765. struct amf_application *app;
  766. struct amf_sg *sg;
  767. struct amf_su *su;
  768. struct amf_comp *comp;
  769. struct amf_si *si;
  770. struct amf_csi *csi;
  771. int i;
  772. log_init ("AMF");
  773. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  774. if (objdb->object_find (
  775. OBJECT_PARENT_HANDLE,
  776. "amf",
  777. strlen ("amf"),
  778. &object_service_handle) == 0) {
  779. value = NULL;
  780. if ( !objdb->object_key_get (object_service_handle,
  781. "mode",
  782. strlen ("mode"),
  783. (void *)&value,
  784. NULL) && value) {
  785. if (strcmp (value, "enabled") == 0) {
  786. enabled = 1;
  787. } else
  788. if (strcmp (value, "disabled") == 0) {
  789. enabled = 0;
  790. }
  791. }
  792. }
  793. if (!enabled) {
  794. return 0;
  795. }
  796. if (gethostname (hostname, sizeof(hostname)) == -1) {
  797. log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
  798. return -1;
  799. }
  800. res = amf_config_read (&amf_cluster, &error_string);
  801. if (res == -1) {
  802. log_printf (LOG_LEVEL_ERROR, error_string);
  803. return res;
  804. }
  805. dprintf("Cluster: %s", getSaNameT(&amf_cluster.name));
  806. dprintf(" timeout: %d ms\n", amf_cluster.saAmfClusterStartupTimeout);
  807. dprintf(" admin state: %s\n", admin_state_text[amf_cluster.saAmfClusterAdminState]);
  808. for (node = amf_cluster.node_head; node != NULL; node = node->next) {
  809. dprintf(" Node: %s\n", getSaNameT (&node->name));
  810. dprintf(" su_fail_over_prob: %u\n", node->saAmfNodeSuFailOverProb);
  811. dprintf(" su_fail_over_max: %u\n", node->saAmfNodeSuFailoverMax);
  812. dprintf(" auto repair: %u\n", node->saAmfNodeAutoRepair);
  813. /* look for this node */
  814. if (strcmp(hostname, getSaNameT (&node->name)) == 0) {
  815. this_amf_node = node;
  816. }
  817. }
  818. for (app = amf_cluster.application_head; app != NULL; app = app->next) {
  819. dprintf(" Application: %s\n", getSaNameT(&app->name));
  820. dprintf(" num_sg: %d\n", app->saAmfApplicationCurrNumSG);
  821. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  822. dprintf(" SG: %s\n", getSaNameT(&sg->name));
  823. dprintf(" red model: %u\n", sg->saAmfSGRedundancyModel);
  824. dprintf(" auto adjust: %u\n", sg->saAmfSGAutoAdjust);
  825. for (su = sg->su_head; su != NULL; su = su->next) {
  826. dprintf(" SU: %s\n", getSaNameT(&su->name));
  827. dprintf(" rank: %u\n", su->saAmfSURank);
  828. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  829. dprintf(" Comp: %s\n", getSaNameT(&comp->name));
  830. dprintf(" category: %u\n", comp->saAmfCompCategory);
  831. dprintf(" env vars:");
  832. i = 0;
  833. while (comp->saAmfCompCmdEnv && comp->saAmfCompCmdEnv[i]) {
  834. dprintf(" %s", comp->saAmfCompCmdEnv[i]);
  835. i++;
  836. }
  837. }
  838. }
  839. }
  840. for (si = app->si_head; si != NULL; si = si->next) {
  841. dprintf(" SI: %s\n", getSaNameT(&si->name));
  842. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  843. dprintf(" CSI: %s\n", getSaNameT(&csi->name));
  844. }
  845. }
  846. }
  847. if (this_amf_node != NULL) {
  848. /* wait a while before instantiating SUs as the AMF spec. says. */
  849. poll_timer_add(aisexec_poll_handle,
  850. amf_cluster.saAmfClusterStartupTimeout,
  851. NULL,
  852. clc_instantiate_all,
  853. &amf_cluster.timeout_handle);
  854. } else {
  855. log_printf (LOG_LEVEL_INFO, "This CLM node (%s) is not configured as an AMF node, disabling...", hostname);
  856. }
  857. return (0);
  858. }
  859. static void amf_confchg_fn (
  860. enum totem_configuration_type configuration_type,
  861. unsigned int *member_list, int member_list_entries,
  862. unsigned int *left_list, int left_list_entries,
  863. unsigned int *joined_list, int joined_list_entries,
  864. struct memb_ring_id *ring_id)
  865. {
  866. #ifdef COMPILE_OUT
  867. int i;
  868. 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);
  869. recovery = 1;
  870. /*
  871. * If node join, component register
  872. */
  873. if ( joined_list_entries > 0 ) {
  874. enumerate_components (amf_confchg_njoin, NULL);
  875. }
  876. /*
  877. * If node leave, component unregister
  878. */
  879. for (i = 0; i<left_list_entries ; i++) {
  880. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  881. }
  882. #ifdef TODO
  883. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  884. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  885. recovery = 0;
  886. }
  887. #endif
  888. #endif
  889. }
  890. static int amf_lib_exit_fn (void *conn)
  891. {
  892. struct amf_comp *comp;
  893. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  894. comp = amf_pd->comp;
  895. TRACE8("amf_lib_exit_fn");
  896. if (comp) {
  897. comp->conn = 0;
  898. dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name));
  899. }
  900. return (0);
  901. }
  902. static int amf_lib_init_fn (void *conn)
  903. {
  904. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  905. list_init (&amf_pd->list);
  906. return (0);
  907. }
  908. #ifdef COMPILE_OUT
  909. static void amf_synchronize (void *message, struct in_addr source_addr)
  910. {
  911. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  912. struct amf_comp *component;
  913. struct amf_comp *amfProxyComponent;
  914. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  915. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  916. /* Find Component */
  917. component = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  918. amfProxyComponent = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  919. /* If this processor is component owner */
  920. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  921. /* No Operation */
  922. return;
  923. }
  924. /* If this isn't synchronizing target processor */
  925. if (!(component->local == 0 && component->registered == 0)){
  926. /* No Operation */
  927. return;
  928. }
  929. /* Synchronize Status */
  930. component->local = 0;
  931. component->registered = 1;
  932. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  933. component->source_addr = source_addr;
  934. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  935. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  936. component->currentHAState = SA_AMF_QUIESCED;
  937. component->newHAState = SA_AMF_QUIESCED;
  938. component->probableCause = 0;
  939. component->enabledUnlockedState = 0;
  940. component->disabledUnlockedState = 0;
  941. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  942. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  943. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  944. component->newHAState = req_exec_amf_componentregister->newHAState;
  945. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  946. component->saAmfProxyComponent = amfProxyComponent;
  947. }
  948. /*
  949. * Determine if we should enter new state
  950. */
  951. dsmSynchronizeStaus (component);
  952. return;
  953. }
  954. #endif
  955. static DECLARE_LIST_INIT (library_notification_send_listhead);
  956. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  957. #ifdef COMPILE_OUT
  958. static void protectiongroup_notifications_send (
  959. struct amf_comp *changedComponent,
  960. SaAmfProtectionGroupChangesT changeToComponent)
  961. {
  962. int i;
  963. struct conn_info *conn_info;
  964. struct list_head *list;
  965. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  966. /*
  967. * Iterate all tracked connections
  968. */
  969. for (list = library_notification_send_listhead.next;
  970. list != &library_notification_send_listhead;
  971. list = list->next) {
  972. conn_info = list_entry (list, struct conn_info, conn_list);
  973. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  974. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  975. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  976. != changedComponent->amf_pg->name.length) {
  977. continue;
  978. }
  979. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  980. changedComponent->amf_pg->name.value,
  981. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  982. continue;
  983. }
  984. #ifdef COMPILE_OUT
  985. protectiongroup_notification_send (conn_info,
  986. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  987. changedComponent->saAmfProtectionGroup,
  988. changedComponent,
  989. changeToComponent,
  990. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  991. #endif
  992. } /* if track flags active */
  993. } /* for all track entries */
  994. } /* for all connection entries */
  995. }
  996. #endif
  997. #ifdef COMPILE_OUT
  998. static int make_protectiongroup_notification_allcomponent (
  999. struct amf_comp *changedComponent,
  1000. SaAmfProtectionGroupChangesT changeToComponent,
  1001. SaAmfProtectionGroupNotificationT **notification )
  1002. {
  1003. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1004. int notifyEntries = 0;
  1005. struct amf_comp *component;
  1006. struct list_head *AmfGroupList;
  1007. struct list_head *AmfUnitList;
  1008. struct list_head *AmfComponentList;
  1009. struct saAmfGroup *saAmfGroup;
  1010. struct saAmfUnit *AmfUnit;
  1011. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  1012. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  1013. /*
  1014. * Search all units
  1015. */
  1016. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  1017. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  1018. AmfUnitList = AmfUnitList->next) {
  1019. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  1020. /*
  1021. * Search all components
  1022. */
  1023. for (AmfComponentList = AmfUnit->amf_compHead.next;
  1024. AmfComponentList != &AmfUnit->amf_compHead;
  1025. AmfComponentList = AmfComponentList->next) {
  1026. component = list_entry (AmfComponentList, struct amf_comp, amf_compList);
  1027. protectionGroupNotification =
  1028. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1029. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1030. memset (&protectionGroupNotification[notifyEntries],
  1031. 0,sizeof (SaAmfProtectionGroupNotificationT));
  1032. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1033. &component->name, sizeof (SaNameT));
  1034. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1035. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1036. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1037. &component->currentHAState, sizeof (SaAmfHAStateT));
  1038. if (component == changedComponent) {
  1039. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1040. } else {
  1041. protectionGroupNotification[notifyEntries].change
  1042. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1043. }
  1044. notifyEntries += 1;
  1045. }
  1046. }
  1047. }
  1048. if (notifyEntries) {
  1049. *notification = protectionGroupNotification;
  1050. }
  1051. return (notifyEntries);
  1052. }
  1053. #endif
  1054. #ifdef COMPILE_OUT
  1055. static int make_protectiongroup_notification (
  1056. struct saAmfProtectionGroup *amfProtectionGroup,
  1057. struct amf_comp *changedComponent,
  1058. SaAmfProtectionGroupChangesT changeToComponent,
  1059. SaAmfProtectionGroupNotificationT **notification )
  1060. {
  1061. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1062. int notifyEntries = 0;
  1063. struct amf_comp *component;
  1064. struct list_head *componentList;
  1065. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1066. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  1067. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1068. componentList != &amfProtectionGroup->saAmfMembersHead;
  1069. componentList = componentList->next) {
  1070. component = list_entry (componentList, struct amf_comp, saAmfProtectionGroupList);
  1071. protectionGroupNotification =
  1072. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1073. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1074. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  1075. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1076. &component->name, sizeof (SaNameT));
  1077. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1078. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1079. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1080. &component->currentHAState, sizeof (SaAmfHAStateT));
  1081. if (component == changedComponent) {
  1082. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1083. } else {
  1084. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1085. }
  1086. notifyEntries += 1;
  1087. } /* for */
  1088. if (notifyEntries) {
  1089. *notification = protectionGroupNotification;
  1090. }
  1091. return (notifyEntries);
  1092. return (0);
  1093. }
  1094. #endif
  1095. #ifdef COMPILE_OUT
  1096. static void protectiongroup_notification_send (struct conn_info *conn_info,
  1097. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1098. struct saAmfProtectionGroup *amfProtectionGroup,
  1099. struct amf_comp *changedComponent,
  1100. SaAmfProtectionGroupChangesT changeToComponent,
  1101. SaUint8T trackFlags)
  1102. {
  1103. //struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1104. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1105. int notifyEntries;
  1106. /*
  1107. * Step through all components and generate protection group list for csi
  1108. */
  1109. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  1110. if ( trackFlags == SA_TRACK_CHANGES ) {
  1111. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  1112. changeToComponent, &protectionGroupNotification);
  1113. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  1114. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  1115. changedComponent, changeToComponent, &protectionGroupNotification );
  1116. }else{
  1117. notifyEntries = 0;
  1118. }
  1119. /*
  1120. * Send track callback
  1121. */
  1122. if (notifyEntries) {
  1123. res_lib_amf_protectiongrouptrackcallback.header.size =
  1124. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  1125. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1126. // res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1127. res_lib_amf_protectiongrouptrackcallback.header.error = SA_AIS_OK;
  1128. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1129. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1130. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1131. &amfProtectionGroup->name, sizeof (SaNameT));
  1132. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1133. openais_conn_send_response (conno, &res_lib_amf_protectiongrouptrackcallback,
  1134. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1135. openais_conn_send_response (conno, protectionGroupNotification,
  1136. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1137. mempool_free (protectionGroupNotification);
  1138. }
  1139. }
  1140. static void error_report (struct amf_comp *comp)
  1141. {
  1142. struct req_exec_amf_error_report req_exec_amf_error_report;
  1143. struct iovec iovec;
  1144. req_exec_amf_error_report.header.size = sizeof (struct req_exec_amf_error_report);
  1145. req_exec_amf_error_report.header.id =
  1146. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERROR_REPORT);
  1147. memcpy (&req_exec_amf_error_report.compName,
  1148. &comp->name,
  1149. sizeof (SaNameT));
  1150. iovec.iov_base = (char *)&req_exec_amf_error_report;
  1151. iovec.iov_len = sizeof (req_exec_amf_error_report);
  1152. assert (totempg_groups_mcast_joined (openais_group_handle,
  1153. &iovec, 1, TOTEMPG_AGREED) == 0);
  1154. }
  1155. static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp)
  1156. {
  1157. struct req_exec_amf_comp_restart req_exec_amf_comp_restart;
  1158. struct iovec iovec;
  1159. req_exec_amf_comp_restart.header.size = sizeof (struct req_exec_amf_comp_restart);
  1160. req_exec_amf_comp_restart.header.id =
  1161. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_UNIT_RESTART);
  1162. memcpy (&req_exec_amf_comp_restart.compName, &comp->name,
  1163. sizeof (SaNameT));
  1164. iovec.iov_base = (char *)&req_exec_amf_comp_restart;
  1165. iovec.iov_len = sizeof (req_exec_amf_comp_restart);
  1166. assert (totempg_groups_mcast_joined (openais_group_handle,
  1167. &iovec, 1, TOTEMPG_AGREED) == 0);
  1168. }
  1169. #endif
  1170. #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL
  1171. #if 0
  1172. static struct healthcheck_active *find_healthcheck_active (
  1173. struct amf_comp *comp,
  1174. SaAmfHealthcheckKeyT *key,
  1175. SaAmfHealthcheckInvocationT invocation)
  1176. {
  1177. struct list_head *list;
  1178. struct healthcheck_active *ret_healthcheck_active = 0;
  1179. struct healthcheck_active *healthcheck_active;
  1180. for (list = comp->healthcheck_head.next;
  1181. list != &comp->healthcheck_head;
  1182. list = list->next) {
  1183. healthcheck_active = list_entry (list,
  1184. struct healthcheck_active, list);
  1185. if ((memcmp (key, &healthcheck_active->key,
  1186. sizeof (SaAmfHealthcheckKeyT)) == 0) &&
  1187. (invocation == INVOCATION_DONT_COMPARE ||
  1188. healthcheck_active->invocationType == invocation)) {
  1189. ret_healthcheck_active = healthcheck_active;
  1190. break;
  1191. }
  1192. }
  1193. return (ret_healthcheck_active);
  1194. }
  1195. #endif
  1196. static void comp_healthcheck_activate (struct amf_comp *comp)
  1197. {
  1198. struct amf_healthcheck *healthcheck;
  1199. for (healthcheck = comp->healthcheck_head;
  1200. healthcheck != NULL;
  1201. healthcheck = healthcheck->next) {
  1202. if (healthcheck->active == 0) {
  1203. healthcheck_activate (healthcheck);
  1204. }
  1205. }
  1206. }
  1207. static void comp_healthcheck_deactivate (
  1208. struct amf_comp *comp)
  1209. {
  1210. struct amf_healthcheck *healthcheck;
  1211. log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n",
  1212. getSaNameT (&comp->name));
  1213. for (healthcheck = comp->healthcheck_head;
  1214. healthcheck != NULL;
  1215. healthcheck = healthcheck->next) {
  1216. dprintf ("healthcheck deactivating %p\n", healthcheck);
  1217. healthcheck_deactivate (healthcheck);
  1218. }
  1219. }
  1220. static void presence_state_comp_set (
  1221. struct amf_comp *comp,
  1222. SaAmfPresenceStateT presence_state)
  1223. {
  1224. struct req_exec_amf_presence_state_comp_set req_exec_amf_presence_state_comp_set;
  1225. struct iovec iovec;
  1226. req_exec_amf_presence_state_comp_set.header.size = sizeof (struct req_exec_amf_presence_state_comp_set);
  1227. req_exec_amf_presence_state_comp_set.header.id =
  1228. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET);
  1229. req_exec_amf_presence_state_comp_set.presence_state = presence_state;
  1230. memcpy (&req_exec_amf_presence_state_comp_set.name,
  1231. &comp->name,
  1232. sizeof (SaNameT));
  1233. iovec.iov_base = (char *)&req_exec_amf_presence_state_comp_set;
  1234. iovec.iov_len = sizeof (req_exec_amf_presence_state_comp_set);
  1235. assert (totempg_groups_mcast_joined (openais_group_handle,
  1236. &iovec, 1, TOTEMPG_AGREED) == 0);
  1237. }
  1238. static void readiness_state_comp_set (struct amf_comp *comp)
  1239. {
  1240. dprintf ("inputs to readiness_state_comp_set\n");
  1241. dprintf ("\tunit readiness state %s\n",
  1242. readiness_state_text[comp->su->saAmfSUReadinessState]);
  1243. dprintf ("\tcomp operational state %s\n",
  1244. oper_state_text[comp->su->saAmfSUReadinessState]);
  1245. /*
  1246. * Set component readiness state appropriately
  1247. * if unit in service and component is enabled, it is in service
  1248. * otherwise it is out of service page 37
  1249. */
  1250. if (comp->su->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE &&
  1251. comp->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1252. comp->saAmfCompReadinessState = SA_AMF_READINESS_IN_SERVICE;
  1253. } else {
  1254. comp->saAmfCompReadinessState = SA_AMF_READINESS_OUT_OF_SERVICE;
  1255. }
  1256. dprintf ("readiness_state_comp_set (%s)\n",
  1257. oper_state_text[comp->saAmfCompOperState]);
  1258. }
  1259. static void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT oper_state)
  1260. {
  1261. struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set;
  1262. struct iovec iovec;
  1263. req_exec_amf_operational_state_comp_set.header.size = sizeof (struct req_exec_amf_operational_state_comp_set);
  1264. req_exec_amf_operational_state_comp_set.header.id =
  1265. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET);
  1266. req_exec_amf_operational_state_comp_set.operational_state = oper_state;
  1267. memcpy (&req_exec_amf_operational_state_comp_set.name,
  1268. &comp->name,
  1269. sizeof (SaNameT));
  1270. iovec.iov_base = (char *)&req_exec_amf_operational_state_comp_set;
  1271. iovec.iov_len = sizeof (req_exec_amf_operational_state_comp_set);
  1272. assert (totempg_groups_mcast_joined (openais_group_handle,
  1273. &iovec, 1, TOTEMPG_AGREED) == 0);
  1274. }
  1275. static void csi_comp_set_callback (
  1276. struct amf_comp *comp,
  1277. struct amf_csi *csi,
  1278. struct amf_pg *pg)
  1279. {
  1280. struct res_lib_amf_csisetcallback* res_lib_amf_csisetcallback;
  1281. void* p;
  1282. struct csi_set_callback_data *csi_set_callback_data;
  1283. struct amf_csi_attribute *attribute;
  1284. size_t char_length_of_csi_attrs=0;
  1285. size_t num_of_csi_attrs=0;
  1286. int i;
  1287. dprintf("\t Assigning CSI %s to component\n", getSaNameT (&csi->name));
  1288. for (attribute = csi->attributes_head;
  1289. attribute != NULL;
  1290. attribute = attribute->next) {
  1291. for (i = 0; attribute->value[i] != NULL; i++) {
  1292. num_of_csi_attrs++;
  1293. char_length_of_csi_attrs += strlen(attribute->name);
  1294. char_length_of_csi_attrs += strlen(attribute->value[i]);
  1295. char_length_of_csi_attrs += 2;
  1296. }
  1297. }
  1298. p = malloc(sizeof(struct res_lib_amf_csisetcallback)+
  1299. char_length_of_csi_attrs);
  1300. assert(p);
  1301. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback*)p;
  1302. /* Address of the buffer containing the Csi name value pair */
  1303. char* csi_attribute_buf = res_lib_amf_csisetcallback->csi_attr_buf;
  1304. /* Byteoffset start at the zero byte */
  1305. unsigned int byte_offset = 0;
  1306. for (attribute = csi->attributes_head;
  1307. attribute != NULL;
  1308. attribute = attribute->next) {
  1309. for (i = 0; attribute->value[i] != NULL; i++) {
  1310. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->name);
  1311. byte_offset += strlen(attribute->name) + 1;
  1312. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->value[i]);
  1313. byte_offset += strlen(attribute->value[i]) + 1;
  1314. }
  1315. }
  1316. res_lib_amf_csisetcallback->number = num_of_csi_attrs;
  1317. res_lib_amf_csisetcallback->csiFlags = SA_AMF_CSI_ADD_ONE;
  1318. switch (comp->su->requested_ha_state) {
  1319. case SA_AMF_HA_ACTIVE: {
  1320. res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.activeCompName.length = 0;
  1321. res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.transitionDescriptor =
  1322. SA_AMF_CSI_NEW_ASSIGN;
  1323. break;
  1324. }
  1325. case SA_AMF_HA_STANDBY: {
  1326. res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0;
  1327. res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.standbyRank = 1;
  1328. break;
  1329. }
  1330. case SA_AMF_HA_QUIESCED: {
  1331. /*TODO*/
  1332. break;
  1333. }
  1334. case SA_AMF_HA_QUIESCING: {
  1335. /*TODO*/
  1336. break;
  1337. }
  1338. default: {
  1339. assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED);
  1340. break;
  1341. }
  1342. }
  1343. res_lib_amf_csisetcallback->header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1344. res_lib_amf_csisetcallback->header.size =
  1345. sizeof (struct res_lib_amf_csisetcallback)+
  1346. char_length_of_csi_attrs;
  1347. res_lib_amf_csisetcallback->header.error = SA_AIS_OK;
  1348. memcpy (&res_lib_amf_csisetcallback->compName,
  1349. &comp->name, sizeof (SaNameT));
  1350. memcpy (&res_lib_amf_csisetcallback->csiName,
  1351. &csi->name, sizeof (SaNameT));
  1352. res_lib_amf_csisetcallback->haState = comp->su->requested_ha_state;
  1353. csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data));
  1354. assert (csi_set_callback_data); // TODO failure here of malloc
  1355. csi_set_callback_data->comp = comp;
  1356. csi_set_callback_data->csi = csi;
  1357. csi_set_callback_data->pg = pg;
  1358. res_lib_amf_csisetcallback->invocation =
  1359. invocation_create (
  1360. AMF_RESPONSE_CSISETCALLBACK,
  1361. csi_set_callback_data);
  1362. openais_conn_send_response (
  1363. openais_conn_partner_get (comp->conn),
  1364. res_lib_amf_csisetcallback,
  1365. res_lib_amf_csisetcallback->header.size);
  1366. free(p);
  1367. }
  1368. #if 0
  1369. static void pg_create (struct amf_si *si, struct amf_pg **pg_out)
  1370. {
  1371. struct amf_pg *pg;
  1372. // struct amf_pg_comp *pg_comp;
  1373. pg = malloc (sizeof (struct amf_pg));
  1374. assert (pg);
  1375. list_init (&pg->pg_comp_head);
  1376. list_init (&pg->pg_list);
  1377. list_add (&pg->pg_list, &si->pg_head);
  1378. *pg_out = pg;
  1379. }
  1380. #endif
  1381. static void csi_unit_set_callback (struct amf_su *unit, struct amf_si *si)
  1382. {
  1383. struct amf_csi *csi;
  1384. struct amf_pg *pg = NULL;
  1385. struct amf_comp *comp;
  1386. SaNameT *cs_type;
  1387. int i;
  1388. // pg_create (csi_in->si, &pg);
  1389. // TODO remove si from csi data structure
  1390. /*
  1391. ** for each component in SU, find a CSI in the SI with the same type
  1392. */
  1393. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1394. dprintf ("\t%s\n", getSaNameT (&comp->name));
  1395. int no_of_csi_types = 0;
  1396. for (i = 0; comp->saAmfCompCsTypes[i]; i++) {
  1397. cs_type = comp->saAmfCompCsTypes[i];
  1398. no_of_csi_types++;
  1399. int no_of_assignments = 0;
  1400. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  1401. if (!memcmp(csi->saAmfCSTypeName.value, cs_type->value, cs_type->length)) {
  1402. csi_comp_set_callback (comp, csi, pg);
  1403. no_of_assignments++;
  1404. }
  1405. }
  1406. if (no_of_assignments == 0) {
  1407. log_printf (LOG_WARNING, "\t No CSIs of type %s configured?!!\n",
  1408. getSaNameT (cs_type));
  1409. }
  1410. }
  1411. if (no_of_csi_types == 0) {
  1412. log_printf (LOG_LEVEL_ERROR, "\t No CS types configured for comp %s ?!!\n",
  1413. getSaNameT (&comp->name));
  1414. }
  1415. }
  1416. }
  1417. #if 0
  1418. static void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
  1419. {
  1420. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  1421. struct csi_remove_callback_data *csi_remove_callback_data;
  1422. dprintf ("\t%s\n",
  1423. getSaNameT (&comp->name));
  1424. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1425. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1426. res_lib_amf_csiremovecallback.header.error = SA_AIS_OK;
  1427. csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
  1428. assert (csi_remove_callback_data); // TODO failure here of malloc
  1429. csi_remove_callback_data->csi = csi;
  1430. res_lib_amf_csiremovecallback.invocation =
  1431. invocation_create (
  1432. AMF_RESPONSE_CSIREMOVECALLBACK,
  1433. csi_remove_callback_data);
  1434. memcpy (&res_lib_amf_csiremovecallback.compName,
  1435. &comp->name, sizeof (SaNameT));
  1436. memcpy (&res_lib_amf_csiremovecallback.csiName,
  1437. &csi->name, sizeof (SaNameT));
  1438. res_lib_amf_csiremovecallback.csiFlags = 0;
  1439. openais_conn_send_response (
  1440. openais_conn_partner_get (comp->conn),
  1441. &res_lib_amf_csiremovecallback,
  1442. sizeof (struct res_lib_amf_csiremovecallback));
  1443. }
  1444. #endif
  1445. static void assign_sis_timeout_fn(void *data)
  1446. {
  1447. struct amf_application *app;
  1448. struct amf_sg *group;
  1449. dprintf("2nd Cluster start timer expired, assigning SIs\n");
  1450. for (app = amf_cluster.application_head; app != NULL; app = app->next) {
  1451. for (group = app->sg_head; group != NULL; group = group->next) {
  1452. assign_sis(group);
  1453. }
  1454. }
  1455. }
  1456. static void clc_instantiate_all (void *data)
  1457. {
  1458. struct amf_application *app;
  1459. struct amf_sg *group;
  1460. struct amf_su *unit;
  1461. struct amf_comp *comp;
  1462. dprintf("1st Cluster start timer expired, instantiating SUs\n");
  1463. for (app = amf_cluster.application_head; app != NULL; app = app->next) {
  1464. for (group = app->sg_head; group != NULL; group = group->next) {
  1465. for (unit = group->su_head; unit != NULL; unit = unit->next) {
  1466. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1467. if (strlen ((char *)comp->saAmfCompInstantiateCmd)) {
  1468. clc_instantiate (comp);
  1469. }
  1470. }
  1471. }
  1472. }
  1473. }
  1474. /* wait a while before assigning SIs as the AMF spec. says. */
  1475. poll_timer_add(aisexec_poll_handle,
  1476. amf_cluster.saAmfClusterStartupTimeout,
  1477. NULL,
  1478. assign_sis_timeout_fn,
  1479. &amf_cluster.timeout_handle);
  1480. }
  1481. #if 0
  1482. static void comp_terminate (struct amf_comp *comp)
  1483. {
  1484. clc_terminate (comp);
  1485. }
  1486. static void unit_terminate (struct amf_su *unit)
  1487. {
  1488. struct amf_comp *comp;
  1489. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1490. clc_terminate (comp);
  1491. }
  1492. }
  1493. #endif
  1494. static void comp_cleanup (struct amf_comp *comp)
  1495. {
  1496. clc_cleanup (comp);
  1497. }
  1498. static void unit_cleanup (struct amf_su *unit)
  1499. {
  1500. struct amf_comp *comp;
  1501. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1502. clc_cleanup (comp);
  1503. }
  1504. }
  1505. static void comp_restart (struct amf_comp *comp)
  1506. {
  1507. presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1508. }
  1509. #if 0
  1510. static void unit_restart (struct amf_su *unit)
  1511. {
  1512. struct amf_comp *comp;
  1513. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1514. presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1515. }
  1516. }
  1517. static void clc_unit_instantiate (struct amf_su *unit)
  1518. {
  1519. struct amf_comp *comp;
  1520. dprintf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
  1521. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1522. clc_instantiate (comp);
  1523. }
  1524. }
  1525. #endif
  1526. static void ha_state_unit_set (struct amf_su *unit, struct amf_si *si,
  1527. SaAmfHAStateT ha_state)
  1528. {
  1529. dprintf ("Assigning SI %s to SU %s with hastate %s\n",
  1530. getSaNameT (&si->name), getSaNameT (&unit->name), ha_state_text[ha_state]);
  1531. unit->requested_ha_state = ha_state;
  1532. csi_unit_set_callback (unit, si);
  1533. }
  1534. static int unit_inservice_count (struct amf_sg *group)
  1535. {
  1536. struct amf_su *unit;
  1537. int answer = 0;
  1538. for (unit = group->su_head; unit != NULL; unit = unit->next) {
  1539. if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE) {
  1540. answer += 1;
  1541. }
  1542. }
  1543. return (answer);
  1544. }
  1545. #if 0
  1546. static int comp_inservice_count (struct amf_su *unit)
  1547. {
  1548. struct amf_comp *comp;
  1549. int answer = 0;
  1550. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  1551. if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) {
  1552. answer += 1;
  1553. }
  1554. }
  1555. return (answer);
  1556. }
  1557. #endif
  1558. static int si_count (struct amf_sg *group)
  1559. {
  1560. struct amf_si *si;
  1561. int answer = 0;
  1562. for (si = group->application->si_head; si != NULL; si = si->next) {
  1563. answer += 1;
  1564. }
  1565. return (answer);
  1566. }
  1567. static inline int div_round (int a, int b)
  1568. {
  1569. int res;
  1570. res = a / b;
  1571. if ((a % b) != 0)
  1572. res++;
  1573. return res;
  1574. }
  1575. static void assign_nm_active (struct amf_sg *group, int su_units_assign)
  1576. {
  1577. struct amf_su *unit;
  1578. struct amf_si *si;
  1579. int assigned = 0;
  1580. int assign_per_su = 0;
  1581. int total_assigned = 0;
  1582. assign_per_su = si_count (group);
  1583. assign_per_su = div_round (assign_per_su, su_units_assign);
  1584. if (assign_per_su > group->saAmfSGMaxActiveSIsperSUs) {
  1585. assign_per_su = group->saAmfSGMaxActiveSIsperSUs;
  1586. }
  1587. si = group->application->si_head;
  1588. unit = group->su_head;
  1589. while (unit != NULL) {
  1590. if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) {
  1591. unit = unit->next;
  1592. continue; /* Not in service */
  1593. }
  1594. assigned = 0;
  1595. while (si != NULL &&
  1596. assigned < assign_per_su &&
  1597. total_assigned < si_count (group)) {
  1598. assigned += 1;
  1599. total_assigned += 1;
  1600. ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
  1601. si = si->next;
  1602. }
  1603. unit = unit->next;
  1604. }
  1605. }
  1606. static void assign_nm_standby (struct amf_sg *group, int units_assign_standby)
  1607. {
  1608. struct amf_su *unit;
  1609. struct amf_si *si;
  1610. int assigned = 0;
  1611. int assign_per_su = 0;
  1612. if (units_assign_standby == 0) {
  1613. return;
  1614. }
  1615. assign_per_su = si_count (group);
  1616. assign_per_su = div_round (assign_per_su, units_assign_standby);
  1617. if (assign_per_su > group->saAmfSGMaxStandbySIsperSUs) {
  1618. assign_per_su = group->saAmfSGMaxStandbySIsperSUs;
  1619. }
  1620. si = group->application->si_head;
  1621. unit = group->su_head;
  1622. while (unit != NULL) {
  1623. if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE ||
  1624. unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1625. unit = unit->next;
  1626. continue; /* Not available for assignment */
  1627. }
  1628. assigned = 0;
  1629. while (si != NULL && assigned < assign_per_su) {
  1630. assigned += 1;
  1631. ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1632. si = si->next;
  1633. }
  1634. unit = unit->next;
  1635. }
  1636. }
  1637. #if 0
  1638. static void assign_nm_spare (struct amf_sg *group)
  1639. {
  1640. struct amf_su *unit;
  1641. for (unit = group->su_head; unit != NULL; unit = unit->next) {
  1642. if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE &&
  1643. (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
  1644. unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
  1645. dprintf ("Assigning to SU %s with SPARE\n",
  1646. getSaNameT (&unit->name));
  1647. }
  1648. }
  1649. }
  1650. #endif
  1651. static void clear_requested_ha_state (struct amf_sg *group)
  1652. {
  1653. struct amf_su *unit;
  1654. for (unit = group->su_head; unit != NULL; unit = unit->next) {
  1655. unit->requested_ha_state = SA_AMF_HA_QUIESCED;
  1656. }
  1657. }
  1658. static void assign_sis (struct amf_sg *group)
  1659. {
  1660. int active_sus_needed;
  1661. int standby_sus_needed;
  1662. int inservice_count;
  1663. int units_for_standby;
  1664. int units_for_active;
  1665. int ii_spare;
  1666. int su_active_assign;
  1667. int su_standby_assign;
  1668. int su_spare_assign;
  1669. clear_requested_ha_state (group);
  1670. /*
  1671. * Number of SUs to assign to active or standby state
  1672. */
  1673. inservice_count = (float)unit_inservice_count (group);
  1674. active_sus_needed = div_round (si_count(group),
  1675. group->saAmfSGMaxActiveSIsperSUs);
  1676. standby_sus_needed = div_round (si_count(group),
  1677. group->saAmfSGMaxStandbySIsperSUs);
  1678. units_for_active = inservice_count - group->saAmfSGNumPrefStandbySUs;
  1679. if (units_for_active < 0) {
  1680. units_for_active = 0;
  1681. }
  1682. units_for_standby = inservice_count - group->saAmfSGNumPrefActiveSUs;
  1683. if (units_for_standby < 0) {
  1684. units_for_standby = 0;
  1685. }
  1686. ii_spare = inservice_count - group->saAmfSGNumPrefActiveSUs - group->saAmfSGNumPrefStandbySUs;
  1687. if (ii_spare < 0) {
  1688. ii_spare = 0;
  1689. }
  1690. /*
  1691. * Determine number of active and standby service units
  1692. * to assign based upon reduction procedure
  1693. */
  1694. if ((inservice_count - active_sus_needed) < 0) {
  1695. dprintf ("assignment VI - partial assignment with SIs drop outs\n");
  1696. su_active_assign = active_sus_needed;
  1697. su_standby_assign = 0;
  1698. su_spare_assign = 0;
  1699. } else
  1700. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  1701. dprintf ("assignment V - partial assignment with reduction of standby units\n");
  1702. su_active_assign = active_sus_needed;
  1703. if (standby_sus_needed > units_for_standby) {
  1704. su_standby_assign = units_for_standby;
  1705. } else {
  1706. su_standby_assign = standby_sus_needed;
  1707. }
  1708. su_spare_assign = 0;
  1709. } else
  1710. if ((group->saAmfSGMaxStandbySIsperSUs * units_for_standby) <= si_count (group)) {
  1711. dprintf ("IV: full assignment with reduction of active service units\n");
  1712. su_active_assign = inservice_count - standby_sus_needed;
  1713. su_standby_assign = standby_sus_needed;
  1714. su_spare_assign = 0;
  1715. } else
  1716. if ((group->saAmfSGMaxActiveSIsperSUs * units_for_active) <= si_count (group)) {
  1717. dprintf ("III: full assignment with reduction of standby service units\n");
  1718. su_active_assign = group->saAmfSGNumPrefActiveSUs;
  1719. su_standby_assign = units_for_standby;
  1720. su_spare_assign = 0;
  1721. } else
  1722. if (ii_spare == 0) {
  1723. dprintf ("II: full assignment with spare reduction\n");
  1724. su_active_assign = group->saAmfSGNumPrefActiveSUs;
  1725. su_standby_assign = group->saAmfSGNumPrefStandbySUs;
  1726. su_spare_assign = 0;
  1727. } else {
  1728. dprintf ("I: full assignment with spares\n");
  1729. su_active_assign = group->saAmfSGNumPrefActiveSUs;
  1730. su_standby_assign = group->saAmfSGNumPrefStandbySUs;
  1731. su_spare_assign = ii_spare;
  1732. }
  1733. dprintf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
  1734. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1735. assign_nm_active (group, su_active_assign);
  1736. assign_nm_standby (group, su_standby_assign);
  1737. }
  1738. static int all_sus_in_sg_ready(struct amf_sg *sg)
  1739. {
  1740. struct amf_su *su;
  1741. struct amf_comp *comp;
  1742. int ready = 1;
  1743. for (su = sg->su_head; su != NULL; su = su->next) {
  1744. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  1745. if (su->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) {
  1746. ready = 0;
  1747. }
  1748. }
  1749. }
  1750. return ready;
  1751. }
  1752. static void readiness_state_unit_set (struct amf_su *unit, SaAmfReadinessStateT readiness_state)
  1753. {
  1754. dprintf ("Assigning unit %s readiness state %s\n",
  1755. getSaNameT (&unit->name), readiness_state_text[readiness_state]);
  1756. unit->saAmfSUReadinessState = readiness_state;
  1757. if (all_sus_in_sg_ready(unit->sg)){
  1758. assign_sis (unit->sg);
  1759. if (amf_cluster.timeout_handle) {
  1760. poll_timer_delete (aisexec_poll_handle, amf_cluster.timeout_handle);
  1761. }
  1762. }
  1763. }
  1764. static void presence_state_unit_set (struct amf_su *unit, SaAmfPresenceStateT presence_state)
  1765. {
  1766. dprintf ("Setting service unit presence state %s\n",
  1767. presence_state_text[presence_state]);
  1768. }
  1769. static void escalation_policy_restart (struct amf_comp *comp)
  1770. {
  1771. dprintf ("escalation_policy_restart %d\n", comp->su->escalation_level);
  1772. dprintf ("escalation policy restart uninsint %p\n", comp);
  1773. presence_state_comp_set (
  1774. comp,
  1775. SA_AMF_PRESENCE_UNINSTANTIATED);
  1776. operational_state_comp_set (
  1777. comp,
  1778. SA_AMF_OPERATIONAL_DISABLED);
  1779. switch (comp->su->escalation_level) {
  1780. case ESCALATION_LEVEL_NO_ESCALATION:
  1781. comp_restart (comp);
  1782. break;
  1783. case ESCALATION_LEVEL_ONE:
  1784. comp_restart (comp);
  1785. break;
  1786. case ESCALATION_LEVEL_TWO:
  1787. break;
  1788. case ESCALATION_LEVEL_THREE:
  1789. break;
  1790. }
  1791. }
  1792. static void escalation_policy_cleanup (struct amf_comp *comp)
  1793. {
  1794. // escalation_timer_start (comp);
  1795. switch (comp->su->escalation_level) {
  1796. case ESCALATION_LEVEL_NO_ESCALATION:
  1797. comp->su->saAmfSURestartCount += 1;
  1798. if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGCompRestartMax) {
  1799. comp->su->escalation_level = ESCALATION_LEVEL_ONE;
  1800. escalation_policy_cleanup (comp);
  1801. comp->su->saAmfSURestartCount = 0;
  1802. return;
  1803. }
  1804. dprintf ("Escalation level 0 - restart component\n");
  1805. dprintf ("Cleaning up and restarting component.\n");
  1806. comp_cleanup (comp);
  1807. break;
  1808. case ESCALATION_LEVEL_ONE:
  1809. comp->su->saAmfSURestartCount += 1;
  1810. if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGSuRestartMax) {
  1811. comp->su->escalation_level = ESCALATION_LEVEL_TWO;
  1812. escalation_policy_cleanup (comp);
  1813. return;
  1814. }
  1815. dprintf ("Escalation level 1 - restart unit\n");
  1816. dprintf ("Cleaning up and restarting unit.\n");
  1817. unit_cleanup (comp->su);
  1818. break;
  1819. case ESCALATION_LEVEL_TWO:
  1820. dprintf ("Escalation level TWO\n");
  1821. unit_cleanup (comp->su);
  1822. // unit_terminate_failover (comp);
  1823. break;
  1824. case ESCALATION_LEVEL_THREE:
  1825. //TODO
  1826. break;
  1827. }
  1828. }
  1829. static void timer_function_healthcheck_timeout (
  1830. void *data)
  1831. {
  1832. struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)data;
  1833. dprintf ("timeout occured on healthcheck for component %s.\n",
  1834. getSaNameT (&healthcheck->comp->name));
  1835. escalation_policy_cleanup (healthcheck->comp);
  1836. }
  1837. static void healthcheck_activate (struct amf_healthcheck *healthcheck_active)
  1838. {
  1839. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1840. healthcheck_active->active = 1;
  1841. // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1842. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1843. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1844. res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
  1845. TRACE8 ("sending healthcheck to component %s",
  1846. getSaNameT (&healthcheck_active->comp->name));
  1847. res_lib_amf_healthcheckcallback.invocation =
  1848. invocation_create (
  1849. AMF_RESPONSE_HEALTHCHECKCALLBACK,
  1850. (void *)healthcheck_active);
  1851. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1852. &healthcheck_active->comp->name,
  1853. sizeof (SaNameT));
  1854. memcpy (&res_lib_amf_healthcheckcallback.key,
  1855. &healthcheck_active->safHealthcheckKey,
  1856. sizeof (SaAmfHealthcheckKeyT));
  1857. openais_conn_send_response (
  1858. openais_conn_partner_get (healthcheck_active->comp->conn),
  1859. &res_lib_amf_healthcheckcallback,
  1860. sizeof (struct res_lib_amf_healthcheckcallback));
  1861. poll_timer_delete (aisexec_poll_handle,
  1862. healthcheck_active->timer_handle_duration);
  1863. poll_timer_add (aisexec_poll_handle,
  1864. healthcheck_active->saAmfHealthcheckMaxDuration,
  1865. (void *)healthcheck_active,
  1866. timer_function_healthcheck_timeout,
  1867. &healthcheck_active->timer_handle_duration);
  1868. }
  1869. static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active)
  1870. {
  1871. log_printf (LOG_LEVEL_NOTICE,
  1872. "ZZZ deactivating healthcheck for component %s\n",
  1873. getSaNameT (&healthcheck_active->comp->name));
  1874. poll_timer_delete (aisexec_poll_handle,
  1875. healthcheck_active->timer_handle_period);
  1876. poll_timer_delete (aisexec_poll_handle,
  1877. healthcheck_active->timer_handle_duration);
  1878. invocation_destroy_by_data ((void *)healthcheck_active);
  1879. healthcheck_active->active = 0;
  1880. }
  1881. static void timer_function_healthcheck_next (
  1882. void *data)
  1883. {
  1884. healthcheck_activate (data);
  1885. }
  1886. static void operational_state_unit_set (
  1887. struct amf_su *unit,
  1888. SaAmfOperationalStateT oper_state)
  1889. {
  1890. if (oper_state == unit->saAmfSUOperState) {
  1891. dprintf ("Not assigning service unit new operational state - same state\n");
  1892. return;
  1893. }
  1894. unit->saAmfSUOperState = oper_state;
  1895. dprintf ("Service unit operational state set to %s\n",
  1896. oper_state_text[oper_state]);
  1897. if (oper_state == SA_AMF_OPERATIONAL_ENABLED) {
  1898. readiness_state_unit_set (unit,
  1899. SA_AMF_READINESS_IN_SERVICE);
  1900. /*
  1901. * Start healthcheck now
  1902. */
  1903. // TODO healthcheck_unit_activate (unit);
  1904. } else
  1905. if (oper_state == SA_AMF_OPERATIONAL_DISABLED) {
  1906. readiness_state_unit_set (unit,
  1907. SA_AMF_READINESS_OUT_OF_SERVICE);
  1908. // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1909. // healthcheck_unit_deactivate (unit);
  1910. }
  1911. }
  1912. static void message_handler_req_exec_amf_operational_state_comp_set (
  1913. void *message,
  1914. unsigned int nodeid)
  1915. {
  1916. struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
  1917. (struct req_exec_amf_operational_state_comp_set *)message;
  1918. struct amf_comp *comp;
  1919. struct amf_comp *comp_compare;
  1920. int all_set = 1;
  1921. comp = amf_find_comp (&amf_cluster, &req_exec_amf_operational_state_comp_set->name);
  1922. comp->saAmfCompOperState = req_exec_amf_operational_state_comp_set->operational_state;
  1923. dprintf ("Setting component %s operational state to %s\n",
  1924. getSaNameT (&comp->name),
  1925. oper_state_text[comp->saAmfCompOperState]);
  1926. /*
  1927. * If all operational states are ENABLED, then SU should be ENABLED
  1928. */
  1929. for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp_compare->next) {
  1930. if (comp_compare->saAmfCompOperState != SA_AMF_OPERATIONAL_ENABLED) {
  1931. all_set = 0;
  1932. break;
  1933. }
  1934. }
  1935. if (all_set) {
  1936. operational_state_unit_set (comp->su,
  1937. SA_AMF_OPERATIONAL_ENABLED);
  1938. } else {
  1939. operational_state_unit_set (comp->su,
  1940. SA_AMF_OPERATIONAL_DISABLED);
  1941. }
  1942. readiness_state_comp_set (comp);
  1943. }
  1944. static void message_handler_req_exec_amf_presence_state_comp_set (
  1945. void *message,
  1946. unsigned int nodeid)
  1947. {
  1948. struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
  1949. (struct req_exec_amf_presence_state_comp_set *)message;
  1950. struct amf_comp *comp;
  1951. struct amf_comp *comp_compare;
  1952. int all_set = 1;
  1953. ENTER_VOID();
  1954. comp = amf_find_comp (&amf_cluster, &req_exec_amf_presence_state_comp_set->name);
  1955. assert(comp);
  1956. if (req_exec_amf_presence_state_comp_set->presence_state == comp->saAmfCompPresenceState) {
  1957. dprintf ("duplicate presence state set, not setting presence state\n");
  1958. return;
  1959. }
  1960. if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_UNINSTANTIATED) {
  1961. comp->conn = 0;
  1962. }
  1963. /*
  1964. * The restarting state can only be entered from the uninstantiated state
  1965. */
  1966. if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_RESTARTING &&
  1967. comp->saAmfCompPresenceState != SA_AMF_PRESENCE_UNINSTANTIATED) {
  1968. dprintf ("restart presence state set even though not in terminating state\n");
  1969. return;
  1970. }
  1971. comp->saAmfCompPresenceState = req_exec_amf_presence_state_comp_set->presence_state;
  1972. if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) {
  1973. dprintf ("SET TO RESTARTING instantiating now\n");
  1974. clc_instantiate (comp);
  1975. }
  1976. dprintf ("Setting component %s presence state %s\n",
  1977. getSaNameT (&comp->name),
  1978. presence_state_text[comp->saAmfCompPresenceState]);
  1979. /*
  1980. * Restart components that are requested to enter the restarting presence state
  1981. */
  1982. /*
  1983. * If all comp presence states are INSTANTIATED, then SU should be instantated
  1984. */
  1985. for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp->next) {
  1986. if (comp_compare->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
  1987. all_set = 0;
  1988. break;
  1989. }
  1990. }
  1991. if (all_set) {
  1992. presence_state_unit_set (comp->su,
  1993. SA_AMF_PRESENCE_INSTANTIATED);
  1994. }
  1995. }
  1996. static void message_handler_req_exec_amf_administrative_state_csi_set (
  1997. void *message,
  1998. unsigned int nodeid)
  1999. {
  2000. // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
  2001. // (struct req_exec_amf_administrative_state_csi_set *)message;
  2002. // TODO
  2003. }
  2004. static void message_handler_req_exec_amf_administrative_state_unit_set (
  2005. void *message,
  2006. unsigned int nodeid)
  2007. {
  2008. // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
  2009. // (struct req_exec_amf_administrative_state_unit_set *)message;
  2010. // TODO
  2011. }
  2012. static void message_handler_req_exec_amf_administrative_state_group_set (
  2013. void *message,
  2014. unsigned int nodeid)
  2015. {
  2016. // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
  2017. // (struct req_exec_amf_administrative_state_group_set *)message;
  2018. // TODO
  2019. }
  2020. /*
  2021. * Library Interface Implementation
  2022. */
  2023. static void message_handler_req_lib_amf_componentregister (
  2024. void *conn,
  2025. void *msg)
  2026. {
  2027. struct req_lib_amf_componentregister *req_lib_amf_componentregister =
  2028. (struct req_lib_amf_componentregister *)msg;
  2029. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  2030. struct amf_comp *comp;
  2031. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  2032. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2033. comp = amf_find_comp (&amf_cluster, &req_lib_amf_componentregister->compName);
  2034. if (comp) {
  2035. presence_state_comp_set (comp,
  2036. SA_AMF_PRESENCE_INSTANTIATED);
  2037. operational_state_comp_set (comp,
  2038. SA_AMF_OPERATIONAL_ENABLED);
  2039. comp->conn = conn;
  2040. amf_pd->comp = comp;
  2041. comp_healthcheck_activate (comp);
  2042. error = SA_AIS_OK;
  2043. }
  2044. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  2045. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  2046. res_lib_amf_componentregister.header.error = error;
  2047. openais_conn_send_response (conn, &res_lib_amf_componentregister,
  2048. sizeof (struct res_lib_amf_componentregister));
  2049. }
  2050. static void message_handler_req_lib_amf_componentunregister (
  2051. void *conn,
  2052. void *msg)
  2053. {
  2054. #ifdef COMPILE_OUT
  2055. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2056. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2057. struct iovec iovec;
  2058. struct amf_comp *component;
  2059. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  2060. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2061. req_exec_amf_componentunregister.header.id =
  2062. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  2063. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2064. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2065. req_lib_amf_componentunregister,
  2066. sizeof (struct req_lib_amf_componentunregister));
  2067. component = amf_find_comp (&amf_cluster, &req_lib_amf_componentunregister->compName);
  2068. if (component && component->registered && component->local) {
  2069. // component->probableCause = SA_AMF_NOT_RESPONDING;
  2070. }
  2071. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2072. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2073. assert (totempg_groups_mcast_joined (openais_group_handle,
  2074. &iovec, 1, TOTEMPG_AGREED) == 0);
  2075. #endif
  2076. }
  2077. static void message_handler_req_lib_amf_pmstart (
  2078. void *conn,
  2079. void *msg)
  2080. {
  2081. }
  2082. static void message_handler_req_lib_amf_pmstop (
  2083. void *conn,
  2084. void *msg)
  2085. {
  2086. }
  2087. static void message_handler_req_lib_amf_healthcheckstart (
  2088. void *conn, void *msg)
  2089. {
  2090. struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
  2091. (struct req_lib_amf_healthcheckstart *)msg;
  2092. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  2093. struct amf_healthcheck *healthcheck;
  2094. struct amf_comp *comp;
  2095. SaAisErrorT error = SA_AIS_OK;
  2096. ENTER();
  2097. comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstart->compName);
  2098. if (comp == 0) {
  2099. error = SA_AIS_ERR_NOT_EXIST;
  2100. goto error_exit;
  2101. }
  2102. healthcheck = amf_find_healthcheck (comp, &req_lib_amf_healthcheckstart->healthcheckKey);
  2103. if (healthcheck == 0) {
  2104. error = SA_AIS_ERR_NOT_EXIST;
  2105. goto error_exit;
  2106. }
  2107. /*
  2108. * Determine if this healthcheck is already active
  2109. */
  2110. if (healthcheck->active) {
  2111. error = SA_AIS_ERR_EXIST;
  2112. goto error_exit;
  2113. }
  2114. /*
  2115. * Initialise
  2116. */
  2117. healthcheck->invocationType = req_lib_amf_healthcheckstart->invocationType;
  2118. healthcheck->timer_handle_duration = 0;
  2119. healthcheck->timer_handle_period = 0;
  2120. healthcheck->active = 0;
  2121. if (comp->conn == NULL) {
  2122. comp->conn = conn;
  2123. }
  2124. healthcheck_activate (healthcheck);
  2125. error_exit:
  2126. res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  2127. res_lib_amf_healthcheckstart.header.size = sizeof (struct res_lib_amf_healthcheckstart);
  2128. res_lib_amf_healthcheckstart.header.error = error;
  2129. openais_conn_send_response (conn, &res_lib_amf_healthcheckstart,
  2130. sizeof (struct res_lib_amf_healthcheckstart));
  2131. }
  2132. static void message_handler_req_lib_amf_healthcheckconfirm (
  2133. void *conn,
  2134. void *msg)
  2135. {
  2136. }
  2137. static void message_handler_req_lib_amf_healthcheckstop (
  2138. void *conn,
  2139. void *msg)
  2140. {
  2141. struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop =
  2142. (struct req_lib_amf_healthcheckstop *)msg;
  2143. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  2144. struct amf_healthcheck *healthcheck;
  2145. struct amf_comp *comp;
  2146. SaAisErrorT error = SA_AIS_OK;
  2147. dprintf ("healthcheck stop\n");
  2148. comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstop->compName);
  2149. if (comp == 0) {
  2150. error = SA_AIS_ERR_NOT_EXIST;
  2151. goto error_exit;
  2152. }
  2153. healthcheck = amf_find_healthcheck (
  2154. comp,
  2155. &req_lib_amf_healthcheckstop->healthcheckKey);
  2156. dprintf ("active %p\n", healthcheck);
  2157. if (healthcheck == 0) {
  2158. error = SA_AIS_ERR_NOT_EXIST;
  2159. goto error_exit;
  2160. }
  2161. healthcheck_deactivate (healthcheck);
  2162. error_exit:
  2163. dprintf ("healthcheck stop\n");
  2164. res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  2165. res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop);
  2166. res_lib_amf_healthcheckstop.header.error = error;
  2167. openais_conn_send_response (conn, &res_lib_amf_healthcheckstop,
  2168. sizeof (struct res_lib_amf_healthcheckstop));
  2169. }
  2170. static void message_handler_req_lib_amf_hastateget (
  2171. void *conn,
  2172. void *msg)
  2173. {
  2174. #ifdef COMPILE_OUT
  2175. struct req_lib_amf_hastateget *req_lib_amf_hastateget = (struct req_lib_amf_hastateget *)msg;
  2176. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2177. struct amf_comp *component;
  2178. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_hastateget()\n");
  2179. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2180. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2181. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2182. #ifdef COMPILE_OUT
  2183. component = component_in_protectiongroup_find (&req_lib_amf_hastateget->csiName, &req_lib_amf_hastateget->compName);
  2184. #endif
  2185. if (component) {
  2186. memcpy (&res_lib_amf_hastateget.haState,
  2187. &component->currentHAState, sizeof (SaAmfHAStateT));
  2188. res_lib_amf_hastateget.header.error = SA_AIS_OK;
  2189. }
  2190. openais_conn_send_response (conn, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2191. #endif
  2192. }
  2193. static void message_handler_req_lib_amf_protectiongrouptrack (
  2194. void *conn,
  2195. void *msg)
  2196. {
  2197. #ifdef COMPILE_OUT
  2198. struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
  2199. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  2200. struct libamf_ci_trackentry *track = 0;
  2201. int i;
  2202. struct saAmfProtectionGroup *amfProtectionGroup;
  2203. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
  2204. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
  2205. if (amfProtectionGroup) {
  2206. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
  2207. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2208. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2209. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2210. break;
  2211. }
  2212. }
  2213. if (track == 0) {
  2214. grow_amf_track_table (conn_info, 1);
  2215. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2216. }
  2217. track->active = 1;
  2218. track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
  2219. track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
  2220. memcpy (&track->csiName,
  2221. &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
  2222. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2223. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2224. /*
  2225. * If SA_TRACK_CURRENT is specified, write out all current connections
  2226. */
  2227. } else {
  2228. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2229. }
  2230. res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
  2231. res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
  2232. res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
  2233. if (amfProtectionGroup) {
  2234. res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
  2235. }
  2236. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
  2237. sizeof (struct res_lib_amf_protectiongrouptrack));
  2238. if (amfProtectionGroup &&
  2239. req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
  2240. protectiongroup_notification_send (conn_info,
  2241. track->notificationBufferAddress,
  2242. amfProtectionGroup,
  2243. 0,
  2244. 0,
  2245. SA_TRACK_CHANGES_ONLY);
  2246. track->trackFlags &= ~SA_TRACK_CURRENT;
  2247. }
  2248. #endif
  2249. }
  2250. static void message_handler_req_lib_amf_csiquiescingcomplete (
  2251. void *conn,
  2252. void *msg)
  2253. {
  2254. }
  2255. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  2256. void *conn,
  2257. void *msg)
  2258. {
  2259. #ifdef COMPILE_OUT
  2260. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  2261. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2262. struct libamf_ci_trackentry *track = 0;
  2263. int i;
  2264. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  2265. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2266. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  2267. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2268. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2269. }
  2270. }
  2271. if (track) {
  2272. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  2273. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2274. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2275. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2276. list_del (&conn_info->conn_list);
  2277. }
  2278. }
  2279. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2280. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2281. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2282. if (track) {
  2283. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  2284. }
  2285. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  2286. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2287. #endif
  2288. }
  2289. static void message_handler_req_lib_amf_componenterrorreport (
  2290. void *conn,
  2291. void *msg)
  2292. {
  2293. struct req_lib_amf_componenterrorreport *req_lib_amf_componenterrorreport = (struct req_lib_amf_componenterrorreport *)msg;
  2294. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2295. struct amf_comp *comp;
  2296. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2297. ENTER();
  2298. log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n");
  2299. dprintf ("ERROR REPORT\n");
  2300. comp = amf_find_comp (&amf_cluster, &req_lib_amf_componenterrorreport->erroneousComponent);
  2301. if (comp) {
  2302. dprintf ("escalation policy terminate\n");
  2303. escalation_policy_cleanup (comp);
  2304. error = SA_AIS_OK;
  2305. }
  2306. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2307. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2308. res_lib_amf_componenterrorreport.header.error = error;
  2309. openais_conn_send_response (
  2310. conn, &res_lib_amf_componenterrorreport,
  2311. sizeof (struct res_lib_amf_componenterrorreport));
  2312. }
  2313. static void message_handler_req_lib_amf_componenterrorclear (
  2314. void *conn,
  2315. void *msg)
  2316. {
  2317. #ifdef COMPILLE_OUT
  2318. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  2319. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  2320. struct iovec iovec;
  2321. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  2322. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  2323. req_exec_amf_componenterrorclear.header.id =
  2324. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  2325. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  2326. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  2327. req_lib_amf_componenterrorclear,
  2328. sizeof (struct req_lib_amf_componenterrorclear));
  2329. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  2330. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  2331. assert (totempg_groups_mcast_joined (openais_group_handle,
  2332. &iovec, 1, TOTEMPG_AGREED) == 0);
  2333. #endif
  2334. }
  2335. #if 0
  2336. static void pg_comp_create (
  2337. struct amf_pg *pg,
  2338. struct amf_csi *csi,
  2339. struct amf_comp *comp)
  2340. {
  2341. struct amf_pg_comp *pg_comp;
  2342. dprintf ("creating component for pg\n");
  2343. pg_comp = malloc (sizeof (struct amf_pg_comp));
  2344. assert (pg_comp);
  2345. pg_comp->comp = comp;
  2346. pg_comp->csi = csi;
  2347. list_init (&pg_comp->list);
  2348. list_add_tail (&pg_comp->list, &pg->pg_comp_head);
  2349. }
  2350. #endif
  2351. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  2352. {
  2353. struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)msg;
  2354. struct res_lib_amf_response res_lib_amf_response;
  2355. struct csi_set_callback_data *csi_set_callback_data;
  2356. struct csi_remove_callback_data *csi_remove_callback_data;
  2357. struct component_terminate_callback_data *component_terminate_callback_data;
  2358. struct amf_healthcheck *healthcheck_active;
  2359. int interface;
  2360. int res;
  2361. void *data;
  2362. SaAisErrorT error = SA_AIS_OK;
  2363. ENTER_VOID();
  2364. res = invocation_get_and_destroy (req_lib_amf_response->invocation,
  2365. &interface, &data);
  2366. if (res == -1) {
  2367. dprintf ("invocation not found\n");
  2368. error = SA_AIS_ERR_NOT_EXIST;
  2369. goto error_exit;
  2370. }
  2371. switch (interface) {
  2372. case AMF_RESPONSE_HEALTHCHECKCALLBACK:
  2373. dprintf ("healtcheck callback executed from library.\n");
  2374. healthcheck_active = (struct amf_healthcheck*)data;
  2375. poll_timer_delete (aisexec_poll_handle,
  2376. healthcheck_active->timer_handle_duration);
  2377. healthcheck_active->timer_handle_duration = 0;
  2378. poll_timer_add (aisexec_poll_handle,
  2379. healthcheck_active->saAmfHealthcheckPeriod,
  2380. (void *)healthcheck_active,
  2381. timer_function_healthcheck_next,
  2382. &healthcheck_active->timer_handle_period);
  2383. break;
  2384. case AMF_RESPONSE_CSISETCALLBACK:
  2385. csi_set_callback_data = (struct csi_set_callback_data *)data;
  2386. dprintf ("csi set callback executed from library.\n");
  2387. // list_add (&csi_set_callback_data->comp->
  2388. /*
  2389. pg_comp_create (
  2390. csi_set_callback_data->pg,
  2391. csi_set_callback_data->csi,
  2392. csi_set_callback_data->comp);
  2393. */
  2394. free (csi_set_callback_data);
  2395. break;
  2396. case AMF_RESPONSE_CSIREMOVECALLBACK:
  2397. csi_remove_callback_data = (struct csi_remove_callback_data *)data;
  2398. dprintf ("response from removing the CSI\n");
  2399. // AAAA
  2400. // list_del (&csi_remove_callback_data->csi->si->su_list);
  2401. // list_del (&csi_remove_callback_data->csi->si_csi_list);
  2402. free (csi_remove_callback_data);
  2403. break;
  2404. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
  2405. component_terminate_callback_data = (struct component_terminate_callback_data *)data;
  2406. dprintf ("response from terminating component\n");
  2407. comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  2408. escalation_policy_restart (component_terminate_callback_data->comp);
  2409. break;
  2410. default:
  2411. // TODO
  2412. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_lib_amf_response->invocation);
  2413. break;
  2414. }
  2415. error_exit:
  2416. res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
  2417. res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
  2418. res_lib_amf_response.header.error = SA_AIS_OK;
  2419. openais_conn_send_response (conn, &res_lib_amf_response,
  2420. sizeof (struct res_lib_amf_response));
  2421. LEAVE_VOID();
  2422. }
  2423. static void amf_dump_comp (struct amf_comp *comp ,void *data)
  2424. {
  2425. #if 0
  2426. int level = LOG_LEVEL_NOTICE;
  2427. data = NULL;
  2428. struct list_head* cs_types;
  2429. struct amf_cs_type* cs_type;
  2430. log_printf (level, "----------------\n" );
  2431. log_printf (level, "source_addr = %s\n",
  2432. inet_ntoa (comp->source_addr));
  2433. log_printf (level, "unit = %s\n",
  2434. comp->su->name.value);
  2435. log_printf (level, "name = %s\n", comp->name.value);
  2436. log_printf (level, "cs types\n");
  2437. for (cs_types = comp->cs_types.next;
  2438. cs_types != &comp->cs_types;
  2439. cs_types = cs_types->next) {
  2440. cs_type = list_entry (cs_types, struct amf_cs_type, comp_cs_type_list);
  2441. log_printf (level, " name = %s\n" , cs_type->attr_name.value);
  2442. }
  2443. log_printf (level, "category = %u\n", comp->category);
  2444. log_printf (level, "capability = %u\n", comp->capability);
  2445. log_printf (level, "num_max_active_csi = %u\n",
  2446. comp->num_max_active_csi);
  2447. log_printf (level, "num_max_standby_csi = %u\n",
  2448. comp->num_max_standby_csi);
  2449. log_printf (level, "default_clc_cli_timeout = %u\n",
  2450. comp->default_clc_cli_timeout);
  2451. log_printf (level, "default_callback_timeout = %u\n",
  2452. comp->default_callback_timeout);
  2453. log_printf (level, "oper state = %s\n",
  2454. oper_state_text[comp->saAmfCompOperState]);
  2455. log_printf (level, "readiness state = %s\n",
  2456. readiness_state_text[comp->saAmfCompReadinessState]);
  2457. log_printf (level, "presence state = %s\n",
  2458. presence_state_text[comp->saAmfCompPresenceState]);
  2459. log_printf (level, "restart_count = %u\n",
  2460. comp->restart_count);
  2461. #endif
  2462. }
  2463. static void enumerate_components (
  2464. void (*function)(struct amf_comp *, void *data),
  2465. void *data)
  2466. {
  2467. #if 0
  2468. struct list_head *AmfGroupList;
  2469. struct list_head *AmfUnitList;
  2470. struct list_head *AmfComponentList;
  2471. struct amf_sg *saAmfGroup;
  2472. struct amf_su *AmfUnit;
  2473. struct amf_comp *AmfComponent;
  2474. /*
  2475. * Search all groups
  2476. */
  2477. for (AmfGroupList = amf_sg_head.next;
  2478. AmfGroupList != &amf_sg_head;
  2479. AmfGroupList = AmfGroupList->next) {
  2480. saAmfGroup = list_entry (AmfGroupList,
  2481. struct amf_sg, application_sg_list);
  2482. /*
  2483. * Search all units
  2484. */
  2485. for (AmfUnitList = saAmfGroup->su_head.next;
  2486. AmfUnitList != &saAmfGroup->su_head;
  2487. AmfUnitList = AmfUnitList->next) {
  2488. AmfUnit = list_entry (AmfUnitList,
  2489. struct amf_su, sg_su_list);
  2490. /*
  2491. * Search all components
  2492. */
  2493. for (AmfComponentList = AmfUnit->comp_head.next;
  2494. AmfComponentList != &AmfUnit->comp_head;
  2495. AmfComponentList = AmfComponentList->next) {
  2496. AmfComponent = list_entry (AmfComponentList,
  2497. struct amf_comp, su_comp_list);
  2498. function (AmfComponent, data);
  2499. }
  2500. }
  2501. }
  2502. #endif
  2503. }
  2504. static void amf_dump ( )
  2505. {
  2506. enumerate_components (amf_dump_comp, NULL);
  2507. }