Prints a more clear statement that Everything is OK at the end of commands.

This commit is contained in:
Andrea Mazzoleni 2013-09-21 19:11:11 +02:00
parent 5033e1e2f1
commit 013306e325
10 changed files with 59 additions and 32 deletions

44
sync.c
View file

@ -53,7 +53,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
block_off_t autosavelimit;
block_off_t autosavemissing;
int ret;
unsigned unrecoverable_error;
unsigned error;
unsigned silent_error;
time_t now;
/* get the present time */
@ -70,7 +71,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
buffer = malloc_nofail_vector_align(buffermax, state->block_size, &buffer_alloc);
unrecoverable_error = 0;
error = 0;
silent_error = 0;
/* first count the number of blocks to process */
countmax = 0;
@ -201,18 +203,18 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
/* and closing a descriptor should never fail */
fprintf(stderr, "DANGER! Unexpected close error in a data disk, it isn't possible to sync.\n");
printf("Stopping at block %u\n", i);
++unrecoverable_error;
++error;
goto bail;
}
}
ret = handle_open(&handle[j], block_file_get(block), stderr, state->opt.skip_sequential);
ret = handle_open(&handle[j], block_file_get(block), state->opt.skip_sequential, stderr);
if (ret == -1) {
if (errno == ENOENT) {
fprintf(stderr, "Missing file '%s'.\n", handle[j].path);
fprintf(stderr, "WARNING! You cannot modify data disk during a sync. Rerun the sync command when finished.\n");
++unrecoverable_error;
++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 */
@ -227,7 +229,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
printf("Stopping to allow recovery. Try with 'snapraid check'\n");
}
++unrecoverable_error;
++error;
goto bail;
}
@ -246,7 +248,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
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. Rerun the sync command when finished.\n");
++unrecoverable_error;
++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 */
@ -258,7 +260,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
if (read_size == -1) {
fprintf(stderr, "DANGER! Unexpected read error in a data disk, it isn't possible to sync.\n");
printf("Stopping to allow recovery. Try with 'snapraid check'\n");
++unrecoverable_error;
++error;
goto bail;
}
@ -281,7 +283,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
fprintf(stderr, "Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block));
fprintf(stderr, "DANGER! Unexpected data error in a data disk, it isn't possible to sync.\n");
printf("Stopping to allow recovery. Try with 'snapraid -s %u check'\n", i);
++unrecoverable_error;
++silent_error;
goto bail;
}
} else {
@ -305,7 +307,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
if (ret == -1) {
fprintf(stderr, "DANGER! Write error in the Parity disk, it isn't possible to sync.\n");
printf("Stopping at block %u\n", i);
++unrecoverable_error;
++error;
goto bail;
}
@ -315,7 +317,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
if (ret == -1) {
fprintf(stderr, "DANGER! Write error in the Q-Parity disk, it isn't possible to sync.\n");
printf("Stopping at block %u\n", i);
++unrecoverable_error;
++error;
goto bail;
}
}
@ -385,12 +387,21 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
state_progress_end(state, countpos, countmax, countsize);
if (error || silent_error) {
printf("%u read/write errors\n", error);
printf("%u data errors\n", silent_error);
} else {
/* print the result only if processed something */
if (countpos != 0)
printf("Everything OK\n");
}
bail:
for(j=0;j<diskmax;++j) {
ret = handle_close(&handle[j]);
if (ret == -1) {
fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n");
++unrecoverable_error;
++error;
/* continue, as we are already exiting */
}
}
@ -400,8 +411,13 @@ bail:
free(buffer);
free(rehandle_alloc);
if (unrecoverable_error != 0)
return -1;
if (state->opt.expect_recoverable) {
if (error + silent_error == 0)
return -1;
} else {
if (error + silent_error != 0)
return -1;
}
return 0;
}