amf.c 94 KB

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