| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295 |
- /*
- * Copyright (c) 2006-2019 Red Hat, Inc.
- *
- * All rights reserved.
- *
- * Author: Christine Caulfield (ccaulfie@redhat.com)
- * Author: Jan Friesse (jfriesse@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 CONTIBUTORS "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>
- #ifdef HAVE_ALLOCA_H
- #include <alloca.h>
- #endif
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <sys/ioctl.h>
- #include <netinet/in.h>
- #include <sys/uio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <time.h>
- #include <assert.h>
- #include <arpa/inet.h>
- #include <sys/mman.h>
- #include <qb/qbmap.h>
- #include <corosync/corotypes.h>
- #include <qb/qbipc_common.h>
- #include <corosync/corodefs.h>
- #include <corosync/list.h>
- #include <corosync/logsys.h>
- #include <corosync/coroapi.h>
- #include <corosync/cpg.h>
- #include <corosync/ipc_cpg.h>
- #ifndef MAP_ANONYMOUS
- #define MAP_ANONYMOUS MAP_ANON
- #endif
- #include "service.h"
- LOGSYS_DECLARE_SUBSYS ("CPG");
- #define GROUP_HASH_SIZE 32
- enum cpg_message_req_types {
- MESSAGE_REQ_EXEC_CPG_PROCJOIN = 0,
- MESSAGE_REQ_EXEC_CPG_PROCLEAVE = 1,
- MESSAGE_REQ_EXEC_CPG_JOINLIST = 2,
- MESSAGE_REQ_EXEC_CPG_MCAST = 3,
- MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD = 4,
- MESSAGE_REQ_EXEC_CPG_DOWNLIST = 5,
- MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST = 6,
- };
- struct zcb_mapped {
- struct list_head list;
- void *addr;
- size_t size;
- };
- /*
- * state` exec deliver
- * match group name, pid -> if matched deliver for YES:
- * XXX indicates impossible state
- *
- * join leave mcast
- * UNJOINED XXX XXX NO
- * LEAVE_STARTED XXX YES(unjoined_enter) YES
- * JOIN_STARTED YES(join_started_enter) XXX NO
- * JOIN_COMPLETED XXX NO YES
- *
- * join_started_enter
- * set JOIN_COMPLETED
- * add entry to process_info list
- * unjoined_enter
- * set UNJOINED
- * delete entry from process_info list
- *
- *
- * library accept join error codes
- * UNJOINED YES(CS_OK) set JOIN_STARTED
- * LEAVE_STARTED NO(CS_ERR_BUSY)
- * JOIN_STARTED NO(CS_ERR_EXIST)
- * JOIN_COMPlETED NO(CS_ERR_EXIST)
- *
- * library accept leave error codes
- * UNJOINED NO(CS_ERR_NOT_EXIST)
- * LEAVE_STARTED NO(CS_ERR_NOT_EXIST)
- * JOIN_STARTED NO(CS_ERR_BUSY)
- * JOIN_COMPLETED YES(CS_OK) set LEAVE_STARTED
- *
- * library accept mcast
- * UNJOINED NO(CS_ERR_NOT_EXIST)
- * LEAVE_STARTED NO(CS_ERR_NOT_EXIST)
- * JOIN_STARTED YES(CS_OK)
- * JOIN_COMPLETED YES(CS_OK)
- */
- enum cpd_state {
- CPD_STATE_UNJOINED,
- CPD_STATE_LEAVE_STARTED,
- CPD_STATE_JOIN_STARTED,
- CPD_STATE_JOIN_COMPLETED
- };
- enum cpg_sync_state {
- CPGSYNC_DOWNLIST,
- CPGSYNC_JOINLIST
- };
- static struct list_head joinlist_messages_head;
- struct cpg_pd {
- void *conn;
- mar_cpg_name_t group_name;
- uint32_t pid;
- enum cpd_state cpd_state;
- unsigned int flags;
- int initial_totem_conf_sent;
- uint64_t transition_counter; /* These two are used when sending fragmented messages */
- uint64_t initial_transition_counter;
- struct list_head list;
- struct list_head iteration_instance_list_head;
- struct list_head zcb_mapped_list_head;
- };
- struct cpg_iteration_instance {
- hdb_handle_t handle;
- struct list_head list;
- struct list_head items_list_head; /* List of process_info */
- struct list_head *current_pointer;
- };
- DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL);
- DECLARE_LIST_INIT(cpg_pd_list_head);
- static unsigned int my_member_list[PROCESSOR_COUNT_MAX];
- static unsigned int my_member_list_entries;
- static unsigned int my_old_member_list[PROCESSOR_COUNT_MAX];
- static unsigned int my_old_member_list_entries = 0;
- static struct corosync_api_v1 *api = NULL;
- static enum cpg_sync_state my_sync_state = CPGSYNC_DOWNLIST;
- static mar_cpg_ring_id_t last_sync_ring_id;
- struct process_info {
- unsigned int nodeid;
- uint32_t pid;
- mar_cpg_name_t group;
- struct list_head list; /* on the group_info members list */
- };
- DECLARE_LIST_INIT(process_info_list_head);
- struct join_list_entry {
- uint32_t pid;
- mar_cpg_name_t group_name;
- };
- /*
- * Service Interfaces required by service_message_handler struct
- */
- static char *cpg_exec_init_fn (struct corosync_api_v1 *);
- static int cpg_lib_init_fn (void *conn);
- static int cpg_lib_exit_fn (void *conn);
- static void message_handler_req_exec_cpg_procjoin (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_procleave (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_joinlist (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_mcast (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_partial_mcast (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_downlist_old (
- const void *message,
- unsigned int nodeid);
- static void message_handler_req_exec_cpg_downlist (
- const void *message,
- unsigned int nodeid);
- static void exec_cpg_procjoin_endian_convert (void *msg);
- static void exec_cpg_joinlist_endian_convert (void *msg);
- static void exec_cpg_mcast_endian_convert (void *msg);
- static void exec_cpg_partial_mcast_endian_convert (void *msg);
- static void exec_cpg_downlist_endian_convert_old (void *msg);
- static void exec_cpg_downlist_endian_convert (void *msg);
- static void message_handler_req_lib_cpg_join (void *conn, const void *message);
- static void message_handler_req_lib_cpg_leave (void *conn, const void *message);
- static void message_handler_req_lib_cpg_finalize (void *conn, const void *message);
- static void message_handler_req_lib_cpg_mcast (void *conn, const void *message);
- static void message_handler_req_lib_cpg_partial_mcast (void *conn, const void *message);
- static void message_handler_req_lib_cpg_membership (void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_local_get (void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_iteration_initialize (
- void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_iteration_next (
- void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_iteration_finalize (
- void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_zc_alloc (
- void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_zc_free (
- void *conn,
- const void *message);
- static void message_handler_req_lib_cpg_zc_execute (
- void *conn,
- const void *message);
- static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason);
- static int cpg_exec_send_downlist(void);
- static int cpg_exec_send_joinlist(void);
- static void downlist_inform_clients (void);
- static void joinlist_inform_clients (void);
- static void joinlist_messages_delete (void);
- static void cpg_sync_init (
- const unsigned int *trans_list,
- size_t trans_list_entries,
- const unsigned int *member_list,
- size_t member_list_entries,
- const struct memb_ring_id *ring_id);
- static int cpg_sync_process (void);
- static void cpg_sync_activate (void);
- static void cpg_sync_abort (void);
- static void do_proc_join(
- const mar_cpg_name_t *name,
- uint32_t pid,
- unsigned int nodeid,
- int reason);
- static void do_proc_leave(
- const mar_cpg_name_t *name,
- uint32_t pid,
- unsigned int nodeid,
- int reason);
- static int notify_lib_totem_membership (
- void *conn,
- int member_list_entries,
- const unsigned int *member_list);
- static inline int zcb_all_free (
- struct cpg_pd *cpd);
- static char *cpg_print_group_name (
- const mar_cpg_name_t *group);
- /*
- * Library Handler Definition
- */
- static struct corosync_lib_handler cpg_lib_engine[] =
- {
- { /* 0 - MESSAGE_REQ_CPG_JOIN */
- .lib_handler_fn = message_handler_req_lib_cpg_join,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 1 - MESSAGE_REQ_CPG_LEAVE */
- .lib_handler_fn = message_handler_req_lib_cpg_leave,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 2 - MESSAGE_REQ_CPG_MCAST */
- .lib_handler_fn = message_handler_req_lib_cpg_mcast,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 3 - MESSAGE_REQ_CPG_MEMBERSHIP */
- .lib_handler_fn = message_handler_req_lib_cpg_membership,
- .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 4 - MESSAGE_REQ_CPG_LOCAL_GET */
- .lib_handler_fn = message_handler_req_lib_cpg_local_get,
- .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 5 - MESSAGE_REQ_CPG_ITERATIONINITIALIZE */
- .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
- .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 6 - MESSAGE_REQ_CPG_ITERATIONNEXT */
- .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
- .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 7 - MESSAGE_REQ_CPG_ITERATIONFINALIZE */
- .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
- .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
- },
- { /* 8 - MESSAGE_REQ_CPG_FINALIZE */
- .lib_handler_fn = message_handler_req_lib_cpg_finalize,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 9 */
- .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 10 */
- .lib_handler_fn = message_handler_req_lib_cpg_zc_free,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 11 */
- .lib_handler_fn = message_handler_req_lib_cpg_zc_execute,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- { /* 12 */
- .lib_handler_fn = message_handler_req_lib_cpg_partial_mcast,
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
- },
- };
- static struct corosync_exec_handler cpg_exec_engine[] =
- {
- { /* 0 - MESSAGE_REQ_EXEC_CPG_PROCJOIN */
- .exec_handler_fn = message_handler_req_exec_cpg_procjoin,
- .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
- },
- { /* 1 - MESSAGE_REQ_EXEC_CPG_PROCLEAVE */
- .exec_handler_fn = message_handler_req_exec_cpg_procleave,
- .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
- },
- { /* 2 - MESSAGE_REQ_EXEC_CPG_JOINLIST */
- .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
- .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
- },
- { /* 3 - MESSAGE_REQ_EXEC_CPG_MCAST */
- .exec_handler_fn = message_handler_req_exec_cpg_mcast,
- .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
- },
- { /* 4 - MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD */
- .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
- .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
- },
- { /* 5 - MESSAGE_REQ_EXEC_CPG_DOWNLIST */
- .exec_handler_fn = message_handler_req_exec_cpg_downlist,
- .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
- },
- { /* 6 - MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST */
- .exec_handler_fn = message_handler_req_exec_cpg_partial_mcast,
- .exec_endian_convert_fn = exec_cpg_partial_mcast_endian_convert
- },
- };
- struct corosync_service_engine cpg_service_engine = {
- .name = "corosync cluster closed process group service v1.01",
- .id = CPG_SERVICE,
- .priority = 1,
- .private_data_size = sizeof (struct cpg_pd),
- .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED,
- .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
- .lib_init_fn = cpg_lib_init_fn,
- .lib_exit_fn = cpg_lib_exit_fn,
- .lib_engine = cpg_lib_engine,
- .lib_engine_count = sizeof (cpg_lib_engine) / sizeof (struct corosync_lib_handler),
- .exec_init_fn = cpg_exec_init_fn,
- .exec_dump_fn = NULL,
- .exec_engine = cpg_exec_engine,
- .exec_engine_count = sizeof (cpg_exec_engine) / sizeof (struct corosync_exec_handler),
- .sync_init = cpg_sync_init,
- .sync_process = cpg_sync_process,
- .sync_activate = cpg_sync_activate,
- .sync_abort = cpg_sync_abort
- };
- struct corosync_service_engine *cpg_get_service_engine_ver0 (void)
- {
- return (&cpg_service_engine);
- }
- struct req_exec_cpg_procjoin {
- struct qb_ipc_request_header header __attribute__((aligned(8)));
- mar_cpg_name_t group_name __attribute__((aligned(8)));
- mar_uint32_t pid __attribute__((aligned(8)));
- mar_uint32_t reason __attribute__((aligned(8)));
- };
- struct req_exec_cpg_mcast {
- struct qb_ipc_request_header header __attribute__((aligned(8)));
- mar_cpg_name_t group_name __attribute__((aligned(8)));
- mar_uint32_t msglen __attribute__((aligned(8)));
- mar_uint32_t pid __attribute__((aligned(8)));
- mar_message_source_t source __attribute__((aligned(8)));
- mar_uint8_t message[] __attribute__((aligned(8)));
- };
- struct req_exec_cpg_partial_mcast {
- struct qb_ipc_request_header header __attribute__((aligned(8)));
- mar_cpg_name_t group_name __attribute__((aligned(8)));
- mar_uint32_t msglen __attribute__((aligned(8)));
- mar_uint32_t fraglen __attribute__((aligned(8)));
- mar_uint32_t pid __attribute__((aligned(8)));
- mar_uint32_t type __attribute__((aligned(8)));
- mar_message_source_t source __attribute__((aligned(8)));
- mar_uint8_t message[] __attribute__((aligned(8)));
- };
- struct req_exec_cpg_downlist_old {
- struct qb_ipc_request_header header __attribute__((aligned(8)));
- mar_uint32_t left_nodes __attribute__((aligned(8)));
- mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
- };
- struct req_exec_cpg_downlist {
- struct qb_ipc_request_header header __attribute__((aligned(8)));
- /* merge decisions */
- mar_uint32_t old_members __attribute__((aligned(8)));
- /* downlist below */
- mar_uint32_t left_nodes __attribute__((aligned(8)));
- mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)));
- };
- struct joinlist_msg {
- mar_uint32_t sender_nodeid;
- uint32_t pid;
- mar_cpg_name_t group_name;
- struct list_head list;
- };
- static struct req_exec_cpg_downlist g_req_exec_cpg_downlist;
- /*
- * Function print group name. It's not reentrant
- */
- static char *cpg_print_group_name(const mar_cpg_name_t *group)
- {
- static char res[CPG_MAX_NAME_LENGTH * 4 + 1];
- int dest_pos = 0;
- char c;
- int i;
- for (i = 0; i < group->length; i++) {
- c = group->value[i];
- if (c >= ' ' && c < 0x7f && c != '\\') {
- res[dest_pos++] = c;
- } else {
- if (c == '\\') {
- res[dest_pos++] = '\\';
- res[dest_pos++] = '\\';
- } else {
- snprintf(res + dest_pos, sizeof(res) - dest_pos, "\\x%02X", c);
- dest_pos += 4;
- }
- }
- }
- res[dest_pos] = 0;
- return (res);
- }
- static void cpg_sync_init (
- const unsigned int *trans_list,
- size_t trans_list_entries,
- const unsigned int *member_list,
- size_t member_list_entries,
- const struct memb_ring_id *ring_id)
- {
- int entries;
- int i, j;
- int found;
- my_sync_state = CPGSYNC_DOWNLIST;
- memcpy (my_member_list, member_list, member_list_entries *
- sizeof (unsigned int));
- my_member_list_entries = member_list_entries;
- last_sync_ring_id.nodeid = ring_id->rep.nodeid;
- last_sync_ring_id.seq = ring_id->seq;
- entries = 0;
- /*
- * Determine list of nodeids for downlist message
- */
- for (i = 0; i < my_old_member_list_entries; i++) {
- found = 0;
- for (j = 0; j < trans_list_entries; j++) {
- if (my_old_member_list[i] == trans_list[j]) {
- found = 1;
- break;
- }
- }
- if (found == 0) {
- g_req_exec_cpg_downlist.nodeids[entries++] =
- my_old_member_list[i];
- }
- }
- g_req_exec_cpg_downlist.left_nodes = entries;
- }
- static int cpg_sync_process (void)
- {
- int res = -1;
- if (my_sync_state == CPGSYNC_DOWNLIST) {
- res = cpg_exec_send_downlist();
- if (res == -1) {
- return (-1);
- }
- my_sync_state = CPGSYNC_JOINLIST;
- }
- if (my_sync_state == CPGSYNC_JOINLIST) {
- res = cpg_exec_send_joinlist();
- }
- return (res);
- }
- static void cpg_sync_activate (void)
- {
- memcpy (my_old_member_list, my_member_list,
- my_member_list_entries * sizeof (unsigned int));
- my_old_member_list_entries = my_member_list_entries;
- downlist_inform_clients ();
- joinlist_inform_clients ();
- joinlist_messages_delete ();
- notify_lib_totem_membership (NULL, my_member_list_entries, my_member_list);
- }
- static void cpg_sync_abort (void)
- {
- joinlist_messages_delete ();
- }
- static int notify_lib_totem_membership (
- void *conn,
- int member_list_entries,
- const unsigned int *member_list)
- {
- struct list_head *iter;
- char *buf;
- int size;
- struct res_lib_cpg_totem_confchg_callback *res;
- size = sizeof(struct res_lib_cpg_totem_confchg_callback) +
- sizeof(mar_uint32_t) * (member_list_entries);
- buf = alloca(size);
- if (!buf)
- return CS_ERR_LIBRARY;
- res = (struct res_lib_cpg_totem_confchg_callback *)buf;
- res->member_list_entries = member_list_entries;
- res->header.size = size;
- res->header.id = MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK;
- res->header.error = CS_OK;
- memcpy (&res->ring_id, &last_sync_ring_id, sizeof (mar_cpg_ring_id_t));
- memcpy (res->member_list, member_list, res->member_list_entries * sizeof (mar_uint32_t));
- if (conn == NULL) {
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
- struct cpg_pd *cpg_pd = list_entry (iter, struct cpg_pd, list);
- api->ipc_dispatch_send (cpg_pd->conn, buf, size);
- }
- } else {
- api->ipc_dispatch_send (conn, buf, size);
- }
- return CS_OK;
- }
- static int notify_lib_joinlist(
- const mar_cpg_name_t *group_name,
- void *conn,
- int joined_list_entries,
- mar_cpg_address_t *joined_list,
- int left_list_entries,
- mar_cpg_address_t *left_list,
- int id)
- {
- int size;
- char *buf;
- struct list_head *iter;
- int count;
- struct res_lib_cpg_confchg_callback *res;
- mar_cpg_address_t *retgi;
- count = 0;
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- if (mar_name_compare (&pi->group, group_name) == 0) {
- int i;
- int founded = 0;
- for (i = 0; i < left_list_entries; i++) {
- if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
- founded++;
- }
- }
- if (!founded)
- count++;
- }
- }
- size = sizeof(struct res_lib_cpg_confchg_callback) +
- sizeof(mar_cpg_address_t) * (count + left_list_entries + joined_list_entries);
- buf = alloca(size);
- if (!buf)
- return CS_ERR_LIBRARY;
- res = (struct res_lib_cpg_confchg_callback *)buf;
- res->joined_list_entries = joined_list_entries;
- res->left_list_entries = left_list_entries;
- res->member_list_entries = count;
- retgi = res->member_list;
- res->header.size = size;
- res->header.id = id;
- res->header.error = CS_OK;
- memcpy(&res->group_name, group_name, sizeof(mar_cpg_name_t));
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi=list_entry (iter, struct process_info, list);
- if (mar_name_compare (&pi->group, group_name) == 0) {
- int i;
- int founded = 0;
- for (i = 0;i < left_list_entries; i++) {
- if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid) {
- founded++;
- }
- }
- if (!founded) {
- retgi->nodeid = pi->nodeid;
- retgi->pid = pi->pid;
- retgi->reason = CPG_REASON_UNDEFINED;
- retgi++;
- }
- }
- }
- if (left_list_entries) {
- memcpy (retgi, left_list, left_list_entries * sizeof(mar_cpg_address_t));
- retgi += left_list_entries;
- }
- if (joined_list_entries) {
- memcpy (retgi, joined_list, joined_list_entries * sizeof(mar_cpg_address_t));
- retgi += joined_list_entries;
- }
- if (conn) {
- api->ipc_dispatch_send (conn, buf, size);
- } else {
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
- struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
- if (mar_name_compare (&cpd->group_name, group_name) == 0) {
- assert (joined_list_entries <= 1);
- if (joined_list_entries) {
- if (joined_list[0].pid == cpd->pid &&
- joined_list[0].nodeid == api->totem_nodeid_get()) {
- cpd->cpd_state = CPD_STATE_JOIN_COMPLETED;
- }
- }
- if (cpd->cpd_state == CPD_STATE_JOIN_COMPLETED ||
- cpd->cpd_state == CPD_STATE_LEAVE_STARTED) {
- api->ipc_dispatch_send (cpd->conn, buf, size);
- cpd->transition_counter++;
- }
- if (left_list_entries) {
- if (left_list[0].pid == cpd->pid &&
- left_list[0].nodeid == api->totem_nodeid_get() &&
- left_list[0].reason == CONFCHG_CPG_REASON_LEAVE) {
- cpd->pid = 0;
- memset (&cpd->group_name, 0, sizeof(cpd->group_name));
- cpd->cpd_state = CPD_STATE_UNJOINED;
- }
- }
- }
- }
- }
- /*
- * Traverse thru cpds and send totem membership for cpd, where it is not send yet
- */
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
- struct cpg_pd *cpd = list_entry (iter, struct cpg_pd, list);
- if ((cpd->flags & CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF) && (cpd->initial_totem_conf_sent == 0)) {
- cpd->initial_totem_conf_sent = 1;
- notify_lib_totem_membership (cpd->conn, my_old_member_list_entries, my_old_member_list);
- }
- }
- return CS_OK;
- }
- static void downlist_log(const char *msg, struct req_exec_cpg_downlist *dl)
- {
- log_printf (LOG_DEBUG,
- "%s: members(old:%d left:%d)",
- msg,
- dl->old_members,
- dl->left_nodes);
- }
- static void downlist_inform_clients (void)
- {
- struct list_head *iter;
- struct process_info *left_pi;
- qb_map_t *group_map;
- struct cpg_name cpg_group;
- mar_cpg_name_t group;
- struct confchg_data{
- struct cpg_name cpg_group;
- mar_cpg_address_t left_list[CPG_MEMBERS_MAX];
- int left_list_entries;
- struct list_head list;
- } *pcd;
- qb_map_iter_t *miter;
- int i, size;
- downlist_log("my downlist", &g_req_exec_cpg_downlist);
- group_map = qb_skiplist_create();
- /*
- * only the cpg groups included in left nodes should receive
- * confchg event, so we will collect these cpg groups and
- * relative left_lists here.
- */
- for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
- struct process_info *pi = list_entry(iter, struct process_info, list);
- iter = iter->next;
- left_pi = NULL;
- for (i = 0; i < g_req_exec_cpg_downlist.left_nodes; i++) {
- if (pi->nodeid == g_req_exec_cpg_downlist.nodeids[i]) {
- left_pi = pi;
- break;
- }
- }
- if (left_pi) {
- marshall_from_mar_cpg_name_t(&cpg_group, &left_pi->group);
- cpg_group.value[cpg_group.length] = 0;
- pcd = (struct confchg_data *)qb_map_get(group_map, cpg_group.value);
- if (pcd == NULL) {
- pcd = (struct confchg_data *)calloc(1, sizeof(struct confchg_data));
- memcpy(&pcd->cpg_group, &cpg_group, sizeof(struct cpg_name));
- qb_map_put(group_map, pcd->cpg_group.value, pcd);
- }
- size = pcd->left_list_entries;
- pcd->left_list[size].nodeid = left_pi->nodeid;
- pcd->left_list[size].pid = left_pi->pid;
- pcd->left_list[size].reason = CONFCHG_CPG_REASON_NODEDOWN;
- pcd->left_list_entries++;
- list_del (&left_pi->list);
- free (left_pi);
- }
- }
- /* send only one confchg event per cpg group */
- miter = qb_map_iter_create(group_map);
- while (qb_map_iter_next(miter, (void **)&pcd)) {
- marshall_to_mar_cpg_name_t(&group, &pcd->cpg_group);
- log_printf (LOG_DEBUG, "left_list_entries:%d", pcd->left_list_entries);
- for (i=0; i<pcd->left_list_entries; i++) {
- log_printf (LOG_DEBUG, "left_list[%d] group:%s, ip:%s, pid:%d",
- i, cpg_print_group_name(&group),
- (char*)api->totem_ifaces_print(pcd->left_list[i].nodeid),
- pcd->left_list[i].pid);
- }
- /* send confchg event */
- notify_lib_joinlist(&group, NULL,
- 0, NULL,
- pcd->left_list_entries,
- pcd->left_list,
- MESSAGE_RES_CPG_CONFCHG_CALLBACK);
- free(pcd);
- }
- qb_map_iter_free(miter);
- qb_map_destroy(group_map);
- }
- /*
- * Remove processes that might have left the group while we were suspended.
- */
- static void joinlist_remove_zombie_pi_entries (void)
- {
- struct list_head *pi_iter;
- struct list_head *jl_iter;
- struct process_info *pi;
- struct joinlist_msg *stored_msg;
- int found;
- for (pi_iter = process_info_list_head.next; pi_iter != &process_info_list_head; ) {
- pi = list_entry (pi_iter, struct process_info, list);
- pi_iter = pi_iter->next;
- /*
- * Ignore local node
- */
- if (pi->nodeid == api->totem_nodeid_get()) {
- continue ;
- }
- /*
- * Try to find message in joinlist messages
- */
- found = 0;
- for (jl_iter = joinlist_messages_head.next;
- jl_iter != &joinlist_messages_head;
- jl_iter = jl_iter->next) {
- stored_msg = list_entry(jl_iter, struct joinlist_msg, list);
- if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
- continue ;
- }
- if (pi->nodeid == stored_msg->sender_nodeid &&
- pi->pid == stored_msg->pid &&
- mar_name_compare (&pi->group, &stored_msg->group_name) == 0) {
- found = 1;
- break ;
- }
- }
- if (!found) {
- do_proc_leave(&pi->group, pi->pid, pi->nodeid, CONFCHG_CPG_REASON_PROCDOWN);
- }
- }
- }
- static void joinlist_inform_clients (void)
- {
- struct joinlist_msg *stored_msg;
- struct list_head *iter;
- unsigned int i;
- i = 0;
- for (iter = joinlist_messages_head.next;
- iter != &joinlist_messages_head;
- iter = iter->next) {
- stored_msg = list_entry(iter, struct joinlist_msg, list);
- log_printf (LOG_DEBUG, "joinlist_messages[%u] group:%s, ip:%s, pid:%d",
- i++, cpg_print_group_name(&stored_msg->group_name),
- (char*)api->totem_ifaces_print(stored_msg->sender_nodeid),
- stored_msg->pid);
- /* Ignore our own messages */
- if (stored_msg->sender_nodeid == api->totem_nodeid_get()) {
- continue ;
- }
- do_proc_join (&stored_msg->group_name, stored_msg->pid, stored_msg->sender_nodeid,
- CONFCHG_CPG_REASON_NODEUP);
- }
- joinlist_remove_zombie_pi_entries ();
- }
- static void joinlist_messages_delete (void)
- {
- struct joinlist_msg *stored_msg;
- struct list_head *iter, *iter_next;
- for (iter = joinlist_messages_head.next;
- iter != &joinlist_messages_head;
- iter = iter_next) {
- iter_next = iter->next;
- stored_msg = list_entry(iter, struct joinlist_msg, list);
- list_del (&stored_msg->list);
- free (stored_msg);
- }
- list_init (&joinlist_messages_head);
- }
- static char *cpg_exec_init_fn (struct corosync_api_v1 *corosync_api)
- {
- list_init (&joinlist_messages_head);
- api = corosync_api;
- return (NULL);
- }
- static void cpg_iteration_instance_finalize (struct cpg_iteration_instance *cpg_iteration_instance)
- {
- struct list_head *iter, *iter_next;
- struct process_info *pi;
- for (iter = cpg_iteration_instance->items_list_head.next;
- iter != &cpg_iteration_instance->items_list_head;
- iter = iter_next) {
- iter_next = iter->next;
- pi = list_entry (iter, struct process_info, list);
- list_del (&pi->list);
- free (pi);
- }
- list_del (&cpg_iteration_instance->list);
- hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
- }
- static void cpg_pd_finalize (struct cpg_pd *cpd)
- {
- struct list_head *iter, *iter_next;
- struct cpg_iteration_instance *cpii;
- zcb_all_free(cpd);
- for (iter = cpd->iteration_instance_list_head.next;
- iter != &cpd->iteration_instance_list_head;
- iter = iter_next) {
- iter_next = iter->next;
- cpii = list_entry (iter, struct cpg_iteration_instance, list);
- cpg_iteration_instance_finalize (cpii);
- }
- list_del (&cpd->list);
- }
- static int cpg_lib_exit_fn (void *conn)
- {
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p", conn);
- if (cpd->group_name.length > 0 && cpd->cpd_state != CPD_STATE_LEAVE_STARTED) {
- cpg_node_joinleave_send (cpd->pid, &cpd->group_name,
- MESSAGE_REQ_EXEC_CPG_PROCLEAVE, CONFCHG_CPG_REASON_PROCDOWN);
- }
- cpg_pd_finalize (cpd);
- api->ipc_refcnt_dec (conn);
- return (0);
- }
- static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason)
- {
- struct req_exec_cpg_procjoin req_exec_cpg_procjoin;
- struct iovec req_exec_cpg_iovec;
- int result;
- memcpy(&req_exec_cpg_procjoin.group_name, group_name, sizeof(mar_cpg_name_t));
- req_exec_cpg_procjoin.pid = pid;
- req_exec_cpg_procjoin.reason = reason;
- req_exec_cpg_procjoin.header.size = sizeof(req_exec_cpg_procjoin);
- req_exec_cpg_procjoin.header.id = SERVICE_ID_MAKE(CPG_SERVICE, fn);
- req_exec_cpg_iovec.iov_base = (char *)&req_exec_cpg_procjoin;
- req_exec_cpg_iovec.iov_len = sizeof(req_exec_cpg_procjoin);
- result = api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED);
- return (result);
- }
- /* Can byteswap join & leave messages */
- static void exec_cpg_procjoin_endian_convert (void *msg)
- {
- struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = msg;
- req_exec_cpg_procjoin->pid = swab32(req_exec_cpg_procjoin->pid);
- swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
- req_exec_cpg_procjoin->reason = swab32(req_exec_cpg_procjoin->reason);
- }
- static void exec_cpg_joinlist_endian_convert (void *msg_v)
- {
- char *msg = msg_v;
- struct qb_ipc_response_header *res = (struct qb_ipc_response_header *)msg;
- struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(struct qb_ipc_response_header));
- swab_mar_int32_t (&res->size);
- while ((const char*)jle < msg + res->size) {
- jle->pid = swab32(jle->pid);
- swab_mar_cpg_name_t (&jle->group_name);
- jle++;
- }
- }
- static void exec_cpg_downlist_endian_convert_old (void *msg)
- {
- }
- static void exec_cpg_downlist_endian_convert (void *msg)
- {
- struct req_exec_cpg_downlist *req_exec_cpg_downlist = msg;
- unsigned int i;
- req_exec_cpg_downlist->left_nodes = swab32(req_exec_cpg_downlist->left_nodes);
- req_exec_cpg_downlist->old_members = swab32(req_exec_cpg_downlist->old_members);
- for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
- req_exec_cpg_downlist->nodeids[i] = swab32(req_exec_cpg_downlist->nodeids[i]);
- }
- }
- static void exec_cpg_mcast_endian_convert (void *msg)
- {
- struct req_exec_cpg_mcast *req_exec_cpg_mcast = msg;
- swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
- swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
- req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
- req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
- swab_mar_message_source_t (&req_exec_cpg_mcast->source);
- }
- static void exec_cpg_partial_mcast_endian_convert (void *msg)
- {
- struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = msg;
- swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
- swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
- req_exec_cpg_mcast->pid = swab32(req_exec_cpg_mcast->pid);
- req_exec_cpg_mcast->msglen = swab32(req_exec_cpg_mcast->msglen);
- req_exec_cpg_mcast->fraglen = swab32(req_exec_cpg_mcast->fraglen);
- req_exec_cpg_mcast->type = swab32(req_exec_cpg_mcast->type);
- swab_mar_message_source_t (&req_exec_cpg_mcast->source);
- }
- static struct process_info *process_info_find(const mar_cpg_name_t *group_name, uint32_t pid, unsigned int nodeid) {
- struct list_head *iter;
- for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- iter = iter->next;
- if (pi->pid == pid && pi->nodeid == nodeid &&
- mar_name_compare (&pi->group, group_name) == 0) {
- return pi;
- }
- }
- return NULL;
- }
- static void do_proc_join(
- const mar_cpg_name_t *name,
- uint32_t pid,
- unsigned int nodeid,
- int reason)
- {
- struct process_info *pi;
- struct process_info *pi_entry;
- mar_cpg_address_t notify_info;
- struct list_head *list;
- struct list_head *list_to_add = NULL;
- if (process_info_find (name, pid, nodeid) != NULL) {
- return ;
- }
- pi = malloc (sizeof (struct process_info));
- if (!pi) {
- log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
- return;
- }
- pi->nodeid = nodeid;
- pi->pid = pid;
- memcpy(&pi->group, name, sizeof(*name));
- list_init(&pi->list);
- /*
- * Insert new process in sorted order so synchronization works properly
- */
- list_to_add = &process_info_list_head;
- for (list = process_info_list_head.next; list != &process_info_list_head; list = list->next) {
- pi_entry = list_entry(list, struct process_info, list);
- if (pi_entry->nodeid > pi->nodeid ||
- (pi_entry->nodeid == pi->nodeid && pi_entry->pid > pi->pid)) {
- break;
- }
- list_to_add = list;
- }
- list_add (&pi->list, list_to_add);
- notify_info.pid = pi->pid;
- notify_info.nodeid = nodeid;
- notify_info.reason = reason;
- notify_lib_joinlist(&pi->group, NULL,
- 1, ¬ify_info,
- 0, NULL,
- MESSAGE_RES_CPG_CONFCHG_CALLBACK);
- }
- static void do_proc_leave(
- const mar_cpg_name_t *name,
- uint32_t pid,
- unsigned int nodeid,
- int reason)
- {
- struct process_info *pi;
- struct list_head *iter;
- mar_cpg_address_t notify_info;
- notify_info.pid = pid;
- notify_info.nodeid = nodeid;
- notify_info.reason = reason;
- notify_lib_joinlist(name, NULL,
- 0, NULL,
- 1, ¬ify_info,
- MESSAGE_RES_CPG_CONFCHG_CALLBACK);
- for (iter = process_info_list_head.next; iter != &process_info_list_head; ) {
- pi = list_entry(iter, struct process_info, list);
- iter = iter->next;
- if (pi->pid == pid && pi->nodeid == nodeid &&
- mar_name_compare (&pi->group, name)==0) {
- list_del (&pi->list);
- free (pi);
- }
- }
- }
- static void message_handler_req_exec_cpg_downlist_old (
- const void *message,
- unsigned int nodeid)
- {
- log_printf (LOGSYS_LEVEL_WARNING, "downlist OLD from node 0x%x",
- nodeid);
- }
- static void message_handler_req_exec_cpg_downlist(
- const void *message,
- unsigned int nodeid)
- {
- const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
- log_printf (LOGSYS_LEVEL_WARNING, "downlist left_list: %d received",
- req_exec_cpg_downlist->left_nodes);
- }
- static void message_handler_req_exec_cpg_procjoin (
- const void *message,
- unsigned int nodeid)
- {
- const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
- log_printf(LOGSYS_LEVEL_DEBUG, "got procjoin message from cluster node 0x%x (%s) for pid %u",
- nodeid,
- api->totem_ifaces_print(nodeid),
- (unsigned int)req_exec_cpg_procjoin->pid);
- do_proc_join (&req_exec_cpg_procjoin->group_name,
- req_exec_cpg_procjoin->pid, nodeid,
- CONFCHG_CPG_REASON_JOIN);
- }
- static void message_handler_req_exec_cpg_procleave (
- const void *message,
- unsigned int nodeid)
- {
- const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
- log_printf(LOGSYS_LEVEL_DEBUG, "got procleave message from cluster node 0x%x (%s) for pid %u",
- nodeid,
- api->totem_ifaces_print(nodeid),
- (unsigned int)req_exec_cpg_procjoin->pid);
- do_proc_leave (&req_exec_cpg_procjoin->group_name,
- req_exec_cpg_procjoin->pid, nodeid,
- req_exec_cpg_procjoin->reason);
- }
- /* Got a proclist from another node */
- static void message_handler_req_exec_cpg_joinlist (
- const void *message_v,
- unsigned int nodeid)
- {
- const char *message = message_v;
- const struct qb_ipc_response_header *res = (const struct qb_ipc_response_header *)message;
- const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(struct qb_ipc_response_header));
- struct joinlist_msg *stored_msg;
- log_printf(LOGSYS_LEVEL_DEBUG, "got joinlist message from node 0x%x",
- nodeid);
- while ((const char*)jle < message + res->size) {
- stored_msg = malloc (sizeof (struct joinlist_msg));
- memset(stored_msg, 0, sizeof (struct joinlist_msg));
- stored_msg->sender_nodeid = nodeid;
- stored_msg->pid = jle->pid;
- memcpy(&stored_msg->group_name, &jle->group_name, sizeof(mar_cpg_name_t));
- list_init (&stored_msg->list);
- list_add (&stored_msg->list, &joinlist_messages_head);
- jle++;
- }
- }
- static void message_handler_req_exec_cpg_mcast (
- const void *message,
- unsigned int nodeid)
- {
- const struct req_exec_cpg_mcast *req_exec_cpg_mcast = message;
- struct res_lib_cpg_deliver_callback res_lib_cpg_mcast;
- int msglen = req_exec_cpg_mcast->msglen;
- struct list_head *iter, *pi_iter;
- struct cpg_pd *cpd;
- struct iovec iovec[2];
- int known_node = 0;
- res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_DELIVER_CALLBACK;
- res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
- res_lib_cpg_mcast.msglen = msglen;
- res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
- res_lib_cpg_mcast.nodeid = nodeid;
- memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
- sizeof(mar_cpg_name_t));
- iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
- iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
- iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
- iovec[1].iov_len = msglen;
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; ) {
- cpd = list_entry(iter, struct cpg_pd, list);
- iter = iter->next;
- if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
- && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
- if (!known_node) {
- /* Try to find, if we know the node */
- for (pi_iter = process_info_list_head.next;
- pi_iter != &process_info_list_head; pi_iter = pi_iter->next) {
- struct process_info *pi = list_entry (pi_iter, struct process_info, list);
- if (pi->nodeid == nodeid &&
- mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
- known_node = 1;
- break;
- }
- }
- }
- if (!known_node) {
- log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
- return ;
- }
- api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
- }
- }
- }
- static void message_handler_req_exec_cpg_partial_mcast (
- const void *message,
- unsigned int nodeid)
- {
- const struct req_exec_cpg_partial_mcast *req_exec_cpg_mcast = message;
- struct res_lib_cpg_partial_deliver_callback res_lib_cpg_mcast;
- int msglen = req_exec_cpg_mcast->fraglen;
- struct list_head *iter, *pi_iter;
- struct cpg_pd *cpd;
- struct iovec iovec[2];
- int known_node = 0;
- log_printf(LOGSYS_LEVEL_DEBUG, "Got fragmented message from node %d, size = %d bytes\n", nodeid, msglen);
- res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK;
- res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast) + msglen;
- res_lib_cpg_mcast.fraglen = msglen;
- res_lib_cpg_mcast.msglen = req_exec_cpg_mcast->msglen;
- res_lib_cpg_mcast.pid = req_exec_cpg_mcast->pid;
- res_lib_cpg_mcast.type = req_exec_cpg_mcast->type;
- res_lib_cpg_mcast.nodeid = nodeid;
- memcpy(&res_lib_cpg_mcast.group_name, &req_exec_cpg_mcast->group_name,
- sizeof(mar_cpg_name_t));
- iovec[0].iov_base = (void *)&res_lib_cpg_mcast;
- iovec[0].iov_len = sizeof (res_lib_cpg_mcast);
- iovec[1].iov_base = (char*)message+sizeof(*req_exec_cpg_mcast);
- iovec[1].iov_len = msglen;
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; ) {
- cpd = list_entry(iter, struct cpg_pd, list);
- iter = iter->next;
- if ((cpd->cpd_state == CPD_STATE_LEAVE_STARTED || cpd->cpd_state == CPD_STATE_JOIN_COMPLETED)
- && (mar_name_compare (&cpd->group_name, &req_exec_cpg_mcast->group_name) == 0)) {
- if (!known_node) {
- /* Try to find, if we know the node */
- for (pi_iter = process_info_list_head.next;
- pi_iter != &process_info_list_head; pi_iter = pi_iter->next) {
- struct process_info *pi = list_entry (pi_iter, struct process_info, list);
- if (pi->nodeid == nodeid &&
- mar_name_compare (&pi->group, &req_exec_cpg_mcast->group_name) == 0) {
- known_node = 1;
- break;
- }
- }
- }
- if (!known_node) {
- log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message");
- return ;
- }
- api->ipc_dispatch_iov_send (cpd->conn, iovec, 2);
- }
- }
- }
- static int cpg_exec_send_downlist(void)
- {
- struct iovec iov;
- g_req_exec_cpg_downlist.header.id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_DOWNLIST);
- g_req_exec_cpg_downlist.header.size = sizeof(struct req_exec_cpg_downlist);
- g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
- iov.iov_base = (void *)&g_req_exec_cpg_downlist;
- iov.iov_len = g_req_exec_cpg_downlist.header.size;
- return (api->totem_mcast (&iov, 1, TOTEM_AGREED));
- }
- static int cpg_exec_send_joinlist(void)
- {
- int count = 0;
- struct list_head *iter;
- struct qb_ipc_response_header *res;
- char *buf;
- struct join_list_entry *jle;
- struct iovec req_exec_cpg_iovec;
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- if (pi->nodeid == api->totem_nodeid_get ()) {
- count++;
- }
- }
- /* Nothing to send */
- if (!count)
- return 0;
- buf = alloca(sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count);
- if (!buf) {
- log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
- return -1;
- }
- jle = (struct join_list_entry *)(buf + sizeof(struct qb_ipc_response_header));
- res = (struct qb_ipc_response_header *)buf;
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- if (pi->nodeid == api->totem_nodeid_get ()) {
- memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t));
- jle->pid = pi->pid;
- jle++;
- }
- }
- res->id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_JOINLIST);
- res->size = sizeof(struct qb_ipc_response_header)+sizeof(struct join_list_entry) * count;
- req_exec_cpg_iovec.iov_base = buf;
- req_exec_cpg_iovec.iov_len = res->size;
- return (api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED));
- }
- static int cpg_lib_init_fn (void *conn)
- {
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- memset (cpd, 0, sizeof(struct cpg_pd));
- cpd->conn = conn;
- list_add (&cpd->list, &cpg_pd_list_head);
- list_init (&cpd->iteration_instance_list_head);
- list_init (&cpd->zcb_mapped_list_head);
- api->ipc_refcnt_inc (conn);
- log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, cpd=%p", conn, cpd);
- return (0);
- }
- /* Join message from the library */
- static void message_handler_req_lib_cpg_join (void *conn, const void *message)
- {
- const struct req_lib_cpg_join *req_lib_cpg_join = message;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- struct res_lib_cpg_join res_lib_cpg_join;
- cs_error_t error = CS_OK;
- struct list_head *iter;
- /* Test, if we don't have same pid and group name joined */
- for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
- struct cpg_pd *cpd_item = list_entry (iter, struct cpg_pd, list);
- if (cpd_item->pid == req_lib_cpg_join->pid &&
- mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) {
- /* We have same pid and group name joined -> return error */
- error = CS_ERR_EXIST;
- goto response_send;
- }
- }
- /*
- * Same check must be done in process info list, because there may be not yet delivered
- * leave of client.
- */
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- if (pi->nodeid == api->totem_nodeid_get () && pi->pid == req_lib_cpg_join->pid &&
- mar_name_compare(&req_lib_cpg_join->group_name, &pi->group) == 0) {
- /* We have same pid and group name joined -> return error */
- error = CS_ERR_TRY_AGAIN;
- goto response_send;
- }
- }
- if (req_lib_cpg_join->group_name.length > CPG_MAX_NAME_LENGTH) {
- error = CS_ERR_NAME_TOO_LONG;
- goto response_send;
- }
- switch (cpd->cpd_state) {
- case CPD_STATE_UNJOINED:
- error = CS_OK;
- cpd->cpd_state = CPD_STATE_JOIN_STARTED;
- cpd->pid = req_lib_cpg_join->pid;
- cpd->flags = req_lib_cpg_join->flags;
- memcpy (&cpd->group_name, &req_lib_cpg_join->group_name,
- sizeof (cpd->group_name));
- cpg_node_joinleave_send (req_lib_cpg_join->pid,
- &req_lib_cpg_join->group_name,
- MESSAGE_REQ_EXEC_CPG_PROCJOIN, CONFCHG_CPG_REASON_JOIN);
- break;
- case CPD_STATE_LEAVE_STARTED:
- error = CS_ERR_BUSY;
- break;
- case CPD_STATE_JOIN_STARTED:
- error = CS_ERR_EXIST;
- break;
- case CPD_STATE_JOIN_COMPLETED:
- error = CS_ERR_EXIST;
- break;
- }
- response_send:
- res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
- res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
- res_lib_cpg_join.header.error = error;
- api->ipc_response_send (conn, &res_lib_cpg_join, sizeof(res_lib_cpg_join));
- }
- /* Leave message from the library */
- static void message_handler_req_lib_cpg_leave (void *conn, const void *message)
- {
- struct res_lib_cpg_leave res_lib_cpg_leave;
- cs_error_t error = CS_OK;
- struct req_lib_cpg_leave *req_lib_cpg_leave = (struct req_lib_cpg_leave *)message;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- log_printf(LOGSYS_LEVEL_DEBUG, "got leave request on %p", conn);
- switch (cpd->cpd_state) {
- case CPD_STATE_UNJOINED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_LEAVE_STARTED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_JOIN_STARTED:
- error = CS_ERR_BUSY;
- break;
- case CPD_STATE_JOIN_COMPLETED:
- error = CS_OK;
- cpd->cpd_state = CPD_STATE_LEAVE_STARTED;
- cpg_node_joinleave_send (req_lib_cpg_leave->pid,
- &req_lib_cpg_leave->group_name,
- MESSAGE_REQ_EXEC_CPG_PROCLEAVE,
- CONFCHG_CPG_REASON_LEAVE);
- break;
- }
- /* send return */
- res_lib_cpg_leave.header.size = sizeof(res_lib_cpg_leave);
- res_lib_cpg_leave.header.id = MESSAGE_RES_CPG_LEAVE;
- res_lib_cpg_leave.header.error = error;
- api->ipc_response_send(conn, &res_lib_cpg_leave, sizeof(res_lib_cpg_leave));
- }
- /* Finalize message from library */
- static void message_handler_req_lib_cpg_finalize (
- void *conn,
- const void *message)
- {
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- struct res_lib_cpg_finalize res_lib_cpg_finalize;
- cs_error_t error = CS_OK;
- log_printf (LOGSYS_LEVEL_DEBUG, "cpg finalize for conn=%p", conn);
- /*
- * We will just remove cpd from list. After this call, connection will be
- * closed on lib side, and cpg_lib_exit_fn will be called
- */
- list_del (&cpd->list);
- list_init (&cpd->list);
- res_lib_cpg_finalize.header.size = sizeof (res_lib_cpg_finalize);
- res_lib_cpg_finalize.header.id = MESSAGE_RES_CPG_FINALIZE;
- res_lib_cpg_finalize.header.error = error;
- api->ipc_response_send (conn, &res_lib_cpg_finalize,
- sizeof (res_lib_cpg_finalize));
- }
- static int
- memory_map (
- const char *path,
- size_t bytes,
- void **buf)
- {
- int32_t fd;
- void *addr;
- int32_t res;
- fd = open (path, O_RDWR, 0600);
- unlink (path);
- if (fd == -1) {
- return (-1);
- }
- res = ftruncate (fd, bytes);
- if (res == -1) {
- goto error_close_unlink;
- }
- addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, 0);
- if (addr == MAP_FAILED) {
- goto error_close_unlink;
- }
- #ifdef MADV_NOSYNC
- madvise(addr, bytes, MADV_NOSYNC);
- #endif
- res = close (fd);
- if (res) {
- munmap (addr, bytes);
- return (-1);
- }
- *buf = addr;
- return (0);
- error_close_unlink:
- close (fd);
- unlink(path);
- return -1;
- }
- static inline int zcb_alloc (
- struct cpg_pd *cpd,
- const char *path_to_file,
- size_t size,
- void **addr)
- {
- struct zcb_mapped *zcb_mapped;
- unsigned int res;
- zcb_mapped = malloc (sizeof (struct zcb_mapped));
- if (zcb_mapped == NULL) {
- return (-1);
- }
- res = memory_map (
- path_to_file,
- size,
- addr);
- if (res == -1) {
- free (zcb_mapped);
- return (-1);
- }
- list_init (&zcb_mapped->list);
- zcb_mapped->addr = *addr;
- zcb_mapped->size = size;
- list_add_tail (&zcb_mapped->list, &cpd->zcb_mapped_list_head);
- return (0);
- }
- static inline int zcb_free (struct zcb_mapped *zcb_mapped)
- {
- unsigned int res;
- res = munmap (zcb_mapped->addr, zcb_mapped->size);
- list_del (&zcb_mapped->list);
- free (zcb_mapped);
- return (res);
- }
- static inline int zcb_by_addr_free (struct cpg_pd *cpd, void *addr)
- {
- struct list_head *list;
- struct zcb_mapped *zcb_mapped;
- unsigned int res = 0;
- for (list = cpd->zcb_mapped_list_head.next;
- list != &cpd->zcb_mapped_list_head; list = list->next) {
- zcb_mapped = list_entry (list, struct zcb_mapped, list);
- if (zcb_mapped->addr == addr) {
- res = zcb_free (zcb_mapped);
- break;
- }
- }
- return (res);
- }
- static inline int zcb_all_free (
- struct cpg_pd *cpd)
- {
- struct list_head *list;
- struct zcb_mapped *zcb_mapped;
- for (list = cpd->zcb_mapped_list_head.next;
- list != &cpd->zcb_mapped_list_head;) {
- zcb_mapped = list_entry (list, struct zcb_mapped, list);
- list = list->next;
- zcb_free (zcb_mapped);
- }
- return (0);
- }
- union u {
- uint64_t server_addr;
- void *server_ptr;
- };
- static uint64_t void2serveraddr (void *server_ptr)
- {
- union u u;
- u.server_ptr = server_ptr;
- return (u.server_addr);
- }
- static void *serveraddr2void (uint64_t server_addr)
- {
- union u u;
- u.server_addr = server_addr;
- return (u.server_ptr);
- };
- static void message_handler_req_lib_cpg_zc_alloc (
- void *conn,
- const void *message)
- {
- mar_req_coroipcc_zc_alloc_t *hdr = (mar_req_coroipcc_zc_alloc_t *)message;
- struct qb_ipc_response_header res_header;
- void *addr = NULL;
- struct coroipcs_zc_header *zc_header;
- unsigned int res;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- log_printf(LOGSYS_LEVEL_DEBUG, "path: %s", hdr->path_to_file);
- res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size,
- &addr);
- assert(res == 0);
- zc_header = (struct coroipcs_zc_header *)addr;
- zc_header->server_address = void2serveraddr(addr);
- res_header.size = sizeof (struct qb_ipc_response_header);
- res_header.id = 0;
- api->ipc_response_send (conn,
- &res_header,
- res_header.size);
- }
- static void message_handler_req_lib_cpg_zc_free (
- void *conn,
- const void *message)
- {
- mar_req_coroipcc_zc_free_t *hdr = (mar_req_coroipcc_zc_free_t *)message;
- struct qb_ipc_response_header res_header;
- void *addr = NULL;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- log_printf(LOGSYS_LEVEL_DEBUG, " free'ing");
- addr = serveraddr2void (hdr->server_address);
- zcb_by_addr_free (cpd, addr);
- res_header.size = sizeof (struct qb_ipc_response_header);
- res_header.id = 0;
- api->ipc_response_send (
- conn, &res_header,
- res_header.size);
- }
- /* Fragmented mcast message from the library */
- static void message_handler_req_lib_cpg_partial_mcast (void *conn, const void *message)
- {
- const struct req_lib_cpg_partial_mcast *req_lib_cpg_mcast = message;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- mar_cpg_name_t group_name = cpd->group_name;
- struct iovec req_exec_cpg_iovec[2];
- struct req_exec_cpg_partial_mcast req_exec_cpg_mcast;
- struct res_lib_cpg_partial_send res_lib_cpg_partial_send;
- int msglen = req_lib_cpg_mcast->fraglen;
- int result;
- cs_error_t error = CS_ERR_NOT_EXIST;
- log_printf(LOGSYS_LEVEL_TRACE, "got fragmented mcast request on %p", conn);
- log_printf(LOGSYS_LEVEL_DEBUG, "Sending fragmented message size = %d bytes\n", msglen);
- switch (cpd->cpd_state) {
- case CPD_STATE_UNJOINED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_LEAVE_STARTED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_JOIN_STARTED:
- error = CS_OK;
- break;
- case CPD_STATE_JOIN_COMPLETED:
- error = CS_OK;
- break;
- }
- res_lib_cpg_partial_send.header.size = sizeof(res_lib_cpg_partial_send);
- res_lib_cpg_partial_send.header.id = MESSAGE_RES_CPG_PARTIAL_SEND;
- if (req_lib_cpg_mcast->type == LIBCPG_PARTIAL_FIRST) {
- cpd->initial_transition_counter = cpd->transition_counter;
- }
- if (cpd->transition_counter != cpd->initial_transition_counter) {
- error = CS_ERR_INTERRUPT;
- }
- if (error == CS_OK) {
- req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
- req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
- MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST);
- req_exec_cpg_mcast.pid = cpd->pid;
- req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
- req_exec_cpg_mcast.type = req_lib_cpg_mcast->type;
- req_exec_cpg_mcast.fraglen = req_lib_cpg_mcast->fraglen;
- api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
- memcpy(&req_exec_cpg_mcast.group_name, &group_name,
- sizeof(mar_cpg_name_t));
- req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
- req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
- req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
- req_exec_cpg_iovec[1].iov_len = msglen;
- result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
- assert(result == 0);
- } else {
- log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
- conn, group_name.value, cpd->cpd_state, error);
- }
- res_lib_cpg_partial_send.header.error = error;
- api->ipc_response_send (conn, &res_lib_cpg_partial_send,
- sizeof (res_lib_cpg_partial_send));
- }
- /* Mcast message from the library */
- static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
- {
- const struct req_lib_cpg_mcast *req_lib_cpg_mcast = message;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- mar_cpg_name_t group_name = cpd->group_name;
- struct iovec req_exec_cpg_iovec[2];
- struct req_exec_cpg_mcast req_exec_cpg_mcast;
- int msglen = req_lib_cpg_mcast->msglen;
- int result;
- cs_error_t error = CS_ERR_NOT_EXIST;
- log_printf(LOGSYS_LEVEL_TRACE, "got mcast request on %p", conn);
- switch (cpd->cpd_state) {
- case CPD_STATE_UNJOINED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_LEAVE_STARTED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_JOIN_STARTED:
- error = CS_OK;
- break;
- case CPD_STATE_JOIN_COMPLETED:
- error = CS_OK;
- break;
- }
- if (error == CS_OK) {
- req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen;
- req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
- MESSAGE_REQ_EXEC_CPG_MCAST);
- req_exec_cpg_mcast.pid = cpd->pid;
- req_exec_cpg_mcast.msglen = msglen;
- api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
- memcpy(&req_exec_cpg_mcast.group_name, &group_name,
- sizeof(mar_cpg_name_t));
- req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
- req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
- req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
- req_exec_cpg_iovec[1].iov_len = msglen;
- result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
- assert(result == 0);
- } else {
- log_printf(LOGSYS_LEVEL_ERROR, "*** %p can't mcast to group %s state:%d, error:%d",
- conn, group_name.value, cpd->cpd_state, error);
- }
- }
- static void message_handler_req_lib_cpg_zc_execute (
- void *conn,
- const void *message)
- {
- mar_req_coroipcc_zc_execute_t *hdr = (mar_req_coroipcc_zc_execute_t *)message;
- struct qb_ipc_request_header *header;
- struct res_lib_cpg_mcast res_lib_cpg_mcast;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- struct iovec req_exec_cpg_iovec[2];
- struct req_exec_cpg_mcast req_exec_cpg_mcast;
- struct req_lib_cpg_mcast *req_lib_cpg_mcast;
- int result;
- cs_error_t error = CS_ERR_NOT_EXIST;
- log_printf(LOGSYS_LEVEL_TRACE, "got ZC mcast request on %p", conn);
- header = (struct qb_ipc_request_header *)(((char *)serveraddr2void(hdr->server_address) + sizeof (struct coroipcs_zc_header)));
- req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)header;
- switch (cpd->cpd_state) {
- case CPD_STATE_UNJOINED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_LEAVE_STARTED:
- error = CS_ERR_NOT_EXIST;
- break;
- case CPD_STATE_JOIN_STARTED:
- error = CS_OK;
- break;
- case CPD_STATE_JOIN_COMPLETED:
- error = CS_OK;
- break;
- }
- res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast);
- res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST;
- if (error == CS_OK) {
- req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen;
- req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE,
- MESSAGE_REQ_EXEC_CPG_MCAST);
- req_exec_cpg_mcast.pid = cpd->pid;
- req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
- api->ipc_source_set (&req_exec_cpg_mcast.source, conn);
- memcpy(&req_exec_cpg_mcast.group_name, &cpd->group_name,
- sizeof(mar_cpg_name_t));
- req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
- req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
- req_exec_cpg_iovec[1].iov_base = (char *)header + sizeof(struct req_lib_cpg_mcast);
- req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen;
- result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED);
- if (result == 0) {
- res_lib_cpg_mcast.header.error = CS_OK;
- } else {
- res_lib_cpg_mcast.header.error = CS_ERR_TRY_AGAIN;
- }
- } else {
- res_lib_cpg_mcast.header.error = error;
- }
- api->ipc_response_send (conn, &res_lib_cpg_mcast,
- sizeof (res_lib_cpg_mcast));
- }
- static void message_handler_req_lib_cpg_membership (void *conn,
- const void *message)
- {
- struct req_lib_cpg_membership_get *req_lib_cpg_membership_get =
- (struct req_lib_cpg_membership_get *)message;
- struct res_lib_cpg_membership_get res_lib_cpg_membership_get;
- struct list_head *iter;
- int member_count = 0;
- res_lib_cpg_membership_get.header.id = MESSAGE_RES_CPG_MEMBERSHIP;
- res_lib_cpg_membership_get.header.error = CS_OK;
- res_lib_cpg_membership_get.header.size =
- sizeof (struct res_lib_cpg_membership_get);
- for (iter = process_info_list_head.next;
- iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- if (mar_name_compare (&pi->group, &req_lib_cpg_membership_get->group_name) == 0) {
- res_lib_cpg_membership_get.member_list[member_count].nodeid = pi->nodeid;
- res_lib_cpg_membership_get.member_list[member_count].pid = pi->pid;
- member_count += 1;
- }
- }
- res_lib_cpg_membership_get.member_count = member_count;
- api->ipc_response_send (conn, &res_lib_cpg_membership_get,
- sizeof (res_lib_cpg_membership_get));
- }
- static void message_handler_req_lib_cpg_local_get (void *conn,
- const void *message)
- {
- struct res_lib_cpg_local_get res_lib_cpg_local_get;
- res_lib_cpg_local_get.header.size = sizeof (res_lib_cpg_local_get);
- res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET;
- res_lib_cpg_local_get.header.error = CS_OK;
- res_lib_cpg_local_get.local_nodeid = api->totem_nodeid_get ();
- api->ipc_response_send (conn, &res_lib_cpg_local_get,
- sizeof (res_lib_cpg_local_get));
- }
- static void message_handler_req_lib_cpg_iteration_initialize (
- void *conn,
- const void *message)
- {
- const struct req_lib_cpg_iterationinitialize *req_lib_cpg_iterationinitialize = message;
- struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
- hdb_handle_t cpg_iteration_handle = 0;
- struct res_lib_cpg_iterationinitialize res_lib_cpg_iterationinitialize;
- struct list_head *iter, *iter2;
- struct cpg_iteration_instance *cpg_iteration_instance;
- cs_error_t error = CS_OK;
- int res;
- log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration initialize");
- /* Because between calling this function and *next can be some operations which will
- * change list, we must do full copy.
- */
- /*
- * Create new iteration instance
- */
- res = hdb_handle_create (&cpg_iteration_handle_t_db, sizeof (struct cpg_iteration_instance),
- &cpg_iteration_handle);
- if (res != 0) {
- error = CS_ERR_NO_MEMORY;
- goto response_send;
- }
- res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (void *)&cpg_iteration_instance);
- if (res != 0) {
- error = CS_ERR_BAD_HANDLE;
- goto error_destroy;
- }
- list_init (&cpg_iteration_instance->items_list_head);
- cpg_iteration_instance->handle = cpg_iteration_handle;
- /*
- * Create copy of process_info list "grouped by" group name
- */
- for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) {
- struct process_info *pi = list_entry (iter, struct process_info, list);
- struct process_info *new_pi;
- if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
- /*
- * Try to find processed group name in our list new list
- */
- int found = 0;
- for (iter2 = cpg_iteration_instance->items_list_head.next;
- iter2 != &cpg_iteration_instance->items_list_head;
- iter2 = iter2->next) {
- struct process_info *pi2 = list_entry (iter2, struct process_info, list);
- if (mar_name_compare (&pi2->group, &pi->group) == 0) {
- found = 1;
- break;
- }
- }
- if (found) {
- /*
- * We have this name in list -> don't add
- */
- continue ;
- }
- } else if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_ONE_GROUP) {
- /*
- * Test pi group name with request
- */
- if (mar_name_compare (&pi->group, &req_lib_cpg_iterationinitialize->group_name) != 0)
- /*
- * Not same -> don't add
- */
- continue ;
- }
- new_pi = malloc (sizeof (struct process_info));
- if (!new_pi) {
- log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
- error = CS_ERR_NO_MEMORY;
- goto error_put_destroy;
- }
- memcpy (new_pi, pi, sizeof (struct process_info));
- list_init (&new_pi->list);
- if (req_lib_cpg_iterationinitialize->iteration_type == CPG_ITERATION_NAME_ONLY) {
- /*
- * pid and nodeid -> undefined
- */
- new_pi->pid = new_pi->nodeid = 0;
- }
- /*
- * We will return list "grouped" by "group name", so try to find right place to add
- */
- for (iter2 = cpg_iteration_instance->items_list_head.next;
- iter2 != &cpg_iteration_instance->items_list_head;
- iter2 = iter2->next) {
- struct process_info *pi2 = list_entry (iter2, struct process_info, list);
- if (mar_name_compare (&pi2->group, &pi->group) == 0) {
- break;
- }
- }
- list_add (&new_pi->list, iter2);
- }
- /*
- * Now we have a full "grouped by" copy of process_info list
- */
- /*
- * Add instance to current cpd list
- */
- list_init (&cpg_iteration_instance->list);
- list_add (&cpg_iteration_instance->list, &cpd->iteration_instance_list_head);
- cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
- error_put_destroy:
- hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
- error_destroy:
- if (error != CS_OK) {
- hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
- }
- response_send:
- res_lib_cpg_iterationinitialize.header.size = sizeof (res_lib_cpg_iterationinitialize);
- res_lib_cpg_iterationinitialize.header.id = MESSAGE_RES_CPG_ITERATIONINITIALIZE;
- res_lib_cpg_iterationinitialize.header.error = error;
- res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
- api->ipc_response_send (conn, &res_lib_cpg_iterationinitialize,
- sizeof (res_lib_cpg_iterationinitialize));
- }
- static void message_handler_req_lib_cpg_iteration_next (
- void *conn,
- const void *message)
- {
- const struct req_lib_cpg_iterationnext *req_lib_cpg_iterationnext = message;
- struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext;
- struct cpg_iteration_instance *cpg_iteration_instance;
- cs_error_t error = CS_OK;
- int res;
- struct process_info *pi;
- log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration next");
- res = hdb_handle_get (&cpg_iteration_handle_t_db,
- req_lib_cpg_iterationnext->iteration_handle,
- (void *)&cpg_iteration_instance);
- if (res != 0) {
- error = CS_ERR_LIBRARY;
- goto error_exit;
- }
- assert (cpg_iteration_instance);
- cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
- if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
- error = CS_ERR_NO_SECTIONS;
- goto error_put;
- }
- pi = list_entry (cpg_iteration_instance->current_pointer, struct process_info, list);
- /*
- * Copy iteration data
- */
- res_lib_cpg_iterationnext.description.nodeid = pi->nodeid;
- res_lib_cpg_iterationnext.description.pid = pi->pid;
- memcpy (&res_lib_cpg_iterationnext.description.group,
- &pi->group,
- sizeof (mar_cpg_name_t));
- error_put:
- hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
- error_exit:
- res_lib_cpg_iterationnext.header.size = sizeof (res_lib_cpg_iterationnext);
- res_lib_cpg_iterationnext.header.id = MESSAGE_RES_CPG_ITERATIONNEXT;
- res_lib_cpg_iterationnext.header.error = error;
- api->ipc_response_send (conn, &res_lib_cpg_iterationnext,
- sizeof (res_lib_cpg_iterationnext));
- }
- static void message_handler_req_lib_cpg_iteration_finalize (
- void *conn,
- const void *message)
- {
- const struct req_lib_cpg_iterationfinalize *req_lib_cpg_iterationfinalize = message;
- struct res_lib_cpg_iterationfinalize res_lib_cpg_iterationfinalize;
- struct cpg_iteration_instance *cpg_iteration_instance;
- cs_error_t error = CS_OK;
- int res;
- log_printf (LOGSYS_LEVEL_DEBUG, "cpg iteration finalize");
- res = hdb_handle_get (&cpg_iteration_handle_t_db,
- req_lib_cpg_iterationfinalize->iteration_handle,
- (void *)&cpg_iteration_instance);
- if (res != 0) {
- error = CS_ERR_LIBRARY;
- goto error_exit;
- }
- assert (cpg_iteration_instance);
- cpg_iteration_instance_finalize (cpg_iteration_instance);
- hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
- error_exit:
- res_lib_cpg_iterationfinalize.header.size = sizeof (res_lib_cpg_iterationfinalize);
- res_lib_cpg_iterationfinalize.header.id = MESSAGE_RES_CPG_ITERATIONFINALIZE;
- res_lib_cpg_iterationfinalize.header.error = error;
- api->ipc_response_send (conn, &res_lib_cpg_iterationfinalize,
- sizeof (res_lib_cpg_iterationfinalize));
- }
|