.. | .. |
---|
9 | 9 | #include "../disk-io.h" |
---|
10 | 10 | #include "../free-space-tree.h" |
---|
11 | 11 | #include "../transaction.h" |
---|
| 12 | +#include "../block-group.h" |
---|
12 | 13 | |
---|
13 | 14 | struct free_space_extent { |
---|
14 | 15 | u64 start; |
---|
.. | .. |
---|
17 | 18 | |
---|
18 | 19 | static int __check_free_space_extents(struct btrfs_trans_handle *trans, |
---|
19 | 20 | struct btrfs_fs_info *fs_info, |
---|
20 | | - struct btrfs_block_group_cache *cache, |
---|
| 21 | + struct btrfs_block_group *cache, |
---|
21 | 22 | struct btrfs_path *path, |
---|
22 | 23 | const struct free_space_extent * const extents, |
---|
23 | 24 | unsigned int num_extents) |
---|
.. | .. |
---|
30 | 31 | unsigned int i; |
---|
31 | 32 | int ret; |
---|
32 | 33 | |
---|
33 | | - info = search_free_space_info(trans, fs_info, cache, path, 0); |
---|
| 34 | + info = search_free_space_info(trans, cache, path, 0); |
---|
34 | 35 | if (IS_ERR(info)) { |
---|
35 | 36 | test_err("could not find free space info"); |
---|
36 | 37 | ret = PTR_ERR(info); |
---|
.. | .. |
---|
47 | 48 | if (flags & BTRFS_FREE_SPACE_USING_BITMAPS) { |
---|
48 | 49 | if (path->slots[0] != 0) |
---|
49 | 50 | goto invalid; |
---|
50 | | - end = cache->key.objectid + cache->key.offset; |
---|
| 51 | + end = cache->start + cache->length; |
---|
51 | 52 | i = 0; |
---|
52 | 53 | while (++path->slots[0] < btrfs_header_nritems(path->nodes[0])) { |
---|
53 | 54 | btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); |
---|
.. | .. |
---|
59 | 60 | if (prev_bit == 0 && bit == 1) { |
---|
60 | 61 | extent_start = offset; |
---|
61 | 62 | } else if (prev_bit == 1 && bit == 0) { |
---|
62 | | - if (i >= num_extents) |
---|
63 | | - goto invalid; |
---|
64 | 63 | if (i >= num_extents || |
---|
65 | 64 | extent_start != extents[i].start || |
---|
66 | 65 | offset - extent_start != extents[i].length) |
---|
.. | .. |
---|
106 | 105 | |
---|
107 | 106 | static int check_free_space_extents(struct btrfs_trans_handle *trans, |
---|
108 | 107 | struct btrfs_fs_info *fs_info, |
---|
109 | | - struct btrfs_block_group_cache *cache, |
---|
| 108 | + struct btrfs_block_group *cache, |
---|
110 | 109 | struct btrfs_path *path, |
---|
111 | 110 | const struct free_space_extent * const extents, |
---|
112 | 111 | unsigned int num_extents) |
---|
.. | .. |
---|
115 | 114 | u32 flags; |
---|
116 | 115 | int ret; |
---|
117 | 116 | |
---|
118 | | - info = search_free_space_info(trans, fs_info, cache, path, 0); |
---|
| 117 | + info = search_free_space_info(trans, cache, path, 0); |
---|
119 | 118 | if (IS_ERR(info)) { |
---|
120 | 119 | test_err("could not find free space info"); |
---|
121 | 120 | btrfs_release_path(path); |
---|
.. | .. |
---|
149 | 148 | |
---|
150 | 149 | static int test_empty_block_group(struct btrfs_trans_handle *trans, |
---|
151 | 150 | struct btrfs_fs_info *fs_info, |
---|
152 | | - struct btrfs_block_group_cache *cache, |
---|
| 151 | + struct btrfs_block_group *cache, |
---|
153 | 152 | struct btrfs_path *path, |
---|
154 | 153 | u32 alignment) |
---|
155 | 154 | { |
---|
156 | 155 | const struct free_space_extent extents[] = { |
---|
157 | | - {cache->key.objectid, cache->key.offset}, |
---|
| 156 | + {cache->start, cache->length}, |
---|
158 | 157 | }; |
---|
159 | 158 | |
---|
160 | 159 | return check_free_space_extents(trans, fs_info, cache, path, |
---|
.. | .. |
---|
163 | 162 | |
---|
164 | 163 | static int test_remove_all(struct btrfs_trans_handle *trans, |
---|
165 | 164 | struct btrfs_fs_info *fs_info, |
---|
166 | | - struct btrfs_block_group_cache *cache, |
---|
| 165 | + struct btrfs_block_group *cache, |
---|
167 | 166 | struct btrfs_path *path, |
---|
168 | 167 | u32 alignment) |
---|
169 | 168 | { |
---|
.. | .. |
---|
171 | 170 | int ret; |
---|
172 | 171 | |
---|
173 | 172 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
174 | | - cache->key.objectid, |
---|
175 | | - cache->key.offset); |
---|
| 173 | + cache->start, |
---|
| 174 | + cache->length); |
---|
176 | 175 | if (ret) { |
---|
177 | 176 | test_err("could not remove free space"); |
---|
178 | 177 | return ret; |
---|
.. | .. |
---|
184 | 183 | |
---|
185 | 184 | static int test_remove_beginning(struct btrfs_trans_handle *trans, |
---|
186 | 185 | struct btrfs_fs_info *fs_info, |
---|
187 | | - struct btrfs_block_group_cache *cache, |
---|
| 186 | + struct btrfs_block_group *cache, |
---|
188 | 187 | struct btrfs_path *path, |
---|
189 | 188 | u32 alignment) |
---|
190 | 189 | { |
---|
191 | 190 | const struct free_space_extent extents[] = { |
---|
192 | | - {cache->key.objectid + alignment, |
---|
193 | | - cache->key.offset - alignment}, |
---|
| 191 | + {cache->start + alignment, cache->length - alignment}, |
---|
194 | 192 | }; |
---|
195 | 193 | int ret; |
---|
196 | 194 | |
---|
197 | 195 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
198 | | - cache->key.objectid, alignment); |
---|
| 196 | + cache->start, alignment); |
---|
199 | 197 | if (ret) { |
---|
200 | 198 | test_err("could not remove free space"); |
---|
201 | 199 | return ret; |
---|
.. | .. |
---|
208 | 206 | |
---|
209 | 207 | static int test_remove_end(struct btrfs_trans_handle *trans, |
---|
210 | 208 | struct btrfs_fs_info *fs_info, |
---|
211 | | - struct btrfs_block_group_cache *cache, |
---|
| 209 | + struct btrfs_block_group *cache, |
---|
212 | 210 | struct btrfs_path *path, |
---|
213 | 211 | u32 alignment) |
---|
214 | 212 | { |
---|
215 | 213 | const struct free_space_extent extents[] = { |
---|
216 | | - {cache->key.objectid, cache->key.offset - alignment}, |
---|
| 214 | + {cache->start, cache->length - alignment}, |
---|
217 | 215 | }; |
---|
218 | 216 | int ret; |
---|
219 | 217 | |
---|
220 | 218 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
221 | | - cache->key.objectid + |
---|
222 | | - cache->key.offset - alignment, |
---|
223 | | - alignment); |
---|
| 219 | + cache->start + cache->length - alignment, |
---|
| 220 | + alignment); |
---|
224 | 221 | if (ret) { |
---|
225 | 222 | test_err("could not remove free space"); |
---|
226 | 223 | return ret; |
---|
.. | .. |
---|
232 | 229 | |
---|
233 | 230 | static int test_remove_middle(struct btrfs_trans_handle *trans, |
---|
234 | 231 | struct btrfs_fs_info *fs_info, |
---|
235 | | - struct btrfs_block_group_cache *cache, |
---|
| 232 | + struct btrfs_block_group *cache, |
---|
236 | 233 | struct btrfs_path *path, |
---|
237 | 234 | u32 alignment) |
---|
238 | 235 | { |
---|
239 | 236 | const struct free_space_extent extents[] = { |
---|
240 | | - {cache->key.objectid, alignment}, |
---|
241 | | - {cache->key.objectid + 2 * alignment, |
---|
242 | | - cache->key.offset - 2 * alignment}, |
---|
| 237 | + {cache->start, alignment}, |
---|
| 238 | + {cache->start + 2 * alignment, cache->length - 2 * alignment}, |
---|
243 | 239 | }; |
---|
244 | 240 | int ret; |
---|
245 | 241 | |
---|
246 | 242 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
247 | | - cache->key.objectid + alignment, |
---|
| 243 | + cache->start + alignment, |
---|
248 | 244 | alignment); |
---|
249 | 245 | if (ret) { |
---|
250 | 246 | test_err("could not remove free space"); |
---|
.. | .. |
---|
257 | 253 | |
---|
258 | 254 | static int test_merge_left(struct btrfs_trans_handle *trans, |
---|
259 | 255 | struct btrfs_fs_info *fs_info, |
---|
260 | | - struct btrfs_block_group_cache *cache, |
---|
| 256 | + struct btrfs_block_group *cache, |
---|
261 | 257 | struct btrfs_path *path, |
---|
262 | 258 | u32 alignment) |
---|
263 | 259 | { |
---|
264 | 260 | const struct free_space_extent extents[] = { |
---|
265 | | - {cache->key.objectid, 2 * alignment}, |
---|
| 261 | + {cache->start, 2 * alignment}, |
---|
266 | 262 | }; |
---|
267 | 263 | int ret; |
---|
268 | 264 | |
---|
269 | 265 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
270 | | - cache->key.objectid, |
---|
271 | | - cache->key.offset); |
---|
| 266 | + cache->start, cache->length); |
---|
272 | 267 | if (ret) { |
---|
273 | 268 | test_err("could not remove free space"); |
---|
274 | 269 | return ret; |
---|
275 | 270 | } |
---|
276 | 271 | |
---|
277 | | - ret = __add_to_free_space_tree(trans, cache, path, cache->key.objectid, |
---|
| 272 | + ret = __add_to_free_space_tree(trans, cache, path, cache->start, |
---|
278 | 273 | alignment); |
---|
279 | 274 | if (ret) { |
---|
280 | 275 | test_err("could not add free space"); |
---|
.. | .. |
---|
282 | 277 | } |
---|
283 | 278 | |
---|
284 | 279 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
285 | | - cache->key.objectid + alignment, |
---|
| 280 | + cache->start + alignment, |
---|
286 | 281 | alignment); |
---|
287 | 282 | if (ret) { |
---|
288 | 283 | test_err("could not add free space"); |
---|
.. | .. |
---|
295 | 290 | |
---|
296 | 291 | static int test_merge_right(struct btrfs_trans_handle *trans, |
---|
297 | 292 | struct btrfs_fs_info *fs_info, |
---|
298 | | - struct btrfs_block_group_cache *cache, |
---|
| 293 | + struct btrfs_block_group *cache, |
---|
299 | 294 | struct btrfs_path *path, |
---|
300 | 295 | u32 alignment) |
---|
301 | 296 | { |
---|
302 | 297 | const struct free_space_extent extents[] = { |
---|
303 | | - {cache->key.objectid + alignment, 2 * alignment}, |
---|
| 298 | + {cache->start + alignment, 2 * alignment}, |
---|
304 | 299 | }; |
---|
305 | 300 | int ret; |
---|
306 | 301 | |
---|
307 | 302 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
308 | | - cache->key.objectid, |
---|
309 | | - cache->key.offset); |
---|
| 303 | + cache->start, cache->length); |
---|
310 | 304 | if (ret) { |
---|
311 | 305 | test_err("could not remove free space"); |
---|
312 | 306 | return ret; |
---|
313 | 307 | } |
---|
314 | 308 | |
---|
315 | 309 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
316 | | - cache->key.objectid + 2 * alignment, |
---|
| 310 | + cache->start + 2 * alignment, |
---|
317 | 311 | alignment); |
---|
318 | 312 | if (ret) { |
---|
319 | 313 | test_err("could not add free space"); |
---|
.. | .. |
---|
321 | 315 | } |
---|
322 | 316 | |
---|
323 | 317 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
324 | | - cache->key.objectid + alignment, |
---|
| 318 | + cache->start + alignment, |
---|
325 | 319 | alignment); |
---|
326 | 320 | if (ret) { |
---|
327 | 321 | test_err("could not add free space"); |
---|
.. | .. |
---|
334 | 328 | |
---|
335 | 329 | static int test_merge_both(struct btrfs_trans_handle *trans, |
---|
336 | 330 | struct btrfs_fs_info *fs_info, |
---|
337 | | - struct btrfs_block_group_cache *cache, |
---|
| 331 | + struct btrfs_block_group *cache, |
---|
338 | 332 | struct btrfs_path *path, |
---|
339 | 333 | u32 alignment) |
---|
340 | 334 | { |
---|
341 | 335 | const struct free_space_extent extents[] = { |
---|
342 | | - {cache->key.objectid, 3 * alignment}, |
---|
| 336 | + {cache->start, 3 * alignment}, |
---|
343 | 337 | }; |
---|
344 | 338 | int ret; |
---|
345 | 339 | |
---|
346 | 340 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
347 | | - cache->key.objectid, |
---|
348 | | - cache->key.offset); |
---|
| 341 | + cache->start, cache->length); |
---|
349 | 342 | if (ret) { |
---|
350 | 343 | test_err("could not remove free space"); |
---|
351 | 344 | return ret; |
---|
352 | 345 | } |
---|
353 | 346 | |
---|
354 | | - ret = __add_to_free_space_tree(trans, cache, path, cache->key.objectid, |
---|
| 347 | + ret = __add_to_free_space_tree(trans, cache, path, cache->start, |
---|
355 | 348 | alignment); |
---|
356 | 349 | if (ret) { |
---|
357 | 350 | test_err("could not add free space"); |
---|
.. | .. |
---|
359 | 352 | } |
---|
360 | 353 | |
---|
361 | 354 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
362 | | - cache->key.objectid + 2 * alignment, |
---|
363 | | - alignment); |
---|
| 355 | + cache->start + 2 * alignment, alignment); |
---|
364 | 356 | if (ret) { |
---|
365 | 357 | test_err("could not add free space"); |
---|
366 | 358 | return ret; |
---|
367 | 359 | } |
---|
368 | 360 | |
---|
369 | 361 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
370 | | - cache->key.objectid + alignment, |
---|
371 | | - alignment); |
---|
| 362 | + cache->start + alignment, alignment); |
---|
372 | 363 | if (ret) { |
---|
373 | 364 | test_err("could not add free space"); |
---|
374 | 365 | return ret; |
---|
.. | .. |
---|
380 | 371 | |
---|
381 | 372 | static int test_merge_none(struct btrfs_trans_handle *trans, |
---|
382 | 373 | struct btrfs_fs_info *fs_info, |
---|
383 | | - struct btrfs_block_group_cache *cache, |
---|
| 374 | + struct btrfs_block_group *cache, |
---|
384 | 375 | struct btrfs_path *path, |
---|
385 | 376 | u32 alignment) |
---|
386 | 377 | { |
---|
387 | 378 | const struct free_space_extent extents[] = { |
---|
388 | | - {cache->key.objectid, alignment}, |
---|
389 | | - {cache->key.objectid + 2 * alignment, alignment}, |
---|
390 | | - {cache->key.objectid + 4 * alignment, alignment}, |
---|
| 379 | + {cache->start, alignment}, |
---|
| 380 | + {cache->start + 2 * alignment, alignment}, |
---|
| 381 | + {cache->start + 4 * alignment, alignment}, |
---|
391 | 382 | }; |
---|
392 | 383 | int ret; |
---|
393 | 384 | |
---|
394 | 385 | ret = __remove_from_free_space_tree(trans, cache, path, |
---|
395 | | - cache->key.objectid, |
---|
396 | | - cache->key.offset); |
---|
| 386 | + cache->start, cache->length); |
---|
397 | 387 | if (ret) { |
---|
398 | 388 | test_err("could not remove free space"); |
---|
399 | 389 | return ret; |
---|
400 | 390 | } |
---|
401 | 391 | |
---|
402 | | - ret = __add_to_free_space_tree(trans, cache, path, cache->key.objectid, |
---|
| 392 | + ret = __add_to_free_space_tree(trans, cache, path, cache->start, |
---|
403 | 393 | alignment); |
---|
404 | 394 | if (ret) { |
---|
405 | 395 | test_err("could not add free space"); |
---|
.. | .. |
---|
407 | 397 | } |
---|
408 | 398 | |
---|
409 | 399 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
410 | | - cache->key.objectid + 4 * alignment, |
---|
411 | | - alignment); |
---|
| 400 | + cache->start + 4 * alignment, alignment); |
---|
412 | 401 | if (ret) { |
---|
413 | 402 | test_err("could not add free space"); |
---|
414 | 403 | return ret; |
---|
415 | 404 | } |
---|
416 | 405 | |
---|
417 | 406 | ret = __add_to_free_space_tree(trans, cache, path, |
---|
418 | | - cache->key.objectid + 2 * alignment, |
---|
419 | | - alignment); |
---|
| 407 | + cache->start + 2 * alignment, alignment); |
---|
420 | 408 | if (ret) { |
---|
421 | 409 | test_err("could not add free space"); |
---|
422 | 410 | return ret; |
---|
.. | .. |
---|
428 | 416 | |
---|
429 | 417 | typedef int (*test_func_t)(struct btrfs_trans_handle *, |
---|
430 | 418 | struct btrfs_fs_info *, |
---|
431 | | - struct btrfs_block_group_cache *, |
---|
| 419 | + struct btrfs_block_group *, |
---|
432 | 420 | struct btrfs_path *, |
---|
433 | 421 | u32 alignment); |
---|
434 | 422 | |
---|
.. | .. |
---|
437 | 425 | { |
---|
438 | 426 | struct btrfs_fs_info *fs_info; |
---|
439 | 427 | struct btrfs_root *root = NULL; |
---|
440 | | - struct btrfs_block_group_cache *cache = NULL; |
---|
| 428 | + struct btrfs_block_group *cache = NULL; |
---|
441 | 429 | struct btrfs_trans_handle trans; |
---|
442 | 430 | struct btrfs_path *path = NULL; |
---|
443 | 431 | int ret; |
---|
444 | 432 | |
---|
445 | 433 | fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); |
---|
446 | 434 | if (!fs_info) { |
---|
447 | | - test_err("couldn't allocate dummy fs info"); |
---|
| 435 | + test_std_err(TEST_ALLOC_FS_INFO); |
---|
448 | 436 | ret = -ENOMEM; |
---|
449 | 437 | goto out; |
---|
450 | 438 | } |
---|
451 | 439 | |
---|
452 | 440 | root = btrfs_alloc_dummy_root(fs_info); |
---|
453 | 441 | if (IS_ERR(root)) { |
---|
454 | | - test_err("couldn't allocate dummy root"); |
---|
| 442 | + test_std_err(TEST_ALLOC_ROOT); |
---|
455 | 443 | ret = PTR_ERR(root); |
---|
456 | 444 | goto out; |
---|
457 | 445 | } |
---|
.. | .. |
---|
463 | 451 | |
---|
464 | 452 | root->node = alloc_test_extent_buffer(root->fs_info, nodesize); |
---|
465 | 453 | if (IS_ERR(root->node)) { |
---|
466 | | - test_err("couldn't allocate dummy buffer"); |
---|
| 454 | + test_std_err(TEST_ALLOC_EXTENT_BUFFER); |
---|
467 | 455 | ret = PTR_ERR(root->node); |
---|
468 | 456 | goto out; |
---|
469 | 457 | } |
---|
.. | .. |
---|
473 | 461 | |
---|
474 | 462 | cache = btrfs_alloc_dummy_block_group(fs_info, 8 * alignment); |
---|
475 | 463 | if (!cache) { |
---|
476 | | - test_err("couldn't allocate dummy block group cache"); |
---|
| 464 | + test_std_err(TEST_ALLOC_BLOCK_GROUP); |
---|
477 | 465 | ret = -ENOMEM; |
---|
478 | 466 | goto out; |
---|
479 | 467 | } |
---|
.. | .. |
---|
486 | 474 | |
---|
487 | 475 | path = btrfs_alloc_path(); |
---|
488 | 476 | if (!path) { |
---|
489 | | - test_err("couldn't allocate path"); |
---|
| 477 | + test_std_err(TEST_ALLOC_ROOT); |
---|
490 | 478 | ret = -ENOMEM; |
---|
491 | 479 | goto out; |
---|
492 | 480 | } |
---|
.. | .. |
---|
539 | 527 | ret = run_test(test_func, 0, sectorsize, nodesize, alignment); |
---|
540 | 528 | if (ret) { |
---|
541 | 529 | test_err( |
---|
542 | | - "%pf failed with extents, sectorsize=%u, nodesize=%u, alignment=%u", |
---|
| 530 | + "%ps failed with extents, sectorsize=%u, nodesize=%u, alignment=%u", |
---|
543 | 531 | test_func, sectorsize, nodesize, alignment); |
---|
544 | 532 | test_ret = ret; |
---|
545 | 533 | } |
---|
.. | .. |
---|
547 | 535 | ret = run_test(test_func, 1, sectorsize, nodesize, alignment); |
---|
548 | 536 | if (ret) { |
---|
549 | 537 | test_err( |
---|
550 | | - "%pf failed with bitmaps, sectorsize=%u, nodesize=%u, alignment=%u", |
---|
| 538 | + "%ps failed with bitmaps, sectorsize=%u, nodesize=%u, alignment=%u", |
---|
551 | 539 | test_func, sectorsize, nodesize, alignment); |
---|
552 | 540 | test_ret = ret; |
---|
553 | 541 | } |
---|