evt.c 114 KB

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