diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2010-10-25 03:11:43 -0400 |
---|---|---|
committer | Li Zefan <lizf@cn.fujitsu.com> | 2010-12-22 10:15:41 -0500 |
commit | 8844355df7f4e091b03cc131e1549631238b397b (patch) | |
tree | 90568648b57f05265def659b7dbf8f45baaaeb65 /fs | |
parent | 83a50de97fe96aca82389e061862ed760ece2283 (diff) |
btrfs: Fix bugs in zlib workspace
- 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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/zlib.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index b9cd5445f71c..e5b8b22e07d6 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c | |||
@@ -75,16 +75,19 @@ again: | |||
75 | return workspace; | 75 | return workspace; |
76 | 76 | ||
77 | } | 77 | } |
78 | spin_unlock(&workspace_lock); | ||
79 | if (atomic_read(&alloc_workspace) > cpus) { | 78 | if (atomic_read(&alloc_workspace) > cpus) { |
80 | DEFINE_WAIT(wait); | 79 | DEFINE_WAIT(wait); |
80 | |||
81 | spin_unlock(&workspace_lock); | ||
81 | prepare_to_wait(&workspace_wait, &wait, TASK_UNINTERRUPTIBLE); | 82 | prepare_to_wait(&workspace_wait, &wait, TASK_UNINTERRUPTIBLE); |
82 | if (atomic_read(&alloc_workspace) > cpus) | 83 | if (atomic_read(&alloc_workspace) > cpus && !num_workspace) |
83 | schedule(); | 84 | schedule(); |
84 | finish_wait(&workspace_wait, &wait); | 85 | finish_wait(&workspace_wait, &wait); |
85 | goto again; | 86 | goto again; |
86 | } | 87 | } |
87 | atomic_inc(&alloc_workspace); | 88 | atomic_inc(&alloc_workspace); |
89 | spin_unlock(&workspace_lock); | ||
90 | |||
88 | workspace = kzalloc(sizeof(*workspace), GFP_NOFS); | 91 | workspace = kzalloc(sizeof(*workspace), GFP_NOFS); |
89 | if (!workspace) { | 92 | if (!workspace) { |
90 | ret = -ENOMEM; | 93 | ret = -ENOMEM; |