From 7014486bb727ad8efb517d8eac667cad919ac169 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 3 Oct 2013 22:16:29 +0200 Subject: [PATCH] In sync if a silent error is detect marks the block as bad like in scrub. --- HISTORY | 2 ++ TODO | 6 ++++-- sync.c | 29 ++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/HISTORY b/HISTORY index 6934b6c3..3237d94d 100644 --- a/HISTORY +++ b/HISTORY @@ -10,6 +10,8 @@ SnapRAID HISTORY up to 89 disks with Hexa (6) parity is possible, but not yet implemented. Note that more general approaches without these limitations are also possible, but they would affect badly the performance. + * In sync, if a silent error is found, directly mark the block as bad + just like in scrub, and continue with the sync process. * Sort files by inode when listing the directory. This improves performance in scanning. * Removed the detailed list of errors from the screen output. diff --git a/TODO b/TODO index c7d1a8be..731bb370 100644 --- a/TODO +++ b/TODO @@ -5,12 +5,14 @@ This is the list of TODO items for SnapRAID. - Next -* In sync if a data error is found, we can mark the block as bad, like in scrub -and allow sync to continue. +* Remove/Reduce the opt.gui uses. We can now always output to stdlog becase +it never go to screen. * Detect files moved from one disk to another. We won't be able to reuse parity, but we can reuse the hash to check that the file was moved correctly. +We can assume a file moved to another disk if it has the same name, size, +and timestamp. Directory and inode can be different. * Add a way to list the content of the array. A new "list" command ? Something similar at "diff" and "dup". diff --git a/sync.c b/sync.c index 37265526..cae791b9 100644 --- a/sync.c +++ b/sync.c @@ -122,7 +122,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari for(i=blockstart;iinfoarr, i); @@ -245,7 +247,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* if the file is missing, it means that it was removed during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ - skip_this_block = 1; + error_on_this_block = 1; continue; } else if (errno == EACCES) { fprintf(stderr, "No access at file '%s'.\n", handle[j].path); @@ -279,7 +281,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* if the file is changed, it means that it was modified during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ - skip_this_block = 1; + error_on_this_block = 1; continue; } @@ -307,11 +309,17 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (block_has_updated_hash(block)) { /* compare the hash */ if (memcmp(hash, block->hash, HASH_SIZE) != 0) { + fprintf(stdlog, "error:%u:%s:%s: Data error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); fprintf(stderr, "Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); - fprintf(stderr, "DANGER! Unexpected data error in a data disk, it isn't possible to sync.\n"); - printf("Stopping to allow recovery. Try with 'snapraid -s %u check'\n", i); + fprintf(stderr, "DANGER! Unexpected data error in a data disk! The block is now marked as bad!\n"); + fprintf(stderr, "Try with 'snapraid -e fix' to recover!\n"); + + /* silent errors are very rare, and are not a signal that a disk */ + /* is going to fail. So, we just continue marking the block as bad */ + /* just like in scrub */ ++silent_error; - goto bail; + silent_error_on_this_block = 1; + continue; } } else { /* if until now the parity doesn't need to be update */ @@ -343,8 +351,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } } - /* if we have read all the data required, proceed with the parity */ - if (!skip_this_block) { + /* if we have read all the data required and it's correct, proceed with the parity */ + if (!error_on_this_block && !silent_error_on_this_block) { /* updates the parity only if really needed */ if (parity_needs_to_be_updated) { @@ -402,6 +410,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* we are also clearing any previous bad and rehash flag */ info_set(&state->infoarr, i, info_make(now, 0, 0)); } + } else if (silent_error_on_this_block) { + /* set the error status keeping the existing time and hash */ + info_set(&state->infoarr, i, info_set_bad(info)); } /* mark the state as needing write */