From 4030b18d400184d39d6c404aec38890d17633612 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 10 Nov 2015 21:27:56 +0100 Subject: [PATCH] Show differently scrubbed and new blocks in the graph --- HISTORY | 2 ++ cmdline/status.c | 76 +++++++++++++++++++++++++++++++----------------- snapraid.1 | 4 +++ snapraid.d | 4 +++ snapraid.txt | 4 +++ 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/HISTORY b/HISTORY index 497aac0b..07a895d6 100644 --- a/HISTORY +++ b/HISTORY @@ -20,6 +20,8 @@ SnapRAID HISTORY command to show the amount blocks not yet scrubbed. The "bad" scrubs only bad blocks. The "full" scrubs all blocks. + * The graph in the "status" command now show scrubbed blocks + with '*' and synced, but not yet scrubbed, blocks with 'o'. * Content files are now written asyncronously from different threads to avoid the unfortunate condition that a memory error affects all of them in the same way. diff --git a/cmdline/status.c b/cmdline/status.c index a3a951ed..e418be63 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -43,6 +43,11 @@ static unsigned perc(uint64_t part, uint64_t total) return (unsigned)(part * 100 / total); } +/** + * Bit used to mark unscrubbed time info. + */ +#define TIME_NEW 1 + int state_status(struct snapraid_state* state) { block_off_t blockmax; @@ -56,7 +61,8 @@ int state_status(struct snapraid_state* state) block_off_t count; unsigned l; unsigned dayoldest, daymedian, daynewest; - unsigned bar[GRAPH_COLUMN]; + unsigned bar_scrubbed[GRAPH_COLUMN]; + unsigned bar_new[GRAPH_COLUMN]; unsigned barpos; unsigned barmax; time_t oldest, newest, median; @@ -296,6 +302,8 @@ int state_status(struct snapraid_state* state) /* skip unused blocks */ if (info != 0) { + time_t scrub_time; + if (info_get_bad(info)) { if (bad == 0) bad_first = i; @@ -306,10 +314,16 @@ int state_status(struct snapraid_state* state) if (info_get_rehash(info)) ++rehash; - if (info_get_justsynced(info)) + scrub_time = info_get_time(info); + + if (info_get_justsynced(info)) { ++unscrubbed_blocks; - timemap[count++] = info_get_time(info); + /* mark the time as not scrubbed */ + scrub_time |= TIME_NEW; + } + + timemap[count++] = scrub_time; } if (state->opt.gui) { @@ -342,7 +356,11 @@ int state_status(struct snapraid_state* state) unsigned j = i + 1; while (j < count && timemap[i] == timemap[j]) ++j; - log_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)timemap[i], j - i); + if ((timemap[i] & TIME_NEW) == 0) { + log_tag("info_time:%" PRIu64 ":%u:scrubbed\n", (uint64_t)timemap[i], j - i); + } else { + log_tag("info_time:%" PRIu64 ":%u:new\n", (uint64_t)(timemap[i] & ~TIME_NEW), j - i); + } i = j; } @@ -358,20 +376,25 @@ int state_status(struct snapraid_state* state) barmax = 0; for (i = 0; i < GRAPH_COLUMN; ++i) { time_t limit; - unsigned step; + unsigned step_scrubbed, step_new; limit = oldest + (newest - oldest) * (i + 1) / GRAPH_COLUMN; - step = 0; + step_scrubbed = 0; + step_new = 0; while (barpos < count && timemap[barpos] <= limit) { ++barpos; - ++step; + if ((timemap[barpos] & TIME_NEW) != 0) + ++step_new; + else + ++step_scrubbed; } - if (step > barmax) - barmax = step; + if (step_new + step_scrubbed > barmax) + barmax = step_new + step_scrubbed; - bar[i] = step; + bar_scrubbed[i] = step_scrubbed; + bar_new[i] = step_new; } printf("\n\n"); @@ -387,25 +410,26 @@ int state_status(struct snapraid_state* state) else printf(" |"); for (x = 0; x < GRAPH_COLUMN; ++x) { - unsigned pivot = barmax * (GRAPH_ROW - y) / GRAPH_ROW; - /* if it's the baseline */ - if (y == GRAPH_ROW - 1) { - if (bar[x] >= pivot) { + unsigned pivot_upper = barmax * (GRAPH_ROW - y) / GRAPH_ROW; + unsigned pivot_lower = barmax * (GRAPH_ROW - 1 - y) / GRAPH_ROW; + unsigned both = bar_scrubbed[x] + bar_new[x]; + unsigned scrubbed = bar_scrubbed[x]; + + if (both > pivot_upper) { + if (scrubbed > pivot_lower) printf("*"); - } else if (bar[x] > 0) { - printf("+"); - } else { - printf("_"); - } + else + printf("o"); + } else if (both > pivot_lower) { + if (scrubbed == both) + printf("*"); + else + printf("o"); } else { - unsigned halfpivot = pivot - barmax / GRAPH_ROW / 2; - if (bar[x] >= pivot) { - printf("*"); - } else if (bar[x] >= halfpivot) { - printf("+"); - } else { + if (y == GRAPH_ROW - 1) + printf("_"); + else printf(" "); - } } } printf("\n"); diff --git a/snapraid.1 b/snapraid.1 index 67b1b882..c2c73d65 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -674,6 +674,10 @@ run \[dq]sync\[dq]. Later modifications are not taken into account. If bad blocks were detected, their block numbers are listed. To fix them, you can use the \[dq]fix \-e\[dq] command. .PP +It also shows a graph representing the the last time each block +was scrubbed or synced. Scrubbed blocks are shown with \'*\', +blocks synced but not yet scrubbed with \'o\'. +.PP Nothing is modified. .SS smart Prints a SMART report of all the disks of the array. diff --git a/snapraid.d b/snapraid.d index c376ff57..cfef2aa8 100644 --- a/snapraid.d +++ b/snapraid.d @@ -391,6 +391,10 @@ Commands If bad blocks were detected, their block numbers are listed. To fix them, you can use the "fix -e" command. + It also shows a graph representing the the last time each block + was scrubbed or synced. Scrubbed blocks are shown with '*', + blocks synced but not yet scrubbed with 'o'. + Nothing is modified. smart diff --git a/snapraid.txt b/snapraid.txt index db1a8fd2..8439ffaa 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -417,6 +417,10 @@ run "sync". Later modifications are not taken into account. If bad blocks were detected, their block numbers are listed. To fix them, you can use the "fix -e" command. +It also shows a graph representing the the last time each block +was scrubbed or synced. Scrubbed blocks are shown with '*', +blocks synced but not yet scrubbed with 'o'. + Nothing is modified. 5.2 smart