evt.c 113 KB

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