evt.c 113 KB

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