evt.c 113 KB

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