| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932 |
- /*
- * Copyright (c) 2004 Mark Haverkamp
- * Copyright (c) 2004 Open Source Development Lab
- *
- * All rights reserved.
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the Open Source Development Lab nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- #define DUMP_CHAN_INFO
- #define RECOVERY_DEBUG LOG_LEVEL_DEBUG
- #define CHAN_DEL_DEBUG LOG_LEVEL_DEBUG
- #define CHAN_OPEN_DEBUG LOG_LEVEL_DEBUG
- #define CHAN_UNLINK_DEBUG LOG_LEVEL_DEBUG
- #define REMOTE_OP_DEBUG LOG_LEVEL_DEBUG
- #include <sys/types.h>
- #include <malloc.h>
- #include <errno.h>
- #include <sys/time.h>
- #include <sys/uio.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include "../include/ipc_evt.h"
- #include "../include/list.h"
- #include "../include/queue.h"
- #include "util.h"
- #include "aispoll.h"
- #include "mempool.h"
- #include "parse.h"
- #include "main.h"
- #include "totempg.h"
- #include "hdb.h"
- #include "clm.h"
- #include "evt.h"
- #include "swab.h"
- #define LOG_SERVICE LOG_SERVICE_EVT
- #include "print.h"
- static int message_handler_req_lib_activatepoll (struct conn_info *conn_info,
- void *message);
- static int lib_evt_open_channel(struct conn_info *conn_info, void *message);
- static int lib_evt_open_channel_async(struct conn_info *conn_info,
- void *message);
- static int lib_evt_close_channel(struct conn_info *conn_info, void *message);
- static int lib_evt_unlink_channel(struct conn_info *conn_info, void *message);
- static int lib_evt_event_subscribe(struct conn_info *conn_info,
- void *message);
- static int lib_evt_event_unsubscribe(struct conn_info *conn_info,
- void *message);
- static int lib_evt_event_publish(struct conn_info *conn_info, void *message);
- static int lib_evt_event_clear_retentiontime(struct conn_info *conn_info,
- void *message);
- static int lib_evt_event_data_get(struct conn_info *conn_info,
- void *message);
- static int evt_conf_change(
- enum totem_configuration_type configuration_type,
- struct in_addr *member_list, void *member_list_private,
- int member_list_entries,
- struct in_addr *left_list, void *left_list_private,
- int left_list_entries,
- struct in_addr *joined_list, void *joined_list_private,
- int joined_list_entries,
- struct memb_ring_id *ring_id);
- static int evt_initialize(struct conn_info *conn_info, void *msg);
- static int evt_finalize(struct conn_info *conn_info);
- static int evt_exec_init(void);
- /*
- * Recovery sync functions
- */
- static void evt_sync_init(void);
- static int evt_sync_process(void);
- static void evt_sync_activate(void);
- static void evt_sync_abort(void);
- static struct libais_handler evt_libais_handlers[] = {
- {
- .libais_handler_fn = message_handler_req_lib_activatepoll,
- .response_size = sizeof(struct res_lib_activatepoll),
- .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_open_channel,
- .response_size = sizeof(struct res_evt_channel_open),
- .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_open_channel_async,
- .response_size = sizeof(struct res_evt_channel_open),
- .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_close_channel,
- .response_size = sizeof(struct res_evt_channel_close),
- .response_id = MESSAGE_RES_EVT_CLOSE_CHANNEL,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_unlink_channel,
- .response_size = sizeof(struct res_evt_channel_unlink),
- .response_id = MESSAGE_RES_EVT_UNLINK_CHANNEL,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_event_subscribe,
- .response_size = sizeof(struct res_evt_event_subscribe),
- .response_id = MESSAGE_RES_EVT_SUBSCRIBE,
- .flow_control = FLOW_CONTROL_NOT_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_event_unsubscribe,
- .response_size = sizeof(struct res_evt_event_unsubscribe),
- .response_id = MESSAGE_RES_EVT_UNSUBSCRIBE,
- .flow_control = FLOW_CONTROL_NOT_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_event_publish,
- .response_size = sizeof(struct res_evt_event_publish),
- .response_id = MESSAGE_RES_EVT_PUBLISH,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_event_clear_retentiontime,
- .response_size = sizeof(struct res_evt_event_clear_retentiontime),
- .response_id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME,
- .flow_control = FLOW_CONTROL_REQUIRED
- },
- {
- .libais_handler_fn = lib_evt_event_data_get,
- .response_size = sizeof(struct lib_event_data),
- .response_id = MESSAGE_RES_EVT_EVENT_DATA,
- .flow_control = FLOW_CONTROL_NOT_REQUIRED
- },
- };
-
- static int evt_remote_evt(void *msg, struct in_addr source_addr,
- int endian_conversion_required);
- static int evt_remote_recovery_evt(void *msg, struct in_addr source_addr,
- int endian_conversion_required);
- static int evt_remote_chan_op(void *msg, struct in_addr source_addr,
- int endian_conversion_required);
- static int (*evt_exec_handler_fns[]) (void *m, struct in_addr s,
- int endian_conversion_required) = {
- evt_remote_evt,
- evt_remote_chan_op,
- evt_remote_recovery_evt
- };
- struct service_handler evt_service_handler = {
- .libais_handlers = evt_libais_handlers,
- .libais_handlers_count = sizeof(evt_libais_handlers) /
- sizeof(struct libais_handler),
- .aisexec_handler_fns = evt_exec_handler_fns,
- .aisexec_handler_fns_count = sizeof(evt_exec_handler_fns) /
- sizeof(int (*)),
- .confchg_fn = evt_conf_change,
- .libais_init_fn = evt_initialize,
- .libais_exit_fn = evt_finalize,
- .exec_init_fn = evt_exec_init,
- .exec_dump_fn = 0,
- .sync_init = evt_sync_init,
- .sync_process = evt_sync_process,
- .sync_activate = evt_sync_activate,
- .sync_abort = evt_sync_abort
- };
- // TODO static totempg_recovery_plug_handle evt_recovery_plug_handle;
- /*
- * list of all retained events
- * struct event_data
- */
- static DECLARE_LIST_INIT(retained_list);
- /*
- * list of all event channel information
- * struct event_svr_channel_instance
- */
- static DECLARE_LIST_INIT(esc_head);
- /*
- * list of all unlinked event channel information
- * struct event_svr_channel_instance
- */
- static DECLARE_LIST_INIT(esc_unlinked_head);
- /*
- * list of all active event conn_info structs.
- * struct conn_info
- */
- static DECLARE_LIST_INIT(ci_head);
- /*
- * Track the state of event service recovery.
- *
- * evt_recovery_complete: Normal operational mode
- *
- * evt_send_event_id: Node is sending known last
- * event IDs.
- *
- * evt_send_open_count: Node is sending its open
- * Channel information.
- *
- * evt_wait_open_count_done: Node is done sending open channel data and
- * is waiting for the other nodes to finish.
- *
- * evt_send_retained_events: Node is sending retained event data.
- *
- * evt_wait_send_retained_events: Node is waiting for other nodes to
- * finish sending retained event data.
- */
- enum recovery_phases {
- evt_recovery_complete,
- evt_send_event_id,
- evt_send_open_count,
- evt_wait_open_count_done,
- evt_send_retained_events,
- evt_wait_send_retained_events
- };
- /*
- * Global varaibles used by the event service
- *
- * base_id_top: upper bits of next event ID to assign
- * base_id: Lower bits of Next event ID to assign
- * my_node_id: My cluster node id
- * total_member_count: how many members in this cluster
- * joined_member_count: How many joined this configuration.
- * left_member_count: How many left this configuration.
- * checked_in: keep track during config change.
- * recovery_node: True if we're the recovery node.
- * next_retained: pointer to next retained message to send
- * during recovery.
- * next_chan: pointer to next channel to send during recovery.
- * recovery_phase: Indicates what recovery is taking place.
- * left_member_list: Members that left this config
- * joined_member_list: Members that joined this config
- * current_member_list: Total membership this config
- * add_list: pointer to joined list used for sending event id
- * recovery data.
- * add_list_count: count of joined members used for sending event id
- * recovery data.
- *
- */
- #define BASE_ID_MASK 0xffffffffLL
- static SaEvtEventIdT base_id = 0;
- static SaEvtEventIdT base_id_top = 0;
- static SaClmNodeIdT my_node_id = 0;
- static int total_member_count = 0;
- static int joined_member_count = 0;
- static int left_member_count = 0;
- static int checked_in = 0;
- static int recovery_node = 0;
- static struct list_head *next_retained = 0;
- static struct list_head *next_chan = 0;
- static enum recovery_phases recovery_phase = evt_recovery_complete;
- static struct in_addr *left_member_list = 0;
- static struct in_addr *joined_member_list = 0;
- static struct in_addr *current_member_list = 0;
- static struct in_addr *add_list = 0;
- static int add_count = 0;
- /*
- * Structure to track pending channel open requests.
- * ocp_async: 1 for async open
- * ocp_invocation: invocation for async open
- * ocp_chan_name: requested channel
- * ocp_conn_info: conn_info for returning to the library.
- * ocp_open_flags: channel open flags
- * ocp_timer_handle: timer handle for sync open
- * ocp_entry: list entry for pending open list.
- */
- struct open_chan_pending {
- int ocp_async;
- SaInvocationT ocp_invocation;
- SaNameT ocp_chan_name;
- struct conn_info *ocp_conn_info;
- SaEvtChannelOpenFlagsT ocp_open_flag;
- poll_timer_handle ocp_timer_handle;
- uint32_t ocp_c_handle;
- struct list_head ocp_entry;
- };
- /*
- * list of pending channel opens
- */
- static DECLARE_LIST_INIT(open_pending);
- static void chan_open_timeout(void *data);
- /*
- * Structure to track pending channel unlink requests.
- * ucp_unlink_id: unlink ID of unlinked channel.
- * ucp_conn_info: conn_info for returning to the library.
- * ucp_entry: list entry for pending unlink list.
- */
- struct unlink_chan_pending {
- uint64_t ucp_unlink_id;
- struct conn_info *ucp_conn_info;
- struct list_head ucp_entry;
- };
- /*
- * list of pending unlink requests
- */
- static DECLARE_LIST_INIT(unlink_pending);
- /*
- * Next unlink ID
- */
- static uint64_t base_unlink_id = 0;
- inline uint64_t
- next_chan_unlink_id()
- {
- uint64_t uid = my_node_id;
- uid = (uid << 32ULL) | base_unlink_id;
- base_unlink_id = (base_unlink_id + 1ULL) & BASE_ID_MASK;
- return uid;
- }
- #define min(a,b) ((a) < (b) ? (a) : (b))
- /*
- * Throttle event delivery to applications to keep
- * the exec from using too much memory if the app is
- * slow to process its events.
- */
- #define MAX_EVT_DELIVERY_QUEUE 1000
- #define MIN_EVT_QUEUE_RESUME (MAX_EVT_DELIVERY_QUEUE / 2)
- #define LOST_PUB "EVENT_SERIVCE"
- #define LOST_CHAN "LOST EVENT"
- /*
- * Event to send when the delivery queue gets too full
- */
- char lost_evt[] = SA_EVT_LOST_EVENT;
- static int dropped_event_size;
- static struct event_data *dropped_event;
- struct evt_pattern {
- SaEvtEventPatternT pat;
- char str[sizeof(lost_evt)];
- };
- static struct evt_pattern dropped_pattern = {
- .pat = {&dropped_pattern.str[0],
- sizeof(lost_evt)},
- .str = {SA_EVT_LOST_EVENT}
- };
- SaNameT lost_chan = {
- .value = LOST_CHAN,
- .length = sizeof(LOST_CHAN)
- };
- SaNameT dropped_publisher = {
- .value = LOST_PUB,
- .length = sizeof(LOST_PUB)
- };
- struct event_svr_channel_open;
- struct event_svr_channel_subscr;
- struct open_count {
- SaClmNodeIdT oc_node_id;
- int32_t oc_open_count;
- };
- /*
- * Structure to contain global channel releated information
- *
- * esc_channel_name: The name of this channel.
- * esc_total_opens: The total number of opens on this channel including
- * other nodes.
- * esc_local_opens: The number of opens on this channel for this node.
- * esc_oc_size: The total number of entries in esc_node_opens;
- * esc_node_opens: list of node IDs and how many opens are associated.
- * esc_retained_count: How many retained events for this channel
- * esc_open_chans: list of opens of this channel.
- * (event_svr_channel_open.eco_entry)
- * esc_entry: links to other channels. (used by esc_head)
- * esc_unlink_id: If non-zero, then the channel has been marked
- * for unlink. This unlink ID is used to
- * mark events still associated with current openings
- * so they get delivered to the proper recipients.
- */
- struct event_svr_channel_instance {
- SaNameT esc_channel_name;
- int32_t esc_total_opens;
- int32_t esc_local_opens;
- uint32_t esc_oc_size;
- struct open_count *esc_node_opens;
- uint32_t esc_retained_count;
- struct list_head esc_open_chans;
- struct list_head esc_entry;
- uint64_t esc_unlink_id;
- };
- /*
- * Has the event data in the correct format to send to the library API
- * with aditional field for accounting.
- *
- * ed_ref_count: how many other strutures are referencing.
- * ed_retained: retained event list.
- * ed_timer_handle: Timer handle for retained event expiration.
- * ed_delivered: arrays of open channel pointers that this event
- * has been delivered to. (only used for events
- * with a retention time).
- * ed_delivered_count: Number of entries available in ed_delivered.
- * ed_delivered_next: Next free spot in ed_delivered
- * ed_my_chan: pointer to the global channel instance associated
- * with this event.
- * ed_event: The event data formatted to be ready to send.
- */
- struct event_data {
- uint32_t ed_ref_count;
- struct list_head ed_retained;
- poll_timer_handle ed_timer_handle;
- struct event_svr_channel_open **ed_delivered;
- uint32_t ed_delivered_count;
- uint32_t ed_delivered_next;
- struct event_svr_channel_instance *ed_my_chan;
- struct lib_event_data ed_event;
- };
- /*
- * Contains a list of pending events to be delivered to a subscribed
- * application.
- *
- * cel_chan_handle: associated library channel handle
- * cel_sub_id: associated library subscription ID
- * cel_event: event structure to deliver.
- * cel_entry: list of pending events
- * (struct event_server_instance.esi_events)
- */
- struct chan_event_list {
- uint32_t cel_chan_handle;
- uint32_t cel_sub_id;
- struct event_data* cel_event;
- struct list_head cel_entry;
- };
- /*
- * Contains information about each open for a given channel
- *
- * eco_flags: How the channel was opened.
- * eco_lib_handle: channel handle in the app. Used for event delivery.
- * eco_my_handle: the handle used to access this data structure.
- * eco_channel: Pointer to global channel info.
- * eco_entry: links to other opeinings of this channel.
- * eco_instance_entry: links to other channel opeinings for the
- * associated server instance.
- * eco_subscr: head of list of sbuscriptions for this channel open.
- * (event_svr_channel_subscr.ecs_entry)
- * eco_conn_info: refrence to EvtInitialize who owns this open.
- */
- struct event_svr_channel_open {
- uint8_t eco_flags;
- uint32_t eco_lib_handle;
- uint32_t eco_my_handle;
- struct event_svr_channel_instance *eco_channel;
- struct list_head eco_entry;
- struct list_head eco_instance_entry;
- struct list_head eco_subscr;
- struct conn_info *eco_conn_info;
- };
- /*
- * Contains information about each channel subscription
- *
- * ecs_open_chan: Link to our open channel.
- * ecs_sub_id: Subscription ID.
- * ecs_filter_count: number of filters in ecs_filters
- * ecs_filters: filters for determining event delivery.
- * ecs_entry: Links to other subscriptions to this channel opening.
- */
- struct event_svr_channel_subscr {
- struct event_svr_channel_open *ecs_open_chan;
- uint32_t ecs_sub_id;
- SaEvtEventFilterArrayT *ecs_filters;
- struct list_head ecs_entry;
- };
- /*
- * Member node data
- * mn_node_info: cluster node info from membership
- * mn_last_evt_id: last seen event ID for this node
- * mn_started: Indicates that event service has started
- * on this node.
- * mn_next: pointer to the next node in the hash chain.
- * mn_entry: List of all nodes.
- */
- struct member_node_data {
- struct in_addr mn_node_addr;
- SaClmClusterNodeT mn_node_info;
- SaEvtEventIdT mn_last_evt_id;
- SaClmNodeIdT mn_started;
- struct member_node_data *mn_next;
- struct list_head mn_entry;
- };
- DECLARE_LIST_INIT(mnd);
- /*
- * Take the filters we received from the application via the library and
- * make them into a real SaEvtEventFilterArrayT
- */
- static SaErrorT evtfilt_to_aisfilt(struct req_evt_event_subscribe *req,
- SaEvtEventFilterArrayT **evtfilters)
- {
- SaEvtEventFilterArrayT *filta =
- (SaEvtEventFilterArrayT *)req->ics_filter_data;
- SaEvtEventFilterArrayT *filters;
- SaEvtEventFilterT *filt = (void *)filta + sizeof(SaEvtEventFilterArrayT);
- SaUint8T *str = (void *)filta + sizeof(SaEvtEventFilterArrayT) +
- (sizeof(SaEvtEventFilterT) * filta->filtersNumber);
- int i;
- int j;
- filters = malloc(sizeof(SaEvtEventFilterArrayT));
- if (!filters) {
- return SA_AIS_ERR_NO_MEMORY;
- }
- filters->filtersNumber = filta->filtersNumber;
- filters->filters = malloc(sizeof(SaEvtEventFilterT) *
- filta->filtersNumber);
- if (!filters->filters) {
- free(filters);
- return SA_AIS_ERR_NO_MEMORY;
- }
- for (i = 0; i < filters->filtersNumber; i++) {
- filters->filters[i].filter.pattern =
- malloc(filt[i].filter.patternSize);
- if (!filters->filters[i].filter.pattern) {
- for (j = 0; j < i; j++) {
- free(filters->filters[j].filter.pattern);
- }
- free(filters->filters);
- free(filters);
- return SA_AIS_ERR_NO_MEMORY;
- }
- filters->filters[i].filter.patternSize =
- filt[i].filter.patternSize;
- memcpy(filters->filters[i].filter.pattern,
- str, filters->filters[i].filter.patternSize);
- filters->filters[i].filterType = filt[i].filterType;
- str += filters->filters[i].filter.patternSize;
- }
- *evtfilters = filters;
-
- return SA_AIS_OK;
- }
- /*
- * Free up filter data
- */
- static void free_filters(SaEvtEventFilterArrayT *fp)
- {
- int i;
- for (i = 0; i < fp->filtersNumber; i++) {
- free(fp->filters[i].filter.pattern);
- }
- free(fp->filters);
- free(fp);
- }
- /*
- * Look up a channel in the global channel list
- */
- static struct event_svr_channel_instance *
- find_channel(SaNameT *chan_name, uint64_t unlink_id)
- {
- struct list_head *l, *head;
- struct event_svr_channel_instance *eci;
- /*
- * choose which list to look through
- */
- if (unlink_id == EVT_CHAN_ACTIVE) {
- head = &esc_head;
- } else {
- head = &esc_unlinked_head;
- }
- for (l = head->next; l != head; l = l->next) {
- eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
- if (!name_match(chan_name, &eci->esc_channel_name)) {
- continue;
- } else if (unlink_id != eci->esc_unlink_id) {
- continue;
- }
- return eci;
- }
- return 0;
- }
- /*
- * Find the last unlinked version of a channel.
- */
- static struct event_svr_channel_instance *
- find_last_unlinked_channel(SaNameT *chan_name)
- {
- struct list_head *l;
- struct event_svr_channel_instance *eci;
- /*
- * unlinked channels are added to the head of the list
- * so the first one we see is the last one added.
- */
- for (l = esc_unlinked_head.next; l != &esc_unlinked_head; l = l->next) {
- eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
- if (!name_match(chan_name, &eci->esc_channel_name)) {
- continue;
- }
- }
- return 0;
- }
- /*
- * Create and initialize a channel instance structure
- */
- static struct event_svr_channel_instance *create_channel(SaNameT *cn)
- {
- struct event_svr_channel_instance *eci;
- eci = (struct event_svr_channel_instance *) malloc(sizeof(*eci));
- if (!eci) {
- return (eci);
- }
- memset(eci, 0, sizeof(*eci));
- list_init(&eci->esc_entry);
- list_init(&eci->esc_open_chans);
- eci->esc_oc_size = total_member_count;
- eci->esc_node_opens =
- malloc(sizeof(struct open_count) * total_member_count);
- if (!eci->esc_node_opens) {
- free(eci);
- return 0;
- }
- memset(eci->esc_node_opens, 0,
- sizeof(struct open_count) * total_member_count);
- eci->esc_channel_name = *cn;
- eci->esc_channel_name.value[eci->esc_channel_name.length] = '\0';
- list_add(&eci->esc_entry, &esc_head);
- return eci;
- }
- /*
- * Make sure that the list of nodes is large enough to hold the whole
- * membership
- */
- static int check_open_size(struct event_svr_channel_instance *eci)
- {
- if (total_member_count > eci->esc_oc_size) {
- eci->esc_node_opens = realloc(eci->esc_node_opens,
- sizeof(struct open_count) * total_member_count);
- if (!eci->esc_node_opens) {
- log_printf(LOG_LEVEL_WARNING,
- "Memory error realloc of node list\n");
- return -1;
- }
- memset(&eci->esc_node_opens[eci->esc_oc_size], 0,
- sizeof(struct open_count) *
- (total_member_count - eci->esc_oc_size));
- eci->esc_oc_size = total_member_count;
- }
- return 0;
- }
- /*
- * Find the specified node ID in the node list of the channel.
- * If it's not in the list, add it.
- */
- static struct open_count* find_open_count(
- struct event_svr_channel_instance *eci,
- SaClmNodeIdT node_id)
- {
- int i;
- for (i = 0; i < eci->esc_oc_size; i++) {
- if (eci->esc_node_opens[i].oc_node_id == 0) {
- eci->esc_node_opens[i].oc_node_id = node_id;
- eci->esc_node_opens[i].oc_open_count = 0;
- }
- if (eci->esc_node_opens[i].oc_node_id == node_id) {
- return &eci->esc_node_opens[i];
- }
- }
- log_printf(LOG_LEVEL_DEBUG,
- "find_open_count: node id 0x%x not found\n",
- node_id);
- return 0;
- }
- static void dump_chan_opens(struct event_svr_channel_instance *eci)
- {
- int i;
- log_printf(LOG_LEVEL_NOTICE,
- "Channel %s, total %d, local %d\n",
- eci->esc_channel_name.value,
- eci->esc_total_opens,
- eci->esc_local_opens);
- for (i = 0; i < eci->esc_oc_size; i++) {
- if (eci->esc_node_opens[i].oc_node_id == 0) {
- break;
- }
- log_printf(LOG_LEVEL_NOTICE, "Node 0x%x, count %d\n",
- eci->esc_node_opens[i].oc_node_id,
- eci->esc_node_opens[i].oc_open_count);
- }
- }
- #ifdef DUMP_CHAN_INFO
- /*
- * Scan the list of channels and dump the open count info.
- */
- static void dump_all_chans()
- {
- struct list_head *l;
- struct event_svr_channel_instance *eci;
- for (l = esc_head.next; l != &esc_head; l = l->next) {
- eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
- dump_chan_opens(eci);
- }
- }
- #endif
- /*
- * Replace the current open count for a node with the specified value.
- */
- static int set_open_count(struct event_svr_channel_instance *eci,
- SaClmNodeIdT node_id, uint32_t open_count)
- {
- struct open_count *oc;
- int i;
- if ((i = check_open_size(eci)) != 0) {
- return i;
- }
- oc = find_open_count(eci, node_id);
- if (oc) {
- if (oc->oc_open_count) {
- /*
- * If the open count wasn't zero, then we already
- * knew about this node. It should never be different than
- * what we already had for an open count.
- */
- if (oc->oc_open_count != open_count) {
- log_printf(LOG_LEVEL_ERROR,
- "Channel open count error\n");
- dump_chan_opens(eci);
- }
- return 0;
- }
- log_printf(LOG_LEVEL_DEBUG,
- "Set count: Chan %s for node 0x%x, was %d, now %d\n",
- eci->esc_channel_name.value,
- node_id, eci->esc_node_opens[i].oc_open_count, open_count);
- eci->esc_total_opens += open_count;
- oc->oc_open_count = open_count;
- return 0;
- }
- return -1;
- }
- /*
- * Increment the open count for the specified node.
- */
- static int inc_open_count(struct event_svr_channel_instance *eci,
- SaClmNodeIdT node_id)
- {
- struct open_count *oc;
- int i;
- if ((i = check_open_size(eci)) != 0) {
- return i;
- }
- if (node_id == my_node_id) {
- eci->esc_local_opens++;
- }
- oc = find_open_count(eci, node_id);
- if (oc) {
- eci->esc_total_opens++;
- oc->oc_open_count++;
- return 0;
- }
- return -1;
- }
- /*
- * Decrement the open count for the specified node in the
- * specified channel.
- */
- static int dec_open_count(struct event_svr_channel_instance *eci,
- SaClmNodeIdT node_id)
- {
- struct open_count *oc;
- int i;
- if ((i = check_open_size(eci)) != 0) {
- return i;
- }
- if (node_id == my_node_id) {
- eci->esc_local_opens--;
- }
- oc = find_open_count(eci, node_id);
- if (oc) {
- eci->esc_total_opens--;
- oc->oc_open_count--;
- if ((eci->esc_total_opens < 0) || (oc->oc_open_count < 0)) {
- log_printf(LOG_LEVEL_ERROR, "Channel open decrement error\n");
- dump_chan_opens(eci);
- }
- return 0;
- }
- return -1;
- }
- /*
- * Remove a channel and free its memory if it's not in use anymore.
- */
- static void delete_channel(struct event_svr_channel_instance *eci)
- {
- log_printf(CHAN_DEL_DEBUG,
- "Called Delete channel %s t %d, l %d, r %d\n",
- eci->esc_channel_name.value,
- eci->esc_total_opens, eci->esc_local_opens,
- eci->esc_retained_count);
- /*
- * If no one has the channel open anywhere and there are no unexpired
- * retained events for this channel, and it has been marked for deletion
- * by an unlink, then it is OK to delete the data structure.
- */
- if ((eci->esc_retained_count == 0) && (eci->esc_total_opens == 0) &&
- (eci->esc_unlink_id != EVT_CHAN_ACTIVE)) {
- log_printf(CHAN_DEL_DEBUG, "Delete channel %s\n",
- eci->esc_channel_name.value);
- log_printf(CHAN_UNLINK_DEBUG, "Delete channel %s, unlink_id %0llx\n",
- eci->esc_channel_name.value, eci->esc_unlink_id);
- if (!list_empty(&eci->esc_open_chans)) {
- log_printf(LOG_LEVEL_NOTICE,
- "Last channel close request for %s (still open)\n",
- eci->esc_channel_name.value);
- dump_chan_opens(eci);
- return;
- }
-
- /*
- * adjust if we're sending open counts on a config change.
- */
- if ((recovery_phase != evt_recovery_complete) &&
- (&eci->esc_entry == next_chan)) {
- next_chan = eci->esc_entry.next;
- }
- list_del(&eci->esc_entry);
- if (eci->esc_node_opens) {
- free(eci->esc_node_opens);
- }
- free(eci);
- }
- }
- /*
- * Mark a channel for deletion.
- */
- static void unlink_channel(struct event_svr_channel_instance *eci,
- uint64_t unlink_id)
- {
- struct event_data *edp;
- struct list_head *l;
- log_printf(CHAN_UNLINK_DEBUG, "Unlink request: %s, id 0x%llx\n",
- eci->esc_channel_name.value, unlink_id);
- /*
- * The unlink ID is used to note that the channel has been marked
- * for deletion and is a way to distinguish between multiple
- * channels of the same name each marked for deletion.
- */
- eci->esc_unlink_id = unlink_id;
- /*
- * Move the unlinked channel to the unlinked list. This way
- * we don't have to worry about filtering it out when we need to
- * distribute retained events at recovery time.
- */
- list_del(&eci->esc_entry);
- list_add(&eci->esc_entry, &esc_unlinked_head);
- /*
- * Scan the retained event list and tag any associated with this channel
- * with the unlink ID so that they get routed properly.
- */
- for (l = retained_list.next; l != &retained_list; l = l->next) {
- edp = list_entry(l, struct event_data, ed_retained);
- if ((edp->ed_my_chan == eci) &&
- (edp->ed_event.led_chan_unlink_id == EVT_CHAN_ACTIVE)) {
- edp->ed_event.led_chan_unlink_id = unlink_id;
- }
- }
- delete_channel(eci);
- }
- /*
- * Remove the specified node from the node list in this channel.
- */
- static int remove_open_count(
- struct event_svr_channel_instance *eci,
- SaClmNodeIdT node_id)
- {
- int i;
- int j;
- /*
- * Find the node, remove it and re-pack the array.
- */
- for (i = 0; i < eci->esc_oc_size; i++) {
- if (eci->esc_node_opens[i].oc_node_id == 0) {
- break;
- }
- log_printf(RECOVERY_DEBUG, "roc: %x/%x, t %d, oc %d\n",
- node_id, eci->esc_node_opens[i].oc_node_id,
- eci->esc_total_opens, eci->esc_node_opens[i].oc_open_count);
-
- if (eci->esc_node_opens[i].oc_node_id == node_id) {
- eci->esc_total_opens -= eci->esc_node_opens[i].oc_open_count;
- for (j = i+1; j < eci->esc_oc_size; j++, i++) {
- eci->esc_node_opens[i].oc_node_id =
- eci->esc_node_opens[j].oc_node_id;
- eci->esc_node_opens[i].oc_open_count =
- eci->esc_node_opens[j].oc_open_count;
- }
- eci->esc_node_opens[eci->esc_oc_size-1].oc_node_id = 0;
- eci->esc_node_opens[eci->esc_oc_size-1].oc_open_count = 0;
- /*
- * Remove the channel if it's not being used anymore
- */
- delete_channel(eci);
- return 0;
- }
- }
- return -1;
- }
- /*
- * Send a request to open a channel to the rest of the cluster.
- */
- static SaErrorT evt_open_channel(SaNameT *cn, SaUint8T flgs)
- {
- struct req_evt_chan_command cpkt;
- struct event_svr_channel_instance *eci;
- struct iovec chn_iovec;
- int res;
- SaErrorT ret;
- ret = SA_AIS_OK;
- eci = find_channel(cn, EVT_CHAN_ACTIVE);
- /*
- * If the create flag set, and it doesn't exist, we can make the channel.
- * Otherwise, it's an error since we're notified of channels being created
- * and opened.
- */
- if (!eci && !(flgs & SA_EVT_CHANNEL_CREATE)) {
- ret = SA_AIS_ERR_NOT_EXIST;
- goto chan_open_end;
- }
- /*
- * create the channel packet to send. Tell the the cluster
- * to create the channel.
- */
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_OPEN_CHAN_OP;
- cpkt.u.chc_chan = *cn;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Send open mcast\n");
- res = totempg_mcast (&chn_iovec, 1, TOTEMPG_AGREED);
- log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Open mcast result: %d\n",
- res);
- if (res != 0) {
- ret = SA_AIS_ERR_LIBRARY;
- }
- chan_open_end:
- return ret;
- }
- /*
- * Send a request to close a channel with the rest of the cluster.
- */
- static SaErrorT evt_close_channel(SaNameT *cn, uint64_t unlink_id)
- {
- struct req_evt_chan_command cpkt;
- struct iovec chn_iovec;
- int res;
- SaErrorT ret;
- ret = SA_AIS_OK;
- /*
- * create the channel packet to send. Tell the the cluster
- * to close the channel.
- */
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_CLOSE_CHAN_OP;
- cpkt.u.chcu.chcu_name = *cn;
- cpkt.u.chcu.chcu_unlink_id = unlink_id;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- res = totempg_mcast (&chn_iovec, 1, TOTEMPG_AGREED);
- if (res != 0) {
- ret = SA_AIS_ERR_LIBRARY;
- }
- return ret;
- }
- /*
- * Node data access functions. Used to keep track of event IDs
- * delivery of messages.
- *
- * add_node: Add a new member node to our list.
- * remove_node: Remove a node that left membership.
- * find_node: Given the node ID return a pointer to node information.
- *
- */
- #define NODE_HASH_SIZE 256
- static struct member_node_data *nl[NODE_HASH_SIZE] = {0};
- inline int
- hash_sock_addr(struct in_addr addr)
- {
- return addr.s_addr & (NODE_HASH_SIZE - 1);
- }
- static struct member_node_data **lookup_node(struct in_addr addr)
- {
- int index = hash_sock_addr(addr);
- struct member_node_data **nlp;
- nlp = &nl[index];
- for (nlp = &nl[index]; *nlp; nlp = &((*nlp)->mn_next)) {
- if ((*nlp)->mn_node_addr.s_addr == addr.s_addr) {
- break;
- }
- }
- return nlp;
- }
- static struct member_node_data *
- evt_find_node(struct in_addr addr)
- {
- struct member_node_data **nlp;
- nlp = lookup_node(addr);
- if (!nlp) {
- log_printf(LOG_LEVEL_DEBUG, "find_node: Got NULL nlp?\n");
- return 0;
- }
- return *nlp;
- }
- static SaErrorT
- evt_add_node(struct in_addr addr, SaClmClusterNodeT *cn)
- {
- struct member_node_data **nlp;
- struct member_node_data *nl;
- SaErrorT err = SA_AIS_ERR_EXIST;
- nlp = lookup_node(addr);
- if (!nlp) {
- log_printf(LOG_LEVEL_DEBUG, "add_node: Got NULL nlp?\n");
- goto an_out;
- }
- if (*nlp) {
- goto an_out;
- }
- *nlp = malloc(sizeof(struct member_node_data));
- if (!nlp) {
- return SA_AIS_ERR_NO_MEMORY;
- }
- nl = *nlp;
- if (nl) {
- memset(nl, 0, sizeof(*nl));
- err = SA_AIS_OK;
- nl->mn_node_addr = addr;
- nl->mn_started = 1;
- }
- list_init(&nl->mn_entry);
- list_add(&nl->mn_entry, &mnd);
- nl->mn_node_info = *cn;
- an_out:
- return err;
- }
- #ifdef REMOVE_NODE
- static SaErrorT
- evt_remove_node(struct in_addr addr)
- {
- struct member_node_data **nlp;
- struct member_node_data *nl;
- SaErrorT err = SA_AIS_ERR_NOT_EXIST;
- nlp = lookup_node(addr);
- if (!nlp) {
- log_printf(LOG_LEVEL_DEBUG, "remove_node: Got NULL nlp?\n");
- goto an_out;
- }
- if (!(*nlp)) {
- goto an_out;
- }
- nl = *nlp;
- list_del(&nl->mn_entry);
- *nlp = nl->mn_next;
- free(*nlp);
- err = SA_AIS_OK;
- an_out:
- return err;
- }
- #endif /* REMOVE_NODE */
- /*
- * Find the oldest node in the membership. This is the one we choose to
- * perform some cluster-wide functions like distributing retained events.
- */
- static struct member_node_data* oldest_node()
- {
- struct list_head *l;
- struct member_node_data *mn = 0;
- struct member_node_data *oldest = 0;
- for (l = mnd.next; l != &mnd; l = l->next) {
- mn = list_entry(l, struct member_node_data, mn_entry);
- if (mn->mn_started == 0) {
- continue;
- }
- if ((oldest == NULL) ||
- (mn->mn_node_info.bootTimestamp <
- oldest->mn_node_info.bootTimestamp )) {
- oldest = mn;
- } else if (mn->mn_node_info.bootTimestamp ==
- oldest->mn_node_info.bootTimestamp) {
- if (mn->mn_node_info.nodeId < oldest->mn_node_info.nodeId) {
- oldest = mn;
- }
- }
- }
- return oldest;
- }
- /*
- * keep track of the last event ID from a node.
- * If we get an event ID less than our last, we've already
- * seen it. It's probably a retained event being sent to
- * a new node.
- */
- static int check_last_event(struct lib_event_data *evtpkt,
- struct in_addr addr)
- {
- struct member_node_data *nd;
- SaClmClusterNodeT *cn;
- nd = evt_find_node(addr);
- if (!nd) {
- log_printf(LOG_LEVEL_DEBUG,
- "Node ID 0x%x not found for event %llx\n",
- evtpkt->led_publisher_node_id, evtpkt->led_event_id);
- cn = clm_get_by_nodeid(addr);
- if (!cn) {
- log_printf(LOG_LEVEL_DEBUG,
- "Cluster Node 0x%x not found for event %llx\n",
- evtpkt->led_publisher_node_id, evtpkt->led_event_id);
- } else {
- evt_add_node(addr, cn);
- nd = evt_find_node(addr);
- }
- }
- if (!nd) {
- return 0;
- }
- if ((nd->mn_last_evt_id < evtpkt->led_event_id)) {
- nd->mn_last_evt_id = evtpkt->led_event_id;
- return 0;
- }
- return 1;
- }
- /*
- * Send a message to the app to wake it up if it is polling
- */
- static int message_handler_req_lib_activatepoll(struct conn_info *conn_info,
- void *message)
- {
- struct res_lib_activatepoll res;
- res.header.error = SA_AIS_OK;
- res.header.size = sizeof (struct res_lib_activatepoll);
- res.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
- libais_send_response(conn_info, &res, sizeof(res));
- return (0);
- }
- /*
- * event id generating code. We use the node ID for this node for the
- * upper 32 bits of the event ID to make sure that we can generate a cluster
- * wide unique event ID for a given event.
- */
- SaErrorT set_event_id(SaClmNodeIdT node_id)
- {
- SaErrorT err = SA_AIS_OK;
- if (base_id_top) {
- err = SA_AIS_ERR_EXIST;
- }
- base_id_top = (SaEvtEventIdT)node_id << 32;
- return err;
- }
- static SaErrorT get_event_id(uint64_t *event_id)
- {
- *event_id = base_id_top | base_id ;
- base_id = (base_id + 1) & BASE_ID_MASK;
- return SA_AIS_OK;
- }
- /*
- * Free up an event structure if it isn't being used anymore.
- */
- static void
- free_event_data(struct event_data *edp)
- {
- if (--edp->ed_ref_count) {
- return;
- }
- log_printf(LOG_LEVEL_DEBUG, "Freeing event ID: 0x%llx\n",
- edp->ed_event.led_event_id);
- if (edp->ed_delivered) {
- free(edp->ed_delivered);
- }
- free(edp);
- }
- /*
- * Timer handler to delete expired events.
- *
- */
- static void
- event_retention_timeout(void *data)
- {
- struct event_data *edp = data;
- log_printf(LOG_LEVEL_DEBUG, "Event ID %llx expired\n",
- edp->ed_event.led_event_id);
- /*
- * adjust next_retained if we're in recovery and
- * were in charge of sending retained events.
- */
- if (recovery_phase != evt_recovery_complete && recovery_node) {
- if (next_retained == &edp->ed_retained) {
- next_retained = edp->ed_retained.next;
- }
- }
- list_del(&edp->ed_retained);
- list_init(&edp->ed_retained);
- /*
- * Check to see if the channel isn't in use anymore.
- */
- edp->ed_my_chan->esc_retained_count--;
- if (edp->ed_my_chan->esc_retained_count == 0) {
- delete_channel(edp->ed_my_chan);
- }
- free_event_data(edp);
- }
- /*
- * clear a particular event's retention time.
- * This will free the event as long as it isn't being
- * currently used.
- *
- */
- static void
- clear_retention_time(SaEvtEventIdT event_id)
- {
- struct event_data *edp;
- struct list_head *l, *nxt;
- int ret;
- log_printf(LOG_LEVEL_DEBUG, "Search for Event ID %llx\n", event_id);
- for (l = retained_list.next; l != &retained_list; l = nxt) {
- nxt = l->next;
- edp = list_entry(l, struct event_data, ed_retained);
- if (edp->ed_event.led_event_id != event_id) {
- continue;
- }
- log_printf(LOG_LEVEL_DEBUG,
- "Clear retention time for Event ID %llx\n",
- edp->ed_event.led_event_id);
- ret = poll_timer_delete(aisexec_poll_handle, edp->ed_timer_handle);
- if (ret != 0 ) {
- log_printf(LOG_LEVEL_ERROR, "Error expiring event ID %llx\n",
- edp->ed_event.led_event_id);
- return;
- }
- edp->ed_event.led_retention_time = 0;
- list_del(&edp->ed_retained);
- list_init(&edp->ed_retained);
- /*
- * Check to see if the channel isn't in use anymore.
- */
- edp->ed_my_chan->esc_retained_count--;
- if (edp->ed_my_chan->esc_retained_count == 0) {
- delete_channel(edp->ed_my_chan);
- }
- free_event_data(edp);
- break;
- }
- }
- /*
- * Remove specified channel from event delivery list
- */
- static void
- remove_delivered_channel(struct event_svr_channel_open *eco)
- {
- int i;
- struct list_head *l;
- struct event_data *edp;
- for (l = retained_list.next; l != &retained_list; l = l->next) {
- edp = list_entry(l, struct event_data, ed_retained);
- for (i = 0; i < edp->ed_delivered_next; i++) {
- if (edp->ed_delivered[i] == eco) {
- edp->ed_delivered_next--;
- if (edp->ed_delivered_next == i) {
- break;
- }
- memmove(&edp->ed_delivered[i],
- &edp->ed_delivered[i+1],
- &edp->ed_delivered[edp->ed_delivered_next] -
- &edp->ed_delivered[i]);
- break;
- }
- }
- }
- return;
- }
- /*
- * If there is a retention time, add this open channel to the event so
- * we can check if we've already delivered this message later if a new
- * subscription matches.
- */
- #define DELIVER_SIZE 8
- static void
- evt_delivered(struct event_data *evt, struct event_svr_channel_open *eco)
- {
- if (!evt->ed_event.led_retention_time) {
- return;
- }
- log_printf(LOG_LEVEL_DEBUG, "delivered ID %llx to eco %p\n",
- evt->ed_event.led_event_id, eco);
- if (evt->ed_delivered_count == evt->ed_delivered_next) {
- evt->ed_delivered = realloc(evt->ed_delivered,
- DELIVER_SIZE * sizeof(struct event_svr_channel_open *));
- memset(evt->ed_delivered + evt->ed_delivered_next, 0,
- DELIVER_SIZE * sizeof(struct event_svr_channel_open *));
- evt->ed_delivered_next = evt->ed_delivered_count;
- evt->ed_delivered_count += DELIVER_SIZE;
- }
- evt->ed_delivered[evt->ed_delivered_next++] = eco;
- }
- /*
- * Check to see if an event has already been delivered to this open channel
- */
- static int
- evt_already_delivered(struct event_data *evt,
- struct event_svr_channel_open *eco)
- {
- int i;
- if (!evt->ed_event.led_retention_time) {
- return 0;
- }
- log_printf(LOG_LEVEL_DEBUG, "Deliver count: %d deliver_next %d\n",
- evt->ed_delivered_count, evt->ed_delivered_next);
- for (i = 0; i < evt->ed_delivered_next; i++) {
- log_printf(LOG_LEVEL_DEBUG, "Checking ID %llx delivered %p eco %p\n",
- evt->ed_event.led_event_id, evt->ed_delivered[i], eco);
- if (evt->ed_delivered[i] == eco) {
- return 1;
- }
- }
- return 0;
- }
- /*
- * Compare a filter to a given pattern.
- * return SA_AIS_OK if the pattern matches a filter
- */
- static SaErrorT
- filter_match(SaEvtEventPatternT *ep, SaEvtEventFilterT *ef)
- {
- int ret;
- ret = SA_AIS_ERR_FAILED_OPERATION;
- switch (ef->filterType) {
- case SA_EVT_PREFIX_FILTER:
- if (ef->filter.patternSize > ep->patternSize) {
- break;
- }
- if (strncmp(ef->filter.pattern, ep->pattern,
- ef->filter.patternSize) == 0) {
- ret = SA_AIS_OK;
- }
- break;
- case SA_EVT_SUFFIX_FILTER:
- if (ef->filter.patternSize > ep->patternSize) {
- break;
- }
- if (strncmp(ef->filter.pattern,
- &ep->pattern[ep->patternSize - ef->filter.patternSize],
- ef->filter.patternSize) == 0) {
- ret = SA_AIS_OK;
- }
-
- break;
- case SA_EVT_EXACT_FILTER:
- if (ef->filter.patternSize != ep->patternSize) {
- break;
- }
- if (strncmp(ef->filter.pattern, ep->pattern,
- ef->filter.patternSize) == 0) {
- ret = SA_AIS_OK;
- }
- break;
- case SA_EVT_PASS_ALL_FILTER:
- ret = SA_AIS_OK;
- break;
- default:
- break;
- }
- return ret;
- }
- /*
- * compare the event's patterns with the subscription's filter rules.
- * SA_AIS_OK is returned if the event matches the filter rules.
- */
- static SaErrorT
- event_match(struct event_data *evt,
- struct event_svr_channel_subscr *ecs)
- {
- SaEvtEventFilterT *ef;
- SaEvtEventPatternT *ep;
- uint32_t filt_count;
- SaErrorT ret = SA_AIS_OK;
- int i;
- ep = (SaEvtEventPatternT *)(&evt->ed_event.led_body[0]);
- ef = ecs->ecs_filters->filters;
- filt_count = min(ecs->ecs_filters->filtersNumber,
- evt->ed_event.led_patterns_number);
- for (i = 0; i < filt_count; i++) {
- ret = filter_match(ep, ef);
- if (ret != SA_AIS_OK) {
- break;
- }
- ep++;
- ef++;
- }
- return ret;
- }
- /*
- * Scan undelivered pending events and either remove them if no subscription
- * filters match anymore or re-assign them to another matching subscription
- */
- static void
- filter_undelivered_events(struct event_svr_channel_open *op_chan)
- {
- struct event_svr_channel_open *eco;
- struct event_svr_channel_instance *eci;
- struct event_svr_channel_subscr *ecs;
- struct chan_event_list *cel;
- struct libevt_ci *esip = &op_chan->eco_conn_info->ais_ci.u.libevt_ci;
- struct list_head *l, *nxt;
- struct list_head *l1, *l2;
- int i;
- eci = op_chan->eco_channel;
- /*
- * Scan each of the priority queues for messages
- */
- for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
- /*
- * examine each message queued for delivery
- */
- for (l = esip->esi_events[i].next; l != &esip->esi_events[i]; l = nxt) {
- nxt = l->next;
- cel = list_entry(l, struct chan_event_list, cel_entry);
- /*
- * Check open channels
- */
- for (l1 = eci->esc_open_chans.next;
- l1 != &eci->esc_open_chans; l1 = l1->next) {
- eco = list_entry(l1, struct event_svr_channel_open, eco_entry);
- /*
- * See if this channel open instance belongs
- * to this evtinitialize instance
- */
- if (eco->eco_conn_info != op_chan->eco_conn_info) {
- continue;
- }
- /*
- * See if enabled to receive
- */
- if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
- continue;
- }
- /*
- * Check subscriptions
- */
- for (l2 = eco->eco_subscr.next;
- l2 != &eco->eco_subscr; l2 = l2->next) {
- ecs = list_entry(l2,
- struct event_svr_channel_subscr, ecs_entry);
- if (event_match(cel->cel_event, ecs) == SA_AIS_OK) {
- /*
- * Something still matches.
- * We'll assign it to
- * the new subscription.
- */
- cel->cel_sub_id = ecs->ecs_sub_id;
- cel->cel_chan_handle = eco->eco_lib_handle;
- goto next_event;
- }
- }
- }
- /*
- * No subscription filter matches anymore. We
- * can delete this event.
- */
- list_del(&cel->cel_entry);
- list_init(&cel->cel_entry);
- esip->esi_nevents--;
-
- free_event_data(cel->cel_event);
- free(cel);
- next_event:
- continue;
- }
- }
- }
- /*
- * Notify the library of a pending event
- */
- static void __notify_event(struct conn_info *conn_info)
- {
- struct res_evt_event_data res;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- log_printf(LOG_LEVEL_DEBUG, "DELIVER: notify\n");
- if (esip->esi_nevents != 0) {
- res.evd_head.size = sizeof(res);
- res.evd_head.id = MESSAGE_RES_EVT_AVAILABLE;
- res.evd_head.error = SA_AIS_OK;
- libais_send_response(conn_info, &res, sizeof(res));
- }
- }
- inline void notify_event(struct conn_info *conn_info)
- {
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- /*
- * Give the library a kick if there aren't already
- * events queued for delivery.
- */
- if (esip->esi_nevents++ == 0) {
- __notify_event(conn_info);
- }
- }
- /*
- * sends/queues up an event for a subscribed channel.
- */
- static void
- deliver_event(struct event_data *evt,
- struct event_svr_channel_open *eco,
- struct event_svr_channel_subscr *ecs)
- {
- struct chan_event_list *ep;
- struct libevt_ci *esip = &eco->eco_conn_info->ais_ci.u.libevt_ci;
- SaEvtEventPriorityT evt_prio = evt->ed_event.led_priority;
- struct chan_event_list *cel;
- int do_deliver_event = 0;
- int do_deliver_warning = 0;
- int i;
- if (evt_prio > SA_EVT_LOWEST_PRIORITY) {
- evt_prio = SA_EVT_LOWEST_PRIORITY;
- }
- /*
- * Delivery queue check.
- * - If the queue is blocked, see if we've sent enough messages to
- * unblock it.
- * - If it isn't blocked, see if this message will put us over the top.
- * - If we can't deliver this message, see if we can toss some lower
- * priority message to make room for this one.
- * - If we toss any messages, queue up an event of SA_EVT_LOST_EVENT_PATTERN
- * to let the application know that we dropped some messages.
- */
- if (esip->esi_queue_blocked) {
- if (esip->esi_nevents < MIN_EVT_QUEUE_RESUME) {
- esip->esi_queue_blocked = 0;
- log_printf(LOG_LEVEL_DEBUG, "unblock\n");
- }
- }
- if (!esip->esi_queue_blocked &&
- (esip->esi_nevents >= MAX_EVT_DELIVERY_QUEUE)) {
- log_printf(LOG_LEVEL_DEBUG, "block\n");
- esip->esi_queue_blocked = 1;
- do_deliver_warning = 1;
- }
- if (esip->esi_queue_blocked) {
- do_deliver_event = 0;
- for (i = SA_EVT_LOWEST_PRIORITY; i > evt_prio; i--) {
- if (!list_empty(&esip->esi_events[i])) {
- /*
- * Get the last item on the list, so we drop the most
- * recent lowest priority event.
- */
- cel = list_entry(esip->esi_events[i].prev,
- struct chan_event_list, cel_entry);
- log_printf(LOG_LEVEL_DEBUG, "Drop 0x%0llx\n",
- cel->cel_event->ed_event.led_event_id);
- list_del(&cel->cel_entry);
- free_event_data(cel->cel_event);
- free(cel);
- esip->esi_nevents--;
- do_deliver_event = 1;
- break;
- }
- }
- } else {
- do_deliver_event = 1;
- }
- /*
- * Queue the event for delivery
- */
- if (do_deliver_event) {
- ep = malloc(sizeof(*ep));
- if (!ep) {
- log_printf(LOG_LEVEL_WARNING,
- "3Memory allocation error, can't deliver event\n");
- return;
- }
- evt->ed_ref_count++;
- ep->cel_chan_handle = eco->eco_lib_handle;
- ep->cel_sub_id = ecs->ecs_sub_id;
- list_init(&ep->cel_entry);
- ep->cel_event = evt;
- list_add_tail(&ep->cel_entry, &esip->esi_events[evt_prio]);
- evt_delivered(evt, eco);
- notify_event(eco->eco_conn_info);
- }
- /*
- * If we dropped an event, queue this so that the application knows
- * what has happened.
- */
- if (do_deliver_warning) {
- struct event_data *ed;
- ed = malloc(dropped_event_size);
- if (!ed) {
- log_printf(LOG_LEVEL_WARNING,
- "4Memory allocation error, can't deliver event\n");
- return;
- }
- log_printf(LOG_LEVEL_DEBUG, "Warn 0x%0llx\n",
- evt->ed_event.led_event_id);
- memcpy(ed, dropped_event, dropped_event_size);
- ed->ed_event.led_publish_time = clust_time_now();
- ed->ed_event.led_event_id = SA_EVT_EVENTID_LOST;
- list_init(&ed->ed_retained);
- ep = malloc(sizeof(*ep));
- if (!ep) {
- log_printf(LOG_LEVEL_WARNING,
- "5Memory allocation error, can't deliver event\n");
- return;
- }
- ep->cel_chan_handle = eco->eco_lib_handle;
- ep->cel_sub_id = ecs->ecs_sub_id;
- list_init(&ep->cel_entry);
- ep->cel_event = ed;
- list_add_tail(&ep->cel_entry, &esip->esi_events[SA_EVT_HIGHEST_PRIORITY]);
- notify_event(eco->eco_conn_info);
- }
- }
- /*
- * Take the event data and swap the elements so they match our architectures
- * word order.
- */
- static void
- convert_event(struct lib_event_data *evt)
- {
- SaEvtEventPatternT *eps;
- int i;
- /*
- * The following elements don't require processing:
- *
- * converted in the main deliver_fn:
- * led_head.id, led_head.size.
- *
- * Supplied localy:
- * source_addr, publisher_node_id, receive_time.
- *
- * Used internaly only:
- * led_svr_channel_handle and led_lib_channel_handle.
- */
- evt->led_chan_name.length = swab16(evt->led_chan_name.length);
- evt->led_chan_unlink_id = swab64(evt->led_chan_unlink_id);
- evt->led_event_id = swab64(evt->led_event_id);
- evt->led_sub_id = swab32(evt->led_sub_id);
- evt->led_publisher_name.length = swab32(evt->led_publisher_name.length);
- evt->led_retention_time = swab64(evt->led_retention_time);
- evt->led_publish_time = swab64(evt->led_publish_time);
- evt->led_user_data_offset = swab32(evt->led_user_data_offset);
- evt->led_user_data_size = swab32(evt->led_user_data_size);
- evt->led_patterns_number = swab32(evt->led_patterns_number);
- /*
- * Now we need to go through the led_body and swizzle pattern counts.
- * We can't do anything about user data since it doesn't have a specified
- * format. The application is on its own here.
- */
- eps = (SaEvtEventPatternT *)evt->led_body;
- for (i = 0; i < evt->led_patterns_number; i++) {
- eps->patternSize = swab32(eps->patternSize);
- eps++;
- }
-
- }
- /*
- * Take an event received from the network and fix it up to be usable.
- * - fix up pointers for pattern list.
- * - fill in some channel info
- */
- static struct event_data *
- make_local_event(struct lib_event_data *p,
- struct event_svr_channel_instance *eci)
- {
- struct event_data *ed;
- SaEvtEventPatternT *eps;
- SaUint8T *str;
- uint32_t ed_size;
- int i;
- ed_size = sizeof(*ed) + p->led_user_data_offset + p->led_user_data_size;
- ed = malloc(ed_size);
- if (!ed) {
- log_printf(LOG_LEVEL_WARNING,
- "Failed to allocate %u bytes for event, offset %u, data size %u\n",
- ed_size, p->led_user_data_offset, p->led_user_data_size);
- return 0;
- }
- memset(ed, 0, ed_size);
- list_init(&ed->ed_retained);
- ed->ed_my_chan = eci;
- /*
- * Fill in lib_event_data and make the pattern pointers valid
- */
- memcpy(&ed->ed_event, p, sizeof(*p) +
- p->led_user_data_offset + p->led_user_data_size);
- eps = (SaEvtEventPatternT *)ed->ed_event.led_body;
- str = ed->ed_event.led_body +
- (ed->ed_event.led_patterns_number * sizeof(SaEvtEventPatternT));
- for (i = 0; i < ed->ed_event.led_patterns_number; i++) {
- eps->pattern = str;
- str += eps->patternSize;
- eps++;
- }
- ed->ed_ref_count++;
- return ed;
- }
- /*
- * Set an event to be retained.
- */
- static void retain_event(struct event_data *evt)
- {
- uint32_t ret;
- int msec_in_future;
- evt->ed_ref_count++;
- evt->ed_my_chan->esc_retained_count++;
- list_add_tail(&evt->ed_retained, &retained_list);
- /*
- * Time in nanoseconds - convert to miliseconds
- */
- msec_in_future = (uint32_t)((evt->ed_event.led_retention_time) / 1000000ULL);
- ret = poll_timer_add(aisexec_poll_handle,
- msec_in_future,
- evt,
- event_retention_timeout,
- &evt->ed_timer_handle);
- if (ret != 0) {
- log_printf(LOG_LEVEL_ERROR,
- "retention of event id 0x%llx failed\n",
- evt->ed_event.led_event_id);
- } else {
- log_printf(LOG_LEVEL_DEBUG, "Retain event ID 0x%llx\n",
- evt->ed_event.led_event_id);
- }
- }
- /*
- * Scan the subscription list and look for the specified subsctiption ID.
- * Only look for the ID in subscriptions that are associated with the
- * saEvtInitialize associated with the specified open channel.
- */
- static struct event_svr_channel_subscr *find_subscr(
- struct event_svr_channel_open *open_chan, SaEvtSubscriptionIdT sub_id)
- {
- struct event_svr_channel_instance *eci;
- struct event_svr_channel_subscr *ecs;
- struct event_svr_channel_open *eco;
- struct list_head *l, *l1;
- struct conn_info* conn_info = open_chan->eco_conn_info;
- eci = open_chan->eco_channel;
- /*
- * Check for subscription id already in use.
- * Subscriptions are unique within saEvtInitialize (Callback scope).
- */
- for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) {
- eco = list_entry(l, struct event_svr_channel_open, eco_entry);
- /*
- * Don't bother with open channels associated with another
- * EvtInitialize
- */
- if (eco->eco_conn_info != conn_info) {
- continue;
- }
- for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) {
- ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry);
- if (ecs->ecs_sub_id == sub_id) {
- return ecs;
- }
- }
- }
- return 0;
- }
- /*
- * Handler for saEvtInitialize
- */
- static int evt_initialize(struct conn_info *conn_info, void *msg)
- {
- struct res_lib_init res;
- struct libevt_ci *libevt_ci = &conn_info->ais_ci.u.libevt_ci;
- int i;
-
- res.header.size = sizeof (struct res_lib_init);
- res.header.id = MESSAGE_RES_INIT;
- res.header.error = SA_AIS_OK;
- log_printf(LOG_LEVEL_DEBUG, "saEvtInitialize request.\n");
- if (!conn_info->authenticated) {
- log_printf(LOG_LEVEL_ERROR, "event service: Not authenticated\n");
- res.header.error = SA_AIS_ERR_LIBRARY;
- libais_send_response(conn_info, &res, sizeof(res));
- return -1;
- }
- memset(libevt_ci, 0, sizeof(*libevt_ci));
- list_init(&libevt_ci->esi_open_chans);
- for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
- list_init(&libevt_ci->esi_events[i]);
- }
- conn_info->service = SOCKET_SERVICE_EVT;
- list_init (&conn_info->conn_list);
- list_add_tail(&conn_info->conn_list, &ci_head);
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Handler for saEvtChannelOpen
- */
- static int lib_evt_open_channel(struct conn_info *conn_info, void *message)
- {
- SaErrorT error;
- struct req_evt_channel_open *req;
- struct res_evt_channel_open res;
- struct open_chan_pending *ocp;
- int msec_in_future;
- int ret;
- req = message;
- log_printf(CHAN_OPEN_DEBUG,
- "saEvtChannelOpen (Open channel request)\n");
- log_printf(CHAN_OPEN_DEBUG,
- "handle 0x%x, to 0x%llx\n",
- req->ico_c_handle,
- req->ico_timeout);
- log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n",
- req->ico_open_flag,
- req->ico_channel_name.length,
- req->ico_channel_name.value);
- /*
- * Open the channel.
- *
- */
- error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag);
- if (error != SA_AIS_OK) {
- goto open_return;
- }
- ocp = malloc(sizeof(struct open_chan_pending));
- if (!ocp) {
- error = SA_AIS_ERR_NO_MEMORY;
- goto open_return;
- }
- ocp->ocp_async = 0;
- ocp->ocp_invocation = 0;
- ocp->ocp_chan_name = req->ico_channel_name;
- ocp->ocp_open_flag = req->ico_open_flag;
- ocp->ocp_conn_info = conn_info;
- ocp->ocp_c_handle = req->ico_c_handle;
- ocp->ocp_timer_handle = 0;
- list_init(&ocp->ocp_entry);
- list_add_tail(&ocp->ocp_entry, &open_pending);
- if (req->ico_timeout != 0) {
- /*
- * Time in nanoseconds - convert to miliseconds
- */
- msec_in_future = (uint32_t)(req->ico_timeout / 1000000ULL);
- ret = poll_timer_add(aisexec_poll_handle,
- msec_in_future,
- ocp,
- chan_open_timeout,
- &ocp->ocp_timer_handle);
- if (ret != 0) {
- log_printf(LOG_LEVEL_WARNING,
- "Error setting timeout for open channel %s\n",
- req->ico_channel_name.value);
- }
- }
- return 0;
- open_return:
- res.ico_head.size = sizeof(res);
- res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
- res.ico_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Handler for saEvtChannelOpen
- */
- static int lib_evt_open_channel_async(struct conn_info *conn_info,
- void *message)
- {
- SaErrorT error;
- struct req_evt_channel_open *req;
- struct res_evt_channel_open res;
- struct open_chan_pending *ocp;
- int msec_in_future;
- int ret;
- req = message;
- log_printf(CHAN_OPEN_DEBUG,
- "saEvtChannelOpenAsync (Async Open channel request)\n");
- log_printf(CHAN_OPEN_DEBUG,
- "handle 0x%x, to 0x%x\n",
- req->ico_c_handle,
- req->ico_invocation);
- log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n",
- req->ico_open_flag,
- req->ico_channel_name.length,
- req->ico_channel_name.value);
- /*
- * Open the channel.
- *
- */
- error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag);
- if (error != SA_AIS_OK) {
- goto open_return;
- }
- ocp = malloc(sizeof(struct open_chan_pending));
- if (!ocp) {
- error = SA_AIS_ERR_NO_MEMORY;
- goto open_return;
- }
- ocp->ocp_async = 1;
- ocp->ocp_invocation = req->ico_invocation;
- ocp->ocp_c_handle = req->ico_c_handle;
- ocp->ocp_chan_name = req->ico_channel_name;
- ocp->ocp_open_flag = req->ico_open_flag;
- ocp->ocp_conn_info = conn_info;
- ocp->ocp_timer_handle = 0;
- list_init(&ocp->ocp_entry);
- list_add_tail(&ocp->ocp_entry, &open_pending);
- if (req->ico_timeout != 0) {
- /*
- * Time in nanoseconds - convert to miliseconds
- */
- msec_in_future = (uint32_t)(req->ico_timeout / 1000000ULL);
- ret = poll_timer_add(aisexec_poll_handle,
- msec_in_future,
- ocp,
- chan_open_timeout,
- &ocp->ocp_timer_handle);
- if (ret != 0) {
- log_printf(LOG_LEVEL_WARNING,
- "Error setting timeout for open channel %s\n",
- req->ico_channel_name.value);
- }
- }
- open_return:
- res.ico_head.size = sizeof(res);
- res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
- res.ico_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Used by the channel close code and by the implicit close
- * when saEvtFinalize is called with channels open.
- */
- static SaErrorT
- common_chan_close(struct event_svr_channel_open *eco, struct libevt_ci *esip)
- {
- struct event_svr_channel_subscr *ecs;
- struct list_head *l, *nxt;
- log_printf(LOG_LEVEL_DEBUG, "Close channel %s flags 0x%02x\n",
- eco->eco_channel->esc_channel_name.value,
- eco->eco_flags);
- /*
- * Disconnect the channel open structure.
- *
- * Check for subscriptions and deal with them. In this case
- * if there are any, we just implicitly unsubscribe.
- *
- * When We're done with the channel open data then we can
- * remove it's handle (this frees the memory too).
- *
- */
- list_del(&eco->eco_entry);
- list_del(&eco->eco_instance_entry);
- for (l = eco->eco_subscr.next; l != &eco->eco_subscr; l = nxt) {
- nxt = l->next;
- ecs = list_entry(l, struct event_svr_channel_subscr, ecs_entry);
- log_printf(LOG_LEVEL_DEBUG, "Unsubscribe ID: %x\n",
- ecs->ecs_sub_id);
- list_del(&ecs->ecs_entry);
- free(ecs);
- /*
- * Purge any pending events associated with this subscription
- * that don't match another subscription.
- */
- filter_undelivered_events(eco);
- }
- /*
- * Remove this channel from the retained event's notion
- * of who they have been delivered to.
- */
- remove_delivered_channel(eco);
- return evt_close_channel(&eco->eco_channel->esc_channel_name,
- eco->eco_channel->esc_unlink_id);
- }
- /*
- * Handler for saEvtChannelClose
- */
- static int lib_evt_close_channel(struct conn_info *conn_info, void *message)
- {
- struct req_evt_channel_close *req;
- struct res_evt_channel_close res;
- struct event_svr_channel_open *eco;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- SaErrorT error;
- void *ptr;
- req = message;
- log_printf(LOG_LEVEL_DEBUG,
- "saEvtChannelClose (Close channel request)\n");
- log_printf(LOG_LEVEL_DEBUG, "handle 0x%x\n", req->icc_channel_handle);
- /*
- * look up the channel handle
- */
- error = saHandleInstanceGet(&esip->esi_hdb,
- req->icc_channel_handle, &ptr);
- if (error != SA_AIS_OK) {
- goto chan_close_done;
- }
- eco = ptr;
- common_chan_close(eco, esip);
- saHandleDestroy(&esip->esi_hdb, req->icc_channel_handle);
- saHandleInstancePut(&esip->esi_hdb, req->icc_channel_handle);
- chan_close_done:
- res.icc_head.size = sizeof(res);
- res.icc_head.id = MESSAGE_RES_EVT_CLOSE_CHANNEL;
- res.icc_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Handler for saEvtChannelUnlink
- */
- static int lib_evt_unlink_channel(struct conn_info *conn_info, void *message)
- {
- struct req_evt_channel_unlink *req;
- struct res_evt_channel_unlink res;
- struct iovec chn_iovec;
- struct unlink_chan_pending *ucp;
- struct req_evt_chan_command cpkt;
- SaAisErrorT error = SA_AIS_ERR_LIBRARY;
- req = message;
- log_printf(CHAN_UNLINK_DEBUG,
- "saEvtChannelUnlink (Unlink channel request)\n");
- log_printf(CHAN_UNLINK_DEBUG, "Channel Name %s\n",
- req->iuc_channel_name.value);
- if (!find_channel(&req->iuc_channel_name, EVT_CHAN_ACTIVE)) {
- log_printf(CHAN_UNLINK_DEBUG, "Channel Name doesn't exist\n");
- error = SA_AIS_ERR_NOT_EXIST;
- goto evt_unlink_err;
- }
- /*
- * Set up the data structure so that the channel op
- * mcast handler can complete the unlink comamnd back to the
- * requestor.
- */
- ucp = malloc(sizeof(*ucp));
- if (!ucp) {
- log_printf(LOG_LEVEL_ERROR,
- "saEvtChannelUnlink: Memory allocation failure\n");
- error = SA_AIS_ERR_NO_MEMORY;
- goto evt_unlink_err;
- }
- ucp->ucp_unlink_id = next_chan_unlink_id();
- ucp->ucp_conn_info = conn_info;
- list_add_tail(&ucp->ucp_entry, &unlink_pending);
- /*
- * Put together a mcast packet to notify everyone
- * of the channel unlink.
- */
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_UNLINK_CHAN_OP;
- cpkt.u.chcu.chcu_name = req->iuc_channel_name;
- cpkt.u.chcu.chcu_unlink_id = ucp->ucp_unlink_id;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- if (totempg_mcast (&chn_iovec, 1, TOTEMPG_AGREED) == 0) {
- return 0;
- }
- evt_unlink_err:
- res.iuc_head.size = sizeof(res);
- res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL;
- res.iuc_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Subscribe to an event channel.
- *
- * - First look up the channel to subscribe.
- * - Make sure that the subscription ID is not already in use.
- * - Fill in the subscription data structures and add them to the channels
- * subscription list.
- * - See if there are any events with retetion times that need to be delivered
- * because of the new subscription.
- */
- static char *filter_types[] = {
- "INVALID FILTER TYPE",
- "SA_EVT_PREFIX_FILTER",
- "SA_EVT_SUFFIX_FILTER",
- "SA_EVT_EXACT_FILTER",
- "SA_EVT_PASS_ALL_FILTER",
- };
- /*
- * saEvtEventSubscribe Handler
- */
- static int lib_evt_event_subscribe(struct conn_info *conn_info, void *message)
- {
- struct req_evt_event_subscribe *req;
- struct res_evt_event_subscribe res;
- SaEvtEventFilterArrayT *filters;
- SaErrorT error = SA_AIS_OK;
- struct event_svr_channel_open *eco;
- struct event_svr_channel_instance *eci;
- struct event_svr_channel_subscr *ecs;
- struct event_data *evt;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- struct list_head *l;
- void *ptr;
- int i;
- req = message;
- log_printf(LOG_LEVEL_DEBUG,
- "saEvtEventSubscribe (Subscribe request)\n");
- log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%x\n",
- req->ics_sub_id);
- error = evtfilt_to_aisfilt(req, &filters);
- if (error == SA_AIS_OK) {
- log_printf(LOG_LEVEL_DEBUG, "Subscribe filters count %d\n",
- filters->filtersNumber);
- for (i = 0; i < filters->filtersNumber; i++) {
- log_printf(LOG_LEVEL_DEBUG, "type %s(%d) sz %d, <%s>\n",
- filter_types[filters->filters[i].filterType],
- filters->filters[i].filterType,
- filters->filters[i].filter.patternSize,
- (filters->filters[i].filter.patternSize)
- ? (char *)filters->filters[i].filter.pattern
- : "");
- }
- }
- if (error != SA_AIS_OK) {
- goto subr_done;
- }
- /*
- * look up the channel handle
- */
- error = saHandleInstanceGet(&esip->esi_hdb,
- req->ics_channel_handle, &ptr);
- if (error != SA_AIS_OK) {
- goto subr_done;
- }
- eco = ptr;
- eci = eco->eco_channel;
- /*
- * See if the id is already being used
- */
- ecs = find_subscr(eco, req->ics_sub_id);
- if (ecs) {
- error = SA_AIS_ERR_EXIST;
- goto subr_put;
- }
- ecs = (struct event_svr_channel_subscr *)malloc(sizeof(*ecs));
- if (!ecs) {
- error = SA_AIS_ERR_NO_MEMORY;
- goto subr_put;
- }
- ecs->ecs_filters = filters;
- ecs->ecs_sub_id = req->ics_sub_id;
- list_init(&ecs->ecs_entry);
- list_add(&ecs->ecs_entry, &eco->eco_subscr);
- res.ics_head.size = sizeof(res);
- res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE;
- res.ics_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- /*
- * See if an existing event with a retention time
- * needs to be delivered based on this subscription
- */
- for (l = retained_list.next; l != &retained_list; l = l->next) {
- evt = list_entry(l, struct event_data, ed_retained);
- log_printf(LOG_LEVEL_DEBUG,
- "Checking event ID %llx chanp %p -- sub chanp %p\n",
- evt->ed_event.led_event_id, evt->ed_my_chan, eci);
- if (evt->ed_my_chan == eci) {
- if (evt_already_delivered(evt, eco)) {
- continue;
- }
- if (event_match(evt, ecs) == SA_AIS_OK) {
- log_printf(LOG_LEVEL_DEBUG,
- "deliver event ID: 0x%llx\n",
- evt->ed_event.led_event_id);
- deliver_event(evt, eco, ecs);
- }
- }
- }
- saHandleInstancePut(&esip->esi_hdb, req->ics_channel_handle);
- return 0;
- subr_put:
- saHandleInstancePut(&esip->esi_hdb, req->ics_channel_handle);
- subr_done:
- res.ics_head.size = sizeof(res);
- res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE;
- res.ics_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
-
- return 0;
- }
- /*
- * saEvtEventUnsubscribe Handler
- */
- static int lib_evt_event_unsubscribe(struct conn_info *conn_info,
- void *message)
- {
- struct req_evt_event_unsubscribe *req;
- struct res_evt_event_unsubscribe res;
- struct event_svr_channel_open *eco;
- struct event_svr_channel_instance *eci;
- struct event_svr_channel_subscr *ecs;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- SaErrorT error = SA_AIS_OK;
- void *ptr;
- req = message;
- log_printf(LOG_LEVEL_DEBUG,
- "saEvtEventUnsubscribe (Unsubscribe request)\n");
- log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%x\n",
- req->icu_sub_id);
- /*
- * look up the channel handle, get the open channel
- * data.
- */
- error = saHandleInstanceGet(&esip->esi_hdb,
- req->icu_channel_handle, &ptr);
- if (error != SA_AIS_OK) {
- goto unsubr_done;
- }
- eco = ptr;
- eci = eco->eco_channel;
- /*
- * Make sure that the id exists.
- */
- ecs = find_subscr(eco, req->icu_sub_id);
- if (!ecs) {
- error = SA_AIS_ERR_INVALID_PARAM;
- goto unsubr_put;
- }
- list_del(&ecs->ecs_entry);
- log_printf(LOG_LEVEL_DEBUG,
- "unsubscribe from channel %s subscription ID 0x%x "
- "with %d filters\n",
- eci->esc_channel_name.value,
- ecs->ecs_sub_id, ecs->ecs_filters->filtersNumber);
- free_filters(ecs->ecs_filters);
- free(ecs);
- unsubr_put:
- saHandleInstancePut(&esip->esi_hdb, req->icu_channel_handle);
- unsubr_done:
- res.icu_head.size = sizeof(res);
- res.icu_head.id = MESSAGE_RES_EVT_UNSUBSCRIBE;
- res.icu_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
-
- return 0;
- }
- /*
- * saEvtEventPublish Handler
- */
- static int lib_evt_event_publish(struct conn_info *conn_info, void *message)
- {
- struct lib_event_data *req;
- struct res_evt_event_publish res;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- struct event_svr_channel_open *eco;
- struct event_svr_channel_instance *eci;
- SaEvtEventIdT event_id = 0;
- SaErrorT error = SA_AIS_OK;
- struct iovec pub_iovec;
- void *ptr;
- int result;
- req = message;
- log_printf(LOG_LEVEL_DEBUG,
- "saEvtEventPublish (Publish event request)\n");
- /*
- * look up and validate open channel info
- */
- error = saHandleInstanceGet(&esip->esi_hdb,
- req->led_svr_channel_handle, &ptr);
- if (error != SA_AIS_OK) {
- goto pub_done;
- }
- eco = ptr;
- eci = eco->eco_channel;
- /*
- * modify the request structure for sending event data to subscribed
- * processes.
- */
- get_event_id(&event_id);
- req->led_head.id = MESSAGE_REQ_EXEC_EVT_EVENTDATA;
- req->led_chan_name = eci->esc_channel_name;
- req->led_event_id = event_id;
- req->led_chan_unlink_id = eci->esc_unlink_id;
- /*
- * Distribute the event.
- * The multicasted event will be picked up and delivered
- * locally by the local network event receiver.
- */
- pub_iovec.iov_base = req;
- pub_iovec.iov_len = req->led_head.size;
- result = totempg_mcast (&pub_iovec, 1, TOTEMPG_AGREED);
- if (result != 0) {
- error = SA_AIS_ERR_LIBRARY;
- }
- saHandleInstancePut(&esip->esi_hdb, req->led_svr_channel_handle);
- pub_done:
- res.iep_head.size = sizeof(res);
- res.iep_head.id = MESSAGE_RES_EVT_PUBLISH;
- res.iep_head.error = error;
- res.iep_event_id = event_id;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * saEvtEventRetentionTimeClear handler
- */
- static int lib_evt_event_clear_retentiontime(struct conn_info *conn_info,
- void *message)
- {
- struct req_evt_event_clear_retentiontime *req;
- struct res_evt_event_clear_retentiontime res;
- struct req_evt_chan_command cpkt;
- struct iovec rtn_iovec;
- SaErrorT error = SA_AIS_OK;
- int ret;
- req = message;
- log_printf(LOG_LEVEL_DEBUG,
- "saEvtEventRetentionTimeClear (Clear event retentiontime request)\n");
- log_printf(LOG_LEVEL_DEBUG,
- "event ID 0x%llx, chan handle 0x%x\n",
- req->iec_event_id,
- req->iec_channel_handle);
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_CLEAR_RET_OP;
- cpkt.u.chc_event_id = req->iec_event_id;
- rtn_iovec.iov_base = &cpkt;
- rtn_iovec.iov_len = cpkt.chc_head.size;
- ret = totempg_mcast (&rtn_iovec, 1, TOTEMPG_AGREED);
- if (ret != 0) {
- error = SA_AIS_ERR_LIBRARY;
- }
- res.iec_head.size = sizeof(res);
- res.iec_head.id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME;
- res.iec_head.error = error;
- libais_send_response (conn_info, &res, sizeof(res));
- return 0;
- }
- /*
- * Send requested event data to the application
- */
- static int lib_evt_event_data_get(struct conn_info *conn_info, void *message)
- {
- struct lib_event_data res;
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- struct chan_event_list *cel;
- struct event_data *edp;
- int i;
- /*
- * Deliver events in publish order within priority
- */
- for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) {
- if (!list_empty(&esip->esi_events[i])) {
- cel = list_entry(esip->esi_events[i].next, struct chan_event_list,
- cel_entry);
- list_del(&cel->cel_entry);
- list_init(&cel->cel_entry);
- esip->esi_nevents--;
- if (esip->esi_queue_blocked &&
- (esip->esi_nevents < MIN_EVT_QUEUE_RESUME)) {
- esip->esi_queue_blocked = 0;
- log_printf(LOG_LEVEL_DEBUG, "unblock\n");
- }
- edp = cel->cel_event;
- edp->ed_event.led_lib_channel_handle = cel->cel_chan_handle;
- edp->ed_event.led_sub_id = cel->cel_sub_id;
- edp->ed_event.led_head.id = MESSAGE_RES_EVT_EVENT_DATA;
- edp->ed_event.led_head.error = SA_AIS_OK;
- free(cel);
- libais_send_response(conn_info, &edp->ed_event,
- edp->ed_event.led_head.size);
- free_event_data(edp);
- goto data_get_done;
- }
- }
- res.led_head.size = sizeof(res.led_head);
- res.led_head.id = MESSAGE_RES_EVT_EVENT_DATA;
- res.led_head.error = SA_AIS_ERR_NOT_EXIST;
- libais_send_response(conn_info, &res, res.led_head.size);
- /*
- * See if there are any events that the app doesn't know about
- * because the notify pipe was full.
- */
- data_get_done:
- if (esip->esi_nevents) {
- __notify_event(conn_info);
- }
- return 0;
- }
- /*
- * Scan the list of channels and remove the specified node.
- */
- static void remove_chan_open_info(SaClmNodeIdT node_id)
- {
- struct list_head *l, *nxt;
- struct event_svr_channel_instance *eci;
- for (l = esc_head.next; l != &esc_head; l = nxt) {
- nxt = l->next;
- eci = list_entry(l, struct event_svr_channel_instance, esc_entry);
- remove_open_count(eci, node_id);
- }
- }
- /*
- * Called when there is a configuration change in the cluster.
- * This function looks at any joiners and leavers and updates the evt
- * node list. The node list is used to keep track of event IDs
- * received for each node for the detection of duplicate events.
- */
- static int evt_conf_change(
- enum totem_configuration_type configuration_type,
- struct in_addr *member_list, void *member_list_private,
- int member_list_entries,
- struct in_addr *left_list, void *left_list_private,
- int left_list_entries,
- struct in_addr *joined_list, void *joined_list_private,
- int joined_list_entries,
- struct memb_ring_id *ring_id)
- {
- log_printf(RECOVERY_DEBUG, "Evt conf change %d\n",
- configuration_type);
- log_printf(RECOVERY_DEBUG, "m %d, j %d, l %d\n",
- member_list_entries,
- joined_list_entries,
- left_list_entries);
- /*
- * TODO: Save transitional membership for selecting representative from
- * each partition to send retained events.
- */
- /*
- * Save the various membership lists for later processing by
- * the synchronization functions. The left list is only
- * valid in the transitional configuration, the joined list is
- * only valid in the regular configuration. Other than for the
- * purposes of delivering retained events from merging partitions,
- * we only care about the final membership from the regular
- * configuration.
- */
- if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
- left_member_count = left_list_entries;
- if (left_member_list) {
- free(left_member_list);
- left_member_list = 0;
- }
- if (left_list_entries) {
- left_member_list =
- malloc(sizeof(struct in_addr) * left_list_entries);
- if (!left_member_list) {
- /*
- * TODO: ERROR
- */
- }
- memcpy(left_member_list, left_list,
- sizeof(struct in_addr) * left_list_entries);
- }
- }
- if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
- joined_member_count = joined_list_entries;
- total_member_count = member_list_entries;
- if (joined_member_list) {
- free(joined_member_list);
- joined_member_list = 0;
- }
- if (joined_list_entries) {
- joined_member_list =
- malloc(sizeof(struct in_addr) * joined_list_entries);
- if (!joined_member_list) {
- /*
- * TODO: ERROR
- */
- }
- memcpy(joined_member_list, joined_list,
- sizeof(struct in_addr) * joined_list_entries);
- }
- if (current_member_list) {
- free(current_member_list);
- current_member_list = 0;
- }
- if (member_list_entries) {
- current_member_list =
- malloc(sizeof(struct in_addr) * member_list_entries);
- if (!current_member_list) {
- /*
- * TODO: ERROR
- */
- }
- memcpy(current_member_list, member_list,
- sizeof(struct in_addr) * member_list_entries);
- }
- }
- return 0;
- }
- /*
- * saEvtFinalize Handler
- */
- static int evt_finalize(struct conn_info *conn_info)
- {
- struct libevt_ci *esip = &conn_info->ais_ci.u.libevt_ci;
- struct event_svr_channel_open *eco;
- struct list_head *l, *nxt;
- log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize (Event exit request)\n");
- log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize %d evts on list\n",
- esip->esi_nevents);
-
- /*
- * Clean up any open channels and associated subscriptions.
- */
- for (l = esip->esi_open_chans.next; l != &esip->esi_open_chans; l = nxt) {
- nxt = l->next;
- eco = list_entry(l, struct event_svr_channel_open, eco_instance_entry);
- common_chan_close(eco, esip);
- saHandleDestroy(&esip->esi_hdb, eco->eco_my_handle);
- }
- /*
- * Delete track entry if there is one
- */
- list_del (&conn_info->conn_list);
- return 0;
- }
- /*
- * Called at service start time.
- */
- static int evt_exec_init(void)
- {
- log_printf(LOG_LEVEL_DEBUG, "Evt exec init request\n");
- #ifdef TODO
- int res;
- res = totempg_recovery_plug_create (&evt_recovery_plug_handle);
- if (res != 0) {
- log_printf(LOG_LEVEL_ERROR,
- "Could not create recovery plug for event service.\n");
- return (-1);
- }
- #endif
- /*
- * Create an event to be sent when we have to drop messages
- * for an application.
- */
- dropped_event_size = sizeof(*dropped_event) + sizeof(dropped_pattern);
- dropped_event = malloc(dropped_event_size);
- if (dropped_event == 0) {
- log_printf(LOG_LEVEL_ERROR,
- "Memory Allocation Failure, event service not started\n");
- // TODO res = totempg_recovery_plug_destroy (evt_recovery_plug_handle);
- errno = ENOMEM;
- return -1;
- }
- memset(dropped_event, 0, sizeof(*dropped_event) + sizeof(dropped_pattern));
- dropped_event->ed_ref_count = 1;
- list_init(&dropped_event->ed_retained);
- dropped_event->ed_event.led_head.size =
- sizeof(*dropped_event) + sizeof(dropped_pattern);
- dropped_event->ed_event.led_head.error = SA_AIS_OK;
- dropped_event->ed_event.led_priority = SA_EVT_HIGHEST_PRIORITY;
- dropped_event->ed_event.led_chan_name = lost_chan;
- dropped_event->ed_event.led_publisher_name = dropped_publisher;
- dropped_event->ed_event.led_patterns_number = 1;
- memcpy(&dropped_event->ed_event.led_body[0],
- &dropped_pattern, sizeof(dropped_pattern));
- return 0;
- }
- /*
- * Receive the network event message and distribute it to local subscribers
- */
- static int evt_remote_evt(void *msg, struct in_addr source_addr,
- int endian_conversion_required)
- {
- /*
- * - retain events that have a retention time
- * - Find assocated channel
- * - Scan list of subscribers
- * - Apply filters
- * - Deliver events that pass the filter test
- */
- struct lib_event_data *evtpkt = msg;
- struct event_svr_channel_instance *eci;
- struct event_svr_channel_open *eco;
- struct event_svr_channel_subscr *ecs;
- struct event_data *evt;
- struct list_head *l, *l1;
- SaClmClusterNodeT *cn;
- log_printf(LOG_LEVEL_DEBUG, "Remote event data received from %s\n",
- inet_ntoa(source_addr));
- /*
- * See where the message came from so that we can set the
- * publishing node id in the message before delivery.
- */
- cn = clm_get_by_nodeid (source_addr);
- if (!cn) {
- /*
- * Not sure how this can happen...
- */
- log_printf(LOG_LEVEL_DEBUG, "No cluster node data for %s\n",
- inet_ntoa(source_addr));
- errno = ENXIO;
- return -1;
- }
- log_printf(LOG_LEVEL_DEBUG, "Cluster node ID 0x%x name %s\n",
- cn->nodeId, cn->nodeName.value);
- if (endian_conversion_required) {
- convert_event(evtpkt);
- }
- evtpkt->led_publisher_node_id = cn->nodeId;
- evtpkt->led_in_addr = source_addr;
- evtpkt->led_receive_time = clust_time_now();
- log_printf(CHAN_UNLINK_DEBUG,
- "evt_remote_evt(0): chan %s, id 0x%llx\n",
- evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
- eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id);
- /*
- * We may have had some events that were already queued when an
- * unlink happened, if we don't find the channel in the active list
- * look for the last unlinked channel of the same name. If this channel
- * is re-opened the messages will still be routed correctly because new
- * active channel messages will be ordered behind the open.
- */
- if (!eci && (evtpkt->led_chan_unlink_id == EVT_CHAN_ACTIVE)) {
- log_printf(CHAN_UNLINK_DEBUG,
- "evt_remote_evt(1): chan %s, id 0x%llx\n",
- evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
- eci = find_last_unlinked_channel(&evtpkt->led_chan_name);
- }
- /*
- * We shouldn't normally see an event for a channel that we
- * don't know about.
- */
- if (!eci) {
- log_printf(LOG_LEVEL_DEBUG, "Channel %s doesn't exist\n",
- evtpkt->led_chan_name.value);
- return 0;
- }
- if (check_last_event(evtpkt, source_addr)) {
- return 0;
- }
- evt = make_local_event(evtpkt, eci);
- if (!evt) {
- log_printf(LOG_LEVEL_WARNING,
- "1Memory allocation error, can't deliver event\n");
- errno = ENOMEM;
- return -1;
- }
-
- if (evt->ed_event.led_retention_time) {
- retain_event(evt);
- }
- /*
- * Check open channels
- */
- for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) {
- eco = list_entry(l, struct event_svr_channel_open, eco_entry);
- /*
- * See if enabled to receive
- */
- if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
- continue;
- }
- /*
- * Check subscriptions
- */
- for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) {
- ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry);
- /*
- * Apply filter rules and deliver if patterns
- * match filters.
- * Only deliver one event per open channel
- */
- if (event_match(evt, ecs) == SA_AIS_OK) {
- deliver_event(evt, eco, ecs);
- break;
- }
- }
- }
- free_event_data(evt);
- return 0;
- }
- /*
- * Calculate the remaining retention time of a received event during recovery
- */
- inline SaTimeT calc_retention_time(SaTimeT retention,
- SaTimeT received, SaTimeT now)
- {
- if ((received < now) && ((now - received) < retention)) {
- return retention - (now - received);
- } else {
- return 0;
- }
- }
- /*
- * Receive a recovery network event message and save it in the retained list
- */
- static int evt_remote_recovery_evt(void *msg, struct in_addr source_addr,
- int endian_conversion_required)
- {
- /*
- * - retain events that have a retention time
- * - Find assocated channel
- */
- struct lib_event_data *evtpkt = msg;
- struct event_svr_channel_instance *eci;
- struct event_data *evt;
- struct member_node_data *md;
- SaTimeT now;
- now = clust_time_now();
- log_printf(LOG_LEVEL_DEBUG,
- "Remote recovery event data received from %s\n",
- inet_ntoa(source_addr));
- if (recovery_phase == evt_recovery_complete) {
- log_printf(LOG_LEVEL_NOTICE,
- "Received recovery data, not in recovery mode\n");
- return 0;
- }
- if (endian_conversion_required) {
- convert_event(evtpkt);
- }
- log_printf(LOG_LEVEL_DEBUG,
- "Processing recovery of retained events\n");
- if (recovery_node) {
- log_printf(LOG_LEVEL_DEBUG, "This node is the recovery node\n");
- }
- log_printf(LOG_LEVEL_DEBUG, "(1)EVT ID: %llx, Time: %llx\n",
- evtpkt->led_event_id, evtpkt->led_retention_time);
- /*
- * Calculate remaining retention time
- */
- evtpkt->led_retention_time = calc_retention_time(
- evtpkt->led_retention_time,
- evtpkt->led_receive_time,
- now);
- log_printf(LOG_LEVEL_DEBUG,
- "(2)EVT ID: %llx, ret: %llx, rec: %llx, now: %llx\n",
- evtpkt->led_event_id,
- evtpkt->led_retention_time, evtpkt->led_receive_time, now);
- /*
- * If we haven't seen this event yet and it has remaining time, process
- * the event.
- */
- if (!check_last_event(evtpkt, evtpkt->led_in_addr) &&
- evtpkt->led_retention_time) {
- /*
- * See where the message came from so that we can set the
- * publishing node id in the message before delivery.
- */
- md = evt_find_node(evtpkt->led_in_addr);
- if (!md) {
- /*
- * Not sure how this can happen
- */
- log_printf(LOG_LEVEL_NOTICE, "No node for %s\n",
- inet_ntoa(evtpkt->led_in_addr));
- errno = ENXIO;
- return -1;
- }
- log_printf(LOG_LEVEL_DEBUG, "Cluster node ID 0x%x name %s\n",
- md->mn_node_info.nodeId,
- md->mn_node_info.nodeName.value);
- log_printf(CHAN_UNLINK_DEBUG,
- "evt_recovery_event: chan %s, id 0x%llx\n",
- evtpkt->led_chan_name.value, evtpkt->led_chan_unlink_id);
- eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id);
- /*
- * We shouldn't normally see an event for a channel that we don't
- * know about.
- */
- if (!eci) {
- log_printf(LOG_LEVEL_DEBUG, "Channel %s doesn't exist\n",
- evtpkt->led_chan_name.value);
- return 0;
- }
- evt = make_local_event(evtpkt, eci);
- if (!evt) {
- log_printf(LOG_LEVEL_WARNING,
- "2Memory allocation error, can't deliver event\n");
- errno = ENOMEM;
- return -1;
- }
-
- retain_event(evt);
- free_event_data(evt);
- }
- return 0;
- }
- /*
- * Timeout handler for event channel open.
- */
- static void chan_open_timeout(void *data)
- {
- struct open_chan_pending *ocp = (struct open_chan_pending *)data;
- struct res_evt_channel_open res;
-
- res.ico_head.size = sizeof(res);
- res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
- res.ico_head.error = SA_AIS_ERR_TIMEOUT;
- libais_send_response (ocp->ocp_conn_info, &res, sizeof(res));
- list_del(&ocp->ocp_entry);
- free(ocp);
- }
- /*
- * Called by the channel open exec handler to finish the open and
- * respond to the application
- */
- static void evt_chan_open_finish(struct open_chan_pending *ocp,
- struct event_svr_channel_instance *eci)
- {
- uint32_t handle;
- struct event_svr_channel_open *eco;
- SaErrorT error;
- struct libevt_ci *esip = &ocp->ocp_conn_info->ais_ci.u.libevt_ci;
- int ret = 0;
- void *ptr;
- log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s\n",
- getSaNameT(&ocp->ocp_chan_name));
- if (ocp->ocp_timer_handle) {
- ret = poll_timer_delete(aisexec_poll_handle, ocp->ocp_timer_handle);
- if (ret != 0 ) {
- log_printf(LOG_LEVEL_WARNING,
- "Error clearing timeout for open channel of %s\n",
- getSaNameT(&ocp->ocp_chan_name));
- }
- }
- /*
- * Create a handle to give back to the caller to associate
- * with this channel open instance.
- */
- error = saHandleCreate(&esip->esi_hdb, sizeof(*eco), &handle);
- if (error != SA_AIS_OK) {
- goto open_return;
- }
- error = saHandleInstanceGet(&esip->esi_hdb, handle, &ptr);
- if (error != SA_AIS_OK) {
- goto open_return;
- }
- eco = ptr;
- /*
- * Initailize and link into the global channel structure.
- */
- list_init(&eco->eco_subscr);
- list_init(&eco->eco_entry);
- list_init(&eco->eco_instance_entry);
- eco->eco_flags = ocp->ocp_open_flag;
- eco->eco_channel = eci;
- eco->eco_lib_handle = ocp->ocp_c_handle;
- eco->eco_my_handle = handle;
- eco->eco_conn_info = ocp->ocp_conn_info;
- list_add_tail(&eco->eco_entry, &eci->esc_open_chans);
- list_add_tail(&eco->eco_instance_entry, &esip->esi_open_chans);
- /*
- * respond back with a handle to access this channel
- * open instance for later subscriptions, etc.
- */
- saHandleInstancePut(&esip->esi_hdb, handle);
- open_return:
- log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s send response %d\n",
- getSaNameT(&ocp->ocp_chan_name),
- error);
- if (ocp->ocp_async) {
- struct res_evt_open_chan_async resa;
- resa.ica_head.size = sizeof(resa);
- resa.ica_head.id = MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK;
- resa.ica_head.error = error;
- resa.ica_channel_handle = handle;
- resa.ica_c_handle = ocp->ocp_c_handle;
- resa.ica_invocation = ocp->ocp_invocation;
- libais_send_response (ocp->ocp_conn_info, &resa, sizeof(resa));
- } else {
- struct res_evt_channel_open res;
- res.ico_head.size = sizeof(res);
- res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL;
- res.ico_head.error = error;
- res.ico_channel_handle = handle;
- libais_send_response (ocp->ocp_conn_info, &res, sizeof(res));
- }
- if (ret == 0) {
- list_del(&ocp->ocp_entry);
- free(ocp);
- }
- }
- /*
- * Called by the channel unlink exec handler to
- * respond to the application.
- */
- static void evt_chan_unlink_finish(struct unlink_chan_pending *ucp)
- {
- struct res_evt_channel_unlink res;
- log_printf(CHAN_UNLINK_DEBUG, "Unlink channel finish ID 0x%llx\n",
- ucp->ucp_unlink_id);
- res.iuc_head.size = sizeof(res);
- res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL;
- res.iuc_head.error = SA_AIS_OK;
- libais_send_response (ucp->ucp_conn_info, &res, sizeof(res));
- list_del(&ucp->ucp_entry);
- free(ucp);
- }
- /*
- * Take the channel command data and swap the elements so they match
- * our architectures word order.
- */
- static void
- convert_chan_packet(struct req_evt_chan_command *cpkt)
- {
- /*
- * converted in the main deliver_fn:
- * led_head.id, led_head.size.
- *
- */
- cpkt->chc_op = swab32(cpkt->chc_op);
- /*
- * Which elements of the packet that are converted depend
- * on the operation.
- */
- switch (cpkt->chc_op) {
-
- case EVT_OPEN_CHAN_OP:
- cpkt->u.chc_chan.length = swab16(cpkt->u.chc_chan.length);
- break;
- case EVT_UNLINK_CHAN_OP:
- case EVT_CLOSE_CHAN_OP:
- cpkt->u.chcu.chcu_name.length = swab16(cpkt->u.chcu.chcu_name.length);
- cpkt->u.chcu.chcu_unlink_id = swab64(cpkt->u.chcu.chcu_unlink_id);
- break;
- case EVT_CLEAR_RET_OP:
- cpkt->u.chc_event_id = swab64(cpkt->u.chc_event_id);
- break;
- case EVT_SET_ID_OP:
- cpkt->u.chc_set_id.chc_addr.s_addr =
- swab32(cpkt->u.chc_set_id.chc_addr.s_addr);
- cpkt->u.chc_set_id.chc_last_id = swab64(cpkt->u.chc_set_id.chc_last_id);
- break;
- case EVT_OPEN_COUNT:
- cpkt->u.chc_set_opens.chc_chan_name.length =
- swab16(cpkt->u.chc_set_opens.chc_chan_name.length);
- cpkt->u.chc_set_opens.chc_open_count =
- swab32(cpkt->u.chc_set_opens.chc_open_count);
- break;
- /*
- * No data assocaited with these ops.
- */
- case EVT_CONF_DONE:
- case EVT_OPEN_COUNT_DONE:
- break;
- /*
- * Make sure that this function is updated when new ops are added.
- */
- default:
- assert(0);
- }
- }
- /*
- * Receive and process remote event operations.
- * Used to communicate channel opens/closes, clear retention time,
- * config change updates...
- */
- static int evt_remote_chan_op(void *msg, struct in_addr source_addr,
- int endian_conversion_required)
- {
- struct req_evt_chan_command *cpkt = msg;
- struct in_addr local_node = {SA_CLM_LOCAL_NODE_ID};
- SaClmClusterNodeT *cn, *my_node;
- struct member_node_data *mn;
- struct event_svr_channel_instance *eci;
- if (endian_conversion_required) {
- convert_chan_packet(cpkt);
- }
- log_printf(REMOTE_OP_DEBUG, "Remote channel operation request\n");
- my_node = clm_get_by_nodeid(local_node);
- log_printf(REMOTE_OP_DEBUG, "my node ID: 0x%x\n", my_node->nodeId);
- mn = evt_find_node(source_addr);
- if (mn == NULL) {
- cn = clm_get_by_nodeid(source_addr);
- if (cn == NULL) {
- log_printf(LOG_LEVEL_WARNING,
- "Evt remote channel op: Node data for addr %s is NULL\n",
- inet_ntoa(source_addr));
- } else {
- evt_add_node(source_addr, cn);
- mn = evt_find_node(source_addr);
- }
- }
- switch (cpkt->chc_op) {
- /*
- * Open channel remote command. The open channel request is done
- * in two steps. When an pplication tries to open, we send an open
- * channel message to the other nodes. When we receive an open channel
- * message, we may create the channel structure if it doesn't exist
- * and also complete applicaiton open requests for the specified
- * channel. We keep a counter of total opens for the given channel and
- * later when it has been completely closed (everywhere in the cluster)
- * we will free up the assocated channel data.
- */
- case EVT_OPEN_CHAN_OP: {
- struct open_chan_pending *ocp;
- struct list_head *l, *nxt;
- log_printf(CHAN_OPEN_DEBUG, "Opening channel %s for node 0x%x\n",
- cpkt->u.chc_chan.value, mn->mn_node_info.nodeId);
- eci = find_channel(&cpkt->u.chc_chan, EVT_CHAN_ACTIVE);
- if (!eci) {
- eci = create_channel(&cpkt->u.chc_chan);
- }
- if (!eci) {
- log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n",
- getSaNameT(&cpkt->u.chc_chan));
- break;
- }
- inc_open_count(eci, mn->mn_node_info.nodeId);
- if (mn->mn_node_info.nodeId == my_node->nodeId) {
- /*
- * Complete one of our pending open requests
- */
- for (l = open_pending.next; l != &open_pending; l = nxt) {
- nxt = l->next;
- ocp = list_entry(l, struct open_chan_pending, ocp_entry);
- log_printf(CHAN_OPEN_DEBUG,
- "Compare channel %s %s\n", ocp->ocp_chan_name.value,
- eci->esc_channel_name.value);
- if (name_match(&ocp->ocp_chan_name, &eci->esc_channel_name)) {
- evt_chan_open_finish(ocp, eci);
- break;
- }
- }
- }
- log_printf(CHAN_OPEN_DEBUG,
- "Open channel %s t %d, l %d, r %d\n",
- getSaNameT(&eci->esc_channel_name),
- eci->esc_total_opens, eci->esc_local_opens,
- eci->esc_retained_count);
- break;
- }
- /*
- * Handle a channel close. We'll decrement the global open counter and
- * free up channel associated data when all instances are closed.
- */
- case EVT_CLOSE_CHAN_OP:
- log_printf(LOG_LEVEL_DEBUG, "Closing channel %s for node 0x%x\n",
- cpkt->u.chcu.chcu_name.value, mn->mn_node_info.nodeId);
- eci = find_channel(&cpkt->u.chcu.chcu_name, cpkt->u.chcu.chcu_unlink_id);
- if (!eci) {
- log_printf(LOG_LEVEL_NOTICE,
- "Channel close request for %s not found\n",
- cpkt->u.chcu.chcu_name.value);
- break;
- }
- /*
- * if last instance, we can free up assocated data.
- */
- dec_open_count(eci, mn->mn_node_info.nodeId);
- log_printf(LOG_LEVEL_DEBUG,
- "Close channel %s t %d, l %d, r %d\n",
- eci->esc_channel_name.value,
- eci->esc_total_opens, eci->esc_local_opens,
- eci->esc_retained_count);
- delete_channel(eci);
- break;
- /*
- * Handle a request for channel unlink saEvtChannelUnlink().
- * We'll look up the channel and mark it as unlinked. Respond to
- * local library unlink commands.
- */
- case EVT_UNLINK_CHAN_OP: {
- struct unlink_chan_pending *ucp;
- struct list_head *l, *nxt;
- log_printf(CHAN_UNLINK_DEBUG,
- "Unlink request channel %s unlink ID 0x%llx from node 0x%x\n",
- cpkt->u.chcu.chcu_name.value,
- cpkt->u.chcu.chcu_unlink_id,
- mn->mn_node_info.nodeId);
- /*
- * look up the channel name and get its assoicated data.
- */
- eci = find_channel(&cpkt->u.chcu.chcu_name,
- EVT_CHAN_ACTIVE);
- if (!eci) {
- log_printf(LOG_LEVEL_NOTICE,
- "Channel unlink request for %s not found\n",
- cpkt->u.chcu.chcu_name);
- break;
- }
- /*
- * Mark channel as unlinked.
- */
- unlink_channel(eci, cpkt->u.chcu.chcu_unlink_id);
- /*
- * respond only to local library requests.
- */
- if (mn->mn_node_info.nodeId == my_node->nodeId) {
- /*
- * Complete one of our pending unlink requests
- */
- for (l = unlink_pending.next; l != &unlink_pending; l = nxt) {
- nxt = l->next;
- ucp = list_entry(l, struct unlink_chan_pending, ucp_entry);
- log_printf(CHAN_UNLINK_DEBUG,
- "Compare channel id 0x%llx 0x%llx\n",
- ucp->ucp_unlink_id, eci->esc_unlink_id);
- if (ucp->ucp_unlink_id == eci->esc_unlink_id) {
- evt_chan_unlink_finish(ucp);
- break;
- }
- }
- }
- break;
- }
- /*
- * saEvtClearRetentiotime handler.
- */
- case EVT_CLEAR_RET_OP:
- log_printf(LOG_LEVEL_DEBUG, "Clear retention time request %llx\n",
- cpkt->u.chc_event_id);
- clear_retention_time(cpkt->u.chc_event_id);
- break;
-
- /*
- * Set our next event ID based on the largest event ID seen
- * by others in the cluster. This way, if we've left and re-joined, we'll
- * start using an event ID that is unique.
- */
- case EVT_SET_ID_OP: {
- struct in_addr my_addr;
- my_addr.s_addr = my_node->nodeId;
- log_printf(RECOVERY_DEBUG,
- "Received Set event ID OP from %x to %llx for %x my addr %x base %llx\n",
- inet_ntoa(source_addr),
- cpkt->u.chc_set_id.chc_last_id,
- cpkt->u.chc_set_id.chc_addr.s_addr,
- my_addr.s_addr,
- base_id);
- if (cpkt->u.chc_set_id.chc_addr.s_addr == my_addr.s_addr) {
- if (cpkt->u.chc_set_id.chc_last_id > base_id) {
- log_printf(RECOVERY_DEBUG,
- "Set event ID from %s to %llx\n",
- inet_ntoa(source_addr), cpkt->u.chc_set_id.chc_last_id);
- base_id = cpkt->u.chc_set_id.chc_last_id + 1;
- }
- }
- break;
- }
- /*
- * Receive the open count for a particular channel during recovery.
- * This insures that everyone has the same notion of who has a channel
- * open so that it can be removed when no one else has it open anymore.
- */
- case EVT_OPEN_COUNT:
- if (recovery_phase == evt_recovery_complete) {
- log_printf(LOG_LEVEL_ERROR,
- "Evt open count msg from %s, but not in membership change\n",
- inet_ntoa(source_addr));
- }
- log_printf(RECOVERY_DEBUG,
- "Open channel count %s is %d for node 0x%x\n",
- cpkt->u.chc_set_opens.chc_chan_name.value,
- cpkt->u.chc_set_opens.chc_open_count,
- mn->mn_node_info.nodeId);
- eci = find_channel(&cpkt->u.chc_set_opens.chc_chan_name,
- EVT_CHAN_ACTIVE);
- if (!eci) {
- eci = create_channel(&cpkt->u.chc_set_opens.chc_chan_name);
- }
- if (!eci) {
- log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n",
- getSaNameT(&cpkt->u.chc_set_opens.chc_chan_name));
- break;
- }
- if (set_open_count(eci, mn->mn_node_info.nodeId,
- cpkt->u.chc_set_opens.chc_open_count)) {
- log_printf(LOG_LEVEL_ERROR,
- "Error setting Open channel count %s for node 0x%x\n",
- cpkt->u.chc_set_opens.chc_chan_name.value,
- mn->mn_node_info.nodeId);
- }
- break;
- /*
- * Once we get all the messages from
- * the current membership, determine who delivers any retained events.
- */
- case EVT_OPEN_COUNT_DONE: {
- if (recovery_phase == evt_recovery_complete) {
- log_printf(LOG_LEVEL_ERROR,
- "Evt config msg from %s, but not in membership change\n",
- inet_ntoa(source_addr));
- }
- log_printf(RECOVERY_DEBUG,
- "Receive EVT_CONF_CHANGE_DONE from %s members %d checked in %d\n",
- inet_ntoa(source_addr), total_member_count, checked_in+1);
- if (!mn) {
- log_printf(RECOVERY_DEBUG,
- "NO NODE DATA AVAILABLE FOR %s\n",
- inet_ntoa(source_addr));
- }
- if (++checked_in == total_member_count) {
- /*
- * We're all here, now figure out who should send the
- * retained events.
- */
- mn = oldest_node();
- if (mn->mn_node_info.nodeId == my_node_id) {
- log_printf(RECOVERY_DEBUG, "I am oldest\n");
- recovery_phase = evt_send_retained_events;
- } else {
- recovery_phase = evt_wait_send_retained_events;
- }
- }
- break;
- }
- /*
- * OK, We're done with recovery, continue operations.
- */
- case EVT_CONF_DONE: {
- log_printf(RECOVERY_DEBUG,
- "Receive EVT_CONF_DONE from %s\n",
- inet_ntoa(source_addr));
- recovery_phase = evt_recovery_complete;
- #ifdef DUMP_CHAN_INFO
- dump_all_chans();
- #endif
- break;
- }
- default:
- log_printf(LOG_LEVEL_NOTICE, "Invalid channel operation %d\n",
- cpkt->chc_op);
- break;
- }
- return 0;
- }
- /*
- * Set up initial conditions for processing event service
- * recovery.
- */
- static void evt_sync_init(void)
- {
- SaClmClusterNodeT *cn;
- struct member_node_data *md;
- struct in_addr my_node = {SA_CLM_LOCAL_NODE_ID};
- int left_list_entries = left_member_count;
- struct in_addr *left_list = left_member_list;
- log_printf(RECOVERY_DEBUG, "Evt synchronize initialization\n");
- /*
- * Set the base event id
- */
- if (!my_node_id) {
- cn = clm_get_by_nodeid(my_node);
- log_printf(RECOVERY_DEBUG, "My node ID 0x%x\n", cn->nodeId);
- my_node_id = cn->nodeId;
- set_event_id(my_node_id);
- }
- /*
- * account for nodes that left the membership
- */
- while (left_list_entries--) {
- md = evt_find_node(*left_list);
- if (md == 0) {
- log_printf(LOG_LEVEL_WARNING,
- "Can't find cluster node at %s\n",
- inet_ntoa(left_list[0]));
- /*
- * Mark this one as down.
- */
- } else {
- log_printf(RECOVERY_DEBUG, "cluster node at %s down\n",
- inet_ntoa(left_list[0]));
- md->mn_started = 0;
- remove_chan_open_info(md->mn_node_info.nodeId);
- }
- left_list++;
- }
- /*
- * set up for recovery processing
- */
- recovery_phase = evt_send_event_id;
- add_list = joined_member_list;
- add_count = joined_member_count;
- next_chan = esc_head.next;
- checked_in = 0;
- next_retained = retained_list.next;
- }
- /*
- * Handle event service recovery. It passes through a number of states to
- * finish the recovery.
- *
- * First, the node broadcasts the highest event ID that it has seen for any
- * joinig node. This helps to make sure that rejoining nodes don't re-use
- * event IDs that have already been seen.
- *
- * Next, The node broadcasts its open channel information to the other nodes.
- * This makes sure that any joining nodes have complete data on any channels
- * already open.
- *
- * Once done sending open channel information the node waits in a state for
- * the rest of the nodes to finish sending their data. When the last node
- * has checked in, then the remote channel operation handler selects the next
- * state which is evt_send_retained_events if this is the oldest node in the
- * cluster, or otherwise to evt_wait_send_retained_events to wait for the
- * retained events to be sent. When the retained events have been sent, the
- * state is changed to evt_recovery_complete and this function exits with
- * zero to inidicate that recovery is done.
- */
- static int evt_sync_process(void)
- {
- log_printf(RECOVERY_DEBUG, "Process Evt synchronization \n");
- switch (recovery_phase) {
-
- /*
- * Send last know event ID to joining nodes to prevent duplicate
- * event IDs.
- */
- case evt_send_event_id:
- {
- struct member_node_data *md;
- SaClmClusterNodeT *cn;
- struct req_evt_chan_command cpkt;
- struct iovec chn_iovec;
- int res;
- log_printf(RECOVERY_DEBUG, "Send max event ID updates\n");
- while (add_count) {
- /*
- * If we've seen this node before, send out the last event ID
- * that we've seen from him. He will set his base event ID to
- * the highest one seen.
- */
- md = evt_find_node(*add_list);
- if (md != NULL) {
- if (!md->mn_started) {
- log_printf(RECOVERY_DEBUG,
- "end set evt ID %llx to %s\n",
- md->mn_last_evt_id, inet_ntoa(*add_list));
- md->mn_started = 1;
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_SET_ID_OP;
- cpkt.u.chc_set_id.chc_addr = *add_list;
- cpkt.u.chc_set_id.chc_last_id =
- md->mn_last_evt_id & BASE_ID_MASK;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- res = totempg_mcast (&chn_iovec, 1,TOTEMPG_AGREED);
- if (res != 0) {
- log_printf(RECOVERY_DEBUG,
- "Unable to send event id to %s\n",
- inet_ntoa(*add_list));
- /*
- * We'll try again later.
- */
- return 1;
- }
- }
- } else {
- /*
- * Not seen before, add it to our list of nodes.
- */
- cn = clm_get_by_nodeid(*add_list);
- if (!cn) {
- /*
- * TODO: Error, shouldn't happen
- */
- }
- evt_add_node(*add_list, cn);
- }
- add_list++;
- add_count--;
- }
- recovery_phase = evt_send_open_count;
- return 1;
- }
- /*
- * Send channel open counts so all members have the same channel open
- * counts.
- */
- case evt_send_open_count:
- {
- log_printf(RECOVERY_DEBUG, "Send open count updates\n");
- struct req_evt_chan_command cpkt;
- struct iovec chn_iovec;
- struct event_svr_channel_instance *eci;
- int res;
- /*
- * Process messages. When we're done, send the done message
- * to the nodes.
- */
- memset(&cpkt, 0, sizeof(cpkt));
- for (;next_chan != &esc_head;
- next_chan = next_chan->next) {
- log_printf(RECOVERY_DEBUG, "Sending next open count\n");
- eci = list_entry(next_chan, struct event_svr_channel_instance,
- esc_entry);
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_OPEN_COUNT;
- cpkt.u.chc_set_opens.chc_chan_name = eci->esc_channel_name;
- cpkt.u.chc_set_opens.chc_open_count = eci->esc_local_opens;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- res = totempg_mcast(&chn_iovec, 1,TOTEMPG_AGREED);
- if (res != 0) {
- /*
- * Try again later.
- */
- return 1;
- }
- }
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_OPEN_COUNT_DONE;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- res = totempg_mcast (&chn_iovec, 1,TOTEMPG_AGREED);
- if (res != 0) {
- /*
- * Try again later.
- */
- return 1;
- }
- log_printf(RECOVERY_DEBUG, "DONE Sending open counts\n");
- recovery_phase = evt_wait_open_count_done;
- return 1;
- }
- /*
- * Wait for all nodes to finish sending open updates before proceding.
- * the EVT_OPEN_COUNT_DONE handler will set the state to
- * evt_send_retained_events to get us out of this.
- */
- case evt_wait_open_count_done:
- {
- log_printf(RECOVERY_DEBUG, "Wait for open count done\n");
- return 1;
- }
- /*
- * If I'm the oldest node, send out retained events so that new nodes
- * have all the information.
- */
- case evt_send_retained_events:
- {
- struct req_evt_chan_command cpkt;
- struct iovec chn_iovec;
- struct event_data *evt;
- int res;
- log_printf(RECOVERY_DEBUG, "Send retained event updates\n");
- /*
- * Process messages. When we're done, send the done message
- * to the nodes.
- */
- for (;next_retained != &retained_list;
- next_retained = next_retained->next) {
- log_printf(LOG_LEVEL_DEBUG, "Sending next retained event\n");
- evt = list_entry(next_retained, struct event_data, ed_retained);
- evt->ed_event.led_head.id = MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA;
- chn_iovec.iov_base = &evt->ed_event;
- chn_iovec.iov_len = evt->ed_event.led_head.size;
- res = totempg_mcast(&chn_iovec, 1, TOTEMPG_AGREED);
- if (res != 0) {
- /*
- * Try again later.
- */
- return -1;
- }
- }
- log_printf(RECOVERY_DEBUG, "DONE Sending retained events\n");
- memset(&cpkt, 0, sizeof(cpkt));
- cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
- cpkt.chc_head.size = sizeof(cpkt);
- cpkt.chc_op = EVT_CONF_DONE;
- chn_iovec.iov_base = &cpkt;
- chn_iovec.iov_len = cpkt.chc_head.size;
- res = totempg_mcast (&chn_iovec, 1, TOTEMPG_AGREED);
- recovery_phase = evt_wait_send_retained_events;
- return 1;
- }
- /*
- * Wait for send of retained events to finish
- * the EVT_CONF_DONE handler will set the state to
- * evt_recovery_complete to get us out of this.
- */
- case evt_wait_send_retained_events:
- {
- log_printf(RECOVERY_DEBUG, "Wait for retained events\n");
- return 1;
- }
- case evt_recovery_complete:
- {
- log_printf(RECOVERY_DEBUG, "Recovery complete\n");
- return 0;
- }
- default:
- log_printf(LOG_LEVEL_WARNING, "Bad recovery phase state: %u\n",
- recovery_phase);
- recovery_phase = evt_recovery_complete;
- return 0;
- }
- return 0;
- }
- /*
- * Not used at this time
- */
- static void evt_sync_activate(void)
- {
- log_printf(RECOVERY_DEBUG, "Evt synchronize activation\n");
- }
- /*
- * Not used at this time
- */
- static void evt_sync_abort(void)
- {
- log_printf(RECOVERY_DEBUG, "Abort Evt synchronization\n");
- }
- /*
- * vi: set autoindent tabstop=4 shiftwidth=4 :
- */
|