Skip to content

Commit

Permalink
btrfs: Fix bugs in zlib workspace
Browse files Browse the repository at this point in the history
- Fix a race that can result in alloc_workspace > cpus.
- Fix to check num_workspace after wakeup.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
  • Loading branch information
Li Zefan committed Dec 22, 2010
1 parent 83a50de commit 8844355
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/btrfs/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ static struct workspace *find_zlib_workspace(void)
return workspace;

}
spin_unlock(&workspace_lock);
if (atomic_read(&alloc_workspace) > cpus) {
DEFINE_WAIT(wait);

spin_unlock(&workspace_lock);
prepare_to_wait(&workspace_wait, &wait, TASK_UNINTERRUPTIBLE);
if (atomic_read(&alloc_workspace) > cpus)
if (atomic_read(&alloc_workspace) > cpus && !num_workspace)
schedule();
finish_wait(&workspace_wait, &wait);
goto again;
}
atomic_inc(&alloc_workspace);
spin_unlock(&workspace_lock);

workspace = kzalloc(sizeof(*workspace), GFP_NOFS);
if (!workspace) {
ret = -ENOMEM;
Expand Down

0 comments on commit 8844355

Please sign in to comment.