Introduce a new messaging system

This commit is contained in:
Andrea Mazzoleni 2015-02-22 14:31:03 +01:00
parent fa5f31ddf9
commit e56de653da
33 changed files with 1642 additions and 1518 deletions

View file

@ -112,7 +112,7 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d
) {
/* if a hash doesn't match, fail the check */
if (blockcmp(state, rehash, failed[failed_map[j]].block, buffer[failed[failed_map[j]].index], buffer_zero) != 0) {
ftag("hash_error: Hash mismatch on entry %u\n", failed_map[j]);
msg_tag("hash_error: Hash mismatch on entry %u\n", failed_map[j]);
return 0;
}
@ -223,13 +223,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
return 0;
/* log */
ftag("parity_error:%u:", pos);
msg_tag("parity_error:%u:", pos);
for (i = 0; i < r; ++i) {
if (i != 0)
ftag("/");
ftag("%s", lev_config_name(ip[i]));
msg_tag("/");
msg_tag("%s", lev_config_name(ip[i]));
}
ftag(":parity: Parity mismatch\n");
msg_tag(":parity: Parity mismatch\n");
++error;
} while (combination_next(r, n, ip));
}
@ -263,13 +263,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
return 0;
/* log */
ftag("parity_error:%u:", pos);
msg_tag("parity_error:%u:", pos);
for (i = 0; i < r; ++i) {
if (i != 0)
ftag("/");
ftag("%s", lev_config_name(ip[i]));
msg_tag("/");
msg_tag("%s", lev_config_name(ip[i]));
}
ftag(":hash: Hash mismatch\n");
msg_tag(":hash: Hash mismatch\n");
++error;
} while (combination_next(r, n, ip));
}
@ -278,7 +278,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u
if (error)
return error;
ftag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n",
msg_tag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n",
pos, failed_count, n, has_hash ? "with" : "without");
return -1;
}
@ -338,9 +338,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
disk = handle->disk->name;
sub = block_file_get(block)->sub;
ftag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block));
msg_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block));
} else {
ftag("entry:%u:%s:%s:%s:\n", j, state, hash, data);
msg_tag("entry:%u:%s:%s:%s:\n", j, state, hash, data);
}
}
@ -375,7 +375,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
|| state_search_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0)
) {
/* we already have corrected it! */
ftag("hash_import: Fixed entry %u\n", j);
msg_tag("hash_import: Fixed entry %u\n", j);
} else {
/* otherwise try to recover it */
failed_map[n] = j;
@ -389,7 +389,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* if nothing to fix */
if (!something_to_recover) {
ftag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n);
msg_tag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n);
/* recompute only the parity */
raid_gen(diskmax, state->level, state->block_size, buffer);
@ -423,7 +423,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* it may contain garbage */
failed[j].is_outofdate = 1;
ftag("hash_unknown: Unknown hash on entry %u\n", j);
msg_tag("hash_unknown: Unknown hash on entry %u\n", j);
} else if (hash_is_zero(failed[j].block->hash)) {
/* if the block is not filled with 0, we are sure to have */
/* restored it to the state after the 'sync' */
@ -434,7 +434,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* it may contain garbage */
failed[j].is_outofdate = 1;
ftag("hash_unknown: Maybe old zero on entry %u\n", j);
msg_tag("hash_unknown: Maybe old zero on entry %u\n", j);
}
} else {
/* if the hash is different than the previous one, we are sure to have */
@ -446,7 +446,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* it may contain garbage */
failed[j].is_outofdate = 1;
ftag("hash_unknown: Maybe old data on entry %u\n", j);
msg_tag("hash_unknown: Maybe old data on entry %u\n", j);
}
}
}
@ -458,9 +458,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
error += ret;
if (ret < 0)
ftag("recover_sync:%u:%u: Failed with no attempts\n", pos, n);
msg_tag("recover_sync:%u:%u: Failed with no attempts\n", pos, n);
else
ftag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret);
msg_tag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret);
/* Now assume that the parity IS NOT updated at the current state, */
/* but still represent the state before the last 'sync' process. */
@ -556,7 +556,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
/* and we don't want to write it to the disk */
failed[j].is_outofdate = 1;
ftag("hash_unknown: Surely old data on entry %u\n", j);
msg_tag("hash_unknown: Surely old data on entry %u\n", j);
}
}
}
@ -567,11 +567,11 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign
error += ret;
if (ret < 0)
ftag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n);
msg_tag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n);
else
ftag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret);
msg_tag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret);
} else {
ftag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n,
msg_tag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n,
!something_to_recover ? " nothing to recover" : "",
!something_unsynced ? " nothing unsynched" : ""
);
@ -636,7 +636,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
/* or at least pointing to NULL, in case it cannot be opened. */
if (handle[j].file != 0 && handle[j].file != file) {
/* LCOV_EXCL_START */
ferr("Internal inconsistency in opened file for block %u\n", block->parity_pos);
msg_error("Internal inconsistency in opened file for block %u\n", block->parity_pos);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
@ -658,8 +658,8 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
ret = handle_close(&handle[j]);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error closing '%s'. %s.\n", path, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Error closing '%s'. %s.\n", path, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
return -1;
/* LCOV_EXCL_STOP */
}
@ -667,16 +667,14 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
ret = rename(path, path_to);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
return -1;
/* LCOV_EXCL_STOP */
}
ftag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("unrecoverable %s\n", path);
}
msg_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
msg_info("unrecoverable %s\n", path);
/* and do not set the time if damaged */
goto close_and_continue;
@ -688,10 +686,8 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
goto close_and_continue;
}
ftag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("recovered %s\n", path);
}
msg_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
msg_info("recovered %s\n", path);
inode = handle[j].st.st_ino;
@ -718,38 +714,32 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
/* LCOV_EXCL_START */
/* mark the file as damaged */
file_flag_set(file, FILE_IS_DAMAGED);
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
return -1;
/* LCOV_EXCL_STOP */
}
} else {
ftag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc(file->sub), esc(collide_file->sub));
msg_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc(file->sub), esc(collide_file->sub));
}
} else {
/* we are not fixing, but only checking */
/* print just the final status */
if (file_flag_has(file, FILE_IS_DAMAGED)) {
if (state->opt.auditonly) {
ftag("status:damaged:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("damaged %s\n", path);
}
msg_tag("status:damaged:%s:%s\n", disk->name, esc(file->sub));
msg_info("damaged %s\n", path);
} else {
ftag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("unrecoverable %s\n", path);
}
msg_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub));
msg_info("unrecoverable %s\n", path);
}
} else if (file_flag_has(file, FILE_IS_FIXED)) {
ftag("status:recoverable:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("recoverable %s\n", path);
}
msg_tag("status:recoverable:%s:%s\n", disk->name, esc(file->sub));
msg_info("recoverable %s\n", path);
} else {
ftag("status:correct:%s:%s\n", disk->name, esc(file->sub));
if (state->opt.verbose) {
fout("correct %s\n", path);
}
msg_tag("status:correct:%s:%s\n", disk->name, esc(file->sub));
/* we don't use msg_verbose() because it also goes into the log */
if (msg_level >= MSG_VERBOSE)
msg_info("correct %s\n", path);
}
}
@ -762,8 +752,8 @@ close_and_continue:
ret = handle_close(&handle[j]);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error closing '%s'. %s.\n", path, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Error closing '%s'. %s.\n", path, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
return -1;
/* LCOV_EXCL_STOP */
}
@ -882,7 +872,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* post process the files */
ret = file_post(state, fix, i, handle, diskmax);
if (ret == -1) {
ferr("Stopping at block %u\n", i);
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
}
@ -977,8 +967,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = handle_close(&handle[j]);
if (ret == -1) {
/* LCOV_EXCL_START */
ferr("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n");
ferr("Stopping at block %u\n", i);
msg_error("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n");
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -991,11 +981,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret == -1) {
/* LCOV_EXCL_START */
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the file.\n");
msg_error("WARNING! Please give write permission to the file.\n");
} else {
ferr("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping at block %u\n", i);
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1009,7 +999,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
}
} else {
/* otherwise, open the file only for reading */
ret = handle_open(&handle[j], file, state->file_mode, flog);
ret = handle_open(&handle[j], file, state->file_mode, msg_warning);
if (ret == -1) {
/* save the failed block for the check/fix */
failed[failed_count].is_bad = 1;
@ -1019,7 +1009,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
failed[failed_count].handle = &handle[j];
++failed_count;
ftag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
msg_tag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
++error;
continue;
}
@ -1046,22 +1036,22 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
&& !(state->opt.syncedonly && file_flag_has(file, FILE_IS_UNSYNCED))
&& handle[j].st.st_size > file->size
) {
flog("File '%s' is larger than expected.\n", handle[j].path);
ftag("error:%u:%s:%s: Size error\n", i, disk->name, esc(file->sub));
msg_warning("File '%s' is larger than expected.\n", handle[j].path);
msg_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc(file->sub));
++error;
if (fix) {
ret = handle_truncate(&handle[j], file);
if (ret == -1) {
/* LCOV_EXCL_START */
ferr("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n");
ferr("Stopping at block %u\n", i);
msg_error("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n");
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc(file->sub));
msg_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc(file->sub));
++recovered_error;
}
}
@ -1073,7 +1063,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
}
/* read from the file */
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, flog);
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning);
if (read_size == -1) {
/* save the failed block for the check/fix */
failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */
@ -1083,7 +1073,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
failed[failed_count].handle = &handle[j];
++failed_count;
ftag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
msg_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
++error;
continue;
}
@ -1124,7 +1114,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
failed[failed_count].handle = &handle[j];
++failed_count;
ftag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
msg_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block));
++error;
continue;
}
@ -1160,11 +1150,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* read the parity */
for (l = 0; l < state->level; ++l) {
if (parity[l]) {
ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, flog);
ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, msg_warning);
if (ret == -1) {
buffer_recov[l] = 0; /* no parity to use */
ftag("parity_error:%u:%s: Read error\n", i, lev_config_name(l));
msg_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l));
++error;
}
} else {
@ -1183,7 +1173,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* print a list of all the errors in files */
for (j = 0; j < failed_count; ++j) {
if (failed[j].is_bad)
ftag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
msg_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
}
/* keep track of damaged files */
@ -1201,7 +1191,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
for (j = 0; j < failed_count; ++j) {
if (failed[j].is_bad && failed[j].is_outofdate) {
++partial_recover_error;
ftag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
msg_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
}
}
if (partial_recover_error != 0) {
@ -1218,7 +1208,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (buffer_recov[l] != 0 && memcmp(buffer_recov[l], buffer[diskmax + l], state->block_size) != 0) {
buffer_recov[l] = 0;
ftag("parity_error:%u:%s: Data error\n", i, lev_config_name(l));
msg_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l));
++error;
}
}
@ -1244,12 +1234,12 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED);
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the file.\n");
msg_error("WARNING! Please give write permission to the file.\n");
} else {
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping at block %u\n", i);
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1266,7 +1256,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* note that it could be also marked as damaged in other iterations */
file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED);
ftag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
msg_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block));
++recovered_error;
}
@ -1281,14 +1271,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret == -1) {
/* LCOV_EXCL_START */
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l));
ferr("Stopping at block %u\n", i);
msg_error("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l));
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l));
msg_tag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l));
++recovered_error;
}
}
@ -1316,7 +1306,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* post process the files */
ret = file_post(state, fix, i, handle, diskmax);
if (ret == -1) {
ferr("Stopping at block %u\n", i);
msg_error("Stopping at block %u\n", i);
++unrecoverable_error;
goto bail;
}
@ -1368,18 +1358,18 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret == -1) {
unsuccesful = 1;
flog("Error stating empty file '%s'. %s.\n", path, strerror(errno));
ftag("error:%s:%s: Empty file stat error\n", disk->name, esc(file->sub));
msg_warning("Error stating empty file '%s'. %s.\n", path, strerror(errno));
msg_tag("error:%s:%s: Empty file stat error\n", disk->name, esc(file->sub));
++error;
} else if (!S_ISREG(st.st_mode)) {
unsuccesful = 1;
ftag("error:%s:%s: Empty file error for not regular file\n", disk->name, esc(file->sub));
msg_tag("error:%s:%s: Empty file error for not regular file\n", disk->name, esc(file->sub));
++error;
} else if (st.st_size != 0) {
unsuccesful = 1;
ftag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc(file->sub), st.st_size);
msg_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc(file->sub), st.st_size);
++error;
}
@ -1390,8 +1380,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = mkancestor(path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1402,14 +1392,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600);
if (f == -1) {
/* LCOV_EXCL_START */
ferr("Error creating empty file '%s'. %s.\n", path, strerror(errno));
msg_error("Error creating empty file '%s'. %s.\n", path, strerror(errno));
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the file.\n");
msg_error("WARNING! Please give write permission to the file.\n");
} else {
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1421,9 +1411,9 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* LCOV_EXCL_START */
close(f);
ferr("Error timing file '%s'. %s.\n", file->sub, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("Error timing file '%s'. %s.\n", file->sub, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1433,20 +1423,18 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = close(f);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("fixed:%s:%s: Fixed empty file\n", disk->name, esc(file->sub));
msg_tag("fixed:%s:%s: Fixed empty file\n", disk->name, esc(file->sub));
++recovered_error;
ftag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
if (!state->opt.quiet) {
fout("recovered %s%s\n", disk->dir, file->sub);
}
msg_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub));
msg_info("recovered %s%s\n", disk->dir, file->sub);
}
}
@ -1478,13 +1466,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret == -1) {
unsuccesful = 1;
flog("Error stating hardlink '%s'. %s.\n", path, strerror(errno));
ftag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, esc(link->sub), esc(link->linkto));
msg_warning("Error stating hardlink '%s'. %s.\n", path, strerror(errno));
msg_tag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, esc(link->sub), esc(link->linkto));
++error;
} else if (!S_ISREG(st.st_mode)) {
unsuccesful = 1;
ftag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
msg_tag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
++error;
}
@ -1508,19 +1496,19 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
}
}
flog("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno));
ftag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, esc(link->sub), esc(link->linkto));
msg_warning("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno));
msg_tag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, esc(link->sub), esc(link->linkto));
++error;
} else if (!S_ISREG(stto.st_mode)) {
unsuccesful = 1;
ftag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
msg_tag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto));
++error;
} else if (!unsuccesful && st.st_ino != stto.st_ino) {
unsuccesful = 1;
flog("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto);
ftag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc(link->sub), esc(link->linkto));
msg_warning("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto);
msg_tag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc(link->sub), esc(link->linkto));
++error;
}
} else {
@ -1530,14 +1518,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret < 0) {
unsuccesful = 1;
flog("Error reading symlink '%s'. %s.\n", path, strerror(errno));
ftag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
msg_warning("Error reading symlink '%s'. %s.\n", path, strerror(errno));
msg_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
++error;
} else if (ret >= PATH_MAX) {
unsuccesful = 1;
flog("Error reading symlink '%s'. Symlink too long.\n", path);
ftag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
msg_warning("Error reading symlink '%s'. Symlink too long.\n", path);
msg_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub));
++error;
} else {
linkto[ret] = 0;
@ -1545,7 +1533,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (strcmp(linkto, link->linkto) != 0) {
unsuccesful = 1;
ftag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc(link->sub), linkto, link->linkto);
msg_tag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc(link->sub), linkto, link->linkto);
++error;
}
}
@ -1556,8 +1544,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = mkancestor(path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1567,9 +1555,9 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = remove(path);
if (ret != 0 && errno != ENOENT) {
/* LCOV_EXCL_START */
ferr("Error removing '%s'. %s.\n", path, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("Error removing '%s'. %s.\n", path, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1580,46 +1568,44 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = hardlink(pathto, path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno));
msg_error("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno));
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the hardlink.\n");
msg_error("WARNING! Please give write permission to the hardlink.\n");
} else {
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, esc(link->sub));
msg_tag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, esc(link->sub));
++recovered_error;
} else {
ret = symlink(link->linkto, path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno));
msg_error("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno));
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the symlink.\n");
msg_error("WARNING! Please give write permission to the symlink.\n");
} else {
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, esc(link->sub));
msg_tag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, esc(link->sub));
++recovered_error;
}
ftag("status:recovered:%s:%s\n", disk->name, esc(link->sub));
if (!state->opt.quiet) {
fout("recovered %s%s\n", disk->dir, link->sub);
}
msg_tag("status:recovered:%s:%s\n", disk->name, esc(link->sub));
msg_info("recovered %s%s\n", disk->dir, link->sub);
}
}
@ -1646,13 +1632,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
if (ret == -1) {
unsuccesful = 1;
flog("Error stating dir '%s'. %s.\n", path, strerror(errno));
ftag("dir_error:%s:%s: Dir stat error\n", disk->name, esc(dir->sub));
msg_warning("Error stating dir '%s'. %s.\n", path, strerror(errno));
msg_tag("dir_error:%s:%s: Dir stat error\n", disk->name, esc(dir->sub));
++error;
} else if (!S_ISDIR(st.st_mode)) {
unsuccesful = 1;
ftag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc(dir->sub));
msg_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc(dir->sub));
++error;
}
@ -1661,8 +1647,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = mkancestor(path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
ferr("Stopping\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
@ -1672,26 +1658,24 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error creating dir '%s'. %s.\n", path, strerror(errno));
msg_error("Error creating dir '%s'. %s.\n", path, strerror(errno));
if (errno == EACCES) {
ferr("WARNING! Please give write permission to the dir.\n");
msg_error("WARNING! Please give write permission to the dir.\n");
} else {
/* we do not use DANGER because it could be ENOSPC which is not always correctly reported */
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
}
ferr("Stopping\n");
msg_error("Stopping\n");
++unrecoverable_error;
goto bail;
/* LCOV_EXCL_STOP */
}
ftag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc(dir->sub));
msg_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc(dir->sub));
++recovered_error;
ftag("status:recovered:%s:%s\n", disk->name, esc(dir->sub));
if (!state->opt.quiet) {
fout("recovered %s%s\n", disk->dir, dir->sub);
}
msg_tag("status:recovered:%s:%s\n", disk->name, esc(dir->sub));
msg_info("recovered %s%s\n", disk->dir, dir->sub);
}
}
}
@ -1704,7 +1688,7 @@ bail:
ret = handle_close(&handle[j]);
if (ret == -1) {
/* LCOV_EXCL_START */
ferr("DANGER! Unexpected close error in a data disk.\n");
msg_error("DANGER! Unexpected close error in a data disk.\n");
++unrecoverable_error;
/* continue, as we are already exiting */
/* LCOV_EXCL_STOP */
@ -1752,8 +1736,8 @@ bail:
ret = remove(path);
if (ret != 0) {
/* LCOV_EXCL_START */
ferr("Error removing '%s'. %s.\n", path, strerror(errno));
ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
msg_error("Error removing '%s'. %s.\n", path, strerror(errno));
msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n");
++unrecoverable_error;
/* continue, as we are already exiting */
/* LCOV_EXCL_STOP */
@ -1763,53 +1747,55 @@ bail:
}
if (error || recovered_error || unrecoverable_error) {
fout("\n");
fout("%8u read/data errors\n", error);
msg_status("\n");
msg_status("%8u errors\n", error);
if (fix) {
fout("%8u recovered errors\n", recovered_error);
msg_status("%8u recovered errors\n", recovered_error);
}
if (unrecoverable_error) {
fout("%8u UNRECOVERABLE errors\n", unrecoverable_error);
fout("DANGER! There are unrecoverable errors!\n");
msg_status("%8u UNRECOVERABLE errors\n", unrecoverable_error);
} else {
/* without checking, we don't know if they are really recoverable or not */
if (!state->opt.auditonly)
fout("%8u unrecoverable errors\n", unrecoverable_error);
msg_status("%8u unrecoverable errors\n", unrecoverable_error);
if (fix)
fout("Everything OK\n");
else
fout("WARNING! There are errors!\n");
msg_status("Everything OK\n");
}
} else {
fout("Everything OK\n");
msg_status("Everything OK\n");
}
ftag("summary:error:%u\n", error);
if (error && !fix)
msg_error("WARNING! There are errors!\n");
if (unrecoverable_error)
msg_error("DANGER! There are unrecoverable errors!\n");
msg_tag("summary:error:%u\n", error);
if (fix)
ftag("summary:error_recovered:%u\n", recovered_error);
msg_tag("summary:error_recovered:%u\n", recovered_error);
if (!state->opt.auditonly)
ftag("summary:error_unrecoverable:%u\n", unrecoverable_error);
msg_tag("summary:error_unrecoverable:%u\n", unrecoverable_error);
if (fix) {
if (error + recovered_error + unrecoverable_error == 0)
ftag("summary:exit:ok\n");
msg_tag("summary:exit:ok\n");
else if (unrecoverable_error == 0)
ftag("summary:exit:recovered\n");
msg_tag("summary:exit:recovered\n");
else
ftag("summary:exit:unrecoverable\n");
msg_tag("summary:exit:unrecoverable\n");
} else if (!state->opt.auditonly) {
if (error + unrecoverable_error == 0)
ftag("summary:exit:ok\n");
msg_tag("summary:exit:ok\n");
else if (unrecoverable_error == 0)
ftag("summary:exit:recoverable\n");
msg_tag("summary:exit:recoverable\n");
else
ftag("summary:exit:unrecoverable\n");
msg_tag("summary:exit:unrecoverable\n");
} else { /* audit only */
if (error == 0)
ftag("summary:exit:ok\n");
msg_tag("summary:exit:ok\n");
else
ftag("summary:exit:error\n");
msg_tag("summary:exit:error\n");
}
fflush_log();
msg_flush();
free(failed);
free(failed_map);
@ -1853,14 +1839,14 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
unsigned error;
unsigned l;
fout("Initializing...\n");
msg_progress("Initializing...\n");
blockmax = parity_allocated_size(state);
size = blockmax * (data_off_t)state->block_size;
if (blockstart > blockmax) {
/* LCOV_EXCL_START */
ferr("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax);
msg_error("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
@ -1878,7 +1864,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode);
if (ret == -1) {
/* LCOV_EXCL_START */
ferr("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l));
msg_error("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l));
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
@ -1886,7 +1872,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate);
if (ret == -1) {
/* LCOV_EXCL_START */
ferr("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
msg_error("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
@ -1898,7 +1884,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
parity_ptr[l] = &parity[l];
ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode);
if (ret == -1) {
fout("No accessible %s file, only files will be checked.\n", lev_name(l));
msg_status("No accessible %s file, only files will be checked.\n", lev_name(l));
/* continue anyway */
parity_ptr[l] = 0;
}
@ -1910,11 +1896,11 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
}
if (fix)
fout("Fixing...\n");
msg_progress("Fixing...\n");
else if (!state->opt.auditonly)
fout("Checking...\n");
msg_progress("Checking...\n");
else
fout("Hashing...\n");
msg_progress("Hashing...\n");
error = 0;
@ -1935,7 +1921,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
ret = parity_close(parity_ptr[l]);
/* LCOV_EXCL_START */
if (ret == -1) {
ferr("DANGER! Unexpected close error in %s disk.\n", lev_name(l));
msg_error("DANGER! Unexpected close error in %s disk.\n", lev_name(l));
++error;
/* continue, as we are already exiting */
}