From 6b55d2a292f515d5f53fd3b4439182257de29b3a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 16 Nov 2015 22:54:00 +0100 Subject: [PATCH] Add extra assertions and consistency checks --- Makefile.am | 1 + cmdline/elem.c | 27 ++++++++++++++++++++++++--- cmdline/scan.c | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 996b9f19..3655ac7e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -287,6 +287,7 @@ endif $(TESTENV) ./mktest$(EXEEXT) generate 1 6 $(CHECKCOUNT) $(CHECKSIZE) echo DUP > bench/disk1/DUP1 echo DUP > bench/disk1/DUP2 + head -c 0 /dev/zero > bench/disk1/ZERO echo --- Some commands with a not empty array # Run a sync using physical offset $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_PHYSICAL) -c $(CONF) --test-expect-need-sync diff > output.log diff --git a/cmdline/elem.c b/cmdline/elem.c index 20672f5b..5772e3ac 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -607,6 +607,9 @@ struct snapraid_chunk* chunk_alloc(block_off_t parity_pos, struct snapraid_file* { struct snapraid_chunk* chunk; + assert(count != 0); + assert(file_pos + count <= file->blockmax); + chunk = malloc_nofail(sizeof(struct snapraid_chunk)); chunk->parity_pos = parity_pos; chunk->file = file; @@ -858,6 +861,15 @@ void chunk_parity_check_foreach(void* void_arg, void* void_obj) /* LCOV_EXCL_STOP */ } + if (obj->count == 0) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency in parity count zero for file '%s' at '%u'\n", + obj->file->sub, obj->parity_pos); + ++arg->result; + return; + /* LCOV_EXCL_STOP */ + } + /* check only if there is a previous block */ if (!prev) return; @@ -899,6 +911,15 @@ void chunk_file_check_foreach(void* void_arg, void* void_obj) /* LCOV_EXCL_STOP */ } + if (obj->count == 0) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency in file count zero for file '%s' at '%u'\n", + obj->file->sub, obj->file_pos); + ++arg->result; + return; + /* LCOV_EXCL_STOP */ + } + /* note that for deleted files, some chunks may be missing */ /* if the files are different */ @@ -1130,7 +1151,7 @@ block_off_t fs_file2par_get_ts(struct snapraid_disk* disk, struct snapraid_chunk chunk = fs_file2chunk_get_ts(disk, fs_last, file, file_pos); if (!chunk) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency when resolving file '%s' at position '%u' in disk '%s'\n", file->sub, file_pos, disk->name); + log_fatal("Internal inconsistency when resolving file '%s' at position '%u/%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, disk->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1152,7 +1173,7 @@ void fs_allocate(struct snapraid_disk* disk, block_off_t parity_pos, struct snap /* ensure that we are extending the chunk at the end */ if (file_pos != chunk->file_pos + chunk->count) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency when allocating file '%s' at position '%u' in the middle of chunk '%u:%u' in disk '%s'\n", file->sub, file_pos, chunk->file_pos, chunk->count, disk->name); + log_fatal("Internal inconsistency when allocating file '%s' at position '%u/%u' in the middle of chunk '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, chunk->file_pos, chunk->count, disk->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1173,7 +1194,7 @@ void fs_allocate(struct snapraid_disk* disk, block_off_t parity_pos, struct snap if (parity_chunk != chunk || file_chunk != chunk) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency when allocating file '%s' at position '%u' for existing chunk '%u:%u' in disk '%s'\n", file->sub, file_pos, chunk->file_pos, chunk->count, disk->name); + log_fatal("Internal inconsistency when allocating file '%s' at position '%u/%u' for existing chunk '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, chunk->file_pos, chunk->count, disk->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/scan.c b/cmdline/scan.c index b335a2fa..82f3bff0 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -251,7 +251,7 @@ static void scan_file_allocate(struct snapraid_scan* scan, struct snapraid_file* /** * Remove the specified file from the parity. - * The file is then inserted in the deleted set, and it should no be deallocated. + * The file is then inserted in the deleted set, and it should not be deallocated. */ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_file* file) {