diff --git a/HISTORY b/HISTORY index 2d98b520..2ab41025 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,7 @@ SnapRAID HISTORY ================ -6.0 2014/1 (BETA) +6.0 2014/2 (BETA) ================= * In "sync", even if a silent error is found, continue to update the parity if it's possible to correct the error. @@ -10,13 +10,18 @@ SnapRAID HISTORY But any new data added will be protected if you are using enough parity to fix both the silent error and at least another potential error. + * In "sync" run a preliminary hashing step for all the new files, + to ensure to detect silent errors caused by the heavy machine usage + of the parity computation. + You can disable this additional hashing with the new "rawsync" + configuration option. * In "fix", if a previous attempt was made, resulting in a .unrecoverable file, uses this file as starting point for the new attempt. * New source code organization. The RAID engine is now an external component usable also in other projects. -5.3 2014/1 (BETA) +5.3 2014/2 (BETA) ================= * Don't warn about UUID changed if it's for an empty disk. diff --git a/Makefile.am b/Makefile.am index 08dd01ac..944ec2f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -396,11 +396,22 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-unrecoverable -c $(PAR2) fix -l test.log rm -r test/disk1/a_copy $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync + echo --- Abort sync late with additions with rawsync and then delete the new additions and sync again + cp -pR test/disk1/a test/disk1/a_copy + cp -pR test/disk2/a test/disk2/a_copy + cp -pR test/disk3/a test/disk3/a_copy + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-kill-after-sync --test-rawsync -c $(CONF) sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check + rm -r test/disk1/a_copy + rm -r test/disk2/a_copy + rm -r test/disk3/a_copy + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync echo --- Abort sync late with additions and then delete the new additions and sync again cp -pR test/disk1/a test/disk1/a_copy cp -pR test/disk2/a test/disk2/a_copy cp -pR test/disk3/a test/disk3/a_copy $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-kill-after-sync -c $(CONF) sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check rm -r test/disk1/a_copy rm -r test/disk2/a_copy rm -r test/disk3/a_copy diff --git a/TODO b/TODO index 8c6f332f..5297ae2b 100644 --- a/TODO +++ b/TODO @@ -30,21 +30,6 @@ as search base. * Avoid to do optimized move operation if more files with same timestamp/size are present. -* Handle new files with a two steps approach to reduce possible -silent errors. -We can first hash them, proceding one disk at time, and then -start computing the parity checking the precomputed hash. -This imply a double read, likely doubling the sync time, -but ensure that the hash are computed with the system not busy, -avoiding to trigger silent errors depending on the usage level. -This will also improve the cases of a crash during sync, because -we already have all the hashes when sync starts. -We need to extend the NEW blocks with an hash, likely using -the dummy 0 hash as marker for no hash. -And create a new block type REP (replaced) where the -hash is intented to match the new block and not the -previous one like for CHG blocks. - - Minor * In the content file save the timestap of the parity files. diff --git a/check.c b/check.c index 9007c5da..84868592 100644 --- a/check.c +++ b/check.c @@ -797,9 +797,6 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, failed[failed_count].block = block; failed[failed_count].handle = &handle[j]; ++failed_count; - - 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)); - ++error; continue; } } diff --git a/maketest.sh b/maketest.sh index 9942239f..a0c74db4 100755 --- a/maketest.sh +++ b/maketest.sh @@ -31,7 +31,3 @@ if ! ./configure ; then exit 1 fi -if ! make check; then - exit 1 -fi - diff --git a/snapraid.1 b/snapraid.1 index a4db60e4..5cd2d262 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -974,6 +974,17 @@ commands interrupted by a machine crash, or any other event that may interrupt SnapRAID. The SIZE argument is specified in gibibytes. Where one gibi bytes is 1073741824 bytes. +.SS rawsync +Enables a single pass \(a"sync\(a" process avoding the initial hashing phase +and saving time. +In this mode no preliminary hashing is done, and the new data is hashed +directly during the parity computation when it\(cqs read for the first time, +This happens when the system is under heavy pressure due all disks spinning +and CPU busy, and in such extreme conditions, if your machine has a latent +hardware problem, it\(cqs possible to encouter silent errors what cannot be +detected because the data is not yet hashed. +To avoid this problem, this \(a"rawsync\(a" mode is by default disabled, +but if you really trust your hardware, you can enable it, and save time. .SS pool DIR Defines the pooling directory where the virtual view of the disk array is created using the \(a"pool\(a" command. diff --git a/snapraid.c b/snapraid.c index 0b3b107e..ab5c44b3 100644 --- a/snapraid.c +++ b/snapraid.c @@ -104,6 +104,7 @@ void memory(void) #define OPT_TEST_FORCE_SCRUB_EVEN 272 #define OPT_TEST_FORCE_CONTENT_WRITE 273 #define OPT_TEST_FORCE_CONTENT_TEXT 274 +#define OPT_TEST_RAWSYNC 275 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -185,6 +186,9 @@ struct option long_options[] = { /* Force the use of text content file . */ { "test-force-content-text", 0, 0, OPT_TEST_FORCE_CONTENT_TEXT }, + /* Like the rawsync configuration option. */ + { "test-rawsync", 0, 0, OPT_TEST_RAWSYNC }, + { 0, 0, 0, 0 } }; #endif @@ -435,6 +439,9 @@ int main(int argc, char* argv[]) case OPT_TEST_FORCE_CONTENT_TEXT : opt.force_content_text = 1; break; + case OPT_TEST_RAWSYNC : + opt.rawsync = 1; + break; default: fprintf(stderr, "Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); diff --git a/snapraid.conf.example b/snapraid.conf.example index 80d8d46e..3ec4b54a 100644 --- a/snapraid.conf.example +++ b/snapraid.conf.example @@ -63,6 +63,20 @@ exclude /lost+found/ # Format: "autosave SIZE_IN_GiB" #autosave 500 +# Enables a single pass "sync" process avoding the initial hashing phase +# and saving time. +# In this mode no preliminary hashing is done, and the new data is hashed +# directly during the parity computation when it's read for the first time, +# This happens when the system is under heavy pressure due all disks spinning +# and CPU busy, and in such extreme conditions, if your machine has a latent +# hardware problem, it's possible to encouter silent errors what cannot be +# detected because the data is not yet hashed. +# To avoid this problem, this "rawsync" mode is by default disabled, +# but if you really trust your hardware, you can enable it, and save time. +# +# Format: rawsync +#rawsync + # Defines the pooling directory where the virtual view of the disk # array is created using the "pool" command (uncomment to enable). # The files are not really copied here, but just linked using diff --git a/snapraid.conf.example.windows b/snapraid.conf.example.windows index 271ac88f..10fc35db 100644 --- a/snapraid.conf.example.windows +++ b/snapraid.conf.example.windows @@ -67,6 +67,20 @@ exclude \Windows\ # Format: "autosave SIZE_IN_GiB" #autosave 500 +# Enables a single pass "sync" process avoding the initial hashing phase +# and saving time. +# In this mode no preliminary hashing is done, and the new data is hashed +# directly during the parity computation when it's read for the first time, +# This happens when the system is under heavy pressure due all disks spinning +# and CPU busy, and in such extreme conditions, if your machine has a latent +# hardware problem, it's possible to encouter silent errors what cannot be +# detected because the data is not yet hashed. +# To avoid this problem, this "rawsync" mode is by default disabled, +# but if you really trust your hardware, you can enable it, and save time. +# +# Format: rawsync +#rawsync + # Defines the pooling directory where the virtual view of the disk # array is created using the "pool" command (uncomment to enable). # The files are not really copied here, but just linked using diff --git a/snapraid.d b/snapraid.d index 07f3dd9a..3a39fe00 100644 --- a/snapraid.d +++ b/snapraid.d @@ -742,6 +742,18 @@ Configuration The SIZE argument is specified in gibibytes. Where one gibi bytes is 1073741824 bytes. + rawsync + Enables a single pass "sync" process avoding the initial hashing phase + and saving time. + In this mode no preliminary hashing is done, and the new data is hashed + directly during the parity computation when it's read for the first time, + This happens when the system is under heavy pressure due all disks spinning + and CPU busy, and in such extreme conditions, if your machine has a latent + hardware problem, it's possible to encouter silent errors what cannot be + detected because the data is not yet hashed. + To avoid this problem, this "rawsync" mode is by default disabled, + but if you really trust your hardware, you can enable it, and save time. + pool DIR Defines the pooling directory where the virtual view of the disk array is created using the "pool" command. diff --git a/snapraid.txt b/snapraid.txt index d0a57fb2..5567ac07 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -806,13 +806,25 @@ may interrupt SnapRAID. The SIZE argument is specified in gibibytes. Where one gibi bytes is 1073741824 bytes. ----- 7.8.2 pool DIR ---- +---- 7.8.2 rawsync ---- +Enables a single pass "sync" process avoding the initial hashing phase +and saving time. +In this mode no preliminary hashing is done, and the new data is hashed +directly during the parity computation when it's read for the first time, +This happens when the system is under heavy pressure due all disks spinning +and CPU busy, and in such extreme conditions, if your machine has a latent +hardware problem, it's possible to encouter silent errors what cannot be +detected because the data is not yet hashed. +To avoid this problem, this "rawsync" mode is by default disabled, +but if you really trust your hardware, you can enable it, and save time. + +---- 7.8.3 pool DIR ---- Defines the pooling directory where the virtual view of the disk array is created using the "pool" command. The directory must already exist. ----- 7.8.3 share UNC_DIR ---- +---- 7.8.4 share UNC_DIR ---- Defines the Windows UNC path required to access the disks remotely. If this option is specified, the symbolic links created in the pool diff --git a/state.c b/state.c index 2b9ca7a0..342e720d 100644 --- a/state.c +++ b/state.c @@ -597,6 +597,8 @@ void state_config(struct snapraid_state* state, const char* path, const char* co tommy_list_insert_tail(&state->disklist, &disk->node, disk); } else if (strcmp(tag, "nohidden") == 0) { state->filter_hidden = 1; + } else if (strcmp(tag, "rawsync") == 0) { + state->opt.rawsync = 1; } else if (strcmp(tag, "exclude") == 0) { struct snapraid_filter* filter; diff --git a/state.h b/state.h index a1e34bb4..c6eae279 100644 --- a/state.h +++ b/state.h @@ -59,6 +59,7 @@ struct snapraid_option { int verbose; /**< Verbose output. */ int quiet; /**< Quiet output. */ int gui; /**< Gui output. */ + int rawsync; /**< Enables the raw sync mode. */ int force_zero; /**< Forced dangerous operations of synching files now with zero size. */ int force_empty; /**< Forced dangerous operations of synching disks now empty. */ int force_uuid; /**< Forced dangerous operations of synching disks with uuid changed. */ diff --git a/sync.c b/sync.c index e6078073..92c9dee7 100644 --- a/sync.c +++ b/sync.c @@ -24,6 +24,255 @@ #include "handle.h" #include "raid/raid.h" +/****************************************************************************/ +/* hash */ + +static void state_hash_process(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax) +{ + struct snapraid_handle* handle; + unsigned diskmax; + block_off_t i; + unsigned j; + void* buffer; + data_off_t countsize; + block_off_t countpos; + block_off_t countmax; + int ret; + unsigned error; + + /* maps the disks to handles */ + handle = handle_map(state, &diskmax); + + /* buffer for reading */ + buffer = malloc_nofail(state->block_size); + + error = 0; + + /* first count the number of blocks to process */ + countmax = 0; + for(j=0;jinfoarr, i); + + /* if we have to use the old hash */ + rehash = info_get_rehash(info); + + /* if the file is different than the current one, close it */ + if (handle[j].file != 0 && handle[j].file != block_file_get(block)) { + /* keep a pointer at the file we are going to close for error reporting */ + struct snapraid_file* file = handle[j].file; + ret = handle_close(&handle[j]); + if (ret == -1) { + /* This one is really an unexpected error, because we are only reading */ + /* and closing a descriptor should never fail */ + fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, handle[j].disk->name, file->sub, strerror(errno)); + fprintf(stderr, "DANGER! Unexpected close error in a data disk, it isn't possible to sync.\n"); + fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", handle[j].disk->dir, handle[j].path); + printf("Stopping at block %u\n", i); + ++error; + goto bail; + } + } + + ret = handle_open(&handle[j], block_file_get(block), state->opt.skip_sequential, stderr); + if (ret == -1) { + /* file we have tried to open for error reporting */ + struct snapraid_file* file = block_file_get(block); + if (errno == ENOENT) { + fprintf(stdlog, "error:%u:%s:%s: Open missing error\n", i, handle[j].disk->name, file->sub); + fprintf(stderr, "Missing file '%s'.\n", handle[j].path); + fprintf(stderr, "WARNING! You cannot modify data disk during a sync.\n"); + fprintf(stderr, "Rerun the sync command when finished.\n"); + + ++error; + + /* 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 */ + continue; + } else if (errno == EACCES) { + fprintf(stdlog, "error:%u:%s:%s: Open access error\n", i, handle[j].disk->name, file->sub); + fprintf(stderr, "No access at file '%s'.\n", handle[j].path); + fprintf(stderr, "WARNING! Please fix the access permission in the data disk.\n"); + fprintf(stderr, "Rerun the sync command when finished.\n"); + + ++error; + + /* this isn't a serious error, so we skip this block, and continue with others */ + continue; + } else { + fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, handle[j].disk->name, file->sub, strerror(errno)); + fprintf(stderr, "DANGER! Unexpected open error in a data disk, it isn't possible to sync.\n"); + fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", handle[j].disk->dir, handle[j].path); + printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + } + + ++error; + goto bail; + } + + /* check if the file is changed */ + if (handle[j].st.st_size != block_file_get(block)->size + || handle[j].st.st_mtime != block_file_get(block)->mtime_sec + || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec + || handle[j].st.st_ino != block_file_get(block)->inode + ) { + fprintf(stdlog, "error:%u:%s:%s: Unexpected change\n", i, handle[j].disk->name, handle[j].file->sub); + if (handle[j].st.st_size != block_file_get(block)->size) + fprintf(stderr, "Unexpected size change at file '%s' from %"PRIu64" to %"PRIu64".\n", handle[j].path, block_file_get(block)->size, handle[j].st.st_size); + else if (handle[j].st.st_mtime != block_file_get(block)->mtime_sec + || STAT_NSEC(&handle[j].st) != block_file_get(block)->mtime_nsec) { + fprintf(stderr, "Unexpected time change at file '%s' from %"PRIu64".%d to %"PRIu64".%d.\n", handle[j].path, block_file_get(block)->mtime_sec, block_file_get(block)->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + } else { + fprintf(stderr, "Unexpected inode change from %"PRIu64" to %"PRIu64" at file '%s'.\n", block_file_get(block)->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + } + fprintf(stderr, "WARNING! You cannot modify files during a sync.\n"); + fprintf(stderr, "Rerun the sync command when finished.\n"); + + ++error; + + /* 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 */ + continue; + } + + read_size = handle_read(&handle[j], block, buffer, state->block_size, stderr); + if (read_size == -1) { + fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, handle[j].file->sub, block_file_pos(block)); + fprintf(stderr, "DANGER! Unexpected read error in a data disk, it isn't possible to sync.\n"); + fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be read.\n", handle[j].disk->dir, handle[j].path); + printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", handle[j].file->sub); + ++error; + goto bail; + } + + countsize += read_size; + + /* now compute the hash */ + if (rehash) { + memhash(state->prevhash, state->prevhashseed, hash, buffer, read_size); + } else { + memhash(state->hash, state->hashseed, hash, buffer, read_size); + } + + /* copy the hash in the block */ + memcpy(block->hash, hash, HASH_SIZE); + + /* and mark the block as hashed */ + block_state_set(block, BLOCK_STATE_REP); + + /* mark the state as needing write */ + state->need_write = 1; + + /* count the number of processed block */ + ++countpos; + + /* progress */ + if (state_progress(state, i, countpos, countmax, countsize)) { + break; + } + } + + /* close the last file in the disk */ + if (handle[j].file != 0) { + /* keep a pointer at the file we are going to close for error reporting */ + struct snapraid_file* file = handle[j].file; + ret = handle_close(&handle[j]); + + if (ret == -1) { + /* This one is really an unexpected error, because we are only reading */ + /* and closing a descriptor should never fail */ + fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", blockmax, handle[j].disk->name, file->sub, strerror(errno)); + fprintf(stderr, "DANGER! Unexpected close error in a data disk, it isn't possible to sync.\n"); + fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", handle[j].disk->dir, handle[j].path); + printf("Stopping at block %u\n", blockmax); + ++error; + goto bail; + } + } + } + + state_progress_end(state, countpos, countmax, countsize); + + if (error) { + printf("\n"); + printf("%8u read/write errors\n", error); + printf("WARNING! There are errors!\n"); + } else { + /* print the result only if processed something */ + if (countpos != 0) + printf("Everything OK\n"); + } + + fprintf(stdlog, "hash_summary:error_readwrite:%u\n", error); + +bail: + for(j=0;jopt.rawsync) { + printf("Hashing...\n"); + + state_hash_process(state, blockstart, blockmax); + + if (state->need_write) + state_write(state); + } + printf("Syncing...\n"); unrecoverable_error = 0;