mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-02 21:00:16 -05:00
Fix io_flush_thread() to wait for in-flight writer tasks before returning
This commit is contained in:
parent
bf3647f355
commit
3f63bd69fa
2 changed files with 12 additions and 3 deletions
14
cmdline/io.c
14
cmdline/io.c
|
|
@ -348,6 +348,8 @@ static struct snapraid_task* io_writer_step(struct snapraid_worker* worker, int
|
||||||
if (error_index >= 0 && error_index < IO_WRITER_ERROR_MAX)
|
if (error_index >= 0 && error_index < IO_WRITER_ERROR_MAX)
|
||||||
++io->writer_error[error_index];
|
++io->writer_error[error_index];
|
||||||
|
|
||||||
|
worker->busy = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned next_index;
|
unsigned next_index;
|
||||||
|
|
||||||
|
|
@ -368,6 +370,8 @@ static struct snapraid_task* io_writer_step(struct snapraid_worker* worker, int
|
||||||
worker->index = next_index;
|
worker->index = next_index;
|
||||||
task = &worker->task_map[worker->index];
|
task = &worker->task_map[worker->index];
|
||||||
|
|
||||||
|
worker->busy = 1;
|
||||||
|
|
||||||
/* if the just completed task is at this index */
|
/* if the just completed task is at this index */
|
||||||
if (done_index == waiting_index) {
|
if (done_index == waiting_index) {
|
||||||
/* notify the IO that a new write is complete */
|
/* notify the IO that a new write is complete */
|
||||||
|
|
@ -545,8 +549,12 @@ static void io_flush_thread(struct snapraid_io* io)
|
||||||
/* get the next pending task */
|
/* get the next pending task */
|
||||||
unsigned next_index = (worker->index + 1) % io->io_max;
|
unsigned next_index = (worker->index + 1) % io->io_max;
|
||||||
|
|
||||||
/* if the queue of pending tasks is not empty */
|
/*
|
||||||
if (next_index != io->writer_index) {
|
* Ring indices can look empty after a writer dequeues its last task and
|
||||||
|
* executes it outside the mutex. busy represents this in-flight gap;
|
||||||
|
* without it flush could return before the final parity write completes.
|
||||||
|
*/
|
||||||
|
if (worker->busy || next_index != io->writer_index) {
|
||||||
all_done = 0;
|
all_done = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -873,6 +881,7 @@ static void io_start_thread(struct snapraid_io* io,
|
||||||
struct snapraid_worker* worker = &io->writer_map[i];
|
struct snapraid_worker* worker = &io->writer_map[i];
|
||||||
|
|
||||||
worker->index = io->io_max - 1;
|
worker->index = io->io_max - 1;
|
||||||
|
worker->busy = 0;
|
||||||
|
|
||||||
thread_create(&worker->thread, io_writer_thread, worker);
|
thread_create(&worker->thread, io_writer_thread, worker);
|
||||||
}
|
}
|
||||||
|
|
@ -1150,4 +1159,3 @@ void io_done(struct snapraid_io* io)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ struct snapraid_task {
|
||||||
struct snapraid_worker {
|
struct snapraid_worker {
|
||||||
#if HAVE_THREAD
|
#if HAVE_THREAD
|
||||||
thread_id_t thread; /**< Thread context for the worker. */
|
thread_id_t thread; /**< Thread context for the worker. */
|
||||||
|
int busy; /**< A task is currently being processed. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue