From 0d231038ffd558665c6f3f448b6f140da2a6404d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 7 Apr 2014 23:12:40 +0200 Subject: [PATCH] Extends the sync regression test to cover error conditions. --- Makefile.am | 32 ++++++++++++++++++++++++++++++++ cmdline/snapraid.c | 20 ++++++++++++++++++++ cmdline/sync.c | 13 +++++++------ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9a7beb9b..d662e3e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -246,6 +246,38 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub 100000 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status + echo --- Modify files during a sync + echo RUN > bench/disk1/RUN-RM + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "rm bench/disk1/RUN-RM" --test-expect-failure sync + echo RUN > bench/disk1/RUN-CHMOD + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "chmod a-r bench/disk1/RUN-CHMOD" --test-expect-failure sync + echo RUN > bench/disk1/RUN-SIZE + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "echo RUNRUN > bench/disk1/RUN-SIZE" --test-expect-failure sync + echo RUN > bench/disk1/RUN-TOUCH + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "touch -t 200001011200 bench/disk1/RUN-TOUCH" --test-expect-failure sync + echo RUN > bench/disk1/RUN-INODE + cp -p bench/disk1/RUN-INODE bench/disk1/RUN-INODE-COPY + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "mv bench/disk1/RUN-INODE-COPY bench/disk1/RUN-INODE" --test-expect-failure sync + rm bench/disk1/RUN-CHMOD + rm bench/disk1/RUN-SIZE + rm bench/disk1/RUN-TOUCH + rm bench/disk1/RUN-INODE + echo HASH > bench/disk1/HASH-RM + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "rm bench/disk1/HASH-RM" --test-expect-failure -h sync + echo HASH > bench/disk1/HASH-CHMOD + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "chmod a-r bench/disk1/HASH-CHMOD" --test-expect-failure -h sync + echo HASH > bench/disk1/HASH-SIZE + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "echo HASHHASH > bench/disk1/HASH-SIZE" --test-expect-failure -h sync + echo HASH > bench/disk1/HASH-TOUCH + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "touch -t 200001011200 bench/disk1/HASH-TOUCH" --test-expect-failure -h sync + echo HASH > bench/disk1/HASH-INODE + cp -p bench/disk1/HASH-INODE bench/disk1/HASH-INODE-COPY + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-run "mv bench/disk1/HASH-INODE-COPY bench/disk1/HASH-INODE" --test-expect-failure -h sync + rm bench/disk1/HASH-CHMOD + rm bench/disk1/HASH-SIZE + rm bench/disk1/HASH-TOUCH + rm bench/disk1/HASH-INODE + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync echo --- Silently corrupt some files, scrub and fix filtering for error $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./mktest$(EXEEXT) damage 1 10 1 bench/disk1/a/* diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 559053a1..8adf7768 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -230,6 +230,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_SKIP_CONTENT_CHECK 275 #define OPT_TEST_SKIP_PARITY_ACCESS 276 #define OPT_TEST_EXPECT_FAILURE 277 +#define OPT_TEST_RUN 278 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -321,6 +322,9 @@ struct option long_options[] = { /* Exit generic failure */ { "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE }, + /* Run some command after loading the state and before the command */ + { "test-run", 1, 0, OPT_TEST_RUN }, + { 0, 0, 0, 0 } }; #endif @@ -375,6 +379,7 @@ int main(int argc, char* argv[]) const char* log; int lock; const char* gen_conf; + const char* run; int period; os_init(); @@ -397,6 +402,7 @@ int main(int argc, char* argv[]) log = 0; lock = 0; gen_conf = 0; + run = 0; opterr = 0; while ((c = @@ -603,6 +609,9 @@ int main(int argc, char* argv[]) exit_success = 1; exit_failure = 0; break; + case OPT_TEST_RUN : + run = optarg; + break; default: /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); @@ -819,6 +828,17 @@ int main(int argc, char* argv[]) if (state.need_write) state_write(&state); + /* run a test command if required */ + if (run != 0) { + ret = system(run); /* ignore error */ + if (ret != 0) { + /* LCOV_EXCL_START */ + fprintf(stderr, "Error in running command '%s'.\n", run); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + } + /* waits some time to ensure that any concurrent modification done at the files, */ /* using the same mtime read by the scan process, will be read by sync. */ /* Note that any later modification done, potentially not read by sync, will have */ diff --git a/cmdline/sync.c b/cmdline/sync.c index 29eb0b80..7c960dc2 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -147,7 +147,8 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* 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) { + } + if (errno == EACCES) { fprintf(stdlog, "error:%u:%s:%s: Open access error\n", i, 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"); @@ -157,14 +158,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* 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, 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", disk->dir, handle[j].path); - printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); } /* LCOV_EXCL_START */ + fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, 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", disk->dir, handle[j].path); + printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + ++error; goto bail; /* LCOV_EXCL_STOP */