amf.c 93 KB

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