mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
The progress estimation not takes care of the actual work to do.
This commit is contained in:
parent
e17b505c90
commit
81f14d1dfb
4 changed files with 54 additions and 25 deletions
22
check.c
22
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<blockmax;++i) {
|
||||
int failed;
|
||||
struct snapraid_block* failed_block;
|
||||
|
|
@ -172,7 +173,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
|||
/* compute the parity */
|
||||
memxor(xor_buffer, block_buffer, read_size);
|
||||
|
||||
count_size += read_size;
|
||||
countsize += read_size;
|
||||
}
|
||||
|
||||
if (parity_f == -1 || !all_parity) {
|
||||
|
|
@ -271,16 +272,19 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
|||
}
|
||||
|
||||
/* 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<diskmax;++j) {
|
||||
|
|
|
|||
12
state.c
12
state.c
|
|
@ -512,7 +512,7 @@ void state_write(struct snapraid_state* state)
|
|||
|
||||
#define PROGRESS_CLEAR " "
|
||||
|
||||
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)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
|
|
@ -521,17 +521,17 @@ int state_progress(time_t* start, time_t* last, block_off_t blockpos, block_off_
|
|||
if (*last != now) {
|
||||
time_t delta = now - *start;
|
||||
|
||||
printf("%u%%, %u MiB", blockpos * 100 / blockmax, (unsigned)(count_size / (1024*1024)));
|
||||
printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024)));
|
||||
|
||||
if (delta != 0) {
|
||||
printf(", %u MiB/s", (unsigned)(count_size / (1024*1024) / delta));
|
||||
printf(", %u MiB/s", (unsigned)(countsize / (1024*1024) / delta));
|
||||
}
|
||||
|
||||
if (delta > 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;
|
||||
|
|
|
|||
2
state.h
2
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
|
||||
|
||||
|
|
|
|||
43
sync.c
43
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;i<blockmax;++i) {
|
||||
int one_invalid;
|
||||
|
||||
/* for each disk */
|
||||
one_invalid = 0;
|
||||
for(j=0;j<diskmax;++j) {
|
||||
struct snapraid_block* block = disk_block_get(handle[j].disk, i);
|
||||
if (block && !bit_has(block->flag, 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;i<blockmax;++i) {
|
||||
int one_invalid;
|
||||
int ret;
|
||||
|
|
@ -157,7 +179,7 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_
|
|||
/* compute the parity */
|
||||
memxor(xor_buffer, block_buffer, read_size);
|
||||
|
||||
count_size += read_size;
|
||||
countsize += read_size;
|
||||
}
|
||||
|
||||
/* write the parity */
|
||||
|
|
@ -184,16 +206,19 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_
|
|||
state->need_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<diskmax;++j) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue