evt.c 113 KB

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