amf.c 88 KB

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