summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShin Hong <hongshin@gmail.com>2009-06-10 20:11:29 -0400
committerChris Mason <chris.mason@oracle.com>2009-06-10 20:11:29 -0400
commitfd0fb038d5a308c7faddd1701be5e70aaffec98b (patch)
tree50b0f3cda5a957bad1090ec4d7bd4e49f43171da
parent4eedeb75e7f15ffdb12d1ad559b565e7505bdbaf (diff)
downloadop-kernel-dev-fd0fb038d5a308c7faddd1701be5e70aaffec98b.zip
op-kernel-dev-fd0fb038d5a308c7faddd1701be5e70aaffec98b.tar.gz
Btrfs: init worker struct fields before kthread-run
This patch fixes a bug which may result race condition between btrfs_start_workers() and worker_loop(). btrfs_start_workers() executed in a parent thread writes on workers->worker and worker_loop() in a child thread reads workers->worker. However, there is no synchronization enforcing the order of two operations. This patch makes btrfs_start_workers() fill workers->worker before it starts a child thread with worker_loop() Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/async-thread.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 502c3d6..7f88628 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -294,10 +294,10 @@ int btrfs_start_workers(struct btrfs_workers *workers, int num_workers)
INIT_LIST_HEAD(&worker->worker_list);
spin_lock_init(&worker->lock);
atomic_set(&worker->num_pending, 0);
+ worker->workers = workers;
worker->task = kthread_run(worker_loop, worker,
"btrfs-%s-%d", workers->name,
workers->num_workers + i);
- worker->workers = workers;
if (IS_ERR(worker->task)) {
kfree(worker);
ret = PTR_ERR(worker->task);
OpenPOWER on IntegriCloud