| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851 |
- /*
- * Copyright (c) 2005 MontaVista Software, Inc.
- * Copyright (c) 2006-2009 Red Hat, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake (sdake@redhat.com)
- *
- * 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 MontaVista Software, Inc. 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.
- */
- #include <config.h>
- #include <assert.h>
- #include <pthread.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <sys/un.h>
- #include <sys/ioctl.h>
- #include <sys/param.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <sched.h>
- #include <time.h>
- #include <sys/time.h>
- #include <sys/poll.h>
- #include <limits.h>
- #include <corosync/sq.h>
- #include <corosync/list.h>
- #include <corosync/hdb.h>
- #include <corosync/swab.h>
- #include <corosync/totem/coropoll.h>
- #define LOGSYS_UTILS_ONLY 1
- #include <corosync/engine/logsys.h>
- #include "totemnet.h"
- #include "totemrrp.h"
- void rrp_deliver_fn (
- void *context,
- const void *msg,
- unsigned int msg_len);
- void rrp_iface_change_fn (
- void *context,
- const struct totem_ip_address *iface_addr);
- struct totemrrp_instance;
- struct passive_instance {
- struct totemrrp_instance *rrp_instance;
- unsigned int *faulty;
- unsigned int *token_recv_count;
- unsigned int *mcast_recv_count;
- unsigned char token[15000];
- unsigned int token_len;
- poll_timer_handle timer_expired_token;
- poll_timer_handle timer_problem_decrementer;
- void *totemrrp_context;
- unsigned int token_xmit_iface;
- unsigned int msg_xmit_iface;
- };
- struct active_instance {
- struct totemrrp_instance *rrp_instance;
- unsigned int *faulty;
- unsigned int *last_token_recv;
- unsigned int *counter_problems;
- unsigned char token[15000];
- unsigned int token_len;
- unsigned int last_token_seq;
- poll_timer_handle timer_expired_token;
- poll_timer_handle timer_problem_decrementer;
- void *totemrrp_context;
- };
- struct rrp_algo {
- const char *name;
- void * (*initialize) (
- struct totemrrp_instance *rrp_instance,
- int interface_count);
- void (*mcast_recv) (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len);
- void (*mcast_noflush_send) (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- void (*mcast_flush_send) (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- void (*token_recv) (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seqid);
- void (*token_send) (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- void (*recv_flush) (
- struct totemrrp_instance *instance);
- void (*send_flush) (
- struct totemrrp_instance *instance);
- void (*iface_check) (
- struct totemrrp_instance *instance);
- void (*processor_count_set) (
- struct totemrrp_instance *instance,
- unsigned int processor_count);
- void (*token_target_set) (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no);
- void (*ring_reenable) (
- struct totemrrp_instance *instance);
- int (*mcast_recv_empty) (
- struct totemrrp_instance *instance);
- };
- struct totemrrp_instance {
- hdb_handle_t totemrrp_poll_handle;
- struct totem_interface *interfaces;
- struct rrp_algo *rrp_algo;
- void *context;
- char *status[INTERFACE_MAX];
- void (*totemrrp_deliver_fn) (
- void *context,
- const void *msg,
- unsigned int msg_len);
- void (*totemrrp_iface_change_fn) (
- void *context,
- const struct totem_ip_address *iface_addr,
- unsigned int iface_no);
- void (*totemrrp_token_seqid_get) (
- const void *msg,
- unsigned int *seqid,
- unsigned int *token_is);
- unsigned int (*totemrrp_msgs_missing) (void);
- /*
- * Function and data used to log messages
- */
- int totemrrp_log_level_security;
- int totemrrp_log_level_error;
- int totemrrp_log_level_warning;
- int totemrrp_log_level_notice;
- int totemrrp_log_level_debug;
- int totemrrp_subsys_id;
- void (*totemrrp_log_printf) (
- unsigned int rec_ident,
- const char *function,
- const char *file,
- int line,
- const char *format, ...)__attribute__((format(printf, 5, 6)));
- hdb_handle_t handle;
- hdb_handle_t *net_handles;
- void *rrp_algo_instance;
- int interface_count;
- hdb_handle_t poll_handle;
- int processor_count;
- struct totem_config *totem_config;
- };
- /*
- * None Replication Forward Declerations
- */
- static void none_mcast_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len);
- static void none_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void none_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void none_token_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seqid);
- static void none_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void none_recv_flush (
- struct totemrrp_instance *instance);
- static void none_send_flush (
- struct totemrrp_instance *instance);
- static void none_iface_check (
- struct totemrrp_instance *instance);
- static void none_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count_set);
- static void none_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no);
- static void none_ring_reenable (
- struct totemrrp_instance *instance);
- static int none_mcast_recv_empty (
- struct totemrrp_instance *instance);
- /*
- * Passive Replication Forward Declerations
- */
- static void *passive_instance_initialize (
- struct totemrrp_instance *rrp_instance,
- int interface_count);
- static void passive_mcast_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len);
- static void passive_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void passive_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void passive_token_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seqid);
- static void passive_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void passive_recv_flush (
- struct totemrrp_instance *instance);
- static void passive_send_flush (
- struct totemrrp_instance *instance);
- static void passive_iface_check (
- struct totemrrp_instance *instance);
- static void passive_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count_set);
- static void passive_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no);
- static void passive_ring_reenable (
- struct totemrrp_instance *instance);
- static int passive_mcast_recv_empty (
- struct totemrrp_instance *instance);
- /*
- * Active Replication Forward Definitions
- */
- static void *active_instance_initialize (
- struct totemrrp_instance *rrp_instance,
- int interface_count);
- static void active_mcast_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len);
- static void active_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void active_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void active_token_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seqid);
- static void active_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len);
- static void active_recv_flush (
- struct totemrrp_instance *instance);
- static void active_send_flush (
- struct totemrrp_instance *instance);
- static void active_iface_check (
- struct totemrrp_instance *instance);
- static void active_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count_set);
- static void active_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no);
- static void active_ring_reenable (
- struct totemrrp_instance *instance);
- static int active_mcast_recv_empty (
- struct totemrrp_instance *instance);
- static void active_timer_expired_token_start (
- struct active_instance *active_instance);
- static void active_timer_expired_token_cancel (
- struct active_instance *active_instance);
- static void active_timer_problem_decrementer_start (
- struct active_instance *active_instance);
- static void active_timer_problem_decrementer_cancel (
- struct active_instance *active_instance);
- struct rrp_algo none_algo = {
- .name = "none",
- .initialize = NULL,
- .mcast_recv = none_mcast_recv,
- .mcast_noflush_send = none_mcast_noflush_send,
- .mcast_flush_send = none_mcast_flush_send,
- .token_recv = none_token_recv,
- .token_send = none_token_send,
- .recv_flush = none_recv_flush,
- .send_flush = none_send_flush,
- .iface_check = none_iface_check,
- .processor_count_set = none_processor_count_set,
- .token_target_set = none_token_target_set,
- .ring_reenable = none_ring_reenable,
- .mcast_recv_empty = none_mcast_recv_empty
- };
- struct rrp_algo passive_algo = {
- .name = "passive",
- .initialize = passive_instance_initialize,
- .mcast_recv = passive_mcast_recv,
- .mcast_noflush_send = passive_mcast_noflush_send,
- .mcast_flush_send = passive_mcast_flush_send,
- .token_recv = passive_token_recv,
- .token_send = passive_token_send,
- .recv_flush = passive_recv_flush,
- .send_flush = passive_send_flush,
- .iface_check = passive_iface_check,
- .processor_count_set = passive_processor_count_set,
- .token_target_set = passive_token_target_set,
- .ring_reenable = passive_ring_reenable,
- .mcast_recv_empty = passive_mcast_recv_empty
- };
- struct rrp_algo active_algo = {
- .name = "active",
- .initialize = active_instance_initialize,
- .mcast_recv = active_mcast_recv,
- .mcast_noflush_send = active_mcast_noflush_send,
- .mcast_flush_send = active_mcast_flush_send,
- .token_recv = active_token_recv,
- .token_send = active_token_send,
- .recv_flush = active_recv_flush,
- .send_flush = active_send_flush,
- .iface_check = active_iface_check,
- .processor_count_set = active_processor_count_set,
- .token_target_set = active_token_target_set,
- .ring_reenable = active_ring_reenable,
- .mcast_recv_empty = active_mcast_recv_empty
- };
- struct rrp_algo *rrp_algos[] = {
- &none_algo,
- &passive_algo,
- &active_algo
- };
- #define RRP_ALGOS_COUNT 3
- /*
- * All instances in one database
- */
- DECLARE_HDB_DATABASE (totemrrp_instance_database,NULL);
- #define log_printf(level, format, args...) \
- do { \
- rrp_instance->totemrrp_log_printf ( \
- LOGSYS_ENCODE_RECID(level, \
- rrp_instance->totemrrp_subsys_id, \
- LOGSYS_RECID_LOG), \
- __FUNCTION__, __FILE__, __LINE__, \
- format, ##args); \
- } while (0);
- /*
- * None Replication Implementation
- */
- static void none_mcast_recv (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len)
- {
- rrp_instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- }
- static void none_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- totemnet_mcast_flush_send (instance->net_handles[0], msg, msg_len);
- }
- static void none_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- totemnet_mcast_noflush_send (instance->net_handles[0], msg, msg_len);
- }
- static void none_token_recv (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seq)
- {
- rrp_instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- }
- static void none_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- totemnet_token_send (
- instance->net_handles[0],
- msg, msg_len);
- }
- static void none_recv_flush (struct totemrrp_instance *instance)
- {
- totemnet_recv_flush (instance->net_handles[0]);
- }
- static void none_send_flush (struct totemrrp_instance *instance)
- {
- totemnet_send_flush (instance->net_handles[0]);
- }
- static void none_iface_check (struct totemrrp_instance *instance)
- {
- totemnet_iface_check (instance->net_handles[0]);
- }
- static void none_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count)
- {
- totemnet_processor_count_set (instance->net_handles[0],
- processor_count);
- }
- static void none_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no)
- {
- totemnet_token_target_set (instance->net_handles[0], token_target);
- }
- static void none_ring_reenable (
- struct totemrrp_instance *instance)
- {
- /*
- * No operation
- */
- }
- static int none_mcast_recv_empty (
- struct totemrrp_instance *instance)
- {
- int res;
- res = totemnet_recv_mcast_empty (instance->net_handles[0]);
- return (res);
- }
- /*
- * Passive Replication Implementation
- */
- void *passive_instance_initialize (
- struct totemrrp_instance *rrp_instance,
- int interface_count)
- {
- struct passive_instance *instance;
- instance = malloc (sizeof (struct passive_instance));
- if (instance == 0) {
- goto error_exit;
- }
- memset (instance, 0, sizeof (struct passive_instance));
- instance->faulty = malloc (sizeof (int) * interface_count);
- if (instance->faulty == 0) {
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->faulty, 0, sizeof (int) * interface_count);
- instance->token_recv_count = malloc (sizeof (int) * interface_count);
- if (instance->token_recv_count == 0) {
- free (instance->faulty);
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->token_recv_count, 0, sizeof (int) * interface_count);
- instance->mcast_recv_count = malloc (sizeof (int) * interface_count);
- if (instance->mcast_recv_count == 0) {
- free (instance->token_recv_count);
- free (instance->faulty);
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->mcast_recv_count, 0, sizeof (int) * interface_count);
- error_exit:
- return ((void *)instance);
- }
- static void timer_function_passive_token_expired (void *context)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)context;
- struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
- rrp_instance->totemrrp_deliver_fn (
- passive_instance->totemrrp_context,
- passive_instance->token,
- passive_instance->token_len);
- }
- /* TODO
- static void timer_function_passive_problem_decrementer (void *context)
- {
- // struct passive_instance *passive_instance = (struct passive_instance *)context;
- // struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
- }
- */
- static void passive_timer_expired_token_start (
- struct passive_instance *passive_instance)
- {
- poll_timer_add (
- passive_instance->rrp_instance->poll_handle,
- passive_instance->rrp_instance->totem_config->rrp_token_expired_timeout,
- (void *)passive_instance,
- timer_function_passive_token_expired,
- &passive_instance->timer_expired_token);
- }
- static void passive_timer_expired_token_cancel (
- struct passive_instance *passive_instance)
- {
- poll_timer_delete (
- passive_instance->rrp_instance->poll_handle,
- passive_instance->timer_expired_token);
- }
- /*
- static void passive_timer_problem_decrementer_start (
- struct passive_instance *passive_instance)
- {
- poll_timer_add (
- passive_instance->rrp_instance->poll_handle,
- passive_instance->rrp_instance->totem_config->rrp_problem_count_timeout,
- (void *)passive_instance,
- timer_function_passive_problem_decrementer,
- &passive_instance->timer_problem_decrementer);
- }
- static void passive_timer_problem_decrementer_cancel (
- struct passive_instance *passive_instance)
- {
- poll_timer_delete (
- passive_instance->rrp_instance->poll_handle,
- passive_instance->timer_problem_decrementer);
- }
- */
- static void passive_mcast_recv (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
- unsigned int max;
- unsigned int i;
- rrp_instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- if (rrp_instance->totemrrp_msgs_missing() == 0 &&
- passive_instance->timer_expired_token) {
- /*
- * Delivers the last token
- */
- rrp_instance->totemrrp_deliver_fn (
- passive_instance->totemrrp_context,
- passive_instance->token,
- passive_instance->token_len);
- passive_timer_expired_token_cancel (passive_instance);
- }
- /*
- * Monitor for failures
- * TODO doesn't handle wrap-around of the mcast recv count
- */
- passive_instance->mcast_recv_count[iface_no] += 1;
- max = 0;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (max < passive_instance->mcast_recv_count[i]) {
- max = passive_instance->mcast_recv_count[i];
- }
- }
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if ((passive_instance->faulty[i] == 0) &&
- (max - passive_instance->mcast_recv_count[i] >
- rrp_instance->totem_config->rrp_problem_count_threshold)) {
- passive_instance->faulty[i] = 1;
- sprintf (rrp_instance->status[i],
- "Marking ringid %u interface %s FAULTY - adminisrtative intervention required.",
- i,
- totemnet_iface_print (rrp_instance->net_handles[i]));
- log_printf (
- rrp_instance->totemrrp_log_level_error,
- "%s",
- rrp_instance->status[i]);
- }
- }
- }
- static void passive_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
- do {
- passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
- } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
- totemnet_mcast_flush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
- }
- static void passive_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
- do {
- passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
- } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
- totemnet_mcast_noflush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
- }
- static void passive_token_recv (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seq)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
- unsigned int max;
- unsigned int i;
- passive_instance->totemrrp_context = context; // this should be in totemrrp_instance ? TODO
- if (rrp_instance->totemrrp_msgs_missing() == 0) {
- rrp_instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- } else {
- memcpy (passive_instance->token, msg, msg_len);
- passive_timer_expired_token_start (passive_instance);
- }
- /*
- * Monitor for failures
- * TODO doesn't handle wrap-around of the token
- */
- passive_instance->token_recv_count[iface_no] += 1;
- max = 0;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (max < passive_instance->token_recv_count[i]) {
- max = passive_instance->token_recv_count[i];
- }
- }
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if ((passive_instance->faulty[i] == 0) &&
- (max - passive_instance->token_recv_count[i] >
- rrp_instance->totem_config->rrp_problem_count_threshold)) {
- passive_instance->faulty[i] = 1;
- sprintf (rrp_instance->status[i],
- "Marking seqid %d ringid %u interface %s FAULTY - adminisrtative intervention required.",
- token_seq,
- i,
- totemnet_iface_print (rrp_instance->net_handles[i]));
- log_printf (
- rrp_instance->totemrrp_log_level_error,
- "%s",
- rrp_instance->status[i]);
- }
- }
- }
- static void passive_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
- do {
- passive_instance->token_xmit_iface = (passive_instance->token_xmit_iface + 1) % instance->interface_count;
- } while (passive_instance->faulty[passive_instance->token_xmit_iface] == 1);
- totemnet_token_send (
- instance->net_handles[passive_instance->token_xmit_iface],
- msg, msg_len);
- }
- static void passive_recv_flush (struct totemrrp_instance *instance)
- {
- struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_recv_flush (instance->net_handles[i]);
- }
- }
- }
- static void passive_send_flush (struct totemrrp_instance *instance)
- {
- struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_send_flush (instance->net_handles[i]);
- }
- }
- }
- static void passive_iface_check (struct totemrrp_instance *instance)
- {
- struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_iface_check (instance->net_handles[i]);
- }
- }
- }
- static void passive_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count)
- {
- struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_processor_count_set (instance->net_handles[i],
- processor_count);
- }
- }
- }
- static void passive_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no)
- {
- totemnet_token_target_set (instance->net_handles[iface_no], token_target);
- }
- static int passive_mcast_recv_empty (
- struct totemrrp_instance *instance)
- {
- int res;
- int msgs_emptied = 0;
- int i;
- for (i = 0; i < instance->interface_count; i++) {
- res = totemnet_recv_mcast_empty (instance->net_handles[i]);
- if (res == -1) {
- return (-1);
- }
- if (res == 1) {
- msgs_emptied = 1;
- }
- }
- return (msgs_emptied);
- }
- static void passive_ring_reenable (
- struct totemrrp_instance *instance)
- {
- struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
- memset (rrp_algo_instance->mcast_recv_count, 0, sizeof (unsigned int) *
- instance->interface_count);
- memset (rrp_algo_instance->token_recv_count, 0, sizeof (unsigned int) *
- instance->interface_count);
- memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
- instance->interface_count);
- }
- /*
- * Active Replication Implementation
- */
- void *active_instance_initialize (
- struct totemrrp_instance *rrp_instance,
- int interface_count)
- {
- struct active_instance *instance;
- instance = malloc (sizeof (struct active_instance));
- if (instance == 0) {
- goto error_exit;
- }
- memset (instance, 0, sizeof (struct active_instance));
- instance->faulty = malloc (sizeof (int) * interface_count);
- if (instance->faulty == 0) {
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->faulty, 0, sizeof (unsigned int) * interface_count);
- instance->last_token_recv = malloc (sizeof (int) * interface_count);
- if (instance->last_token_recv == 0) {
- free (instance->faulty);
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->last_token_recv, 0, sizeof (unsigned int) * interface_count);
- instance->counter_problems = malloc (sizeof (int) * interface_count);
- if (instance->counter_problems == 0) {
- free (instance->last_token_recv);
- free (instance->faulty);
- free (instance);
- instance = 0;
- goto error_exit;
- }
- memset (instance->counter_problems, 0, sizeof (unsigned int) * interface_count);
- instance->timer_expired_token = 0;
- instance->timer_problem_decrementer = 0;
- instance->rrp_instance = rrp_instance;
- error_exit:
- return ((void *)instance);
- }
- static void timer_function_active_problem_decrementer (void *context)
- {
- struct active_instance *active_instance = (struct active_instance *)context;
- struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
- unsigned int problem_found = 0;
- unsigned int i;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (active_instance->counter_problems[i] > 0) {
- problem_found = 1;
- active_instance->counter_problems[i] -= 1;
- if (active_instance->counter_problems[i] == 0) {
- sprintf (rrp_instance->status[i],
- "ring %d active with no faults", i);
- } else {
- sprintf (rrp_instance->status[i],
- "Decrementing problem counter for iface %s to [%d of %d]",
- totemnet_iface_print (rrp_instance->net_handles[i]),
- active_instance->counter_problems[i],
- rrp_instance->totem_config->rrp_problem_count_threshold);
- }
- log_printf (
- rrp_instance->totemrrp_log_level_warning,
- "%s",
- rrp_instance->status[i]);
- }
- }
- if (problem_found) {
- active_timer_problem_decrementer_start (active_instance);
- } else {
- active_instance->timer_problem_decrementer = 0;
- }
- }
- static void timer_function_active_token_expired (void *context)
- {
- struct active_instance *active_instance = (struct active_instance *)context;
- struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
- unsigned int i;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (active_instance->last_token_recv[i] == 0) {
- active_instance->counter_problems[i] += 1;
- if (active_instance->timer_problem_decrementer == 0) {
- active_timer_problem_decrementer_start (active_instance);
- }
- sprintf (rrp_instance->status[i],
- "Incrementing problem counter for seqid %d iface %s to [%d of %d]",
- active_instance->last_token_seq,
- totemnet_iface_print (rrp_instance->net_handles[i]),
- active_instance->counter_problems[i],
- rrp_instance->totem_config->rrp_problem_count_threshold);
- log_printf (
- rrp_instance->totemrrp_log_level_warning,
- "%s",
- rrp_instance->status[i]);
- }
- }
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (active_instance->counter_problems[i] >= rrp_instance->totem_config->rrp_problem_count_threshold)
- {
- active_instance->faulty[i] = 1;
- sprintf (rrp_instance->status[i],
- "Marking seqid %d ringid %u interface %s FAULTY - adminisrtative intervention required.",
- active_instance->last_token_seq,
- i,
- totemnet_iface_print (rrp_instance->net_handles[i]));
- log_printf (
- rrp_instance->totemrrp_log_level_error,
- "%s",
- rrp_instance->status[i]);
- active_timer_problem_decrementer_cancel (active_instance);
- }
- }
- rrp_instance->totemrrp_deliver_fn (
- active_instance->totemrrp_context,
- active_instance->token,
- active_instance->token_len);
- }
- static void active_timer_expired_token_start (
- struct active_instance *active_instance)
- {
- poll_timer_add (
- active_instance->rrp_instance->poll_handle,
- active_instance->rrp_instance->totem_config->rrp_token_expired_timeout,
- (void *)active_instance,
- timer_function_active_token_expired,
- &active_instance->timer_expired_token);
- }
- static void active_timer_expired_token_cancel (
- struct active_instance *active_instance)
- {
- poll_timer_delete (
- active_instance->rrp_instance->poll_handle,
- active_instance->timer_expired_token);
- }
- static void active_timer_problem_decrementer_start (
- struct active_instance *active_instance)
- {
- poll_timer_add (
- active_instance->rrp_instance->poll_handle,
- active_instance->rrp_instance->totem_config->rrp_problem_count_timeout,
- (void *)active_instance,
- timer_function_active_problem_decrementer,
- &active_instance->timer_problem_decrementer);
- }
- static void active_timer_problem_decrementer_cancel (
- struct active_instance *active_instance)
- {
- poll_timer_delete (
- active_instance->rrp_instance->poll_handle,
- active_instance->timer_problem_decrementer);
- }
- /*
- * active replication
- */
- static void active_mcast_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len)
- {
- instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- }
- static void active_mcast_flush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- int i;
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_mcast_flush_send (instance->net_handles[i], msg, msg_len);
- }
- }
- }
- static void active_mcast_noflush_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- int i;
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_mcast_noflush_send (instance->net_handles[i], msg, msg_len);
- }
- }
- }
- static void active_token_recv (
- struct totemrrp_instance *instance,
- unsigned int iface_no,
- void *context,
- const void *msg,
- unsigned int msg_len,
- unsigned int token_seq)
- {
- int i;
- struct active_instance *active_instance = (struct active_instance *)instance->rrp_algo_instance;
- active_instance->totemrrp_context = context; // this should be in totemrrp_instance ?
- if (token_seq > active_instance->last_token_seq) {
- memcpy (active_instance->token, msg, msg_len);
- active_instance->token_len = msg_len;
- for (i = 0; i < instance->interface_count; i++) {
- active_instance->last_token_recv[i] = 0;
- }
- active_instance->last_token_recv[iface_no] = 1;
- active_timer_expired_token_start (active_instance);
- }
- active_instance->last_token_seq = token_seq;
- if (token_seq == active_instance->last_token_seq) {
- active_instance->last_token_recv[iface_no] = 1;
- for (i = 0; i < instance->interface_count; i++) {
- if ((active_instance->last_token_recv[i] == 0) &&
- active_instance->faulty[i] == 0) {
- return; /* don't deliver token */
- }
- }
- active_timer_expired_token_cancel (active_instance);
- instance->totemrrp_deliver_fn (
- context,
- msg,
- msg_len);
- }
- }
- static void active_token_send (
- struct totemrrp_instance *instance,
- const void *msg,
- unsigned int msg_len)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_token_send (
- instance->net_handles[i],
- msg, msg_len);
- }
- }
- }
- static void active_recv_flush (struct totemrrp_instance *instance)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_recv_flush (instance->net_handles[i]);
- }
- }
- }
- static void active_send_flush (struct totemrrp_instance *instance)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_send_flush (instance->net_handles[i]);
- }
- }
- }
- static void active_iface_check (struct totemrrp_instance *instance)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_iface_check (instance->net_handles[i]);
- }
- }
- }
- static void active_processor_count_set (
- struct totemrrp_instance *instance,
- unsigned int processor_count)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- unsigned int i;
- for (i = 0; i < instance->interface_count; i++) {
- if (rrp_algo_instance->faulty[i] == 0) {
- totemnet_processor_count_set (instance->net_handles[i],
- processor_count);
- }
- }
- }
- static void active_token_target_set (
- struct totemrrp_instance *instance,
- struct totem_ip_address *token_target,
- unsigned int iface_no)
- {
- totemnet_token_target_set (instance->net_handles[iface_no], token_target);
- }
- static int active_mcast_recv_empty (
- struct totemrrp_instance *instance)
- {
- int res;
- int msgs_emptied = 0;
- int i;
- for (i = 0; i < instance->interface_count; i++) {
- res = totemnet_recv_mcast_empty (instance->net_handles[i]);
- if (res == -1) {
- return (-1);
- }
- if (res == 1) {
- msgs_emptied = 1;
- }
- }
- return (msgs_emptied);
- }
- static void active_ring_reenable (
- struct totemrrp_instance *instance)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- memset (rrp_algo_instance->last_token_recv, 0, sizeof (unsigned int) *
- instance->interface_count);
- memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
- instance->interface_count);
- memset (rrp_algo_instance->counter_problems, 0, sizeof (unsigned int) *
- instance->interface_count);
- }
- struct deliver_fn_context {
- struct totemrrp_instance *instance;
- void *context;
- int iface_no;
- };
- static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
- {
- memset (instance, 0, sizeof (struct totemrrp_instance));
- }
- static int totemrrp_algorithm_set (
- struct totem_config *totem_config,
- struct totemrrp_instance *instance)
- {
- unsigned int res = -1;
- unsigned int i;
- for (i = 0; i < RRP_ALGOS_COUNT; i++) {
- if (strcmp (totem_config->rrp_mode, rrp_algos[i]->name) == 0) {
- instance->rrp_algo = rrp_algos[i];
- if (rrp_algos[i]->initialize) {
- instance->rrp_algo_instance = rrp_algos[i]->initialize (
- instance,
- totem_config->interface_count);
- }
- res = 0;
- break;
- }
- }
- for (i = 0; i < totem_config->interface_count; i++) {
- instance->status[i] = malloc (1024);
- sprintf (instance->status[i], "ring %d active with no faults", i);
- }
- return (res);
- }
- void rrp_deliver_fn (
- void *context,
- const void *msg,
- unsigned int msg_len)
- {
- unsigned int token_seqid;
- unsigned int token_is;
- struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
- deliver_fn_context->instance->totemrrp_token_seqid_get (
- msg,
- &token_seqid,
- &token_is);
- if (token_is) {
- /*
- * Deliver to the token receiver for this rrp algorithm
- */
- deliver_fn_context->instance->rrp_algo->token_recv (
- deliver_fn_context->instance,
- deliver_fn_context->iface_no,
- deliver_fn_context->context,
- msg,
- msg_len,
- token_seqid);
- } else {
- /*
- * Deliver to the mcast receiver for this rrp algorithm
- */
- deliver_fn_context->instance->rrp_algo->mcast_recv (
- deliver_fn_context->instance,
- deliver_fn_context->iface_no,
- deliver_fn_context->context,
- msg,
- msg_len);
- }
- }
- void rrp_iface_change_fn (
- void *context,
- const struct totem_ip_address *iface_addr)
- {
- struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
- deliver_fn_context->instance->totemrrp_iface_change_fn (
- deliver_fn_context->context,
- iface_addr,
- deliver_fn_context->iface_no);
- }
- int totemrrp_finalize (
- hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- int i;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- for (i = 0; i < instance->interface_count; i++) {
- totemnet_finalize (instance->net_handles[i]);
- }
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- /*
- * Totem Redundant Ring interface
- * depends on poll abstraction, POSIX, IPV4
- */
- /*
- * Create an instance
- */
- int totemrrp_initialize (
- hdb_handle_t poll_handle,
- hdb_handle_t *handle,
- struct totem_config *totem_config,
- void *context,
- void (*deliver_fn) (
- void *context,
- const void *msg,
- unsigned int msg_len),
- void (*iface_change_fn) (
- void *context,
- const struct totem_ip_address *iface_addr,
- unsigned int iface_no),
- void (*token_seqid_get) (
- const void *msg,
- unsigned int *seqid,
- unsigned int *token_is),
- unsigned int (*msgs_missing) (void))
- {
- struct totemrrp_instance *instance;
- unsigned int res;
- int i;
- res = hdb_handle_create (&totemrrp_instance_database,
- sizeof (struct totemrrp_instance), handle);
- if (res != 0) {
- goto error_exit;
- }
- res = hdb_handle_get (&totemrrp_instance_database, *handle,
- (void *)&instance);
- if (res != 0) {
- goto error_destroy;
- }
- totemrrp_instance_initialize (instance);
- instance->totem_config = totem_config;
- res = totemrrp_algorithm_set (
- instance->totem_config,
- instance);
- if (res == -1) {
- goto error_put;
- }
- /*
- * Configure logging
- */
- instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
- instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
- instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
- instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
- instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
- instance->totemrrp_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
- instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
- instance->interfaces = totem_config->interfaces;
- instance->totemrrp_poll_handle = poll_handle;
- instance->totemrrp_deliver_fn = deliver_fn;
- instance->totemrrp_iface_change_fn = iface_change_fn;
- instance->totemrrp_token_seqid_get = token_seqid_get;
- instance->totemrrp_msgs_missing = msgs_missing;
- instance->interface_count = totem_config->interface_count;
- instance->net_handles = malloc (sizeof (hdb_handle_t) * totem_config->interface_count);
- instance->context = context;
- instance->poll_handle = poll_handle;
- for (i = 0; i < totem_config->interface_count; i++) {
- struct deliver_fn_context *deliver_fn_context;
- deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
- assert (deliver_fn_context);
- deliver_fn_context->instance = instance;
- deliver_fn_context->context = context;
- deliver_fn_context->iface_no = i;
- totemnet_initialize (
- poll_handle,
- &instance->net_handles[i],
- totem_config,
- i,
- (void *)deliver_fn_context,
- rrp_deliver_fn,
- rrp_iface_change_fn);
- }
- totemnet_net_mtu_adjust (totem_config);
- error_exit:
- hdb_handle_put (&totemrrp_instance_database, *handle);
- return (0);
- error_put:
- hdb_handle_put (&totemrrp_instance_database, *handle);
- error_destroy:
- hdb_handle_destroy (&totemrrp_instance_database, *handle);
- return (res);
- }
- int totemrrp_processor_count_set (
- hdb_handle_t handle,
- unsigned int processor_count)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->processor_count_set (instance, processor_count);
- instance->processor_count = processor_count;
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_token_target_set (
- hdb_handle_t handle,
- struct totem_ip_address *addr,
- unsigned int iface_no)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->token_target_set (instance, addr, iface_no);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_recv_flush (hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->recv_flush (instance);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_send_flush (hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->send_flush (instance);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_token_send (
- hdb_handle_t handle,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->token_send (instance, msg, msg_len);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_mcast_flush_send (
- hdb_handle_t handle,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- // TODO this needs to return the result
- instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_mcast_noflush_send (
- hdb_handle_t handle,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- /*
- * merge detects go out through mcast_flush_send so it is safe to
- * flush these messages if we are only one processor. This avoids
- * an encryption/hmac and decryption/hmac
- */
- if (instance->processor_count > 1) {
- // TODO this needs to return the result
- instance->rrp_algo->mcast_noflush_send (instance, msg, msg_len);
- }
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_iface_check (hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->iface_check (instance);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_ifaces_get (
- hdb_handle_t handle,
- char ***status,
- unsigned int *iface_count)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- *status = instance->status;
- if (iface_count) {
- *iface_count = instance->interface_count;
- }
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- int totemrrp_crypto_set (
- hdb_handle_t handle,
- unsigned int type)
- {
- int res;
- struct totemrrp_instance *instance;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- return (0);
- }
- res = totemnet_crypto_set(instance->net_handles[0], type);
- hdb_handle_put (&totemrrp_instance_database, handle);
- return (res);
- }
- int totemrrp_ring_reenable (
- hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res = 0;
- unsigned int i;
- printf ("totemrrp ring reenable\n");
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- instance->rrp_algo->ring_reenable (instance);
- for (i = 0; i < instance->interface_count; i++) {
- sprintf (instance->status[i], "ring %d active with no faults", i);
- }
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
- extern int totemrrp_mcast_recv_empty (
- hdb_handle_t handle)
- {
- struct totemrrp_instance *instance;
- int res;
- res = hdb_handle_get (&totemrrp_instance_database, handle,
- (void *)&instance);
- if (res != 0) {
- res = ENOENT;
- goto error_exit;
- }
- res = instance->rrp_algo->mcast_recv_empty (instance);
- hdb_handle_put (&totemrrp_instance_database, handle);
- error_exit:
- return (res);
- }
|