diff --git a/cmdline/dry.c b/cmdline/dry.c index 7a33f317..0f415259 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -185,15 +185,15 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit countpos = 0; blockcur = blockstart; - /* start all the worker threads */ - io_start(&io, blockstart, blockmax, 0); - int alert = state_progress_begin(state, blockstart, blockmax, countmax); if (alert > 0) goto end; if (alert < 0) goto bail; + /* start all the worker threads */ + io_start(&io, blockstart, blockmax, 0); + while (1) { void** buffer; diff --git a/cmdline/io.c b/cmdline/io.c index 944e743c..77e95daa 100644 --- a/cmdline/io.c +++ b/cmdline/io.c @@ -295,6 +295,7 @@ static void io_start_mono(struct snapraid_io* io, { unsigned i; + io->started = 1; io->block_start = blockstart; io->block_max = blockmax; io->block_enabled = block_enabled; @@ -307,7 +308,10 @@ static void io_start_mono(struct snapraid_io* io, static void io_stop_mono(struct snapraid_io* io) { - (void)io; + if (!io->started) + return; + + io->started = 0; } /*****************************************************************************/ @@ -579,6 +583,11 @@ static void io_flush_thread(struct snapraid_io* io, int* writer_error) { unsigned i; + if (!io->started) { + io_writer_error_get(io, writer_error); + return; + } + while (1) { int all_done = 1; @@ -628,6 +637,9 @@ static void io_quiesce_thread(struct snapraid_io* io) { unsigned i; + if (!io->started) + return; + while (1) { int all_done = 1; @@ -923,6 +935,7 @@ static void io_start_thread(struct snapraid_io* io, { unsigned i; + io->started = 1; io->block_start = blockstart; io->block_max = blockmax; io->block_enabled = block_enabled; @@ -976,6 +989,11 @@ static void io_stop_thread(struct snapraid_io* io) { unsigned i; + if (!io->started) + return; + + io->started = 0; + thread_mutex_lock(&io->io_mutex); /* mark that we are stopping */ @@ -1033,6 +1051,9 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state, io_op_t parity_op_default = IO_OP_NONE; io->state = state; + io->started = 0; + for (i = 0; i < IO_WRITER_ERROR_MAX; ++i) + io->writer_error[i] = 0; assert(buffer_max >= handle_max + parity_handle_max); diff --git a/cmdline/io.h b/cmdline/io.h index 63176476..42e7f127 100644 --- a/cmdline/io.h +++ b/cmdline/io.h @@ -320,6 +320,11 @@ struct snapraid_io { */ int done; + /** + * If worker threads have been started. + */ + int started; + /** * The worker task index currently used by the operation in * progress. It's the position in all the reader task_map[]. diff --git a/cmdline/scrub.c b/cmdline/scrub.c index aac2c096..2b0e7e0a 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -529,15 +529,15 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par msg_progress("Scrubbing...\n"); - /* start all the worker threads */ - io_start(&io, blockstart, blockmax, block_enabled); - int alert = state_progress_begin(state, blockstart, blockmax, countmax); if (alert > 0) goto end; if (alert < 0) goto bail; + /* start all the worker threads */ + io_start(&io, blockstart, blockmax, block_enabled); + while (1) { unsigned char* buffer_recov[LEV_MAX]; snapraid_info info; diff --git a/cmdline/sync.c b/cmdline/sync.c index 145405c2..5ad019a9 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -1026,15 +1026,15 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari msg_progress("Syncing...\n"); - /* start all the worker threads */ - io_start(&io, blockstart, blockmax, block_enabled); - int alert = state_progress_begin(state, blockstart, blockmax, countmax); if (alert > 0) goto end; if (alert < 0) goto bail_abort; + /* start all the worker threads */ + io_start(&io, blockstart, blockmax, block_enabled); + while (1) { unsigned failed_count; int error_on_this_block; diff --git a/cmdline/thermal.c b/cmdline/thermal.c index 4a4c29d6..2f9ff17f 100644 --- a/cmdline/thermal.c +++ b/cmdline/thermal.c @@ -345,7 +345,7 @@ void state_thermal_cooldown(struct snapraid_state* state) int sleep_time = cooldown_time; log_tag("thermal:spindown\n"); - + /* * Power management is best effort. * @@ -417,11 +417,8 @@ int state_thermal_begin(struct snapraid_state* state, time_t now) } if (state_thermal_alarm(state)) { - /* LCOV_EXCL_START */ - log_fatal(EENVIRONMENT, "DANGER! Hard disk temperature of %d degrees is already outside the operating range. Unable to proceed!\n", state->thermal_highest_temperature); - log_flush(); - return 0; - /* LCOV_EXCL_STOP */ + msg_progress("Hard disk temperature of %d degrees is already outside the operating range. Cooling down before starting...\n", state->thermal_highest_temperature); + state_thermal_cooldown(state); } return 1;