mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Suppress missing file warnings if -m is specified
This commit is contained in:
parent
a5a72f4a31
commit
adbc74f862
10 changed files with 57 additions and 16 deletions
|
|
@ -999,7 +999,8 @@ 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, msg_warning);
|
||||
ret = handle_open(&handle[j], file, state->file_mode,
|
||||
msg_warning, state->opt.expected_missing ? msg_expected : 0);
|
||||
if (ret == -1) {
|
||||
/* save the failed block for the check/fix */
|
||||
failed[failed_count].is_bad = 1;
|
||||
|
|
@ -1063,7 +1064,8 @@ 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, msg_warning);
|
||||
read_size = handle_read(&handle[j], block, buffer[j], state->block_size,
|
||||
msg_warning, state->opt.expected_missing ? msg_expected : 0);
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit
|
|||
}
|
||||
|
||||
/* open the file only for reading */
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_error);
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_error, 0);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
msg_error("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n");
|
||||
|
|
@ -103,7 +103,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit
|
|||
}
|
||||
|
||||
/* read from the file */
|
||||
read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, msg_warning);
|
||||
read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, msg_warning, 0);
|
||||
if (read_size == -1) {
|
||||
msg_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block));
|
||||
++error;
|
||||
|
|
|
|||
|
|
@ -148,11 +148,14 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out)
|
||||
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing)
|
||||
{
|
||||
int ret;
|
||||
int flags;
|
||||
|
||||
if (!out_missing)
|
||||
out_missing = out;
|
||||
|
||||
/* if already opened, nothing to do */
|
||||
if (handle->file == file && handle->f != -1) {
|
||||
return 0;
|
||||
|
|
@ -179,7 +182,10 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int
|
|||
handle->f = -1;
|
||||
handle->valid_size = 0;
|
||||
|
||||
out("Error opening file '%s'. %s.\n", handle->path, strerror(errno));
|
||||
if (errno == ENOENT)
|
||||
out_missing("Missing file '%s'.\n", handle->path);
|
||||
else
|
||||
out("Error opening file '%s'. %s.\n", handle->path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +248,7 @@ int handle_close(struct snapraid_handle* handle)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out)
|
||||
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing)
|
||||
{
|
||||
ssize_t read_ret;
|
||||
data_off_t offset;
|
||||
|
|
@ -251,9 +257,16 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
|
|||
|
||||
offset = block_file_pos(block) * (data_off_t)block_size;
|
||||
|
||||
if (!out_missing)
|
||||
out_missing = out;
|
||||
|
||||
/* check if we are going to read only not initialized data */
|
||||
if (offset >= handle->valid_size) {
|
||||
out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
|
||||
/* if the file is missing, it's at 0 size, or it's rebuilt while reading */
|
||||
if (offset == handle->valid_size || handle->valid_size == 0)
|
||||
out_missing("Reading data from missing file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
|
||||
else
|
||||
out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file);
|
|||
* Opens a file.
|
||||
* The file is opened for reading.
|
||||
*/
|
||||
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out);
|
||||
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing);
|
||||
|
||||
/**
|
||||
* Closes a file.
|
||||
|
|
@ -64,7 +64,7 @@ int handle_close(struct snapraid_handle* handle);
|
|||
* Read a block from a file.
|
||||
* If the read block is shorter, it's padded with 0.
|
||||
*/
|
||||
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out);
|
||||
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing);
|
||||
|
||||
/**
|
||||
* Writes a block to a file.
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
}
|
||||
}
|
||||
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning);
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0);
|
||||
if (ret == -1) {
|
||||
/* file we have tried to open for error reporting */
|
||||
struct snapraid_file* file = block_file_get(block);
|
||||
|
|
@ -283,7 +283,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
/* from the last sync, as we are expected to return errors if running */
|
||||
/* in an unsynced array. This is just like the check command. */
|
||||
|
||||
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning);
|
||||
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning, 0);
|
||||
if (read_size == -1) {
|
||||
/* file we are processing for error reporting */
|
||||
struct snapraid_file* file = block_file_get(block);
|
||||
|
|
|
|||
|
|
@ -481,6 +481,7 @@ int main(int argc, char* argv[])
|
|||
} break;
|
||||
case 'm' :
|
||||
filter_missing = 1;
|
||||
opt.expected_missing = 1;
|
||||
break;
|
||||
case 'e' :
|
||||
/* when processing only error, we filter both files and blocks */
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ struct snapraid_option {
|
|||
int force_progress; /**< Force the use of the progress status. */
|
||||
unsigned force_autosave_at; /**< Force autosave at the specified block. */
|
||||
int fake_device; /**< Fake device data. */
|
||||
int expected_missing; /**< If missing files are expected and should not be reported. */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -98,6 +98,23 @@ void msg_warning(const char* format, ...)
|
|||
pthread_mutex_unlock(&msg_lock);
|
||||
}
|
||||
|
||||
void msg_expected(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
pthread_mutex_lock(&msg_lock);
|
||||
|
||||
if (stdlog) {
|
||||
va_start(ap, format);
|
||||
fprintf(stdlog, "msg:warning: ");
|
||||
vfprintf(stdlog, format, ap);
|
||||
fflush(stdlog);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&msg_lock);
|
||||
}
|
||||
|
||||
void msg_tag(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,13 @@ void msg_error(const char* format, ...) __attribute__((format(attribute_printf,
|
|||
*/
|
||||
void msg_warning(const char* format, ...) __attribute__((format(attribute_printf, 1, 2)));
|
||||
|
||||
/**
|
||||
* Warning messages, without fallback to stderr.
|
||||
*
|
||||
* These messages go in the log file if specified, otherwise they are lost.
|
||||
*/
|
||||
void msg_expected(const char* format, ...) __attribute__((format(attribute_printf, 1, 2)));
|
||||
|
||||
/**
|
||||
* Tag messages.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
}
|
||||
}
|
||||
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning);
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0);
|
||||
if (ret == -1) {
|
||||
/* file we have tried to open for error reporting */
|
||||
struct snapraid_file* file = block_file_get(block);
|
||||
|
|
@ -221,7 +221,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
continue;
|
||||
}
|
||||
|
||||
read_size = handle_read(&handle[j], block, buffer, state->block_size, msg_error);
|
||||
read_size = handle_read(&handle[j], block, buffer, state->block_size, msg_error, 0);
|
||||
if (read_size == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
/* file we are processing for error reporting */
|
||||
|
|
@ -624,7 +624,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
}
|
||||
}
|
||||
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning);
|
||||
ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0);
|
||||
if (ret == -1) {
|
||||
/* file we have tried to open for error reporting */
|
||||
struct snapraid_file* file = block_file_get(block);
|
||||
|
|
@ -698,7 +698,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
continue;
|
||||
}
|
||||
|
||||
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning);
|
||||
read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning, 0);
|
||||
if (read_size == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
/* file we are processing for error reporting */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue