diff --git a/include/server_plugin.h b/include/server_plugin.h index cc75c86..77c05a8 100644 --- a/include/server_plugin.h +++ b/include/server_plugin.h @@ -16,7 +16,8 @@ -typedef void * srv_context_t; +typedef void * listener_context_t; +typedef void * backend_context_t; /* These callbacks hand requests off to the appropriate backend. */ @@ -49,8 +50,9 @@ typedef int (*fence_status_callback)(const char *vm_name, is responding to requests. */ typedef int (*fence_devstatus_callback)(void *priv); -typedef int (*fence_init_callback)(srv_context_t *c, config_object_t *config); -typedef int (*fence_cleanup_callback)(srv_context_t c); +typedef int (*fence_init_callback)(backend_context_t *c, + config_object_t *config); +typedef int (*fence_cleanup_callback)(backend_context_t c); typedef struct _fence_callbacks { fence_null_callback null; @@ -82,15 +84,15 @@ typedef void serial_options; /* Directory path / hypervisor uri if using libvirt... .. whatever you think you need... */ -int serial_init(srv_context_t *, fence_callbacks_t *, +int serial_init(listener_context_t *, fence_callbacks_t *, config_object_t *, void *priv); /* NULL = no timeout; wait forever */ -int serial_dispatch(srv_context_t, struct timeval *timeout); -int serial_shutdown(srv_context_t); +int serial_dispatch(listener_context_t, struct timeval *timeout); +int serial_shutdown(listener_context_t); -int mcast_init(srv_context_t *, const fence_callbacks_t *, +int mcast_init(listener_context_t *, const fence_callbacks_t *, config_object_t *, void *priv); -int mcast_dispatch(srv_context_t, struct timeval *timeout); -int mcast_shutdown(srv_context_t); +int mcast_dispatch(listener_context_t, struct timeval *timeout); +int mcast_shutdown(listener_context_t); diff --git a/server/libvirt.c b/server/libvirt.c index 8a32e24..a1585b7 100644 --- a/server/libvirt.c +++ b/server/libvirt.c @@ -278,7 +278,7 @@ libvirt_reboot(const char *vm_name, void *priv) } static int -libvirt_init(srv_context_t *c, config_object_t *config) +libvirt_init(backend_context_t *c, config_object_t *config) { virConnectPtr vp; char value[256]; @@ -298,7 +298,7 @@ libvirt_init(srv_context_t *c, config_object_t *config) static int -libvirt_shutdown(srv_context_t c) +libvirt_shutdown(backend_context_t c) { return virConnectClose((virConnectPtr)c); } diff --git a/server/main.c b/server/main.c index 68223bd..62c4ccd 100644 --- a/server/main.c +++ b/server/main.c @@ -16,12 +16,13 @@ int main(int argc, char **argv) { char val[80]; + char listener_name[80]; + char backend_name[80]; const char *config_file = DEFAULT_CONFIG_FILE; config_object_t *config; const plugin_t *p; - srv_context_t mcast_context = NULL; - srv_context_t libvirt_context; /*XXX these should be differently - named context types */ + listener_context_t listener_ctx = NULL; + backend_context_t backend_ctx = NULL; int debug_set = 0; int opt; @@ -55,13 +56,21 @@ main(int argc, char **argv) sc_dump(config, stdout); - if (sc_get(config, "fence_virtd/@backend", val, sizeof(val))) { + if (sc_get(config, "fence_virtd/@backend", backend_name, + sizeof(backend_name))) { printf("Failed to determine backend.\n"); printf("%s\n", val); return -1; } - printf("Backend plugin: %s\n", val); + if (sc_get(config, "fence_virtd/@listener", listener_name, + sizeof(listener_name))) { + printf("Failed to determine backend.\n"); + printf("%s\n", val); + return -1; + } + + printf("Backend plugin: %s\n", backend_name); #ifdef _MODULE if (plugin_load("./libvirt.so") < 0) { @@ -79,22 +88,22 @@ main(int argc, char **argv) return 1; } - if (p->init(&libvirt_context, config) < 0) { + if (p->init(&backend_ctx, config) < 0) { printf("%s failed to initialize\n", val); return 1; } /* only client we have now is mcast (fence_xvm behavior) */ - if (mcast_init(&mcast_context, p->callbacks, config, - libvirt_context) < 0) { + if (mcast_init(&listener_ctx, p->callbacks, config, + backend_ctx) < 0) { printf("Failed initialization!\n"); return 1; } - while (mcast_dispatch(mcast_context, NULL) >= 0); + while (mcast_dispatch(listener_ctx, NULL) >= 0); - mcast_shutdown(mcast_context); - p->cleanup(libvirt_context); + mcast_shutdown(listener_ctx); + p->cleanup(backend_ctx); return 0; } diff --git a/server/mcast.c b/server/mcast.c index e58cb3c..95d6df0 100644 --- a/server/mcast.c +++ b/server/mcast.c @@ -256,7 +256,7 @@ out: int -mcast_dispatch(srv_context_t c, struct timeval *timeout) +mcast_dispatch(listener_context_t c, struct timeval *timeout) { mcast_info *info; fence_req_t data; @@ -459,7 +459,7 @@ mcast_config(config_object_t *config, mcast_options *args) int -mcast_init(srv_context_t *c, const fence_callbacks_t *cb, +mcast_init(listener_context_t *c, const fence_callbacks_t *cb, config_object_t *config, void *priv) { mcast_info *info; @@ -516,13 +516,13 @@ mcast_init(srv_context_t *c, const fence_callbacks_t *cb, info->magic = MCAST_MAGIC; info->mc_sock = mc_sock; - *c = (srv_context_t)info; + *c = (listener_context_t)info; return 0; } int -mcast_shutdown(srv_context_t c) +mcast_shutdown(listener_context_t c) { mcast_info *info = (mcast_info *)c; diff --git a/server/plugin.c b/server/plugin.c index 4c9f4d9..49b61ce 100644 --- a/server/plugin.c +++ b/server/plugin.c @@ -83,14 +83,14 @@ plugin_find(const char *name) int -plugin_init(const plugin_t *p, srv_context_t *c, config_object_t *config) +plugin_init(const plugin_t *p, backend_context_t *c, config_object_t *config) { return p->init(c, config); } int -plugin_shutdown(const plugin_t *p, srv_context_t c) +plugin_shutdown(const plugin_t *p, backend_context_t c) { return p->cleanup(c); }