evt.c 114 KB

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