David Sterba | c1d7c51 | 2018-04-03 19:23:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 Oracle. All rights reserved. |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 4 | */ |
David Sterba | c1d7c51 | 2018-04-03 19:23:33 +0200 | [diff] [blame] | 5 | |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 6 | #include <linux/sched.h> |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 7 | #include <linux/pagemap.h> |
| 8 | #include <linux/spinlock.h> |
| 9 | #include <linux/page-flags.h> |
Chris Mason | 4881ee5 | 2008-07-24 09:51:08 -0400 | [diff] [blame] | 10 | #include <asm/bug.h> |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 11 | #include "ctree.h" |
| 12 | #include "extent_io.h" |
| 13 | #include "locking.h" |
| 14 | |
David Sterba | e4e9fd0 | 2018-08-24 14:45:20 +0200 | [diff] [blame] | 15 | #ifdef CONFIG_BTRFS_DEBUG |
| 16 | static void btrfs_assert_spinning_writers_get(struct extent_buffer *eb) |
| 17 | { |
| 18 | WARN_ON(atomic_read(&eb->spinning_writers)); |
| 19 | atomic_inc(&eb->spinning_writers); |
| 20 | } |
| 21 | |
| 22 | static void btrfs_assert_spinning_writers_put(struct extent_buffer *eb) |
| 23 | { |
| 24 | WARN_ON(atomic_read(&eb->spinning_writers) != 1); |
| 25 | atomic_dec(&eb->spinning_writers); |
| 26 | } |
| 27 | |
| 28 | static void btrfs_assert_no_spinning_writers(struct extent_buffer *eb) |
| 29 | { |
| 30 | WARN_ON(atomic_read(&eb->spinning_writers)); |
| 31 | } |
| 32 | |
David Sterba | 225948d | 2018-08-24 15:53:42 +0200 | [diff] [blame] | 33 | static void btrfs_assert_spinning_readers_get(struct extent_buffer *eb) |
| 34 | { |
| 35 | atomic_inc(&eb->spinning_readers); |
| 36 | } |
| 37 | |
| 38 | static void btrfs_assert_spinning_readers_put(struct extent_buffer *eb) |
| 39 | { |
| 40 | WARN_ON(atomic_read(&eb->spinning_readers) == 0); |
| 41 | atomic_dec(&eb->spinning_readers); |
| 42 | } |
| 43 | |
David Sterba | 58a2ddae | 2018-08-24 16:13:41 +0200 | [diff] [blame] | 44 | static void btrfs_assert_tree_read_locks_get(struct extent_buffer *eb) |
| 45 | { |
| 46 | atomic_inc(&eb->read_locks); |
| 47 | } |
| 48 | |
| 49 | static void btrfs_assert_tree_read_locks_put(struct extent_buffer *eb) |
| 50 | { |
| 51 | atomic_dec(&eb->read_locks); |
| 52 | } |
| 53 | |
| 54 | static void btrfs_assert_tree_read_locked(struct extent_buffer *eb) |
| 55 | { |
| 56 | BUG_ON(!atomic_read(&eb->read_locks)); |
| 57 | } |
| 58 | |
David Sterba | e4e9fd0 | 2018-08-24 14:45:20 +0200 | [diff] [blame] | 59 | #else |
| 60 | static void btrfs_assert_spinning_writers_get(struct extent_buffer *eb) { } |
| 61 | static void btrfs_assert_spinning_writers_put(struct extent_buffer *eb) { } |
| 62 | static void btrfs_assert_no_spinning_writers(struct extent_buffer *eb) { } |
David Sterba | 225948d | 2018-08-24 15:53:42 +0200 | [diff] [blame] | 63 | static void btrfs_assert_spinning_readers_put(struct extent_buffer *eb) { } |
| 64 | static void btrfs_assert_spinning_readers_get(struct extent_buffer *eb) { } |
David Sterba | 58a2ddae | 2018-08-24 16:13:41 +0200 | [diff] [blame] | 65 | static void btrfs_assert_tree_read_locked(struct extent_buffer *eb) { } |
| 66 | static void btrfs_assert_tree_read_locks_get(struct extent_buffer *eb) { } |
| 67 | static void btrfs_assert_tree_read_locks_put(struct extent_buffer *eb) { } |
David Sterba | e4e9fd0 | 2018-08-24 14:45:20 +0200 | [diff] [blame] | 68 | #endif |
| 69 | |
David Sterba | b95be2d | 2018-04-04 01:43:05 +0200 | [diff] [blame] | 70 | void btrfs_set_lock_blocking_read(struct extent_buffer *eb) |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 71 | { |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 72 | /* |
David Sterba | b95be2d | 2018-04-04 01:43:05 +0200 | [diff] [blame] | 73 | * No lock is required. The lock owner may change if we have a read |
| 74 | * lock, but it won't change to or away from us. If we have the write |
| 75 | * lock, we are the owner and it'll never change. |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 76 | */ |
| 77 | if (eb->lock_nested && current->pid == eb->lock_owner) |
| 78 | return; |
David Sterba | b95be2d | 2018-04-04 01:43:05 +0200 | [diff] [blame] | 79 | btrfs_assert_tree_read_locked(eb); |
| 80 | atomic_inc(&eb->blocking_readers); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 81 | btrfs_assert_spinning_readers_put(eb); |
David Sterba | b95be2d | 2018-04-04 01:43:05 +0200 | [diff] [blame] | 82 | read_unlock(&eb->lock); |
| 83 | } |
| 84 | |
| 85 | void btrfs_set_lock_blocking_write(struct extent_buffer *eb) |
| 86 | { |
| 87 | /* |
| 88 | * No lock is required. The lock owner may change if we have a read |
| 89 | * lock, but it won't change to or away from us. If we have the write |
| 90 | * lock, we are the owner and it'll never change. |
| 91 | */ |
| 92 | if (eb->lock_nested && current->pid == eb->lock_owner) |
| 93 | return; |
| 94 | if (atomic_read(&eb->blocking_writers) == 0) { |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 95 | btrfs_assert_spinning_writers_put(eb); |
David Sterba | b95be2d | 2018-04-04 01:43:05 +0200 | [diff] [blame] | 96 | btrfs_assert_tree_locked(eb); |
| 97 | atomic_inc(&eb->blocking_writers); |
| 98 | write_unlock(&eb->lock); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 99 | } |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 100 | } |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 101 | |
David Sterba | aa12c02 | 2018-04-04 01:52:31 +0200 | [diff] [blame] | 102 | void btrfs_clear_lock_blocking_read(struct extent_buffer *eb) |
| 103 | { |
| 104 | /* |
| 105 | * No lock is required. The lock owner may change if we have a read |
| 106 | * lock, but it won't change to or away from us. If we have the write |
| 107 | * lock, we are the owner and it'll never change. |
| 108 | */ |
| 109 | if (eb->lock_nested && current->pid == eb->lock_owner) |
| 110 | return; |
| 111 | BUG_ON(atomic_read(&eb->blocking_readers) == 0); |
| 112 | read_lock(&eb->lock); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 113 | btrfs_assert_spinning_readers_get(eb); |
David Sterba | aa12c02 | 2018-04-04 01:52:31 +0200 | [diff] [blame] | 114 | /* atomic_dec_and_test implies a barrier */ |
| 115 | if (atomic_dec_and_test(&eb->blocking_readers)) |
| 116 | cond_wake_up_nomb(&eb->read_lock_wq); |
| 117 | } |
| 118 | |
| 119 | void btrfs_clear_lock_blocking_write(struct extent_buffer *eb) |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 120 | { |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 121 | /* |
| 122 | * no lock is required. The lock owner may change if |
| 123 | * we have a read lock, but it won't change to or away |
| 124 | * from us. If we have the write lock, we are the owner |
| 125 | * and it'll never change. |
| 126 | */ |
| 127 | if (eb->lock_nested && current->pid == eb->lock_owner) |
| 128 | return; |
David Sterba | aa12c02 | 2018-04-04 01:52:31 +0200 | [diff] [blame] | 129 | BUG_ON(atomic_read(&eb->blocking_writers) != 1); |
| 130 | write_lock(&eb->lock); |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 131 | btrfs_assert_spinning_writers_get(eb); |
David Sterba | aa12c02 | 2018-04-04 01:52:31 +0200 | [diff] [blame] | 132 | /* atomic_dec_and_test implies a barrier */ |
| 133 | if (atomic_dec_and_test(&eb->blocking_writers)) |
| 134 | cond_wake_up_nomb(&eb->write_lock_wq); |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 138 | * take a spinning read lock. This will wait for any blocking |
| 139 | * writers |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 140 | */ |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 141 | void btrfs_tree_read_lock(struct extent_buffer *eb) |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 142 | { |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 143 | again: |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 144 | BUG_ON(!atomic_read(&eb->blocking_writers) && |
| 145 | current->pid == eb->lock_owner); |
| 146 | |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 147 | read_lock(&eb->lock); |
| 148 | if (atomic_read(&eb->blocking_writers) && |
| 149 | current->pid == eb->lock_owner) { |
| 150 | /* |
| 151 | * This extent is already write-locked by our thread. We allow |
| 152 | * an additional read lock to be added because it's for the same |
| 153 | * thread. btrfs_find_all_roots() depends on this as it may be |
| 154 | * called on a partly (write-)locked tree. |
| 155 | */ |
| 156 | BUG_ON(eb->lock_nested); |
| 157 | eb->lock_nested = 1; |
| 158 | read_unlock(&eb->lock); |
| 159 | return; |
| 160 | } |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 161 | if (atomic_read(&eb->blocking_writers)) { |
| 162 | read_unlock(&eb->lock); |
Liu Bo | 39f9d02 | 2012-12-27 09:01:22 +0000 | [diff] [blame] | 163 | wait_event(eb->write_lock_wq, |
| 164 | atomic_read(&eb->blocking_writers) == 0); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 165 | goto again; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 166 | } |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame^] | 167 | btrfs_assert_tree_read_locks_get(eb); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 168 | btrfs_assert_spinning_readers_get(eb); |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* |
Chris Mason | f82c458 | 2014-11-19 10:25:09 -0800 | [diff] [blame] | 172 | * take a spinning read lock. |
| 173 | * returns 1 if we get the read lock and 0 if we don't |
| 174 | * this won't wait for blocking writers |
| 175 | */ |
| 176 | int btrfs_tree_read_lock_atomic(struct extent_buffer *eb) |
| 177 | { |
| 178 | if (atomic_read(&eb->blocking_writers)) |
| 179 | return 0; |
| 180 | |
| 181 | read_lock(&eb->lock); |
| 182 | if (atomic_read(&eb->blocking_writers)) { |
| 183 | read_unlock(&eb->lock); |
| 184 | return 0; |
| 185 | } |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame^] | 186 | btrfs_assert_tree_read_locks_get(eb); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 187 | btrfs_assert_spinning_readers_get(eb); |
Chris Mason | f82c458 | 2014-11-19 10:25:09 -0800 | [diff] [blame] | 188 | return 1; |
| 189 | } |
| 190 | |
| 191 | /* |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 192 | * returns 1 if we get the read lock and 0 if we don't |
| 193 | * this won't wait for blocking writers |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 194 | */ |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 195 | int btrfs_try_tree_read_lock(struct extent_buffer *eb) |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 196 | { |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 197 | if (atomic_read(&eb->blocking_writers)) |
| 198 | return 0; |
Chris Mason | 66d7e85 | 2009-03-12 20:12:45 -0400 | [diff] [blame] | 199 | |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 200 | if (!read_trylock(&eb->lock)) |
| 201 | return 0; |
| 202 | |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 203 | if (atomic_read(&eb->blocking_writers)) { |
| 204 | read_unlock(&eb->lock); |
| 205 | return 0; |
Chris Mason | f9efa9c | 2008-06-25 16:14:04 -0400 | [diff] [blame] | 206 | } |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame^] | 207 | btrfs_assert_tree_read_locks_get(eb); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 208 | btrfs_assert_spinning_readers_get(eb); |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 209 | return 1; |
| 210 | } |
| 211 | |
| 212 | /* |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 213 | * returns 1 if we get the read lock and 0 if we don't |
| 214 | * this won't wait for blocking writers or readers |
| 215 | */ |
| 216 | int btrfs_try_tree_write_lock(struct extent_buffer *eb) |
| 217 | { |
| 218 | if (atomic_read(&eb->blocking_writers) || |
| 219 | atomic_read(&eb->blocking_readers)) |
| 220 | return 0; |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 221 | |
Chris Mason | f82c458 | 2014-11-19 10:25:09 -0800 | [diff] [blame] | 222 | write_lock(&eb->lock); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 223 | if (atomic_read(&eb->blocking_writers) || |
| 224 | atomic_read(&eb->blocking_readers)) { |
| 225 | write_unlock(&eb->lock); |
| 226 | return 0; |
| 227 | } |
| 228 | atomic_inc(&eb->write_locks); |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 229 | btrfs_assert_spinning_writers_get(eb); |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 230 | eb->lock_owner = current->pid; |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 231 | return 1; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * drop a spinning read lock |
| 236 | */ |
| 237 | void btrfs_tree_read_unlock(struct extent_buffer *eb) |
| 238 | { |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 239 | /* |
| 240 | * if we're nested, we have the write lock. No new locking |
| 241 | * is needed as long as we are the lock owner. |
| 242 | * The write unlock will do a barrier for us, and the lock_nested |
| 243 | * field only matters to the lock owner. |
| 244 | */ |
| 245 | if (eb->lock_nested && current->pid == eb->lock_owner) { |
| 246 | eb->lock_nested = 0; |
| 247 | return; |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 248 | } |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 249 | btrfs_assert_tree_read_locked(eb); |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 250 | btrfs_assert_spinning_readers_put(eb); |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame^] | 251 | btrfs_assert_tree_read_locks_put(eb); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 252 | read_unlock(&eb->lock); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * drop a blocking read lock |
| 257 | */ |
| 258 | void btrfs_tree_read_unlock_blocking(struct extent_buffer *eb) |
| 259 | { |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 260 | /* |
| 261 | * if we're nested, we have the write lock. No new locking |
| 262 | * is needed as long as we are the lock owner. |
| 263 | * The write unlock will do a barrier for us, and the lock_nested |
| 264 | * field only matters to the lock owner. |
| 265 | */ |
| 266 | if (eb->lock_nested && current->pid == eb->lock_owner) { |
| 267 | eb->lock_nested = 0; |
| 268 | return; |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 269 | } |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 270 | btrfs_assert_tree_read_locked(eb); |
| 271 | WARN_ON(atomic_read(&eb->blocking_readers) == 0); |
David Sterba | 093258e | 2018-02-26 16:15:17 +0100 | [diff] [blame] | 272 | /* atomic_dec_and_test implies a barrier */ |
| 273 | if (atomic_dec_and_test(&eb->blocking_readers)) |
| 274 | cond_wake_up_nomb(&eb->read_lock_wq); |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame^] | 275 | btrfs_assert_tree_read_locks_put(eb); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* |
| 279 | * take a spinning write lock. This will wait for both |
| 280 | * blocking readers or writers |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 281 | */ |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 282 | void btrfs_tree_lock(struct extent_buffer *eb) |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 283 | { |
Zhaolei | 166f66d | 2015-08-06 22:39:36 +0800 | [diff] [blame] | 284 | WARN_ON(eb->lock_owner == current->pid); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 285 | again: |
| 286 | wait_event(eb->read_lock_wq, atomic_read(&eb->blocking_readers) == 0); |
| 287 | wait_event(eb->write_lock_wq, atomic_read(&eb->blocking_writers) == 0); |
| 288 | write_lock(&eb->lock); |
David Sterba | 970e74d | 2018-04-04 02:11:50 +0200 | [diff] [blame] | 289 | if (atomic_read(&eb->blocking_readers) || |
| 290 | atomic_read(&eb->blocking_writers)) { |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 291 | write_unlock(&eb->lock); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 292 | goto again; |
| 293 | } |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 294 | btrfs_assert_spinning_writers_get(eb); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 295 | atomic_inc(&eb->write_locks); |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 296 | eb->lock_owner = current->pid; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 299 | /* |
| 300 | * drop a spinning or a blocking write lock. |
| 301 | */ |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 302 | void btrfs_tree_unlock(struct extent_buffer *eb) |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 303 | { |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 304 | int blockers = atomic_read(&eb->blocking_writers); |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 305 | |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 306 | BUG_ON(blockers > 1); |
| 307 | |
| 308 | btrfs_assert_tree_locked(eb); |
Chris Mason | ea4ebde | 2014-06-19 14:16:52 -0700 | [diff] [blame] | 309 | eb->lock_owner = 0; |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 310 | atomic_dec(&eb->write_locks); |
| 311 | |
| 312 | if (blockers) { |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 313 | btrfs_assert_no_spinning_writers(eb); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 314 | atomic_dec(&eb->blocking_writers); |
David Sterba | 093258e | 2018-02-26 16:15:17 +0100 | [diff] [blame] | 315 | /* Use the lighter barrier after atomic */ |
Nikolay Borisov | 2e32ef8 | 2018-02-14 14:37:26 +0200 | [diff] [blame] | 316 | smp_mb__after_atomic(); |
David Sterba | 093258e | 2018-02-26 16:15:17 +0100 | [diff] [blame] | 317 | cond_wake_up_nomb(&eb->write_lock_wq); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 318 | } else { |
David Sterba | 843ccf9 | 2018-08-24 14:56:28 +0200 | [diff] [blame] | 319 | btrfs_assert_spinning_writers_put(eb); |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 320 | write_unlock(&eb->lock); |
| 321 | } |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Chris Mason | b9447ef8 | 2009-03-09 11:45:38 -0400 | [diff] [blame] | 324 | void btrfs_assert_tree_locked(struct extent_buffer *eb) |
Chris Mason | 925baed | 2008-06-25 16:01:30 -0400 | [diff] [blame] | 325 | { |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 326 | BUG_ON(!atomic_read(&eb->write_locks)); |
| 327 | } |