From 167d1edfec8ab019a5f426b7170682501a80a892 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 2 Sep 2015 19:44:48 +0200 Subject: [PATCH] Add some missing log_tag() when opening files --- cmdline/check.c | 2 +- cmdline/dry.c | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index 3eeb5028..e2f2d7ad 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -706,7 +706,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_open(&handle[j], file, state->file_mode, log_error, 0); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening '%s'. %s.\n", path, strerror(errno)); + log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ diff --git a/cmdline/dry.c b/cmdline/dry.c index 70d43dbe..8c2b0815 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -60,6 +60,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit int read_size; struct snapraid_block* block = BLOCK_EMPTY; struct snapraid_disk* disk = handle[j].disk; + struct snapraid_file* file; if (!disk) { /* if no disk, nothing to do */ @@ -73,29 +74,31 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit continue; } + /* get the file of this block */ + file = block_file_get(block); + /* until now is CPU */ state_usage_cpu(state); /* if the file is closed or different than the current one */ - if (handle[j].file == 0 || handle[j].file != block_file_get(block)) { - struct snapraid_file* file = handle[j].file; - if (file != 0) { - ret = handle_close(&handle[j]); - if (ret == -1) { - /* LCOV_EXCL_START */ - log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); - log_fatal("Stopping at block %u\n", i); - ++error; - goto bail; - /* LCOV_EXCL_STOP */ - } + if (handle[j].file == 0 || handle[j].file != file) { + /* close the old one, if any */ + ret = handle_close(&handle[j]); + if (ret == -1) { + /* LCOV_EXCL_START */ + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(handle[j].file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); + log_fatal("Stopping at block %u\n", i); + ++error; + goto bail; + /* LCOV_EXCL_STOP */ } /* open the file only for reading */ - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_fatal, 0); + ret = handle_open(&handle[j], file, state->file_mode, log_fatal, 0); if (ret == -1) { /* LCOV_EXCL_START */ + log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); log_fatal("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n"); log_fatal("Stopping at block %u\n", i); ++error; @@ -107,7 +110,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, log_error, 0); if (read_size == -1) { - log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); ++error; continue; }