evt.c 114 KB

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