Commit b5555f77 authored by Amit Gud's avatar Amit Gud Committed by Chris Mason

Btrfs: fix race in worker_loop

Need to check kthread_should_stop after schedule_timeout() before calling
schedule(). This causes threads to sleep with potentially no one to wake them
up causing mount(2) to hang in btrfs_stop_workers waiting for threads to stop.
Signed-off-by: default avatarAmit Gud <gud@ksu.edu>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent dccae999
...@@ -195,6 +195,9 @@ static int worker_loop(void *arg) ...@@ -195,6 +195,9 @@ static int worker_loop(void *arg)
if (!list_empty(&worker->pending)) if (!list_empty(&worker->pending))
continue; continue;
if (kthread_should_stop())
break;
/* still no more work?, sleep for real */ /* still no more work?, sleep for real */
spin_lock_irq(&worker->lock); spin_lock_irq(&worker->lock);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
...@@ -208,7 +211,8 @@ static int worker_loop(void *arg) ...@@ -208,7 +211,8 @@ static int worker_loop(void *arg)
worker->working = 0; worker->working = 0;
spin_unlock_irq(&worker->lock); spin_unlock_irq(&worker->lock);
schedule(); if (!kthread_should_stop())
schedule();
} }
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment