evt.c 111 KB

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