public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "홍신 shin hong" <hongshin@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] BTRFS: fix data race
Date: Wed, 27 May 2009 21:43:18 +0900	[thread overview]
Message-ID: <2014bcab0905270543s44976c64p2cda48bd4f3c8b8a@mail.gmail.com> (raw)

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() writes workers->worker
before it starts a child thread with worker_loop() in order to
resolve possible race condition.

--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -273,10 +273,10 @@
                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);

                 reply	other threads:[~2009-05-27 12:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2014bcab0905270543s44976c64p2cda48bd4f3c8b8a@mail.gmail.com \
    --to=hongshin@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox