Skip to content

Commit

Permalink
Btrfs: fix race in worker_loop
Browse files Browse the repository at this point in the history
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: Amit Gud <gud@ksu.edu>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Amit Gud authored and Chris Mason committed Apr 2, 2009
1 parent dccae99 commit b5555f7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/btrfs/async-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ static int worker_loop(void *arg)
if (!list_empty(&worker->pending))
continue;

if (kthread_should_stop())
break;

/* still no more work?, sleep for real */
spin_lock_irq(&worker->lock);
set_current_state(TASK_INTERRUPTIBLE);
Expand All @@ -208,7 +211,8 @@ static int worker_loop(void *arg)
worker->working = 0;
spin_unlock_irq(&worker->lock);

schedule();
if (!kthread_should_stop())
schedule();
}
__set_current_state(TASK_RUNNING);
}
Expand Down

0 comments on commit b5555f7

Please sign in to comment.