From 27d1137e26703d7fa5fba638e56961384a140eb2 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jun 2014 14:52:19 +1000 Subject: ctdb-logging: Split ringbuffer handling code from ctdb_collect_log Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/ctdb_logging.c | 28 +++++++++++++++++++++------- ctdb/include/ctdb_private.h | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index baaf7007993..03ac2689581 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -103,7 +103,8 @@ void ctdb_log_ringbuffer_free(void) log_ringbuf_size = 0; } -void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr) +TDB_DATA ctdb_log_ringbuffer_collect_log(TALLOC_CTX *mem_ctx, + enum debug_level max_level) { TDB_DATA data; FILE *f; @@ -118,14 +119,15 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a /* dump to a file, then send the file as a blob */ f = tmpfile(); if (f == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", strerror(errno))); - return; + DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", + strerror(errno))); + return tdb_null; } for (i=0; i log_addr->level) { + if (log_entries[tmp_entry].level > max_level) { continue; } @@ -143,23 +145,35 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a if (fsize < 0) { fclose(f); DEBUG(DEBUG_ERR, ("Cannot get file size for log entries\n")); - return; + return tdb_null; } rewind(f); data.dptr = talloc_size(NULL, fsize); if (data.dptr == NULL) { fclose(f); - CTDB_NO_MEMORY_VOID(ctdb, data.dptr); + DEBUG(DEBUG_ERR, (__location__ " Memory allocation error\n")); + return tdb_null; } data.dsize = fread(data.dptr, 1, fsize, f); fclose(f); DEBUG(DEBUG_ERR,("Marshalling log entries into a blob of %d bytes\n", (int)data.dsize)); + return data; +} + +void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr) +{ + TDB_DATA data; + + data = ctdb_log_ringbuffer_collect_log(ctdb, log_addr->level); + DEBUG(DEBUG_ERR,("Send log to %d:%d\n", (int)log_addr->pnn, (int)log_addr->srvid)); ctdb_client_send_message(ctdb, log_addr->pnn, log_addr->srvid, data); - talloc_free(data.dptr); + if (data.dptr) { + talloc_free(data.dptr); + } } int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr) diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 9e87976419d..0481e434297 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1458,6 +1458,8 @@ struct ctdb_get_log_addr { extern int log_ringbuf_size; +TDB_DATA ctdb_log_ringbuffer_collect_log(TALLOC_CTX *mem_ctx, + enum debug_level max_level); void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr); void ctdb_clear_log(struct ctdb_context *ctdb); int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr); -- cgit