Manages the degenerated cases of empty or skipping all.

Some change in the check screen output.
This commit is contained in:
Andrea Mazzoleni 2011-03-17 16:17:59 +01:00
parent 543658640a
commit a30c93024a
7 changed files with 34 additions and 18 deletions

View file

@ -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

29
check.c
View file

@ -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) {

2
scan.c
View file

@ -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);
}

View file

@ -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]

View file

@ -10,7 +10,7 @@ Synopsis
<pre>
snapraid [-c, --conf CONFIG] [-s, --start BLOCK]
&nbsp;&nbsp;&nbsp;&nbsp;[-Z, --force-zero] [-E, --force-empty]
&nbsp;&nbsp;&nbsp;&nbsp;[-v, --verbose] [-e, --exclude PATTERN]
&nbsp;&nbsp;&nbsp;&nbsp;[-v, --verbose]
&nbsp;&nbsp;&nbsp;&nbsp;COMMAND
</pre>
<p>

View file

@ -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]

12
sync.c
View file

@ -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;j<diskmax;++j) {
handle_close(&handle[j]);
}
@ -148,9 +146,10 @@ void state_sync(struct snapraid_state* state, block_off_t blockstart)
printf("Syncing...\n");
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);
}
@ -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);