amfsg.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  1. /** @file amfsg.c
  2. *
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt, Anders Eriksson, Lars Holm
  8. * - Introduced AMF B.02 information model
  9. * - Use DN in API and multicast messages
  10. * - (Re-)Introduction of event based multicast messages
  11. * - Refactoring of code into several AMF files
  12. * - Component/SU restart, SU failover
  13. * - Constructors/destructors
  14. * - Serializers/deserializers
  15. *
  16. * All rights reserved.
  17. *
  18. *
  19. * This software licensed under BSD license, the text of which follows:
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright notice,
  25. * this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright notice,
  27. * this list of conditions and the following disclaimer in the documentation
  28. * and/or other materials provided with the distribution.
  29. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  30. * contributors may be used to endorse or promote products derived from this
  31. * software without specific prior written permission.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  37. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  38. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  40. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  41. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  43. * THE POSSIBILITY OF SUCH DAMAGE.
  44. *
  45. * AMF Service Group Class Implementation
  46. *
  47. * This file contains functions for handling AMF-service groups(SGs). It can be
  48. * viewed as the implementation of the AMF Service Group class (called SG)
  49. * as described in SAI-Overview-B.02.01. The SA Forum specification
  50. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  51. * and is referred to as 'the spec' below.
  52. *
  53. * The functions in this file are responsible for:
  54. * -on request start the service group by instantiating the contained SUs
  55. * -on request assign the service instances it protects to the in-service
  56. * service units it contains respecting as many as possible of the configured
  57. * requirements for the group
  58. * -create and delete an SI-assignment object for each relation between
  59. * an SI and an SU
  60. * -order each contained SU to create and delete CSI-assignments
  61. * -request the Service Instance class (SI) to execute the transfer of the
  62. * HA-state set/remove requests to each component involved
  63. * -fully control the execution of component failover and SU failover
  64. * -on request control the execution of the initial steps of node switchover
  65. * and node failover
  66. * -fully handle the auto adjust procedure
  67. *
  68. * Currently only the 'n+m' redundancy model is implemented. It is the
  69. * ambition to identify n+m specific variables and functions and add the suffix
  70. * '_nplusm' to them so that they can be easily recognized.
  71. *
  72. * When SG is requested to assign workload to all SUs or all SUs hosted on
  73. * a specific node, a procedure containing several steps is executed:
  74. * <1> An algorithm is executed which assigns SIs to SUs respecting the rules
  75. * that has been configured for SG. The algorithm also has to consider
  76. * if assignments between som SIs and SUs already exist. The scope of this
  77. * algorithm is to create SI-assignments and set up requested HA-state for
  78. * each assignment but not to transfer those HA-states to the components.
  79. * <2> All SI-assignments with a requested HA state == ACTIVE are transferred
  80. * to the components concerned before any STANDBY assignments are
  81. * transferred. All components have to acknowledge the setting of the
  82. * ACTIVE HA state before the transfer of any STANDBY assignment is
  83. * initiated.
  84. * <3> All active assignments can not be transferred at the same time to the
  85. * different components because the rules for dependencies between SI and
  86. * SI cluster wide and CSI and CSI within one SI, has to be respected.
  87. *
  88. * SG is fully responsible for step <1> but not fully responsible for handling
  89. * step <2> and <3>. However, SG uses an attribute called 'dependency level'
  90. * when requsted to assign workload. This parameter refers to an integer that
  91. * has been calculated initially for each SI. The 'dependency level' indicates
  92. * to which extent an SI depends on other SIs such that an SI that depends on
  93. * no other SI is on dependecy_level == 1, an SI that depends only on an SI on
  94. * dependency_level == 1 is on dependency-level == 2.
  95. * An SI that depends on several SIs gets a
  96. * dependency_level that is one unit higher than the SI with the highest
  97. * dependency_level it depends on. When SG is requested to assign the workload
  98. * on a certain dependency level, it requests all SI objects on that level to
  99. * activate (all) SI-assignments that during step <1> has been requested to
  100. * assume the active HA state.
  101. *
  102. * SG contains the following state machines:
  103. * - administrative state machine (ADSM) (NOT IN THIS RELEASE)
  104. * - availability control state machine (ACSM)
  105. *
  106. * The availability control state machine contains three states and one of them
  107. * is composite. Being a composite state means that it contains substates.
  108. * The states are:
  109. * - IDLE (non composite state)
  110. * - INSTANTIATING_SERVICE_UNITS
  111. * - MANAGING_SG (composite state)
  112. * MANAGING_SG is entered at several different events which has in common
  113. * the need to set up or change the assignment of SIs to SUs. Only one such
  114. * event can be handled at the time. If new events occur while one event is
  115. * being handled then the new event is saved and will be handled after the
  116. * handling of the first event is ready (return to IDLE state has been done).
  117. * MANAGING_SG handles the following events:
  118. * - start (requests SG to order SU to instantiate all SUs in SG and waits
  119. * for SU to indicate presence state change reports from the SUs and
  120. * finally responds 'started' to the requester)
  121. * - assign_si (requests SG to assign SIs to SUs according to pre-configured
  122. * rules (if not already done) and transfer the HA state of
  123. * the SIs on the requested SI dependency level. Then SG waits for
  124. * confirmation that the HA state has been succesfully set and
  125. * finally responds 'assigned' to the reqeuster)
  126. * - auto_adjust (this event indicates that the auto-adjust probation timer has
  127. * expired and that SG should evaluate current assignments of
  128. * SIs to SUs and if needed remove current assignments and
  129. * create new according to what is specified in paragraph
  130. * 3.7.1.2)
  131. * - failover_comp (requests SG to failover a specific component according to
  132. * the procedure described in paragraph 3.12.1.3)
  133. * - failover_su (requests SG to failover a specific SU according to the
  134. * procedure described in paragraph 3.12.1.3 and 3.12.1.4)
  135. * - switchover_node (requests SG to execute the recovery actions described
  136. * in 3.12.1.3 and respond to the requester when recovery
  137. * is completed)
  138. * - failover_node (requests SG to execute the recovery actions described
  139. * in 3.12.1.3 and respond to the requester when recovery is
  140. * completed)
  141. *
  142. * 1. SG Availability Control State Machine
  143. * ==========================================
  144. *
  145. * 1.1 State Transition Table
  146. *
  147. * State: Event: Action: New state:
  148. * ============================================================================
  149. * IDLE start A48,A28 INSTANTIATING_SUs
  150. * IDLE assign_si A48,A31 ASSIGNING_ON_REQ
  151. * IDLE failover_su A48,[C22]A10,A11 DEACTIVATING_DEP
  152. * IDLE failover_su A48,[!C22]A12 TERMINATING_SUSP
  153. * IDLE failover_node A48,[!C22]A12 TERMINATING_SUSP
  154. * IDLE failover_node A48,[C22]A10,A11 DEACTIVATING_DEP
  155. * IDLE failover_node A48,[C100]A34 IDLE
  156. * INSTANTIATING_SUs start A48,A28 INSTANTIATING_SUs
  157. * INSTANTIATING_SUs su_state_chg [C101]A26,A53 IDLE
  158. * INSTANTIATING_SUs su_state_chg [C102]A26,A53 IDLE
  159. * INSTANTIATING_SUs assign_si A31 ASSIGNING_ON_REQ
  160. * INSTANTIATING_SUs failover_su A52 INSTANTIATING_SUs
  161. * INSTANTIATING_SUs failover_node A52 INSTANTIATING_SUs
  162. * ASSIGNING_ON_REQ ha_state_assumed [C15]A54 IDLE
  163. * ASSIGNING_ON_REQ failover_su A52 ASSIGNING_ON_REQ
  164. * ASSIGNING_ON_REQ failover_node A52 ASSIGNING_ON_REQ
  165. * DEACTIVATING_DEP si_deactivated [C20] REMOVING_S-BY_ASS
  166. * DEACTIVATING_DEP si_deactivated [!C20]A12 TERMINATING_SUSP
  167. * TERMINATING_SUSP su_state_chg [C103]A24,A20 ASS_S-BY_TO_SPARE
  168. * TERMINATING_SUSP su_state_chg [C104]A24,A50 REMOVING_S-BY_ASS
  169. * TERMINATING_SUSP su_state_chg [C105]A16,A17 ACTIVATING_S-BY
  170. * TERMINATING_SUSP su_state_chg [C106]A20 ASS_S-BY_TO_SPARE
  171. * TERMINATING_SUSP su_state_chg [C108]A23 REPAIRING_SU
  172. * TERMINATING_SUSP su_state_chg [C109] IDLE
  173. * TERMINATING_SUSP failover_su A52 TERMINATING_SUSP
  174. * TERMINATING_SUSP failover_node A52 TERMINATING_SUSP
  175. * REMOVING_S-BY_ASS assignment_removed A51 REMOVING_S-BY_ASS
  176. * REMOVING_S-BY_ASS assignment_removed [C27]&[C24] ACTIVATING_S-BY
  177. * REMOVING_S-BY_ASS assignment_removed [C110]A20 ASS_S-BY_TO_SPARE
  178. * REMOVING_S-BY_ASS assignment_removed [C111]A23 REPAIRING_SU
  179. * REMOVING_S-BY_ASS assignment_removed [C112] IDLE
  180. * REMOVING_S-BY_ASS failover_su A52 REMOVING_S-BY_ASS
  181. * REMOVING_S-BY_ASS failover_node A52 REMOVING_S-BY_ASS
  182. * ACTIVATING_S-BY su_activated [C2]&[C11]A20 ASS_S-BY_TO_SPARE
  183. * ACTIVATING_S-BY su_activated [C113]A23 REPAIRING_SU
  184. * ACTIVATING_S-BY su_activated [C114] IDLE
  185. * ACTIVATING_S-BY failover_su A52 ACTIVATING_S-BY
  186. * ACTIVATING_S-BY failover_node A52 ACTIVATING_S-BY
  187. * ASS_S-BY_TO_SPARE ha_state_assumed [C115]A23 REPAIRING_SU
  188. * ASS_S-BY_TO_SPARE ha_state_assumed [C116] IDLE
  189. * ASS_S-BY_TO_SPARE failover_su A52 ASS_S-BY_TO_SPARE
  190. * ASS_S-BY_TO_SPARE failover_node A52 ASS_S-BY_TO_SPARE
  191. * REPAIRING_SU su_state_chg [C28]A36,A37,A31 ASSIGNING_WL
  192. * REPAIRING_SU su_state_chg [C28][C31] IDLE
  193. * REPAIRING_SU failover_su A52 REPAIRING_SU
  194. * REPAIRING_SU failover_node A52 REPAIRING_SU
  195. * ASSIGNING_WL ha_state_assumed [C15] IDLE
  196. * ASSIGNING_WL failover_su A52 ASSIGNING_WL
  197. * ASSIGNING_WL failover_node A52 ASSIGNING_WL
  198. *
  199. * 1.2 State Description
  200. * =====================
  201. * IDLE - SG is synchronized and idle. When IDLE state is set,
  202. * the oldest deferred event (if any) is recalled.
  203. * INSTANTIATING_SUs - INSTANTIATING_SERVICE_UNITS
  204. * SG has ordered all contained SUs to instantiate and
  205. * waits for the SUs to report a change of their
  206. * presence state. SG is also prepared to accept an
  207. * order to assign workload in this state.
  208. * ASSIGNING_ON_REQ - ASSIGNING_ON_REQUEST
  209. * SG has on request assigned workload to all service units
  210. * on the requested dependency level and waits for SIs to
  211. * indicate that the requested HA-state have been set to the
  212. * appropriate components.
  213. * TERMINATING_SUSP - TERMINATING_SUSPECTED
  214. * SG has cleaned up all components suspected to be
  215. * erroneous and waits for the concerned SUs to report a
  216. * change of their presence states.
  217. * REMOVING_S-BY_ASS - REMOVING_STANDBY_ASSIGNMENTS
  218. * This state is only applicable to the n-plus-m redundancy
  219. * model. In this state, SG has initiated the removal of
  220. * those assignments from standby SUs that do not match the
  221. * assignments of error suspected SUs. The reason for this
  222. * removal is a preparation for not violating the rule which
  223. * says an SU can not have both active and standby assign-
  224. * ments simultaneously in the n-plus-m redundancy model.
  225. * ACTIVATING_S-BY - ACTIVATING_STANDBY
  226. * SG has located all standby SI-assignments in the recovery
  227. * scope and ordered the corresponding SI to set the active
  228. * HA-state and waits for SI to indicate that the requested
  229. * HA-state has been set to the appropriate components.
  230. * ASS_S-BY_TO_SPARE - ASSIGNING_STANDBY_TO_SPARE
  231. * Current SG is configured with a spare SU. In this state,
  232. * SG has requested all SIs to assign the standby HA-state
  233. * to the spare SU and waits for the SIs to indicate that
  234. * the standby HA-state have been set.
  235. * REPAIRING_SU - REPAIRING_SU
  236. * In this state SG has initiated instantiation of all SUs
  237. * in current recovery scope until the configured preference
  238. * of number of instantiated SUs is fulfiled. SG then waits
  239. * for the concerned SUs to report a change of presence
  240. * state.
  241. * ASSIGNING_WL - ASSIGNING_WORKLOAD
  242. * In this state SG has initiated the assignment of workload
  243. * to all or a subset of its contained SUs and waits for the
  244. * concerned SIs to indicated that the requested HA-state
  245. * has been assumed.
  246. *
  247. * 1.3 Actions
  248. * ===========
  249. * A1 -
  250. * A2 -
  251. * A3 -
  252. * A4 -
  253. * A5 -
  254. * A6 -
  255. * A7 -
  256. * A8 -
  257. * A9 -
  258. * A10 - [foreach SI in the scope]&[foreach SI-assignment with
  259. * confirmed-HA-state == ACTIVE]/set requested-ha-state = QUIESCED
  260. * A11 - [foreach SI in the scope]/deactivate SI
  261. * A12 - [foreach suspected SU]/terminate all components
  262. * A13 -
  263. * A14 -
  264. * A15 -
  265. * A16 - [foreach SI in the scope]&[foreach SI-assignment with
  266. * confirmed-HA-state == STANDBY]/set requested-ha-state = ACTIVE
  267. * A17 - [foreach SI in the scope]/activate SI
  268. * A18 -
  269. * A19 -
  270. * A20 -
  271. * A21 -
  272. * A22 -
  273. * A23 -
  274. * A24 -
  275. * A25 -
  276. * A26 -
  277. * A27 -
  278. * A28 -
  279. * A29 -
  280. * A30 -
  281. * A31 -
  282. * A32 -
  283. * A33 -
  284. * A34 -
  285. * A35 -
  286. * A36 -
  287. * A37 -
  288. * A38 -
  289. * A39 -
  290. * A40 -
  291. * A41 -
  292. * A42 -
  293. * A43 -
  294. * A44 -
  295. * A45 -
  296. * A46 -
  297. * A47 -
  298. * A48 -
  299. * A49 -
  300. *
  301. * 1.4 Composite Guards
  302. * ====================
  303. * The meaning with these guards is just to save space in the state transition
  304. * table above.
  305. * C100 - [C7]&[!C22]&[C20]
  306. * C101 - [C12]&[C28]
  307. * C102 - [C13]&[C28]
  308. * C103 - [C6]&[C21]&[C11]
  309. * C104 - [C6]&[C25]&[C26]
  310. * C105 - [C6]&(!([C25]|[C26]))&[C24]
  311. * C106 - [C6]&(!([C25]|[C26]))&[!C24]&[C11]
  312. * C107 -
  313. * C108 - [C6]&(!([C25]|[C26]))&[!C24]&[!C11]&[C9]&[C10]&[!C30]
  314. * C109 - [C6]&(!([C25]|[C26]))&[!C24]&[!C11]&[C9]&[C10]&[C30]
  315. * C110 - [C27]&[!C24]&[C11]
  316. * C111 - [C27]&[!C24]&[!C11]&[C9]&[C10]&[!C30]
  317. * C112 - [C27]&[!C24]&[!C11]&[C9]&[C10]&[C30]
  318. * C113 - [C2]&[!C11]&[C9]&[C10]&[!C30]
  319. * C114 - [C2]&[!C11]&[C9]&[C10]&[C30]
  320. * C115 - [C9]&[C10]&[!C30]
  321. * C116 - [C9]&[C10]&[C30]
  322. *
  323. * 1.4 Guards
  324. * ==========
  325. * C1 -
  326. * C2 - all SI in the recovery scope
  327. * C3 -
  328. * C4 -
  329. * C5 -
  330. * C6 - all supected SUs or components have presence state == UNINSTANTIATED
  331. * or presence state == INSTANTIATION_FAILED
  332. * C7 - original event == failover node
  333. * C8 -
  334. * C9 - original event == failover su
  335. * C10 - SaAmfSGAutoRepair == true
  336. * C11 - spare SUs exist
  337. * C12 - original event == start(all SUs)
  338. * C13 - original event == start(node)
  339. * C14 -
  340. * C15 - all SI-assignments on current dependency-level have requested-ha-state
  341. == confirmed-ha-state or operation failed
  342. * C16 -
  343. * C17 -
  344. * C18 -
  345. * C19 -
  346. * C20 - all suspected SUs have presence state == UNINSTANTIATED or
  347. presence state == xx_FAILED
  348. * C21 - no SI in the scope has an SI-assignment with HA-state == STANDBY
  349. * C22 - the concerned entity has ACTIVE HA-state
  350. * C23 -
  351. * C24 - at least one SI-assignment related to an SI in the scope has HA-state
  352. == STANDBY
  353. * C25 - redundancy model == N plus M
  354. * C26 - at least one SU has STANDBY assignments for more SIs than those SIs
  355. that are within the recovery scope
  356. * C27 - no SI-assignment related to SI protected by current SG has requested
  357. HA-state == REMOVED
  358. * C28 - no SU has presence state == INSTANTIATING
  359. * C29 -
  360. * C30 - more SUs not needed or the node hosting the SU to repair is disabled.
  361. * C31 - no new additional assignments needed or possible
  362. */
  363. #include <stdlib.h>
  364. #include <errno.h>
  365. #include "amf.h"
  366. #include "logsys.h"
  367. #include "main.h"
  368. #include "util.h"
  369. LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO);
  370. static int assign_si (struct amf_sg *sg, int dependency_level);
  371. static void acsm_enter_activating_standby (struct amf_sg *sg);
  372. static void delete_si_assignments_in_scope (struct amf_sg *sg);
  373. static void acsm_enter_repairing_su (struct amf_sg *sg);
  374. static void standby_su_activated_cbfn (
  375. struct amf_si_assignment *si_assignment, int result);
  376. static void dependent_si_deactivated_cbfn (
  377. struct amf_si_assignment *si_assignment, int result);
  378. static void dependent_si_deactivated_cbfn2 (struct amf_sg *sg);
  379. static void assign_si_assumed_cbfn (
  380. struct amf_si_assignment *si_assignment, int result);
  381. static void acsm_enter_removing_standby_assignments (amf_sg_t *sg);
  382. static void acsm_enter_assigning_standby_to_spare (amf_sg_t *sg);
  383. static const char *sg_event_type_text[] = {
  384. "Unknown",
  385. "Failover SU",
  386. "Failover node",
  387. "Failover comp",
  388. "Switchover node",
  389. "Start",
  390. "Autoadjust",
  391. "Assign SI"
  392. };
  393. typedef struct sg_event {
  394. amf_sg_event_type_t event_type;
  395. amf_sg_t *sg;
  396. amf_su_t *su;
  397. amf_comp_t *comp;
  398. amf_node_t *node;
  399. } sg_event_t;
  400. /******************************************************************************
  401. * Internal (static) utility functions
  402. *****************************************************************************/
  403. static int is_cluster_start(amf_node_t *node_to_start)
  404. {
  405. return node_to_start == NULL;
  406. }
  407. static void sg_set_event (amf_sg_event_type_t sg_event_type,
  408. amf_sg_t *sg, amf_su_t *su, amf_comp_t *comp, amf_node_t * node,
  409. sg_event_t *sg_event)
  410. {
  411. sg_event->event_type = sg_event_type;
  412. sg_event->node = node;
  413. sg_event->su = su;
  414. sg_event->comp = comp;
  415. sg_event->sg = sg;
  416. }
  417. static void sg_defer_event (amf_sg_event_type_t event_type,
  418. sg_event_t *sg_event)
  419. {
  420. ENTER("Defered event = %d", event_type);
  421. amf_fifo_put (event_type, &sg_event->sg->deferred_events,
  422. sizeof (sg_event_t),
  423. sg_event);
  424. }
  425. static void sg_recall_deferred_events (amf_sg_t *sg)
  426. {
  427. sg_event_t sg_event;
  428. ENTER ("%s", sg->name.value);
  429. if (amf_fifo_get (&sg->deferred_events, &sg_event)) {
  430. switch (sg_event.event_type) {
  431. case SG_FAILOVER_SU_EV:
  432. amf_sg_failover_su_req (sg_event.sg,
  433. sg_event.su, sg_event.node);
  434. break;
  435. case SG_FAILOVER_NODE_EV:
  436. amf_sg_failover_node_req (sg_event.sg,
  437. sg_event.node);
  438. break;
  439. case SG_FAILOVER_COMP_EV:
  440. case SG_SWITCH_OVER_NODE_EV:
  441. case SG_START_EV:
  442. case SG_AUTO_ADJUST_EV:
  443. default:
  444. dprintf("event_type = %d", sg_event.event_type);
  445. break;
  446. }
  447. }
  448. }
  449. static void timer_function_sg_recall_deferred_events (void *data)
  450. {
  451. amf_sg_t *sg = (amf_sg_t*)data;
  452. ENTER ("");
  453. sg_recall_deferred_events (sg);
  454. }
  455. static void acsm_enter_idle (amf_sg_t *sg)
  456. {
  457. SaNameT dn;
  458. ENTER ("sg: %s state: %d", sg->name.value, sg->avail_state);
  459. sg->avail_state = SG_AC_Idle;
  460. if (sg->recovery_scope.event_type != 0) {
  461. switch (sg->recovery_scope.event_type) {
  462. case SG_FAILOVER_SU_EV:
  463. assert (sg->recovery_scope.sus[0] != NULL);
  464. amf_su_dn_make (sg->recovery_scope.sus[0], &dn);
  465. log_printf (
  466. LOG_NOTICE,
  467. "'%s' %s recovery action finished",
  468. dn.value,
  469. sg_event_type_text[sg->recovery_scope.event_type]);
  470. break;
  471. case SG_FAILOVER_NODE_EV:
  472. amf_node_sg_failed_over (
  473. sg->recovery_scope.node, sg);
  474. log_printf (
  475. LOG_NOTICE,
  476. "'%s for %s' recovery action finished",
  477. sg_event_type_text[sg->recovery_scope.event_type],
  478. sg->name.value);
  479. break;
  480. case SG_START_EV:
  481. amf_application_sg_started (sg->application,
  482. sg, this_amf_node);
  483. break;
  484. case SG_ASSIGN_SI_EV:
  485. log_printf (LOG_NOTICE, "All SI assigned");
  486. break;
  487. default:
  488. log_printf (
  489. LOG_NOTICE,
  490. "'%s' recovery action finished",
  491. sg_event_type_text[sg->recovery_scope.event_type]);
  492. break;
  493. }
  494. }
  495. if (sg->recovery_scope.sus != NULL) {
  496. free ((void *)sg->recovery_scope.sus);
  497. }
  498. if (sg->recovery_scope.sis != NULL) {
  499. free ((void *)sg->recovery_scope.sis);
  500. }
  501. memset (&sg->recovery_scope, 0, sizeof (struct sg_recovery_scope));
  502. sg->node_to_start = NULL;
  503. amf_call_function_asynchronous (
  504. timer_function_sg_recall_deferred_events, sg);
  505. }
  506. static int su_instantiated_count (struct amf_sg *sg)
  507. {
  508. int cnt = 0;
  509. struct amf_su *su;
  510. for (su = sg->su_head; su != NULL; su = su->next) {
  511. if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATED)
  512. cnt++;
  513. }
  514. return cnt;
  515. }
  516. static int has_any_su_in_scope_active_workload (struct amf_sg *sg)
  517. {
  518. struct amf_su **sus= sg->recovery_scope.sus;
  519. struct amf_si_assignment *si_assignment;
  520. while (*sus != NULL) {
  521. si_assignment = amf_su_get_next_si_assignment (*sus, NULL);
  522. while (si_assignment != NULL) {
  523. if (si_assignment->saAmfSISUHAState !=
  524. SA_AMF_HA_ACTIVE) {
  525. break;
  526. }
  527. si_assignment = amf_su_get_next_si_assignment (
  528. *sus, si_assignment);
  529. }
  530. if (si_assignment != NULL) {
  531. break;
  532. }
  533. sus++;
  534. }
  535. return(*sus == NULL);
  536. }
  537. static int is_any_si_in_scope_assigned_standby (struct amf_sg *sg)
  538. {
  539. struct amf_si **sis= sg->recovery_scope.sis;
  540. struct amf_si_assignment *si_assignment;
  541. /*
  542. * Check if there is any si in the scope which has no
  543. * active assignment and at least one standby assignment.
  544. */
  545. while (*sis != NULL) {
  546. si_assignment = (*sis)->assigned_sis;
  547. while (si_assignment != NULL) {
  548. if (si_assignment->saAmfSISUHAState ==
  549. SA_AMF_HA_ACTIVE) {
  550. break;
  551. }
  552. si_assignment = si_assignment->next;
  553. }
  554. if (si_assignment == NULL) {
  555. /* There is no ACTIVE assignment ..*/
  556. si_assignment = (*sis)->assigned_sis;
  557. while (si_assignment != NULL) {
  558. if (si_assignment->saAmfSISUHAState ==
  559. SA_AMF_HA_STANDBY) {
  560. break;
  561. }
  562. si_assignment = si_assignment->next;
  563. }
  564. if (si_assignment != NULL) {
  565. /* .. and one STANDBY assignment*/
  566. break;
  567. }
  568. }
  569. sis++;
  570. }
  571. return(*sis != NULL);
  572. }
  573. static void acsm_enter_terminating_suspected (struct amf_sg *sg)
  574. {
  575. struct amf_su **sus= sg->recovery_scope.sus;
  576. ENTER("%s",sg->name.value);
  577. sg->avail_state = SG_AC_TerminatingSuspected;
  578. /*
  579. * Terminate suspected SU(s)
  580. */
  581. while (*sus != 0) {
  582. amf_su_terminate (*sus);
  583. sus++;
  584. }
  585. }
  586. static inline int su_presense_state_is_ored (amf_su_t *su,
  587. SaAmfPresenceStateT state1,SaAmfPresenceStateT state2,
  588. SaAmfPresenceStateT state3)
  589. {
  590. return(su->saAmfSUPresenceState == state1 || su->saAmfSUPresenceState ==
  591. state2 || su->saAmfSUPresenceState == state3) ? 1 : 0;
  592. }
  593. static inline int su_presense_state_is_not (amf_su_t *su,
  594. SaAmfPresenceStateT state1,SaAmfPresenceStateT state2,
  595. SaAmfPresenceStateT state3)
  596. {
  597. return(su->saAmfSUPresenceState != state1 && su->saAmfSUPresenceState !=
  598. state2 && su->saAmfSUPresenceState != state3) ? 1 : 0;
  599. }
  600. static void timer_function_dependent_si_deactivated2 (void *data)
  601. {
  602. amf_sg_t *sg = (amf_sg_t *)data;
  603. ENTER ("");
  604. dependent_si_deactivated_cbfn2 (sg);
  605. }
  606. static struct amf_si *si_get_dependent (struct amf_si *si)
  607. {
  608. struct amf_si *tmp_si = NULL;
  609. if (si->depends_on != NULL) {
  610. SaNameT res_arr[2];
  611. int is_match;
  612. if (si->depends_on->name.length < SA_MAX_NAME_LENGTH) {
  613. si->depends_on->name.value[si->depends_on->name.length] = '\0';
  614. }
  615. is_match = sa_amf_grep ((char*)si->depends_on->name.value,
  616. "safDepend=.*,safSi=(.*),safApp=.*",
  617. 2, res_arr);
  618. if (is_match) {
  619. tmp_si = amf_si_find (si->application, (char*)res_arr[1].value);
  620. } else {
  621. log_printf (LOG_LEVEL_ERROR, "distinguished name for "
  622. "amf_si_depedency failed\n");
  623. openais_exit_error (AIS_DONE_FATAL_ERR);
  624. }
  625. }
  626. return tmp_si;
  627. }
  628. static struct amf_si *amf_dependent_get_next (struct amf_si *si,
  629. struct amf_si *si_iter)
  630. {
  631. struct amf_si *tmp_si;
  632. struct amf_application *application;
  633. if (si_iter == NULL) {
  634. assert(amf_cluster != NULL);
  635. application = amf_cluster->application_head;
  636. assert(application != NULL);
  637. tmp_si = application->si_head;
  638. } else {
  639. tmp_si = si_iter->next;
  640. if (tmp_si == NULL) {
  641. application = si->application->next;
  642. if (application == NULL) {
  643. goto out;
  644. }
  645. }
  646. }
  647. for (; tmp_si != NULL; tmp_si = tmp_si->next) {
  648. struct amf_si *depends_on_si = si_get_dependent (tmp_si);
  649. while (depends_on_si != NULL) {
  650. if (depends_on_si == si) {
  651. goto out;
  652. }
  653. depends_on_si = depends_on_si->next;
  654. }
  655. }
  656. out:
  657. return tmp_si;
  658. }
  659. static void acsm_enter_deactivating_dependent_workload (amf_sg_t *sg)
  660. {
  661. struct amf_si **sis= sg->recovery_scope.sis;
  662. struct amf_si_assignment *si_assignment;
  663. int callback_pending = 0;
  664. sg->avail_state = SG_AC_DeactivatingDependantWorkload;
  665. ENTER("'%s'",sg->name.value);
  666. /*
  667. * For each SI in the recovery scope, find all active
  668. * assignments and request them to be deactivated.
  669. */
  670. while (*sis != NULL) {
  671. struct amf_si *dependent_si;
  672. struct amf_si *si = *sis;
  673. si_assignment = si->assigned_sis;
  674. dependent_si = amf_dependent_get_next (si, NULL);
  675. while (dependent_si != NULL) {
  676. si_assignment = dependent_si->assigned_sis;
  677. while (si_assignment != NULL) {
  678. if (si_assignment->saAmfSISUHAState ==
  679. SA_AMF_HA_ACTIVE) {
  680. si_assignment->requested_ha_state =
  681. SA_AMF_HA_QUIESCED;
  682. callback_pending = 1;
  683. amf_si_ha_state_assume (
  684. si_assignment,
  685. dependent_si_deactivated_cbfn);
  686. }
  687. si_assignment = si_assignment->next;
  688. }
  689. dependent_si = amf_dependent_get_next (si, dependent_si);
  690. }
  691. sis++;
  692. }
  693. if (callback_pending == 0) {
  694. static poll_timer_handle dependent_si_deactivated_handle;
  695. ENTER("");
  696. poll_timer_add (aisexec_poll_handle, 0, sg,
  697. timer_function_dependent_si_deactivated2,
  698. &dependent_si_deactivated_handle);
  699. }
  700. }
  701. /**
  702. * Enter function for state SG_AC_ActivatingStandby. It activates
  703. * one STANDBY assignment for each SI in the recovery scope.
  704. * @param sg
  705. */
  706. static void acsm_enter_activating_standby (struct amf_sg *sg)
  707. {
  708. struct amf_si **sis= sg->recovery_scope.sis;
  709. struct amf_si_assignment *si_assignment;
  710. int is_no_standby_activated = 1;
  711. ENTER("'%s'",sg->name.value);
  712. sg->avail_state = SG_AC_ActivatingStandby;
  713. /*
  714. * For each SI in the recovery scope, find one standby
  715. * SI assignment and activate it.
  716. */
  717. while (*sis != NULL) {
  718. si_assignment = (*sis)->assigned_sis;
  719. while (si_assignment != NULL) {
  720. if (si_assignment->saAmfSISUHAState ==
  721. SA_AMF_HA_STANDBY) {
  722. si_assignment->requested_ha_state =
  723. SA_AMF_HA_ACTIVE;
  724. amf_si_ha_state_assume (
  725. si_assignment, standby_su_activated_cbfn);
  726. is_no_standby_activated = 0;
  727. break;
  728. }
  729. si_assignment = si_assignment->next;
  730. }
  731. sis++;
  732. }
  733. if (is_no_standby_activated) {
  734. acsm_enter_assigning_standby_to_spare (sg);
  735. }
  736. }
  737. static void acsm_enter_repairing_su (struct amf_sg *sg)
  738. {
  739. struct amf_su **sus= sg->recovery_scope.sus;
  740. int is_any_su_instantiated = 0;
  741. const int PERFORMS_INSTANTIATING = 1;
  742. ENTER("'%s'",sg->name.value);
  743. sg->avail_state = SG_AC_ReparingSu;
  744. /*
  745. * Instantiate SUs in current recovery scope until the configured
  746. * preference is fulfiled.
  747. */
  748. while (*sus != NULL) {
  749. if (su_instantiated_count ((*sus)->sg) <
  750. (*sus)->sg->saAmfSGNumPrefInserviceSUs) {
  751. struct amf_node *node =
  752. amf_node_find(&((*sus)->saAmfSUHostedByNode));
  753. if (node == NULL) {
  754. log_printf (LOG_LEVEL_ERROR,
  755. "Su to recover not hosted on any node\n");
  756. openais_exit_error (AIS_DONE_FATAL_ERR);
  757. }
  758. if (node->saAmfNodeOperState == SA_AMF_OPERATIONAL_ENABLED) {
  759. /* node is synchronized */
  760. if (amf_su_instantiate ((*sus)) == PERFORMS_INSTANTIATING) {
  761. is_any_su_instantiated = 1;
  762. }
  763. }
  764. }
  765. sus++;
  766. }
  767. if (is_any_su_instantiated == 0) {
  768. acsm_enter_idle (sg);
  769. }
  770. }
  771. static inline void remove_all_suspected_sus (amf_sg_t *sg)
  772. {
  773. amf_su_t *su;
  774. ENTER("");
  775. for (su = sg->su_head; su != NULL; su =su->next) {
  776. amf_comp_t *component;
  777. for (component = su->comp_head; component != NULL;
  778. component = component->next) {
  779. amf_comp_error_suspected_clear (component);
  780. }
  781. }
  782. }
  783. static int is_all_si_assigned (amf_sg_t *sg)
  784. {
  785. struct amf_si_assignment *si_assignment;
  786. int si_assignment_cnt = 0;
  787. int confirmed_assignments = 0;
  788. amf_si_t *si;
  789. for (si = sg->application->si_head; si != NULL; si = si->next) {
  790. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  791. for (si_assignment = si->assigned_sis;
  792. si_assignment != NULL;
  793. si_assignment = si_assignment->next) {
  794. si_assignment_cnt++;
  795. if (si_assignment->requested_ha_state ==
  796. si_assignment->saAmfSISUHAState) {
  797. confirmed_assignments++;
  798. }
  799. }
  800. }
  801. }
  802. return (confirmed_assignments == si_assignment_cnt);
  803. }
  804. /**
  805. * Inquire if SI is assigned to SU
  806. * @param si
  807. * @param su
  808. *
  809. * @return int
  810. */
  811. static int is_si_assigned_to_su (amf_si_t *si, amf_su_t *su)
  812. {
  813. amf_si_assignment_t *si_assignment = 0;
  814. int si_assignment_assigned_to_su = 0;
  815. for (si_assignment = si->assigned_sis; si_assignment != NULL;
  816. si_assignment = si_assignment->next) {
  817. if (si_assignment->su == su) {
  818. si_assignment_assigned_to_su = 1;
  819. break;
  820. }
  821. }
  822. return si_assignment_assigned_to_su;
  823. }
  824. /**
  825. * Inquire if SU is a spare.
  826. * @param sg
  827. * @param su
  828. *
  829. * @return int
  830. */
  831. static int is_spare_su (amf_sg_t *sg, amf_su_t *su)
  832. {
  833. amf_si_t *si;
  834. int spare_su = 1;
  835. for (si = sg->application->si_head; si != NULL; si = si->next) {
  836. if(name_match(&sg->name, &si->saAmfSIProtectedbySG)) {
  837. if (is_si_assigned_to_su (si, su)) {
  838. spare_su = 0;
  839. break;
  840. }
  841. }
  842. }
  843. return (spare_su && su->saAmfSUPresenceState ==
  844. SA_AMF_PRESENCE_INSTANTIATED);
  845. }
  846. /**
  847. * Inqure if it is any spare SUs covered by SG
  848. * @param sg
  849. *
  850. * @return int
  851. */
  852. static int is_spare_sus (amf_sg_t *sg)
  853. {
  854. amf_su_t *su = NULL;
  855. int spare_sus = 0;
  856. for (su = sg->su_head; su != NULL; su = su->next) {
  857. if (is_spare_su(sg, su)) {
  858. spare_sus = 1;
  859. break;
  860. }
  861. }
  862. return spare_sus;
  863. }
  864. /**
  865. * Provide standby assignments for the spare SUs in SG
  866. * @param sg
  867. */
  868. static void assume_standby_si_assignment_for_spare_sus (amf_sg_t *sg)
  869. {
  870. ENTER("");
  871. assign_si (sg, 0);
  872. }
  873. /**
  874. * Enter the AssigningStandbyToSpare state.
  875. * @param sg
  876. */
  877. static void acsm_enter_assigning_standby_to_spare (amf_sg_t *sg)
  878. {
  879. ENTER("%s", sg->name.value);
  880. sg->avail_state = SG_AC_AssigningStandbyToSpare;
  881. if (is_spare_sus (sg)) {
  882. assume_standby_si_assignment_for_spare_sus (sg);
  883. } else {
  884. switch (sg->recovery_scope.event_type) {
  885. case SG_FAILOVER_NODE_EV:
  886. acsm_enter_idle (sg);
  887. break;
  888. case SG_FAILOVER_SU_EV:
  889. acsm_enter_repairing_su (sg);
  890. break;
  891. default:
  892. dprintf("event_type %d",sg->recovery_scope.event_type);
  893. assert (0);
  894. break;
  895. }
  896. }
  897. }
  898. /**
  899. * Checks if the si pointed out is already in the scope.
  900. * @param sg
  901. * @param si
  902. */
  903. static int is_si_in_scope(struct amf_sg *sg, struct amf_si *si)
  904. {
  905. struct amf_si **tmp_sis= sg->recovery_scope.sis;
  906. while (*tmp_sis != NULL) {
  907. if (*tmp_sis == si) {
  908. break;
  909. }
  910. tmp_sis++;
  911. }
  912. return(*tmp_sis == si);
  913. }
  914. /**
  915. * Adds the si pointed out to the scope.
  916. * @param sg
  917. * @param si
  918. */
  919. static void add_si_to_scope ( struct amf_sg *sg, struct amf_si *si)
  920. {
  921. int number_of_si = 2; /* It shall be at least two */
  922. struct amf_si **tmp_sis= sg->recovery_scope.sis;
  923. ENTER ("'%s'", si->name.value);
  924. while (*tmp_sis != NULL) {
  925. number_of_si++;
  926. tmp_sis++;
  927. }
  928. sg->recovery_scope.sis = (struct amf_si **)
  929. realloc((void *)sg->recovery_scope.sis,
  930. sizeof (struct amf_si *)*number_of_si);
  931. assert (sg->recovery_scope.sis != NULL);
  932. tmp_sis= sg->recovery_scope.sis;
  933. while (*tmp_sis != NULL) {
  934. tmp_sis++;
  935. }
  936. *tmp_sis = si;
  937. *(++tmp_sis) = NULL;
  938. }
  939. /**
  940. * Adds the ssu pointed out to the scope.
  941. * @param sg
  942. * @param su
  943. */
  944. static void add_su_to_scope (struct amf_sg *sg, struct amf_su *su)
  945. {
  946. int number_of_su = 2; /* It shall be at least two */
  947. struct amf_su **tmp_sus= sg->recovery_scope.sus;
  948. ENTER ("'%s'", su->name.value);
  949. while (*tmp_sus != NULL) {
  950. number_of_su++;
  951. tmp_sus++;
  952. }
  953. sg->recovery_scope.sus = (struct amf_su **)
  954. realloc((void *)sg->recovery_scope.sus,
  955. sizeof (struct amf_su *)*number_of_su);
  956. assert (sg->recovery_scope.sus != NULL);
  957. tmp_sus= sg->recovery_scope.sus;
  958. while (*tmp_sus != NULL) {
  959. tmp_sus++;
  960. }
  961. *tmp_sus = su;
  962. *(++tmp_sus) = NULL;
  963. }
  964. /**
  965. * Set recovery scope for failover SU.
  966. * @param sg
  967. * @param su
  968. */
  969. static void set_scope_for_failover_su (struct amf_sg *sg, struct amf_su *su)
  970. {
  971. struct amf_si_assignment *si_assignment;
  972. struct amf_si **sis;
  973. struct amf_su **sus;
  974. SaNameT dn;
  975. sg->recovery_scope.event_type = SG_FAILOVER_SU_EV;
  976. sg->recovery_scope.node = NULL;
  977. sg->recovery_scope.comp = NULL;
  978. sg->recovery_scope.sus = (struct amf_su **)
  979. calloc (2, sizeof (struct amf_su *));
  980. sg->recovery_scope.sis = (struct amf_si **)
  981. calloc (1, sizeof (struct amf_si *));
  982. assert ((sg->recovery_scope.sus != NULL) &&
  983. (sg->recovery_scope.sis != NULL));
  984. sg->recovery_scope.sus[0] = su;
  985. amf_su_dn_make (sg->recovery_scope.sus[0], &dn);
  986. log_printf (
  987. LOG_NOTICE, "'%s' for %s recovery action started",
  988. sg_event_type_text[sg->recovery_scope.event_type],
  989. dn.value);
  990. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  991. while (si_assignment != NULL) {
  992. if (is_si_in_scope(sg, si_assignment->si) == 0) {
  993. add_si_to_scope(sg,si_assignment->si );
  994. }
  995. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  996. }
  997. sus = sg->recovery_scope.sus;
  998. dprintf("The following sus are within the scope:\n");
  999. while (*sus != NULL) {
  1000. dprintf("%s\n", (*sus)->name.value);
  1001. sus++;
  1002. }
  1003. sis= sg->recovery_scope.sis;
  1004. dprintf("The following sis are within the scope:\n");
  1005. while (*sis != NULL) {
  1006. dprintf("%s\n", (*sis)->name.value);
  1007. sis++;
  1008. }
  1009. }
  1010. static void set_scope_for_failover_node (struct amf_sg *sg, struct amf_node *node)
  1011. {
  1012. struct amf_si_assignment *si_assignment;
  1013. struct amf_si **sis;
  1014. struct amf_su **sus;
  1015. struct amf_su *su;
  1016. ENTER ("'%s'", node->name.value);
  1017. sg->recovery_scope.event_type = SG_FAILOVER_NODE_EV;
  1018. sg->recovery_scope.node = node;
  1019. sg->recovery_scope.comp = NULL;
  1020. sg->recovery_scope.sus = (struct amf_su **)
  1021. calloc (1, sizeof (struct amf_su *));
  1022. sg->recovery_scope.sis = (struct amf_si **)
  1023. calloc (1, sizeof (struct amf_si *));
  1024. log_printf (
  1025. LOG_NOTICE, "'%s' for node %s recovery action started",
  1026. sg_event_type_text[sg->recovery_scope.event_type],
  1027. node->name.value);
  1028. assert ((sg->recovery_scope.sus != NULL) &&
  1029. (sg->recovery_scope.sis != NULL));
  1030. for (su = sg->su_head; su != NULL; su = su->next) {
  1031. if (name_match (&node->name, &su->saAmfSUHostedByNode)) {
  1032. add_su_to_scope (sg, su);
  1033. }
  1034. }
  1035. sus = sg->recovery_scope.sus;
  1036. while (*sus != 0) {
  1037. su = *sus;
  1038. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  1039. while (si_assignment != NULL) {
  1040. if (is_si_in_scope(sg, si_assignment->si) == 0) {
  1041. add_si_to_scope(sg, si_assignment->si );
  1042. }
  1043. si_assignment = amf_su_get_next_si_assignment (
  1044. su, si_assignment);
  1045. }
  1046. sus++;
  1047. }
  1048. sus = sg->recovery_scope.sus;
  1049. dprintf("The following sus are within the scope:\n");
  1050. while (*sus != NULL) {
  1051. dprintf("%s\n", (*sus)->name.value);
  1052. sus++;
  1053. }
  1054. sis = sg->recovery_scope.sis;
  1055. dprintf("The following sis are within the scope:\n");
  1056. while (*sis != NULL) {
  1057. dprintf("%s\n", (*sis)->name.value);
  1058. sis++;
  1059. }
  1060. }
  1061. static void delete_si_assignment (amf_si_assignment_t *si_assignment)
  1062. {
  1063. amf_csi_t *csi;
  1064. amf_si_assignment_t *si_assignment_tmp;
  1065. amf_si_assignment_t **prev = &si_assignment->si->assigned_sis;
  1066. for (csi = si_assignment->si->csi_head; csi != NULL; csi = csi->next) {
  1067. amf_csi_delete_assignments (csi, si_assignment->su);
  1068. }
  1069. for (si_assignment_tmp = si_assignment->si->assigned_sis;
  1070. si_assignment_tmp != NULL;
  1071. si_assignment_tmp = si_assignment_tmp->next) {
  1072. if (si_assignment_tmp == si_assignment) {
  1073. amf_si_assignment_t *to_be_removed = si_assignment_tmp;
  1074. *prev = si_assignment_tmp->next;
  1075. dprintf ("SI assignment %s unlinked",
  1076. to_be_removed->name.value);
  1077. free (to_be_removed);
  1078. } else {
  1079. prev = &si_assignment_tmp->next;
  1080. }
  1081. }
  1082. }
  1083. /**
  1084. * Delete all SI assignments and all CSI assignments
  1085. * by requesting all contained components.
  1086. * @param su
  1087. */
  1088. static void delete_si_assignments (struct amf_su *su)
  1089. {
  1090. struct amf_csi *csi;
  1091. struct amf_si *si;
  1092. struct amf_si_assignment *si_assignment;
  1093. struct amf_si_assignment **prev;
  1094. ENTER ("'%s'", su->name.value);
  1095. for (si = su->sg->application->si_head; si != NULL; si = si->next) {
  1096. prev = &si->assigned_sis;
  1097. if (!name_match (&si->saAmfSIProtectedbySG, &su->sg->name)) {
  1098. continue;
  1099. }
  1100. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  1101. amf_csi_delete_assignments (csi, su);
  1102. }
  1103. for (si_assignment = si->assigned_sis; si_assignment != NULL;
  1104. si_assignment = si_assignment->next) {
  1105. if (si_assignment->su == su) {
  1106. struct amf_si_assignment *tmp = si_assignment;
  1107. *prev = si_assignment->next;
  1108. dprintf ("SI assignment %s unlinked", tmp->name.value);
  1109. free (tmp);
  1110. } else {
  1111. prev = &si_assignment->next;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. /**
  1117. * Delete all SI assignments and all CSI assignments in current
  1118. * recovery scope.
  1119. * @param sg
  1120. */
  1121. static void delete_si_assignments_in_scope (struct amf_sg *sg)
  1122. {
  1123. struct amf_su **sus= sg->recovery_scope.sus;
  1124. while (*sus != NULL) {
  1125. delete_si_assignments (*sus);
  1126. sus++;
  1127. }
  1128. }
  1129. /**
  1130. * Given an SI, find and return the SU assigned as standby
  1131. * @param si
  1132. *
  1133. * @return amf_su_t*
  1134. */
  1135. static amf_su_t *find_standby_su (amf_si_t *si)
  1136. {
  1137. amf_si_assignment_t *si_assignment;
  1138. amf_su_t *standby_su = NULL;
  1139. si_assignment = si->assigned_sis;
  1140. while (si_assignment != NULL) {
  1141. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) {
  1142. standby_su = si_assignment->su;
  1143. break;
  1144. }
  1145. si_assignment = si_assignment->next;
  1146. }
  1147. return standby_su;
  1148. }
  1149. static int no_si_assignment_is_requested_to_be_removed (amf_sg_t *sg)
  1150. {
  1151. amf_si_t *si;
  1152. int no_to_be_removed = 1;
  1153. for (si = sg->application->si_head; si != NULL; si = si->next) {
  1154. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  1155. amf_si_assignment_t *si_assignment = 0;
  1156. for (si_assignment = si->assigned_sis; si_assignment != NULL;
  1157. si_assignment = si_assignment->next) {
  1158. if (si_assignment->requested_ha_state ==
  1159. USR_AMF_HA_STATE_REMOVED) {
  1160. no_to_be_removed = 0;
  1161. goto out;
  1162. }
  1163. }
  1164. }
  1165. }
  1166. out:
  1167. return no_to_be_removed;
  1168. }
  1169. static void removed_si_assignment_callback_fn (void *si_assignment_in)
  1170. {
  1171. amf_si_assignment_t *si_assignment = si_assignment_in;
  1172. ENTER("");
  1173. delete_si_assignment (si_assignment);
  1174. /*
  1175. * if all si assignments are remove then change state
  1176. */
  1177. if (no_si_assignment_is_requested_to_be_removed (si_assignment->su->sg)) {
  1178. acsm_enter_activating_standby (si_assignment->su->sg);
  1179. }
  1180. }
  1181. /**
  1182. *
  1183. * @param sg
  1184. *
  1185. * @return int, number of removed SI assignments
  1186. */
  1187. static int remove_standby_si_assignments (amf_sg_t *sg)
  1188. {
  1189. struct amf_si **sis = sg->recovery_scope.sis;
  1190. struct amf_si_assignment *si_assignment;
  1191. amf_su_t *standby_su;
  1192. int removed = 0;
  1193. ENTER("'%s'", sg->name.value);
  1194. /*
  1195. * For each SI in the recovery scope, find a standby
  1196. * SU, then remove all 'standby SI assignment' not in
  1197. * the recovery scope.
  1198. */
  1199. while (*sis != NULL) {
  1200. standby_su = find_standby_su (*sis);
  1201. if (standby_su != NULL) {
  1202. si_assignment = amf_su_get_next_si_assignment (standby_su, NULL);
  1203. while (si_assignment != NULL) {
  1204. amf_si_t **sia;
  1205. int in_recovery_scope;
  1206. for (sia = sg->recovery_scope.sis, in_recovery_scope = 0;
  1207. *sia != NULL; sia++) {
  1208. if (name_match (&si_assignment->si->name, &(*sia)->name)) {
  1209. in_recovery_scope = 1;
  1210. }
  1211. }
  1212. /*
  1213. * The si_assignment found with standby hastate is not in the
  1214. * recovery scope. The found si_assignment will then be
  1215. * requested to be removed once.
  1216. */
  1217. if (!in_recovery_scope &&
  1218. si_assignment->requested_ha_state !=
  1219. USR_AMF_HA_STATE_REMOVED) {
  1220. amf_si_assignment_remove (si_assignment,
  1221. removed_si_assignment_callback_fn);
  1222. removed++;
  1223. }
  1224. si_assignment = amf_su_get_next_si_assignment (standby_su,
  1225. si_assignment);
  1226. }
  1227. }
  1228. sis++;
  1229. }
  1230. return removed;
  1231. }
  1232. /**
  1233. * Entry function for state 'removing standby assignments'
  1234. * @param sg
  1235. */
  1236. static void acsm_enter_removing_standby_assignments (amf_sg_t *sg)
  1237. {
  1238. ENTER("SG: %s", sg->name.value);
  1239. sg->avail_state = SG_AC_RemovingStandbyAssignments;
  1240. if (sg->saAmfSGRedundancyModel == SA_AMF_NPM_REDUNDANCY_MODEL) {
  1241. if (!remove_standby_si_assignments (sg)) {
  1242. acsm_enter_activating_standby (sg);
  1243. }
  1244. }
  1245. }
  1246. static inline int div_round (int a, int b)
  1247. {
  1248. int res;
  1249. assert (b != 0);
  1250. res = a / b;
  1251. if ((a % b) != 0)
  1252. res++;
  1253. return res;
  1254. }
  1255. static int no_su_has_presence_state (
  1256. struct amf_sg *sg, struct amf_node *node_to_start,
  1257. SaAmfPresenceStateT state)
  1258. {
  1259. struct amf_su *su;
  1260. int no_su_has_presence_state = 1;
  1261. for (su = sg->su_head; su != NULL; su = su->next) {
  1262. if (su->saAmfSUPresenceState == state) {
  1263. if (node_to_start == NULL) {
  1264. no_su_has_presence_state = 0;
  1265. break;
  1266. } else {
  1267. if (name_match(&node_to_start->name,
  1268. &su->saAmfSUHostedByNode)) {
  1269. no_su_has_presence_state = 0;
  1270. break;
  1271. }
  1272. }
  1273. }
  1274. }
  1275. return no_su_has_presence_state;
  1276. }
  1277. #if COMPILE_OUT
  1278. static int all_su_in_scope_has_presence_state (
  1279. struct amf_sg *sg, SaAmfPresenceStateT state)
  1280. {
  1281. struct amf_su **sus= sg->recovery_scope.sus;
  1282. while (*sus != NULL) {
  1283. if ((*sus)->saAmfSUPresenceState != state) {
  1284. break;
  1285. }
  1286. sus++;
  1287. }
  1288. return(*sus == NULL);
  1289. }
  1290. #endif
  1291. static int all_su_in_scope_has_either_two_presence_state (
  1292. amf_sg_t *sg,
  1293. SaAmfPresenceStateT state1,
  1294. SaAmfPresenceStateT state2)
  1295. {
  1296. struct amf_su **sus = sg->recovery_scope.sus;
  1297. while (*sus != NULL) {
  1298. if (!((*sus)->saAmfSUPresenceState == state1 ||
  1299. (*sus)->saAmfSUPresenceState == state2)) {
  1300. break;
  1301. }
  1302. sus++;
  1303. }
  1304. return (*sus == NULL);
  1305. }
  1306. static int all_su_in_scope_has_either_of_three_presence_state (amf_sg_t *sg,
  1307. SaAmfPresenceStateT state1, SaAmfPresenceStateT state2,
  1308. SaAmfPresenceStateT state3)
  1309. {
  1310. struct amf_su **sus = sg->recovery_scope.sus;
  1311. while (*sus != NULL) {
  1312. if (!((*sus)->saAmfSUPresenceState == state1 ||
  1313. (*sus)->saAmfSUPresenceState == state2 ||
  1314. (*sus)->saAmfSUPresenceState == state3)) {
  1315. break;
  1316. }
  1317. sus++;
  1318. }
  1319. return (*sus == NULL);
  1320. }
  1321. /**
  1322. * Get number of SIs protected by the specified SG.
  1323. * @param sg
  1324. *
  1325. * @return int
  1326. */
  1327. static int sg_si_count_get (struct amf_sg *sg)
  1328. {
  1329. struct amf_si *si;
  1330. int cnt = 0;
  1331. for (si = sg->application->si_head; si != NULL; si = si->next) {
  1332. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  1333. cnt += 1;
  1334. }
  1335. }
  1336. return(cnt);
  1337. }
  1338. static int amf_si_get_saAmfSINumReqActiveAssignments(struct amf_si *si)
  1339. {
  1340. struct amf_si_assignment *si_assignment = si->assigned_sis;
  1341. int number_of_req_active_assignments = 0;
  1342. for (; si_assignment != NULL; si_assignment = si_assignment->next) {
  1343. if (si_assignment->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1344. number_of_req_active_assignments++;
  1345. }
  1346. }
  1347. return number_of_req_active_assignments;
  1348. }
  1349. static int amf_si_get_saAmfSINumReqStandbyAssignments(struct amf_si *si)
  1350. {
  1351. struct amf_si_assignment *si_assignment = si->assigned_sis;
  1352. int number_of_req_active_assignments = 0;
  1353. for (; si_assignment != NULL; si_assignment = si_assignment->next) {
  1354. if (si_assignment->requested_ha_state == SA_AMF_HA_STANDBY) {
  1355. number_of_req_active_assignments++;
  1356. }
  1357. }
  1358. return number_of_req_active_assignments;
  1359. }
  1360. static int sg_assign_active_nplusm (struct amf_sg *sg, int su_active_assign)
  1361. {
  1362. struct amf_su *su;
  1363. struct amf_si *si;
  1364. int assigned = 0;
  1365. int assign_to_su = 0;
  1366. int total_assigned = 0;
  1367. int si_left;
  1368. int si_total;
  1369. int su_left_to_assign = su_active_assign;
  1370. ENTER("SG: %s", sg->name.value);
  1371. si_total = sg_si_count_get (sg);
  1372. si_left = si_total;
  1373. assign_to_su = div_round (si_left, su_active_assign);
  1374. if (assign_to_su > sg->saAmfSGMaxActiveSIsperSUs) {
  1375. assign_to_su = sg->saAmfSGMaxActiveSIsperSUs;
  1376. }
  1377. su = sg->su_head;
  1378. while (su != NULL && su_left_to_assign > 0) {
  1379. if (amf_su_get_saAmfSUReadinessState (su) !=
  1380. SA_AMF_READINESS_IN_SERVICE ||
  1381. amf_su_get_saAmfSUNumCurrActiveSIs (su) == assign_to_su ||
  1382. amf_su_get_saAmfSUNumCurrStandbySIs (su) > 0) {
  1383. su = su->next;
  1384. continue; /* Not in service */
  1385. }
  1386. si = sg->application->si_head;
  1387. assigned = 0;
  1388. assign_to_su = div_round (si_left, su_left_to_assign);
  1389. if (assign_to_su > sg->saAmfSGMaxActiveSIsperSUs) {
  1390. assign_to_su = sg->saAmfSGMaxActiveSIsperSUs;
  1391. }
  1392. while (si != NULL) {
  1393. if (name_match (&si->saAmfSIProtectedbySG, &sg->name) &&
  1394. assigned < assign_to_su &&
  1395. amf_si_get_saAmfSINumReqActiveAssignments(si) == 0) {
  1396. assigned += 1;
  1397. total_assigned += 1;
  1398. amf_su_assign_si (su, si, SA_AMF_HA_ACTIVE);
  1399. }
  1400. si = si->next;
  1401. }
  1402. su = su->next;
  1403. su_left_to_assign -= 1;
  1404. si_left -= assigned;
  1405. dprintf (" su_left_to_assign =%d, si_left=%d\n",
  1406. su_left_to_assign, si_left);
  1407. }
  1408. assert (total_assigned <= si_total);
  1409. if (total_assigned == 0) {
  1410. dprintf ("Info: No SIs assigned");
  1411. }
  1412. return total_assigned;
  1413. }
  1414. static int sg_assign_standby_nplusm (struct amf_sg *sg, int su_standby_assign)
  1415. {
  1416. struct amf_su *su;
  1417. struct amf_si *si;
  1418. int assigned = 0;
  1419. int assign_to_su = 0;
  1420. int total_assigned = 0;
  1421. int si_left;
  1422. int si_total;
  1423. int su_left_to_assign = su_standby_assign;
  1424. ENTER ("'%s'", sg->name.value);
  1425. if (su_standby_assign == 0) {
  1426. return 0;
  1427. }
  1428. si_total = sg_si_count_get (sg);
  1429. si_left = si_total;
  1430. assign_to_su = div_round (si_left, su_standby_assign);
  1431. if (assign_to_su > sg->saAmfSGMaxStandbySIsperSUs) {
  1432. assign_to_su = sg->saAmfSGMaxStandbySIsperSUs;
  1433. }
  1434. su = sg->su_head;
  1435. while (su != NULL && su_left_to_assign > 0) {
  1436. if (amf_su_get_saAmfSUReadinessState (su) !=
  1437. SA_AMF_READINESS_IN_SERVICE ||
  1438. amf_su_get_saAmfSUNumCurrActiveSIs (su) > 0 ||
  1439. amf_su_get_saAmfSUNumCurrStandbySIs (su) ==
  1440. assign_to_su) {
  1441. su = su->next;
  1442. continue; /* Not available for assignment */
  1443. }
  1444. si = sg->application->si_head;
  1445. assigned = 0;
  1446. assign_to_su = div_round (si_left, su_left_to_assign);
  1447. if (assign_to_su > sg->saAmfSGMaxStandbySIsperSUs) {
  1448. assign_to_su = sg->saAmfSGMaxStandbySIsperSUs;
  1449. }
  1450. while (si != NULL) {
  1451. if (name_match (&si->saAmfSIProtectedbySG, &sg->name) &&
  1452. assigned < assign_to_su &&
  1453. amf_si_get_saAmfSINumReqStandbyAssignments (si) == 0) {
  1454. assigned += 1;
  1455. total_assigned += 1;
  1456. amf_su_assign_si (su, si, SA_AMF_HA_STANDBY);
  1457. }
  1458. si = si->next;
  1459. }
  1460. su_left_to_assign -= 1;
  1461. si_left -= assigned;
  1462. dprintf (" su_left_to_assign =%d, si_left=%d\n",
  1463. su_left_to_assign, si_left);
  1464. su = su->next;
  1465. }
  1466. assert (total_assigned <= si_total);
  1467. if (total_assigned == 0) {
  1468. dprintf ("Info: No SIs assigned!");
  1469. }
  1470. return total_assigned;
  1471. }
  1472. static int su_inservice_count_get (struct amf_sg *sg)
  1473. {
  1474. struct amf_su *su;
  1475. int answer = 0;
  1476. for (su = sg->su_head; su != NULL; su = su->next) {
  1477. if (amf_su_get_saAmfSUReadinessState (su) ==
  1478. SA_AMF_READINESS_IN_SERVICE) {
  1479. answer += 1;
  1480. }
  1481. }
  1482. return(answer);
  1483. }
  1484. static int su_active_out_of_service_count_get (amf_sg_t *sg)
  1485. {
  1486. int active_out_of_service_count = 0;
  1487. amf_su_t *su;
  1488. for (su = sg->su_head; su != NULL; su = su->next) {
  1489. amf_si_assignment_t *si_assignment;
  1490. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  1491. while (si_assignment != NULL) {
  1492. if ((si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) &&
  1493. (amf_su_get_saAmfSUReadinessState (su) ==
  1494. SA_AMF_READINESS_OUT_OF_SERVICE)) {
  1495. active_out_of_service_count += 1;
  1496. }
  1497. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  1498. }
  1499. }
  1500. return active_out_of_service_count;
  1501. }
  1502. static int su_standby_out_of_service_count_get (amf_sg_t *sg)
  1503. {
  1504. int active_out_of_service_count = 0;
  1505. amf_su_t *su;
  1506. for (su = sg->su_head; su != NULL; su = su->next) {
  1507. amf_si_assignment_t *si_assignment;
  1508. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  1509. while (si_assignment != NULL) {
  1510. if ((si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) &&
  1511. (amf_su_get_saAmfSUReadinessState (su) ==
  1512. SA_AMF_READINESS_OUT_OF_SERVICE)) {
  1513. active_out_of_service_count += 1;
  1514. }
  1515. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  1516. }
  1517. }
  1518. return active_out_of_service_count;
  1519. }
  1520. /**
  1521. * This function calculates the number of active and standby assignments that
  1522. * shall be done according to what is configured and the number of in-service
  1523. * SUs available. This function leaves possible existing assignments as they are
  1524. * but possibly adds new assignments. This function also initiates the transfer
  1525. * of the calculated assignments to the SUs that shall execute them.
  1526. *
  1527. * TODO: dependency_level not used, hard coded
  1528. * @param sg
  1529. * @param dependency_level
  1530. * @return - the sum of assignments initiated
  1531. */
  1532. static int assign_si (struct amf_sg *sg, int dependency_level)
  1533. {
  1534. int active_sus_needed = 0;
  1535. int standby_sus_needed = 0;
  1536. int inservice_count;
  1537. int su_active_assign;
  1538. int su_standby_assign;
  1539. int su_spare_assign;
  1540. int assigned = 0;
  1541. int active_out_of_service = 0;
  1542. int standby_out_of_service = 0;
  1543. ENTER ("'%s'", sg->name.value);
  1544. /**
  1545. * Phase 1: Calculate assignments and create all runtime objects in
  1546. * information model. Do not do the actual assignment, done in
  1547. * phase 2.
  1548. */
  1549. /**
  1550. * Calculate number of SUs to assign to active or standby state
  1551. */
  1552. inservice_count = su_inservice_count_get (sg);
  1553. active_out_of_service = su_active_out_of_service_count_get(sg);
  1554. standby_out_of_service = su_standby_out_of_service_count_get(sg);
  1555. if (sg->saAmfSGNumPrefActiveSUs > 0) {
  1556. active_sus_needed = div_round (
  1557. sg_si_count_get (sg),
  1558. sg->saAmfSGMaxActiveSIsperSUs);
  1559. } else {
  1560. log_printf (LOG_LEVEL_ERROR, "ERROR: saAmfSGNumPrefActiveSUs == 0 !!");
  1561. openais_exit_error (AIS_DONE_FATAL_ERR);
  1562. }
  1563. if (sg->saAmfSGNumPrefStandbySUs > 0) {
  1564. standby_sus_needed = div_round (
  1565. sg_si_count_get (sg),
  1566. sg->saAmfSGMaxStandbySIsperSUs);
  1567. } else {
  1568. log_printf (LOG_LEVEL_ERROR, "ERROR: saAmfSGNumPrefStandbySUs == 0 !!");
  1569. openais_exit_error (AIS_DONE_FATAL_ERR);
  1570. }
  1571. dprintf ("(inservice=%d) (active_sus_needed=%d) (standby_sus_needed=%d)"
  1572. "\n",
  1573. inservice_count, active_sus_needed, standby_sus_needed);
  1574. /* Determine number of active and standby service units
  1575. * to assign based upon reduction procedure
  1576. */
  1577. if ((inservice_count < active_sus_needed - active_out_of_service)) {
  1578. dprintf ("assignment VI - partial assignment with SIs drop outs\n");
  1579. su_active_assign = inservice_count;
  1580. su_standby_assign = 0;
  1581. su_spare_assign = 0;
  1582. } else
  1583. if ((inservice_count < active_sus_needed - active_out_of_service +
  1584. standby_sus_needed)) {
  1585. dprintf ("assignment V - partial assignment with reduction of"
  1586. " standby units\n");
  1587. su_active_assign = active_sus_needed;
  1588. su_standby_assign = inservice_count - active_sus_needed - active_out_of_service;
  1589. su_spare_assign = 0;
  1590. } else
  1591. if ((inservice_count < sg->saAmfSGNumPrefActiveSUs + standby_sus_needed)) {
  1592. dprintf ("IV: full assignment with reduction of active service"
  1593. " units\n");
  1594. su_active_assign = inservice_count - standby_sus_needed;
  1595. su_standby_assign = standby_sus_needed;
  1596. su_spare_assign = 0;
  1597. } else
  1598. if ((inservice_count <
  1599. sg->saAmfSGNumPrefActiveSUs + sg->saAmfSGNumPrefStandbySUs)) {
  1600. dprintf ("III: full assignment with reduction of standby service"
  1601. " units\n");
  1602. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  1603. su_standby_assign = inservice_count - sg->saAmfSGNumPrefActiveSUs;
  1604. su_spare_assign = 0;
  1605. } else
  1606. if ((inservice_count ==
  1607. sg->saAmfSGNumPrefActiveSUs + sg->saAmfSGNumPrefStandbySUs)) {
  1608. if (sg->saAmfSGNumPrefInserviceSUs > inservice_count) {
  1609. dprintf ("II: full assignment with spare reduction\n");
  1610. } else {
  1611. dprintf ("II: full assignment without spares\n");
  1612. }
  1613. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  1614. su_standby_assign = sg->saAmfSGNumPrefStandbySUs;
  1615. su_spare_assign = 0;
  1616. } else {
  1617. dprintf ("I: full assignment with spares\n");
  1618. su_active_assign = sg->saAmfSGNumPrefActiveSUs;
  1619. su_standby_assign = sg->saAmfSGNumPrefStandbySUs;
  1620. su_spare_assign = inservice_count -
  1621. sg->saAmfSGNumPrefActiveSUs - sg->saAmfSGNumPrefStandbySUs;
  1622. }
  1623. dprintf ("(inservice=%d) (assigning active=%d) (assigning standby=%d)"
  1624. " (assigning spares=%d)\n",
  1625. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1626. if (inservice_count > 0) {
  1627. assigned = sg_assign_active_nplusm (sg, su_active_assign);
  1628. assigned += sg_assign_standby_nplusm (sg, su_standby_assign);
  1629. sg->saAmfSGNumCurrAssignedSUs = inservice_count;
  1630. /**
  1631. * Phase 2: do the actual assignment to the component
  1632. * TODO: first do active, then standby
  1633. */
  1634. {
  1635. struct amf_si *si;
  1636. struct amf_si_assignment *si_assignment;
  1637. for (si = sg->application->si_head; si != NULL; si = si->next) {
  1638. if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) {
  1639. for (si_assignment = si->assigned_sis;
  1640. si_assignment != NULL;
  1641. si_assignment = si_assignment->next) {
  1642. if (si_assignment->requested_ha_state !=
  1643. si_assignment->saAmfSISUHAState) {
  1644. amf_si_ha_state_assume (
  1645. si_assignment, assign_si_assumed_cbfn);
  1646. }
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. LEAVE ("'%s'", sg->name.value);
  1653. return assigned;
  1654. }
  1655. #ifdef COMPILE_OUT
  1656. static void remove_si_in_scope (amf_sg_t *sg, amf_si_t *si)
  1657. {
  1658. int i;
  1659. int j;
  1660. amf_si_t **sis = sg->recovery_scope.sis;
  1661. amf_si_t **new_sis = amf_calloc (1, sizeof (amf_si_t*));
  1662. for (i = 0,j = 0; sis[i] != NULL; i++) {
  1663. if (sis[i] == si) {
  1664. continue;
  1665. }
  1666. new_sis[j] = sis[i];
  1667. new_sis = amf_realloc (new_sis, j + sizeof (amf_si_t *));
  1668. j++;
  1669. }
  1670. sg->recovery_scope.sis = new_sis;
  1671. }
  1672. #endif
  1673. #ifdef COMPILE_OUT
  1674. static void remove_sis_for_term_failed_su_from_scope (amf_sg_t *sg,
  1675. amf_su_t *su)
  1676. {
  1677. amf_comp_t *component;
  1678. /*
  1679. * foreach component with presense state termiantion failed in su
  1680. */
  1681. for (component = su->comp_head; component != NULL;
  1682. component = component->next) {
  1683. amf_csi_assignment_t *csi_assignment;
  1684. if (component->saAmfCompPresenceState !=
  1685. SA_AMF_PRESENCE_INSTANTIATION_FAILED) {
  1686. continue;
  1687. }
  1688. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1689. while (csi_assignment != NULL) {
  1690. remove_si_in_scope (sg, csi_assignment->csi->si);
  1691. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1692. }
  1693. }
  1694. }
  1695. #endif
  1696. /**
  1697. * This function returns 1 if the redundancy model is N plus M and at least one
  1698. * component of the specified SU has an active HA-state, else the function
  1699. * returns 0.
  1700. * @param sg
  1701. * @param su
  1702. * @return int
  1703. */
  1704. static int is_comp_in_active_ha_state_nplusm (
  1705. amf_sg_t *sg, amf_su_t *su)
  1706. {
  1707. amf_comp_t *component;
  1708. amf_csi_assignment_t *csi_assignment;
  1709. int comp_is_in_active_ha_state = 0;
  1710. if(sg->saAmfSGRedundancyModel == SA_AMF_NPM_REDUNDANCY_MODEL) {
  1711. for (component = su->comp_head; component != NULL;
  1712. component = component->next) {
  1713. csi_assignment = amf_comp_get_next_csi_assignment(component, NULL);
  1714. while (csi_assignment != NULL) {
  1715. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) {
  1716. comp_is_in_active_ha_state = 1;
  1717. goto out;
  1718. }
  1719. csi_assignment = amf_comp_get_next_csi_assignment(component,
  1720. csi_assignment);
  1721. }
  1722. }
  1723. }
  1724. out:
  1725. return comp_is_in_active_ha_state;
  1726. }
  1727. /**
  1728. * This function handles a change of presence state reported by an SU contained
  1729. * in specified SG. The new presence state is INSTANTIATED.
  1730. * @param sg
  1731. * @param su
  1732. */
  1733. static void sg_su_state_changed_to_instantiated (struct amf_sg *sg, struct amf_su *su)
  1734. {
  1735. ENTER("%s %s",sg->name.value, su->name.value);
  1736. switch (sg->avail_state) {
  1737. case SG_AC_InstantiatingServiceUnits:
  1738. if (no_su_has_presence_state(sg, sg->node_to_start,
  1739. SA_AMF_PRESENCE_INSTANTIATING)) {
  1740. acsm_enter_idle (sg);
  1741. }
  1742. break;
  1743. case SG_AC_ReparingSu:
  1744. if (no_su_has_presence_state(sg, sg->node_to_start,
  1745. SA_AMF_PRESENCE_INSTANTIATING)) {
  1746. if (all_su_in_scope_has_either_of_three_presence_state(
  1747. su->sg,
  1748. SA_AMF_PRESENCE_INSTANTIATED,
  1749. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  1750. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1751. su->sg->avail_state = SG_AC_AssigningWorkload;
  1752. if (assign_si (sg, 0) == 0) {
  1753. acsm_enter_idle (sg);
  1754. }
  1755. } else {
  1756. dprintf ("avail-state: %u", sg->avail_state);
  1757. assert (0);
  1758. }
  1759. }
  1760. break;
  1761. default:
  1762. dprintf ("avail-state: %u", sg->avail_state);
  1763. assert (0);
  1764. break;
  1765. }
  1766. }
  1767. /**
  1768. * This function handles a change of presence state reported by an SU contained
  1769. * in specified SG. The new presence state is UNINSTANTIATED.
  1770. * @param sg
  1771. * @param su
  1772. */
  1773. static void amf_sg_su_state_changed_to_uninstantiated (amf_sg_t *sg,
  1774. amf_su_t *su)
  1775. {
  1776. ENTER("%s %s",sg->name.value, su->name.value);
  1777. switch (sg->avail_state) {
  1778. case SG_AC_TerminatingSuspected:
  1779. if (no_su_has_presence_state(sg, sg->node_to_start,
  1780. SA_AMF_PRESENCE_TERMINATING)) {
  1781. if (all_su_in_scope_has_either_two_presence_state (sg,
  1782. SA_AMF_PRESENCE_UNINSTANTIATED,
  1783. SA_AMF_PRESENCE_TERMINATION_FAILED)) {
  1784. delete_si_assignments_in_scope (sg);
  1785. if (is_any_si_in_scope_assigned_standby (sg)) {
  1786. remove_all_suspected_sus (sg);
  1787. acsm_enter_removing_standby_assignments (sg);
  1788. } else { /*is_no_si_in_scope_assigned_standby*/
  1789. remove_all_suspected_sus (sg);
  1790. acsm_enter_assigning_standby_to_spare (sg);
  1791. }
  1792. }
  1793. }
  1794. break;
  1795. case SG_AC_ReparingSu:
  1796. if (no_su_has_presence_state(sg, sg->node_to_start,
  1797. SA_AMF_PRESENCE_TERMINATING)) {
  1798. if (all_su_in_scope_has_either_of_three_presence_state(
  1799. su->sg,
  1800. SA_AMF_PRESENCE_INSTANTIATED,
  1801. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  1802. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1803. su->sg->avail_state = SG_AC_AssigningWorkload;
  1804. if (assign_si (sg, 0) == 0) {
  1805. acsm_enter_idle (sg);
  1806. }
  1807. }
  1808. }
  1809. break;
  1810. default:
  1811. log_printf (LOG_ERR, "sg avail_state = %d", sg->avail_state);
  1812. assert (0);
  1813. break;
  1814. }
  1815. }
  1816. /**
  1817. * This function handles a change of presence state reported by an SU contained
  1818. * in specified SG. The new presence state is TERMINATION_FAILED.
  1819. * @param sg
  1820. * @param su
  1821. */
  1822. static void amf_sg_su_state_changed_to_termination_failed (amf_sg_t *sg,
  1823. amf_su_t *su)
  1824. {
  1825. ENTER("%s %s",sg->name.value, su->name.value);
  1826. if (no_su_has_presence_state(sg, sg->node_to_start,
  1827. SA_AMF_PRESENCE_TERMINATING)) {
  1828. if (is_comp_in_active_ha_state_nplusm (sg, su)) {
  1829. acsm_enter_idle (sg);
  1830. goto out;
  1831. }
  1832. if (all_su_in_scope_has_either_two_presence_state (sg,
  1833. SA_AMF_PRESENCE_UNINSTANTIATED,
  1834. SA_AMF_PRESENCE_TERMINATION_FAILED)) {
  1835. delete_si_assignments_in_scope (sg);
  1836. if (is_any_si_in_scope_assigned_standby (sg)) {
  1837. remove_all_suspected_sus (sg);
  1838. acsm_enter_removing_standby_assignments (sg);
  1839. } else { /*is_no_si_in_scope_assigned_standby*/
  1840. remove_all_suspected_sus (sg);
  1841. acsm_enter_assigning_standby_to_spare (sg);
  1842. }
  1843. }
  1844. }
  1845. out:
  1846. return;
  1847. }
  1848. /**
  1849. * This function handles a change of presence state reported by an SU contained
  1850. * in specified SG. The new presence state is INSTANTIATION_FAILED.
  1851. * @param sg
  1852. * @param su
  1853. */
  1854. static void amf_sg_su_state_changed_to_instantiation_failed (amf_sg_t *sg,
  1855. amf_su_t *su)
  1856. {
  1857. ENTER("%s %s",sg->name.value, su->name.value);
  1858. switch (sg->avail_state) {
  1859. case SG_AC_InstantiatingServiceUnits:
  1860. if (no_su_has_presence_state(sg, sg->node_to_start,
  1861. SA_AMF_PRESENCE_INSTANTIATING)) {
  1862. acsm_enter_idle (sg);
  1863. }
  1864. break;
  1865. case SG_AC_ReparingSu:
  1866. if (no_su_has_presence_state(sg, sg->node_to_start,
  1867. SA_AMF_PRESENCE_INSTANTIATING)) {
  1868. if (all_su_in_scope_has_either_of_three_presence_state(
  1869. su->sg,
  1870. SA_AMF_PRESENCE_INSTANTIATED,
  1871. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  1872. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1873. su->sg->avail_state = SG_AC_AssigningWorkload;
  1874. if (assign_si (sg, 0) == 0) {
  1875. acsm_enter_idle (sg);
  1876. }
  1877. }
  1878. }
  1879. break;
  1880. default:
  1881. /* TODO: Insert the assert (0) until solving defers in SU */
  1882. dprintf("sg->avail_state = %d", sg->avail_state);
  1883. break;
  1884. }
  1885. }
  1886. /******************************************************************************
  1887. * Event methods
  1888. *****************************************************************************/
  1889. /**
  1890. * This function starts all SUs in the SG or all SUs on a specified node.
  1891. * @param sg
  1892. * @param node - Node on which all SUs shall be started or
  1893. * NULL indicating that all SUs on all nodes shall be started.
  1894. * @return - No of SUs that has been attempted to start
  1895. */
  1896. int amf_sg_start (struct amf_sg *sg, struct amf_node *node)
  1897. {
  1898. sg->recovery_scope.event_type = SG_START_EV;
  1899. ENTER ("'%s'", sg->name.value);
  1900. int instantiated_sus = 0;
  1901. switch (sg->avail_state) {
  1902. case SG_AC_InstantiatingServiceUnits:
  1903. case SG_AC_Idle: {
  1904. amf_su_t *su;
  1905. sg_avail_control_state_t old_avail_state = sg->avail_state;
  1906. ENTER ("'%s'", sg->name.value);
  1907. sg->node_to_start = node;
  1908. sg->avail_state = SG_AC_InstantiatingServiceUnits;
  1909. for (su = sg->su_head;
  1910. (su != NULL) &&
  1911. (instantiated_sus < sg->saAmfSGNumPrefInserviceSUs);
  1912. su = su->next) {
  1913. if (is_cluster_start (node)) {
  1914. amf_su_instantiate (su);
  1915. instantiated_sus++;
  1916. } else { /*is_not_cluster_start*/
  1917. /*
  1918. * Node start, match if SU is hosted on the
  1919. * specified node
  1920. */
  1921. if (name_match (&node->name,
  1922. &su->saAmfSUHostedByNode)) {
  1923. amf_su_instantiate (su);
  1924. instantiated_sus++;
  1925. }
  1926. }
  1927. }
  1928. if (instantiated_sus == 0) {
  1929. sg->avail_state = old_avail_state;
  1930. }
  1931. break;
  1932. }
  1933. case SG_AC_DeactivatingDependantWorkload:
  1934. case SG_AC_TerminatingSuspected:
  1935. case SG_AC_ActivatingStandby:
  1936. case SG_AC_AssigningStandbyToSpare:
  1937. case SG_AC_ReparingComponent:
  1938. case SG_AC_ReparingSu:
  1939. case SG_AC_AssigningOnRequest:
  1940. case SG_AC_RemovingAssignment:
  1941. case SG_AC_AssigningActiveworkload:
  1942. case SG_AC_AssigningAutoAdjust:
  1943. case SG_AC_AssigningWorkload:
  1944. case SG_AC_WaitingAfterOperationFailed:
  1945. case SG_AC_RemovingStandbyAssignments:
  1946. default:
  1947. assert (0);
  1948. break;
  1949. }
  1950. return instantiated_sus;
  1951. }
  1952. /**
  1953. * This function initiates assignment of the subset of the workload which
  1954. * matches the specified workload dependency level, to all SUs contained in the
  1955. * SG according to the requirements specified in the configuration.
  1956. * @param sg -
  1957. * @param dependency_level - Dependency level to assign
  1958. * @return - No of SUs that has been attempted to start
  1959. */
  1960. int amf_sg_assign_si_req (struct amf_sg *sg, int dependency_level)
  1961. {
  1962. /* TODO: Introduce state control in this function
  1963. */
  1964. int posible_to_assign_si;
  1965. sg->recovery_scope.event_type = SG_ASSIGN_SI_EV;
  1966. sg->avail_state = SG_AC_AssigningOnRequest;
  1967. if ((posible_to_assign_si = assign_si (sg, dependency_level)) == 0) {
  1968. acsm_enter_idle (sg);
  1969. }
  1970. return posible_to_assign_si;
  1971. }
  1972. /**
  1973. * This function is called because an error has been detected and the analysis
  1974. * (done elsewhere) indicated that this error shall be recovered by a Node
  1975. * failover. This function initiates the recovery action 'Node failover'.
  1976. * @param sg
  1977. * @param su - SU to failover
  1978. * @param node -
  1979. */
  1980. void amf_sg_failover_node_req (struct amf_sg *sg, struct amf_node *node)
  1981. {
  1982. ENTER("'%s, %s'",node->name.value, sg->name.value);
  1983. sg_event_t sg_event;
  1984. switch (sg->avail_state) {
  1985. case SG_AC_Idle:
  1986. set_scope_for_failover_node(sg, node);
  1987. if (has_any_su_in_scope_active_workload (sg)) {
  1988. acsm_enter_deactivating_dependent_workload (sg);
  1989. } else {
  1990. amf_su_t **sus = sg->recovery_scope.sus;
  1991. /*
  1992. * Select next state depending on if some
  1993. * SU in the scope needs to be terminated.
  1994. */
  1995. while (*sus != NULL) {
  1996. amf_su_t *su = *sus;
  1997. ENTER("SU %s pr_state='%d'",su->name.value,
  1998. su->saAmfSUPresenceState);
  1999. if (su_presense_state_is_ored (su,
  2000. SA_AMF_PRESENCE_UNINSTANTIATED,
  2001. SA_AMF_PRESENCE_TERMINATION_FAILED,
  2002. SA_AMF_PRESENCE_INSTANTIATION_FAILED)) {
  2003. sus++;
  2004. continue;
  2005. }
  2006. break;
  2007. }
  2008. if (*sus != NULL) {
  2009. acsm_enter_terminating_suspected (sg);
  2010. } else {
  2011. delete_si_assignments_in_scope (sg);
  2012. acsm_enter_idle (sg);
  2013. }
  2014. }
  2015. break;
  2016. case SG_AC_DeactivatingDependantWorkload:
  2017. case SG_AC_TerminatingSuspected:
  2018. case SG_AC_ActivatingStandby:
  2019. case SG_AC_AssigningStandbyToSpare:
  2020. case SG_AC_ReparingComponent:
  2021. case SG_AC_ReparingSu:
  2022. case SG_AC_AssigningOnRequest:
  2023. case SG_AC_InstantiatingServiceUnits:
  2024. case SG_AC_RemovingAssignment:
  2025. case SG_AC_AssigningActiveworkload:
  2026. case SG_AC_AssigningAutoAdjust:
  2027. case SG_AC_AssigningWorkload:
  2028. case SG_AC_WaitingAfterOperationFailed:
  2029. case SG_AC_RemovingStandbyAssignments:
  2030. sg_set_event (SG_FAILOVER_NODE_EV, sg, 0, 0, node, &sg_event);
  2031. sg_defer_event (SG_FAILOVER_NODE_EV, &sg_event);
  2032. break;
  2033. default:
  2034. assert (0);
  2035. break;
  2036. }
  2037. }
  2038. /**
  2039. * This function is called because an error has been detected and the analysis
  2040. * (done elsewhere) indicated that this error shall be recovered by an SU
  2041. * failover. This function initiates the recovery action 'SU failover'.
  2042. * @param sg
  2043. * @param su - SU to failover
  2044. * @param node -
  2045. */
  2046. void amf_sg_failover_su_req (struct amf_sg *sg, struct amf_su *su,
  2047. struct amf_node *node)
  2048. {
  2049. ENTER ("%s", su->name.value);
  2050. sg_event_t sg_event;
  2051. switch (sg->avail_state) {
  2052. case SG_AC_Idle:
  2053. su->su_failover_cnt += 1;
  2054. set_scope_for_failover_su (sg, su);
  2055. if (has_any_su_in_scope_active_workload (sg)) {
  2056. acsm_enter_deactivating_dependent_workload (sg);
  2057. } else {
  2058. acsm_enter_terminating_suspected (sg);
  2059. }
  2060. break;
  2061. case SG_AC_DeactivatingDependantWorkload:
  2062. case SG_AC_TerminatingSuspected:
  2063. case SG_AC_ActivatingStandby:
  2064. case SG_AC_AssigningStandbyToSpare:
  2065. case SG_AC_ReparingComponent:
  2066. case SG_AC_ReparingSu:
  2067. case SG_AC_AssigningOnRequest:
  2068. case SG_AC_InstantiatingServiceUnits:
  2069. case SG_AC_RemovingAssignment:
  2070. case SG_AC_AssigningActiveworkload:
  2071. case SG_AC_AssigningAutoAdjust:
  2072. case SG_AC_AssigningWorkload:
  2073. case SG_AC_WaitingAfterOperationFailed:
  2074. case SG_AC_RemovingStandbyAssignments:
  2075. sg_set_event (SG_FAILOVER_SU_EV, sg, su, 0, 0, &sg_event);
  2076. sg_defer_event (SG_FAILOVER_SU_EV, &sg_event);
  2077. break;
  2078. default:
  2079. assert (0);
  2080. break;
  2081. }
  2082. }
  2083. /******************************************************************************
  2084. * Event response methods
  2085. *****************************************************************************/
  2086. #ifdef COMPILE_OUT
  2087. void amf_sg_su_state_changed_2 (struct amf_sg *sg,
  2088. struct amf_su *su, SaAmfStateT type, int state)
  2089. {
  2090. ENTER ("'%s' SU '%s' state %s",
  2091. sg->name.value, su->name.value, amf_presence_state(state));
  2092. if (type == SA_AMF_PRESENCE_STATE) {
  2093. if (state == SA_AMF_PRESENCE_INSTANTIATED) {
  2094. if (sg->avail_state == SG_AC_InstantiatingServiceUnits) {
  2095. if (no_su_has_presence_state(sg, sg->node_to_start,
  2096. SA_AMF_PRESENCE_INSTANTIATING)) {
  2097. acsm_enter_idle (sg);
  2098. }
  2099. } else if (sg->avail_state == SG_AC_ReparingSu) {
  2100. if (all_su_in_scope_has_either_of_three_presence_state(
  2101. su->sg,
  2102. SA_AMF_PRESENCE_INSTANTIATED,
  2103. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  2104. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  2105. su->sg->avail_state = SG_AC_AssigningWorkload;
  2106. if (assign_si (sg, 0) == 0) {
  2107. acsm_enter_idle (sg);
  2108. }
  2109. } else {
  2110. dprintf ("avail-state: %u", sg->avail_state);
  2111. assert (0);
  2112. }
  2113. } else {
  2114. dprintf ("avail-state: %u", sg->avail_state);
  2115. assert (0);
  2116. }
  2117. } else if (state == SA_AMF_PRESENCE_UNINSTANTIATED) {
  2118. if (sg->avail_state == SG_AC_TerminatingSuspected) {
  2119. if (all_su_in_scope_has_either_two_presence_state (sg,
  2120. SA_AMF_PRESENCE_UNINSTANTIATED,
  2121. SA_AMF_PRESENCE_TERMINATION_FAILED)) {
  2122. delete_si_assignments_in_scope (sg);
  2123. if (is_any_si_in_scope_assigned_standby (sg)) {
  2124. remove_all_suspected_sus (sg);
  2125. acsm_enter_removing_standby_assignments (sg);
  2126. } else { /*is_no_si_in_scope_assigned_standby*/
  2127. remove_all_suspected_sus (sg);
  2128. acsm_enter_assigning_standby_to_spare (sg);
  2129. }
  2130. }
  2131. } else if (sg->avail_state == SG_AC_ReparingSu) {
  2132. if (all_su_in_scope_has_either_of_three_presence_state(
  2133. su->sg,
  2134. SA_AMF_PRESENCE_INSTANTIATED,
  2135. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  2136. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  2137. su->sg->avail_state = SG_AC_AssigningWorkload;
  2138. if (assign_si (sg, 0) == 0) {
  2139. acsm_enter_idle (sg);
  2140. }
  2141. } else {
  2142. dprintf("%d",sg->avail_state);
  2143. assert (0);
  2144. }
  2145. }
  2146. } else if (state == SA_AMF_PRESENCE_TERMINATION_FAILED) {
  2147. if (all_su_in_scope_has_either_two_presence_state (sg,
  2148. SA_AMF_PRESENCE_UNINSTANTIATED,
  2149. SA_AMF_PRESENCE_TERMINATION_FAILED) &&
  2150. is_any_si_in_scope_assigned_standby (sg)) {
  2151. remove_all_suspected_sus (sg);
  2152. acsm_enter_removing_standby_assignments (sg);
  2153. } else if (all_su_in_scope_has_either_two_presence_state (sg,
  2154. SA_AMF_PRESENCE_UNINSTANTIATED,
  2155. SA_AMF_PRESENCE_TERMINATION_FAILED) &&
  2156. !is_any_si_in_scope_assigned_standby (sg)) {
  2157. remove_all_suspected_sus (sg);
  2158. acsm_enter_assigning_standby_to_spare (sg);
  2159. } else {
  2160. remove_sis_for_term_failed_su_from_scope (sg, su);
  2161. }
  2162. } else if (state == SA_AMF_PRESENCE_INSTANTIATING) {
  2163. ; /* nop */
  2164. } else if (state == SA_AMF_PRESENCE_INSTANTIATION_FAILED) {
  2165. if (sg->avail_state == SG_AC_InstantiatingServiceUnits) {
  2166. if (no_su_has_presence_state(sg, sg->node_to_start,
  2167. SA_AMF_PRESENCE_INSTANTIATING)) {
  2168. acsm_enter_idle (sg);
  2169. }
  2170. } else if (sg->avail_state == SG_AC_ReparingSu) {
  2171. if (all_su_in_scope_has_either_of_three_presence_state(
  2172. su->sg,
  2173. SA_AMF_PRESENCE_INSTANTIATED,
  2174. SA_AMF_PRESENCE_INSTANTIATION_FAILED,
  2175. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  2176. su->sg->avail_state = SG_AC_AssigningWorkload;
  2177. if (assign_si (sg, 0) == 0) {
  2178. acsm_enter_idle (sg);
  2179. }
  2180. }
  2181. } else {
  2182. /* TODO: Insert the assert (0) until solving defers in SU */
  2183. dprintf("sg->avail_state = %d, su instantiation state = %d",
  2184. sg->avail_state, state);
  2185. }
  2186. } else {
  2187. dprintf("sg->avail_state = %d, su instantiation state = %d",
  2188. sg->avail_state, state);
  2189. assert (0);
  2190. }
  2191. }
  2192. }
  2193. #endif
  2194. /**
  2195. * SU indicates to SG that one of its state machines has changed state.
  2196. * @param sg - SG which contains the SU that has changed state
  2197. * @param su - SU which has changed state
  2198. * @param type - Indicates which state machine that has changed state
  2199. * @param state - The new state that has been assumed.
  2200. *
  2201. */
  2202. void amf_sg_su_state_changed (struct amf_sg *sg, struct amf_su *su,
  2203. SaAmfStateT type, int state)
  2204. {
  2205. ENTER ("'%s' SU '%s' state %s",
  2206. sg->name.value, su->name.value, amf_presence_state(state));
  2207. if (sg->avail_state != SG_AC_Idle) {
  2208. if (type == SA_AMF_PRESENCE_STATE) {
  2209. switch (state) {
  2210. case SA_AMF_PRESENCE_INSTANTIATED:
  2211. sg_su_state_changed_to_instantiated(sg, su);
  2212. break;
  2213. case SA_AMF_PRESENCE_UNINSTANTIATED:
  2214. amf_sg_su_state_changed_to_uninstantiated(sg, su);
  2215. break;
  2216. case SA_AMF_PRESENCE_TERMINATION_FAILED:
  2217. amf_sg_su_state_changed_to_termination_failed(sg, su);
  2218. break;
  2219. case SA_AMF_PRESENCE_INSTANTIATING:
  2220. ; /* nop */
  2221. break;
  2222. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  2223. amf_sg_su_state_changed_to_instantiation_failed(sg, su);
  2224. break;
  2225. case SA_AMF_PRESENCE_TERMINATING:
  2226. ; /* nop */
  2227. break;
  2228. default :
  2229. dprintf("sg->avail_state = %d, su instantiation state = %d",
  2230. sg->avail_state, state);
  2231. assert (0);
  2232. break;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. /**
  2238. * Callback function used by SI when there is no dependent SI to
  2239. * deactivate.
  2240. * @param sg
  2241. */
  2242. static void dependent_si_deactivated_cbfn2 (struct amf_sg *sg)
  2243. {
  2244. struct amf_su **sus = sg->recovery_scope.sus;
  2245. ENTER("'%s'", sg->name.value);
  2246. /*
  2247. * Select next state depending on if some
  2248. * SU in the scope needs to be terminated.
  2249. */
  2250. while (*sus != NULL) {
  2251. amf_su_t *su = *sus;
  2252. ENTER("SU %s pr_state='%d'",su->name.value,
  2253. su->saAmfSUPresenceState);
  2254. if (su_presense_state_is_ored (su,
  2255. SA_AMF_PRESENCE_UNINSTANTIATED,
  2256. SA_AMF_PRESENCE_TERMINATION_FAILED,
  2257. SA_AMF_PRESENCE_INSTANTIATION_FAILED)) {
  2258. sus++;
  2259. continue;
  2260. }
  2261. break;
  2262. }
  2263. if (*sus != NULL) {
  2264. acsm_enter_terminating_suspected (sg);
  2265. } else {
  2266. delete_si_assignments_in_scope(sg);
  2267. acsm_enter_removing_standby_assignments (sg);
  2268. }
  2269. }
  2270. /**
  2271. * Callback function used by SI when an SI has been deactivated, i.e.
  2272. * transitioned from active HA-state to any other state.
  2273. * @param si_assignment
  2274. * @param result - Indicates the result of the operation.
  2275. */
  2276. static void dependent_si_deactivated_cbfn (
  2277. struct amf_si_assignment *si_assignment, int result)
  2278. {
  2279. struct amf_sg *sg = si_assignment->su->sg;
  2280. struct amf_su **sus = sg->recovery_scope.sus;
  2281. struct amf_su *su;
  2282. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  2283. /*
  2284. * If all SI assignments for all SUs in the SG are not pending,
  2285. * goto next state (TerminatingSuspected).
  2286. */
  2287. for (su = sg->su_head ; su != NULL; su = su->next) {
  2288. struct amf_si_assignment *si_assignment;
  2289. si_assignment = amf_su_get_next_si_assignment(su, NULL);
  2290. while (si_assignment != NULL) {
  2291. if (si_assignment->saAmfSISUHAState !=
  2292. si_assignment->requested_ha_state) {
  2293. goto still_wating;
  2294. }
  2295. si_assignment = amf_su_get_next_si_assignment(su,
  2296. si_assignment);
  2297. }
  2298. }
  2299. still_wating:
  2300. if (su == NULL) {
  2301. sus = si_assignment->su->sg->recovery_scope.sus;
  2302. /*
  2303. * Select next state depending on if some
  2304. * SU in the scope is needs to be terminated.
  2305. */
  2306. while (*sus != NULL) {
  2307. if (su_presense_state_is_not (*sus,
  2308. SA_AMF_PRESENCE_UNINSTANTIATED,
  2309. SA_AMF_PRESENCE_TERMINATION_FAILED,
  2310. SA_AMF_PRESENCE_INSTANTIATION_FAILED)) {
  2311. break;
  2312. }
  2313. sus++;
  2314. }
  2315. if (*sus != NULL) {
  2316. acsm_enter_terminating_suspected (sg);
  2317. } else {
  2318. acsm_enter_removing_standby_assignments (sg);
  2319. }
  2320. }
  2321. LEAVE("");
  2322. }
  2323. /**
  2324. * Callback function used by SI to indicate an SI has assumed a new HA-state or
  2325. * that the attempt to do so failed.
  2326. * @param si_assignment
  2327. * @param result - Indicates the result of the operation.
  2328. */
  2329. static void assign_si_assumed_cbfn (
  2330. struct amf_si_assignment *si_assignment, int result)
  2331. {
  2332. struct amf_sg *sg = si_assignment->su->sg;
  2333. int si_assignment_cnt = 0;
  2334. int confirmed_assignments = 0;
  2335. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  2336. switch (sg->avail_state) {
  2337. case SG_AC_AssigningOnRequest:
  2338. if (is_all_si_assigned (sg)) {
  2339. acsm_enter_idle (sg);
  2340. amf_application_sg_assigned (sg->application, sg);
  2341. } else {
  2342. dprintf ("%d, %d", si_assignment_cnt, confirmed_assignments);
  2343. }
  2344. break;
  2345. case SG_AC_AssigningWorkload:
  2346. {
  2347. if (is_all_si_assigned(sg)) {
  2348. acsm_enter_idle (sg);
  2349. }
  2350. break;
  2351. }
  2352. case SG_AC_AssigningStandbyToSpare:
  2353. {
  2354. if(is_all_si_assigned (sg)) {
  2355. /*
  2356. * All si_assignments has asumed
  2357. * Prescense state SA_AMF_HA_STANDBY
  2358. */
  2359. switch (sg->recovery_scope.event_type) {
  2360. case SG_FAILOVER_NODE_EV:
  2361. acsm_enter_idle (sg);
  2362. break;
  2363. case SG_FAILOVER_SU_EV:
  2364. if (sg->saAmfSGAutoRepair == SA_TRUE) {
  2365. acsm_enter_repairing_su (sg);
  2366. }
  2367. break;
  2368. default:
  2369. assert (0);
  2370. break;
  2371. }
  2372. } else {
  2373. si_assignment->saAmfSISUHAState = SA_AMF_HA_STANDBY;
  2374. }
  2375. }
  2376. break;
  2377. default:
  2378. dprintf ("%d, %d, %d", sg->avail_state, si_assignment_cnt,
  2379. confirmed_assignments);
  2380. amf_runtime_attributes_print (amf_cluster);
  2381. assert (0);
  2382. break;
  2383. }
  2384. }
  2385. /**
  2386. * Callback function used by SI when an SI has been activated, i.e. transitioned
  2387. * from any HA-state to an active HA-state.
  2388. * @param si_assignment
  2389. * @param result - Indicates the result of the operation.
  2390. */
  2391. static void standby_su_activated_cbfn (
  2392. struct amf_si_assignment *si_assignment, int result)
  2393. {
  2394. struct amf_su **sus = si_assignment->su->sg->recovery_scope.sus;
  2395. struct amf_si **sis = si_assignment->su->sg->recovery_scope.sis;
  2396. ENTER ("'%s', %d", si_assignment->si->name.value, result);
  2397. /*
  2398. * If all SI assignments for all SIs in the scope are activated, goto next
  2399. * state.
  2400. */
  2401. while (*sis != NULL) {
  2402. if ((*sis)->assigned_sis != NULL &&
  2403. (*sis)->assigned_sis->saAmfSISUHAState != SA_AMF_HA_ACTIVE) {
  2404. break;
  2405. }
  2406. sis++;
  2407. }
  2408. if (*sis == NULL) {
  2409. acsm_enter_assigning_standby_to_spare ((*sus)->sg);
  2410. }
  2411. }
  2412. /******************************************************************************
  2413. * General methods
  2414. *****************************************************************************/
  2415. /**
  2416. * Constructor for SG objects. Adds SG to the list owned by
  2417. * the specified application. Always returns a valid SG
  2418. * object, out-of-memory problems are handled here. Default
  2419. * values are initialized.
  2420. * @param sg
  2421. * @param name
  2422. *
  2423. * @return struct amf_sg*
  2424. */
  2425. struct amf_sg *amf_sg_new (struct amf_application *app, char *name)
  2426. {
  2427. struct amf_sg *sg = amf_calloc (1, sizeof (struct amf_sg));
  2428. setSaNameT (&sg->name, name);
  2429. sg->saAmfSGAdminState = SA_AMF_ADMIN_UNLOCKED;
  2430. sg->saAmfSGNumPrefActiveSUs = 1;
  2431. sg->saAmfSGNumPrefStandbySUs = 1;
  2432. sg->saAmfSGNumPrefInserviceSUs = ~0;
  2433. sg->saAmfSGNumPrefAssignedSUs = ~0;
  2434. sg->saAmfSGCompRestartProb = -1;
  2435. sg->saAmfSGCompRestartMax = ~0;
  2436. sg->saAmfSGSuRestartProb = -1;
  2437. sg->saAmfSGSuRestartMax = ~0;
  2438. sg->saAmfSGAutoAdjustProb = -1;
  2439. sg->saAmfSGAutoRepair = SA_TRUE;
  2440. sg->application = app;
  2441. sg->next = app->sg_head;
  2442. app->sg_head = sg;
  2443. sg->deferred_events = NULL;
  2444. return sg;
  2445. }
  2446. void amf_sg_delete (struct amf_sg *sg)
  2447. {
  2448. struct amf_su *su;
  2449. for (su = sg->su_head; su != NULL;) {
  2450. struct amf_su *tmp = su;
  2451. su = su->next;
  2452. amf_su_delete (tmp);
  2453. }
  2454. free (sg);
  2455. }
  2456. void *amf_sg_serialize (struct amf_sg *sg, int *len)
  2457. {
  2458. char *buf = NULL;
  2459. int offset = 0, size = 0;
  2460. TRACE8 ("%s", sg->name.value);
  2461. buf = amf_serialize_SaNameT (buf, &size, &offset, &sg->name);
  2462. buf = amf_serialize_SaUint32T (buf, &size, &offset, sg->saAmfSGRedundancyModel);
  2463. buf = amf_serialize_SaUint32T (
  2464. buf, &size, &offset, sg->saAmfSGAutoAdjust);
  2465. buf = amf_serialize_SaUint32T (
  2466. buf, &size, &offset, sg->saAmfSGNumPrefActiveSUs);
  2467. buf = amf_serialize_SaUint32T (
  2468. buf, &size, &offset, sg->saAmfSGNumPrefStandbySUs);
  2469. buf = amf_serialize_SaUint32T (
  2470. buf, &size, &offset, sg->saAmfSGNumPrefInserviceSUs);
  2471. buf = amf_serialize_SaUint32T (
  2472. buf, &size, &offset, sg->saAmfSGNumPrefAssignedSUs);
  2473. buf = amf_serialize_SaUint32T (
  2474. buf, &size, &offset, sg->saAmfSGMaxActiveSIsperSUs);
  2475. buf = amf_serialize_SaUint32T (
  2476. buf, &size, &offset, sg->saAmfSGMaxStandbySIsperSUs);
  2477. buf = amf_serialize_SaUint32T (
  2478. buf, &size, &offset, sg->saAmfSGCompRestartProb);
  2479. buf = amf_serialize_SaUint32T (
  2480. buf, &size, &offset, sg->saAmfSGCompRestartMax);
  2481. buf = amf_serialize_SaUint32T (
  2482. buf, &size, &offset, sg->saAmfSGSuRestartProb);
  2483. buf = amf_serialize_SaUint32T (
  2484. buf, &size, &offset, sg->saAmfSGSuRestartMax);
  2485. buf = amf_serialize_SaUint32T (
  2486. buf, &size, &offset, sg->saAmfSGAutoAdjustProb);
  2487. buf = amf_serialize_SaUint32T (
  2488. buf, &size, &offset, sg->saAmfSGAutoRepair);
  2489. buf = amf_serialize_SaUint32T (
  2490. buf, &size, &offset, sg->saAmfSGAdminState);
  2491. buf = amf_serialize_SaUint32T (
  2492. buf, &size, &offset, sg->saAmfSGNumCurrAssignedSUs);
  2493. buf = amf_serialize_SaUint32T (
  2494. buf, &size, &offset, sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  2495. buf = amf_serialize_SaUint32T (
  2496. buf, &size, &offset, sg->saAmfSGNumCurrInstantiatedSpareSUs);
  2497. buf = amf_serialize_SaStringT (
  2498. buf, &size, &offset, sg->clccli_path);
  2499. buf = amf_serialize_SaUint32T (
  2500. buf, &size, &offset, sg->avail_state);
  2501. buf = amf_serialize_SaUint32T (
  2502. buf, &size, &offset, sg->recovery_scope.event_type);
  2503. *len = offset;
  2504. return buf;
  2505. }
  2506. struct amf_sg *amf_sg_deserialize (struct amf_application *app, char *buf)
  2507. {
  2508. char *tmp = buf;
  2509. struct amf_sg *sg = amf_sg_new (app, "");
  2510. tmp = amf_deserialize_SaNameT (tmp, &sg->name);
  2511. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGRedundancyModel);
  2512. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoAdjust);
  2513. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefActiveSUs);
  2514. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefStandbySUs);
  2515. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefInserviceSUs);
  2516. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefAssignedSUs);
  2517. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGMaxActiveSIsperSUs);
  2518. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGMaxStandbySIsperSUs);
  2519. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGCompRestartProb);
  2520. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGCompRestartMax);
  2521. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGSuRestartProb);
  2522. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGSuRestartMax);
  2523. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoAdjustProb);
  2524. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoRepair);
  2525. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAdminState);
  2526. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrAssignedSUs);
  2527. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  2528. tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrInstantiatedSpareSUs);
  2529. tmp = amf_deserialize_SaStringT (tmp, &sg->clccli_path);
  2530. tmp = amf_deserialize_SaUint32T (tmp, &sg->avail_state);
  2531. tmp = amf_deserialize_SaUint32T (tmp, &sg->recovery_scope.event_type);
  2532. return sg;
  2533. }
  2534. struct amf_sg *amf_sg_find (struct amf_application *app, char *name)
  2535. {
  2536. struct amf_sg *sg;
  2537. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  2538. if (sg->name.length == strlen(name) &&
  2539. strncmp (name, (char*)sg->name.value, sg->name.length) == 0) {
  2540. break;
  2541. }
  2542. }
  2543. return sg;
  2544. }