From 4a33ba11fa44035d661cb0baea9388b4171dc1b6 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Sat, 18 Mar 2006 21:00:19 +0000 Subject: [PATCH] defect 1139 merge object database and do a general refactor of the code git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@952 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/Makefile | 31 +- exec/amf.c | 14 +- exec/cfg.c | 14 +- exec/ckpt.c | 13 +- exec/clm.c | 18 +- exec/cpg.c | 14 +- exec/evs.c | 14 +- exec/evt.c | 13 +- exec/lck.c | 13 +- exec/main.c | 216 +++++-------- exec/main.h | 1 - exec/mainconfig.c | 36 +-- exec/mainconfig.h | 7 +- exec/msg.c | 13 +- exec/objdb.c | 537 +++++++++++++++++++++++++++++++++ exec/objdb.h | 105 +++++++ exec/print.c | 5 +- exec/print.h | 1 + exec/{handlers.h => service.h} | 34 ++- exec/util.c | 10 + exec/util.h | 18 ++ exec/ykd.c | 2 +- 22 files changed, 868 insertions(+), 261 deletions(-) create mode 100644 exec/objdb.c create mode 100644 exec/objdb.h rename exec/{handlers.h => service.h} (81%) diff --git a/exec/Makefile b/exec/Makefile index 4c8d823a..6dc21fa1 100644 --- a/exec/Makefile +++ b/exec/Makefile @@ -58,9 +58,10 @@ SERV_OBJS = evs.o clm.o amf.o ckpt.o evt.o lck.o msg.o cfg.o cpg.o # main executive objects MAIN_SRC = main.c print.c mempool.c \ - util.c sync.c ykd.c mainconfig.c amfconfig.c + util.c sync.c ykd.c mainconfig.c amfconfig.c service.c MAIN_OBJS = main.o print.o mempool.o \ - util.o sync.o ykd.o mainconfig.o amfconfig.o ../lcr/lcr_ifact.o + util.o sync.o ykd.o mainconfig.o amfconfig.o service.o ../lcr/lcr_ifact.o +OTHER_OBJS = objdb.o ifeq (${BUILD_DYNAMIC}, 1) EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) @@ -71,9 +72,9 @@ all:libtotem_pg.a libtotem_pg.so.1.0 ../lcr/lcr_ifact.o \ service_evs.lcrso service_clm.lcrso service_amf.lcrso \ service_ckpt.lcrso service_evt.lcrso service_lck.lcrso \ service_msg.lcrso service_cfg.lcrso service_cpg.lcrso \ - keygen openais-instantiate + objdb.lcrso keygen openais-instantiate else -EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) $(SERV_OBJS) +EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) $(OTHER_OBJS) $(SERV_OBJS) all: libtotem_pg.a aisexec keygen openais-instantiate endif @@ -107,6 +108,8 @@ service_cfg.lcrso: cfg.o service_cpg.lcrso: cpg.o $(CC) -bundle -bundle_loader ./aisexec -bind_at_load cpg.o -o $@ +objdb.lcrso: objdb.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_looad objdb.o -o $@ else service_evs.lcrso: evs.o @@ -136,10 +139,14 @@ service_cfg.lcrso: cfg.o service_cpg.lcrso: cpg.o $(CC) -shared -Wl,-soname,service_cpg.lcrso cpg.o -o $@ +objdb.lcrso: objdb.o + $(CC) -shared -Wl,-soname,objdb.lcrso objdb.o -o $@ + +aisexec: $(EXEC_OBJS) libtotem_pg.a + endif -aisexec: $(EXEC_OBJS) libtotem_pg.a $(CC) $(LDFLAGS) $(EXEC_OBJS) $(EXEC_LIBS) -o aisexec libtotem_pg.a: $(TOTEM_OBJS) @@ -206,6 +213,8 @@ cfg.o: cfg.c cpg.o: cpg.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(*F).c +objdb.o: objdb.c + $(CC) $(CFLAGS) -c -o $@ $(*F).c # -fPIC rules required for lib totem aispoll.o: aispoll.c @@ -246,33 +255,33 @@ totemconfig.o: totemconfig.c main.o: ../include/saAis.h ../include/ipc_evs.h ../include/saAis.h main.o: ../include/saClm.h ../include/ipc_gen.h ../include/list.h main.o: ../include/queue.h totempg.h aispoll.h totemsrp.h mempool.h amfconfig.h -main.o: main.h ../include/saClm.h handlers.h +main.o: main.h ../include/saClm.h service.h main.o: ../include/saEvt.h swab.h print.h clm.o: ../include/saAis.h ../include/saClm.h ../include/saAis.h clm.o: ../include/ipc_evs.h ../include/saClm.h ../include/ipc_gen.h clm.o: ../include/ipc_clm.h ../include/list.h ../include/queue.h aispoll.h -clm.o: totempg.h totemsrp.h amfconfig.h main.h handlers.h +clm.o: totempg.h totemsrp.h amfconfig.h main.h service.h clm.o: ../include/saEvt.h mempool.h print.h amf.o: ../include/saAis.h ../include/ipc_evs.h ../include/saAis.h amf.o: ../include/saClm.h ../include/ipc_gen.h ../include/list.h amf.o: ../include/queue.h totempg.h aispoll.h totemsrp.h mempool.h util.h -amf.o: amfconfig.h main.h ../include/saClm.h handlers.h +amf.o: amfconfig.h main.h ../include/saClm.h service.h amf.o: ../include/saEvt.h print.h ckpt.o: ../include/saAis.h ../include/ipc_evs.h ../include/saAis.h ckpt.o: ../include/saClm.h ../include/ipc_gen.h ../include/list.h ckpt.o: ../include/queue.h aispoll.h mempool.h util.h amfconfig.h totempg.h -ckpt.o: totemsrp.h main.h ../include/saClm.h handlers.h +ckpt.o: totemsrp.h main.h ../include/saClm.h service.h ckpt.o: ../include/saEvt.h print.h evt.o: ../include/ipc_evt.h ../include/saAis.h ../include/saEvt.h evt.o: ../include/saClm.h ../include/ipc_gen.h ../include/list.h evt.o: ../include/queue.h util.h ../include/saAis.h aispoll.h mempool.h evt.o: amfconfig.h totempg.h totemsrp.h main.h ../include/saClm.h -evt.o: ../include/ipc_evs.h handlers.h +evt.o: ../include/ipc_evs.h service.h evt.o: ../include/saEvt.h swab.h print.h evs.o: ../include/saAis.h ../include/ipc_evs.h ../include/saAis.h evs.o: ../include/saClm.h ../include/ipc_gen.h ../include/list.h evs.o: ../include/queue.h aispoll.h totempg.h totemsrp.h amfconfig.h main.h -evs.o: ../include/saClm.h handlers.h +evs.o: ../include/saClm.h service.h evs.o: ../include/saEvt.h mempool.h print.h amfconfig.o: ../include/saAis.h ../include/list.h util.h amfconfig.h aispoll.h amfconfig.o: totempg.h totemsrp.h mempool.h print.h ../include/saClm.h diff --git a/exec/amf.c b/exec/amf.c index 32bc1855..b29f5efa 100644 --- a/exec/amf.c +++ b/exec/amf.c @@ -63,7 +63,7 @@ int waiting = 0; #include "util.h" #include "amfconfig.h" #include "main.h" -#include "handlers.h" +#include "service.h" #define LOG_SERVICE LOG_SERVICE_AMF #include "print.h" @@ -280,7 +280,7 @@ struct clc_interface *clc_interfaces[4] = { /* * Service Handler Definition */ -static struct openais_lib_handler amf_lib_handlers[] = +static struct openais_lib_handler amf_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_amf_componentregister, @@ -368,7 +368,7 @@ static struct openais_lib_handler amf_lib_handlers[] = }, }; -static struct openais_exec_handler amf_exec_handlers[] = { +static struct openais_exec_handler amf_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_amf_operational_state_comp_set, }, @@ -396,11 +396,11 @@ struct openais_service_handler amf_service_handler = { .private_data_size = sizeof (struct amf_pd), .lib_init_fn = amf_lib_init_fn, .lib_exit_fn = amf_lib_exit_fn, - .lib_handlers = amf_lib_handlers, - .lib_handlers_count = sizeof (amf_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = amf_lib_service, + .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = amf_exec_init_fn, - .exec_handlers = amf_exec_handlers, - .exec_handlers_count = sizeof (amf_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = amf_exec_service, + .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = amf_confchg_fn, }; diff --git a/exec/cfg.c b/exec/cfg.c index a90a52de..3238252f 100644 --- a/exec/cfg.c +++ b/exec/cfg.c @@ -52,11 +52,11 @@ #include "../include/list.h" #include "../include/queue.h" #include "../lcr/lcr_comp.h" +#include "service.h" #include "totempg.h" #include "aispoll.h" #include "mempool.h" #include "util.h" -#include "handlers.h" #define LOG_SERVICE LOG_SERVICE_AMF #include "print.h" @@ -88,7 +88,7 @@ static void message_handler_req_lib_cfg_administrativestateget (void *conn, void /* * Service Handler Definition */ -static struct openais_lib_handler cfg_lib_handlers[] = +static struct openais_lib_handler cfg_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_cfg_statetrackstart, @@ -116,7 +116,7 @@ static struct openais_lib_handler cfg_lib_handlers[] = } }; -static struct openais_exec_handler cfg_exec_handlers[] = +static struct openais_exec_handler cfg_exec_service[] = { { } @@ -137,11 +137,11 @@ struct openais_service_handler cfg_service_handler = { .private_data_size = 0, .lib_init_fn = cfg_lib_init_fn, .lib_exit_fn = cfg_lib_exit_fn, - .lib_handlers = cfg_lib_handlers, - .lib_handlers_count = sizeof (cfg_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = cfg_lib_service, + .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = cfg_exec_init_fn, - .exec_handlers = cfg_exec_handlers, - .exec_handlers_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */ + .exec_service = cfg_exec_service, + .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */ .confchg_fn = cfg_confchg_fn, }; diff --git a/exec/ckpt.c b/exec/ckpt.c index 479df7bd..856c36cc 100644 --- a/exec/ckpt.c +++ b/exec/ckpt.c @@ -53,6 +53,7 @@ #include "../include/hdb.h" #include "../lcr/lcr_comp.h" #include "aispoll.h" +#include "service.h" #include "mempool.h" #include "util.h" #include "main.h" @@ -326,7 +327,7 @@ static void ckpt_confchg_fn( /* * Executive Handler Definition */ -static struct openais_lib_handler ckpt_lib_handlers[] = +static struct openais_lib_handler ckpt_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_ckpt_checkpointopen, @@ -439,7 +440,7 @@ static struct openais_lib_handler ckpt_lib_handlers[] = }; -static struct openais_exec_handler ckpt_exec_handlers[] = { +static struct openais_exec_handler ckpt_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_ckpt_checkpointopen, }, @@ -487,12 +488,12 @@ struct openais_service_handler ckpt_service_handler = { .private_data_size = sizeof (struct ckpt_pd), .lib_init_fn = ckpt_lib_init_fn, .lib_exit_fn = ckpt_lib_exit_fn, - .lib_handlers = ckpt_lib_handlers, - .lib_handlers_count = sizeof (ckpt_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = ckpt_lib_service, + .lib_service_count = sizeof (ckpt_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = ckpt_exec_init_fn, .exec_dump_fn = 0, - .exec_handlers = ckpt_exec_handlers, - .exec_handlers_count = sizeof (ckpt_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = ckpt_exec_service, + .exec_service_count = sizeof (ckpt_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = ckpt_confchg_fn, .sync_init = ckpt_recovery_initialize, .sync_process = ckpt_recovery_process, diff --git a/exec/clm.c b/exec/clm.c index 7dcac2af..c6989973 100644 --- a/exec/clm.c +++ b/exec/clm.c @@ -67,7 +67,7 @@ #include "totempg.h" #include "main.h" #include "mempool.h" -#include "handlers.h" +#include "service.h" #define LOG_SERVICE LOG_SERVICE_CLM #include "print.h" @@ -157,7 +157,7 @@ struct clm_pd { /* * Executive Handler Definition */ -static struct openais_lib_handler clm_lib_handlers[] = +static struct openais_lib_handler clm_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_clm_clustertrack, @@ -185,7 +185,7 @@ static struct openais_lib_handler clm_lib_handlers[] = } }; -static struct openais_exec_handler clm_exec_handlers[] = +static struct openais_exec_handler clm_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_clm_nodejoin, @@ -199,12 +199,12 @@ struct openais_service_handler clm_service_handler = { .private_data_size = sizeof (struct clm_pd), .lib_init_fn = clm_lib_init_fn, .lib_exit_fn = clm_lib_exit_fn, - .lib_handlers = clm_lib_handlers, - .lib_handlers_count = sizeof (clm_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = clm_lib_service, + .lib_service_count = sizeof (clm_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = clm_exec_init_fn, .exec_dump_fn = NULL, - .exec_handlers = clm_exec_handlers, - .exec_handlers_count = sizeof (clm_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = clm_exec_service, + .exec_service_count = sizeof (clm_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = clm_confchg_fn, .sync_init = clm_sync_init, .sync_process = clm_sync_process, @@ -215,7 +215,7 @@ struct openais_service_handler clm_service_handler = { /* * Dynamic loader definition */ -struct openais_service_handler *clm_get_service_handler_ver0 (void); +static struct openais_service_handler *clm_get_service_handler_ver0 (void); struct openais_service_handler_iface_ver0 clm_service_handler_iface = { .openais_get_service_handler_ver0 = clm_get_service_handler_ver0 @@ -240,7 +240,7 @@ struct lcr_comp clm_comp_ver0 = { .ifaces = openais_clm_ver0 }; -struct openais_service_handler *clm_get_service_handler_ver0 (void) +static struct openais_service_handler *clm_get_service_handler_ver0 (void) { return (&clm_service_handler); } diff --git a/exec/cpg.c b/exec/cpg.c index b10a67ba..2fdaceea 100644 --- a/exec/cpg.c +++ b/exec/cpg.c @@ -62,7 +62,7 @@ #include "totemip.h" #include "main.h" #include "mempool.h" -#include "handlers.h" +#include "service.h" #include "jhash.h" #include "swab.h" @@ -169,7 +169,7 @@ static void cpg_exec_send_joinlist(void); /* * Library Handler Definition */ -static struct openais_lib_handler cpg_lib_handlers[] = +static struct openais_lib_handler cpg_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_cpg_join, @@ -209,7 +209,7 @@ static struct openais_lib_handler cpg_lib_handlers[] = } }; -static struct openais_exec_handler cpg_exec_handlers[] = +static struct openais_exec_handler cpg_exec_service[] = { { /* 0 */ .exec_handler_fn = message_handler_req_exec_cpg_procjoin, @@ -235,12 +235,12 @@ struct openais_service_handler cpg_service_handler = { .private_data_size = sizeof (struct process_info), .lib_init_fn = cpg_lib_init_fn, .lib_exit_fn = cpg_lib_exit_fn, - .lib_handlers = cpg_lib_handlers, - .lib_handlers_count = sizeof (cpg_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = cpg_lib_service, + .lib_service_count = sizeof (cpg_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = cpg_exec_init_fn, .exec_dump_fn = NULL, - .exec_handlers = cpg_exec_handlers, - .exec_handlers_count = sizeof (cpg_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = cpg_exec_service, + .exec_service_count = sizeof (cpg_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = cpg_confchg_fn, }; diff --git a/exec/evs.c b/exec/evs.c index c77f6bf5..95e605bd 100644 --- a/exec/evs.c +++ b/exec/evs.c @@ -60,7 +60,7 @@ #include "totemip.h" #include "main.h" #include "mempool.h" -#include "handlers.h" +#include "service.h" #define LOG_SERVICE LOG_SERVICE_EVS #include "print.h" @@ -99,7 +99,7 @@ struct evs_pd { void *conn; }; -static struct openais_lib_handler evs_lib_handlers[] = +static struct openais_lib_handler evs_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_evs_join, @@ -133,7 +133,7 @@ static struct openais_lib_handler evs_lib_handlers[] = } }; -static struct openais_exec_handler evs_exec_handlers[] = +static struct openais_exec_handler evs_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_mcast, @@ -147,10 +147,10 @@ struct openais_service_handler evs_service_handler = { .private_data_size = sizeof (struct evs_pd), .lib_init_fn = evs_lib_init_fn, .lib_exit_fn = evs_lib_exit_fn, - .lib_handlers = evs_lib_handlers, - .lib_handlers_count = sizeof (evs_lib_handlers) / sizeof (struct openais_lib_handler), - .exec_handlers = evs_exec_handlers, - .exec_handlers_count = sizeof (evs_exec_handlers) / sizeof (struct openais_exec_handler), + .lib_service = evs_lib_service, + .lib_service_count = sizeof (evs_lib_service) / sizeof (struct openais_lib_handler), + .exec_service = evs_exec_service, + .exec_service_count = sizeof (evs_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = evs_confchg_fn, .exec_init_fn = NULL, .exec_dump_fn = NULL diff --git a/exec/evt.c b/exec/evt.c index 076fb1c9..e4d288a4 100644 --- a/exec/evt.c +++ b/exec/evt.c @@ -54,6 +54,7 @@ #include "../include/queue.h" #include "../lcr/lcr_comp.h" #include "util.h" +#include "service.h" #include "aispoll.h" #include "mempool.h" #include "main.h" @@ -131,7 +132,7 @@ static void evt_sync_abort(void); static void convert_event(void *msg); static void convert_chan_packet(void *msg); -static struct openais_lib_handler evt_lib_handlers[] = { +static struct openais_lib_handler evt_lib_service[] = { { .lib_handler_fn = lib_evt_open_channel, .response_size = sizeof(struct res_evt_channel_open), @@ -193,7 +194,7 @@ static void evt_remote_evt(void *msg, struct totem_ip_address *source_addr); static void evt_remote_recovery_evt(void *msg, struct totem_ip_address *source_addr); static void evt_remote_chan_op(void *msg, struct totem_ip_address *source_addr); -static struct openais_exec_handler evt_exec_handlers[] = { +static struct openais_exec_handler evt_exec_service[] = { { .exec_handler_fn = evt_remote_evt, .exec_endian_convert_fn = convert_event @@ -215,11 +216,11 @@ struct openais_service_handler evt_service_handler = { .private_data_size = sizeof (struct libevt_pd), .lib_init_fn = evt_lib_init, .lib_exit_fn = evt_lib_exit, - .lib_handlers = evt_lib_handlers, - .lib_handlers_count = sizeof(evt_lib_handlers) / sizeof(struct openais_lib_handler), + .lib_service = evt_lib_service, + .lib_service_count = sizeof(evt_lib_service) / sizeof(struct openais_lib_handler), .exec_init_fn = evt_exec_init, - .exec_handlers = evt_exec_handlers, - .exec_handlers_count = sizeof(evt_exec_handlers) / sizeof(struct openais_exec_handler), + .exec_service = evt_exec_service, + .exec_service_count = sizeof(evt_exec_service) / sizeof(struct openais_exec_handler), .exec_dump_fn = NULL, .confchg_fn = evt_conf_change, .sync_init = evt_sync_init, diff --git a/exec/lck.c b/exec/lck.c index 16d0ff18..74dbb87d 100644 --- a/exec/lck.c +++ b/exec/lck.c @@ -45,6 +45,7 @@ #include #include +#include "service.h" #include "../include/saAis.h" #include "../include/saLck.h" #include "../include/ipc_lck.h" @@ -205,7 +206,7 @@ struct lck_pd { /* * Executive Handler Definition */ -static struct openais_lib_handler lck_lib_handlers[] = +static struct openais_lib_handler lck_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_lck_resourceopen, @@ -258,7 +259,7 @@ static struct openais_lib_handler lck_lib_handlers[] = }; -static struct openais_exec_handler lck_exec_handlers[] = { +static struct openais_exec_handler lck_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_lck_resourceopen, }, @@ -285,11 +286,11 @@ struct openais_service_handler lck_service_handler = { .private_data_size = sizeof (struct lck_pd), .lib_init_fn = lck_lib_init_fn, .lib_exit_fn = lck_lib_exit_fn, - .lib_handlers = lck_lib_handlers, - .lib_handlers_count = sizeof (lck_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = lck_lib_service, + .lib_service_count = sizeof (lck_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = lck_exec_init_fn, - .exec_handlers = lck_exec_handlers, - .exec_handlers_count = sizeof (lck_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = lck_exec_service, + .exec_service_count = sizeof (lck_exec_service) / sizeof (struct openais_exec_handler), .exec_dump_fn = NULL, .confchg_fn = lck_confchg_fn, .sync_init = NULL, diff --git a/exec/main.c b/exec/main.c index fffa4ef8..24b20d0e 100644 --- a/exec/main.c +++ b/exec/main.c @@ -68,22 +68,22 @@ #include "amfconfig.h" #include "totemconfig.h" #include "main.h" -#include "handlers.h" +#include "service.h" #include "sync.h" #include "ykd.h" #include "swab.h" - +#include "objdb.h" #define LOG_SERVICE LOG_SERVICE_MAIN #include "print.h" +#include "util.h" + #define SERVER_BACKLOG 5 int ais_uid = 0; int gid_valid = 0; -static struct openais_service_handler *ais_service_handlers[32]; - -static unsigned int service_handlers_count = 32; +static unsigned int service_count = 32; struct outq_item { void *msg; @@ -120,37 +120,15 @@ static int dispatch_init_send_response (struct conn_info *conn_info, void *messa static int response_init_send_response (struct conn_info *conn_info, void *message); -static int (*ais_init_handlers[]) (struct conn_info *conn_info, void *message) = { +static int (*ais_init_service[]) (struct conn_info *conn_info, void *message) = { response_init_send_response, dispatch_init_send_response }; static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, void *data, unsigned int *prio); -enum e_ais_done { - AIS_DONE_EXIT = -1, - AIS_DONE_UID_DETERMINE = -2, - AIS_DONE_GID_DETERMINE = -3, - AIS_DONE_MEMPOOL_INIT = -4, - AIS_DONE_FORK = -5, - AIS_DONE_LIBAIS_SOCKET = -6, - AIS_DONE_LIBAIS_BIND = -7, - AIS_DONE_READKEY = -8, - AIS_DONE_MAINCONFIGREAD = -9, - AIS_DONE_LOGSETUP = -10, - AIS_DONE_AMFCONFIGREAD = -11, - AIS_DONE_DYNAMICLOAD = -12, -}; - extern int openais_amf_config_read (char **error_string); -static inline void ais_done (enum e_ais_done err) -{ - log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting.\n"); - poll_destroy (aisexec_poll_handle); - exit (1); -} - static inline struct conn_info *conn_info_create (int fd) { struct conn_info *conn_info; int res; @@ -186,8 +164,8 @@ static void sigusr2_handler (int num) int i; for (i = 0; i < AIS_SERVICE_HANDLERS_COUNT; i++) { - if (ais_service_handlers[i]->exec_dump_fn) { - ais_service_handlers[i]->exec_dump_fn (); + if (ais_service[i]->exec_dump_fn) { + ais_service[i]->exec_dump_fn (); } } @@ -237,9 +215,9 @@ static int libais_disconnect (struct conn_info *conn_info) struct outq_item *outq_item; if (conn_info->should_exit_fn && - ais_service_handlers[conn_info->service]->lib_exit_fn) { + ais_service[conn_info->service]->lib_exit_fn) { - res = ais_service_handlers[conn_info->service]->lib_exit_fn (conn_info); + res = ais_service[conn_info->service]->lib_exit_fn (conn_info); } /* @@ -247,9 +225,9 @@ static int libais_disconnect (struct conn_info *conn_info) */ if (conn_info->conn_info_partner && conn_info->conn_info_partner->should_exit_fn && - ais_service_handlers[conn_info->conn_info_partner->service]->lib_exit_fn) { + ais_service[conn_info->conn_info_partner->service]->lib_exit_fn) { - res = ais_service_handlers[conn_info->conn_info_partner->service]->lib_exit_fn (conn_info->conn_info_partner); + res = ais_service[conn_info->conn_info_partner->service]->lib_exit_fn (conn_info->conn_info_partner); if (conn_info->private_data) { free (conn_info->private_data); } @@ -577,7 +555,7 @@ static int dispatch_init_send_response (struct conn_info *conn_info, void *messa if (conn_info->authenticated) { conn_info->service = req_lib_dispatch_init->resdis_header.service; - if (!ais_service_handlers[req_lib_dispatch_init->resdis_header.service]) + if (!ais_service[req_lib_dispatch_init->resdis_header.service]) error = SA_AIS_ERR_NOT_SUPPORTED; else error = SA_AIS_OK; @@ -590,7 +568,7 @@ static int dispatch_init_send_response (struct conn_info *conn_info, void *messa if (error == SA_AIS_OK) { int private_data_size; - private_data_size = ais_service_handlers[req_lib_dispatch_init->resdis_header.service]->private_data_size; + private_data_size = ais_service[req_lib_dispatch_init->resdis_header.service]->private_data_size; if (private_data_size) { conn_info->private_data = malloc (private_data_size); @@ -622,7 +600,7 @@ static int dispatch_init_send_response (struct conn_info *conn_info, void *messa } conn_info->should_exit_fn = 1; - ais_service_handlers[req_lib_dispatch_init->resdis_header.service]->lib_init_fn (conn_info); + ais_service[req_lib_dispatch_init->resdis_header.service]->lib_init_fn (conn_info); return (0); } @@ -796,18 +774,18 @@ retry_recv: /* * If this service is in init phase, initialize service - * else handle message using service handlers + * else handle message using service service */ if (service == SOCKET_SERVICE_INIT) { - res = ais_init_handlers[header->id] (conn_info, header); + res = ais_init_service[header->id] (conn_info, header); // TODO error in init_two_fn needs to be handled } else { /* * Not an init service, but a standard service */ - if (header->id < 0 || header->id > ais_service_handlers[service]->lib_handlers_count) { + if (header->id < 0 || header->id > ais_service[service]->lib_service_count) { log_printf (LOG_LEVEL_SECURITY, "Invalid header id is %d min 0 max %d\n", - header->id, ais_service_handlers[service]->lib_handlers_count); + header->id, ais_service[service]->lib_service_count); res = -1; goto error_disconnect; } @@ -825,14 +803,14 @@ retry_recv: send_ok = (ykd_primary() == 1) && ( - (ais_service_handlers[service]->lib_handlers[header->id].flow_control == OPENAIS_FLOW_CONTROL_NOT_REQUIRED) || - ((ais_service_handlers[service]->lib_handlers[header->id].flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) && + (ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_NOT_REQUIRED) || + ((ais_service[service]->lib_service[header->id].flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) && (send_ok_joined) && (sync_in_process() == 0))); if (send_ok) { // *prio = 0; - ais_service_handlers[service]->lib_handlers[header->id].lib_handler_fn(conn_info, header); + ais_service[service]->lib_service[header->id].lib_handler_fn(conn_info, header); } else { // *prio = (*prio) + 1; @@ -840,9 +818,9 @@ retry_recv: * Overload, tell library to retry */ res_overlay.header.size = - ais_service_handlers[service]->lib_handlers[header->id].response_size; + ais_service[service]->lib_service[header->id].response_size; res_overlay.header.id = - ais_service_handlers[service]->lib_handlers[header->id].response_id; + ais_service[service]->lib_service[header->id].response_id; res_overlay.header.error = SA_AIS_ERR_TRY_AGAIN; openais_conn_send_response ( conn_info, @@ -892,7 +870,7 @@ void sigintr_handler (int signum) #endif totempg_finalize (); - ais_done (AIS_DONE_EXIT); + openais_exit_error (AIS_DONE_EXIT); } @@ -907,15 +885,15 @@ static void openais_sync_completed (void) static int openais_sync_callbacks_retrieve (int sync_id, struct sync_callbacks *callbacks) { - if (ais_service_handlers[sync_id] == NULL) { + if (ais_service[sync_id] == NULL) { memset (callbacks, 0, sizeof (struct sync_callbacks)); return (-1); } - callbacks->name = ais_service_handlers[sync_id]->name; - callbacks->sync_init = ais_service_handlers[sync_id]->sync_init; - callbacks->sync_process = ais_service_handlers[sync_id]->sync_process; - callbacks->sync_activate = ais_service_handlers[sync_id]->sync_activate; - callbacks->sync_abort = ais_service_handlers[sync_id]->sync_abort; + callbacks->name = ais_service[sync_id]->name; + callbacks->sync_init = ais_service[sync_id]->sync_init; + callbacks->sync_process = ais_service[sync_id]->sync_process; + callbacks->sync_activate = ais_service[sync_id]->sync_activate; + callbacks->sync_abort = ais_service[sync_id]->sync_abort; return (0); } @@ -961,11 +939,11 @@ static void deliver_fn ( service = header->id >> 16; fn_id = header->id & 0xffff; if (endian_conversion_required) { - ais_service_handlers[service]->exec_handlers[fn_id].exec_endian_convert_fn + ais_service[service]->exec_service[fn_id].exec_endian_convert_fn (header); } - ais_service_handlers[service]->exec_handlers[fn_id].exec_handler_fn + ais_service[service]->exec_service[fn_id].exec_handler_fn (header, source_addr); } @@ -989,9 +967,9 @@ static void confchg_fn ( /* * Call configuration change for all services */ - for (i = 0; i < service_handlers_count; i++) { - if (ais_service_handlers[i] && ais_service_handlers[i]->confchg_fn) { - ais_service_handlers[i]->confchg_fn (configuration_type, + for (i = 0; i < service_count; i++) { + if (ais_service[i] && ais_service[i]->confchg_fn) { + ais_service[i]->confchg_fn (configuration_type, member_list, member_list_entries, left_list, left_list_entries, joined_list, joined_list_entries, ring_id); @@ -1006,7 +984,7 @@ static void aisexec_uid_determine (void) passwd = getpwnam(OPENAIS_USER); if (passwd == 0) { log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", OPENAIS_USER); - ais_done (AIS_DONE_UID_DETERMINE); + openais_exit_error (AIS_DONE_UID_DETERMINE); } ais_uid = passwd->pw_uid; } @@ -1017,7 +995,7 @@ static void aisexec_gid_determine (void) group = getgrnam (OPENAIS_GROUP); if (group == 0) { log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", OPENAIS_GROUP); - ais_done (AIS_DONE_GID_DETERMINE); + openais_exit_error (AIS_DONE_GID_DETERMINE); } gid_valid = group->gr_gid; } @@ -1036,7 +1014,7 @@ static void aisexec_mempool_init (void) res = mempool_init (pool_sizes); if (res == ENOMEM) { log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory"); - ais_done (AIS_DONE_MEMPOOL_INIT); + openais_exit_error (AIS_DONE_MEMPOOL_INIT); } } @@ -1049,7 +1027,7 @@ static void aisexec_tty_detach (void) */ switch (fork ()) { case -1: - ais_done (AIS_DONE_FORK); + openais_exit_error (AIS_DONE_FORK); break; case 0: /* @@ -1076,14 +1054,14 @@ static void aisexec_libais_bind (int *server_fd) libais_server_fd = socket (PF_UNIX, SOCK_STREAM, 0); if (libais_server_fd == -1) { log_printf (LOG_LEVEL_ERROR ,"Cannot create libais client connections socket.\n"); - ais_done (AIS_DONE_LIBAIS_SOCKET); + openais_exit_error (AIS_DONE_LIBAIS_SOCKET); }; totemip_nosigpipe(libais_server_fd); res = fcntl (libais_server_fd, F_SETFL, O_NONBLOCK); if (res == -1) { log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on server socket: %s\n", strerror (errno)); - ais_done (AIS_DONE_LIBAIS_SOCKET); + openais_exit_error (AIS_DONE_LIBAIS_SOCKET); } #if !defined(OPENAIS_LINUX) @@ -1103,7 +1081,7 @@ static void aisexec_libais_bind (int *server_fd) res = bind (libais_server_fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr)); if (res) { log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno)); - ais_done (AIS_DONE_LIBAIS_BIND); + openais_exit_error (AIS_DONE_LIBAIS_BIND); } listen (libais_server_fd, SERVER_BACKLOG); @@ -1176,76 +1154,14 @@ void message_source_set ( struct totem_logging_configuration totem_logging_configuration; -int service_handler_register ( - struct openais_service_handler *handler, - struct openais_config *config) -{ - int res = 0; - assert (ais_service_handlers[handler->id] == NULL); - log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name); - ais_service_handlers[handler->id] = handler; - if (ais_service_handlers[handler->id]->config_init_fn) { - res = ais_service_handlers[handler->id]->config_init_fn (config); - } - return (res); -} - -int service_handler_init ( - struct openais_service_handler *handler, - struct openais_config *config) -{ - int res = 0; - assert (ais_service_handlers[handler->id] != NULL); - log_printf (LOG_LEVEL_NOTICE, "Initializing service handler '%s'\n", handler->name); - if (ais_service_handlers[handler->id]->exec_init_fn) { - res = ais_service_handlers[handler->id]->exec_init_fn (config); - } - return (res); -} - -void default_services_register (struct openais_config *openais_config) -{ - int i; - - for (i = 0; i < openais_config->num_dynamic_services; i++) { - lcr_ifact_reference ( - &openais_config->dynamic_services[i].handle, - openais_config->dynamic_services[i].name, - openais_config->dynamic_services[i].ver, - (void **)&openais_config->dynamic_services[i].iface_ver0, - (void *)0); - - if (!openais_config->dynamic_services[i].iface_ver0) { - log_printf(LOG_LEVEL_ERROR, "AIS Component %s did not load.\n", openais_config->dynamic_services[i].name); - ais_done(AIS_DONE_DYNAMICLOAD); - } else { - log_printf(LOG_LEVEL_ERROR, "AIS Component %s loaded.\n", openais_config->dynamic_services[i].name); - } - - service_handler_register ( - openais_config->dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(), - openais_config); - } - -} - -void default_services_init (struct openais_config *openais_config) -{ - int i; - - for (i = 0; i < openais_config->num_dynamic_services; i++) { - service_handler_init (openais_config->dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(), - openais_config); - } -} - int main (int argc, char **argv) { int libais_server_fd; - int res; - char *error_string; struct openais_config openais_config; + unsigned int objdb_handle; + struct objdb_iface_ver0 *objdb; + int res; memset(&this_non_loopback_ip, 0, sizeof(struct totem_ip_address)); @@ -1260,23 +1176,30 @@ int main (int argc, char **argv) //TODO signal (SIGUSR2, sigusr2_handler); /* - * if totempg_initialize doesn't have root priveleges, it cannot - * bind to a specific interface. This only matters if - * there is more then one interface in a system, so - * in this case, only a warning is printed + * Load the object database interface */ - res = openais_main_config_read (&error_string, &openais_config, 1); + res = lcr_ifact_reference ( + &objdb_handle, + "objdb", + 0, + (void **)&objdb, + 0); + + objdb->objdb_init (); + openais_service_default_objdb_set (objdb); + + res = openais_main_config_read (objdb, &error_string, &openais_config, 1); if (res == -1) { log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n"); log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_MAINCONFIGREAD); + openais_exit_error (AIS_DONE_MAINCONFIGREAD); } res = openais_amf_config_read (&error_string); if (res == -1) { log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_AMFCONFIGREAD); + openais_exit_error (AIS_DONE_AMFCONFIGREAD); } if (!openais_config.totem_config.interface_count) { @@ -1284,26 +1207,26 @@ int main (int argc, char **argv) if (res == -1) { log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n"); log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_MAINCONFIGREAD); + openais_exit_error (AIS_DONE_MAINCONFIGREAD); } } res = totem_config_keyread ("/etc/ais/authkey", &openais_config.totem_config, &error_string); if (res == -1) { log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_MAINCONFIGREAD); + openais_exit_error (AIS_DONE_MAINCONFIGREAD); } res = totem_config_validate (&openais_config.totem_config, &error_string); if (res == -1) { log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_MAINCONFIGREAD); + openais_exit_error (AIS_DONE_MAINCONFIGREAD); } res = log_setup (&error_string, openais_config.logmode, openais_config.logfile); if (res == -1) { log_printf (LOG_LEVEL_ERROR, error_string); - ais_done (AIS_DONE_LOGSETUP); + openais_exit_error (AIS_DONE_LOGSETUP); } log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc. and contributors.\n"); @@ -1326,8 +1249,12 @@ int main (int argc, char **argv) openais_config.totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI); openais_config.totem_config.totem_logging_configuration.log_printf = internal_log_printf; - default_services_register(&openais_config); - + /* + * if totempg_initialize doesn't have root priveleges, it cannot + * bind to a specific interface. This only matters if + * there is more then one interface in a system, so + * in this case, only a warning is printed + */ totempg_initialize ( aisexec_poll_handle, &openais_config.totem_config); @@ -1346,7 +1273,8 @@ int main (int argc, char **argv) * This must occur after totempg is initialized because "this_ip" must be set */ this_ip = &openais_config.totem_config.interfaces[0].boundto; - default_services_init(&openais_config); + openais_service_link_all (objdb, &openais_config); + sync_register (openais_sync_callbacks_retrieve, openais_sync_completed); diff --git a/exec/main.h b/exec/main.h index 6e84d9c4..288c2713 100644 --- a/exec/main.h +++ b/exec/main.h @@ -41,7 +41,6 @@ #include "../include/ipc_gen.h" #include "mainconfig.h" #include "poll.h" -#include "handlers.h" #ifndef AIS_EXEC_H_DEFINED #define AIS_EXEC_H_DEFINED diff --git a/exec/mainconfig.c b/exec/mainconfig.c index aa2d9b34..766cfc23 100644 --- a/exec/mainconfig.c +++ b/exec/mainconfig.c @@ -47,6 +47,7 @@ #include "mempool.h" #include "print.h" #include "totem.h" +#include "service.h" DECLARE_LIST_INIT (saAmfGroupHead); @@ -88,27 +89,6 @@ char *strstr_rs (const char *haystack, const char *needle) return (end_address); } -static void set_default_services(struct openais_config *config) -{ - config->dynamic_services[0].name = "openais_evs"; - config->dynamic_services[0].ver = 0; - config->dynamic_services[1].name = "openais_clm"; - config->dynamic_services[1].ver = 0; - config->dynamic_services[2].name = "openais_amf"; - config->dynamic_services[2].ver = 0; - config->dynamic_services[3].name = "openais_ckpt"; - config->dynamic_services[3].ver = 0; - config->dynamic_services[4].name = "openais_evt"; - config->dynamic_services[4].ver = 0; - config->dynamic_services[5].name = "openais_lck"; - config->dynamic_services[5].ver = 0; - config->dynamic_services[6].name = "openais_msg"; - config->dynamic_services[6].ver = 0; - config->dynamic_services[7].name = "openais_cfg"; - config->dynamic_services[7].ver = 0; - config->num_dynamic_services = 8; -} - /* Returns an allocated string */ static char *get_component(const char *line, int *version) { @@ -135,8 +115,10 @@ static char *get_component(const char *line, int *version) return compname; } -extern int openais_main_config_read (char **error_string, - struct openais_config *openais_config, +extern int openais_main_config_read ( + struct objdb_iface_ver0 *objdb, + char **error_string, + struct openais_config *openais_config, int interface_max) { FILE *fp; @@ -287,9 +269,7 @@ extern int openais_main_config_read (char **error_string, int version; char *name = get_component(line, &version); if (name) { - openais_config->dynamic_services[openais_config->num_dynamic_services].name = name; - openais_config->dynamic_services[openais_config->num_dynamic_services].ver = version; - openais_config->num_dynamic_services++; + openais_service_objdb_add (objdb, name, version); } } break; @@ -304,10 +284,6 @@ extern int openais_main_config_read (char **error_string, goto parse_error; } - /* Load default services if the config file doesn't specify */ - if (!openais_config->num_dynamic_services) { - set_default_services(openais_config); - } if (parse == MAIN_HEAD) { fclose (fp); return (0); diff --git a/exec/mainconfig.h b/exec/mainconfig.h index 9a6d3ea1..c82c4c13 100644 --- a/exec/mainconfig.h +++ b/exec/mainconfig.h @@ -37,6 +37,7 @@ #include "aispoll.h" #include "totemsrp.h" #include "totempg.h" +#include "objdb.h" #ifndef MAINCONFIG_H_DEFINED #define MAINCONFIG_H_DEFINED @@ -71,13 +72,13 @@ struct openais_config { unsigned int amf_enabled; struct totem_config totem_config; - struct dynamic_service dynamic_services[MAX_DYNAMIC_SERVICES]; - int num_dynamic_services; }; extern char *strstr_rs (const char *haystack, const char *needle); -extern int openais_main_config_read (char **error_string, +extern int openais_main_config_read ( + struct objdb_iface_ver0 *objdb, + char **error_string, struct openais_config *openais_config, int interface_max); diff --git a/exec/msg.c b/exec/msg.c index 74a2e760..d555e0bd 100644 --- a/exec/msg.c +++ b/exec/msg.c @@ -51,6 +51,7 @@ #include "../include/list.h" #include "../include/queue.h" #include "../lcr/lcr_comp.h" +#include "service.h" #include "aispoll.h" #include "mempool.h" #include "util.h" @@ -271,7 +272,7 @@ struct msg_pd { /* * Executive Handler Definition */ -struct openais_lib_handler msg_lib_handlers[] = +struct openais_lib_handler msg_lib_service[] = { { /* 0 */ .lib_handler_fn = message_handler_req_lib_msg_queueopen, @@ -384,7 +385,7 @@ struct openais_lib_handler msg_lib_handlers[] = }; -static struct openais_exec_handler msg_exec_handlers[] = { +static struct openais_exec_handler msg_exec_service[] = { { .exec_handler_fn = message_handler_req_exec_msg_queueopen, }, @@ -438,11 +439,11 @@ struct openais_service_handler msg_service_handler = { .private_data_size = sizeof (struct msg_pd), .lib_init_fn = msg_lib_init_fn, .lib_exit_fn = msg_lib_exit_fn, - .lib_handlers = msg_lib_handlers, - .lib_handlers_count = sizeof (msg_lib_handlers) / sizeof (struct openais_lib_handler), + .lib_service = msg_lib_service, + .lib_service_count = sizeof (msg_lib_service) / sizeof (struct openais_lib_handler), .exec_init_fn = msg_exec_init_fn, - .exec_handlers = msg_exec_handlers, - .exec_handlers_count = sizeof (msg_exec_handlers) / sizeof (struct openais_exec_handler), + .exec_service = msg_exec_service, + .exec_service_count = sizeof (msg_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = msg_confchg_fn, .exec_dump_fn = NULL, .sync_init = NULL, // TODO msg_sync_init, diff --git a/exec/objdb.c b/exec/objdb.c new file mode 100644 index 00000000..de9c62aa --- /dev/null +++ b/exec/objdb.c @@ -0,0 +1,537 @@ +/* + * Copyright (c) 2006 MontaVista Software, Inc. + * + * All rights reserved. + * + * Author: Steven Dake (sdake@mvista.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 +#include +#include "objdb.h" +#include "../lcr/lcr_comp.h" +#include "../include/hdb.h" +#include "../include/list.h" + +struct object_key { + void *key_name; + int key_len; + void *value; + int value_len; + struct list_head list; +}; + +struct object_instance { + void *object_name; + int object_name_len; + unsigned int object_handle; + struct list_head key_head; + struct list_head child_head; + struct list_head child_list; + struct list_head *find_child_list; + void *priv; + struct object_valid *object_valid_list; + int object_valid_list_entries; + struct object_key_valid *object_key_valid_list; + int object_key_valid_list_entries; +}; + +static struct hdb_handle_database object_instance_database = { + .handle_count = 0, + .handles = 0, + .iterator = 0 +}; + +static int objdb_init (void) +{ + unsigned int handle; + struct object_instance *instance; + unsigned int res; + + res = hdb_handle_create (&object_instance_database, + sizeof (struct object_instance), &handle); + if (res != 0) { + goto error_exit; + } + res = hdb_handle_get (&object_instance_database, + handle, (void *)&instance); + if (res != 0) { + goto error_destroy; + } + instance->find_child_list = &instance->child_head; + instance->object_name = "parent"; + instance->object_name_len = strlen ("parent"); + instance->object_handle = handle; + instance->priv = NULL; + instance->object_valid_list = NULL; + instance->object_valid_list_entries = 0; + list_init (&instance->key_head); + list_init (&instance->child_head); + list_init (&instance->child_list); + + hdb_handle_put (&object_instance_database, handle); + return (0); + +error_destroy: + hdb_handle_destroy (&object_instance_database, handle); + +error_exit: + return (-1); +} + +/* + * object db create/destroy/set + */ +static int object_create ( + unsigned int parent_object_handle, + unsigned int *object_handle, + void *object_name, + unsigned int object_name_len) +{ + struct object_instance *object_instance; + struct object_instance *parent_instance; + unsigned int res; + int found = 0; + int i; + + res = hdb_handle_get (&object_instance_database, + parent_object_handle, (void *)&parent_instance); + if (res != 0) { + goto error_exit; + } + + /* + * Do validation check if validation is configured for the parent object + */ + if (parent_instance->object_valid_list_entries) { + for (i = 0; i < parent_instance->object_valid_list_entries; i++) { + if ((object_name_len == + parent_instance->object_valid_list[i].object_len) && + (memcmp (object_name, + parent_instance->object_valid_list[i].object_name, + object_name_len) == 0)) { + + found = 1; + break; + } + } + + /* + * Item not found in validation list + */ + if (found == 0) { + goto error_object_put; + } + } + + + res = hdb_handle_create (&object_instance_database, + sizeof (struct object_instance), object_handle); + if (res != 0) { + goto error_object_put; + } + + res = hdb_handle_get (&object_instance_database, + *object_handle, (void *)&object_instance); + if (res != 0) { + goto error_destroy; + } + list_init (&object_instance->key_head); + list_init (&object_instance->child_head); + list_init (&object_instance->child_list); + object_instance->object_name = malloc (object_name_len); + if (object_instance->object_name == 0) { + goto error_put_destroy; + } + memcpy (object_instance->object_name, object_name, object_name_len); + + object_instance->object_name_len = object_name_len; + + list_add (&object_instance->child_list, &parent_instance->child_head); + + object_instance->object_handle = *object_handle; + object_instance->find_child_list = &object_instance->child_head; + object_instance->priv = NULL; + object_instance->object_valid_list = NULL; + object_instance->object_valid_list_entries = 0; + + hdb_handle_put (&object_instance_database, *object_handle); + + hdb_handle_put (&object_instance_database, parent_object_handle); + + return (0); + +error_put_destroy: + hdb_handle_put (&object_instance_database, *object_handle); + +error_destroy: + hdb_handle_destroy (&object_instance_database, *object_handle); + +error_object_put: + hdb_handle_put (&object_instance_database, parent_object_handle); + +error_exit: + return (-1); +} + +static int object_priv_set ( + unsigned int object_handle, + void *priv) +{ + int res; + struct object_instance *object_instance; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&object_instance); + if (res != 0) { + goto error_exit; + } + + object_instance->priv = priv; + + hdb_handle_put (&object_instance_database, object_handle); + return (0); + +error_exit: + return (-1); +} + +static int object_key_create ( + unsigned int object_handle, + void *key_name, + int key_len, + void *value, + int value_len) +{ + struct object_instance *instance; + struct object_key *object_key; + unsigned int res; + int found = 0; + int i; + unsigned int val; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + + /* + * Do validation check if validation is configured for the parent object + */ + if (instance->object_key_valid_list_entries) { + for (i = 0; i < instance->object_key_valid_list_entries; i++) { + if ((key_len == + instance->object_key_valid_list[i].key_len) && + (memcmp (key_name, + instance->object_key_valid_list[i].key_name, + key_len) == 0)) { + + found = 1; + break; + } + } + + /* + * Item not found in validation list + */ + if (found == 0) { + goto error_put; + } else { + if (instance->object_key_valid_list[i].validate_callback) { + res = instance->object_key_valid_list[i].validate_callback ( + key_name, key_len, value, value_len); + if (res != 0) { + goto error_put; + } + } + } + } + + object_key = malloc (sizeof (struct object_key)); + if (object_key == 0) { + goto error_put; + } + object_key->key_name = malloc (key_len); + if (object_key->key_name == 0) { + goto error_put_object; + } + memcpy (&val, value, 4); + object_key->value = malloc (value_len); + if (object_key->value == 0) { + goto error_put_key; + } + memcpy (object_key->key_name, key_name, key_len); + memcpy (object_key->value, value, value_len); + + object_key->key_len = key_len; + + list_init (&object_key->list); + list_add (&object_key->list, &instance->key_head); + + return (0); + +error_put_key: + free (object_key->key_name); + +error_put_object: + free (object_key); + +error_put: + hdb_handle_put (&object_instance_database, object_handle); + +error_exit: + return (-1); +} + +static int object_destroy ( + unsigned int object_handle) +{ + return (0); +} + +static int object_valid_set ( + unsigned int object_handle, + struct object_valid *object_valid_list, + unsigned int object_valid_list_entries) +{ + struct object_instance *instance; + unsigned int res; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + + instance->object_valid_list = object_valid_list; + instance->object_valid_list_entries = object_valid_list_entries; + + hdb_handle_put (&object_instance_database, object_handle); + + return (0); + +error_exit: + return (-1); +} + +static int object_key_valid_set ( + unsigned int object_handle, + struct object_key_valid *object_key_valid_list, + unsigned int object_key_valid_list_entries) +{ + struct object_instance *instance; + unsigned int res; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + + instance->object_key_valid_list = object_key_valid_list; + instance->object_key_valid_list_entries = object_key_valid_list_entries; + + hdb_handle_put (&object_instance_database, object_handle); + + return (0); + +error_exit: + return (-1); +} + +/* + * object db reading + */ +static int object_find_reset ( + unsigned int object_handle) +{ + unsigned int res; + struct object_instance *instance; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + instance->find_child_list = &instance->child_head; + + hdb_handle_put (&object_instance_database, object_handle); + return (0); + +error_exit: + return (-1); +} + +static int object_find ( + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle) +{ + unsigned int res; + struct object_instance *instance; + struct object_instance *find_instance = NULL; + struct list_head *list; + unsigned int found = 0; + + res = hdb_handle_get (&object_instance_database, + parent_object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + res = -ENOENT; + for (list = instance->find_child_list->next; + list != &instance->child_head; list = list->next) { + + find_instance = list_entry (list, struct object_instance, + child_list); + + if ((find_instance->object_name_len == object_name_len) && + (memcmp (find_instance->object_name, object_name, + object_name_len) == 0)) { + found = 1; + break; + } + } + instance->find_child_list = list; + hdb_handle_put (&object_instance_database, parent_object_handle); + if (found) { + *object_handle = find_instance->object_handle; + res = 0; + } + return (res); + +error_exit: + return (-1); +} + +static int object_key_get ( + unsigned int object_handle, + void *key_name, + int key_len, + void **value, + int *value_len) +{ + unsigned int res; + struct object_instance *instance; + struct object_key *object_key = NULL; + struct list_head *list; + int found = 0; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&instance); + if (res != 0) { + goto error_exit; + } + for (list = instance->key_head.next; + list != &instance->key_head; list = list->next) { + + object_key = list_entry (list, struct object_key, list); + + if ((object_key->key_len == key_len) && + (memcmp (object_key->key_name, key_name, key_len) == 0)) { + found = 1; + break; + } + } + if (found) { + *value = object_key->value; + if (value_len) { + *value_len = object_key->value_len; + } + } + + hdb_handle_put (&object_instance_database, object_handle); + return (0); + +error_exit: + return (-1); +} + +static int object_priv_get ( + unsigned int object_handle, + void **priv) +{ + int res; + struct object_instance *object_instance; + + res = hdb_handle_get (&object_instance_database, + object_handle, (void *)&object_instance); + if (res != 0) { + goto error_exit; + } + + *priv = object_instance->priv; + + hdb_handle_put (&object_instance_database, object_handle); + return (0); + +error_exit: + return (-1); +} + +struct objdb_iface_ver0 objdb_iface = { + .objdb_init = objdb_init, + .object_create = object_create, + .object_priv_set = object_priv_set, + .object_key_create = object_key_create, + .object_destroy = object_destroy, + .object_valid_set = object_valid_set, + .object_key_valid_set = object_key_valid_set, + .object_find_reset = object_find_reset, + .object_find = object_find, + .object_key_get = object_key_get, + .object_priv_get = object_priv_set +}; + +struct lcr_iface objdb_iface_ver0[1] = { + { + .name = "objdb", + .version = 0, + .versions_replace = 0, + .versions_replace_count = 0, + .dependencies = 0, + .dependency_count = 0, + .constructor = NULL, + .destructor = NULL, + .interfaces = (void **)&objdb_iface, + } +}; + +struct lcr_comp objdb_comp_ver0 = { + .iface_count = 1, + .ifaces = objdb_iface_ver0 +}; + + + +__attribute__ ((constructor)) static void objdb_comp_register (void) { + lcr_component_register (&objdb_comp_ver0); +} diff --git a/exec/objdb.h b/exec/objdb.h new file mode 100644 index 00000000..d8d35d4a --- /dev/null +++ b/exec/objdb.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2006 MontaVista Software, Inc. + * + * All rights reserved. + * + * Author: Steven Dake (sdake@mvista.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. + */ + +#ifndef OBJDB_H_DEFINED +#define OBJDB_H_DEFINED + +#define OBJECT_PARENT_HANDLE 0 + +struct object_valid { + char *object_name; + int object_len; +}; + +struct object_key_valid { + char *key_name; + int key_len; + int (*validate_callback) (void *key, int key_len, void *value, int value_len); +}; + +struct objdb_iface_ver0 { + int (*objdb_init) (void); + + int (*object_create) ( + unsigned int parent_object_handle, + unsigned int *object_handle, + void *object_name, + unsigned int object_name_len); + + int (*object_priv_set) ( + unsigned int object_handle, + void *priv); + + int (*object_key_create) ( + unsigned int object_handle, + void *key_name, + int key_len, + void *value, + int value_len); + + int (*object_destroy) ( + unsigned int object_handle); + + int (*object_valid_set) ( + unsigned int object_handle, + struct object_valid *object_valid_list, + unsigned int object_valid_list_entries); + + int (*object_key_valid_set) ( + unsigned int object_handle, + struct object_key_valid *object_key_valid_list, + unsigned int object_key_valid_list_entries); + + int (*object_find_reset) ( + unsigned int parent_object_handle); + + int (*object_find) ( + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle); + + int (*object_key_get) ( + unsigned int object_handle, + void *key_name, + int key_len, + void **value, + int *value_len); + + int (*object_priv_get) ( + unsigned int jobject_handle, + void **priv); +}; + +#endif /* OBJDB_H_DEFINED */ diff --git a/exec/print.c b/exec/print.c index e45cc123..84fdb9d1 100644 --- a/exec/print.c +++ b/exec/print.c @@ -62,7 +62,7 @@ static char *log_levels[] = { }; static char *log_services[] = { - "[ASSERT]", + "[ASSER]", "[MAIN ]", "[TOTEM]", "[CLM ]", @@ -74,7 +74,8 @@ static char *log_services[] = { "[EVS ]", "[SYNC ]", "[YKD ]", - "[CPG ]" + "[CPG ]", + "[SERV ]" }; #define LOG_MODE_DEBUG 1 diff --git a/exec/print.h b/exec/print.h index 9247bae1..1c23788c 100644 --- a/exec/print.h +++ b/exec/print.h @@ -67,6 +67,7 @@ #define LOG_SERVICE_SYNC 10 #define LOG_SERVICE_YKD 11 #define LOG_SERVICE_CPG 12 +#define LOG_SERVICE_SERV 13 extern void internal_log_printf (int logclass, char *format, ...); diff --git a/exec/handlers.h b/exec/service.h similarity index 81% rename from exec/handlers.h rename to exec/service.h index 577a5d46..01d83755 100644 --- a/exec/handlers.h +++ b/exec/service.h @@ -31,13 +31,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OPENAIS_HANDLERS_H_DEFINED -#define OPENAIS_HANDLERS_H_DEFINED +#ifndef OPENAIS_SERVICE_H_DEFINED +#define OPENAIS_SERVICE_H_DEFINED #include #include "mainconfig.h" /* openais_config */ -#include "main.h" /* conn_info */ #include "totemip.h" +#include "objdb.h" #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) ) @@ -66,13 +66,13 @@ struct openais_service_handler { unsigned int private_data_size; int (*lib_init_fn) (void *conn); int (*lib_exit_fn) (void *conn); - struct openais_lib_handler *lib_handlers; - int lib_handlers_count; - struct openais_exec_handler *exec_handlers; + struct openais_lib_handler *lib_service; + int lib_service_count; + struct openais_exec_handler *exec_service; int (*exec_init_fn) (struct openais_config *); int (*config_init_fn) (struct openais_config *); void (*exec_dump_fn) (void); - int exec_handlers_count; + int exec_service_count; void (*confchg_fn) ( enum totem_configuration_type configuration_type, struct totem_ip_address *member_list, int member_list_entries, @@ -90,4 +90,22 @@ struct openais_service_handler_iface_ver0 { struct openais_service_handler *(*openais_get_service_handler_ver0) (void); }; -#endif /* HANDLERS_H_DEFINED */ +extern int openais_service_objdb_add ( + struct objdb_iface_ver0 *objdb, + char *name, + int version); + + +extern int openais_service_handler_register ( + struct openais_service_handler *handler, + struct openais_config *config); + +extern int openais_service_default_objdb_set (struct objdb_iface_ver0 *objdb); + +extern int openais_service_link_all ( + struct objdb_iface_ver0 *objdb, + struct openais_config *openais_config); + +extern struct openais_service_handler *ais_service[]; + +#endif /* SERVICE_H_DEFINED */ diff --git a/exec/util.c b/exec/util.c index 350e440c..07d27a72 100644 --- a/exec/util.c +++ b/exec/util.c @@ -40,7 +40,10 @@ #include "../include/saAis.h" #include "../include/list.h" +#include "aispoll.h" #include "util.h" +#define LOG_SERVICE LOG_SERVICE_MAIN +#include "print.h" /* * Compare two names. returns non-zero on match. @@ -71,3 +74,10 @@ SaTimeT clust_time_now(void) return time_now; } + + +void openais_exit_error (enum e_ais_done err) +{ + log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting.\n"); + exit (1); +} diff --git a/exec/util.h b/exec/util.h index c8d620f9..ba3cb7c1 100644 --- a/exec/util.h +++ b/exec/util.h @@ -46,4 +46,22 @@ extern int name_match(SaNameT *name1, SaNameT *name2); * Get the time of day and convert to nanoseconds */ extern SaTimeT clust_time_now(void); + +enum e_ais_done { + AIS_DONE_EXIT = -1, + AIS_DONE_UID_DETERMINE = -2, + AIS_DONE_GID_DETERMINE = -3, + AIS_DONE_MEMPOOL_INIT = -4, + AIS_DONE_FORK = -5, + AIS_DONE_LIBAIS_SOCKET = -6, + AIS_DONE_LIBAIS_BIND = -7, + AIS_DONE_READKEY = -8, + AIS_DONE_MAINCONFIGREAD = -9, + AIS_DONE_LOGSETUP = -10, + AIS_DONE_AMFCONFIGREAD = -11, + AIS_DONE_DYNAMICLOAD = -12, +}; + +void openais_exit_error (enum e_ais_done err); + #endif /* UTIL_H_DEFINED */ diff --git a/exec/ykd.c b/exec/ykd.c index 451fd869..e9c028af 100644 --- a/exec/ykd.c +++ b/exec/ykd.c @@ -55,7 +55,7 @@ #include #include -#include "handlers.h" +#include "main.h" #include "print.h" #include "swab.h"