# HG changeset patch # Parent 1e456ff1fdff444054de0b5d475cd1a19cea1bb9 Medium: stonith: Allow clients to avoid use of Glib mainloop. Allow an application to avoid use of the Glib mainloop by polling on the asyncronous file descriptor provided in the connect call. Activity is then handled by using the newly provided dispatch api routine, whcih calls stonith_dispatch(). diff -r 1e456ff1fdff crmd/te_utils.c --- a/crmd/te_utils.c Fri Apr 29 11:51:01 2011 -0400 +++ b/crmd/te_utils.c Fri Apr 29 12:41:50 2011 -0400 @@ -214,7 +214,7 @@ crm_info("Attempting connection to fencing daemon..."); sleep(1); - rc = stonith_api->cmds->connect(stonith_api, crm_system_name, NULL, NULL); + rc = stonith_api->cmds->connect(stonith_api, crm_system_name, NULL); if(rc == stonith_ok) { break; diff -r 1e456ff1fdff fencing/admin.c --- a/fencing/admin.c Fri Apr 29 11:51:01 2011 -0400 +++ b/fencing/admin.c Fri Apr 29 12:41:50 2011 -0400 @@ -177,7 +177,7 @@ st = stonith_api_new(); if(action != 'M') { - rc = st->cmds->connect(st, crm_system_name, NULL, NULL); + rc = st->cmds->connect(st, crm_system_name, NULL); crm_debug("Connect: %d", rc); rc = st->cmds->register_notification(st, T_STONITH_NOTIFY_DISCONNECT, st_callback); diff -r 1e456ff1fdff fencing/test.c --- a/fencing/test.c Fri Apr 29 11:51:01 2011 -0400 +++ b/fencing/test.c Fri Apr 29 12:41:50 2011 -0400 @@ -49,27 +49,21 @@ }; int st_opts = st_opt_sync_call; -GMainLoop *mainloop = NULL; static void st_callback(stonith_t *st, const char *event, xmlNode *msg) { crm_log_xml_notice(msg, event); } -static gboolean timeout_handler(gpointer data) -{ - g_main_quit(mainloop); - return FALSE; -} - int main(int argc, char ** argv) { + int argerr = 0; int flag; + int option_index = 0; int rc = 0; - int argerr = 0; - int option_index = 0; + struct pollfd pollfd; stonith_t *st = NULL; stonith_key_value_t *params = NULL; @@ -119,23 +113,26 @@ crm_debug("Create"); st = stonith_api_new(); - rc = st->cmds->connect(st, crm_system_name, NULL, NULL); + rc = st->cmds->connect(st, crm_system_name, &pollfd.fd); crm_debug("Connect: %d", rc); rc = st->cmds->register_notification(st, T_STONITH_NOTIFY_DISCONNECT, st_callback); if(passive_mode) { - rc = st->cmds->register_notification(st, STONITH_OP_FENCE, st_callback); - + rc = st->cmds->register_notification(st, STONITH_OP_FENCE, st_callback); rc = st->cmds->register_notification(st, STONITH_OP_DEVICE_ADD, st_callback); rc = st->cmds->register_notification(st, STONITH_OP_DEVICE_DEL, st_callback); - - mainloop = g_main_new(FALSE); + crm_info("Looking for notification"); - g_timeout_add(500*1000, timeout_handler, NULL); - - g_main_run(mainloop); - + pollfd.events = POLLIN; + while(true) { + rc = poll( &pollfd, 1, 600 * 1000 ); /* wait 10 minutes, -1 forever */ + if (rc > 0 ) + stonith_dispatch( st ); + else + break; + } + } else { rc = st->cmds->register_device(st, st_opts, "test-id", "stonith-ng", "fence_virsh", params); crm_debug("Register: %d", rc); diff -r 1e456ff1fdff include/crm/stonith-ng.h --- a/include/crm/stonith-ng.h Fri Apr 29 11:51:01 2011 -0400 +++ b/include/crm/stonith-ng.h Fri Apr 29 12:41:50 2011 -0400 @@ -116,7 +116,7 @@ typedef struct stonith_api_operations_s { int (*free) (stonith_t *st); - int (*connect) (stonith_t *st, const char *name, int *async_fd, int *sync_fd); + int (*connect) (stonith_t *st, const char *name, int *stonith_fd); int (*disconnect)(stonith_t *st); int (*remove_device)( @@ -169,6 +169,8 @@ extern const char *get_stonith_provider(const char *agent, const char *provider); +extern bool stonith_dispatch(stonith_t *st); + extern stonith_key_value_t *stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value); extern void stonith_key_value_freeall(stonith_key_value_t *kvp); diff -r 1e456ff1fdff lib/fencing/st_client.c --- a/lib/fencing/st_client.c Fri Apr 29 11:51:01 2011 -0400 +++ b/lib/fencing/st_client.c Fri Apr 29 12:41:50 2011 -0400 @@ -115,7 +115,8 @@ " \n" "\n"; -gboolean stonith_dispatch(IPC_Channel *channel, gpointer user_data); +bool stonith_dispatch(stonith_t *st); +gboolean stonith_dispatch_internal(IPC_Channel *channel, gpointer user_data); void stonith_perform_callback(stonith_t *stonith, xmlNode *msg, int call_id, int rc); xmlNode *stonith_create_op( int call_id, const char *token, const char *op, xmlNode *data, int call_options); @@ -915,7 +916,7 @@ } static int stonith_api_signon( - stonith_t* stonith, const char *name, int *async_fd, int *sync_fd) + stonith_t* stonith, const char *name, int *stonith_fd) { int rc = stonith_ok; xmlNode *hello = NULL; @@ -985,21 +986,15 @@ } if(rc == stonith_ok) { - gboolean do_mainloop = TRUE; - if(async_fd != NULL) { - do_mainloop = FALSE; - *async_fd = native->callback_channel->ops->get_recv_select_fd(native->callback_channel); - } + if(stonith_fd != NULL) { + *stonith_fd = native->callback_channel->ops->get_recv_select_fd( + native->callback_channel); - if(sync_fd != NULL) { - do_mainloop = FALSE; - *sync_fd = native->callback_channel->ops->get_send_select_fd(native->callback_channel); - } + } else { /* do mainloop */ - if(do_mainloop) { crm_debug_4("Connecting callback channel"); native->callback_source = G_main_add_IPC_Channel( - G_PRIORITY_HIGH, native->callback_channel, FALSE, stonith_dispatch, + G_PRIORITY_HIGH, native->callback_channel, FALSE, stonith_dispatch_internal, stonith, default_ipc_connection_destroy); if(native->callback_source == NULL) { @@ -1525,7 +1520,21 @@ return 1; } -gboolean stonith_dispatch(IPC_Channel *channel, gpointer user_data) +bool stonith_dispatch(stonith_t *st) +{ + stonith_private_t *private = NULL; + bool stay_connected = TRUE; + + CRM_CHECK(st != NULL, return FALSE); + + private = st->private; + + stay_connected = stonith_dispatch_internal(private->callback_channel, + (gpointer *)st); + return stay_connected; +} + +gboolean stonith_dispatch_internal(IPC_Channel *channel, gpointer user_data) { stonith_t *stonith = user_data; stonith_private_t *private = NULL; diff -r 1e456ff1fdff lib/plugins/lrm/raexecstonith.c --- a/lib/plugins/lrm/raexecstonith.c Fri Apr 29 11:51:01 2011 -0400 +++ b/lib/plugins/lrm/raexecstonith.c Fri Apr 29 12:41:50 2011 -0400 @@ -145,7 +145,7 @@ } stonith_api = stonith_api_new(); - rc = stonith_api->cmds->connect(stonith_api, "lrmd", NULL, NULL); + rc = stonith_api->cmds->connect(stonith_api, "lrmd", NULL); if(provider == NULL) { crm_err("No such legacy stonith device: %s", rsc_type); rc = st_err_unknown_device;