evt.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245
  1. /*
  2. * Copyright (c) 2004-2006 Mark Haverkamp
  3. * Copyright (c) 2004-2006 Open Source Development Lab
  4. *
  5. * All rights reserved.
  6. *
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither the name of the Open Source Development Lab nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. * THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #define DUMP_CHAN_INFO
  34. #define RECOVERY_EVENT_DEBUG LOG_LEVEL_DEBUG
  35. #define RECOVERY_DEBUG LOG_LEVEL_DEBUG
  36. #define CHAN_DEL_DEBUG LOG_LEVEL_DEBUG
  37. #define CHAN_OPEN_DEBUG LOG_LEVEL_DEBUG
  38. #define CHAN_UNLINK_DEBUG LOG_LEVEL_DEBUG
  39. #define REMOTE_OP_DEBUG LOG_LEVEL_DEBUG
  40. #define RETENTION_TIME_DEBUG LOG_LEVEL_DEBUG
  41. #include <sys/types.h>
  42. #include <stdlib.h>
  43. #include <errno.h>
  44. #include <sys/time.h>
  45. #include <sys/uio.h>
  46. #include <sys/socket.h>
  47. #include <netinet/in.h>
  48. #include <arpa/inet.h>
  49. #include "../include/hdb.h"
  50. #include "../include/ipc_evt.h"
  51. #include "../include/list.h"
  52. #include "../include/queue.h"
  53. #include "../lcr/lcr_comp.h"
  54. #include "util.h"
  55. #include "aispoll.h"
  56. #include "mempool.h"
  57. #include "main.h"
  58. #include "totemip.h"
  59. #include "totempg.h"
  60. #include "swab.h"
  61. #define LOG_SERVICE LOG_SERVICE_EVT
  62. #include "print.h"
  63. /*
  64. * event instance structure. Contains information about the
  65. * active connection to the API library.
  66. *
  67. * esi_version: Version that the library is running.
  68. * esi_open_chans: list of open channels associated with this
  69. * instance. Used to clean up any data left
  70. * allocated when the finalize is done.
  71. * (event_svr_channel_open.eco_instance_entry)
  72. * esi_events: list of pending events to be delivered on this
  73. * instance (struct chan_event_list.cel_entry)
  74. * esi_queue_blocked: non-zero if the delivery queue got too full
  75. * and we're blocking new messages until we
  76. * drain some of the queued messages.
  77. * esi_nevents: Number of events in events lists to be sent.
  78. * esi_hdb: Handle data base for open channels on this
  79. * instance. Used for a quick lookup of
  80. * open channel data from a lib api message.
  81. */
  82. struct libevt_pd {
  83. SaVersionT esi_version;
  84. struct list_head esi_open_chans;
  85. struct list_head esi_events[SA_EVT_LOWEST_PRIORITY+1];
  86. int esi_nevents;
  87. int esi_queue_blocked;
  88. struct hdb_handle_database esi_hdb;
  89. };
  90. enum evt_message_req_types {
  91. MESSAGE_REQ_EXEC_EVT_EVENTDATA = 0,
  92. MESSAGE_REQ_EXEC_EVT_CHANCMD = 1,
  93. MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA = 2
  94. };
  95. static void lib_evt_open_channel(void *conn, void *message);
  96. static void lib_evt_open_channel_async(void *conn, void *message);
  97. static void lib_evt_close_channel(void *conn, void *message);
  98. static void lib_evt_unlink_channel(void *conn, void *message);
  99. static void lib_evt_event_subscribe(void *conn, void *message);
  100. static void lib_evt_event_unsubscribe(void *conn, void *message);
  101. static void lib_evt_event_publish(void *conn, void *message);
  102. static void lib_evt_event_clear_retentiontime(void *conn, void *message);
  103. static void lib_evt_event_data_get(void *conn, void *message);
  104. static void evt_conf_change(
  105. enum totem_configuration_type configuration_type,
  106. struct totem_ip_address *member_list, int member_list_entries,
  107. struct totem_ip_address *left_list, int left_list_entries,
  108. struct totem_ip_address *joined_list, int joined_list_entries,
  109. struct memb_ring_id *ring_id);
  110. static int evt_lib_init(void *conn);
  111. static int evt_lib_exit(void *conn);
  112. static int evt_exec_init(struct openais_config *openais_config);
  113. /*
  114. * Recovery sync functions
  115. */
  116. static void evt_sync_init(void);
  117. static int evt_sync_process(void);
  118. static void evt_sync_activate(void);
  119. static void evt_sync_abort(void);
  120. static void convert_event(void *msg);
  121. static void convert_chan_packet(void *msg);
  122. static struct openais_lib_handler evt_lib_handlers[] = {
  123. {
  124. .lib_handler_fn = lib_evt_open_channel,
  125. .response_size = sizeof(struct res_evt_channel_open),
  126. .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL,
  127. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  128. },
  129. {
  130. .lib_handler_fn = lib_evt_open_channel_async,
  131. .response_size = sizeof(struct res_evt_channel_open),
  132. .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL,
  133. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  134. },
  135. {
  136. .lib_handler_fn = lib_evt_close_channel,
  137. .response_size = sizeof(struct res_evt_channel_close),
  138. .response_id = MESSAGE_RES_EVT_CLOSE_CHANNEL,
  139. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  140. },
  141. {
  142. .lib_handler_fn = lib_evt_unlink_channel,
  143. .response_size = sizeof(struct res_evt_channel_unlink),
  144. .response_id = MESSAGE_RES_EVT_UNLINK_CHANNEL,
  145. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  146. },
  147. {
  148. .lib_handler_fn = lib_evt_event_subscribe,
  149. .response_size = sizeof(struct res_evt_event_subscribe),
  150. .response_id = MESSAGE_RES_EVT_SUBSCRIBE,
  151. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  152. },
  153. {
  154. .lib_handler_fn = lib_evt_event_unsubscribe,
  155. .response_size = sizeof(struct res_evt_event_unsubscribe),
  156. .response_id = MESSAGE_RES_EVT_UNSUBSCRIBE,
  157. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  158. },
  159. {
  160. .lib_handler_fn = lib_evt_event_publish,
  161. .response_size = sizeof(struct res_evt_event_publish),
  162. .response_id = MESSAGE_RES_EVT_PUBLISH,
  163. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  164. },
  165. {
  166. .lib_handler_fn = lib_evt_event_clear_retentiontime,
  167. .response_size = sizeof(struct res_evt_event_clear_retentiontime),
  168. .response_id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME,
  169. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  170. },
  171. {
  172. .lib_handler_fn = lib_evt_event_data_get,
  173. .response_size = sizeof(struct lib_event_data),
  174. .response_id = MESSAGE_RES_EVT_EVENT_DATA,
  175. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  176. },
  177. };
  178. static void evt_remote_evt(void *msg, struct totem_ip_address *source_addr);
  179. static void evt_remote_recovery_evt(void *msg, struct totem_ip_address *source_addr);
  180. static void evt_remote_chan_op(void *msg, struct totem_ip_address *source_addr);
  181. static struct openais_exec_handler evt_exec_handlers[] = {
  182. {
  183. .exec_handler_fn = evt_remote_evt,
  184. .exec_endian_convert_fn = convert_event
  185. },
  186. {
  187. .exec_handler_fn = evt_remote_chan_op,
  188. .exec_endian_convert_fn = convert_chan_packet
  189. },
  190. {
  191. .exec_handler_fn = evt_remote_recovery_evt,
  192. .exec_endian_convert_fn = convert_event
  193. }
  194. };
  195. struct openais_service_handler evt_service_handler = {
  196. .name =
  197. (unsigned char*)"openais event service B.01.01",
  198. .id = EVT_SERVICE,
  199. .private_data_size = sizeof (struct libevt_pd),
  200. .lib_init_fn = evt_lib_init,
  201. .lib_exit_fn = evt_lib_exit,
  202. .lib_handlers = evt_lib_handlers,
  203. .lib_handlers_count = sizeof(evt_lib_handlers) / sizeof(struct openais_lib_handler),
  204. .exec_init_fn = evt_exec_init,
  205. .exec_handlers = evt_exec_handlers,
  206. .exec_handlers_count = sizeof(evt_exec_handlers) / sizeof(struct openais_exec_handler),
  207. .exec_dump_fn = NULL,
  208. .confchg_fn = evt_conf_change,
  209. .sync_init = evt_sync_init,
  210. .sync_process = evt_sync_process,
  211. .sync_activate = evt_sync_activate,
  212. .sync_abort = evt_sync_abort
  213. };
  214. struct openais_service_handler *evt_get_handler_ver0(void);
  215. struct openais_service_handler_iface_ver0 evt_service_handler_iface = {
  216. .openais_get_service_handler_ver0 = evt_get_handler_ver0
  217. };
  218. struct lcr_iface openais_evt_ver0[1] = {
  219. {
  220. .name = "openais_evt",
  221. .version = 0,
  222. .versions_replace = 0,
  223. .versions_replace_count = 0,
  224. .dependencies = 0,
  225. .dependency_count = 0,
  226. .constructor = NULL,
  227. .destructor = NULL,
  228. .interfaces = (void **)&evt_service_handler_iface,
  229. }
  230. };
  231. struct lcr_comp evt_comp_ver0 = {
  232. .iface_count = 1,
  233. .ifaces = openais_evt_ver0
  234. };
  235. struct openais_service_handler *evt_get_handler_ver0(void)
  236. {
  237. return (&evt_service_handler);
  238. }
  239. __attribute__ ((constructor)) static void evt_comp_register (void) {
  240. lcr_component_register (&evt_comp_ver0);
  241. }
  242. /*
  243. * list of all retained events
  244. * struct event_data
  245. */
  246. static DECLARE_LIST_INIT(retained_list);
  247. /*
  248. * list of all event channel information
  249. * struct event_svr_channel_instance
  250. */
  251. static DECLARE_LIST_INIT(esc_head);
  252. /*
  253. * list of all unlinked event channel information
  254. * struct event_svr_channel_instance
  255. */
  256. static DECLARE_LIST_INIT(esc_unlinked_head);
  257. /*
  258. * Track the state of event service recovery.
  259. *
  260. * evt_recovery_complete: Normal operational mode
  261. *
  262. * evt_send_event_id: Node is sending known last
  263. * event IDs.
  264. *
  265. * evt_send_open_count: Node is sending its open
  266. * Channel information.
  267. *
  268. * evt_wait_open_count_done: Node is done sending open channel data and
  269. * is waiting for the other nodes to finish.
  270. *
  271. * evt_send_retained_events: Node is sending retained event data.
  272. *
  273. * evt_send_retained_events_done: Node is sending done message.
  274. *
  275. * evt_wait_send_retained_events: Node is waiting for other nodes to
  276. * finish sending retained event data.
  277. */
  278. enum recovery_phases {
  279. evt_recovery_complete,
  280. evt_send_event_id,
  281. evt_send_open_count,
  282. evt_wait_open_count_done,
  283. evt_send_retained_events,
  284. evt_send_retained_events_done,
  285. evt_wait_send_retained_events
  286. };
  287. /*
  288. * Global varaibles used by the event service
  289. *
  290. * base_id_top: upper bits of next event ID to assign
  291. * base_id: Lower bits of Next event ID to assign
  292. * my_node_id: My cluster node id
  293. * checked_in: keep track during config change.
  294. * recovery_node: True if we're the recovery node. i.e. the
  295. * node that sends the retained events.
  296. * next_retained: pointer to next retained message to send
  297. * during recovery.
  298. * next_chan: pointer to next channel to send during recovery.
  299. * recovery_phase: Indicates what recovery is taking place.
  300. * left_member_count: How many left this configuration.
  301. * left_member_list: Members that left this config
  302. * joined_member_count: How many joined this configuration.
  303. * joined_member_list: Members that joined this config
  304. * total_member_count: how many members in this cluster
  305. * current_member_list: Total membership this config
  306. * trans_member_count: Node count in transitional membership
  307. * trans_member_list: Total membership from the transitional membership
  308. * add_count: count of joined members used for sending event id
  309. * recovery data.
  310. * add_list: pointer to joined list used for sending event id
  311. * recovery data.
  312. * processed_open_counts: Flag used to coordinate clearing open
  313. * channel counts for config change recovery.
  314. *
  315. */
  316. #define BASE_ID_MASK 0xffffffffLL
  317. static SaEvtEventIdT base_id = 1;
  318. static SaEvtEventIdT base_id_top = 0;
  319. static SaClmNodeIdT my_node_id = 0;
  320. static int checked_in = 0;
  321. static int recovery_node = 0;
  322. static struct list_head *next_retained = 0;
  323. static struct list_head *next_chan = 0;
  324. static enum recovery_phases recovery_phase = evt_recovery_complete;
  325. static int left_member_count = 0;
  326. static struct totem_ip_address *left_member_list = 0;
  327. static int joined_member_count = 0;
  328. static struct totem_ip_address *joined_member_list = 0;
  329. static int total_member_count = 0;
  330. static struct totem_ip_address *current_member_list = 0;
  331. static int trans_member_count = 0;
  332. static struct totem_ip_address *trans_member_list = 0;
  333. static int add_count = 0;
  334. static struct totem_ip_address *add_list = 0;
  335. static int processed_open_counts = 0;
  336. /*
  337. * Structure to track pending channel open requests.
  338. * ocp_async: 1 for async open
  339. * ocp_invocation: invocation for async open
  340. * ocp_chan_name: requested channel
  341. * ocp_conn: conn for returning to the library.
  342. * ocp_open_flags: channel open flags
  343. * ocp_timer_handle: timer handle for sync open
  344. * ocp_serial_no: Identifier for the request
  345. * ocp_entry: list entry for pending open list.
  346. */
  347. struct open_chan_pending {
  348. int ocp_async;
  349. SaInvocationT ocp_invocation;
  350. SaNameT ocp_chan_name;
  351. void *ocp_conn;
  352. SaEvtChannelOpenFlagsT ocp_open_flag;
  353. poll_timer_handle ocp_timer_handle;
  354. uint64_t ocp_c_handle;
  355. uint64_t ocp_serial_no;
  356. struct list_head ocp_entry;
  357. };
  358. static uint64_t open_serial_no = 0;
  359. /*
  360. * code to indicate that the open request has timed out. The
  361. * invocation data element is used for this code since it is
  362. * only used by the open async call which cannot have a timeout.
  363. */
  364. #define OPEN_TIMED_OUT 0x5a6b5a6b5a6b5a6bLLU
  365. /*
  366. * list of pending channel opens
  367. */
  368. static DECLARE_LIST_INIT(open_pending);
  369. static void chan_open_timeout(void *data);
  370. /*
  371. * Structure to track pending channel unlink requests.
  372. * ucp_unlink_id: unlink ID of unlinked channel.
  373. * ucp_conn: conn for returning to the library.
  374. * ucp_entry: list entry for pending unlink list.
  375. */
  376. struct unlink_chan_pending {
  377. uint64_t ucp_unlink_id;
  378. void *ucp_conn;
  379. struct list_head ucp_entry;
  380. };
  381. /*
  382. * list of pending unlink requests
  383. */
  384. static DECLARE_LIST_INIT(unlink_pending);
  385. /*
  386. * Structure to track pending retention time clear requests.
  387. * rtc_event_id: event ID to clear.
  388. * rtc_conn: conn for returning to the library.
  389. * rtc_entry: list entry for pending clear list.
  390. */
  391. struct retention_time_clear_pending {
  392. SaEvtEventIdT rtc_event_id;
  393. void *rtc_conn;
  394. struct list_head rtc_entry;
  395. };
  396. /*
  397. * list of pending clear requests.
  398. */
  399. static DECLARE_LIST_INIT(clear_pending);
  400. /*
  401. * Next unlink ID
  402. */
  403. static uint64_t base_unlink_id = 0;
  404. inline uint64_t
  405. next_chan_unlink_id()
  406. {
  407. uint64_t uid = my_node_id;
  408. uid = (uid << 32ULL) | base_unlink_id;
  409. base_unlink_id = (base_unlink_id + 1ULL) & BASE_ID_MASK;
  410. return uid;
  411. }
  412. #define min(a,b) ((a) < (b) ? (a) : (b))
  413. /*
  414. * Throttle event delivery to applications to keep
  415. * the exec from using too much memory if the app is
  416. * slow to process its events.
  417. */
  418. #define MAX_EVT_DELIVERY_QUEUE 1000
  419. #define MIN_EVT_QUEUE_RESUME (MAX_EVT_DELIVERY_QUEUE / 2)
  420. static unsigned int evt_delivery_queue_size = MAX_EVT_DELIVERY_QUEUE;
  421. static unsigned int evt_delivery_queue_resume = MIN_EVT_QUEUE_RESUME;
  422. #define LOST_PUB "EVENT_SERIVCE"
  423. #define LOST_CHAN "LOST EVENT"
  424. /*
  425. * Event to send when the delivery queue gets too full
  426. */
  427. char lost_evt[] = SA_EVT_LOST_EVENT;
  428. static int dropped_event_size;
  429. static struct event_data *dropped_event;
  430. struct evt_pattern {
  431. SaEvtEventPatternT pat;
  432. char str[sizeof(lost_evt)];
  433. };
  434. static struct evt_pattern dropped_pattern = {
  435. .pat = {
  436. sizeof(lost_evt),
  437. sizeof(lost_evt),
  438. (SaUint8T *) &dropped_pattern.str[0]},
  439. .str = {SA_EVT_LOST_EVENT}
  440. };
  441. SaNameT lost_chan = {
  442. .value = LOST_CHAN,
  443. .length = sizeof(LOST_CHAN)
  444. };
  445. SaNameT dropped_publisher = {
  446. .value = LOST_PUB,
  447. .length = sizeof(LOST_PUB)
  448. };
  449. struct event_svr_channel_open;
  450. struct event_svr_channel_subscr;
  451. struct open_count {
  452. SaClmNodeIdT oc_node_id;
  453. int32_t oc_open_count;
  454. };
  455. /*
  456. * Structure to contain global channel releated information
  457. *
  458. * esc_channel_name: The name of this channel.
  459. * esc_total_opens: The total number of opens on this channel including
  460. * other nodes.
  461. * esc_local_opens: The number of opens on this channel for this node.
  462. * esc_oc_size: The total number of entries in esc_node_opens;
  463. * esc_node_opens: list of node IDs and how many opens are associated.
  464. * esc_retained_count: How many retained events for this channel
  465. * esc_open_chans: list of opens of this channel.
  466. * (event_svr_channel_open.eco_entry)
  467. * esc_entry: links to other channels. (used by esc_head)
  468. * esc_unlink_id: If non-zero, then the channel has been marked
  469. * for unlink. This unlink ID is used to
  470. * mark events still associated with current openings
  471. * so they get delivered to the proper recipients.
  472. */
  473. struct event_svr_channel_instance {
  474. SaNameT esc_channel_name;
  475. int32_t esc_total_opens;
  476. int32_t esc_local_opens;
  477. uint32_t esc_oc_size;
  478. struct open_count *esc_node_opens;
  479. uint32_t esc_retained_count;
  480. struct list_head esc_open_chans;
  481. struct list_head esc_entry;
  482. uint64_t esc_unlink_id;
  483. };
  484. /*
  485. * Has the event data in the correct format to send to the library API
  486. * with aditional field for accounting.
  487. *
  488. * ed_ref_count: how many other strutures are referencing.
  489. * ed_retained: retained event list.
  490. * ed_timer_handle: Timer handle for retained event expiration.
  491. * ed_delivered: arrays of open channel pointers that this event
  492. * has been delivered to. (only used for events
  493. * with a retention time).
  494. * ed_delivered_count: Number of entries available in ed_delivered.
  495. * ed_delivered_next: Next free spot in ed_delivered
  496. * ed_my_chan: pointer to the global channel instance associated
  497. * with this event.
  498. * ed_event: The event data formatted to be ready to send.
  499. */
  500. struct event_data {
  501. uint32_t ed_ref_count;
  502. struct list_head ed_retained;
  503. poll_timer_handle ed_timer_handle;
  504. struct event_svr_channel_open **ed_delivered;
  505. uint32_t ed_delivered_count;
  506. uint32_t ed_delivered_next;
  507. struct event_svr_channel_instance *ed_my_chan;
  508. struct lib_event_data ed_event;
  509. };
  510. /*
  511. * Contains a list of pending events to be delivered to a subscribed
  512. * application.
  513. *
  514. * cel_chan_handle: associated library channel handle
  515. * cel_sub_id: associated library subscription ID
  516. * cel_event: event structure to deliver.
  517. * cel_entry: list of pending events
  518. * (struct event_server_instance.esi_events)
  519. */
  520. struct chan_event_list {
  521. uint64_t cel_chan_handle;
  522. uint32_t cel_sub_id;
  523. struct event_data* cel_event;
  524. struct list_head cel_entry;
  525. };
  526. /*
  527. * Contains information about each open for a given channel
  528. *
  529. * eco_flags: How the channel was opened.
  530. * eco_lib_handle: channel handle in the app. Used for event delivery.
  531. * eco_my_handle: the handle used to access this data structure.
  532. * eco_channel: Pointer to global channel info.
  533. * eco_entry: links to other opeinings of this channel.
  534. * eco_instance_entry: links to other channel opeinings for the
  535. * associated server instance.
  536. * eco_subscr: head of list of sbuscriptions for this channel open.
  537. * (event_svr_channel_subscr.ecs_entry)
  538. * eco_conn: refrence to EvtInitialize who owns this open.
  539. */
  540. struct event_svr_channel_open {
  541. uint8_t eco_flags;
  542. uint64_t eco_lib_handle;
  543. uint32_t eco_my_handle;
  544. struct event_svr_channel_instance *eco_channel;
  545. struct list_head eco_entry;
  546. struct list_head eco_instance_entry;
  547. struct list_head eco_subscr;
  548. void *eco_conn;
  549. };
  550. /*
  551. * Contains information about each channel subscription
  552. *
  553. * ecs_open_chan: Link to our open channel.
  554. * ecs_sub_id: Subscription ID.
  555. * ecs_filter_count: number of filters in ecs_filters
  556. * ecs_filters: filters for determining event delivery.
  557. * ecs_entry: Links to other subscriptions to this channel opening.
  558. */
  559. struct event_svr_channel_subscr {
  560. struct event_svr_channel_open *ecs_open_chan;
  561. uint32_t ecs_sub_id;
  562. SaEvtEventFilterArrayT *ecs_filters;
  563. struct list_head ecs_entry;
  564. };
  565. /*
  566. * Member node data
  567. * mn_node_info: cluster node info from membership
  568. * mn_last_msg_id: last seen message ID for this node
  569. * mn_started: Indicates that event service has started
  570. * on this node.
  571. * mn_next: pointer to the next node in the hash chain.
  572. * mn_entry: List of all nodes.
  573. */
  574. struct member_node_data {
  575. struct totem_ip_address mn_node_addr;
  576. SaClmClusterNodeT mn_node_info;
  577. SaEvtEventIdT mn_last_msg_id;
  578. SaClmNodeIdT mn_started;
  579. struct member_node_data *mn_next;
  580. struct list_head mn_entry;
  581. };
  582. DECLARE_LIST_INIT(mnd);
  583. /*
  584. * Take the filters we received from the application via the library and
  585. * make them into a real SaEvtEventFilterArrayT
  586. */
  587. static SaAisErrorT evtfilt_to_aisfilt(struct req_evt_event_subscribe *req,
  588. SaEvtEventFilterArrayT **evtfilters)
  589. {
  590. SaEvtEventFilterArrayT *filta =
  591. (SaEvtEventFilterArrayT *)req->ics_filter_data;
  592. SaEvtEventFilterArrayT *filters;
  593. SaEvtEventFilterT *filt = (void *)filta + sizeof(SaEvtEventFilterArrayT);
  594. SaUint8T *str = (void *)filta + sizeof(SaEvtEventFilterArrayT) +
  595. (sizeof(SaEvtEventFilterT) * filta->filtersNumber);
  596. int i;
  597. int j;
  598. filters = malloc(sizeof(SaEvtEventFilterArrayT));
  599. if (!filters) {
  600. return SA_AIS_ERR_NO_MEMORY;
  601. }
  602. filters->filtersNumber = filta->filtersNumber;
  603. filters->filters = malloc(sizeof(SaEvtEventFilterT) *
  604. filta->filtersNumber);
  605. if (!filters->filters) {
  606. free(filters);
  607. return SA_AIS_ERR_NO_MEMORY;
  608. }
  609. for (i = 0; i < filters->filtersNumber; i++) {
  610. filters->filters[i].filter.pattern =
  611. malloc(filt[i].filter.patternSize);
  612. if (!filters->filters[i].filter.pattern) {
  613. for (j = 0; j < i; j++) {
  614. free(filters->filters[j].filter.pattern);
  615. }
  616. free(filters->filters);
  617. free(filters);
  618. return SA_AIS_ERR_NO_MEMORY;
  619. }
  620. filters->filters[i].filter.patternSize =
  621. filt[i].filter.patternSize;
  622. filters->filters[i].filter.allocatedSize =
  623. filt[i].filter.patternSize;
  624. memcpy(filters->filters[i].filter.pattern,
  625. str, filters->filters[i].filter.patternSize);
  626. filters->filters[i].filterType = filt[i].filterType;
  627. str += filters->filters[i].filter.patternSize;
  628. }
  629. *evtfilters = filters;
  630. return SA_AIS_OK;
  631. }
  632. /*
  633. * Free up filter data
  634. */
  635. static void free_filters(SaEvtEventFilterArrayT *fp)
  636. {
  637. int i;
  638. for (i = 0; i < fp->filtersNumber; i++) {
  639. free(fp->filters[i].filter.pattern);
  640. }
  641. free(fp->filters);
  642. free(fp);
  643. }
  644. /*
  645. * Look up a channel in the global channel list
  646. */
  647. static struct event_svr_channel_instance *
  648. find_channel(SaNameT *chan_name, uint64_t unlink_id)
  649. {
  650. struct list_head *l, *head;
  651. struct event_svr_channel_instance *eci;
  652. /*
  653. * choose which list to look through
  654. */
  655. if (unlink_id == EVT_CHAN_ACTIVE) {
  656. head = &esc_head;
  657. } else {
  658. head = &esc_unlinked_head;
  659. }
  660. for (l = head->next; l != head; l = l->next) {
  661. eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
  662. if (!name_match(chan_name, &eci->esc_channel_name)) {
  663. continue;
  664. } else if (unlink_id != eci->esc_unlink_id) {
  665. continue;
  666. }
  667. return eci;
  668. }
  669. return 0;
  670. }
  671. /*
  672. * Find the last unlinked version of a channel.
  673. */
  674. static struct event_svr_channel_instance *
  675. find_last_unlinked_channel(SaNameT *chan_name)
  676. {
  677. struct list_head *l;
  678. struct event_svr_channel_instance *eci;
  679. /*
  680. * unlinked channels are added to the head of the list
  681. * so the first one we see is the last one added.
  682. */
  683. for (l = esc_unlinked_head.next; l != &esc_unlinked_head; l = l->next) {
  684. eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
  685. if (!name_match(chan_name, &eci->esc_channel_name)) {
  686. continue;
  687. }
  688. }
  689. return 0;
  690. }
  691. /*
  692. * Create and initialize a channel instance structure
  693. */
  694. static struct event_svr_channel_instance *create_channel(SaNameT *cn)
  695. {
  696. struct event_svr_channel_instance *eci;
  697. eci = (struct event_svr_channel_instance *) malloc(sizeof(*eci));
  698. if (!eci) {
  699. return (eci);
  700. }
  701. memset(eci, 0, sizeof(*eci));
  702. list_init(&eci->esc_entry);
  703. list_init(&eci->esc_open_chans);
  704. eci->esc_oc_size = total_member_count;
  705. eci->esc_node_opens =
  706. malloc(sizeof(struct open_count) * total_member_count);
  707. if (!eci->esc_node_opens) {
  708. free(eci);
  709. return 0;
  710. }
  711. memset(eci->esc_node_opens, 0,
  712. sizeof(struct open_count) * total_member_count);
  713. eci->esc_channel_name = *cn;
  714. eci->esc_channel_name.value[eci->esc_channel_name.length] = '\0';
  715. list_add(&eci->esc_entry, &esc_head);
  716. return eci;
  717. }
  718. /*
  719. * Make sure that the list of nodes is large enough to hold the whole
  720. * membership
  721. */
  722. static int check_open_size(struct event_svr_channel_instance *eci)
  723. {
  724. if (total_member_count > eci->esc_oc_size) {
  725. eci->esc_node_opens = realloc(eci->esc_node_opens,
  726. sizeof(struct open_count) * total_member_count);
  727. if (!eci->esc_node_opens) {
  728. log_printf(LOG_LEVEL_WARNING,
  729. "Memory error realloc of node list\n");
  730. return -1;
  731. }
  732. memset(&eci->esc_node_opens[eci->esc_oc_size], 0,
  733. sizeof(struct open_count) *
  734. (total_member_count - eci->esc_oc_size));
  735. eci->esc_oc_size = total_member_count;
  736. }
  737. return 0;
  738. }
  739. /*
  740. * Find the specified node ID in the node list of the channel.
  741. * If it's not in the list, add it.
  742. */
  743. static struct open_count* find_open_count(
  744. struct event_svr_channel_instance *eci,
  745. SaClmNodeIdT node_id)
  746. {
  747. int i;
  748. for (i = 0; i < eci->esc_oc_size; i++) {
  749. if (eci->esc_node_opens[i].oc_node_id == 0) {
  750. eci->esc_node_opens[i].oc_node_id = node_id;
  751. eci->esc_node_opens[i].oc_open_count = 0;
  752. }
  753. if (eci->esc_node_opens[i].oc_node_id == node_id) {
  754. return &eci->esc_node_opens[i];
  755. }
  756. }
  757. log_printf(LOG_LEVEL_DEBUG,
  758. "find_open_count: node id 0x%x not found\n",
  759. node_id);
  760. return 0;
  761. }
  762. static void dump_chan_opens(struct event_svr_channel_instance *eci)
  763. {
  764. int i;
  765. log_printf(LOG_LEVEL_NOTICE,
  766. "Channel %s, total %d, local %d\n",
  767. eci->esc_channel_name.value,
  768. eci->esc_total_opens,
  769. eci->esc_local_opens);
  770. for (i = 0; i < eci->esc_oc_size; i++) {
  771. if (eci->esc_node_opens[i].oc_node_id == 0) {
  772. break;
  773. }
  774. log_printf(LOG_LEVEL_NOTICE, "Node 0x%x, count %d\n",
  775. eci->esc_node_opens[i].oc_node_id,
  776. eci->esc_node_opens[i].oc_open_count);
  777. }
  778. }
  779. #ifdef DUMP_CHAN_INFO
  780. /*
  781. * Scan the list of channels and dump the open count info.
  782. */
  783. static void dump_all_chans()
  784. {
  785. struct list_head *l;
  786. struct event_svr_channel_instance *eci;
  787. for (l = esc_head.next; l != &esc_head; l = l->next) {
  788. eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
  789. dump_chan_opens(eci);
  790. }
  791. }
  792. #endif
  793. /*
  794. * Scan the list of channels and zero out the open counts
  795. */
  796. static void zero_chan_open_counts()
  797. {
  798. struct list_head *l;
  799. struct event_svr_channel_instance *eci;
  800. int i;
  801. for (l = esc_head.next; l != &esc_head; l = l->next) {
  802. eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
  803. for (i = 0; i < eci->esc_oc_size; i++) {
  804. if (eci->esc_node_opens[i].oc_node_id == 0) {
  805. break;
  806. }
  807. eci->esc_node_opens[i].oc_open_count = 0;
  808. }
  809. eci->esc_total_opens = 0;
  810. }
  811. }
  812. /*
  813. * Replace the current open count for a node with the specified value.
  814. */
  815. static int set_open_count(struct event_svr_channel_instance *eci,
  816. SaClmNodeIdT node_id, uint32_t open_count)
  817. {
  818. struct open_count *oc;
  819. int i;
  820. if ((i = check_open_size(eci)) != 0) {
  821. return i;
  822. }
  823. oc = find_open_count(eci, node_id);
  824. if (oc) {
  825. log_printf(RECOVERY_DEBUG,
  826. "Set count: Chan %s for node 0x%x, was %d, now %d\n",
  827. eci->esc_channel_name.value, node_id,
  828. oc->oc_open_count, open_count);
  829. eci->esc_total_opens -= oc->oc_open_count;
  830. eci->esc_total_opens += open_count;
  831. oc->oc_open_count = open_count;
  832. return 0;
  833. }
  834. return -1;
  835. }
  836. /*
  837. * Increment the open count for the specified node.
  838. */
  839. static int inc_open_count(struct event_svr_channel_instance *eci,
  840. SaClmNodeIdT node_id)
  841. {
  842. struct open_count *oc;
  843. int i;
  844. if ((i = check_open_size(eci)) != 0) {
  845. return i;
  846. }
  847. if (node_id == my_node_id) {
  848. eci->esc_local_opens++;
  849. }
  850. oc = find_open_count(eci, node_id);
  851. if (oc) {
  852. eci->esc_total_opens++;
  853. oc->oc_open_count++;
  854. return 0;
  855. }
  856. return -1;
  857. }
  858. /*
  859. * Decrement the open count for the specified node in the
  860. * specified channel.
  861. */
  862. static int dec_open_count(struct event_svr_channel_instance *eci,
  863. SaClmNodeIdT node_id)
  864. {
  865. struct open_count *oc;
  866. int i;
  867. if ((i = check_open_size(eci)) != 0) {
  868. return i;
  869. }
  870. if (node_id == my_node_id) {
  871. eci->esc_local_opens--;
  872. }
  873. oc = find_open_count(eci, node_id);
  874. if (oc) {
  875. eci->esc_total_opens--;
  876. oc->oc_open_count--;
  877. if ((eci->esc_total_opens < 0) || (oc->oc_open_count < 0)) {
  878. log_printf(LOG_LEVEL_ERROR, "Channel open decrement error\n");
  879. dump_chan_opens(eci);
  880. }
  881. return 0;
  882. }
  883. return -1;
  884. }
  885. /*
  886. * Remove a channel and free its memory if it's not in use anymore.
  887. */
  888. static void delete_channel(struct event_svr_channel_instance *eci)
  889. {
  890. log_printf(CHAN_DEL_DEBUG,
  891. "Called Delete channel %s t %d, l %d, r %d\n",
  892. eci->esc_channel_name.value,
  893. eci->esc_total_opens, eci->esc_local_opens,
  894. eci->esc_retained_count);
  895. /*
  896. * If no one has the channel open anywhere and there are no unexpired
  897. * retained events for this channel, and it has been marked for deletion
  898. * by an unlink, then it is OK to delete the data structure.
  899. */
  900. if ((eci->esc_retained_count == 0) && (eci->esc_total_opens == 0) &&
  901. (eci->esc_unlink_id != EVT_CHAN_ACTIVE)) {
  902. log_printf(CHAN_DEL_DEBUG, "Delete channel %s\n",
  903. eci->esc_channel_name.value);
  904. log_printf(CHAN_UNLINK_DEBUG, "Delete channel %s, unlink_id %0llx\n",
  905. eci->esc_channel_name.value, eci->esc_unlink_id);
  906. if (!list_empty(&eci->esc_open_chans)) {
  907. log_printf(LOG_LEVEL_NOTICE,
  908. "Last channel close request for %s (still open)\n",
  909. eci->esc_channel_name.value);
  910. dump_chan_opens(eci);
  911. return;
  912. }
  913. /*
  914. * adjust if we're sending open counts on a config change.
  915. */
  916. if ((recovery_phase != evt_recovery_complete) &&
  917. (&eci->esc_entry == next_chan)) {
  918. next_chan = eci->esc_entry.next;
  919. }
  920. list_del(&eci->esc_entry);
  921. if (eci->esc_node_opens) {
  922. free(eci->esc_node_opens);
  923. }
  924. free(eci);
  925. }
  926. }
  927. /*
  928. * Free up an event structure if it isn't being used anymore.
  929. */
  930. static void
  931. free_event_data(struct event_data *edp)
  932. {
  933. if (--edp->ed_ref_count) {
  934. return;
  935. }
  936. log_printf(LOG_LEVEL_DEBUG, "Freeing event ID: 0x%llx\n",
  937. edp->ed_event.led_event_id);
  938. if (edp->ed_delivered) {
  939. free(edp->ed_delivered);
  940. }
  941. free(edp);
  942. }
  943. /*
  944. * Mark a channel for deletion.
  945. */
  946. static void unlink_channel(struct event_svr_channel_instance *eci,
  947. uint64_t unlink_id)
  948. {
  949. struct event_data *edp;
  950. struct list_head *l, *nxt;
  951. log_printf(CHAN_UNLINK_DEBUG, "Unlink request: %s, id 0x%llx\n",
  952. eci->esc_channel_name.value, unlink_id);
  953. /*
  954. * The unlink ID is used to note that the channel has been marked
  955. * for deletion and is a way to distinguish between multiple
  956. * channels of the same name each marked for deletion.
  957. */
  958. eci->esc_unlink_id = unlink_id;
  959. /*
  960. * Move the unlinked channel to the unlinked list. This way
  961. * we don't have to worry about filtering it out when we need to
  962. * distribute retained events at recovery time.
  963. */
  964. list_del(&eci->esc_entry);
  965. list_add(&eci->esc_entry, &esc_unlinked_head);
  966. /*
  967. * Scan the retained event list and remove any retained events.
  968. * Since no new opens can occur there won't be any need of sending
  969. * retained events on the channel.
  970. */
  971. for (l = retained_list.next; l != &retained_list; l = nxt) {
  972. nxt = l->next;
  973. edp = list_entry(l, struct event_data, ed_retained);
  974. if ((edp->ed_my_chan == eci) &&
  975. (edp->ed_event.led_chan_unlink_id == EVT_CHAN_ACTIVE)) {
  976. poll_timer_delete(aisexec_poll_handle, edp->ed_timer_handle);
  977. edp->ed_event.led_retention_time = 0;
  978. list_del(&edp->ed_retained);
  979. list_init(&edp->ed_retained);
  980. edp->ed_my_chan->esc_retained_count--;
  981. log_printf(CHAN_UNLINK_DEBUG,
  982. "Unlink: Delete retained event id 0x%llx\n",
  983. edp->ed_event.led_event_id);
  984. free_event_data(edp);
  985. }
  986. }
  987. delete_channel(eci);
  988. }
  989. /*
  990. * Remove the specified node from the node list in this channel.
  991. */
  992. static int remove_open_count(
  993. struct event_svr_channel_instance *eci,
  994. SaClmNodeIdT node_id)
  995. {
  996. int i;
  997. int j;
  998. /*
  999. * Find the node, remove it and re-pack the array.
  1000. */
  1001. for (i = 0; i < eci->esc_oc_size; i++) {
  1002. if (eci->esc_node_opens[i].oc_node_id == 0) {
  1003. break;
  1004. }
  1005. log_printf(RECOVERY_DEBUG, "roc: %x/%x, t %d, oc %d\n",
  1006. node_id, eci->esc_node_opens[i].oc_node_id,
  1007. eci->esc_total_opens, eci->esc_node_opens[i].oc_open_count);
  1008. if (eci->esc_node_opens[i].oc_node_id == node_id) {
  1009. eci->esc_total_opens -= eci->esc_node_opens[i].oc_open_count;
  1010. for (j = i+1; j < eci->esc_oc_size; j++, i++) {
  1011. eci->esc_node_opens[i].oc_node_id =
  1012. eci->esc_node_opens[j].oc_node_id;
  1013. eci->esc_node_opens[i].oc_open_count =
  1014. eci->esc_node_opens[j].oc_open_count;
  1015. }
  1016. eci->esc_node_opens[eci->esc_oc_size-1].oc_node_id = 0;
  1017. eci->esc_node_opens[eci->esc_oc_size-1].oc_open_count = 0;
  1018. /*
  1019. * Remove the channel if it's not being used anymore
  1020. */
  1021. delete_channel(eci);
  1022. return 0;
  1023. }
  1024. }
  1025. return -1;
  1026. }
  1027. /*
  1028. * Send a request to open a channel to the rest of the cluster.
  1029. */
  1030. static SaAisErrorT evt_open_channel(SaNameT *cn, SaUint8T flgs)
  1031. {
  1032. struct req_evt_chan_command cpkt;
  1033. struct event_svr_channel_instance *eci;
  1034. struct iovec chn_iovec;
  1035. int res;
  1036. SaAisErrorT ret;
  1037. ret = SA_AIS_OK;
  1038. eci = find_channel(cn, EVT_CHAN_ACTIVE);
  1039. /*
  1040. * If the create flag set, and it doesn't exist, we can make the channel.
  1041. * Otherwise, it's an error since we're notified of channels being created
  1042. * and opened.
  1043. */
  1044. if (!eci && !(flgs & SA_EVT_CHANNEL_CREATE)) {
  1045. ret = SA_AIS_ERR_NOT_EXIST;
  1046. goto chan_open_end;
  1047. }
  1048. /*
  1049. * create the channel packet to send. Tell the the cluster
  1050. * to create the channel.
  1051. */
  1052. memset(&cpkt, 0, sizeof(cpkt));
  1053. cpkt.chc_head.id =
  1054. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  1055. cpkt.chc_head.size = sizeof(cpkt);
  1056. cpkt.chc_op = EVT_OPEN_CHAN_OP;
  1057. cpkt.u.chc_chan.ocr_name = *cn;
  1058. cpkt.u.chc_chan.ocr_serial_no = ++open_serial_no;
  1059. chn_iovec.iov_base = &cpkt;
  1060. chn_iovec.iov_len = cpkt.chc_head.size;
  1061. log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Send open mcast\n");
  1062. res = totempg_groups_mcast_joined(openais_group_handle,
  1063. &chn_iovec, 1, TOTEMPG_AGREED);
  1064. log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Open mcast result: %d\n",
  1065. res);
  1066. if (res != 0) {
  1067. ret = SA_AIS_ERR_LIBRARY;
  1068. }
  1069. chan_open_end:
  1070. return ret;
  1071. }
  1072. /*
  1073. * Send a request to close a channel with the rest of the cluster.
  1074. */
  1075. static SaAisErrorT evt_close_channel(SaNameT *cn, uint64_t unlink_id)
  1076. {
  1077. struct req_evt_chan_command cpkt;
  1078. struct iovec chn_iovec;
  1079. int res;
  1080. SaAisErrorT ret;
  1081. ret = SA_AIS_OK;
  1082. /*
  1083. * create the channel packet to send. Tell the the cluster
  1084. * to close the channel.
  1085. */
  1086. memset(&cpkt, 0, sizeof(cpkt));
  1087. cpkt.chc_head.id =
  1088. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  1089. cpkt.chc_head.size = sizeof(cpkt);
  1090. cpkt.chc_op = EVT_CLOSE_CHAN_OP;
  1091. cpkt.u.chcu.chcu_name = *cn;
  1092. cpkt.u.chcu.chcu_unlink_id = unlink_id;
  1093. chn_iovec.iov_base = &cpkt;
  1094. chn_iovec.iov_len = cpkt.chc_head.size;
  1095. res = totempg_groups_mcast_joined(openais_group_handle,
  1096. &chn_iovec, 1, TOTEMPG_AGREED);
  1097. if (res != 0) {
  1098. ret = SA_AIS_ERR_LIBRARY;
  1099. }
  1100. return ret;
  1101. }
  1102. /*
  1103. * Node data access functions. Used to keep track of event IDs
  1104. * delivery of messages.
  1105. *
  1106. * add_node: Add a new member node to our list.
  1107. * remove_node: Remove a node that left membership.
  1108. * find_node: Given the node ID return a pointer to node information.
  1109. *
  1110. */
  1111. #define NODE_HASH_SIZE 256
  1112. static struct member_node_data *nl[NODE_HASH_SIZE] = {0};
  1113. inline int
  1114. hash_sock_addr(struct totem_ip_address *addr)
  1115. {
  1116. return addr->nodeid & (NODE_HASH_SIZE - 1);
  1117. }
  1118. static struct member_node_data **lookup_node(struct totem_ip_address *addr)
  1119. {
  1120. int index = hash_sock_addr(addr);
  1121. struct member_node_data **nlp;
  1122. nlp = &nl[index];
  1123. for (nlp = &nl[index]; *nlp; nlp = &((*nlp)->mn_next)) {
  1124. if (totemip_equal(&(*nlp)->mn_node_addr, addr)) {
  1125. break;
  1126. }
  1127. }
  1128. return nlp;
  1129. }
  1130. static struct member_node_data *
  1131. evt_find_node(struct totem_ip_address *addr)
  1132. {
  1133. struct member_node_data **nlp;
  1134. nlp = lookup_node(addr);
  1135. if (!nlp) {
  1136. log_printf(LOG_LEVEL_DEBUG, "find_node: Got NULL nlp?\n");
  1137. return 0;
  1138. }
  1139. return *nlp;
  1140. }
  1141. static SaAisErrorT
  1142. evt_add_node(struct totem_ip_address *addr, SaClmClusterNodeT *cn)
  1143. {
  1144. struct member_node_data **nlp;
  1145. struct member_node_data *nl;
  1146. SaAisErrorT err = SA_AIS_ERR_EXIST;
  1147. nlp = lookup_node(addr);
  1148. if (!nlp) {
  1149. log_printf(LOG_LEVEL_DEBUG, "add_node: Got NULL nlp?\n");
  1150. goto an_out;
  1151. }
  1152. if (*nlp) {
  1153. goto an_out;
  1154. }
  1155. *nlp = malloc(sizeof(struct member_node_data));
  1156. if (!(*nlp)) {
  1157. return SA_AIS_ERR_NO_MEMORY;
  1158. }
  1159. nl = *nlp;
  1160. if (nl) {
  1161. memset(nl, 0, sizeof(*nl));
  1162. err = SA_AIS_OK;
  1163. totemip_copy(&nl->mn_node_addr, addr);
  1164. nl->mn_started = 1;
  1165. }
  1166. list_init(&nl->mn_entry);
  1167. list_add(&nl->mn_entry, &mnd);
  1168. nl->mn_node_info = *cn;
  1169. an_out:
  1170. return err;
  1171. }
  1172. /*
  1173. * Find the oldest node in the membership. This is the one we choose to
  1174. * perform some cluster-wide functions like distributing retained events.
  1175. * We only check nodes that were in our transitional configuration. In this
  1176. * way there is a recovery node chosen for each original partition in case
  1177. * of a merge.
  1178. */
  1179. static struct member_node_data* oldest_node()
  1180. {
  1181. struct member_node_data *mn = 0;
  1182. struct member_node_data *oldest = 0;
  1183. int i;
  1184. for (i = 0; i < trans_member_count; i++) {
  1185. mn = evt_find_node(&trans_member_list[i]);
  1186. if (!mn || (mn->mn_started == 0)) {
  1187. log_printf(LOG_LEVEL_ERROR,
  1188. "Transitional config Node %s not active\n",
  1189. totemip_print(&trans_member_list[i]));
  1190. continue;
  1191. }
  1192. if ((oldest == NULL) ||
  1193. (mn->mn_node_info.bootTimestamp <
  1194. oldest->mn_node_info.bootTimestamp )) {
  1195. oldest = mn;
  1196. } else if (mn->mn_node_info.bootTimestamp ==
  1197. oldest->mn_node_info.bootTimestamp) {
  1198. if (mn->mn_node_info.nodeId < oldest->mn_node_info.nodeId) {
  1199. oldest = mn;
  1200. }
  1201. }
  1202. }
  1203. return oldest;
  1204. }
  1205. /*
  1206. * keep track of the last event ID from a node.
  1207. * If we get an event ID less than our last, we've already
  1208. * seen it. It's probably a retained event being sent to
  1209. * a new node.
  1210. */
  1211. static int check_last_event(struct lib_event_data *evtpkt,
  1212. struct totem_ip_address *addr)
  1213. {
  1214. struct member_node_data *nd;
  1215. SaClmClusterNodeT *cn;
  1216. nd = evt_find_node(addr);
  1217. if (!nd) {
  1218. log_printf(LOG_LEVEL_DEBUG,
  1219. "Node ID 0x%x not found for event %llx\n",
  1220. evtpkt->led_publisher_node_id, evtpkt->led_event_id);
  1221. cn = main_clm_get_by_nodeid(addr->nodeid);
  1222. if (!cn) {
  1223. log_printf(LOG_LEVEL_DEBUG,
  1224. "Cluster Node 0x%x not found for event %llx\n",
  1225. evtpkt->led_publisher_node_id, evtpkt->led_event_id);
  1226. } else {
  1227. evt_add_node(addr, cn);
  1228. nd = evt_find_node(addr);
  1229. }
  1230. }
  1231. if (!nd) {
  1232. return 0;
  1233. }
  1234. if ((nd->mn_last_msg_id < evtpkt->led_msg_id)) {
  1235. nd->mn_last_msg_id = evtpkt->led_msg_id;
  1236. return 0;
  1237. }
  1238. return 1;
  1239. }
  1240. /*
  1241. * event id generating code. We use the node ID for this node for the
  1242. * upper 32 bits of the event ID to make sure that we can generate a cluster
  1243. * wide unique event ID for a given event.
  1244. */
  1245. SaAisErrorT set_event_id(SaClmNodeIdT node_id)
  1246. {
  1247. SaAisErrorT err = SA_AIS_OK;
  1248. if (base_id_top) {
  1249. err = SA_AIS_ERR_EXIST;
  1250. }
  1251. base_id_top = (SaEvtEventIdT)node_id << 32;
  1252. return err;
  1253. }
  1254. /*
  1255. * See if an event Id is still in use in the retained event
  1256. * list.
  1257. */
  1258. static int id_in_use(uint64_t id, uint64_t base)
  1259. {
  1260. struct list_head *l;
  1261. struct event_data *edp;
  1262. SaEvtEventIdT evtid = (id << 32) | (base & BASE_ID_MASK);
  1263. for (l = retained_list.next; l != &retained_list; l = l->next) {
  1264. edp = list_entry(l, struct event_data, ed_retained);
  1265. if (edp->ed_event.led_event_id == evtid) {
  1266. return 1;
  1267. }
  1268. }
  1269. return 0;
  1270. }
  1271. static SaAisErrorT get_event_id(uint64_t *event_id, uint64_t *msg_id)
  1272. {
  1273. /*
  1274. * Don't reuse an event ID if it is still valid because of
  1275. * a retained event.
  1276. */
  1277. while (id_in_use(base_id_top, base_id)) {
  1278. base_id++;
  1279. }
  1280. *event_id = base_id_top | (base_id & BASE_ID_MASK) ;
  1281. *msg_id = base_id++;
  1282. return SA_AIS_OK;
  1283. }
  1284. /*
  1285. * Timer handler to delete expired events.
  1286. *
  1287. */
  1288. static void
  1289. event_retention_timeout(void *data)
  1290. {
  1291. struct event_data *edp = data;
  1292. log_printf(RETENTION_TIME_DEBUG, "Event ID %llx expired\n",
  1293. edp->ed_event.led_event_id);
  1294. /*
  1295. * adjust next_retained if we're in recovery and
  1296. * were in charge of sending retained events.
  1297. */
  1298. if (recovery_phase != evt_recovery_complete && recovery_node) {
  1299. if (next_retained == &edp->ed_retained) {
  1300. next_retained = edp->ed_retained.next;
  1301. }
  1302. }
  1303. list_del(&edp->ed_retained);
  1304. list_init(&edp->ed_retained);
  1305. /*
  1306. * Check to see if the channel isn't in use anymore.
  1307. */
  1308. edp->ed_my_chan->esc_retained_count--;
  1309. if (edp->ed_my_chan->esc_retained_count == 0) {
  1310. delete_channel(edp->ed_my_chan);
  1311. }
  1312. free_event_data(edp);
  1313. }
  1314. /*
  1315. * clear a particular event's retention time.
  1316. * This will free the event as long as it isn't being
  1317. * currently used.
  1318. *
  1319. */
  1320. static SaAisErrorT
  1321. clear_retention_time(SaEvtEventIdT event_id)
  1322. {
  1323. struct event_data *edp;
  1324. struct list_head *l, *nxt;
  1325. int ret;
  1326. log_printf(RETENTION_TIME_DEBUG, "Search for Event ID %llx\n", event_id);
  1327. for (l = retained_list.next; l != &retained_list; l = nxt) {
  1328. nxt = l->next;
  1329. edp = list_entry(l, struct event_data, ed_retained);
  1330. if (edp->ed_event.led_event_id != event_id) {
  1331. continue;
  1332. }
  1333. log_printf(RETENTION_TIME_DEBUG,
  1334. "Clear retention time for Event ID %llx\n",
  1335. edp->ed_event.led_event_id);
  1336. ret = poll_timer_delete(aisexec_poll_handle, edp->ed_timer_handle);
  1337. if (ret != 0 ) {
  1338. log_printf(LOG_LEVEL_ERROR, "Error expiring event ID %llx\n",
  1339. edp->ed_event.led_event_id);
  1340. return SA_AIS_ERR_NOT_EXIST;
  1341. }
  1342. edp->ed_event.led_retention_time = 0;
  1343. list_del(&edp->ed_retained);
  1344. list_init(&edp->ed_retained);
  1345. /*
  1346. * Check to see if the channel isn't in use anymore.
  1347. */
  1348. edp->ed_my_chan->esc_retained_count--;
  1349. if (edp->ed_my_chan->esc_retained_count == 0) {
  1350. delete_channel(edp->ed_my_chan);
  1351. }
  1352. free_event_data(edp);
  1353. return SA_AIS_OK;
  1354. }
  1355. return SA_AIS_ERR_NOT_EXIST;
  1356. }
  1357. /*
  1358. * Remove specified channel from event delivery list
  1359. */
  1360. static void
  1361. remove_delivered_channel(struct event_svr_channel_open *eco)
  1362. {
  1363. int i;
  1364. struct list_head *l;
  1365. struct event_data *edp;
  1366. for (l = retained_list.next; l != &retained_list; l = l->next) {
  1367. edp = list_entry(l, struct event_data, ed_retained);
  1368. for (i = 0; i < edp->ed_delivered_next; i++) {
  1369. if (edp->ed_delivered[i] == eco) {
  1370. edp->ed_delivered_next--;
  1371. if (edp->ed_delivered_next == i) {
  1372. break;
  1373. }
  1374. memmove(&edp->ed_delivered[i],
  1375. &edp->ed_delivered[i+1],
  1376. &edp->ed_delivered[edp->ed_delivered_next] -
  1377. &edp->ed_delivered[i]);
  1378. break;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /*
  1384. * If there is a retention time, add this open channel to the event so
  1385. * we can check if we've already delivered this message later if a new
  1386. * subscription matches.
  1387. */
  1388. #define DELIVER_SIZE 8
  1389. static void
  1390. evt_delivered(struct event_data *evt, struct event_svr_channel_open *eco)
  1391. {
  1392. if (!evt->ed_event.led_retention_time) {
  1393. return;
  1394. }
  1395. log_printf(LOG_LEVEL_DEBUG, "delivered ID %llx to eco %p\n",
  1396. evt->ed_event.led_event_id, eco);
  1397. if (evt->ed_delivered_count == evt->ed_delivered_next) {
  1398. evt->ed_delivered = realloc(evt->ed_delivered,
  1399. DELIVER_SIZE * sizeof(struct event_svr_channel_open *));
  1400. memset(evt->ed_delivered + evt->ed_delivered_next, 0,
  1401. DELIVER_SIZE * sizeof(struct event_svr_channel_open *));
  1402. evt->ed_delivered_next = evt->ed_delivered_count;
  1403. evt->ed_delivered_count += DELIVER_SIZE;
  1404. }
  1405. evt->ed_delivered[evt->ed_delivered_next++] = eco;
  1406. }
  1407. /*
  1408. * Check to see if an event has already been delivered to this open channel
  1409. */
  1410. static int
  1411. evt_already_delivered(struct event_data *evt,
  1412. struct event_svr_channel_open *eco)
  1413. {
  1414. int i;
  1415. if (!evt->ed_event.led_retention_time) {
  1416. return 0;
  1417. }
  1418. log_printf(LOG_LEVEL_DEBUG, "Deliver count: %d deliver_next %d\n",
  1419. evt->ed_delivered_count, evt->ed_delivered_next);
  1420. for (i = 0; i < evt->ed_delivered_next; i++) {
  1421. log_printf(LOG_LEVEL_DEBUG, "Checking ID %llx delivered %p eco %p\n",
  1422. evt->ed_event.led_event_id, evt->ed_delivered[i], eco);
  1423. if (evt->ed_delivered[i] == eco) {
  1424. return 1;
  1425. }
  1426. }
  1427. return 0;
  1428. }
  1429. /*
  1430. * Compare a filter to a given pattern.
  1431. * return SA_AIS_OK if the pattern matches a filter
  1432. */
  1433. static SaAisErrorT
  1434. filter_match(SaEvtEventPatternT *ep, SaEvtEventFilterT *ef)
  1435. {
  1436. int ret;
  1437. ret = SA_AIS_ERR_FAILED_OPERATION;
  1438. switch (ef->filterType) {
  1439. case SA_EVT_PREFIX_FILTER:
  1440. if (ef->filter.patternSize > ep->patternSize) {
  1441. break;
  1442. }
  1443. if (strncmp((char *)ef->filter.pattern, (char *)ep->pattern,
  1444. ef->filter.patternSize) == 0) {
  1445. ret = SA_AIS_OK;
  1446. }
  1447. break;
  1448. case SA_EVT_SUFFIX_FILTER:
  1449. if (ef->filter.patternSize > ep->patternSize) {
  1450. break;
  1451. }
  1452. if (strncmp((char *)ef->filter.pattern,
  1453. (char *)&ep->pattern[ep->patternSize - ef->filter.patternSize],
  1454. ef->filter.patternSize) == 0) {
  1455. ret = SA_AIS_OK;
  1456. }
  1457. break;
  1458. case SA_EVT_EXACT_FILTER:
  1459. if (ef->filter.patternSize != ep->patternSize) {
  1460. break;
  1461. }
  1462. if (strncmp((char *)ef->filter.pattern, (char *)ep->pattern,
  1463. ef->filter.patternSize) == 0) {
  1464. ret = SA_AIS_OK;
  1465. }
  1466. break;
  1467. case SA_EVT_PASS_ALL_FILTER:
  1468. ret = SA_AIS_OK;
  1469. break;
  1470. default:
  1471. break;
  1472. }
  1473. return ret;
  1474. }
  1475. /*
  1476. * compare the event's patterns with the subscription's filter rules.
  1477. * SA_AIS_OK is returned if the event matches the filter rules.
  1478. */
  1479. static SaAisErrorT
  1480. event_match(struct event_data *evt,
  1481. struct event_svr_channel_subscr *ecs)
  1482. {
  1483. SaEvtEventFilterT *ef;
  1484. SaEvtEventPatternT *ep;
  1485. uint32_t filt_count;
  1486. SaAisErrorT ret = SA_AIS_OK;
  1487. int i;
  1488. ep = (SaEvtEventPatternT *)(&evt->ed_event.led_body[0]);
  1489. ef = ecs->ecs_filters->filters;
  1490. filt_count = min(ecs->ecs_filters->filtersNumber,
  1491. evt->ed_event.led_patterns_number);
  1492. for (i = 0; i < filt_count; i++) {
  1493. ret = filter_match(ep, ef);
  1494. if (ret != SA_AIS_OK) {
  1495. break;
  1496. }
  1497. ep++;
  1498. ef++;
  1499. }
  1500. return ret;
  1501. }
  1502. /*
  1503. * Scan undelivered pending events and either remove them if no subscription
  1504. * filters match anymore or re-assign them to another matching subscription
  1505. */
  1506. static void
  1507. filter_undelivered_events(struct event_svr_channel_open *op_chan)
  1508. {
  1509. struct event_svr_channel_open *eco;
  1510. struct event_svr_channel_instance *eci;
  1511. struct event_svr_channel_subscr *ecs;
  1512. struct chan_event_list *cel;
  1513. struct libevt_pd *esip;
  1514. struct list_head *l, *nxt;
  1515. struct list_head *l1, *l2;
  1516. int i;
  1517. esip = (struct libevt_pd *)openais_conn_private_data_get(op_chan->eco_conn);
  1518. eci = op_chan->eco_channel;
  1519. /*
  1520. * Scan each of the priority queues for messages
  1521. */
  1522. for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
  1523. /*
  1524. * examine each message queued for delivery
  1525. */
  1526. for (l = esip->esi_events[i].next; l != &esip->esi_events[i]; l = nxt) {
  1527. nxt = l->next;
  1528. cel = list_entry(l, struct chan_event_list, cel_entry);
  1529. /*
  1530. * Check open channels
  1531. */
  1532. for (l1 = eci->esc_open_chans.next;
  1533. l1 != &eci->esc_open_chans; l1 = l1->next) {
  1534. eco = list_entry(l1, struct event_svr_channel_open, eco_entry);
  1535. /*
  1536. * See if this channel open instance belongs
  1537. * to this evtinitialize instance
  1538. */
  1539. if (eco->eco_conn != op_chan->eco_conn) {
  1540. continue;
  1541. }
  1542. /*
  1543. * See if enabled to receive
  1544. */
  1545. if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
  1546. continue;
  1547. }
  1548. /*
  1549. * Check subscriptions
  1550. */
  1551. for (l2 = eco->eco_subscr.next;
  1552. l2 != &eco->eco_subscr; l2 = l2->next) {
  1553. ecs = list_entry(l2,
  1554. struct event_svr_channel_subscr, ecs_entry);
  1555. if (event_match(cel->cel_event, ecs) == SA_AIS_OK) {
  1556. /*
  1557. * Something still matches.
  1558. * We'll assign it to
  1559. * the new subscription.
  1560. */
  1561. cel->cel_sub_id = ecs->ecs_sub_id;
  1562. cel->cel_chan_handle = eco->eco_lib_handle;
  1563. goto next_event;
  1564. }
  1565. }
  1566. }
  1567. /*
  1568. * No subscription filter matches anymore. We
  1569. * can delete this event.
  1570. */
  1571. list_del(&cel->cel_entry);
  1572. list_init(&cel->cel_entry);
  1573. esip->esi_nevents--;
  1574. free_event_data(cel->cel_event);
  1575. free(cel);
  1576. next_event:
  1577. continue;
  1578. }
  1579. }
  1580. }
  1581. /*
  1582. * Notify the library of a pending event
  1583. */
  1584. static void __notify_event(void *conn)
  1585. {
  1586. struct res_evt_event_data res;
  1587. struct libevt_pd *esip;
  1588. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  1589. log_printf(LOG_LEVEL_DEBUG, "DELIVER: notify\n");
  1590. if (esip->esi_nevents != 0) {
  1591. res.evd_head.size = sizeof(res);
  1592. res.evd_head.id = MESSAGE_RES_EVT_AVAILABLE;
  1593. res.evd_head.error = SA_AIS_OK;
  1594. openais_conn_send_response(openais_conn_partner_get(conn),
  1595. &res, sizeof(res));
  1596. }
  1597. }
  1598. inline void notify_event(void *conn)
  1599. {
  1600. struct libevt_pd *esip;
  1601. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  1602. /*
  1603. * Give the library a kick if there aren't already
  1604. * events queued for delivery.
  1605. */
  1606. if (esip->esi_nevents++ == 0) {
  1607. __notify_event(conn);
  1608. }
  1609. }
  1610. /*
  1611. * sends/queues up an event for a subscribed channel.
  1612. */
  1613. static void
  1614. deliver_event(struct event_data *evt,
  1615. struct event_svr_channel_open *eco,
  1616. struct event_svr_channel_subscr *ecs)
  1617. {
  1618. struct chan_event_list *ep;
  1619. SaEvtEventPriorityT evt_prio = evt->ed_event.led_priority;
  1620. struct chan_event_list *cel;
  1621. int do_deliver_event = 0;
  1622. int do_deliver_warning = 0;
  1623. int i;
  1624. struct libevt_pd *esip;
  1625. esip = (struct libevt_pd *)openais_conn_private_data_get(eco->eco_conn);
  1626. if (evt_prio > SA_EVT_LOWEST_PRIORITY) {
  1627. evt_prio = SA_EVT_LOWEST_PRIORITY;
  1628. }
  1629. /*
  1630. * Delivery queue check.
  1631. * - If the queue is blocked, see if we've sent enough messages to
  1632. * unblock it.
  1633. * - If it isn't blocked, see if this message will put us over the top.
  1634. * - If we can't deliver this message, see if we can toss some lower
  1635. * priority message to make room for this one.
  1636. * - If we toss any messages, queue up an event of SA_EVT_LOST_EVENT_PATTERN
  1637. * to let the application know that we dropped some messages.
  1638. */
  1639. if (esip->esi_queue_blocked) {
  1640. if (esip->esi_nevents < evt_delivery_queue_resume) {
  1641. esip->esi_queue_blocked = 0;
  1642. log_printf(LOG_LEVEL_DEBUG, "unblock\n");
  1643. }
  1644. }
  1645. if (!esip->esi_queue_blocked &&
  1646. (esip->esi_nevents >= evt_delivery_queue_size)) {
  1647. log_printf(LOG_LEVEL_DEBUG, "block\n");
  1648. esip->esi_queue_blocked = 1;
  1649. do_deliver_warning = 1;
  1650. }
  1651. if (esip->esi_queue_blocked) {
  1652. do_deliver_event = 0;
  1653. for (i = SA_EVT_LOWEST_PRIORITY; i > evt_prio; i--) {
  1654. if (!list_empty(&esip->esi_events[i])) {
  1655. /*
  1656. * Get the last item on the list, so we drop the most
  1657. * recent lowest priority event.
  1658. */
  1659. cel = list_entry(esip->esi_events[i].prev,
  1660. struct chan_event_list, cel_entry);
  1661. log_printf(LOG_LEVEL_DEBUG, "Drop 0x%0llx\n",
  1662. cel->cel_event->ed_event.led_event_id);
  1663. list_del(&cel->cel_entry);
  1664. free_event_data(cel->cel_event);
  1665. free(cel);
  1666. esip->esi_nevents--;
  1667. do_deliver_event = 1;
  1668. break;
  1669. }
  1670. }
  1671. } else {
  1672. do_deliver_event = 1;
  1673. }
  1674. /*
  1675. * Queue the event for delivery
  1676. */
  1677. if (do_deliver_event) {
  1678. ep = malloc(sizeof(*ep));
  1679. if (!ep) {
  1680. log_printf(LOG_LEVEL_WARNING,
  1681. "3Memory allocation error, can't deliver event\n");
  1682. return;
  1683. }
  1684. evt->ed_ref_count++;
  1685. ep->cel_chan_handle = eco->eco_lib_handle;
  1686. ep->cel_sub_id = ecs->ecs_sub_id;
  1687. list_init(&ep->cel_entry);
  1688. ep->cel_event = evt;
  1689. list_add_tail(&ep->cel_entry, &esip->esi_events[evt_prio]);
  1690. evt_delivered(evt, eco);
  1691. notify_event(eco->eco_conn);
  1692. }
  1693. /*
  1694. * If we dropped an event, queue this so that the application knows
  1695. * what has happened.
  1696. */
  1697. if (do_deliver_warning) {
  1698. struct event_data *ed;
  1699. ed = malloc(dropped_event_size);
  1700. if (!ed) {
  1701. log_printf(LOG_LEVEL_WARNING,
  1702. "4Memory allocation error, can't deliver event\n");
  1703. return;
  1704. }
  1705. log_printf(LOG_LEVEL_DEBUG, "Warn 0x%0llx\n",
  1706. evt->ed_event.led_event_id);
  1707. memcpy(ed, dropped_event, dropped_event_size);
  1708. ed->ed_event.led_publish_time = clust_time_now();
  1709. ed->ed_event.led_event_id = SA_EVT_EVENTID_LOST;
  1710. list_init(&ed->ed_retained);
  1711. ep = malloc(sizeof(*ep));
  1712. if (!ep) {
  1713. log_printf(LOG_LEVEL_WARNING,
  1714. "5Memory allocation error, can't deliver event\n");
  1715. return;
  1716. }
  1717. ep->cel_chan_handle = eco->eco_lib_handle;
  1718. ep->cel_sub_id = ecs->ecs_sub_id;
  1719. list_init(&ep->cel_entry);
  1720. ep->cel_event = ed;
  1721. list_add_tail(&ep->cel_entry, &esip->esi_events[SA_EVT_HIGHEST_PRIORITY]);
  1722. notify_event(eco->eco_conn);
  1723. }
  1724. }
  1725. /*
  1726. * Take the event data and swap the elements so they match our architectures
  1727. * word order.
  1728. */
  1729. static void
  1730. convert_event(void *msg)
  1731. {
  1732. struct lib_event_data *evt = (struct lib_event_data *)msg;
  1733. SaEvtEventPatternT *eps;
  1734. int i;
  1735. /*
  1736. * The following elements don't require processing:
  1737. *
  1738. * converted in the main deliver_fn:
  1739. * led_head.id, led_head.size.
  1740. *
  1741. * Supplied localy:
  1742. * source_addr, publisher_node_id, receive_time.
  1743. *
  1744. * Used internaly only:
  1745. * led_svr_channel_handle and led_lib_channel_handle.
  1746. */
  1747. evt->led_chan_name.length = swab16(evt->led_chan_name.length);
  1748. evt->led_chan_unlink_id = swab64(evt->led_chan_unlink_id);
  1749. evt->led_event_id = swab64(evt->led_event_id);
  1750. evt->led_sub_id = swab32(evt->led_sub_id);
  1751. evt->led_publisher_name.length = swab32(evt->led_publisher_name.length);
  1752. evt->led_retention_time = swab64(evt->led_retention_time);
  1753. evt->led_publish_time = swab64(evt->led_publish_time);
  1754. evt->led_user_data_offset = swab32(evt->led_user_data_offset);
  1755. evt->led_user_data_size = swab32(evt->led_user_data_size);
  1756. evt->led_patterns_number = swab32(evt->led_patterns_number);
  1757. /*
  1758. * Now we need to go through the led_body and swizzle pattern counts.
  1759. * We can't do anything about user data since it doesn't have a specified
  1760. * format. The application is on its own here.
  1761. */
  1762. eps = (SaEvtEventPatternT *)evt->led_body;
  1763. for (i = 0; i < evt->led_patterns_number; i++) {
  1764. eps->patternSize = swab32(eps->patternSize);
  1765. eps->allocatedSize = swab32(eps->allocatedSize);
  1766. eps++;
  1767. }
  1768. }
  1769. /*
  1770. * Take an event received from the network and fix it up to be usable.
  1771. * - fix up pointers for pattern list.
  1772. * - fill in some channel info
  1773. */
  1774. static struct event_data *
  1775. make_local_event(struct lib_event_data *p,
  1776. struct event_svr_channel_instance *eci)
  1777. {
  1778. struct event_data *ed;
  1779. SaEvtEventPatternT *eps;
  1780. SaUint8T *str;
  1781. uint32_t ed_size;
  1782. int i;
  1783. ed_size = sizeof(*ed) + p->led_user_data_offset + p->led_user_data_size;
  1784. ed = malloc(ed_size);
  1785. if (!ed) {
  1786. log_printf(LOG_LEVEL_WARNING,
  1787. "Failed to allocate %u bytes for event, offset %u, data size %u\n",
  1788. ed_size, p->led_user_data_offset, p->led_user_data_size);
  1789. return 0;
  1790. }
  1791. memset(ed, 0, ed_size);
  1792. list_init(&ed->ed_retained);
  1793. ed->ed_my_chan = eci;
  1794. /*
  1795. * Fill in lib_event_data and make the pattern pointers valid
  1796. */
  1797. memcpy(&ed->ed_event, p, sizeof(*p) +
  1798. p->led_user_data_offset + p->led_user_data_size);
  1799. eps = (SaEvtEventPatternT *)ed->ed_event.led_body;
  1800. str = ed->ed_event.led_body +
  1801. (ed->ed_event.led_patterns_number * sizeof(SaEvtEventPatternT));
  1802. for (i = 0; i < ed->ed_event.led_patterns_number; i++) {
  1803. eps->pattern = str;
  1804. str += eps->patternSize;
  1805. eps++;
  1806. }
  1807. ed->ed_ref_count++;
  1808. return ed;
  1809. }
  1810. /*
  1811. * Set an event to be retained.
  1812. */
  1813. static void retain_event(struct event_data *evt)
  1814. {
  1815. uint32_t ret;
  1816. int msec_in_future;
  1817. evt->ed_ref_count++;
  1818. evt->ed_my_chan->esc_retained_count++;
  1819. list_add_tail(&evt->ed_retained, &retained_list);
  1820. /*
  1821. * Time in nanoseconds - convert to miliseconds
  1822. */
  1823. msec_in_future = (uint32_t)((evt->ed_event.led_retention_time) / 1000000ULL);
  1824. ret = poll_timer_add(aisexec_poll_handle,
  1825. msec_in_future,
  1826. evt,
  1827. event_retention_timeout,
  1828. &evt->ed_timer_handle);
  1829. if (ret != 0) {
  1830. log_printf(LOG_LEVEL_ERROR,
  1831. "retention of event id 0x%llx failed\n",
  1832. evt->ed_event.led_event_id);
  1833. } else {
  1834. log_printf(RETENTION_TIME_DEBUG, "Retain event ID 0x%llx for %u ms\n",
  1835. evt->ed_event.led_event_id, msec_in_future);
  1836. }
  1837. }
  1838. /*
  1839. * Scan the subscription list and look for the specified subsctiption ID.
  1840. * Only look for the ID in subscriptions that are associated with the
  1841. * saEvtInitialize associated with the specified open channel.
  1842. */
  1843. static struct event_svr_channel_subscr *find_subscr(
  1844. struct event_svr_channel_open *open_chan, SaEvtSubscriptionIdT sub_id)
  1845. {
  1846. struct event_svr_channel_instance *eci;
  1847. struct event_svr_channel_subscr *ecs;
  1848. struct event_svr_channel_open *eco;
  1849. struct list_head *l, *l1;
  1850. void *conn = open_chan->eco_conn;
  1851. eci = open_chan->eco_channel;
  1852. /*
  1853. * Check for subscription id already in use.
  1854. * Subscriptions are unique within saEvtInitialize (Callback scope).
  1855. */
  1856. for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) {
  1857. eco = list_entry(l, struct event_svr_channel_open, eco_entry);
  1858. /*
  1859. * Don't bother with open channels associated with another
  1860. * EvtInitialize
  1861. */
  1862. if (eco->eco_conn != conn) {
  1863. continue;
  1864. }
  1865. for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) {
  1866. ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry);
  1867. if (ecs->ecs_sub_id == sub_id) {
  1868. return ecs;
  1869. }
  1870. }
  1871. }
  1872. return 0;
  1873. }
  1874. /*
  1875. * Handler for saEvtInitialize
  1876. */
  1877. static int evt_lib_init(void *conn)
  1878. {
  1879. struct libevt_pd *libevt_pd;
  1880. int i;
  1881. libevt_pd = (struct libevt_pd *)openais_conn_private_data_get(conn);
  1882. log_printf(LOG_LEVEL_DEBUG, "saEvtInitialize request.\n");
  1883. /*
  1884. * Initailze event instance data
  1885. */
  1886. memset(libevt_pd, 0, sizeof(*libevt_pd));
  1887. /*
  1888. * list of channels open on this instance
  1889. */
  1890. list_init(&libevt_pd->esi_open_chans);
  1891. /*
  1892. * pending event lists for each piriority
  1893. */
  1894. for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
  1895. list_init(&libevt_pd->esi_events[i]);
  1896. }
  1897. return 0;
  1898. }
  1899. /*
  1900. * Handler for saEvtChannelOpen
  1901. */
  1902. static void lib_evt_open_channel(void *conn, void *message)
  1903. {
  1904. SaAisErrorT error;
  1905. struct req_evt_channel_open *req;
  1906. struct res_evt_channel_open res;
  1907. struct open_chan_pending *ocp;
  1908. int msec_in_future;
  1909. int ret;
  1910. req = message;
  1911. log_printf(CHAN_OPEN_DEBUG,
  1912. "saEvtChannelOpen (Open channel request)\n");
  1913. log_printf(CHAN_OPEN_DEBUG,
  1914. "handle 0x%x, to 0x%llx\n",
  1915. req->ico_c_handle,
  1916. req->ico_timeout);
  1917. log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n",
  1918. req->ico_open_flag,
  1919. req->ico_channel_name.length,
  1920. req->ico_channel_name.value);
  1921. /*
  1922. * Open the channel.
  1923. *
  1924. */
  1925. error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag);
  1926. if (error != SA_AIS_OK) {
  1927. goto open_return;
  1928. }
  1929. ocp = malloc(sizeof(struct open_chan_pending));
  1930. if (!ocp) {
  1931. error = SA_AIS_ERR_NO_MEMORY;
  1932. goto open_return;
  1933. }
  1934. ocp->ocp_async = 0;
  1935. ocp->ocp_invocation = 0;
  1936. ocp->ocp_chan_name = req->ico_channel_name;
  1937. ocp->ocp_open_flag = req->ico_open_flag;
  1938. ocp->ocp_conn = conn;
  1939. ocp->ocp_c_handle = req->ico_c_handle;
  1940. ocp->ocp_timer_handle = 0;
  1941. ocp->ocp_serial_no = open_serial_no;
  1942. list_init(&ocp->ocp_entry);
  1943. list_add_tail(&ocp->ocp_entry, &open_pending);
  1944. /*
  1945. * Time in nanoseconds - convert to miliseconds
  1946. */
  1947. msec_in_future = (uint32_t)(req->ico_timeout / 1000000ULL);
  1948. ret = poll_timer_add(aisexec_poll_handle,
  1949. msec_in_future,
  1950. ocp,
  1951. chan_open_timeout,
  1952. &ocp->ocp_timer_handle);
  1953. if (ret != 0) {
  1954. log_printf(LOG_LEVEL_WARNING,
  1955. "Error setting timeout for open channel %s\n",
  1956. req->ico_channel_name.value);
  1957. }
  1958. return;
  1959. open_return:
  1960. res.ico_head.size = sizeof(res);
  1961. res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
  1962. res.ico_head.error = error;
  1963. openais_conn_send_response(conn, &res, sizeof(res));
  1964. }
  1965. /*
  1966. * Handler for saEvtChannelOpen
  1967. */
  1968. static void lib_evt_open_channel_async(void *conn, void *message)
  1969. {
  1970. SaAisErrorT error;
  1971. struct req_evt_channel_open *req;
  1972. struct res_evt_channel_open res;
  1973. struct open_chan_pending *ocp;
  1974. req = message;
  1975. log_printf(CHAN_OPEN_DEBUG,
  1976. "saEvtChannelOpenAsync (Async Open channel request)\n");
  1977. log_printf(CHAN_OPEN_DEBUG,
  1978. "handle 0x%x, to 0x%x\n",
  1979. req->ico_c_handle,
  1980. req->ico_invocation);
  1981. log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n",
  1982. req->ico_open_flag,
  1983. req->ico_channel_name.length,
  1984. req->ico_channel_name.value);
  1985. /*
  1986. * Open the channel.
  1987. *
  1988. */
  1989. error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag);
  1990. if (error != SA_AIS_OK) {
  1991. goto open_return;
  1992. }
  1993. ocp = malloc(sizeof(struct open_chan_pending));
  1994. if (!ocp) {
  1995. error = SA_AIS_ERR_NO_MEMORY;
  1996. goto open_return;
  1997. }
  1998. ocp->ocp_async = 1;
  1999. ocp->ocp_invocation = req->ico_invocation;
  2000. ocp->ocp_c_handle = req->ico_c_handle;
  2001. ocp->ocp_chan_name = req->ico_channel_name;
  2002. ocp->ocp_open_flag = req->ico_open_flag;
  2003. ocp->ocp_conn = conn;
  2004. ocp->ocp_timer_handle = 0;
  2005. ocp->ocp_serial_no = open_serial_no;
  2006. list_init(&ocp->ocp_entry);
  2007. list_add_tail(&ocp->ocp_entry, &open_pending);
  2008. open_return:
  2009. res.ico_head.size = sizeof(res);
  2010. res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
  2011. res.ico_head.error = error;
  2012. openais_conn_send_response(conn, &res, sizeof(res));
  2013. }
  2014. /*
  2015. * Used by the channel close code and by the implicit close
  2016. * when saEvtFinalize is called with channels open.
  2017. */
  2018. static SaAisErrorT
  2019. common_chan_close(struct event_svr_channel_open *eco, struct libevt_pd *esip)
  2020. {
  2021. struct event_svr_channel_subscr *ecs;
  2022. struct list_head *l, *nxt;
  2023. log_printf(LOG_LEVEL_DEBUG, "Close channel %s flags 0x%02x\n",
  2024. eco->eco_channel->esc_channel_name.value,
  2025. eco->eco_flags);
  2026. /*
  2027. * Disconnect the channel open structure.
  2028. *
  2029. * Check for subscriptions and deal with them. In this case
  2030. * if there are any, we just implicitly unsubscribe.
  2031. *
  2032. * When We're done with the channel open data then we can
  2033. * remove it's handle (this frees the memory too).
  2034. *
  2035. */
  2036. list_del(&eco->eco_entry);
  2037. list_del(&eco->eco_instance_entry);
  2038. for (l = eco->eco_subscr.next; l != &eco->eco_subscr; l = nxt) {
  2039. nxt = l->next;
  2040. ecs = list_entry(l, struct event_svr_channel_subscr, ecs_entry);
  2041. log_printf(LOG_LEVEL_DEBUG, "Unsubscribe ID: %x\n",
  2042. ecs->ecs_sub_id);
  2043. list_del(&ecs->ecs_entry);
  2044. free(ecs);
  2045. /*
  2046. * Purge any pending events associated with this subscription
  2047. * that don't match another subscription.
  2048. */
  2049. filter_undelivered_events(eco);
  2050. }
  2051. /*
  2052. * Remove this channel from the retained event's notion
  2053. * of who they have been delivered to.
  2054. */
  2055. remove_delivered_channel(eco);
  2056. return evt_close_channel(&eco->eco_channel->esc_channel_name,
  2057. eco->eco_channel->esc_unlink_id);
  2058. }
  2059. /*
  2060. * Handler for saEvtChannelClose
  2061. */
  2062. static void lib_evt_close_channel(void *conn, void *message)
  2063. {
  2064. struct req_evt_channel_close *req;
  2065. struct res_evt_channel_close res;
  2066. struct event_svr_channel_open *eco;
  2067. unsigned int ret;
  2068. void *ptr;
  2069. struct libevt_pd *esip;
  2070. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  2071. req = message;
  2072. log_printf(LOG_LEVEL_DEBUG,
  2073. "saEvtChannelClose (Close channel request)\n");
  2074. log_printf(LOG_LEVEL_DEBUG, "handle 0x%x\n", req->icc_channel_handle);
  2075. /*
  2076. * look up the channel handle
  2077. */
  2078. ret = hdb_handle_get(&esip->esi_hdb,
  2079. req->icc_channel_handle, &ptr);
  2080. if (ret != 0) {
  2081. goto chan_close_done;
  2082. }
  2083. eco = ptr;
  2084. common_chan_close(eco, esip);
  2085. hdb_handle_destroy(&esip->esi_hdb, req->icc_channel_handle);
  2086. hdb_handle_put(&esip->esi_hdb, req->icc_channel_handle);
  2087. chan_close_done:
  2088. res.icc_head.size = sizeof(res);
  2089. res.icc_head.id = MESSAGE_RES_EVT_CLOSE_CHANNEL;
  2090. res.icc_head.error = ((ret == 0) ? SA_AIS_OK : SA_AIS_ERR_BAD_HANDLE);
  2091. openais_conn_send_response(conn, &res, sizeof(res));
  2092. }
  2093. /*
  2094. * Handler for saEvtChannelUnlink
  2095. */
  2096. static void lib_evt_unlink_channel(void *conn, void *message)
  2097. {
  2098. struct req_evt_channel_unlink *req;
  2099. struct res_evt_channel_unlink res;
  2100. struct iovec chn_iovec;
  2101. struct unlink_chan_pending *ucp = 0;
  2102. struct req_evt_chan_command cpkt;
  2103. SaAisErrorT error = SA_AIS_ERR_LIBRARY;
  2104. req = message;
  2105. log_printf(CHAN_UNLINK_DEBUG,
  2106. "saEvtChannelUnlink (Unlink channel request)\n");
  2107. log_printf(CHAN_UNLINK_DEBUG, "Channel Name %s\n",
  2108. req->iuc_channel_name.value);
  2109. if (!find_channel(&req->iuc_channel_name, EVT_CHAN_ACTIVE)) {
  2110. log_printf(CHAN_UNLINK_DEBUG, "Channel Name doesn't exist\n");
  2111. error = SA_AIS_ERR_NOT_EXIST;
  2112. goto evt_unlink_err;
  2113. }
  2114. /*
  2115. * Set up the data structure so that the channel op
  2116. * mcast handler can complete the unlink comamnd back to the
  2117. * requestor.
  2118. */
  2119. ucp = malloc(sizeof(*ucp));
  2120. if (!ucp) {
  2121. log_printf(LOG_LEVEL_ERROR,
  2122. "saEvtChannelUnlink: Memory allocation failure\n");
  2123. error = SA_AIS_ERR_TRY_AGAIN;
  2124. goto evt_unlink_err;
  2125. }
  2126. ucp->ucp_unlink_id = next_chan_unlink_id();
  2127. ucp->ucp_conn = conn;
  2128. list_init(&ucp->ucp_entry);
  2129. list_add_tail(&ucp->ucp_entry, &unlink_pending);
  2130. /*
  2131. * Put together a mcast packet to notify everyone
  2132. * of the channel unlink.
  2133. */
  2134. memset(&cpkt, 0, sizeof(cpkt));
  2135. cpkt.chc_head.id =
  2136. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  2137. cpkt.chc_head.size = sizeof(cpkt);
  2138. cpkt.chc_op = EVT_UNLINK_CHAN_OP;
  2139. cpkt.u.chcu.chcu_name = req->iuc_channel_name;
  2140. cpkt.u.chcu.chcu_unlink_id = ucp->ucp_unlink_id;
  2141. chn_iovec.iov_base = &cpkt;
  2142. chn_iovec.iov_len = cpkt.chc_head.size;
  2143. if (totempg_groups_mcast_joined(openais_group_handle,
  2144. &chn_iovec, 1, TOTEMPG_AGREED) == 0) {
  2145. return;
  2146. }
  2147. evt_unlink_err:
  2148. if (ucp) {
  2149. list_del(&ucp->ucp_entry);
  2150. free(ucp);
  2151. }
  2152. res.iuc_head.size = sizeof(res);
  2153. res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL;
  2154. res.iuc_head.error = error;
  2155. openais_conn_send_response(conn, &res, sizeof(res));
  2156. }
  2157. /*
  2158. * Subscribe to an event channel.
  2159. *
  2160. * - First look up the channel to subscribe.
  2161. * - Make sure that the subscription ID is not already in use.
  2162. * - Fill in the subscription data structures and add them to the channels
  2163. * subscription list.
  2164. * - See if there are any events with retetion times that need to be delivered
  2165. * because of the new subscription.
  2166. */
  2167. static char *filter_types[] = {
  2168. "INVALID FILTER TYPE",
  2169. "SA_EVT_PREFIX_FILTER",
  2170. "SA_EVT_SUFFIX_FILTER",
  2171. "SA_EVT_EXACT_FILTER",
  2172. "SA_EVT_PASS_ALL_FILTER",
  2173. };
  2174. /*
  2175. * saEvtEventSubscribe Handler
  2176. */
  2177. static void lib_evt_event_subscribe(void *conn, void *message)
  2178. {
  2179. struct req_evt_event_subscribe *req;
  2180. struct res_evt_event_subscribe res;
  2181. SaEvtEventFilterArrayT *filters;
  2182. SaAisErrorT error;
  2183. struct event_svr_channel_open *eco;
  2184. struct event_svr_channel_instance *eci;
  2185. struct event_svr_channel_subscr *ecs;
  2186. struct event_data *evt;
  2187. struct list_head *l;
  2188. void *ptr;
  2189. unsigned int ret;
  2190. int i;
  2191. struct libevt_pd *esip;
  2192. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  2193. req = message;
  2194. log_printf(LOG_LEVEL_DEBUG,
  2195. "saEvtEventSubscribe (Subscribe request)\n");
  2196. log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%x\n",
  2197. req->ics_sub_id);
  2198. /*
  2199. * look up the channel handle
  2200. */
  2201. ret = hdb_handle_get(&esip->esi_hdb,
  2202. req->ics_channel_handle, &ptr);
  2203. if (ret != 0) {
  2204. error = SA_AIS_ERR_BAD_HANDLE;
  2205. goto subr_done;
  2206. }
  2207. eco = ptr;
  2208. eci = eco->eco_channel;
  2209. /*
  2210. * See if the id is already being used
  2211. */
  2212. ecs = find_subscr(eco, req->ics_sub_id);
  2213. if (ecs) {
  2214. error = SA_AIS_ERR_EXIST;
  2215. goto subr_put;
  2216. }
  2217. error = evtfilt_to_aisfilt(req, &filters);
  2218. if (error == SA_AIS_OK) {
  2219. log_printf(LOG_LEVEL_DEBUG, "Subscribe filters count %d\n",
  2220. filters->filtersNumber);
  2221. for (i = 0; i < filters->filtersNumber; i++) {
  2222. log_printf(LOG_LEVEL_DEBUG, "type %s(%d) sz %d, <%s>\n",
  2223. filter_types[filters->filters[i].filterType],
  2224. filters->filters[i].filterType,
  2225. filters->filters[i].filter.patternSize,
  2226. (filters->filters[i].filter.patternSize)
  2227. ? (char *)filters->filters[i].filter.pattern
  2228. : "");
  2229. }
  2230. }
  2231. if (error != SA_AIS_OK) {
  2232. goto subr_put;
  2233. }
  2234. ecs = (struct event_svr_channel_subscr *)malloc(sizeof(*ecs));
  2235. if (!ecs) {
  2236. error = SA_AIS_ERR_NO_MEMORY;
  2237. goto subr_put;
  2238. }
  2239. ecs->ecs_filters = filters;
  2240. ecs->ecs_sub_id = req->ics_sub_id;
  2241. list_init(&ecs->ecs_entry);
  2242. list_add(&ecs->ecs_entry, &eco->eco_subscr);
  2243. res.ics_head.size = sizeof(res);
  2244. res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE;
  2245. res.ics_head.error = error;
  2246. openais_conn_send_response(conn, &res, sizeof(res));
  2247. /*
  2248. * See if an existing event with a retention time
  2249. * needs to be delivered based on this subscription
  2250. */
  2251. for (l = retained_list.next; l != &retained_list; l = l->next) {
  2252. evt = list_entry(l, struct event_data, ed_retained);
  2253. log_printf(LOG_LEVEL_DEBUG,
  2254. "Checking event ID %llx chanp %p -- sub chanp %p\n",
  2255. evt->ed_event.led_event_id, evt->ed_my_chan, eci);
  2256. if (evt->ed_my_chan == eci) {
  2257. if (evt_already_delivered(evt, eco)) {
  2258. continue;
  2259. }
  2260. if (event_match(evt, ecs) == SA_AIS_OK) {
  2261. log_printf(LOG_LEVEL_DEBUG,
  2262. "deliver event ID: 0x%llx\n",
  2263. evt->ed_event.led_event_id);
  2264. deliver_event(evt, eco, ecs);
  2265. }
  2266. }
  2267. }
  2268. hdb_handle_put(&esip->esi_hdb, req->ics_channel_handle);
  2269. return;
  2270. subr_put:
  2271. hdb_handle_put(&esip->esi_hdb, req->ics_channel_handle);
  2272. subr_done:
  2273. res.ics_head.size = sizeof(res);
  2274. res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE;
  2275. res.ics_head.error = error;
  2276. openais_conn_send_response(conn, &res, sizeof(res));
  2277. }
  2278. /*
  2279. * saEvtEventUnsubscribe Handler
  2280. */
  2281. static void lib_evt_event_unsubscribe(void *conn, void *message)
  2282. {
  2283. struct req_evt_event_unsubscribe *req;
  2284. struct res_evt_event_unsubscribe res;
  2285. struct event_svr_channel_open *eco;
  2286. struct event_svr_channel_instance *eci;
  2287. struct event_svr_channel_subscr *ecs;
  2288. SaAisErrorT error = SA_AIS_OK;
  2289. unsigned int ret;
  2290. void *ptr;
  2291. struct libevt_pd *esip;
  2292. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  2293. req = message;
  2294. log_printf(LOG_LEVEL_DEBUG,
  2295. "saEvtEventUnsubscribe (Unsubscribe request)\n");
  2296. log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%x\n",
  2297. req->icu_sub_id);
  2298. /*
  2299. * look up the channel handle, get the open channel
  2300. * data.
  2301. */
  2302. ret = hdb_handle_get(&esip->esi_hdb,
  2303. req->icu_channel_handle, &ptr);
  2304. if (ret != 0) {
  2305. error = SA_AIS_ERR_BAD_HANDLE;
  2306. goto unsubr_done;
  2307. }
  2308. eco = ptr;
  2309. eci = eco->eco_channel;
  2310. /*
  2311. * Make sure that the id exists.
  2312. */
  2313. ecs = find_subscr(eco, req->icu_sub_id);
  2314. if (!ecs) {
  2315. error = SA_AIS_ERR_NOT_EXIST;
  2316. goto unsubr_put;
  2317. }
  2318. list_del(&ecs->ecs_entry);
  2319. log_printf(LOG_LEVEL_DEBUG,
  2320. "unsubscribe from channel %s subscription ID 0x%x "
  2321. "with %d filters\n",
  2322. eci->esc_channel_name.value,
  2323. ecs->ecs_sub_id, ecs->ecs_filters->filtersNumber);
  2324. free_filters(ecs->ecs_filters);
  2325. free(ecs);
  2326. unsubr_put:
  2327. hdb_handle_put(&esip->esi_hdb, req->icu_channel_handle);
  2328. unsubr_done:
  2329. res.icu_head.size = sizeof(res);
  2330. res.icu_head.id = MESSAGE_RES_EVT_UNSUBSCRIBE;
  2331. res.icu_head.error = error;
  2332. openais_conn_send_response(conn, &res, sizeof(res));
  2333. }
  2334. /*
  2335. * saEvtEventPublish Handler
  2336. */
  2337. static void lib_evt_event_publish(void *conn, void *message)
  2338. {
  2339. struct lib_event_data *req;
  2340. struct res_evt_event_publish res;
  2341. struct event_svr_channel_open *eco;
  2342. struct event_svr_channel_instance *eci;
  2343. SaEvtEventIdT event_id = 0;
  2344. uint64_t msg_id = 0;
  2345. SaAisErrorT error = SA_AIS_OK;
  2346. struct iovec pub_iovec;
  2347. void *ptr;
  2348. int result;
  2349. unsigned int ret;
  2350. struct libevt_pd *esip;
  2351. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  2352. req = message;
  2353. log_printf(LOG_LEVEL_DEBUG,
  2354. "saEvtEventPublish (Publish event request)\n");
  2355. /*
  2356. * look up and validate open channel info
  2357. */
  2358. ret = hdb_handle_get(&esip->esi_hdb,
  2359. req->led_svr_channel_handle, &ptr);
  2360. if (ret != 0) {
  2361. error = SA_AIS_ERR_BAD_HANDLE;
  2362. goto pub_done;
  2363. }
  2364. eco = ptr;
  2365. eci = eco->eco_channel;
  2366. /*
  2367. * modify the request structure for sending event data to subscribed
  2368. * processes.
  2369. */
  2370. get_event_id(&event_id, &msg_id);
  2371. req->led_head.id = SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_EVENTDATA);
  2372. req->led_chan_name = eci->esc_channel_name;
  2373. req->led_event_id = event_id;
  2374. req->led_msg_id = msg_id;
  2375. req->led_chan_unlink_id = eci->esc_unlink_id;
  2376. /*
  2377. * Distribute the event.
  2378. * The multicasted event will be picked up and delivered
  2379. * locally by the local network event receiver.
  2380. */
  2381. pub_iovec.iov_base = req;
  2382. pub_iovec.iov_len = req->led_head.size;
  2383. result = totempg_groups_mcast_joined(openais_group_handle, &pub_iovec, 1, TOTEMPG_AGREED);
  2384. if (result != 0) {
  2385. error = SA_AIS_ERR_LIBRARY;
  2386. }
  2387. hdb_handle_put(&esip->esi_hdb, req->led_svr_channel_handle);
  2388. pub_done:
  2389. res.iep_head.size = sizeof(res);
  2390. res.iep_head.id = MESSAGE_RES_EVT_PUBLISH;
  2391. res.iep_head.error = error;
  2392. res.iep_event_id = event_id;
  2393. openais_conn_send_response(conn, &res, sizeof(res));
  2394. }
  2395. /*
  2396. * saEvtEventRetentionTimeClear handler
  2397. */
  2398. static void lib_evt_event_clear_retentiontime(void *conn, void *message)
  2399. {
  2400. struct req_evt_event_clear_retentiontime *req;
  2401. struct res_evt_event_clear_retentiontime res;
  2402. struct req_evt_chan_command cpkt;
  2403. struct retention_time_clear_pending *rtc = 0;
  2404. struct iovec rtn_iovec;
  2405. SaAisErrorT error;
  2406. int ret;
  2407. req = message;
  2408. log_printf(RETENTION_TIME_DEBUG,
  2409. "saEvtEventRetentionTimeClear (Clear event retentiontime request)\n");
  2410. log_printf(RETENTION_TIME_DEBUG,
  2411. "event ID 0x%llx, chan handle 0x%x\n",
  2412. req->iec_event_id,
  2413. req->iec_channel_handle);
  2414. rtc = malloc(sizeof(*rtc));
  2415. if (!rtc) {
  2416. log_printf(LOG_LEVEL_ERROR,
  2417. "saEvtEventRetentionTimeClear: Memory allocation failure\n");
  2418. error = SA_AIS_ERR_TRY_AGAIN;
  2419. goto evt_ret_clr_err;
  2420. }
  2421. rtc->rtc_event_id = req->iec_event_id;
  2422. rtc->rtc_conn = conn;
  2423. list_init(&rtc->rtc_entry);
  2424. list_add_tail(&rtc->rtc_entry, &clear_pending);
  2425. /*
  2426. * Send the clear request
  2427. */
  2428. memset(&cpkt, 0, sizeof(cpkt));
  2429. cpkt.chc_head.id =
  2430. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  2431. cpkt.chc_head.size = sizeof(cpkt);
  2432. cpkt.chc_op = EVT_CLEAR_RET_OP;
  2433. cpkt.u.chc_event_id = req->iec_event_id;
  2434. rtn_iovec.iov_base = &cpkt;
  2435. rtn_iovec.iov_len = cpkt.chc_head.size;
  2436. ret = totempg_groups_mcast_joined(openais_group_handle,
  2437. &rtn_iovec, 1, TOTEMPG_AGREED);
  2438. if (ret == 0) {
  2439. // TODO this should really assert
  2440. return;
  2441. }
  2442. error = SA_AIS_ERR_LIBRARY;
  2443. evt_ret_clr_err:
  2444. if (rtc) {
  2445. list_del(&rtc->rtc_entry);
  2446. free(rtc);
  2447. }
  2448. res.iec_head.size = sizeof(res);
  2449. res.iec_head.id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME;
  2450. res.iec_head.error = error;
  2451. openais_conn_send_response(conn, &res, sizeof(res));
  2452. }
  2453. /*
  2454. * Send requested event data to the application
  2455. */
  2456. static void lib_evt_event_data_get(void *conn, void *message)
  2457. {
  2458. struct lib_event_data res;
  2459. struct chan_event_list *cel;
  2460. struct event_data *edp;
  2461. int i;
  2462. struct libevt_pd *esip;
  2463. esip = (struct libevt_pd *)openais_conn_private_data_get(conn);
  2464. /*
  2465. * Deliver events in publish order within priority
  2466. */
  2467. for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
  2468. if (!list_empty(&esip->esi_events[i])) {
  2469. cel = list_entry(esip->esi_events[i].next, struct chan_event_list,
  2470. cel_entry);
  2471. list_del(&cel->cel_entry);
  2472. list_init(&cel->cel_entry);
  2473. esip->esi_nevents--;
  2474. if (esip->esi_queue_blocked &&
  2475. (esip->esi_nevents < evt_delivery_queue_resume)) {
  2476. esip->esi_queue_blocked = 0;
  2477. log_printf(LOG_LEVEL_DEBUG, "unblock\n");
  2478. }
  2479. edp = cel->cel_event;
  2480. edp->ed_event.led_lib_channel_handle = cel->cel_chan_handle;
  2481. edp->ed_event.led_sub_id = cel->cel_sub_id;
  2482. edp->ed_event.led_head.id = MESSAGE_RES_EVT_EVENT_DATA;
  2483. edp->ed_event.led_head.error = SA_AIS_OK;
  2484. free(cel);
  2485. openais_conn_send_response(conn, &edp->ed_event,
  2486. edp->ed_event.led_head.size);
  2487. free_event_data(edp);
  2488. goto data_get_done;
  2489. }
  2490. }
  2491. res.led_head.size = sizeof(res.led_head);
  2492. res.led_head.id = MESSAGE_RES_EVT_EVENT_DATA;
  2493. res.led_head.error = SA_AIS_ERR_NOT_EXIST;
  2494. openais_conn_send_response(conn, &res, res.led_head.size);
  2495. /*
  2496. * See if there are any events that the app doesn't know about
  2497. * because the notify pipe was full.
  2498. */
  2499. data_get_done:
  2500. if (esip->esi_nevents) {
  2501. __notify_event(conn);
  2502. }
  2503. }
  2504. /*
  2505. * Scan the list of channels and remove the specified node.
  2506. */
  2507. static void remove_chan_open_info(SaClmNodeIdT node_id)
  2508. {
  2509. struct list_head *l, *nxt;
  2510. struct event_svr_channel_instance *eci;
  2511. for (l = esc_head.next; l != &esc_head; l = nxt) {
  2512. nxt = l->next;
  2513. eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
  2514. remove_open_count(eci, node_id);
  2515. }
  2516. }
  2517. /*
  2518. * Called when there is a configuration change in the cluster.
  2519. * This function looks at any joiners and leavers and updates the evt
  2520. * node list. The node list is used to keep track of event IDs
  2521. * received for each node for the detection of duplicate events.
  2522. */
  2523. static void evt_conf_change(
  2524. enum totem_configuration_type configuration_type,
  2525. struct totem_ip_address *member_list, int member_list_entries,
  2526. struct totem_ip_address *left_list, int left_list_entries,
  2527. struct totem_ip_address *joined_list, int joined_list_entries,
  2528. struct memb_ring_id *ring_id)
  2529. {
  2530. log_printf(RECOVERY_DEBUG, "Evt conf change %d\n",
  2531. configuration_type);
  2532. log_printf(RECOVERY_DEBUG, "m %d, j %d, l %d\n",
  2533. member_list_entries,
  2534. joined_list_entries,
  2535. left_list_entries);
  2536. /*
  2537. * Save the various membership lists for later processing by
  2538. * the synchronization functions. The left list is only
  2539. * valid in the transitional configuration, the joined list is
  2540. * only valid in the regular configuration. Other than for the
  2541. * purposes of delivering retained events from merging partitions,
  2542. * we only care about the final membership from the regular
  2543. * configuration.
  2544. */
  2545. if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  2546. left_member_count = left_list_entries;
  2547. trans_member_count = member_list_entries;
  2548. if (left_member_list) {
  2549. free(left_member_list);
  2550. left_member_list = 0;
  2551. }
  2552. if (left_list_entries) {
  2553. left_member_list =
  2554. malloc(sizeof(struct totem_ip_address) * left_list_entries);
  2555. if (!left_member_list) {
  2556. /*
  2557. * ERROR: No recovery.
  2558. */
  2559. log_printf(LOG_LEVEL_ERROR,
  2560. "Config change left list allocation error\n");
  2561. assert(0);
  2562. }
  2563. memcpy(left_member_list, left_list,
  2564. sizeof(struct totem_ip_address) * left_list_entries);
  2565. }
  2566. if (trans_member_list) {
  2567. free(trans_member_list);
  2568. trans_member_list = 0;
  2569. }
  2570. if (member_list_entries) {
  2571. trans_member_list =
  2572. malloc(sizeof(struct totem_ip_address) * member_list_entries);
  2573. if (!trans_member_list) {
  2574. /*
  2575. * ERROR: No recovery.
  2576. */
  2577. log_printf(LOG_LEVEL_ERROR,
  2578. "Config change transitional member list allocation error\n");
  2579. assert(0);
  2580. }
  2581. memcpy(trans_member_list, member_list,
  2582. sizeof(struct totem_ip_address) * member_list_entries);
  2583. }
  2584. }
  2585. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  2586. joined_member_count = joined_list_entries;
  2587. total_member_count = member_list_entries;
  2588. if (joined_member_list) {
  2589. free(joined_member_list);
  2590. joined_member_list = 0;
  2591. }
  2592. if (joined_list_entries) {
  2593. joined_member_list =
  2594. malloc(sizeof(struct totem_ip_address) * joined_list_entries);
  2595. if (!joined_member_list) {
  2596. /*
  2597. * ERROR: No recovery.
  2598. */
  2599. log_printf(LOG_LEVEL_ERROR,
  2600. "Config change joined list allocation error\n");
  2601. assert(0);
  2602. }
  2603. memcpy(joined_member_list, joined_list,
  2604. sizeof(struct totem_ip_address) * joined_list_entries);
  2605. }
  2606. if (current_member_list) {
  2607. free(current_member_list);
  2608. current_member_list = 0;
  2609. }
  2610. if (member_list_entries) {
  2611. current_member_list =
  2612. malloc(sizeof(struct totem_ip_address) * member_list_entries);
  2613. if (!current_member_list) {
  2614. /*
  2615. * ERROR: No recovery.
  2616. */
  2617. log_printf(LOG_LEVEL_ERROR,
  2618. "Config change member list allocation error\n");
  2619. assert(0);
  2620. }
  2621. memcpy(current_member_list, member_list,
  2622. sizeof(struct totem_ip_address) * member_list_entries);
  2623. }
  2624. }
  2625. }
  2626. /*
  2627. * saEvtFinalize Handler
  2628. */
  2629. static int evt_lib_exit(void *conn)
  2630. {
  2631. struct event_svr_channel_open *eco;
  2632. struct list_head *l, *nxt;
  2633. struct open_chan_pending *ocp;
  2634. struct unlink_chan_pending *ucp;
  2635. struct retention_time_clear_pending *rtc;
  2636. struct libevt_pd *esip =
  2637. openais_conn_private_data_get(openais_conn_partner_get(conn));
  2638. log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize (Event exit request)\n");
  2639. log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize %d evts on list\n",
  2640. esip->esi_nevents);
  2641. /*
  2642. * Clean up any open channels and associated subscriptions.
  2643. */
  2644. for (l = esip->esi_open_chans.next; l != &esip->esi_open_chans; l = nxt) {
  2645. nxt = l->next;
  2646. eco = list_entry(l, struct event_svr_channel_open, eco_instance_entry);
  2647. common_chan_close(eco, esip);
  2648. hdb_handle_destroy(&esip->esi_hdb, eco->eco_my_handle);
  2649. }
  2650. /*
  2651. * Clean up any pending async operations
  2652. */
  2653. for (l = open_pending.next; l != &open_pending; l = nxt) {
  2654. nxt = l->next;
  2655. ocp = list_entry(l, struct open_chan_pending, ocp_entry);
  2656. if (esip == openais_conn_private_data_get(ocp->ocp_conn)) {
  2657. list_del(&ocp->ocp_entry);
  2658. free(ocp);
  2659. }
  2660. }
  2661. for (l = unlink_pending.next; l != &unlink_pending; l = nxt) {
  2662. nxt = l->next;
  2663. ucp = list_entry(l, struct unlink_chan_pending, ucp_entry);
  2664. if (esip == openais_conn_private_data_get(ucp->ucp_conn)) {
  2665. list_del(&ucp->ucp_entry);
  2666. free(ucp);
  2667. }
  2668. }
  2669. for (l = clear_pending.next;
  2670. l != &clear_pending; l = nxt) {
  2671. nxt = l->next;
  2672. rtc = list_entry(l, struct retention_time_clear_pending, rtc_entry);
  2673. if (esip == openais_conn_private_data_get(rtc->rtc_conn)) {
  2674. list_del(&rtc->rtc_entry);
  2675. free(rtc);
  2676. }
  2677. }
  2678. return 0;
  2679. }
  2680. /*
  2681. * Called at service start time.
  2682. */
  2683. static int evt_exec_init(struct openais_config *openais_config)
  2684. {
  2685. log_printf(LOG_LEVEL_DEBUG, "Evt exec init request\n");
  2686. if (openais_config->evt_delivery_queue_size) {
  2687. evt_delivery_queue_size = openais_config->evt_delivery_queue_size;
  2688. log_printf(LOG_LEVEL_NOTICE,
  2689. "event delivery_queue_size set to %u\n",
  2690. evt_delivery_queue_size);
  2691. }
  2692. if (openais_config->evt_delivery_queue_resume) {
  2693. evt_delivery_queue_resume = openais_config->evt_delivery_queue_resume;
  2694. log_printf(LOG_LEVEL_NOTICE,
  2695. "event delivery_queue_resume set to %u\n",
  2696. evt_delivery_queue_resume);
  2697. }
  2698. /*
  2699. * Create an event to be sent when we have to drop messages
  2700. * for an application.
  2701. */
  2702. dropped_event_size = sizeof(*dropped_event) + sizeof(dropped_pattern);
  2703. dropped_event = malloc(dropped_event_size);
  2704. if (dropped_event == 0) {
  2705. log_printf(LOG_LEVEL_ERROR,
  2706. "Memory Allocation Failure, event service not started\n");
  2707. errno = ENOMEM;
  2708. return -1;
  2709. }
  2710. memset(dropped_event, 0, sizeof(*dropped_event) + sizeof(dropped_pattern));
  2711. dropped_event->ed_ref_count = 1;
  2712. list_init(&dropped_event->ed_retained);
  2713. dropped_event->ed_event.led_head.size =
  2714. sizeof(*dropped_event) + sizeof(dropped_pattern);
  2715. dropped_event->ed_event.led_head.error = SA_AIS_OK;
  2716. dropped_event->ed_event.led_priority = SA_EVT_HIGHEST_PRIORITY;
  2717. dropped_event->ed_event.led_chan_name = lost_chan;
  2718. dropped_event->ed_event.led_publisher_name = dropped_publisher;
  2719. dropped_event->ed_event.led_patterns_number = 1;
  2720. memcpy(&dropped_event->ed_event.led_body[0],
  2721. &dropped_pattern, sizeof(dropped_pattern));
  2722. return 0;
  2723. }
  2724. static int
  2725. try_deliver_event(struct event_data *evt,
  2726. struct event_svr_channel_instance *eci)
  2727. {
  2728. struct list_head *l, *l1;
  2729. struct event_svr_channel_open *eco;
  2730. struct event_svr_channel_subscr *ecs;
  2731. int delivered_event = 0;
  2732. /*
  2733. * Check open channels
  2734. */
  2735. for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) {
  2736. eco = list_entry(l, struct event_svr_channel_open, eco_entry);
  2737. /*
  2738. * See if enabled to receive
  2739. */
  2740. if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
  2741. continue;
  2742. }
  2743. /*
  2744. * Check subscriptions
  2745. */
  2746. for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) {
  2747. ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry);
  2748. /*
  2749. * Apply filter rules and deliver if patterns
  2750. * match filters.
  2751. * Only deliver one event per open channel
  2752. */
  2753. if (event_match(evt, ecs) == SA_AIS_OK) {
  2754. deliver_event(evt, eco, ecs);
  2755. delivered_event++;
  2756. break;
  2757. }
  2758. }
  2759. }
  2760. return delivered_event;
  2761. }
  2762. /*
  2763. * Receive the network event message and distribute it to local subscribers
  2764. */
  2765. static void evt_remote_evt(void *msg, struct totem_ip_address *source_addr)
  2766. {
  2767. /*
  2768. * - retain events that have a retention time
  2769. * - Find assocated channel
  2770. * - Scan list of subscribers
  2771. * - Apply filters
  2772. * - Deliver events that pass the filter test
  2773. */
  2774. struct lib_event_data *evtpkt = msg;
  2775. struct event_svr_channel_instance *eci;
  2776. struct event_data *evt;
  2777. SaClmClusterNodeT *cn;
  2778. log_printf(LOG_LEVEL_DEBUG, "Remote event data received from %s\n",
  2779. totemip_print(source_addr));
  2780. /*
  2781. * See where the message came from so that we can set the
  2782. * publishing node id in the message before delivery.
  2783. */
  2784. cn = main_clm_get_by_nodeid(source_addr->nodeid);
  2785. if (!cn) {
  2786. /*
  2787. * Not sure how this can happen...
  2788. */
  2789. log_printf(LOG_LEVEL_DEBUG, "No cluster node data for %s\n",
  2790. totemip_print(source_addr));
  2791. errno = ENXIO;
  2792. return;
  2793. }
  2794. log_printf(LOG_LEVEL_DEBUG, "Cluster node ID 0x%x name %s\n",
  2795. cn->nodeId, cn->nodeName.value);
  2796. evtpkt->led_publisher_node_id = cn->nodeId;
  2797. totemip_copy(&evtpkt->led_addr, source_addr);
  2798. evtpkt->led_receive_time = clust_time_now();
  2799. if (evtpkt->led_chan_unlink_id != EVT_CHAN_ACTIVE) {
  2800. log_printf(CHAN_UNLINK_DEBUG,
  2801. "evt_remote_evt(0): chan %s, id 0x%llx\n",
  2802. evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
  2803. }
  2804. eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id);
  2805. /*
  2806. * We may have had some events that were already queued when an
  2807. * unlink happened, if we don't find the channel in the active list
  2808. * look for the last unlinked channel of the same name. If this channel
  2809. * is re-opened the messages will still be routed correctly because new
  2810. * active channel messages will be ordered behind the open.
  2811. */
  2812. if (!eci && (evtpkt->led_chan_unlink_id == EVT_CHAN_ACTIVE)) {
  2813. log_printf(CHAN_UNLINK_DEBUG,
  2814. "evt_remote_evt(1): chan %s, id 0x%llx\n",
  2815. evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
  2816. eci = find_last_unlinked_channel(&evtpkt->led_chan_name);
  2817. }
  2818. /*
  2819. * We shouldn't normally see an event for a channel that we
  2820. * don't know about.
  2821. */
  2822. if (!eci) {
  2823. log_printf(LOG_LEVEL_DEBUG, "Channel %s doesn't exist\n",
  2824. evtpkt->led_chan_name.value);
  2825. return;
  2826. }
  2827. if (check_last_event(evtpkt, source_addr)) {
  2828. return;
  2829. }
  2830. evt = make_local_event(evtpkt, eci);
  2831. if (!evt) {
  2832. log_printf(LOG_LEVEL_WARNING,
  2833. "1Memory allocation error, can't deliver event\n");
  2834. return;
  2835. }
  2836. if (evt->ed_event.led_retention_time) {
  2837. retain_event(evt);
  2838. }
  2839. try_deliver_event(evt, eci);
  2840. free_event_data(evt);
  2841. }
  2842. /*
  2843. * Calculate the remaining retention time of a received event during recovery
  2844. */
  2845. inline SaTimeT calc_retention_time(SaTimeT retention,
  2846. SaTimeT received, SaTimeT now)
  2847. {
  2848. if ((received < now) && ((now - received) < retention)) {
  2849. return retention - (now - received);
  2850. } else {
  2851. return 0;
  2852. }
  2853. }
  2854. /*
  2855. * Receive a recovery network event message and save it in the retained list
  2856. */
  2857. static void evt_remote_recovery_evt(void *msg, struct totem_ip_address *source_addr)
  2858. {
  2859. /*
  2860. * - calculate remaining retention time
  2861. * - Find assocated channel
  2862. * - Scan list of subscribers
  2863. * - Apply filters
  2864. * - Deliver events that pass the filter test
  2865. */
  2866. struct lib_event_data *evtpkt = msg;
  2867. struct event_svr_channel_instance *eci;
  2868. struct event_data *evt;
  2869. struct member_node_data *md;
  2870. int num_delivered;
  2871. SaTimeT now;
  2872. now = clust_time_now();
  2873. log_printf(RECOVERY_EVENT_DEBUG,
  2874. "Remote recovery event data received from %s\n",
  2875. totemip_print(source_addr));
  2876. if (recovery_phase == evt_recovery_complete) {
  2877. log_printf(RECOVERY_EVENT_DEBUG,
  2878. "Received recovery data, not in recovery mode\n");
  2879. return;
  2880. }
  2881. log_printf(RECOVERY_EVENT_DEBUG,
  2882. "Processing recovery of retained events\n");
  2883. if (recovery_node) {
  2884. log_printf(RECOVERY_EVENT_DEBUG, "This node is the recovery node\n");
  2885. }
  2886. log_printf(RECOVERY_EVENT_DEBUG, "(1)EVT ID: %llx, Time: %llx\n",
  2887. evtpkt->led_event_id, evtpkt->led_retention_time);
  2888. /*
  2889. * Calculate remaining retention time
  2890. */
  2891. evtpkt->led_retention_time = calc_retention_time(
  2892. evtpkt->led_retention_time,
  2893. evtpkt->led_receive_time,
  2894. now);
  2895. log_printf(RECOVERY_EVENT_DEBUG,
  2896. "(2)EVT ID: %llx, ret: %llx, rec: %llx, now: %llx\n",
  2897. evtpkt->led_event_id,
  2898. evtpkt->led_retention_time, evtpkt->led_receive_time, now);
  2899. /*
  2900. * If we haven't seen this event yet and it has remaining time, process
  2901. * the event.
  2902. */
  2903. if (!check_last_event(evtpkt, &evtpkt->led_addr) &&
  2904. evtpkt->led_retention_time) {
  2905. /*
  2906. * See where the message came from so that we can set the
  2907. * publishing node id in the message before delivery.
  2908. */
  2909. md = evt_find_node(&evtpkt->led_addr);
  2910. if (!md) {
  2911. /*
  2912. * Not sure how this can happen
  2913. */
  2914. log_printf(LOG_LEVEL_NOTICE, "No node for %s\n",
  2915. totemip_print(&evtpkt->led_addr));
  2916. return;
  2917. }
  2918. log_printf(LOG_LEVEL_DEBUG, "Cluster node ID 0x%x name %s\n",
  2919. md->mn_node_info.nodeId,
  2920. md->mn_node_info.nodeName.value);
  2921. log_printf(CHAN_UNLINK_DEBUG,
  2922. "evt_recovery_event: chan %s, id 0x%llx\n",
  2923. evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
  2924. eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id);
  2925. /*
  2926. * We shouldn't normally see an event for a channel that we don't
  2927. * know about.
  2928. */
  2929. if (!eci) {
  2930. log_printf(RECOVERY_EVENT_DEBUG, "Channel %s doesn't exist\n",
  2931. evtpkt->led_chan_name.value);
  2932. return;
  2933. }
  2934. evt = make_local_event(evtpkt, eci);
  2935. if (!evt) {
  2936. log_printf(LOG_LEVEL_WARNING,
  2937. "2Memory allocation error, can't deliver event\n");
  2938. errno = ENOMEM;
  2939. return;
  2940. }
  2941. retain_event(evt);
  2942. num_delivered = try_deliver_event(evt, eci);
  2943. log_printf(RECOVERY_EVENT_DEBUG, "Delivered to %d subscribers\n",
  2944. num_delivered);
  2945. free_event_data(evt);
  2946. }
  2947. }
  2948. /*
  2949. * Timeout handler for event channel open. We flag the structure
  2950. * as timed out. Then if the open request is ever returned, we can
  2951. * issue a close channel and keep the reference counting correct.
  2952. */
  2953. static void chan_open_timeout(void *data)
  2954. {
  2955. struct open_chan_pending *ocp = (struct open_chan_pending *)data;
  2956. struct res_evt_channel_open res;
  2957. res.ico_head.size = sizeof(res);
  2958. res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
  2959. res.ico_head.error = SA_AIS_ERR_TIMEOUT;
  2960. ocp->ocp_invocation = OPEN_TIMED_OUT;
  2961. openais_conn_send_response(ocp->ocp_conn, &res, sizeof(res));
  2962. }
  2963. /*
  2964. * Called by the channel open exec handler to finish the open and
  2965. * respond to the application
  2966. */
  2967. static void evt_chan_open_finish(struct open_chan_pending *ocp,
  2968. struct event_svr_channel_instance *eci)
  2969. {
  2970. struct event_svr_channel_open *eco;
  2971. SaAisErrorT error = SA_AIS_OK;
  2972. unsigned int ret = 0;
  2973. unsigned int timer_del_status = 0;
  2974. void *ptr = 0;
  2975. uint32_t handle;
  2976. struct libevt_pd *esip;
  2977. esip = (struct libevt_pd *)openais_conn_private_data_get(ocp->ocp_conn);
  2978. log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s\n",
  2979. getSaNameT(&ocp->ocp_chan_name));
  2980. if (ocp->ocp_timer_handle) {
  2981. timer_del_status = poll_timer_delete(aisexec_poll_handle,
  2982. ocp->ocp_timer_handle);
  2983. if (timer_del_status != 0) {
  2984. log_printf(LOG_LEVEL_WARNING,
  2985. "Error clearing timeout for open channel of %s\n",
  2986. getSaNameT(&ocp->ocp_chan_name));
  2987. }
  2988. }
  2989. /*
  2990. * If this is a finished open for a timed out request, then
  2991. * send out a close on this channel to clean things up.
  2992. */
  2993. if (ocp->ocp_invocation == OPEN_TIMED_OUT) {
  2994. log_printf(CHAN_OPEN_DEBUG, "Closing timed out open of %s\n",
  2995. getSaNameT(&ocp->ocp_chan_name));
  2996. error = evt_close_channel(&ocp->ocp_chan_name, EVT_CHAN_ACTIVE);
  2997. if (error != SA_AIS_OK) {
  2998. log_printf(CHAN_OPEN_DEBUG,
  2999. "Close of timed out open failed for %s\n",
  3000. getSaNameT(&ocp->ocp_chan_name));
  3001. }
  3002. list_del(&ocp->ocp_entry);
  3003. free(ocp);
  3004. return;
  3005. }
  3006. /*
  3007. * Create a handle to give back to the caller to associate
  3008. * with this channel open instance.
  3009. */
  3010. ret = hdb_handle_create(&esip->esi_hdb, sizeof(*eco), &handle);
  3011. if (ret != 0) {
  3012. goto open_return;
  3013. }
  3014. ret = hdb_handle_get(&esip->esi_hdb, handle, &ptr);
  3015. if (ret != 0) {
  3016. goto open_return;
  3017. }
  3018. eco = ptr;
  3019. /*
  3020. * Initailize and link into the global channel structure.
  3021. */
  3022. list_init(&eco->eco_subscr);
  3023. list_init(&eco->eco_entry);
  3024. list_init(&eco->eco_instance_entry);
  3025. eco->eco_flags = ocp->ocp_open_flag;
  3026. eco->eco_channel = eci;
  3027. eco->eco_lib_handle = ocp->ocp_c_handle;
  3028. eco->eco_my_handle = handle;
  3029. eco->eco_conn = ocp->ocp_conn;
  3030. list_add_tail(&eco->eco_entry, &eci->esc_open_chans);
  3031. list_add_tail(&eco->eco_instance_entry, &esip->esi_open_chans);
  3032. /*
  3033. * respond back with a handle to access this channel
  3034. * open instance for later subscriptions, etc.
  3035. */
  3036. hdb_handle_put(&esip->esi_hdb, handle);
  3037. open_return:
  3038. log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s send response %d\n",
  3039. getSaNameT(&ocp->ocp_chan_name),
  3040. error);
  3041. if (ocp->ocp_async) {
  3042. struct res_evt_open_chan_async resa;
  3043. resa.ica_head.size = sizeof(resa);
  3044. resa.ica_head.id = MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK;
  3045. resa.ica_head.error = (ret == 0 ? SA_AIS_OK: SA_AIS_ERR_BAD_HANDLE);
  3046. resa.ica_channel_handle = handle;
  3047. resa.ica_c_handle = ocp->ocp_c_handle;
  3048. resa.ica_invocation = ocp->ocp_invocation;
  3049. openais_conn_send_response(openais_conn_partner_get(ocp->ocp_conn),
  3050. &resa, sizeof(resa));
  3051. } else {
  3052. struct res_evt_channel_open res;
  3053. res.ico_head.size = sizeof(res);
  3054. res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
  3055. res.ico_head.error = (ret == 0 ? SA_AIS_OK : SA_AIS_ERR_BAD_HANDLE);
  3056. res.ico_channel_handle = handle;
  3057. openais_conn_send_response(ocp->ocp_conn, &res, sizeof(res));
  3058. }
  3059. if (timer_del_status == 0) {
  3060. list_del(&ocp->ocp_entry);
  3061. free(ocp);
  3062. }
  3063. }
  3064. /*
  3065. * Called by the channel unlink exec handler to
  3066. * respond to the application.
  3067. */
  3068. static void evt_chan_unlink_finish(struct unlink_chan_pending *ucp)
  3069. {
  3070. struct res_evt_channel_unlink res;
  3071. log_printf(CHAN_UNLINK_DEBUG, "Unlink channel finish ID 0x%llx\n",
  3072. ucp->ucp_unlink_id);
  3073. list_del(&ucp->ucp_entry);
  3074. res.iuc_head.size = sizeof(res);
  3075. res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL;
  3076. res.iuc_head.error = SA_AIS_OK;
  3077. openais_conn_send_response(ucp->ucp_conn, &res, sizeof(res));
  3078. free(ucp);
  3079. }
  3080. /*
  3081. * Called by the retention time clear exec handler to
  3082. * respond to the application.
  3083. */
  3084. static void evt_ret_time_clr_finish(struct retention_time_clear_pending *rtc,
  3085. SaAisErrorT ret)
  3086. {
  3087. struct res_evt_event_clear_retentiontime res;
  3088. log_printf(RETENTION_TIME_DEBUG, "Retention Time Clear finish ID 0x%llx\n",
  3089. rtc->rtc_event_id);
  3090. res.iec_head.size = sizeof(res);
  3091. res.iec_head.id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME;
  3092. res.iec_head.error = ret;
  3093. openais_conn_send_response(rtc->rtc_conn, &res, sizeof(res));
  3094. list_del(&rtc->rtc_entry);
  3095. free(rtc);
  3096. }
  3097. /*
  3098. * Take the channel command data and swap the elements so they match
  3099. * our architectures word order.
  3100. */
  3101. static void
  3102. convert_chan_packet(void *msg)
  3103. {
  3104. struct req_evt_chan_command *cpkt = (struct req_evt_chan_command *)msg;
  3105. /*
  3106. * converted in the main deliver_fn:
  3107. * led_head.id, led_head.size.
  3108. *
  3109. */
  3110. cpkt->chc_op = swab32(cpkt->chc_op);
  3111. /*
  3112. * Which elements of the packet that are converted depend
  3113. * on the operation.
  3114. */
  3115. switch (cpkt->chc_op) {
  3116. case EVT_OPEN_CHAN_OP:
  3117. cpkt->u.chc_chan.ocr_name.length =
  3118. swab16(cpkt->u.chc_chan.ocr_name.length);
  3119. cpkt->u.chc_chan.ocr_serial_no = swab64(cpkt->u.chc_chan.ocr_serial_no);
  3120. break;
  3121. case EVT_UNLINK_CHAN_OP:
  3122. case EVT_CLOSE_CHAN_OP:
  3123. cpkt->u.chcu.chcu_name.length = swab16(cpkt->u.chcu.chcu_name.length);
  3124. cpkt->u.chcu.chcu_unlink_id = swab64(cpkt->u.chcu.chcu_unlink_id);
  3125. break;
  3126. case EVT_CLEAR_RET_OP:
  3127. cpkt->u.chc_event_id = swab64(cpkt->u.chc_event_id);
  3128. break;
  3129. case EVT_SET_ID_OP:
  3130. cpkt->u.chc_set_id.chc_nodeid =
  3131. swab32(cpkt->u.chc_set_id.chc_nodeid);
  3132. cpkt->u.chc_set_id.chc_last_id = swab64(cpkt->u.chc_set_id.chc_last_id);
  3133. break;
  3134. case EVT_OPEN_COUNT:
  3135. cpkt->u.chc_set_opens.chc_chan_name.length =
  3136. swab16(cpkt->u.chc_set_opens.chc_chan_name.length);
  3137. cpkt->u.chc_set_opens.chc_open_count =
  3138. swab32(cpkt->u.chc_set_opens.chc_open_count);
  3139. break;
  3140. /*
  3141. * No data assocaited with these ops.
  3142. */
  3143. case EVT_CONF_DONE:
  3144. case EVT_OPEN_COUNT_DONE:
  3145. break;
  3146. /*
  3147. * Make sure that this function is updated when new ops are added.
  3148. */
  3149. default:
  3150. assert(0);
  3151. }
  3152. }
  3153. /*
  3154. * Receive and process remote event operations.
  3155. * Used to communicate channel opens/closes, clear retention time,
  3156. * config change updates...
  3157. */
  3158. static void evt_remote_chan_op(void *msg, struct totem_ip_address *source_addr)
  3159. {
  3160. struct req_evt_chan_command *cpkt = msg;
  3161. unsigned int local_node = {SA_CLM_LOCAL_NODE_ID};
  3162. SaClmClusterNodeT *cn, *my_node;
  3163. struct member_node_data *mn;
  3164. struct event_svr_channel_instance *eci;
  3165. log_printf(REMOTE_OP_DEBUG, "Remote channel operation request\n");
  3166. my_node = main_clm_get_by_nodeid(local_node);
  3167. log_printf(REMOTE_OP_DEBUG, "my node ID: 0x%x\n", my_node->nodeId);
  3168. mn = evt_find_node(source_addr);
  3169. if (mn == NULL) {
  3170. cn = main_clm_get_by_nodeid(source_addr->nodeid);
  3171. if (cn == NULL) {
  3172. log_printf(LOG_LEVEL_WARNING,
  3173. "Evt remote channel op: Node data for addr %s is NULL\n",
  3174. totemip_print(source_addr));
  3175. return;
  3176. } else {
  3177. evt_add_node(source_addr, cn);
  3178. mn = evt_find_node(source_addr);
  3179. }
  3180. }
  3181. switch (cpkt->chc_op) {
  3182. /*
  3183. * Open channel remote command. The open channel request is done
  3184. * in two steps. When an pplication tries to open, we send an open
  3185. * channel message to the other nodes. When we receive an open channel
  3186. * message, we may create the channel structure if it doesn't exist
  3187. * and also complete applicaiton open requests for the specified
  3188. * channel. We keep a counter of total opens for the given channel and
  3189. * later when it has been completely closed (everywhere in the cluster)
  3190. * we will free up the assocated channel data.
  3191. */
  3192. case EVT_OPEN_CHAN_OP: {
  3193. struct open_chan_pending *ocp;
  3194. struct list_head *l, *nxt;
  3195. log_printf(CHAN_OPEN_DEBUG, "Opening channel %s for node 0x%x\n",
  3196. cpkt->u.chc_chan.ocr_name.value,
  3197. mn->mn_node_info.nodeId);
  3198. eci = find_channel(&cpkt->u.chc_chan.ocr_name, EVT_CHAN_ACTIVE);
  3199. if (!eci) {
  3200. eci = create_channel(&cpkt->u.chc_chan.ocr_name);
  3201. }
  3202. if (!eci) {
  3203. log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n",
  3204. getSaNameT(&cpkt->u.chc_chan.ocr_name));
  3205. break;
  3206. }
  3207. inc_open_count(eci, mn->mn_node_info.nodeId);
  3208. if (mn->mn_node_info.nodeId == my_node->nodeId) {
  3209. /*
  3210. * Complete one of our pending open requests
  3211. */
  3212. for (l = open_pending.next; l != &open_pending; l = nxt) {
  3213. nxt = l->next;
  3214. ocp = list_entry(l, struct open_chan_pending, ocp_entry);
  3215. log_printf(CHAN_OPEN_DEBUG,
  3216. "Compare channel req no %llu %llu\n",
  3217. ocp->ocp_serial_no,
  3218. cpkt->u.chc_chan.ocr_serial_no);
  3219. if (ocp->ocp_serial_no == cpkt->u.chc_chan.ocr_serial_no) {
  3220. evt_chan_open_finish(ocp, eci);
  3221. break;
  3222. }
  3223. }
  3224. }
  3225. log_printf(CHAN_OPEN_DEBUG,
  3226. "Open channel %s t %d, l %d, r %d\n",
  3227. getSaNameT(&eci->esc_channel_name),
  3228. eci->esc_total_opens, eci->esc_local_opens,
  3229. eci->esc_retained_count);
  3230. break;
  3231. }
  3232. /*
  3233. * Handle a channel close. We'll decrement the global open counter and
  3234. * free up channel associated data when all instances are closed.
  3235. */
  3236. case EVT_CLOSE_CHAN_OP:
  3237. log_printf(LOG_LEVEL_DEBUG, "Closing channel %s for node 0x%x\n",
  3238. cpkt->u.chcu.chcu_name.value, mn->mn_node_info.nodeId);
  3239. eci = find_channel(&cpkt->u.chcu.chcu_name, cpkt->u.chcu.chcu_unlink_id);
  3240. if (!eci) {
  3241. log_printf(LOG_LEVEL_NOTICE,
  3242. "Channel close request for %s not found\n",
  3243. cpkt->u.chcu.chcu_name.value);
  3244. break;
  3245. }
  3246. /*
  3247. * if last instance, we can free up assocated data.
  3248. */
  3249. dec_open_count(eci, mn->mn_node_info.nodeId);
  3250. log_printf(LOG_LEVEL_DEBUG,
  3251. "Close channel %s t %d, l %d, r %d\n",
  3252. eci->esc_channel_name.value,
  3253. eci->esc_total_opens, eci->esc_local_opens,
  3254. eci->esc_retained_count);
  3255. delete_channel(eci);
  3256. break;
  3257. /*
  3258. * Handle a request for channel unlink saEvtChannelUnlink().
  3259. * We'll look up the channel and mark it as unlinked. Respond to
  3260. * local library unlink commands.
  3261. */
  3262. case EVT_UNLINK_CHAN_OP: {
  3263. struct unlink_chan_pending *ucp;
  3264. struct list_head *l, *nxt;
  3265. log_printf(CHAN_UNLINK_DEBUG,
  3266. "Unlink request channel %s unlink ID 0x%llx from node 0x%x\n",
  3267. cpkt->u.chcu.chcu_name.value,
  3268. cpkt->u.chcu.chcu_unlink_id,
  3269. mn->mn_node_info.nodeId);
  3270. /*
  3271. * look up the channel name and get its assoicated data.
  3272. */
  3273. eci = find_channel(&cpkt->u.chcu.chcu_name,
  3274. EVT_CHAN_ACTIVE);
  3275. if (!eci) {
  3276. log_printf(LOG_LEVEL_NOTICE,
  3277. "Channel unlink request for %s not found\n",
  3278. cpkt->u.chcu.chcu_name.value);
  3279. } else {
  3280. /*
  3281. * Mark channel as unlinked.
  3282. */
  3283. unlink_channel(eci, cpkt->u.chcu.chcu_unlink_id);
  3284. }
  3285. /*
  3286. * respond only to local library requests.
  3287. */
  3288. if (mn->mn_node_info.nodeId == my_node->nodeId) {
  3289. /*
  3290. * Complete one of our pending unlink requests
  3291. */
  3292. for (l = unlink_pending.next; l != &unlink_pending; l = nxt) {
  3293. nxt = l->next;
  3294. ucp = list_entry(l, struct unlink_chan_pending, ucp_entry);
  3295. log_printf(CHAN_UNLINK_DEBUG,
  3296. "Compare channel id 0x%llx 0x%llx\n",
  3297. ucp->ucp_unlink_id, cpkt->u.chcu.chcu_unlink_id);
  3298. if (ucp->ucp_unlink_id == cpkt->u.chcu.chcu_unlink_id) {
  3299. evt_chan_unlink_finish(ucp);
  3300. break;
  3301. }
  3302. }
  3303. }
  3304. break;
  3305. }
  3306. /*
  3307. * saEvtClearRetentionTime handler.
  3308. */
  3309. case EVT_CLEAR_RET_OP:
  3310. {
  3311. SaAisErrorT did_clear;
  3312. struct retention_time_clear_pending *rtc;
  3313. struct list_head *l, *nxt;
  3314. log_printf(RETENTION_TIME_DEBUG, "Clear retention time request %llx\n",
  3315. cpkt->u.chc_event_id);
  3316. did_clear = clear_retention_time(cpkt->u.chc_event_id);
  3317. /*
  3318. * Respond to local library requests
  3319. */
  3320. if (mn->mn_node_info.nodeId == my_node->nodeId) {
  3321. /*
  3322. * Complete pending request
  3323. */
  3324. for (l = clear_pending.next; l != &clear_pending; l = nxt) {
  3325. nxt = l->next;
  3326. rtc = list_entry(l, struct retention_time_clear_pending,
  3327. rtc_entry);
  3328. if (rtc->rtc_event_id == cpkt->u.chc_event_id) {
  3329. evt_ret_time_clr_finish(rtc, did_clear);
  3330. break;
  3331. }
  3332. }
  3333. }
  3334. break;
  3335. }
  3336. /*
  3337. * Set our next event ID based on the largest event ID seen
  3338. * by others in the cluster. This way, if we've left and re-joined, we'll
  3339. * start using an event ID that is unique.
  3340. */
  3341. case EVT_SET_ID_OP: {
  3342. int log_level = LOG_LEVEL_DEBUG;
  3343. if (cpkt->u.chc_set_id.chc_nodeid == my_node->nodeId) {
  3344. log_level = RECOVERY_DEBUG;
  3345. }
  3346. log_printf(log_level,
  3347. "Received Set event ID OP from %s to %llx for %x my addr %x base %llx\n",
  3348. totemip_print(source_addr),
  3349. cpkt->u.chc_set_id.chc_last_id,
  3350. cpkt->u.chc_set_id.chc_nodeid,
  3351. my_node->nodeId,
  3352. base_id);
  3353. if (cpkt->u.chc_set_id.chc_nodeid == my_node->nodeId) {
  3354. if (cpkt->u.chc_set_id.chc_last_id >= base_id) {
  3355. log_printf(RECOVERY_DEBUG,
  3356. "Set event ID from %s to %llx\n",
  3357. totemip_print(source_addr), cpkt->u.chc_set_id.chc_last_id);
  3358. base_id = cpkt->u.chc_set_id.chc_last_id + 1;
  3359. }
  3360. }
  3361. break;
  3362. }
  3363. /*
  3364. * Receive the open count for a particular channel during recovery.
  3365. * This insures that everyone has the same notion of who has a channel
  3366. * open so that it can be removed when no one else has it open anymore.
  3367. */
  3368. case EVT_OPEN_COUNT:
  3369. if (recovery_phase == evt_recovery_complete) {
  3370. log_printf(LOG_LEVEL_ERROR,
  3371. "Evt open count msg from %s, but not in membership change\n",
  3372. totemip_print(source_addr));
  3373. }
  3374. /*
  3375. * Zero out all open counts because we're setting then based
  3376. * on each nodes local counts.
  3377. */
  3378. if (!processed_open_counts) {
  3379. zero_chan_open_counts();
  3380. processed_open_counts = 1;
  3381. }
  3382. log_printf(RECOVERY_DEBUG,
  3383. "Open channel count %s is %d for node 0x%x\n",
  3384. cpkt->u.chc_set_opens.chc_chan_name.value,
  3385. cpkt->u.chc_set_opens.chc_open_count,
  3386. mn->mn_node_info.nodeId);
  3387. eci = find_channel(&cpkt->u.chc_set_opens.chc_chan_name,
  3388. EVT_CHAN_ACTIVE);
  3389. if (!eci) {
  3390. eci = create_channel(&cpkt->u.chc_set_opens.chc_chan_name);
  3391. }
  3392. if (!eci) {
  3393. log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n",
  3394. getSaNameT(&cpkt->u.chc_set_opens.chc_chan_name));
  3395. break;
  3396. }
  3397. if (set_open_count(eci, mn->mn_node_info.nodeId,
  3398. cpkt->u.chc_set_opens.chc_open_count)) {
  3399. log_printf(LOG_LEVEL_ERROR,
  3400. "Error setting Open channel count %s for node 0x%x\n",
  3401. cpkt->u.chc_set_opens.chc_chan_name.value,
  3402. mn->mn_node_info.nodeId);
  3403. }
  3404. break;
  3405. /*
  3406. * Once we get all the messages from
  3407. * the current membership, determine who delivers any retained events.
  3408. */
  3409. case EVT_OPEN_COUNT_DONE: {
  3410. if (recovery_phase == evt_recovery_complete) {
  3411. log_printf(LOG_LEVEL_ERROR,
  3412. "Evt config msg from %s, but not in membership change\n",
  3413. totemip_print(source_addr));
  3414. }
  3415. log_printf(RECOVERY_DEBUG,
  3416. "Receive EVT_CONF_CHANGE_DONE from %s members %d checked in %d\n",
  3417. totemip_print(source_addr), total_member_count, checked_in+1);
  3418. if (!mn) {
  3419. log_printf(RECOVERY_DEBUG,
  3420. "NO NODE DATA AVAILABLE FOR %s\n",
  3421. totemip_print(source_addr));
  3422. }
  3423. if (++checked_in == total_member_count) {
  3424. /*
  3425. * We're all here, now figure out who should send the
  3426. * retained events.
  3427. */
  3428. mn = oldest_node();
  3429. if (mn && mn->mn_node_info.nodeId == my_node_id) {
  3430. log_printf(RECOVERY_DEBUG,
  3431. "I am oldest in my transitional config\n");
  3432. recovery_node = 1;
  3433. recovery_phase = evt_send_retained_events;
  3434. } else {
  3435. recovery_phase = evt_send_retained_events_done;
  3436. recovery_node = 0;
  3437. }
  3438. checked_in = 0;
  3439. }
  3440. break;
  3441. }
  3442. /*
  3443. * Count up the nodes again, when all the nodes have responded, we've
  3444. * distributed the retained events and we're done with recovery and can
  3445. * continue operations.
  3446. */
  3447. case EVT_CONF_DONE: {
  3448. log_printf(RECOVERY_DEBUG,
  3449. "Receive EVT_CONF_DONE from %s, members %d checked in %d\n",
  3450. totemip_print(source_addr),
  3451. total_member_count, checked_in+1);
  3452. if (++checked_in == total_member_count) {
  3453. /*
  3454. * All recovery complete, carry on.
  3455. */
  3456. recovery_phase = evt_recovery_complete;
  3457. #ifdef DUMP_CHAN_INFO
  3458. dump_all_chans();
  3459. #endif
  3460. }
  3461. break;
  3462. }
  3463. default:
  3464. log_printf(LOG_LEVEL_NOTICE, "Invalid channel operation %d\n",
  3465. cpkt->chc_op);
  3466. break;
  3467. }
  3468. }
  3469. /*
  3470. * Set up initial conditions for processing event service
  3471. * recovery.
  3472. */
  3473. static void evt_sync_init(void)
  3474. {
  3475. SaClmClusterNodeT *cn;
  3476. struct member_node_data *md;
  3477. unsigned int my_node = {SA_CLM_LOCAL_NODE_ID};
  3478. int left_list_entries = left_member_count;
  3479. struct totem_ip_address *left_list = left_member_list;
  3480. log_printf(RECOVERY_DEBUG, "Evt synchronize initialization\n");
  3481. /*
  3482. * Set the base event id
  3483. */
  3484. if (!my_node_id) {
  3485. cn = main_clm_get_by_nodeid(my_node);
  3486. log_printf(RECOVERY_DEBUG, "My node ID 0x%x\n", cn->nodeId);
  3487. my_node_id = cn->nodeId;
  3488. set_event_id(my_node_id);
  3489. }
  3490. /*
  3491. * account for nodes that left the membership
  3492. */
  3493. while (left_list_entries--) {
  3494. md = evt_find_node(left_list);
  3495. if (md == 0) {
  3496. log_printf(LOG_LEVEL_WARNING,
  3497. "Can't find cluster node at %s\n",
  3498. totemip_print(&left_list[0]));
  3499. /*
  3500. * Mark this one as down.
  3501. */
  3502. } else {
  3503. log_printf(RECOVERY_DEBUG, "cluster node at %s down\n",
  3504. totemip_print(&left_list[0]));
  3505. md->mn_started = 0;
  3506. remove_chan_open_info(md->mn_node_info.nodeId);
  3507. }
  3508. left_list++;
  3509. }
  3510. /*
  3511. * set up for recovery processing, first phase:
  3512. */
  3513. recovery_phase = evt_send_event_id;
  3514. /*
  3515. * List used to distribute last know event IDs.
  3516. */
  3517. add_list = current_member_list;
  3518. add_count = total_member_count;
  3519. processed_open_counts = 0;
  3520. /*
  3521. * List used for distributing open channel counts
  3522. */
  3523. next_chan = esc_head.next;
  3524. /*
  3525. * List used for distributing retained events
  3526. */
  3527. next_retained = retained_list.next;
  3528. /*
  3529. * Member check in counts for open channel counts and
  3530. * retained events.
  3531. */
  3532. checked_in = 0;
  3533. }
  3534. /*
  3535. * Handle event service recovery. It passes through a number of states to
  3536. * finish the recovery.
  3537. *
  3538. * First, the node broadcasts the highest event ID that it has seen for any
  3539. * joinig node. This helps to make sure that rejoining nodes don't re-use
  3540. * event IDs that have already been seen.
  3541. *
  3542. * Next, The node broadcasts its open channel information to the other nodes.
  3543. * This makes sure that any joining nodes have complete data on any channels
  3544. * already open.
  3545. *
  3546. * Once done sending open channel information the node waits in a state for
  3547. * the rest of the nodes to finish sending their data. When the last node
  3548. * has checked in, then the remote channel operation handler selects the next
  3549. * state which is evt_send_retained_events if this is the oldest node in the
  3550. * cluster, or otherwise to evt_wait_send_retained_events to wait for the
  3551. * retained events to be sent. When the retained events have been sent, the
  3552. * state is changed to evt_recovery_complete and this function exits with
  3553. * zero to inidicate that recovery is done.
  3554. */
  3555. static int evt_sync_process(void)
  3556. {
  3557. log_printf(RECOVERY_DEBUG, "Process Evt synchronization \n");
  3558. switch (recovery_phase) {
  3559. /*
  3560. * Send last know event ID to joining nodes to prevent duplicate
  3561. * event IDs.
  3562. */
  3563. case evt_send_event_id:
  3564. {
  3565. struct member_node_data *md;
  3566. SaClmClusterNodeT *cn;
  3567. struct req_evt_chan_command cpkt;
  3568. struct iovec chn_iovec;
  3569. int res;
  3570. log_printf(RECOVERY_DEBUG, "Send max event ID updates\n");
  3571. while (add_count) {
  3572. /*
  3573. * If we've seen this node before, send out the last msg ID
  3574. * that we've seen from him. He will set his base ID for
  3575. * generating event and message IDs to the highest one seen.
  3576. */
  3577. md = evt_find_node(add_list);
  3578. if (md != NULL) {
  3579. log_printf(RECOVERY_DEBUG,
  3580. "Send set evt ID %llx to %s\n",
  3581. md->mn_last_msg_id, totemip_print(add_list));
  3582. md->mn_started = 1;
  3583. memset(&cpkt, 0, sizeof(cpkt));
  3584. cpkt.chc_head.id =
  3585. SERVICE_ID_MAKE (EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  3586. cpkt.chc_head.size = sizeof(cpkt);
  3587. cpkt.chc_op = EVT_SET_ID_OP;
  3588. cpkt.u.chc_set_id.chc_nodeid = add_list->nodeid;
  3589. cpkt.u.chc_set_id.chc_last_id = md->mn_last_msg_id;
  3590. chn_iovec.iov_base = &cpkt;
  3591. chn_iovec.iov_len = cpkt.chc_head.size;
  3592. res = totempg_groups_mcast_joined(openais_group_handle,
  3593. &chn_iovec, 1, TOTEMPG_AGREED);
  3594. if (res != 0) {
  3595. log_printf(RECOVERY_DEBUG,
  3596. "Unable to send event id to %s\n",
  3597. totemip_print(add_list));
  3598. /*
  3599. * We'll try again later.
  3600. */
  3601. return 1;
  3602. }
  3603. } else {
  3604. /*
  3605. * Not seen before, add it to our list of nodes.
  3606. */
  3607. cn = main_clm_get_by_nodeid(add_list->nodeid);
  3608. if (!cn) {
  3609. /*
  3610. * Error: shouldn't happen
  3611. */
  3612. log_printf(LOG_LEVEL_ERROR,
  3613. "recovery error node: %s not found\n",
  3614. totemip_print(add_list));
  3615. assert(0);
  3616. } else {
  3617. evt_add_node(add_list, cn);
  3618. }
  3619. }
  3620. add_list++;
  3621. add_count--;
  3622. }
  3623. recovery_phase = evt_send_open_count;
  3624. return 1;
  3625. }
  3626. /*
  3627. * Send channel open counts so all members have the same channel open
  3628. * counts.
  3629. */
  3630. case evt_send_open_count:
  3631. {
  3632. struct req_evt_chan_command cpkt;
  3633. struct iovec chn_iovec;
  3634. struct event_svr_channel_instance *eci;
  3635. int res;
  3636. log_printf(RECOVERY_DEBUG, "Send open count updates\n");
  3637. /*
  3638. * Process messages. When we're done, send the done message
  3639. * to the nodes.
  3640. */
  3641. memset(&cpkt, 0, sizeof(cpkt));
  3642. for (;next_chan != &esc_head;
  3643. next_chan = next_chan->next) {
  3644. log_printf(RECOVERY_DEBUG, "Sending next open count\n");
  3645. eci = list_entry(next_chan, struct event_svr_channel_instance,
  3646. esc_entry);
  3647. cpkt.chc_head.id =
  3648. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  3649. cpkt.chc_head.size = sizeof(cpkt);
  3650. cpkt.chc_op = EVT_OPEN_COUNT;
  3651. cpkt.u.chc_set_opens.chc_chan_name = eci->esc_channel_name;
  3652. cpkt.u.chc_set_opens.chc_open_count = eci->esc_local_opens;
  3653. chn_iovec.iov_base = &cpkt;
  3654. chn_iovec.iov_len = cpkt.chc_head.size;
  3655. res = totempg_groups_mcast_joined(openais_group_handle,
  3656. &chn_iovec, 1, TOTEMPG_AGREED);
  3657. if (res != 0) {
  3658. /*
  3659. * Try again later.
  3660. */
  3661. return 1;
  3662. }
  3663. }
  3664. memset(&cpkt, 0, sizeof(cpkt));
  3665. cpkt.chc_head.id =
  3666. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  3667. cpkt.chc_head.size = sizeof(cpkt);
  3668. cpkt.chc_op = EVT_OPEN_COUNT_DONE;
  3669. chn_iovec.iov_base = &cpkt;
  3670. chn_iovec.iov_len = cpkt.chc_head.size;
  3671. res = totempg_groups_mcast_joined(openais_group_handle,
  3672. &chn_iovec, 1,TOTEMPG_AGREED);
  3673. if (res != 0) {
  3674. /*
  3675. * Try again later.
  3676. */
  3677. return 1;
  3678. }
  3679. log_printf(RECOVERY_DEBUG, "DONE Sending open counts\n");
  3680. recovery_phase = evt_wait_open_count_done;
  3681. return 1;
  3682. }
  3683. /*
  3684. * Wait for all nodes to finish sending open updates before proceding.
  3685. * the EVT_OPEN_COUNT_DONE handler will set the state to
  3686. * evt_send_retained_events to get us out of this.
  3687. */
  3688. case evt_wait_open_count_done:
  3689. {
  3690. log_printf(RECOVERY_DEBUG, "Wait for open count done\n");
  3691. return 1;
  3692. }
  3693. /*
  3694. * If I'm the oldest node, send out retained events so that new nodes
  3695. * have all the information.
  3696. */
  3697. case evt_send_retained_events:
  3698. {
  3699. struct iovec chn_iovec;
  3700. struct event_data *evt;
  3701. int res;
  3702. log_printf(RECOVERY_DEBUG, "Send retained event updates\n");
  3703. /*
  3704. * Process messages. When we're done, send the done message
  3705. * to the nodes.
  3706. */
  3707. for (;next_retained != &retained_list;
  3708. next_retained = next_retained->next) {
  3709. log_printf(LOG_LEVEL_DEBUG, "Sending next retained event\n");
  3710. evt = list_entry(next_retained, struct event_data, ed_retained);
  3711. evt->ed_event.led_head.id =
  3712. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA);
  3713. chn_iovec.iov_base = &evt->ed_event;
  3714. chn_iovec.iov_len = evt->ed_event.led_head.size;
  3715. res = totempg_groups_mcast_joined(openais_group_handle,
  3716. &chn_iovec, 1, TOTEMPG_AGREED);
  3717. if (res != 0) {
  3718. /*
  3719. * Try again later.
  3720. */
  3721. return -1;
  3722. }
  3723. }
  3724. recovery_phase = evt_send_retained_events_done;
  3725. return 1;
  3726. }
  3727. case evt_send_retained_events_done:
  3728. {
  3729. struct req_evt_chan_command cpkt;
  3730. struct iovec chn_iovec;
  3731. int res;
  3732. log_printf(RECOVERY_DEBUG, "DONE Sending retained events\n");
  3733. memset(&cpkt, 0, sizeof(cpkt));
  3734. cpkt.chc_head.id =
  3735. SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
  3736. cpkt.chc_head.size = sizeof(cpkt);
  3737. cpkt.chc_op = EVT_CONF_DONE;
  3738. chn_iovec.iov_base = &cpkt;
  3739. chn_iovec.iov_len = cpkt.chc_head.size;
  3740. res = totempg_groups_mcast_joined(openais_group_handle,
  3741. &chn_iovec, 1, TOTEMPG_AGREED);
  3742. recovery_phase = evt_wait_send_retained_events;
  3743. return 1;
  3744. }
  3745. /*
  3746. * Wait for send of retained events to finish
  3747. * the EVT_CONF_DONE handler will set the state to
  3748. * evt_recovery_complete to get us out of this.
  3749. */
  3750. case evt_wait_send_retained_events:
  3751. {
  3752. log_printf(RECOVERY_DEBUG, "Wait for retained events\n");
  3753. return 1;
  3754. }
  3755. case evt_recovery_complete:
  3756. {
  3757. log_printf(RECOVERY_DEBUG, "Recovery complete\n");
  3758. return 0;
  3759. }
  3760. default:
  3761. log_printf(LOG_LEVEL_WARNING, "Bad recovery phase state: %u\n",
  3762. recovery_phase);
  3763. recovery_phase = evt_recovery_complete;
  3764. return 0;
  3765. }
  3766. return 0;
  3767. }
  3768. /*
  3769. * Not used at this time
  3770. */
  3771. static void evt_sync_activate(void)
  3772. {
  3773. log_printf(RECOVERY_DEBUG, "Evt synchronize activation\n");
  3774. }
  3775. /*
  3776. * Not used at this time
  3777. */
  3778. static void evt_sync_abort(void)
  3779. {
  3780. log_printf(RECOVERY_DEBUG, "Abort Evt synchronization\n");
  3781. }
  3782. /*
  3783. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3784. */