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