From 81f14d1dfba9358a630a4af46fec27a86c59072b Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 28 Mar 2011 20:55:57 +0200 Subject: [PATCH] The progress estimation not takes care of the actual work to do. --- check.c | 22 +++++++++++++--------- state.c | 12 ++++++------ state.h | 2 +- sync.c | 43 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/check.c b/check.c index b20a07db..fa37a37e 100644 --- a/check.c +++ b/check.c @@ -35,8 +35,9 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity unsigned char* block_buffer; unsigned char* xor_buffer; int ret; - data_off_t count_size; - data_off_t count_block; + data_off_t countsize; + block_off_t countpos; + block_off_t countmax; time_t start; time_t last; unsigned error; @@ -56,11 +57,11 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity unrecoverable_error = 0; recovered_error = 0; - count_size = 0; - count_block = 0; + countmax = blockmax - blockstart; + countsize = 0; + countpos = 0; start = time(0); last = start; - for(i=blockstart;i 5 && count_block > 0) { + if (delta > 5 && countpos > 0) { unsigned m, h; - data_off_t todo = blockmax - blockpos; + data_off_t todo = countmax - countpos; - m = todo * delta / (60 * count_block); + m = todo * delta / (60 * countpos); h = m / 60; m = m % 60; diff --git a/state.h b/state.h index 89fa4cdb..d8721d6c 100644 --- a/state.h +++ b/state.h @@ -81,7 +81,7 @@ void state_check(struct snapraid_state* state, int fix, block_off_t blockstart, /** * Writes the progress. */ -int state_progress(time_t* start, time_t* last, block_off_t blockpos, block_off_t blockmax, data_off_t count_block, data_off_t count_size); +int state_progress(time_t* start, time_t* last, block_off_t countpos, block_off_t countmax, data_off_t countsize); #endif diff --git a/sync.c b/sync.c index 42123388..957f8ece 100644 --- a/sync.c +++ b/sync.c @@ -34,8 +34,9 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_ unsigned j; unsigned char* block_buffer; unsigned char* xor_buffer; - data_off_t count_size; - data_off_t count_block; + data_off_t countsize; + block_off_t countpos; + block_off_t countmax; time_t start; time_t last; int ret; @@ -52,11 +53,32 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_ } unrecoverable_error = 0; - count_size = 0; - count_block = 0; + /* first count the number of blocks to process */ + countmax = 0; + for(i=blockstart;iflag, BLOCK_HAS_HASH | BLOCK_HAS_PARITY)) { + one_invalid = 1; + break; + } + } + + /* if no invalid block skip */ + if (!one_invalid) + continue; + + ++countmax; + } + + countsize = 0; + countpos = 0; start = time(0); last = start; - for(i=blockstart;ineed_write = 1; /* count the number of processed block */ - ++count_block; + ++countpos; /* progress */ - if (state_progress(&start, &last, i, blockmax, count_block, count_size)) { + if (state_progress(&start, &last, countpos, countmax, countsize)) { printf("Stopping for interruption at block %u\n", i); break; } } - printf("%u%% completed, %u MiB processed\n", i * 100 / blockmax, (unsigned)(count_size / (1024*1024))); + if (countmax) + printf("%u%% completed, %u MiB processed\n", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024))); + else + printf("Nothing to do\n"); bail: for(j=0;j