From a30c93024a5cf07197b00593021299192e04c115 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 17 Mar 2011 16:17:59 +0100 Subject: [PATCH] Manages the degenerated cases of empty or skipping all. Some change in the check screen output. --- Makefile.am | 3 +++ check.c | 29 +++++++++++++++++++---------- scan.c | 2 +- snapraid.d | 2 +- snapraid.html | 2 +- snapraid.txt | 2 +- sync.c | 12 ++++++++---- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Makefile.am b/Makefile.am index a7aee0e9..b16bd4d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,9 @@ check-local: mkdir test/disk1 mkdir test/disk2 mkdir test/disk3 + echo --- As empty, sync and check + ./snapraid -c $(srcdir)/test.conf sync + ./snapraid -c $(srcdir)/test.conf check echo --- Create some files, sync and check ./mktest generate 1 3 1000 4000 ./snapraid -c $(srcdir)/test.conf sync diff --git a/check.c b/check.c index 2c176511..95afae1a 100644 --- a/check.c +++ b/check.c @@ -245,13 +245,17 @@ static int state_check_process(int ret_on_error, struct snapraid_state* state, i printf("%u%% completed, %u MB processed\n", i * 100 / blockmax, (unsigned)(count_size / (1024*1024))); - if (error || unrecoverable_error) { + if (error || recovered_error || unrecoverable_error) { if (error) - printf("%u recoverable errors\n", error); + printf("%u read errors\n", error); else - printf("No recoverable errors\n"); - if (fix) - printf("%u fixed errors\n", recovered_error); + printf("No read errors\n"); + if (fix) { + if (recovered_error) + printf("%u recovered errors\n", recovered_error); + else + printf("No recovered errors\n"); + } if (unrecoverable_error) printf("%u UNRECOVERABLE errors\n", unrecoverable_error); else @@ -287,7 +291,7 @@ void state_check(struct snapraid_state* state, int fix, block_off_t blockstart) blockmax = parity_resize(state); size = blockmax * (data_off_t)state->block_size; - if (blockstart >= blockmax) { + if (blockstart > blockmax) { fprintf(stderr, "The specified starting block %u is bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); } @@ -303,10 +307,15 @@ void state_check(struct snapraid_state* state, int fix, block_off_t blockstart) f = parity_open(-1, path); } - ret = state_check_process(-1, state, fix, f, blockstart, blockmax); - if (ret == -1) { - /* no extra message */ - exit(EXIT_FAILURE); + /* skip degenerated cases of empty parity, or skipping all */ + if (blockstart < blockmax) { + ret = state_check_process(-1, state, fix, f, blockstart, blockmax); + if (ret == -1) { + /* no extra message */ + exit(EXIT_FAILURE); + } + } else { + printf("Nothing to do\n"); } if (f != -1) { diff --git a/scan.c b/scan.c index f4bb007a..cfe3d8f1 100644 --- a/scan.c +++ b/scan.c @@ -250,7 +250,7 @@ void state_scan(struct snapraid_state* state) /* if all the previous file were removed */ if (scan[i].count_equal == 0 && scan[i].count_remove != 0) { if (!state->force_empty) { - fprintf(stderr, "All the file in disk '%s' at dir '%s' are missing!\n", disk->name, disk->dir); + fprintf(stderr, "All the files in disk '%s' at dir '%s' are missing!\n", disk->name, disk->dir); fprintf(stderr, "If it's really what you want to sync it, use 'snapraid --force-empty sync\n"); exit(EXIT_FAILURE); } diff --git a/snapraid.d b/snapraid.d index 676b4bab..4be24e32 100644 --- a/snapraid.d +++ b/snapraid.d @@ -4,7 +4,7 @@ Name{number} Synopsis :snapraid [-c, --conf CONFIG] [-s, --start BLOCK] : [-Z, --force-zero] [-E, --force-empty] - : [-v, --verbose] [-e, --exclude PATTERN] + : [-v, --verbose] : COMMAND :snapraid [-V, --version] [-h, --help] diff --git a/snapraid.html b/snapraid.html index 19f66eb2..444e4bd0 100644 --- a/snapraid.html +++ b/snapraid.html @@ -10,7 +10,7 @@ Synopsis
 snapraid [-c, --conf CONFIG] [-s, --start BLOCK]
     [-Z, --force-zero] [-E, --force-empty]
-    [-v, --verbose] [-e, --exclude PATTERN]
+    [-v, --verbose]
     COMMAND
 

diff --git a/snapraid.txt b/snapraid.txt index bf60f065..fb8f1227 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -8,7 +8,7 @@ snapraid [-c, --conf CONFIG] [-s, --start BLOCK] [-Z, --force-zero] [-E, --force-empty] - [-v, --verbose] [-e, --exclude PATTERN] + [-v, --verbose] COMMAND snapraid [-V, --version] [-h, --help] diff --git a/sync.c b/sync.c index 52266275..2cb09012 100644 --- a/sync.c +++ b/sync.c @@ -127,8 +127,6 @@ static void state_sync_process(struct snapraid_state* state, int parity_f, block printf("%u%% completed, %u MB processed\n", i * 100 / blockmax, (unsigned)(count_size / (1024*1024))); - printf("Done\n"); - for(j=0;jblock_size; - if (blockstart >= blockmax) { + if (blockstart > blockmax) { fprintf(stderr, "The specified starting block %u is bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); } @@ -158,7 +157,12 @@ void state_sync(struct snapraid_state* state, block_off_t blockstart) pathcpy(path, sizeof(path), state->parity); f = parity_create(path, size); - state_sync_process(state, f, blockstart, blockmax); + /* skip degenerated cases of empty parity, or skipping all */ + if (blockstart < blockmax) { + state_sync_process(state, f, blockstart, blockmax); + } else { + printf("Nothing to do\n"); + } parity_sync(path, f);