evt.c 114 KB

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