| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251 |
- /*
- * 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,
- unsigned int iface_no);
- int (*mcast_recv_empty) (
- struct totemrrp_instance *instance);
- int (*member_add) (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- int (*member_remove) (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- void (*membership_changed) (
- struct totemrrp_instance *instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id);
- };
- struct totemrrp_instance {
- hdb_handle_t 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);
- void (*totemrrp_target_set_completed) (
- void *context);
- 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)));
- void **net_handles;
- void *rrp_algo_instance;
- int interface_count;
- int processor_count;
- int my_nodeid;
- struct totem_config *totem_config;
- void *deliver_fn_context[INTERFACE_MAX];
- poll_timer_handle timer_active_test_ring_timeout[INTERFACE_MAX];
- };
- /*
- * 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,
- unsigned int iface_no);
- static int none_mcast_recv_empty (
- struct totemrrp_instance *instance);
- static int none_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static int none_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static void none_membership_changed (
- struct totemrrp_instance *instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id);
- /*
- * 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_monitor (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- int is_token_recv_count);
- 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,
- unsigned int iface_no);
- static int passive_mcast_recv_empty (
- struct totemrrp_instance *instance);
- static int passive_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static int passive_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static void passive_membership_changed (
- struct totemrrp_instance *instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id);
- /*
- * 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,
- unsigned int iface_no);
- static int active_mcast_recv_empty (
- struct totemrrp_instance *instance);
- static int active_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static int active_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no);
- static void active_membership_changed (
- struct totemrrp_instance *instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id);
- 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);
- /*
- * 0-5 reserved for totemsrp.c
- */
- #define MESSAGE_TYPE_RING_TEST_ACTIVE 6
- #define MESSAGE_TYPE_RING_TEST_ACTIVATE 7
- #define ENDIAN_LOCAL 0xff22
- /*
- * Rollover handling:
- *
- * ARR_SEQNO_START_TOKEN is the starting sequence number of last seen sequence
- * for a token for active redundand ring. This should remain zero, unless testing
- * overflow in which case 07fffff00 or 0xffffff00 are good starting values.
- * It should be same as on defined in totemsrp.c
- */
- #define ARR_SEQNO_START_TOKEN 0x0
- /*
- * These can be used ot test different rollover points
- * #define ARR_SEQNO_START_MSG 0xfffffe00
- */
- /*
- * Threshold value when recv_count for passive rrp should be adjusted.
- * Set this value to some smaller for testing of adjusting proper
- * functionality. Also keep in mind that this value must be smaller
- * than rrp_problem_count_threshold
- */
- #define PASSIVE_RECV_COUNT_THRESHOLD (INT_MAX / 2)
- struct message_header {
- char type;
- char encapsulated;
- unsigned short endian_detector;
- int ring_number;
- int nodeid_activator;
- } __attribute__((packed));
- struct deliver_fn_context {
- struct totemrrp_instance *instance;
- void *context;
- int iface_no;
- };
- 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,
- .member_add = none_member_add,
- .member_remove = none_member_remove,
- .membership_changed = none_membership_changed
- };
- 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,
- .member_add = passive_member_add,
- .member_remove = passive_member_remove,
- .membership_changed = passive_membership_changed
- };
- 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,
- .member_add = active_member_add,
- .member_remove = active_member_remove,
- .membership_changed = active_membership_changed
- };
- struct rrp_algo *rrp_algos[] = {
- &none_algo,
- &passive_algo,
- &active_algo
- };
- #define RRP_ALGOS_COUNT 3
- #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);
- static void test_active_msg_endian_convert(const struct message_header *in, struct message_header *out)
- {
- out->type = in->type;
- out->encapsulated = in->encapsulated;
- out->endian_detector = ENDIAN_LOCAL;
- out->ring_number = swab32 (in->ring_number);
- out->nodeid_activator = swab32(in->nodeid_activator);
- }
- static void timer_function_test_ring_timeout (void *context)
- {
- struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
- struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
- unsigned int *faulty = NULL;
- int iface_no = deliver_fn_context->iface_no;
- struct message_header msg = {
- .type = MESSAGE_TYPE_RING_TEST_ACTIVE,
- .endian_detector = ENDIAN_LOCAL,
- };
- if (strcmp(rrp_instance->totem_config->rrp_mode, "active") == 0)
- faulty = ((struct active_instance *)(rrp_instance->rrp_algo_instance))->faulty;
- if (strcmp(rrp_instance->totem_config->rrp_mode, "passive") == 0)
- faulty = ((struct passive_instance *)(rrp_instance->rrp_algo_instance))->faulty;
- assert (faulty != NULL);
- if (faulty[iface_no] == 1) {
- msg.ring_number = iface_no;
- msg.nodeid_activator = rrp_instance->my_nodeid;
- totemnet_token_send (
- rrp_instance->net_handles[iface_no],
- &msg, sizeof (struct message_header));
- poll_timer_add (rrp_instance->poll_handle,
- rrp_instance->totem_config->rrp_autorecovery_check_timeout,
- (void *)deliver_fn_context,
- timer_function_test_ring_timeout,
- &rrp_instance->timer_active_test_ring_timeout[iface_no]);
- }
- }
- /*
- * 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,
- unsigned int iface_no)
- {
- /*
- * 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);
- }
- static int none_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_add (instance->net_handles[0], member);
- return (res);
- }
- static int none_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_remove (instance->net_handles[0], member);
- return (res);
- }
- static void none_membership_changed (
- struct totemrrp_instance *rrp_instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id)
- {
- int i;
- for (i = 0; i < left_list_entries; i++) {
- if (left_list[i].addr[0].family != AF_INET && left_list[i].addr[0].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership left list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[0],
- &left_list[i].addr[0], 0);
- }
- }
- for (i = 0; i < joined_list_entries; i++) {
- if (joined_list[i].addr[0].family != AF_INET && joined_list[i].addr[0].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership join list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[0],
- &joined_list[i].addr[0], 1);
- }
- }
- }
- /*
- * 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);
- }
- */
- /*
- * Monitor function implementation from rrp paper.
- * rrp_instance is passive rrp instance, iface_no is interface with received messgae/token and
- * is_token_recv_count is boolean variable which donates if message is token (>1) or regular
- * message (= 0)
- */
- static void passive_monitor (
- struct totemrrp_instance *rrp_instance,
- unsigned int iface_no,
- int is_token_recv_count)
- {
- struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
- unsigned int *recv_count;
- unsigned int max;
- unsigned int i;
- unsigned int min_all, min_active;
- unsigned int threshold;
- /*
- * Monitor for failures
- */
- if (is_token_recv_count) {
- recv_count = passive_instance->token_recv_count;
- threshold = rrp_instance->totem_config->rrp_problem_count_threshold;
- } else {
- recv_count = passive_instance->mcast_recv_count;
- threshold = rrp_instance->totem_config->rrp_problem_count_mcast_threshold;
- }
- recv_count[iface_no] += 1;
- max = 0;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (max < recv_count[i]) {
- max = recv_count[i];
- }
- }
- /*
- * Max is larger than threshold -> start adjusting process
- */
- if (max > PASSIVE_RECV_COUNT_THRESHOLD) {
- min_all = min_active = recv_count[iface_no];
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (recv_count[i] < min_all) {
- min_all = recv_count[i];
- }
- if (passive_instance->faulty[i] == 0 &&
- recv_count[i] < min_active) {
- min_active = recv_count[i];
- }
- }
- if (min_all > 0) {
- /*
- * There is one or more faulty device with recv_count > 0
- */
- for (i = 0; i < rrp_instance->interface_count; i++) {
- recv_count[i] -= min_all;
- }
- } else {
- /*
- * No faulty device with recv_count > 0, adjust only active
- * devices
- */
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (passive_instance->faulty[i] == 0) {
- recv_count[i] -= min_active;
- }
- }
- }
- /*
- * Find again max
- */
- max = 0;
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if (max < recv_count[i]) {
- max = recv_count[i];
- }
- }
- }
- for (i = 0; i < rrp_instance->interface_count; i++) {
- if ((passive_instance->faulty[i] == 0) &&
- (max - recv_count[i] > threshold)) {
- passive_instance->faulty[i] = 1;
- poll_timer_add (rrp_instance->poll_handle,
- rrp_instance->totem_config->rrp_autorecovery_check_timeout,
- rrp_instance->deliver_fn_context[i],
- timer_function_test_ring_timeout,
- &rrp_instance->timer_active_test_ring_timeout[i]);
- sprintf (rrp_instance->status[i],
- "Marking ringid %u interface %s FAULTY",
- 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_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;
- 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);
- }
- passive_monitor (rrp_instance, iface_no, 0);
- }
- 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;
- int i = 0;
- do {
- passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
- i++;
- } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1));
- if (i <= instance->interface_count) {
- 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;
- int i = 0;
- do {
- passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
- i++;
- } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1));
- if (i <= instance->interface_count) {
- 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;
- 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);
- }
- passive_monitor (rrp_instance, iface_no, 1);
- }
- 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;
- int i = 0;
- do {
- passive_instance->token_xmit_iface = (passive_instance->token_xmit_iface + 1) % instance->interface_count;
- i++;
- } while ((i <= instance->interface_count) && (passive_instance->faulty[passive_instance->token_xmit_iface] == 1));
- if (i <= instance->interface_count) {
- 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 int passive_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_add (instance->net_handles[iface_no], member);
- return (res);
- }
- static int passive_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_remove (instance->net_handles[iface_no], member);
- return (res);
- }
- static void passive_membership_changed (
- struct totemrrp_instance *rrp_instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id)
- {
- int i;
- int interface;
- for (interface = 0; interface < rrp_instance->interface_count; interface++) {
- for (i = 0; i < left_list_entries; i++) {
- if (left_list[i].addr[interface].family != AF_INET &&
- left_list[i].addr[interface].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership left list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[interface],
- &left_list[i].addr[interface], 0);
- }
- }
- for (i = 0; i < joined_list_entries; i++) {
- if (joined_list[i].addr[interface].family != AF_INET &&
- joined_list[i].addr[interface].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership join list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[interface],
- &joined_list[i].addr[interface], 1);
- }
- }
- }
- }
- static void passive_ring_reenable (
- struct totemrrp_instance *instance,
- unsigned int iface_no)
- {
- 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);
- if (iface_no == instance->interface_count) {
- memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
- instance->interface_count);
- } else {
- rrp_algo_instance->faulty[iface_no] = 0;
- }
- }
- /*
- * 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;
- instance->last_token_seq = ARR_SEQNO_START_TOKEN - 1;
- 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;
- poll_timer_add (rrp_instance->poll_handle,
- rrp_instance->totem_config->rrp_autorecovery_check_timeout,
- rrp_instance->deliver_fn_context[i],
- timer_function_test_ring_timeout,
- &rrp_instance->timer_active_test_ring_timeout[i]);
- sprintf (rrp_instance->status[i],
- "Marking seqid %d ringid %u interface %s FAULTY",
- 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 *rrp_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 *)rrp_instance->rrp_algo_instance;
- active_instance->totemrrp_context = context;
- if (sq_lt_compare (active_instance->last_token_seq, token_seq)) {
- memcpy (active_instance->token, msg, msg_len);
- active_instance->token_len = msg_len;
- for (i = 0; i < rrp_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);
- }
- /*
- * This doesn't follow spec because the spec assumes we will know
- * when token resets occur.
- */
- 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 < rrp_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);
- rrp_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 int active_member_add (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_add (instance->net_handles[iface_no], member);
- return (res);
- }
- static int active_member_remove (
- struct totemrrp_instance *instance,
- const struct totem_ip_address *member,
- unsigned int iface_no)
- {
- int res;
- res = totemnet_member_remove (instance->net_handles[iface_no], member);
- return (res);
- }
- static void active_membership_changed (
- struct totemrrp_instance *rrp_instance,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id)
- {
- int i;
- int interface;
- for (interface = 0; interface < rrp_instance->interface_count; interface++) {
- for (i = 0; i < left_list_entries; i++) {
- if (left_list[i].addr[interface].family != AF_INET &&
- left_list[i].addr[interface].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership left list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[interface],
- &left_list[i].addr[interface], 0);
- }
- }
- for (i = 0; i < joined_list_entries; i++) {
- if (joined_list[i].addr[interface].family != AF_INET &&
- joined_list[i].addr[interface].family != AF_INET6) {
- log_printf(rrp_instance->totemrrp_log_level_error,
- "Membership join list contains incorrect address. "
- "This is sign of misconfiguration between nodes!");
- } else {
- totemnet_member_set_active(rrp_instance->net_handles[interface],
- &joined_list[i].addr[interface], 1);
- }
- }
- }
- }
- 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,
- unsigned int iface_no)
- {
- struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
- if (iface_no == instance->interface_count) {
- 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);
- } else {
- rrp_algo_instance->last_token_recv[iface_no] = 0;
- rrp_algo_instance->faulty[iface_no] = 0;
- rrp_algo_instance->counter_problems[iface_no] = 0;
- }
- }
- 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;
- struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
- const struct message_header *hdr = msg;
- struct message_header tmp_msg, activate_msg;
- memset(&tmp_msg, 0, sizeof(struct message_header));
- memset(&activate_msg, 0, sizeof(struct message_header));
- rrp_instance->totemrrp_token_seqid_get (
- msg,
- &token_seqid,
- &token_is);
- if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVE) {
- log_printf (
- rrp_instance->totemrrp_log_level_debug,
- "received message requesting test of ring now active\n");
- if (hdr->endian_detector != ENDIAN_LOCAL) {
- test_active_msg_endian_convert(hdr, &tmp_msg);
- hdr = &tmp_msg;
- }
- if (hdr->nodeid_activator == rrp_instance->my_nodeid) {
- /*
- * Send an activate message
- */
- activate_msg.type = MESSAGE_TYPE_RING_TEST_ACTIVATE;
- activate_msg.endian_detector = ENDIAN_LOCAL;
- activate_msg.ring_number = hdr->ring_number;
- activate_msg.nodeid_activator = rrp_instance->my_nodeid;
- totemnet_token_send (
- rrp_instance->net_handles[deliver_fn_context->iface_no],
- &activate_msg, sizeof (struct message_header));
- } else {
- /*
- * Send a ring test message
- */
- totemnet_token_send (
- rrp_instance->net_handles[deliver_fn_context->iface_no],
- msg, msg_len);
- }
- } else
- if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVATE) {
- log_printf (
- rrp_instance->totemrrp_log_level_notice,
- "Automatically recovered ring %d\n", hdr->ring_number);
- if (hdr->endian_detector != ENDIAN_LOCAL) {
- test_active_msg_endian_convert(hdr, &tmp_msg);
- hdr = &tmp_msg;
- }
- totemrrp_ring_reenable (rrp_instance, deliver_fn_context->iface_no);
- if (hdr->nodeid_activator != rrp_instance->my_nodeid) {
- totemnet_token_send (
- rrp_instance->net_handles[deliver_fn_context->iface_no],
- msg, msg_len);
- }
- } else
- if (token_is) {
- /*
- * Deliver to the token receiver for this rrp algorithm
- */
- rrp_instance->rrp_algo->token_recv (
- rrp_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
- */
- rrp_instance->rrp_algo->mcast_recv (
- rrp_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->my_nodeid = iface_addr->nodeid;
- deliver_fn_context->instance->totemrrp_iface_change_fn (
- deliver_fn_context->context,
- iface_addr,
- deliver_fn_context->iface_no);
- }
- int totemrrp_finalize (
- void *rrp_context)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int i;
- for (i = 0; i < instance->interface_count; i++) {
- totemnet_finalize (instance->net_handles[i]);
- }
- return (0);
- }
- static void rrp_target_set_completed (void *context)
- {
- struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
- deliver_fn_context->instance->totemrrp_target_set_completed (deliver_fn_context->context);
- }
- /*
- * Totem Redundant Ring interface
- * depends on poll abstraction, POSIX, IPV4
- */
- /*
- * Create an instance
- */
- int totemrrp_initialize (
- hdb_handle_t poll_handle,
- void **rrp_context,
- struct totem_config *totem_config,
- totemsrp_stats_t *stats,
- 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),
- void (*target_set_completed) (void *context))
- {
- struct totemrrp_instance *instance;
- unsigned int res;
- int i;
- instance = malloc (sizeof (struct totemrrp_instance));
- if (instance == 0) {
- return (-1);
- }
- totemrrp_instance_initialize (instance);
- instance->totem_config = totem_config;
- res = totemrrp_algorithm_set (
- instance->totem_config,
- instance);
- if (res == -1) {
- goto error_destroy;
- }
- /*
- * 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->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_target_set_completed = target_set_completed;
- instance->totemrrp_msgs_missing = msgs_missing;
- instance->interface_count = totem_config->interface_count;
- instance->net_handles = malloc (sizeof (void *) * 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;
- instance->deliver_fn_context[i] = (void *)deliver_fn_context;
- totemnet_initialize (
- poll_handle,
- &instance->net_handles[i],
- totem_config,
- stats,
- i,
- (void *)deliver_fn_context,
- rrp_deliver_fn,
- rrp_iface_change_fn,
- rrp_target_set_completed);
- totemnet_net_mtu_adjust (instance->net_handles[i], totem_config);
- }
- *rrp_context = instance;
- return (0);
- error_destroy:
- free (instance);
- return (res);
- }
- int totemrrp_processor_count_set (
- void *rrp_context,
- unsigned int processor_count)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->processor_count_set (instance, processor_count);
- instance->processor_count = processor_count;
- return (0);
- }
- int totemrrp_token_target_set (
- void *rrp_context,
- struct totem_ip_address *addr,
- unsigned int iface_no)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->token_target_set (instance, addr, iface_no);
- return (0);
- }
- int totemrrp_recv_flush (void *rrp_context)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->recv_flush (instance);
- return (0);
- }
- int totemrrp_send_flush (void *rrp_context)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->send_flush (instance);
- return (0);
- }
- int totemrrp_token_send (
- void *rrp_context,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->token_send (instance, msg, msg_len);
- return (0);
- }
- int totemrrp_mcast_flush_send (
- void *rrp_context,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res = 0;
- // TODO this needs to return the result
- instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
- return (res);
- }
- int totemrrp_mcast_noflush_send (
- void *rrp_context,
- const void *msg,
- unsigned int msg_len)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- /*
- * 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);
- }
- return (0);
- }
- int totemrrp_iface_check (void *rrp_context)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->iface_check (instance);
- return (0);
- }
- int totemrrp_ifaces_get (
- void *rrp_context,
- char ***status,
- unsigned int *iface_count)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- *status = instance->status;
- if (iface_count) {
- *iface_count = instance->interface_count;
- }
- return (0);
- }
- int totemrrp_crypto_set (
- void *rrp_context,
- unsigned int type)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res;
- res = totemnet_crypto_set(instance->net_handles[0], type);
- return (res);
- }
- /*
- * iface_no indicates the interface number [0, ..., interface_count-1] of the
- * specific ring which will be reenabled. We specify iface_no == interface_count
- * means reenabling all the rings.
- */
- int totemrrp_ring_reenable (
- void *rrp_context,
- unsigned int iface_no)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res = 0;
- unsigned int i;
- instance->rrp_algo->ring_reenable (instance, iface_no);
- if (iface_no == instance->interface_count) {
- for (i = 0; i < instance->interface_count; i++) {
- sprintf (instance->status[i], "ring %d active with no faults", i);
- }
- } else {
- sprintf (instance->status[iface_no], "ring %d active with no faults", iface_no);
- }
- return (res);
- }
- extern int totemrrp_mcast_recv_empty (
- void *rrp_context)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res;
- res = instance->rrp_algo->mcast_recv_empty (instance);
- return (res);
- }
- int totemrrp_member_add (
- void *rrp_context,
- const struct totem_ip_address *member,
- int iface_no)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res;
- res = instance->rrp_algo->member_add (instance, member, iface_no);
- return (res);
- }
- int totemrrp_member_remove (
- void *rrp_context,
- const struct totem_ip_address *member,
- int iface_no)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- int res;
- res = instance->rrp_algo->member_remove (instance, member, iface_no);
- return (res);
- }
- void totemrrp_membership_changed (
- void *rrp_context,
- enum totem_configuration_type configuration_type,
- const struct srp_addr *member_list, size_t member_list_entries,
- const struct srp_addr *left_list, size_t left_list_entries,
- const struct srp_addr *joined_list, size_t joined_list_entries,
- const struct memb_ring_id *ring_id)
- {
- struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
- instance->rrp_algo->membership_changed (instance,
- configuration_type,
- member_list, member_list_entries,
- left_list, left_list_entries,
- joined_list, joined_list_entries,
- ring_id);
- }
|