From 73e532326170518e4ec8e42f09dbde6c8643a445 Mon Sep 17 00:00:00 2001 From: "Liu, Xinwu" Date: Tue, 19 Feb 2019 15:39:35 +0800 Subject: [PATCH] tools: acrn-crashlog: stop only collecting logs when exceeding configured size Crashlog would drop all events after the storaged log size exceeds the configured parameter "foldersize" previously, that basically means all activities are stopped. This patch brings other activities back (e.g. the records in the file "history_event" will be updated continually), and restricts the "foldersize" by stopping log collection. Tracked-On: #1024 Signed-off-by: Liu, Xinwu Reviewed-by: Zhi Jin Acked-by: Chen, Gang --- tools/acrn-crashlog/acrnprobe/event_handler.c | 35 -------- .../acrnprobe/include/load_conf.h | 1 - tools/acrn-crashlog/acrnprobe/sender.c | 88 ++++++++++--------- 3 files changed, 48 insertions(+), 76 deletions(-) diff --git a/tools/acrn-crashlog/acrnprobe/event_handler.c b/tools/acrn-crashlog/acrnprobe/event_handler.c index 2c21eb5db..19b085570 100644 --- a/tools/acrn-crashlog/acrnprobe/event_handler.c +++ b/tools/acrn-crashlog/acrnprobe/event_handler.c @@ -126,38 +126,6 @@ static void watchdog_init(int timeout) } } -static int check_folder_space(struct sender_t *sender) -{ - size_t dsize; - int cfg_size; - - if (dir_size(sender->outdir, sender->outdir_len, &dsize) == -1) { - LOGE("failed to check outdir size, drop ev\n"); - return -1; - } - - if (cfg_atoi(sender->foldersize, sender->foldersize_len, - &cfg_size) == -1) - return -1; - - if (dsize/MB >= (size_t)cfg_size) { - if (sender->suspending) - return -1; - - LOGW("suspend (%s), since (%s: %ldM) meets quota (%dM)\n", - sender->name, sender->outdir, dsize/MB, cfg_size); - sender->suspending = 1; - return -1; - } - - if (!sender->suspending) - return 0; - - LOGW("resume (%s), %s: left space %ldM for storage\n", - sender->name, sender->outdir, cfg_size - dsize/MB); - return 0; -} - /** * Process each event in event queue. * Note that currently event handler is single threaded. @@ -191,9 +159,6 @@ static void *event_handle(void *unused __attribute__((unused))) if (!sender) continue; - if (check_folder_space(sender) == -1) - continue; - if (sender->send) sender->send(e); } diff --git a/tools/acrn-crashlog/acrnprobe/include/load_conf.h b/tools/acrn-crashlog/acrnprobe/include/load_conf.h index 664c6ccd5..b12c591f5 100644 --- a/tools/acrn-crashlog/acrnprobe/include/load_conf.h +++ b/tools/acrn-crashlog/acrnprobe/include/load_conf.h @@ -132,7 +132,6 @@ struct sender_t { void (*send)(struct event_t *); char *log_vmrecordid; int sw_updated; /* each sender has their own record */ - int suspending; /* drop all events while suspending */ }; struct conf_t { diff --git a/tools/acrn-crashlog/acrnprobe/sender.c b/tools/acrn-crashlog/acrnprobe/sender.c index b0dffe1a3..d4421111d 100644 --- a/tools/acrn-crashlog/acrnprobe/sender.c +++ b/tools/acrn-crashlog/acrnprobe/sender.c @@ -39,6 +39,39 @@ struct telemd_data_t { }; #endif +static int crashlog_check_space(void) +{ + struct sender_t *crashlog = get_sender_by_name("crashlog"); + int quota; + size_t dsize; + int cfg_size; + + + if (!crashlog) + return -1; + + if (cfg_atoi(crashlog->spacequota, crashlog->spacequota_len, + "a) == -1) + return -1; + + if (!space_available(crashlog->outdir, quota)) + return -1; + + if (dir_size(crashlog->outdir, crashlog->outdir_len, &dsize) == -1) { + LOGE("failed to check outdir size\n"); + return -1; + } + + if (cfg_atoi(crashlog->foldersize, crashlog->foldersize_len, + &cfg_size) == -1) + return -1; + + if (dsize/MB >= (size_t)cfg_size) + return -1; + + return 0; +} + static int cal_log_filepath(char **out, const struct log_t *log, const char *srcname, const char *desdir) { @@ -273,27 +306,15 @@ send_nologs: static void crashlog_get_log(struct log_t *log, void *data) { - struct sender_t *crashlog; unsigned long long start, end; int spent; - int quota; int res; char *des; char *desdir = (char *)data; - crashlog = get_sender_by_name("crashlog"); - if (!crashlog) + if (crashlog_check_space() == -1) return; - if (cfg_atoi(crashlog->spacequota, crashlog->spacequota_len, - "a) == -1) - return; - - if (!space_available(crashlog->outdir, quota)) { - hist_raise_infoerror("SPACE_FULL", 10); - return; - } - start = get_uptime(); if (is_ac_filefmt(log->path)) { int i; @@ -746,17 +767,12 @@ static void crashlog_send_crash(struct event_t *e) char *data0; char *data1; char *data2; - int quota; size_t d0len; size_t d1len; size_t d2len; char *trfile = NULL; - struct sender_t *crashlog = get_sender_by_name("crashlog"); struct crash_t *rcrash = (struct crash_t *)e->private; - if (!crashlog) - return; - if (!strcmp(rcrash->trigger->type, "dir")) { if (asprintf(&trfile, "%s/%s", rcrash->trigger->path, e->path) == -1) { @@ -785,13 +801,8 @@ static void crashlog_send_crash(struct event_t *e) } /* check space before collecting logs */ - if (cfg_atoi(crashlog->spacequota, crashlog->spacequota_len, - "a) == -1) - goto free_key; - - if (!space_available(crashlog->outdir, quota)) { - hist_raise_infoerror("SPACE_FULL", 10); - hist_raise_event("CRASH", crash->name, NULL, "", key); + if (crashlog_check_space() == -1) { + hist_raise_event("CRASH", crash->name, "SPACE_FULL", "", key); goto free_key; } @@ -869,6 +880,13 @@ static void crashlog_send_info(struct event_t *e) } if (to_collect_logs(info)) { + /* check space before collecting logs */ + if (crashlog_check_space() == -1) { + hist_raise_event("INFO", info->name, "SPACE_FULL", "", + key); + goto free_key; + } + e->dir = generate_log_dir(MODE_STATS, key); if (e->dir == NULL) { LOGE("generate crashlog dir failed\n"); @@ -931,7 +949,6 @@ static void crashlog_send_reboot(void) static int crashlog_new_vmevent(const char *line_to_sync, size_t len, const struct vm_t *vm) { - struct sender_t *crashlog; char event[ANDROID_WORD_LEN]; char longtime[ANDROID_WORD_LEN]; char type[ANDROID_WORD_LEN]; @@ -942,7 +959,6 @@ static int crashlog_new_vmevent(const char *line_to_sync, char *log; int ret = VMEVT_HANDLED; int res; - int quota; int cnt; char *dir; @@ -966,19 +982,6 @@ static int crashlog_new_vmevent(const char *line_to_sync, return ret; } - crashlog = get_sender_by_name("crashlog"); - if (!crashlog) - return ret; - - if (cfg_atoi(crashlog->spacequota, crashlog->spacequota_len, - "a) == -1) - return ret; - - if (!space_available(crashlog->outdir, quota)) { - hist_raise_infoerror("SPACE_FULL", 10); - return ret; - } - key = generate_event_id("SOS", 3, (const char *)vmkey, strnlen(vmkey, ANDROID_WORD_LEN), KEY_SHORT); if (key == NULL) { @@ -987,6 +990,11 @@ static int crashlog_new_vmevent(const char *line_to_sync, return VMEVT_DEFER; } + if (crashlog_check_space() == -1) { + hist_raise_event(vm->name, type, "SPACE_FULL", "", key); + goto free_key; + } + dir = generate_log_dir(MODE_VMEVENT, key); if (dir == NULL) { LOGE("generate crashlog dir failed\n");