mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-10 00:00:24 +03:00
Fix refcount bug in blkdev and timer kthreads.
The shutdown code in d79d57e and b20e160 had a race condition during shutdown, due to not owning a reference on the associated task_struct while the associated threads shut themselves down. Patch over this by taking an appropriate reference. Signed-off-by: Justin Husted <sigstop@gmail.com>
This commit is contained in:
parent
ff695c5afb
commit
76e147d0a9
@ -281,6 +281,7 @@ static void blkdev_cleanup(void)
|
|||||||
{
|
{
|
||||||
struct task_struct *p = NULL;
|
struct task_struct *p = NULL;
|
||||||
swap(aio_task, p);
|
swap(aio_task, p);
|
||||||
|
get_task_struct(p);
|
||||||
|
|
||||||
atomic_set(&aio_thread_stop, 1);
|
atomic_set(&aio_thread_stop, 1);
|
||||||
|
|
||||||
@ -305,6 +306,8 @@ static void blkdev_cleanup(void)
|
|||||||
ret = kthread_stop(p);
|
ret = kthread_stop(p);
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
|
|
||||||
|
put_task_struct(p);
|
||||||
|
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -312,6 +312,8 @@ static void timers_init(void)
|
|||||||
__attribute__((destructor(103)))
|
__attribute__((destructor(103)))
|
||||||
static void timers_cleanup(void)
|
static void timers_cleanup(void)
|
||||||
{
|
{
|
||||||
|
get_task_struct(timer_task);
|
||||||
|
|
||||||
pthread_mutex_lock(&timer_lock);
|
pthread_mutex_lock(&timer_lock);
|
||||||
timer_thread_stop = true;
|
timer_thread_stop = true;
|
||||||
pthread_cond_signal(&timer_cond);
|
pthread_cond_signal(&timer_cond);
|
||||||
@ -320,5 +322,6 @@ static void timers_cleanup(void)
|
|||||||
int ret = kthread_stop(timer_task);
|
int ret = kthread_stop(timer_task);
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
|
|
||||||
|
put_task_struct(timer_task);
|
||||||
timer_task = NULL;
|
timer_task = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user