amf.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <string.h>
  47. #include "../include/ais_types.h"
  48. #include "../include/ais_msg.h"
  49. #include "../include/list.h"
  50. #include "../include/queue.h"
  51. #include "totempg.h"
  52. #include "aispoll.h"
  53. #include "mempool.h"
  54. #include "util.h"
  55. #include "parse.h"
  56. #include "main.h"
  57. #include "handlers.h"
  58. #define LOG_SERVICE LOG_SERVICE_AMF
  59. #include "print.h"
  60. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  61. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  62. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  63. struct invocation {
  64. struct conn_info *conn_info;
  65. int interface;
  66. int active;
  67. };
  68. struct invocation *invocation_entries = 0;
  69. int invocation_entries_size = 0;
  70. //TODO static void *tok_call_handle = NULL;
  71. static int recovery = 0;
  72. #ifdef INPARSEDOTH
  73. enum amfOperationalState {
  74. AMF_OPER_DISABLED,
  75. AMF_OPER_ENABLED
  76. };
  77. enum amfAdministrativeState {
  78. AMF_ADMIN_UNLOCKED,
  79. AMF_ADMIN_LOCKED,
  80. AMF_ADMIN_STOPPING
  81. };
  82. enum amfOperationalAdministrativeState {
  83. AMF_ENABLED_UNLOCKED,
  84. AMF_DISABLED_UNLOCKED,
  85. AMF_DISABLED_LOCKED,
  86. AMF_ENABLED_STOPPING
  87. };
  88. /*
  89. * State machines for states in AMF
  90. */
  91. enum amfEnabledUnlockedState {
  92. AMF_ENABLED_UNLOCKED_INITIAL,
  93. AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED,
  94. AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED,
  95. AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED,
  96. AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED,
  97. AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED,
  98. AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED,
  99. };
  100. enum amfDisabledUnlockedState {
  101. AMF_DISABLED_UNLOCKED_INITIAL,
  102. AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED,
  103. AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED,
  104. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED,
  105. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED
  106. };
  107. enum amfDisabledLockedState {
  108. AMF_DISABLED_LOCKED_INITIAL,
  109. AMF_DISABLED_LOCKED_QUIESCED_REQUESTED,
  110. AMF_DISABLED_LOCKED_QUIESCED_COMPLETED,
  111. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_REQUESTED
  112. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_COMPLETED
  113. };
  114. enum amfEnabledStoppingState {
  115. AMF_ENABLED_STOPPING_INITIAL,
  116. AMF_ENABLED_STOPPING_STOPPING_REQUESTED,
  117. AMF_ENABLED_STOPPING_STOPPING_COMPLETED
  118. };
  119. /*
  120. * Internal Functions
  121. */
  122. static void componentOutOfServiceSetNoApi (
  123. struct saAmfComponent *component);
  124. #endif
  125. static void grow_amf_track_table (
  126. struct conn_info *conn_info,
  127. int growby);
  128. static int activeServiceUnitsCount (
  129. struct saAmfGroup *saAmfGroup);
  130. static void component_unregister (
  131. struct saAmfComponent *component);
  132. static void enumerate_components (
  133. void (*function)(struct saAmfComponent *, void *data),
  134. void *data);
  135. #ifdef COMPILE_OUT
  136. static void CSIRemove (
  137. struct conn_info *conn_info);
  138. static void haStateSetClusterInit (
  139. struct conn_info *conn_info,
  140. struct saAmfComponent *saAmfComponent);
  141. #endif
  142. static void ha_state_api_set (
  143. struct saAmfComponent *saAmfComponent,
  144. SaAmfHAStateT haState);
  145. static void ha_state_group_set (
  146. struct saAmfComponent *saAmfComponent,
  147. SaAmfHAStateT haState);
  148. static void readiness_state_api_set (
  149. struct saAmfComponent *component,
  150. SaAmfReadinessStateT readinessState);
  151. #ifdef COMPILE_OUT
  152. static void readinessStateSetClusterInit (
  153. struct conn_info *conn_info,
  154. struct saAmfComponent *saAmfComponent);
  155. #endif
  156. static void readiness_state_group_set (
  157. struct saAmfComponent *saAmfComponent,
  158. SaAmfReadinessStateT readinessState);
  159. #ifdef COMPILE_OUT
  160. static void enumerateComponentsClusterInit (
  161. struct saAmfComponent *component,
  162. void *data);
  163. #endif
  164. static void dsm (
  165. struct saAmfComponent *saAmfComponent);
  166. #if 0 /* NOT IMPLEMENTED */
  167. static void componentTerminate (
  168. struct conn_info *conn_info);
  169. #endif
  170. static void timer_function_libamf_healthcheck (
  171. void *data);
  172. static struct saAmfProtectionGroup *protectiongroup_find (
  173. SaNameT *csiName);
  174. static struct saAmfComponent *component_in_protectiongroup_find (
  175. SaNameT *csiName,
  176. SaNameT *compName);
  177. static void protectiongroup_notifications_send (
  178. struct saAmfComponent *changedComponent,
  179. SaAmfProtectionGroupChangesT changeToComponent);
  180. static void protectiongroup_notification_send (
  181. struct conn_info *conn_info,
  182. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  183. struct saAmfProtectionGroup *amfProtectionGroup,
  184. struct saAmfComponent *changedComponent,
  185. SaAmfProtectionGroupChangesT changeToComponent,
  186. SaUint8T trackFlags);
  187. static void response_handler_readinessstatesetcallback (
  188. struct conn_info *conn_info,
  189. struct req_amf_response *req_amf_response);
  190. static void response_handler_csisetcallback (
  191. struct conn_info *conn_info,
  192. struct req_amf_response *req_amf_response);
  193. static void amf_confchg_nleave (
  194. struct saAmfComponent *component,
  195. void *data);
  196. static void amf_confchg_njoin (
  197. struct saAmfComponent *component,
  198. void *data);
  199. static int amf_confchg_fn (
  200. enum totem_configuration_type configuration_type,
  201. struct in_addr *member_list, int member_list_entries,
  202. struct in_addr *left_list, int left_list_entries,
  203. struct in_addr *joined_list, int joined_list_entries,
  204. struct memb_ring_id *ring_id);
  205. /***
  206. static void amf_dump (void);
  207. ***/
  208. static int amf_exit_fn (struct conn_info *conn_info);
  209. static int amf_exec_init_fn (void);
  210. static void amf_synchronize (void *message, struct in_addr source_addr);
  211. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  212. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  213. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required);
  214. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required);
  215. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  216. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  217. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message);
  218. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message);
  219. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message);
  220. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message);
  221. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message);
  222. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message);
  223. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message);
  224. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message);
  225. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message);
  226. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message);
  227. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info, void *message);
  228. static int message_handler_req_amf_response (struct conn_info *conn_info, void *message);
  229. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message);
  230. /*
  231. int (*amf_libais_handler_fns[]) (struct conn_info *conn_info, void *) = {
  232. message_handler_req_lib_activatepoll,
  233. message_handler_req_amf_componentregister,
  234. message_handler_req_amf_componentunregister,
  235. message_handler_req_amf_readinessstateget,
  236. message_handler_req_amf_hastateget,
  237. message_handler_req_amf_protectiongrouptrackstart,
  238. message_handler_req_amf_protectiongrouptrackstop,
  239. message_handler_req_amf_errorreport,
  240. message_handler_req_amf_errorcancelall,
  241. message_handler_req_amf_stoppingcomplete,
  242. message_handler_req_amf_response,
  243. message_handler_req_amf_componentcapabilitymodelget
  244. };
  245. */
  246. struct libais_handler amf_libais_handlers[] =
  247. {
  248. { /* 0 */
  249. .libais_handler_fn = message_handler_req_lib_activatepoll,
  250. .response_size = sizeof (struct res_lib_activatepoll),
  251. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL, // TODO RESPONSE
  252. .flow_control = FLOW_CONTROL_REQUIRED
  253. },
  254. { /* 1 */
  255. .libais_handler_fn = message_handler_req_amf_componentregister,
  256. .response_size = sizeof (struct res_lib_amf_componentregister),
  257. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  258. .flow_control = FLOW_CONTROL_REQUIRED
  259. },
  260. { /* 2 */
  261. .libais_handler_fn = message_handler_req_amf_componentunregister,
  262. .response_size = sizeof (struct res_lib_amf_componentunregister),
  263. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  264. .flow_control = FLOW_CONTROL_REQUIRED
  265. },
  266. { /* 3 */
  267. .libais_handler_fn = message_handler_req_amf_readinessstateget,
  268. .response_size = sizeof (struct res_lib_amf_readinessstateget),
  269. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  270. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  271. },
  272. { /* 4 */
  273. .libais_handler_fn = message_handler_req_amf_hastateget,
  274. .response_size = sizeof (struct res_lib_amf_hastateget),
  275. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  276. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  277. },
  278. { /* 5 */
  279. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstart,
  280. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart),
  281. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART,
  282. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  283. },
  284. { /* 6 */
  285. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstop,
  286. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  287. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  288. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  289. },
  290. { /* 7 */
  291. .libais_handler_fn = message_handler_req_amf_errorreport,
  292. .response_size = sizeof (struct res_lib_amf_errorreport),
  293. .response_id = MESSAGE_RES_AMF_ERRORREPORT,
  294. .flow_control = FLOW_CONTROL_REQUIRED
  295. },
  296. { /* 8 */
  297. .libais_handler_fn = message_handler_req_amf_errorcancelall,
  298. .response_size = sizeof (struct res_lib_amf_errorcancelall),
  299. .response_id = MESSAGE_RES_AMF_ERRORCANCELALL,
  300. .flow_control = FLOW_CONTROL_REQUIRED
  301. },
  302. { /* 9 */
  303. .libais_handler_fn = message_handler_req_amf_stoppingcomplete,
  304. .response_size = sizeof (struct res_lib_amf_stoppingcomplete),
  305. .response_id = MESSAGE_RES_AMF_STOPPINGCOMPLETE, // TODO
  306. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  307. },
  308. { /* 10 */
  309. .libais_handler_fn = message_handler_req_amf_response,
  310. .response_size = sizeof (struct res_lib_amf_response),
  311. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  312. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  313. },
  314. { /* 11 */
  315. .libais_handler_fn = message_handler_req_amf_componentcapabilitymodelget,
  316. .response_size = sizeof (struct res_lib_amf_componentcapabilitymodelget),
  317. .response_id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET,
  318. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  319. }
  320. };
  321. int (*amf_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  322. message_handler_req_exec_amf_componentregister,
  323. message_handler_req_exec_amf_componentunregister,
  324. message_handler_req_exec_amf_errorreport,
  325. message_handler_req_exec_amf_errorcancelall,
  326. message_handler_req_exec_amf_readinessstateset,
  327. message_handler_req_exec_amf_hastateset,
  328. };
  329. /*
  330. * Exports the interface for the service
  331. */
  332. struct service_handler amf_service_handler = {
  333. .libais_handlers = amf_libais_handlers,
  334. .libais_handlers_count = sizeof (amf_libais_handlers) / sizeof (struct libais_handler),
  335. .aisexec_handler_fns = amf_aisexec_handler_fns,
  336. .aisexec_handler_fns_count = sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  337. .confchg_fn = amf_confchg_fn,
  338. .libais_init_fn = message_handler_req_amf_init,
  339. .libais_exit_fn = amf_exit_fn,
  340. .exec_init_fn = amf_exec_init_fn,
  341. .exec_dump_fn = amf_dump
  342. };
  343. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  344. {
  345. struct libamf_ci_trackentry *tracks;
  346. int newsize;
  347. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  348. newsize = growby + currsize;
  349. if (newsize > currsize) {
  350. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  351. (newsize) * sizeof (struct libamf_ci_trackentry));
  352. if (tracks == 0) {
  353. #ifdef DEBUG
  354. printf ("grow_amf_track_table: out of memory, woops\n");
  355. #endif
  356. // TODO
  357. exit (1);
  358. }
  359. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  360. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  361. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  362. }
  363. }
  364. int req_amf_invocation_create (int interface,
  365. struct conn_info *conn_info)
  366. {
  367. struct invocation *invocation_addr = 0;
  368. struct invocation *invocation_temp;
  369. int i;
  370. int loc = 0;
  371. for (i = 0; i < invocation_entries_size; i++) {
  372. if (invocation_entries[i].active == 0) {
  373. invocation_addr = &invocation_entries[i];
  374. loc = i;
  375. break;
  376. }
  377. }
  378. if (invocation_addr == 0) {
  379. invocation_temp = (struct invocation *)realloc (invocation_entries,
  380. (invocation_entries_size + 1) * sizeof (struct invocation));
  381. if (invocation_temp == 0) {
  382. return (-1);
  383. }
  384. invocation_entries = invocation_temp;
  385. invocation_addr = &invocation_entries[invocation_entries_size];
  386. loc = invocation_entries_size;
  387. invocation_entries_size += 1;
  388. }
  389. invocation_addr->interface = interface;
  390. invocation_addr->conn_info = conn_info;
  391. invocation_addr->active = 1;
  392. return (loc);
  393. }
  394. int req_amf_invocation_get_and_destroy (int invocation, int *interface,
  395. struct conn_info **conn_info)
  396. {
  397. if (invocation > invocation_entries_size) {
  398. return (-1);
  399. }
  400. if (invocation_entries[invocation].active == 0) {
  401. return (-1);
  402. }
  403. *interface = invocation_entries[invocation].interface;
  404. *conn_info = invocation_entries[invocation].conn_info;
  405. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  406. return (0);
  407. }
  408. static void component_unregister (
  409. struct saAmfComponent *component)
  410. {
  411. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  412. struct iovec iovecs[2];
  413. /*
  414. * This only works on local components
  415. */
  416. if (component == 0 || component->local != 1) {
  417. return;
  418. }
  419. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  420. getSaNameT (&component->name));
  421. component->probableCause = SA_AMF_NOT_RESPONDING;
  422. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  423. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  424. req_exec_amf_componentunregister.source.conn_info = 0;
  425. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  426. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  427. 0, sizeof (struct req_lib_amf_componentunregister));
  428. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  429. &component->name,
  430. sizeof (SaNameT));
  431. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  432. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  433. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  434. }
  435. static void component_register (
  436. struct saAmfComponent *component)
  437. {
  438. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  439. struct iovec iovecs[2];
  440. /*
  441. * This only works on local components
  442. */
  443. if (component == 0 || component->local != 1) {
  444. return;
  445. }
  446. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  447. getSaNameT (&component->name));
  448. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  449. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  450. req_exec_amf_componentregister.source.conn_info = 0;
  451. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  452. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  453. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  454. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  455. req_exec_amf_componentregister.newHAState = component->newHAState;
  456. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  457. 0, sizeof (struct req_lib_amf_componentregister));
  458. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  459. &component->name,
  460. sizeof (SaNameT));
  461. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  462. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  463. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  464. }
  465. /***
  466. This should be used for a partition I think
  467. **/
  468. void enumerate_components (
  469. void (*function)(struct saAmfComponent *, void *data),
  470. void *data)
  471. {
  472. struct list_head *AmfGroupList;
  473. struct list_head *AmfUnitList;
  474. struct list_head *AmfComponentList;
  475. struct saAmfGroup *saAmfGroup;
  476. struct saAmfUnit *AmfUnit;
  477. struct saAmfComponent *AmfComponent;
  478. /*
  479. * Search all groups
  480. */
  481. for (AmfGroupList = saAmfGroupHead.next;
  482. AmfGroupList != &saAmfGroupHead;
  483. AmfGroupList = AmfGroupList->next) {
  484. saAmfGroup = list_entry (AmfGroupList,
  485. struct saAmfGroup, saAmfGroupList);
  486. /*
  487. * Search all units
  488. */
  489. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  490. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  491. AmfUnitList = AmfUnitList->next) {
  492. AmfUnit = list_entry (AmfUnitList,
  493. struct saAmfUnit, saAmfUnitList);
  494. /*
  495. * Search all components
  496. */
  497. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  498. AmfComponentList != &AmfUnit->saAmfComponentHead;
  499. AmfComponentList = AmfComponentList->next) {
  500. AmfComponent = list_entry (AmfComponentList,
  501. struct saAmfComponent, saAmfComponentList);
  502. function (AmfComponent, data);
  503. }
  504. }
  505. }
  506. }
  507. int activeServiceUnitsCount (struct saAmfGroup *saAmfGroup) {
  508. struct saAmfUnit *saAmfUnit;
  509. struct saAmfComponent *saAmfComponent;
  510. struct list_head *saAmfComponentList;
  511. struct list_head *saAmfUnitList;
  512. int activeServiceUnits = 0;
  513. int thisServiceUnitActive;
  514. /*
  515. * Search all units
  516. */
  517. for (activeServiceUnits = 0, saAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  518. saAmfUnitList != &saAmfGroup->saAmfUnitHead;
  519. saAmfUnitList = saAmfUnitList->next) {
  520. saAmfUnit = list_entry (saAmfUnitList,
  521. struct saAmfUnit, saAmfUnitList);
  522. /*
  523. * Search all components
  524. */
  525. for (thisServiceUnitActive = 1, saAmfComponentList = saAmfUnit->saAmfComponentHead.next;
  526. saAmfComponentList != &saAmfUnit->saAmfComponentHead;
  527. saAmfComponentList = saAmfComponentList->next) {
  528. saAmfComponent = list_entry (saAmfComponentList,
  529. struct saAmfComponent, saAmfComponentList);
  530. if (saAmfComponent->newHAState != SA_AMF_ACTIVE) {
  531. thisServiceUnitActive = 0;
  532. }
  533. }
  534. /*
  535. * If all components are active in service unit, count service unit as active
  536. */
  537. if (thisServiceUnitActive) {
  538. activeServiceUnits += 1;
  539. }
  540. }
  541. return (activeServiceUnits);
  542. }
  543. #ifdef CONFIG_TODO
  544. This should be sent after a service unit is made out of service
  545. void CSIRemove (struct conn_info *conn_info)
  546. {
  547. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  548. if (conn_info->active == 0 ||
  549. conn_info->service != SOCKET_SERVICE_AMF) {
  550. return;
  551. }
  552. log_printf (LOG_NOTICE_DEBUG, "executing CSI remove callback into API\n");
  553. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  554. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  555. res_lib_amf_csiremovecallback.header.error = SA_OK;
  556. res_lib_amf_csiremovecallback.invocation =
  557. req_amf_response_set (
  558. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK,
  559. conn_info->fd);
  560. memcpy (&res_lib_amf_csiremovecallback.compName,
  561. &conn_info->component->name, sizeof (SaNameT));
  562. memcpy (&res_lib_amf_csiremovecallback.csiName,
  563. &conn_info->component->saAmfProtectionGroup->name, sizeof (SaNameT));
  564. res_lib_amf_csiremovecallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  565. libais_send_response (conn_info, &res_lib_amf_csiremovecallback,
  566. sizeof (struct res_lib_amf_csiremovecallback));
  567. }
  568. #endif
  569. void ha_state_api_set (struct saAmfComponent *component, SaAmfHAStateT haState)
  570. {
  571. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  572. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  573. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  574. if (component->local != 1) {
  575. return;
  576. }
  577. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  578. return;
  579. }
  580. /*
  581. * this should be an assertion
  582. */
  583. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  584. component->conn_info->service != SOCKET_SERVICE_AMF) {
  585. return;
  586. }
  587. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  588. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  589. res_lib_amf_csisetcallback.header.error = SA_OK;
  590. res_lib_amf_csisetcallback.invocation =
  591. req_amf_invocation_create (
  592. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK,
  593. component->conn_info);
  594. if (res_lib_amf_csisetcallback.invocation == -1) {
  595. printf ("TODO set callback\n");
  596. }
  597. memcpy (&res_lib_amf_csisetcallback.compName,
  598. &component->name, sizeof (SaNameT));
  599. memcpy (&res_lib_amf_csisetcallback.csiName,
  600. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  601. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  602. res_lib_amf_csisetcallback.haState = haState;
  603. // TODO set activeCompName to correct component name
  604. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  605. &component->name, sizeof (SaNameT));
  606. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  607. component->newHAState = haState;
  608. libais_send_response (component->conn_info, &res_lib_amf_csisetcallback,
  609. sizeof (struct res_lib_amf_csisetcallback));
  610. }
  611. static void ha_state_group_set (
  612. struct saAmfComponent *component,
  613. SaAmfHAStateT haState)
  614. {
  615. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  616. struct iovec iovecs[2];
  617. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  618. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  619. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  620. req_exec_amf_hastateset.haState = haState;
  621. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  622. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  623. iovecs[0].iov_base = (char *)&req_exec_amf_hastateset;
  624. iovecs[0].iov_len = sizeof (req_exec_amf_hastateset);
  625. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  626. }
  627. void readiness_state_api_set (struct saAmfComponent *component,
  628. SaAmfReadinessStateT readinessState)
  629. {
  630. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  631. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  632. /*
  633. * If component is local, don't request service from API
  634. */
  635. if (component->local != 1) {
  636. return;
  637. }
  638. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  639. return;
  640. }
  641. /*
  642. * this should be an assertion
  643. */
  644. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  645. component->conn_info->service != SOCKET_SERVICE_AMF) {
  646. return;
  647. }
  648. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  649. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  650. res_lib_amf_readinessstatesetcallback.header.error = SA_OK;
  651. res_lib_amf_readinessstatesetcallback.invocation =
  652. req_amf_invocation_create (
  653. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  654. component->conn_info);
  655. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  656. printf ("TODO readiness set callback\n");
  657. }
  658. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  659. &component->name, sizeof (SaNameT));
  660. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  661. component->newReadinessState = readinessState;
  662. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  663. libais_send_response (component->conn_info, &res_lib_amf_readinessstatesetcallback,
  664. sizeof (struct res_lib_amf_readinessstatesetcallback));
  665. }
  666. static void readiness_state_group_set (
  667. struct saAmfComponent *component,
  668. SaAmfReadinessStateT readinessState)
  669. {
  670. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  671. struct iovec iovecs[2];
  672. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  673. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  674. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  675. req_exec_amf_readinessstateset.readinessState = readinessState;
  676. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  677. getSaNameT (&component->name));
  678. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  679. iovecs[0].iov_base = (char *)&req_exec_amf_readinessstateset;
  680. iovecs[0].iov_len = sizeof (req_exec_amf_readinessstateset);
  681. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  682. }
  683. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  684. struct saAmfComponent *component)
  685. {
  686. struct saAmfUnit *unit;
  687. struct list_head *list;
  688. int serviceUnitEnabled;
  689. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  690. getSaNameT (&component->name));
  691. unit = component->saAmfUnit;
  692. for (serviceUnitEnabled = 1, list = unit->saAmfComponentHead.next;
  693. list != &unit->saAmfComponentHead;
  694. list = list->next) {
  695. component = list_entry (list,
  696. struct saAmfComponent, saAmfComponentList);
  697. if (component->registered == 0 ||
  698. component->probableCause) {
  699. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  700. serviceUnitEnabled = 0;
  701. break;
  702. }
  703. }
  704. if (serviceUnitEnabled == 1) {
  705. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  706. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  707. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  708. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  709. dsm (component);
  710. }
  711. }
  712. static void dsmDisabledUnlockedFailedComponent (
  713. struct saAmfComponent *component)
  714. {
  715. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  716. getSaNameT (&component->name));
  717. switch (component->enabledUnlockedState) {
  718. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  719. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  720. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  721. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  722. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  723. } else {
  724. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  725. }
  726. break;
  727. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  728. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  729. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  730. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  731. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  732. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  733. ha_state_group_set (component, SA_AMF_QUIESCED);
  734. } else {
  735. ha_state_api_set (component, SA_AMF_QUIESCED);
  736. }
  737. poll_timer_delete (aisexec_poll_handle,
  738. component->timer_healthcheck);
  739. component->timer_healthcheck = 0;
  740. break;
  741. default:
  742. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  743. break;
  744. }
  745. }
  746. static void dsmDisabledUnlockedFailed (
  747. struct saAmfComponent *component)
  748. {
  749. struct saAmfUnit *unit;
  750. struct list_head *list;
  751. unit = component->saAmfUnit;
  752. for (list = unit->saAmfComponentHead.next;
  753. list != &unit->saAmfComponentHead;
  754. list = list->next) {
  755. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  756. dsmDisabledUnlockedFailedComponent (component);
  757. }
  758. return;
  759. }
  760. static void dsmDisabledUnlockedQuiescedRequested (
  761. struct saAmfComponent *component)
  762. {
  763. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  764. dsm (component);
  765. }
  766. static void dsmDisabledUnlockedQuiescedCompleted (
  767. struct saAmfComponent *component)
  768. {
  769. struct saAmfUnit *unit;
  770. struct list_head *list;
  771. int serviceUnitQuiesced;
  772. unit = component->saAmfUnit;
  773. for (serviceUnitQuiesced = 1, list = unit->saAmfComponentHead.next;
  774. list != &unit->saAmfComponentHead;
  775. list = list->next) {
  776. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  777. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  778. if (component->currentHAState != SA_AMF_QUIESCED) {
  779. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  780. serviceUnitQuiesced = 0;
  781. break;
  782. }
  783. }
  784. }
  785. if (serviceUnitQuiesced == 1) {
  786. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  787. for (list = unit->saAmfComponentHead.next;
  788. list != &unit->saAmfComponentHead;
  789. list = list->next) {
  790. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  791. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  792. getSaNameT (&component->name));
  793. if ( component->probableCause == SA_AMF_NOT_RESPONDING ) {
  794. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  795. } else {
  796. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  797. }
  798. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  799. }
  800. }
  801. }
  802. static void dsmDisabledUnlockedOutOfServiceRequested (
  803. struct saAmfComponent *component)
  804. {
  805. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  806. dsm (component);
  807. }
  808. static void dsmDisabledUnlockedOutOfServiceCompleted (
  809. struct saAmfComponent *component)
  810. {
  811. struct saAmfUnit *unit;
  812. struct list_head *list;
  813. int serviceUnitOutOfService;
  814. struct saAmfGroup *group = 0;
  815. struct list_head *comp_list = 0;
  816. struct list_head *unit_list = 0;
  817. int serviceUnitInStandby = 0;
  818. int activeServiceUnits = 0;
  819. /*
  820. * Once all components of a service unit are out of service,
  821. * activate another service unit in standby
  822. */
  823. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  824. /*
  825. * Determine if all components have responded to going out of service
  826. */
  827. unit = component->saAmfUnit;
  828. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  829. list != &unit->saAmfComponentHead;
  830. list = list->next) {
  831. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  832. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  833. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  834. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  835. serviceUnitOutOfService = 0;
  836. break;
  837. }
  838. }
  839. if ( component->registered == 0 ) {
  840. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  841. }
  842. }
  843. group = unit->saAmfGroup;
  844. activeServiceUnits = activeServiceUnitsCount(group);
  845. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  846. return;
  847. }
  848. if (serviceUnitOutOfService == 1) {
  849. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  850. /*
  851. * Search all units
  852. */
  853. for (unit_list = group->saAmfUnitHead.next;
  854. unit_list != &group->saAmfUnitHead;
  855. unit_list = unit_list->next) {
  856. unit = list_entry (unit_list,
  857. struct saAmfUnit, saAmfUnitList);
  858. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  859. /*
  860. * Search all components
  861. */
  862. for (serviceUnitInStandby = 1,
  863. comp_list = unit->saAmfComponentHead.next;
  864. comp_list != &unit->saAmfComponentHead;
  865. comp_list = comp_list->next) {
  866. component = list_entry (comp_list,
  867. struct saAmfComponent, saAmfComponentList);
  868. if (component->currentHAState != SA_AMF_STANDBY) {
  869. serviceUnitInStandby = 0;
  870. break; /* for iteration of service unit components */
  871. }
  872. }
  873. if (serviceUnitInStandby) {
  874. break; /* for iteration of service group's service units */
  875. }
  876. }
  877. /*
  878. * All components in service unit are standby, activate standby service unit
  879. */
  880. if (serviceUnitInStandby) {
  881. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  882. for (list = unit->saAmfComponentHead.next;
  883. list != &unit->saAmfComponentHead;
  884. list = list->next) {
  885. component = list_entry (list,
  886. struct saAmfComponent, saAmfComponentList);
  887. ha_state_api_set (component, SA_AMF_ACTIVE);
  888. }
  889. } else {
  890. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  891. }
  892. }
  893. }
  894. static void dsmEnabledUnlockedInitial (
  895. struct saAmfComponent *component)
  896. {
  897. struct saAmfUnit *unit;
  898. struct list_head *list;
  899. unit = component->saAmfUnit;
  900. for (list = unit->saAmfComponentHead.next;
  901. list != &unit->saAmfComponentHead;
  902. list = list->next) {
  903. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  904. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  905. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  906. getSaNameT (&component->name));
  907. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  908. }
  909. }
  910. static void dsmEnabledUnlockedInServiceRequested (
  911. struct saAmfComponent *component)
  912. {
  913. struct saAmfUnit *unit;
  914. struct list_head *list;
  915. int in_service;
  916. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  917. unit = component->saAmfUnit;
  918. for (in_service = 1, list = unit->saAmfComponentHead.next;
  919. list != &unit->saAmfComponentHead;
  920. list = list->next) {
  921. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  922. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  923. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  924. in_service = 0;
  925. break;
  926. }
  927. }
  928. if (in_service) {
  929. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  930. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  931. dsm (component);
  932. }
  933. }
  934. static void dsmEnabledUnlockedInServiceCompleted (
  935. struct saAmfComponent *component)
  936. {
  937. struct saAmfUnit *unit;
  938. struct list_head *list;
  939. SaAmfHAStateT newHaState;
  940. int activeServiceUnits;
  941. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  942. unit = component->saAmfUnit;
  943. for (list = unit->saAmfComponentHead.next;
  944. list != &unit->saAmfComponentHead;
  945. list = list->next) {
  946. component = list_entry (list,
  947. struct saAmfComponent, saAmfComponentList);
  948. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  949. /*
  950. * Count number of active service units
  951. */
  952. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  953. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  954. newHaState = SA_AMF_ACTIVE;
  955. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  956. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  957. } else {
  958. newHaState = SA_AMF_STANDBY;
  959. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  960. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  961. }
  962. ha_state_api_set (component, newHaState);
  963. }
  964. }
  965. static void dsmEnabledUnlockedActiveRequested (
  966. struct saAmfComponent *component)
  967. {
  968. if (component->local == 1) {
  969. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  970. poll_timer_add (aisexec_poll_handle,
  971. component->healthcheckInterval,
  972. (void *)component->conn_info,
  973. timer_function_libamf_healthcheck,
  974. &component->timer_healthcheck);
  975. }
  976. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  977. }
  978. static void dsmEnabledUnlockedStandbyRequested (
  979. struct saAmfComponent *component)
  980. {
  981. if (component->local == 1) {
  982. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  983. poll_timer_add (aisexec_poll_handle,
  984. component->healthcheckInterval,
  985. (void *)component->conn_info,
  986. timer_function_libamf_healthcheck,
  987. &component->timer_healthcheck);
  988. }
  989. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  990. }
  991. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  992. struct saAmfComponent *component)
  993. {
  994. struct saAmfUnit *unit;
  995. struct list_head *list;
  996. unit = component->saAmfUnit;
  997. for (list = unit->saAmfComponentHead.next;
  998. list != &unit->saAmfComponentHead;
  999. list = list->next) {
  1000. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  1001. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  1002. getSaNameT (&component->name));
  1003. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  1004. }
  1005. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1006. dsm (component);
  1007. }
  1008. static void dsmSynchronizeStaus (
  1009. struct saAmfComponent *component)
  1010. {
  1011. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  1012. struct saAmfUnit *unit;
  1013. struct saAmfGroup *group;
  1014. struct list_head *list;
  1015. int activeServiceUnits;
  1016. if (component->currentReadinessState == component->newReadinessState) {
  1017. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1018. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1019. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1020. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  1021. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1022. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  1023. unit_status = AMF_ENABLED_UNLOCKED;
  1024. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  1025. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  1026. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1027. }
  1028. } else {
  1029. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1030. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  1031. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1032. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  1033. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1034. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  1035. unit_status = AMF_ENABLED_UNLOCKED;
  1036. } else {
  1037. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1038. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1039. }
  1040. }
  1041. if (component->currentHAState == component->newHAState) {
  1042. if (component->currentHAState == SA_AMF_ACTIVE) {
  1043. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1044. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  1045. unit_status = AMF_ENABLED_UNLOCKED;
  1046. } else if (component->currentHAState == SA_AMF_STANDBY) {
  1047. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1048. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  1049. unit_status = AMF_ENABLED_UNLOCKED;
  1050. } else {
  1051. /* depend on readiness status */
  1052. }
  1053. } else {
  1054. if (component->newHAState == SA_AMF_ACTIVE) {
  1055. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1056. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  1057. unit_status = AMF_ENABLED_UNLOCKED;
  1058. } else if (component->newHAState == SA_AMF_STANDBY) {
  1059. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1060. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  1061. unit_status = AMF_ENABLED_UNLOCKED;
  1062. } else {
  1063. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1064. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1065. }
  1066. }
  1067. /* Syncronize Operational AdministrativeState */
  1068. component->saAmfUnit->operationalAdministrativeState = unit_status;
  1069. unit = component->saAmfUnit;
  1070. group = unit->saAmfGroup;
  1071. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1072. activeServiceUnits = activeServiceUnitsCount(group);
  1073. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  1074. break;
  1075. }
  1076. if (component->currentHAState != SA_AMF_ACTIVE) {
  1077. continue;
  1078. }
  1079. ha_state_api_set (component, SA_AMF_STANDBY);
  1080. }
  1081. return;
  1082. }
  1083. static void dsmEnabledUnlocked (
  1084. struct saAmfComponent *component)
  1085. {
  1086. switch (component->enabledUnlockedState) {
  1087. case AMF_ENABLED_UNLOCKED_INITIAL:
  1088. dsmEnabledUnlockedInitial (component);
  1089. break;
  1090. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  1091. dsmEnabledUnlockedInServiceRequested (component);
  1092. break;
  1093. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  1094. dsmEnabledUnlockedInServiceCompleted (component);
  1095. break;
  1096. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  1097. dsmEnabledUnlockedActiveRequested (component);
  1098. break;
  1099. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  1100. /* noop - operational state */
  1101. break;
  1102. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  1103. dsmEnabledUnlockedStandbyRequested (component);
  1104. break;
  1105. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  1106. /* noop - operational state */
  1107. break;
  1108. default:
  1109. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  1110. }
  1111. }
  1112. static void dsmDisabledUnlocked (
  1113. struct saAmfComponent *component)
  1114. {
  1115. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  1116. getSaNameT (&component->name),
  1117. component->disabledUnlockedState);
  1118. switch (component->disabledUnlockedState) {
  1119. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  1120. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  1121. break;
  1122. case AMF_DISABLED_UNLOCKED_FAILED:
  1123. dsmDisabledUnlockedFailed (component);
  1124. break;
  1125. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  1126. dsmDisabledUnlockedQuiescedRequested (component);
  1127. break;
  1128. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  1129. dsmDisabledUnlockedQuiescedCompleted (component);
  1130. break;
  1131. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  1132. dsmDisabledUnlockedOutOfServiceRequested (component);
  1133. break;
  1134. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  1135. dsmDisabledUnlockedOutOfServiceCompleted (component);
  1136. break;
  1137. default:
  1138. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  1139. }
  1140. }
  1141. static void dsm (
  1142. struct saAmfComponent *component)
  1143. {
  1144. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  1145. switch (component->saAmfUnit->operationalAdministrativeState) {
  1146. case AMF_DISABLED_UNLOCKED:
  1147. dsmDisabledUnlocked (component);
  1148. break;
  1149. case AMF_ENABLED_UNLOCKED:
  1150. dsmEnabledUnlocked (component);
  1151. break;
  1152. /*
  1153. AMF_DISABLED_LOCKED,
  1154. AMF_ENABLED_STOPPING
  1155. */
  1156. default:
  1157. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  1158. }
  1159. }
  1160. #if 0
  1161. /*
  1162. * This is currently unused, but executes the componentterminatecallback
  1163. * callback in the AMF api.
  1164. */
  1165. void componentTerminate (struct conn_info *conn_info)
  1166. {
  1167. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  1168. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  1169. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  1170. res_lib_amf_componentterminatecallback.header.error = SA_OK;
  1171. res_lib_amf_componentterminatecallback.invocation =
  1172. req_amf_response_set (
  1173. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  1174. fd);
  1175. memcpy (&res_lib_amf_componentterminatecallback.compName,
  1176. &connections[fd].component->name, sizeof (SaNameT));
  1177. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1178. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  1179. libais_send_response (fd, &res_lib_amf_componentterminatecallback,
  1180. sizeof (struct res_lib_amf_componentterminatecallback));
  1181. }
  1182. #endif /* Not currently implemented */
  1183. void error_report (
  1184. struct saAmfComponent *component,
  1185. SaAmfProbableCauseT probableCause)
  1186. {
  1187. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1188. struct iovec iovecs[2];
  1189. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1190. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1191. req_exec_amf_errorreport.source.conn_info = 0;
  1192. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  1193. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  1194. &component->name,
  1195. sizeof (SaNameT));
  1196. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  1197. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  1198. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1199. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1200. }
  1201. int healthcheck_instance = 0;
  1202. void timer_function_libamf_healthcheck (void *data) {
  1203. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1204. memset (&res_lib_amf_healthcheckcallback,0,sizeof(res_lib_amf_healthcheckcallback));
  1205. struct conn_info *conn_info = (struct conn_info *)data;
  1206. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1207. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1208. res_lib_amf_healthcheckcallback.header.error = SA_OK;
  1209. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  1210. getSaNameT (&conn_info->component->name));
  1211. if (conn_info->component->healthcheck_outstanding == 1) {
  1212. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  1213. getSaNameT (&conn_info->component->name));
  1214. /*
  1215. * Report the error to the rest of the cluster using the normal state machine
  1216. */
  1217. error_report (conn_info->component, SA_AMF_NOT_RESPONDING);
  1218. conn_info->component->healthcheck_outstanding = 2;
  1219. } else
  1220. if (conn_info->component->healthcheck_outstanding == 0) {
  1221. conn_info->component->healthcheck_outstanding = 1;
  1222. /*
  1223. * Send healthcheck message
  1224. */
  1225. res_lib_amf_healthcheckcallback.invocation =
  1226. req_amf_invocation_create (
  1227. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1228. conn_info);
  1229. if (res_lib_amf_healthcheckcallback.invocation == -1) {
  1230. printf ("TODO healthcheck set callback\n");
  1231. }
  1232. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1233. &conn_info->component->name,
  1234. sizeof (SaNameT));
  1235. res_lib_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1236. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1237. res_lib_amf_healthcheckcallback.instance = healthcheck_instance++;
  1238. libais_send_response (conn_info,
  1239. &res_lib_amf_healthcheckcallback,
  1240. sizeof (struct res_lib_amf_healthcheckcallback));
  1241. poll_timer_add (aisexec_poll_handle,
  1242. conn_info->component->healthcheckInterval,
  1243. (void *)conn_info,
  1244. timer_function_libamf_healthcheck,
  1245. &conn_info->component->timer_healthcheck);
  1246. }
  1247. }
  1248. struct saAmfProtectionGroup *protectiongroup_find (
  1249. SaNameT *csiName)
  1250. {
  1251. struct list_head *AmfGroupList;
  1252. struct list_head *AmfProtectionGroupList;
  1253. struct saAmfGroup *saAmfGroup;
  1254. struct saAmfProtectionGroup *AmfProtectionGroup;
  1255. /*
  1256. * Search all groups
  1257. */
  1258. for (AmfGroupList = saAmfGroupHead.next;
  1259. AmfGroupList != &saAmfGroupHead;
  1260. AmfGroupList = AmfGroupList->next) {
  1261. saAmfGroup = list_entry (AmfGroupList,
  1262. struct saAmfGroup, saAmfGroupList);
  1263. /*
  1264. * Search all protection groups
  1265. */
  1266. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1267. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1268. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1269. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1270. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1271. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1272. return (AmfProtectionGroup);
  1273. }
  1274. }
  1275. }
  1276. return (0);
  1277. }
  1278. struct saAmfComponent *component_in_protectiongroup_find (
  1279. SaNameT *csiName,
  1280. SaNameT *compName)
  1281. {
  1282. struct list_head *AmfGroupList = 0;
  1283. struct list_head *AmfProtectionGroupList = 0;
  1284. struct list_head *AmfComponentList = 0;
  1285. struct saAmfGroup *saAmfGroup = 0;
  1286. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1287. struct saAmfComponent *AmfComponent = 0;
  1288. int found = 0;
  1289. /*
  1290. * Search all groups
  1291. */
  1292. for (AmfGroupList = saAmfGroupHead.next;
  1293. AmfGroupList != &saAmfGroupHead;
  1294. AmfGroupList = AmfGroupList->next) {
  1295. saAmfGroup = list_entry (AmfGroupList,
  1296. struct saAmfGroup, saAmfGroupList);
  1297. /*
  1298. * Search all protection groups
  1299. */
  1300. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1301. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1302. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1303. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1304. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1305. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1306. /*
  1307. * Search all components
  1308. */
  1309. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1310. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1311. AmfComponentList = AmfComponentList->next) {
  1312. AmfComponent = list_entry (AmfComponentList,
  1313. struct saAmfComponent, saAmfProtectionGroupList);
  1314. if (name_match (compName, &AmfComponent->name)) {
  1315. found = 1;
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. if (found) {
  1322. return (AmfComponent);
  1323. } else {
  1324. return (0);
  1325. }
  1326. }
  1327. DECLARE_LIST_INIT (library_notification_send_listhead);
  1328. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  1329. static void protectiongroup_notifications_send (
  1330. struct saAmfComponent *changedComponent,
  1331. SaAmfProtectionGroupChangesT changeToComponent)
  1332. {
  1333. int i;
  1334. struct conn_info *conn_info;
  1335. struct list_head *list;
  1336. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  1337. /*
  1338. * Iterate all tracked connections
  1339. */
  1340. for (list = library_notification_send_listhead.next;
  1341. list != &library_notification_send_listhead;
  1342. list = list->next) {
  1343. conn_info = list_entry (list, struct conn_info, conn_list);
  1344. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1345. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  1346. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  1347. != changedComponent->saAmfProtectionGroup->name.length) {
  1348. continue;
  1349. }
  1350. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  1351. changedComponent->saAmfProtectionGroup->name.value,
  1352. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  1353. continue;
  1354. }
  1355. protectiongroup_notification_send (conn_info,
  1356. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1357. changedComponent->saAmfProtectionGroup,
  1358. changedComponent,
  1359. changeToComponent,
  1360. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1361. } /* if track flags active */
  1362. } /* for all track entries */
  1363. } /* for all connection entries */
  1364. }
  1365. static int make_protectiongroup_notification_allcomponent (
  1366. struct saAmfComponent *changedComponent,
  1367. SaAmfProtectionGroupChangesT changeToComponent,
  1368. SaAmfProtectionGroupNotificationT **notification )
  1369. {
  1370. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1371. int notifyEntries = 0;
  1372. struct saAmfComponent *component;
  1373. struct list_head *AmfGroupList;
  1374. struct list_head *AmfUnitList;
  1375. struct list_head *AmfComponentList;
  1376. struct saAmfGroup *saAmfGroup;
  1377. struct saAmfUnit *AmfUnit;
  1378. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  1379. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  1380. /*
  1381. * Search all units
  1382. */
  1383. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  1384. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  1385. AmfUnitList = AmfUnitList->next) {
  1386. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  1387. /*
  1388. * Search all components
  1389. */
  1390. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  1391. AmfComponentList != &AmfUnit->saAmfComponentHead;
  1392. AmfComponentList = AmfComponentList->next) {
  1393. component = list_entry (AmfComponentList, struct saAmfComponent, saAmfComponentList);
  1394. protectionGroupNotification =
  1395. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1396. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1397. memset (&protectionGroupNotification[notifyEntries],
  1398. 0,sizeof (SaAmfProtectionGroupNotificationT));
  1399. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1400. &component->name, sizeof (SaNameT));
  1401. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1402. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1403. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1404. &component->currentHAState, sizeof (SaAmfHAStateT));
  1405. if (component == changedComponent) {
  1406. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1407. } else {
  1408. protectionGroupNotification[notifyEntries].change
  1409. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1410. }
  1411. notifyEntries += 1;
  1412. }
  1413. }
  1414. }
  1415. if (notifyEntries) {
  1416. *notification = protectionGroupNotification;
  1417. }
  1418. return (notifyEntries);
  1419. }
  1420. static int make_protectiongroup_notification (
  1421. struct saAmfProtectionGroup *amfProtectionGroup,
  1422. struct saAmfComponent *changedComponent,
  1423. SaAmfProtectionGroupChangesT changeToComponent,
  1424. SaAmfProtectionGroupNotificationT **notification )
  1425. {
  1426. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1427. int notifyEntries = 0;
  1428. struct saAmfComponent *component;
  1429. struct list_head *componentList;
  1430. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1431. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  1432. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1433. componentList != &amfProtectionGroup->saAmfMembersHead;
  1434. componentList = componentList->next) {
  1435. component = list_entry (componentList, struct saAmfComponent, saAmfProtectionGroupList);
  1436. protectionGroupNotification =
  1437. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1438. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1439. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  1440. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1441. &component->name, sizeof (SaNameT));
  1442. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1443. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1444. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1445. &component->currentHAState, sizeof (SaAmfHAStateT));
  1446. if (component == changedComponent) {
  1447. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1448. } else {
  1449. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1450. }
  1451. notifyEntries += 1;
  1452. } /* for */
  1453. if (notifyEntries) {
  1454. *notification = protectionGroupNotification;
  1455. }
  1456. return (notifyEntries);
  1457. }
  1458. static void protectiongroup_notification_send (struct conn_info *conn_info,
  1459. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1460. struct saAmfProtectionGroup *amfProtectionGroup,
  1461. struct saAmfComponent *changedComponent,
  1462. SaAmfProtectionGroupChangesT changeToComponent,
  1463. SaUint8T trackFlags)
  1464. {
  1465. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1466. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1467. int notifyEntries;
  1468. /*
  1469. * Step through all components and generate protection group list for csi
  1470. */
  1471. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  1472. if ( trackFlags == SA_TRACK_CHANGES ) {
  1473. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  1474. changeToComponent, &protectionGroupNotification);
  1475. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  1476. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  1477. changedComponent, changeToComponent, &protectionGroupNotification );
  1478. }else{
  1479. notifyEntries = 0;
  1480. }
  1481. /*
  1482. * Send track callback
  1483. */
  1484. if (notifyEntries) {
  1485. res_lib_amf_protectiongrouptrackcallback.header.size =
  1486. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  1487. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1488. res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1489. res_lib_amf_protectiongrouptrackcallback.header.error = SA_OK;
  1490. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1491. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1492. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1493. &amfProtectionGroup->name, sizeof (SaNameT));
  1494. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1495. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackcallback,
  1496. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1497. libais_send_response (conn_info, protectionGroupNotification,
  1498. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1499. mempool_free (protectionGroupNotification);
  1500. }
  1501. }
  1502. /*
  1503. * The response handler for readiness state set callback
  1504. */
  1505. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  1506. struct req_amf_response *req_amf_response)
  1507. {
  1508. if (req_amf_response->error == SA_OK && conn_info->component) {
  1509. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  1510. getSaNameT (&conn_info->component->name));
  1511. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  1512. }
  1513. }
  1514. /*
  1515. * iterate service unit components
  1516. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1517. */
  1518. static void response_handler_csisetcallback (struct conn_info *conn_info,
  1519. struct req_amf_response *req_amf_response)
  1520. {
  1521. if (req_amf_response->error == SA_OK && conn_info->component) {
  1522. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  1523. }
  1524. }
  1525. static int amf_exec_init_fn (void)
  1526. {
  1527. #ifdef TODO
  1528. int res;
  1529. res = totempg_recovery_plug_create (&amf_recovery_plug_handle);
  1530. if (res != 0) {
  1531. log_printf(LOG_LEVEL_ERROR,
  1532. "Could not create recovery plug for amf service.\n");
  1533. return (-1);
  1534. }
  1535. #endif
  1536. return (0);
  1537. }
  1538. void amf_confchg_njoin (struct saAmfComponent *component ,void *data)
  1539. {
  1540. if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) {
  1541. return;
  1542. }
  1543. component_register (component);
  1544. return;
  1545. }
  1546. void amf_confchg_nleave (struct saAmfComponent *component ,void *data)
  1547. {
  1548. struct in_addr *source_addr = (struct in_addr *)data;
  1549. struct saAmfUnit *unit;
  1550. struct list_head *list;
  1551. struct saAmfComponent *leave_component = NULL;
  1552. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  1553. if (component->source_addr.s_addr != source_addr->s_addr) {
  1554. return;
  1555. }
  1556. if (!component->registered) {
  1557. return;
  1558. }
  1559. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  1560. /* Component status Initialize */
  1561. unit = component->saAmfUnit;
  1562. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1563. component = list_entry (list,
  1564. struct saAmfComponent, saAmfComponentList);
  1565. if (component->source_addr.s_addr != source_addr->s_addr) {
  1566. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  1567. continue;
  1568. }
  1569. component->registered = 0;
  1570. component->local = 0;
  1571. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1572. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1573. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1574. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1575. component->newHAState = SA_AMF_QUIESCED;
  1576. component->currentHAState = SA_AMF_QUIESCED;
  1577. component->source_addr.s_addr = 0;
  1578. leave_component = component;
  1579. }
  1580. if (leave_component == NULL) {
  1581. return;
  1582. }
  1583. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1584. leave_component->disabledUnlockedState = disablestate;
  1585. dsm (leave_component);
  1586. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1587. return;
  1588. }
  1589. static int amf_confchg_fn (
  1590. enum totem_configuration_type configuration_type,
  1591. struct in_addr *member_list, int member_list_entries,
  1592. struct in_addr *left_list, int left_list_entries,
  1593. struct in_addr *joined_list, int joined_list_entries,
  1594. struct memb_ring_id *ring_id)
  1595. {
  1596. int i;
  1597. 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);
  1598. recovery = 1;
  1599. /*
  1600. * If node join, component register
  1601. */
  1602. if ( joined_list_entries > 0 ) {
  1603. enumerate_components (amf_confchg_njoin, NULL);
  1604. }
  1605. /*
  1606. * If node leave, component unregister
  1607. */
  1608. for (i = 0; i<left_list_entries ; i++) {
  1609. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  1610. }
  1611. #ifdef TODO
  1612. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  1613. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  1614. recovery = 0;
  1615. }
  1616. #endif
  1617. return (0);
  1618. }
  1619. int amf_exit_fn (struct conn_info *conn_info)
  1620. {
  1621. /*
  1622. * Unregister all components registered to this file descriptor
  1623. */
  1624. if (conn_info->service == SOCKET_SERVICE_AMF) {
  1625. component_unregister (conn_info->component);
  1626. if (conn_info->component && conn_info->component->timer_healthcheck) {
  1627. poll_timer_delete (aisexec_poll_handle,
  1628. conn_info->component->timer_healthcheck);
  1629. conn_info->component->timer_healthcheck = 0;
  1630. }
  1631. if (conn_info->ais_ci.u.libamf_ci.tracks) {
  1632. mempool_free (conn_info->ais_ci.u.libamf_ci.tracks);
  1633. conn_info->ais_ci.u.libamf_ci.tracks = 0;
  1634. list_del (&conn_info->conn_list);
  1635. }
  1636. }
  1637. return (0);
  1638. }
  1639. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1640. {
  1641. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1642. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1643. struct saAmfComponent *component;
  1644. struct saAmfComponent *amfProxyComponent;
  1645. SaErrorT error;
  1646. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  1647. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1648. /*
  1649. * Determine if proxy isn't registered
  1650. */
  1651. error = SA_OK;
  1652. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1653. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1654. /*
  1655. * If a node is joining menber ship ,Component States Synchronize
  1656. */
  1657. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  1658. amf_synchronize (message, source_addr);
  1659. return (0);
  1660. }
  1661. /*
  1662. * If component not in configuration files, return error
  1663. */
  1664. if (component == 0) {
  1665. error = SA_ERR_NOT_EXIST;
  1666. }
  1667. /*
  1668. * If proxy doesn't exist and isn't registered, return error
  1669. */
  1670. if ((amfProxyComponent == 0 &&
  1671. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1672. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1673. error = SA_ERR_NOT_EXIST;
  1674. }
  1675. /*
  1676. * If component already registered, return error
  1677. */
  1678. if (error == SA_OK) {
  1679. if (component->registered) {
  1680. error = SA_ERR_EXIST;
  1681. }
  1682. }
  1683. /*
  1684. * Finally register component and setup links for proxy if
  1685. * proxy present
  1686. */
  1687. if (error == SA_OK) {
  1688. component->local = 0;
  1689. component->registered = 1;
  1690. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1691. component->source_addr = source_addr;
  1692. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1693. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1694. component->currentHAState = 0;
  1695. component->newHAState = 0;
  1696. component->probableCause = 0;
  1697. component->enabledUnlockedState = 0;
  1698. component->disabledUnlockedState = 0;
  1699. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1700. component->saAmfProxyComponent = amfProxyComponent;
  1701. }
  1702. }
  1703. /*
  1704. * If this node originated the request to the cluster, respond back
  1705. * to the AMF library
  1706. */
  1707. if (message_source_is_local(&req_exec_amf_componentregister->source)) {
  1708. if (error == SA_OK) {
  1709. component->local = 1;
  1710. req_exec_amf_componentregister->source.conn_info->component = component;
  1711. }
  1712. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  1713. req_exec_amf_componentregister->source.conn_info->fd);
  1714. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1715. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1716. res_lib_amf_componentregister.header.error = error;
  1717. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  1718. &res_lib_amf_componentregister,
  1719. sizeof (struct res_lib_amf_componentregister));
  1720. }
  1721. /*
  1722. * If no error on registration, determine if we should enter new state
  1723. */
  1724. if (error == SA_OK) {
  1725. dsm (component);
  1726. }
  1727. return (0);
  1728. }
  1729. static void amf_synchronize (void *message, struct in_addr source_addr)
  1730. {
  1731. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1732. struct saAmfComponent *component;
  1733. struct saAmfComponent *amfProxyComponent;
  1734. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  1735. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1736. /* Find Component */
  1737. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1738. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1739. /* If this processor is component owner */
  1740. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  1741. /* No Operation */
  1742. return;
  1743. }
  1744. /* If this isn't synchronizing target processor */
  1745. if (!(component->local == 0 && component->registered == 0)){
  1746. /* No Operation */
  1747. return;
  1748. }
  1749. /* Synchronize Status */
  1750. component->local = 0;
  1751. component->registered = 1;
  1752. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1753. component->source_addr = source_addr;
  1754. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1755. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1756. component->currentHAState = SA_AMF_QUIESCED;
  1757. component->newHAState = SA_AMF_QUIESCED;
  1758. component->probableCause = 0;
  1759. component->enabledUnlockedState = 0;
  1760. component->disabledUnlockedState = 0;
  1761. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  1762. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  1763. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  1764. component->newHAState = req_exec_amf_componentregister->newHAState;
  1765. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1766. component->saAmfProxyComponent = amfProxyComponent;
  1767. }
  1768. /*
  1769. * Determine if we should enter new state
  1770. */
  1771. dsmSynchronizeStaus (component);
  1772. return;
  1773. }
  1774. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1775. {
  1776. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1777. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1778. struct saAmfComponent *component;
  1779. struct saAmfComponent *amfProxyComponent;
  1780. SaErrorT error;
  1781. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  1782. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1783. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1784. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1785. /*
  1786. * Check for proxy and component not existing in system
  1787. */
  1788. error = SA_OK;
  1789. if (component == 0) {
  1790. error = SA_ERR_NOT_EXIST;
  1791. }
  1792. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1793. if (amfProxyComponent) {
  1794. if (amfProxyComponent->registered == 0) {
  1795. error = SA_ERR_NOT_EXIST;
  1796. }
  1797. } else {
  1798. error = SA_ERR_NOT_EXIST;
  1799. }
  1800. }
  1801. /*
  1802. * If there is a proxycompname, make sure it is the proxy
  1803. * of compName
  1804. */
  1805. if (error == SA_OK && amfProxyComponent) {
  1806. if (component->saAmfProxyComponent != amfProxyComponent) {
  1807. error = SA_ERR_BAD_OPERATION;
  1808. }
  1809. }
  1810. /*
  1811. * Finally unregister the component
  1812. */
  1813. if (error == SA_OK) {
  1814. component->registered = 0;
  1815. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1816. }
  1817. /*
  1818. * If this node originated the request to the cluster, respond back
  1819. * to the AMF library
  1820. */
  1821. if (message_source_is_local (&req_exec_amf_componentunregister->source)) {
  1822. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1823. req_exec_amf_componentunregister->source.conn_info->fd);
  1824. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1825. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1826. res_lib_amf_componentunregister.header.error = error;
  1827. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  1828. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1829. }
  1830. return (0);
  1831. }
  1832. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  1833. {
  1834. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1835. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1836. struct saAmfComponent *component;
  1837. SaErrorT error = SA_ERR_BAD_OPERATION;
  1838. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorReport for %s\n",
  1839. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1840. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1841. if (component && component->registered) {
  1842. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1843. /*
  1844. * One registered component left, so transition
  1845. * SU to failed operational state
  1846. */
  1847. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1848. error = SA_OK;
  1849. }
  1850. /*
  1851. * If this node originated the request to the cluster, respond back
  1852. * to the AMF library
  1853. */
  1854. if (message_source_is_local (&req_exec_amf_errorreport->source)) {
  1855. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1856. req_exec_amf_errorreport->source.conn_info->fd);
  1857. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1858. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1859. res_lib_amf_errorreport.header.error = error;
  1860. libais_send_response (req_exec_amf_errorreport->source.conn_info,
  1861. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1862. }
  1863. return (0);
  1864. }
  1865. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required)
  1866. {
  1867. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1868. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1869. struct saAmfComponent *component;
  1870. SaErrorT error = SA_ERR_BAD_OPERATION;
  1871. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  1872. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1873. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1874. if (component && component->registered) {
  1875. /*
  1876. * Mark component in service if its a AMF service
  1877. * connected to this aisexec
  1878. */
  1879. if (component->probableCause) {
  1880. component->probableCause = 0;
  1881. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1882. dsm (component);
  1883. }
  1884. error = SA_OK;
  1885. }
  1886. /*
  1887. * If this node originated the request to the cluster, respond back
  1888. * to the AMF library
  1889. */
  1890. if (message_source_is_local (&req_exec_amf_errorcancelall->source)) {
  1891. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1892. req_exec_amf_errorcancelall->source.conn_info->fd);
  1893. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1894. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1895. res_lib_amf_errorcancelall.header.error = error;
  1896. libais_send_response (req_exec_amf_errorcancelall->source.conn_info,
  1897. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1898. }
  1899. return (0);
  1900. }
  1901. /*
  1902. * If receiving this message from another cluster node, another cluster node
  1903. * has selected a readiness state for a component connected to _that_ cluster
  1904. * node. That cluster node API has verified the readiness state, so its time to let
  1905. * the rest of the cluster nodes know about the readiness state change.
  1906. */
  1907. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1908. {
  1909. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1910. struct saAmfComponent *component;
  1911. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1912. if (component) {
  1913. log_printf (LOG_LEVEL_FROM_GMI,
  1914. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  1915. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  1916. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1917. component->newReadinessState = component->currentReadinessState;
  1918. dsm (component);
  1919. }
  1920. return (0);
  1921. }
  1922. /*
  1923. * If receiving this message from another cluster node, another cluster node
  1924. * has selected a ha state for a component connected to _that_ cluster
  1925. * node. That cluster node API has verified the ha state, so its time to let
  1926. * the rest of the cluster nodes know about the HA state change.
  1927. */
  1928. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1929. {
  1930. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1931. struct saAmfComponent *component;
  1932. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  1933. component = findComponent (&req_exec_amf_hastateset->compName);
  1934. if (!component) {
  1935. return (0);
  1936. }
  1937. log_printf (LOG_LEVEL_FROM_GMI,
  1938. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  1939. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  1940. if ( component->currentHAState == 0 ) {
  1941. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  1942. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  1943. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  1944. }
  1945. } else {
  1946. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  1947. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1948. }
  1949. }
  1950. component->currentHAState = req_exec_amf_hastateset->haState;
  1951. component->newHAState = component->currentHAState;
  1952. dsm (component);
  1953. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  1954. protectiongroup_notifications_send (component, changeToComponent);
  1955. }
  1956. return (0);
  1957. }
  1958. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message)
  1959. {
  1960. struct res_lib_init res_lib_init;
  1961. SaErrorT error = SA_ERR_SECURITY;
  1962. log_printf (LOG_LEVEL_DEBUG, "Got AMF request to initalize availability management framework service.\n");
  1963. if (conn_info->authenticated) {
  1964. conn_info->service = SOCKET_SERVICE_AMF;
  1965. error = SA_OK;
  1966. }
  1967. res_lib_init.header.size = sizeof (struct res_lib_init);
  1968. res_lib_init.header.id = MESSAGE_RES_INIT;
  1969. res_lib_init.header.error = error;
  1970. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1971. list_init (&conn_info->conn_list);
  1972. if (conn_info->authenticated) {
  1973. return (0);
  1974. }
  1975. return (-1);
  1976. }
  1977. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  1978. {
  1979. struct res_lib_activatepoll res_lib_activatepoll;
  1980. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_activatepoll()\n");
  1981. memset (&res_lib_activatepoll,0,sizeof(res_lib_activatepoll));
  1982. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  1983. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  1984. libais_send_response (conn_info, &res_lib_activatepoll, sizeof (struct res_lib_activatepoll));
  1985. return (0);
  1986. }
  1987. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message)
  1988. {
  1989. struct req_amf_componentregister *req_lib_amf_componentregister = (struct req_amf_componentregister *)message;
  1990. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1991. struct iovec iovecs[2];
  1992. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  1993. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1994. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1995. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  1996. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  1997. req_lib_amf_componentregister,
  1998. sizeof (struct req_lib_amf_componentregister));
  1999. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  2000. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  2001. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2002. return (0);
  2003. }
  2004. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  2005. {
  2006. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2007. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2008. struct iovec iovecs[2];
  2009. struct saAmfComponent *component;
  2010. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  2011. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2012. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  2013. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2014. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2015. req_lib_amf_componentunregister,
  2016. sizeof (struct req_lib_amf_componentunregister));
  2017. component = findComponent (&req_lib_amf_componentunregister->compName);
  2018. if (component && component->registered && component->local) {
  2019. component->probableCause = SA_AMF_NOT_RESPONDING;
  2020. }
  2021. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  2022. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  2023. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2024. return (0);
  2025. }
  2026. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  2027. {
  2028. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  2029. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  2030. struct saAmfComponent *component;
  2031. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_readinessstateget()\n");
  2032. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  2033. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  2034. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  2035. component = findComponent (&req_amf_readinessstateget->compName);
  2036. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  2037. if (component) {
  2038. memcpy (&res_lib_amf_readinessstateget.readinessState,
  2039. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  2040. res_lib_amf_readinessstateget.header.error = SA_OK;
  2041. }
  2042. libais_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  2043. return (0);
  2044. }
  2045. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message)
  2046. {
  2047. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  2048. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2049. struct saAmfComponent *component;
  2050. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_hastateget()\n");
  2051. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2052. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2053. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2054. component = component_in_protectiongroup_find (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  2055. if (component) {
  2056. memcpy (&res_lib_amf_hastateget.haState,
  2057. &component->currentHAState, sizeof (SaAmfHAStateT));
  2058. res_lib_amf_hastateget.header.error = SA_OK;
  2059. }
  2060. libais_send_response (conn_info, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2061. return (0);
  2062. }
  2063. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  2064. {
  2065. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  2066. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2067. struct libamf_ci_trackentry *track = 0;
  2068. int i;
  2069. struct saAmfProtectionGroup *amfProtectionGroup;
  2070. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  2071. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  2072. if (amfProtectionGroup) {
  2073. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  2074. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2075. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2076. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2077. break;
  2078. }
  2079. }
  2080. if (track == 0) {
  2081. grow_amf_track_table (conn_info, 1);
  2082. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2083. }
  2084. track->active = 1;
  2085. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  2086. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  2087. memcpy (&track->csiName,
  2088. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2089. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2090. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2091. /*
  2092. * If SA_TRACK_CURRENT is specified, write out all current connections
  2093. */
  2094. } else {
  2095. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2096. }
  2097. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2098. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2099. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2100. if (amfProtectionGroup) {
  2101. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  2102. }
  2103. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  2104. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2105. if (amfProtectionGroup &&
  2106. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2107. protectiongroup_notification_send (conn_info,
  2108. track->notificationBufferAddress,
  2109. amfProtectionGroup,
  2110. 0,
  2111. 0,
  2112. SA_TRACK_CHANGES_ONLY);
  2113. track->trackFlags &= ~SA_TRACK_CURRENT;
  2114. }
  2115. return (0);
  2116. }
  2117. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  2118. {
  2119. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  2120. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2121. struct libamf_ci_trackentry *track = 0;
  2122. int i;
  2123. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  2124. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2125. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  2126. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2127. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2128. }
  2129. }
  2130. if (track) {
  2131. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  2132. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2133. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2134. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2135. list_del (&conn_info->conn_list);
  2136. }
  2137. }
  2138. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2139. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2140. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2141. if (track) {
  2142. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  2143. }
  2144. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  2145. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2146. return (0);
  2147. }
  2148. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  2149. {
  2150. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  2151. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  2152. struct iovec iovecs[2];
  2153. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  2154. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  2155. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  2156. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  2157. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  2158. req_lib_amf_errorreport,
  2159. sizeof (struct req_lib_amf_errorreport));
  2160. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  2161. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  2162. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  2163. // iovecs[1].iov_base = (char *)&req_lib_amf_errorreport;
  2164. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  2165. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2166. return (0);
  2167. }
  2168. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  2169. {
  2170. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  2171. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  2172. struct iovec iovecs[2];
  2173. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  2174. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  2175. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  2176. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  2177. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  2178. req_lib_amf_errorcancelall,
  2179. sizeof (struct req_lib_amf_errorcancelall));
  2180. iovecs[0].iov_base = (char *)&req_exec_amf_errorcancelall;
  2181. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  2182. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  2183. // iovecs[1].iov_base = (char *)&req_lib_amf_errorcancelall;
  2184. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  2185. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2186. return (0);
  2187. }
  2188. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  2189. void *message)
  2190. {
  2191. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  2192. struct conn_info *inv_conn_info;
  2193. int interface;
  2194. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_stoppingcomplete()\n");
  2195. req_amf_invocation_get_and_destroy (req_amf_stoppingcomplete->invocation,
  2196. &interface, &inv_conn_info);
  2197. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  2198. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  2199. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  2200. return (0);
  2201. }
  2202. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  2203. struct req_amf_response *req_amf_response) {
  2204. if (req_amf_response->error == SA_OK) {
  2205. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  2206. conn_info->component->healthcheck_outstanding = 0;
  2207. }
  2208. }
  2209. static int message_handler_req_amf_response (struct conn_info *conn_info_nouse, void *message)
  2210. {
  2211. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  2212. struct conn_info *conn_info;
  2213. int interface;
  2214. int res;
  2215. log_printf (LOG_LEVEL_DEBUG, "Handle : message_handler_req_amf_response()\n");
  2216. res = req_amf_invocation_get_and_destroy (req_amf_response->invocation,
  2217. &interface, &conn_info);
  2218. log_printf (LOG_LEVEL_DEBUG, "handling response connection %p interface %x\n", conn_info, interface);
  2219. switch (interface) {
  2220. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  2221. response_handler_healthcheckcallback (conn_info, req_amf_response);
  2222. break;
  2223. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  2224. response_handler_readinessstatesetcallback (conn_info, req_amf_response);
  2225. break;
  2226. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  2227. response_handler_csisetcallback (conn_info, req_amf_response);
  2228. break;
  2229. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  2230. break;
  2231. default:
  2232. // TODO
  2233. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  2234. break;
  2235. }
  2236. return (0);
  2237. }
  2238. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  2239. {
  2240. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  2241. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  2242. struct saAmfComponent *component;
  2243. SaErrorT error = SA_OK;
  2244. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentcapabilitymodelget()\n");
  2245. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  2246. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  2247. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  2248. if (component && component->registered) {
  2249. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  2250. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  2251. } else {
  2252. error = SA_ERR_NOT_EXIST;
  2253. }
  2254. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  2255. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  2256. res_lib_amf_componentcapabilitymodelget.header.error = error;
  2257. libais_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  2258. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  2259. return (0);
  2260. }
  2261. static char disabled_unlocked_state_text[6][64] = {
  2262. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  2263. "AMF_DISABLED_UNLOCKED_FAILED",
  2264. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  2265. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  2266. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  2267. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  2268. };
  2269. static char *disabledunlockedstate_ntoa (int state)
  2270. {
  2271. static char str[64];
  2272. if (state >= 0 && state < 6) {
  2273. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  2274. }else{
  2275. sprintf (str, "Unknown(%d)", state);
  2276. }
  2277. return (str);
  2278. }
  2279. static char enabled_unlocked_state_text[7][64] = {
  2280. "AMF_ENABLED_UNLOCKED_INITIAL",
  2281. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  2282. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  2283. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  2284. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  2285. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  2286. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  2287. };
  2288. static char *enabledunlockedstate_ntoa (int state)
  2289. {
  2290. static char str[64];
  2291. if (state >= 0 && state < 7) {
  2292. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  2293. }else{
  2294. sprintf (str, "Unknown(%d)", state);
  2295. }
  2296. return (str);
  2297. }
  2298. static char readiness_state_text[4][32] = {
  2299. "Unknown",
  2300. "SA_AMF_OUT_OF_SERVICE",
  2301. "SA_AMF_IN_SERVICE",
  2302. "SA_AMF_QUIESCED",
  2303. };
  2304. static char *readinessstate_ntoa (int state)
  2305. {
  2306. static char str[32];
  2307. if (state > 0 && state < 4) {
  2308. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  2309. }else{
  2310. sprintf (str, "Unknown(%d)", state);
  2311. }
  2312. return (str);
  2313. }
  2314. static char ha_state_text[4][32] = {
  2315. "Unknown",
  2316. "SA_AMF_ACTIVE",
  2317. "SA_AMF_STANDBY",
  2318. "SA_AMF_QUIESCED",
  2319. };
  2320. static char *hastate_ntoa (SaAmfHAStateT state)
  2321. {
  2322. static char str[32];
  2323. if (state > 0 && state < 4) {
  2324. sprintf (str, "%s(%d)", ha_state_text[state], state);
  2325. }else{
  2326. sprintf (str, "Unknown(%d)", state);
  2327. }
  2328. return (str);
  2329. }
  2330. static void amf_dump_comp (struct saAmfComponent *component ,void *data)
  2331. {
  2332. char name[64];
  2333. int level = LOG_LEVEL_NOTICE;
  2334. data = NULL;
  2335. log_printf (level, "----------------\n" );
  2336. log_printf (level, "registered = %d\n" ,component->registered);
  2337. log_printf (level, "local = %d\n" ,component->local );
  2338. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  2339. memset (name, 0 , sizeof(name));
  2340. memcpy (name, component->name.value, component->name.length);
  2341. log_printf (level, "name = %s\n" ,name );
  2342. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  2343. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  2344. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  2345. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  2346. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  2347. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  2348. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  2349. }
  2350. void amf_dump ( )
  2351. {
  2352. enumerate_components (amf_dump_comp, NULL);
  2353. fflush (stderr);
  2354. return;
  2355. }