commit 02bc6c85f814e85b5840f75e198a29d86ac6f2f2 Author: Andrew Beekhof Date: Thu Feb 27 11:27:30 2014 +1100 Log: Fencing: Send details of stonith_api_time() and stonith_api_kick() to syslog (cherry picked from commit b0a8876fe230f5e3e5770734f78e36284c0bae62) diff --git a/include/crm/stonith-ng.h b/include/crm/stonith-ng.h index 35f6e5a..7f6938a 100644 --- a/include/crm/stonith-ng.h +++ b/include/crm/stonith-ng.h @@ -348,8 +348,8 @@ void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values); * * At least one of nodeid and uname are required */ -int stonith_api_kick(int nodeid, const char *uname, int timeout, bool off); -time_t stonith_api_time(int nodeid, const char *uname, bool in_progress); +int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off); +time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress); /* * Helpers for using the above functions without install-time dependancies @@ -394,7 +394,7 @@ time_t stonith_api_time(int nodeid, const char *uname, bool in_progress); # define STONITH_LIBRARY "libstonithd.so.2" static inline int -stonith_api_kick_helper(int nodeid, int timeout, bool off) +stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off) { static void *st_library = NULL; static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL; @@ -413,7 +413,7 @@ stonith_api_kick_helper(int nodeid, int timeout, bool off) } static inline time_t -stonith_api_time_helper(int nodeid, bool in_progress) +stonith_api_time_helper(uint32_t nodeid, bool in_progress) { static void *st_library = NULL; static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL; diff --git a/lib/fencing/st_client.c b/lib/fencing/st_client.c index 3c6a7e7..7f2204f 100644 --- a/lib/fencing/st_client.c +++ b/lib/fencing/st_client.c @@ -2361,8 +2361,11 @@ stonith_key_value_freeall(stonith_key_value_t * head, int keys, int values) } } +#define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) +#define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __FUNCTION__, args) + int -stonith_api_kick(int nodeid, const char *uname, int timeout, bool off) +stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off) { char *name = NULL; const char *action = "reboot"; @@ -2371,9 +2374,13 @@ stonith_api_kick(int nodeid, const char *uname, int timeout, bool off) stonith_t *st = NULL; enum stonith_call_options opts = st_opt_sync_call | st_opt_allow_suicide; + api_log_open(); st = stonith_api_new(); if (st) { rc = st->cmds->connect(st, "stonith-api", NULL); + if(rc != pcmk_ok) { + api_log(LOG_ERR, "Connection failed, could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname, pcmk_strerror(rc), rc); + } } if (uname != NULL) { @@ -2390,6 +2397,11 @@ stonith_api_kick(int nodeid, const char *uname, int timeout, bool off) if (rc == pcmk_ok) { rc = st->cmds->fence(st, opts, name, action, timeout, 0); + if(rc != pcmk_ok) { + api_log(LOG_ERR, "Could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname, pcmk_strerror(rc), rc); + } else { + api_log(LOG_NOTICE, "Node %u/%s kicked: %s ", nodeid, uname, action); + } } if (st) { @@ -2402,7 +2414,7 @@ stonith_api_kick(int nodeid, const char *uname, int timeout, bool off) } time_t -stonith_api_time(int nodeid, const char *uname, bool in_progress) +stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress) { int rc = 0; char *name = NULL; @@ -2416,6 +2428,9 @@ stonith_api_time(int nodeid, const char *uname, bool in_progress) st = stonith_api_new(); if (st) { rc = st->cmds->connect(st, "stonith-api", NULL); + if(rc != pcmk_ok) { + api_log(LOG_NOTICE, "Connection failed: %s (%d)", pcmk_strerror(rc), rc); + } } if (uname != NULL) { @@ -2427,18 +2442,31 @@ stonith_api_time(int nodeid, const char *uname, bool in_progress) } if (st && rc == pcmk_ok) { - st->cmds->history(st, st_opt_sync_call | st_opt_cs_nodeid, name, &history, 120); + int entries = 0; + int progress = 0; + int completed = 0; + + rc = st->cmds->history(st, st_opt_sync_call | st_opt_cs_nodeid, name, &history, 120); for (hp = history; hp; hp = hp->next) { + entries++; if (in_progress) { + progress++; if (hp->state != st_done && hp->state != st_failed) { progress = time(NULL); } } else if (hp->state == st_done) { + completed++; when = hp->completed; } } + + if(rc == pcmk_ok) { + api_log(LOG_INFO, "Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed); + } else { + api_log(LOG_ERR, "Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname, pcmk_strerror(rc), rc); + } } if (progress) { @@ -2450,6 +2478,9 @@ stonith_api_time(int nodeid, const char *uname, bool in_progress) stonith_api_delete(st); } + if(when) { + api_log(LOG_INFO, "Node %u/%s last kicked at: %ld", nodeid, uname, (long int)when); + } free(name); return when; }