hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/fs/btrfs/tests/free-space-tree-tests.c
....@@ -9,6 +9,7 @@
99 #include "../disk-io.h"
1010 #include "../free-space-tree.h"
1111 #include "../transaction.h"
12
+#include "../block-group.h"
1213
1314 struct free_space_extent {
1415 u64 start;
....@@ -17,7 +18,7 @@
1718
1819 static int __check_free_space_extents(struct btrfs_trans_handle *trans,
1920 struct btrfs_fs_info *fs_info,
20
- struct btrfs_block_group_cache *cache,
21
+ struct btrfs_block_group *cache,
2122 struct btrfs_path *path,
2223 const struct free_space_extent * const extents,
2324 unsigned int num_extents)
....@@ -30,7 +31,7 @@
3031 unsigned int i;
3132 int ret;
3233
33
- info = search_free_space_info(trans, fs_info, cache, path, 0);
34
+ info = search_free_space_info(trans, cache, path, 0);
3435 if (IS_ERR(info)) {
3536 test_err("could not find free space info");
3637 ret = PTR_ERR(info);
....@@ -47,7 +48,7 @@
4748 if (flags & BTRFS_FREE_SPACE_USING_BITMAPS) {
4849 if (path->slots[0] != 0)
4950 goto invalid;
50
- end = cache->key.objectid + cache->key.offset;
51
+ end = cache->start + cache->length;
5152 i = 0;
5253 while (++path->slots[0] < btrfs_header_nritems(path->nodes[0])) {
5354 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
....@@ -59,8 +60,6 @@
5960 if (prev_bit == 0 && bit == 1) {
6061 extent_start = offset;
6162 } else if (prev_bit == 1 && bit == 0) {
62
- if (i >= num_extents)
63
- goto invalid;
6463 if (i >= num_extents ||
6564 extent_start != extents[i].start ||
6665 offset - extent_start != extents[i].length)
....@@ -106,7 +105,7 @@
106105
107106 static int check_free_space_extents(struct btrfs_trans_handle *trans,
108107 struct btrfs_fs_info *fs_info,
109
- struct btrfs_block_group_cache *cache,
108
+ struct btrfs_block_group *cache,
110109 struct btrfs_path *path,
111110 const struct free_space_extent * const extents,
112111 unsigned int num_extents)
....@@ -115,7 +114,7 @@
115114 u32 flags;
116115 int ret;
117116
118
- info = search_free_space_info(trans, fs_info, cache, path, 0);
117
+ info = search_free_space_info(trans, cache, path, 0);
119118 if (IS_ERR(info)) {
120119 test_err("could not find free space info");
121120 btrfs_release_path(path);
....@@ -149,12 +148,12 @@
149148
150149 static int test_empty_block_group(struct btrfs_trans_handle *trans,
151150 struct btrfs_fs_info *fs_info,
152
- struct btrfs_block_group_cache *cache,
151
+ struct btrfs_block_group *cache,
153152 struct btrfs_path *path,
154153 u32 alignment)
155154 {
156155 const struct free_space_extent extents[] = {
157
- {cache->key.objectid, cache->key.offset},
156
+ {cache->start, cache->length},
158157 };
159158
160159 return check_free_space_extents(trans, fs_info, cache, path,
....@@ -163,7 +162,7 @@
163162
164163 static int test_remove_all(struct btrfs_trans_handle *trans,
165164 struct btrfs_fs_info *fs_info,
166
- struct btrfs_block_group_cache *cache,
165
+ struct btrfs_block_group *cache,
167166 struct btrfs_path *path,
168167 u32 alignment)
169168 {
....@@ -171,8 +170,8 @@
171170 int ret;
172171
173172 ret = __remove_from_free_space_tree(trans, cache, path,
174
- cache->key.objectid,
175
- cache->key.offset);
173
+ cache->start,
174
+ cache->length);
176175 if (ret) {
177176 test_err("could not remove free space");
178177 return ret;
....@@ -184,18 +183,17 @@
184183
185184 static int test_remove_beginning(struct btrfs_trans_handle *trans,
186185 struct btrfs_fs_info *fs_info,
187
- struct btrfs_block_group_cache *cache,
186
+ struct btrfs_block_group *cache,
188187 struct btrfs_path *path,
189188 u32 alignment)
190189 {
191190 const struct free_space_extent extents[] = {
192
- {cache->key.objectid + alignment,
193
- cache->key.offset - alignment},
191
+ {cache->start + alignment, cache->length - alignment},
194192 };
195193 int ret;
196194
197195 ret = __remove_from_free_space_tree(trans, cache, path,
198
- cache->key.objectid, alignment);
196
+ cache->start, alignment);
199197 if (ret) {
200198 test_err("could not remove free space");
201199 return ret;
....@@ -208,19 +206,18 @@
208206
209207 static int test_remove_end(struct btrfs_trans_handle *trans,
210208 struct btrfs_fs_info *fs_info,
211
- struct btrfs_block_group_cache *cache,
209
+ struct btrfs_block_group *cache,
212210 struct btrfs_path *path,
213211 u32 alignment)
214212 {
215213 const struct free_space_extent extents[] = {
216
- {cache->key.objectid, cache->key.offset - alignment},
214
+ {cache->start, cache->length - alignment},
217215 };
218216 int ret;
219217
220218 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);
224221 if (ret) {
225222 test_err("could not remove free space");
226223 return ret;
....@@ -232,19 +229,18 @@
232229
233230 static int test_remove_middle(struct btrfs_trans_handle *trans,
234231 struct btrfs_fs_info *fs_info,
235
- struct btrfs_block_group_cache *cache,
232
+ struct btrfs_block_group *cache,
236233 struct btrfs_path *path,
237234 u32 alignment)
238235 {
239236 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},
243239 };
244240 int ret;
245241
246242 ret = __remove_from_free_space_tree(trans, cache, path,
247
- cache->key.objectid + alignment,
243
+ cache->start + alignment,
248244 alignment);
249245 if (ret) {
250246 test_err("could not remove free space");
....@@ -257,24 +253,23 @@
257253
258254 static int test_merge_left(struct btrfs_trans_handle *trans,
259255 struct btrfs_fs_info *fs_info,
260
- struct btrfs_block_group_cache *cache,
256
+ struct btrfs_block_group *cache,
261257 struct btrfs_path *path,
262258 u32 alignment)
263259 {
264260 const struct free_space_extent extents[] = {
265
- {cache->key.objectid, 2 * alignment},
261
+ {cache->start, 2 * alignment},
266262 };
267263 int ret;
268264
269265 ret = __remove_from_free_space_tree(trans, cache, path,
270
- cache->key.objectid,
271
- cache->key.offset);
266
+ cache->start, cache->length);
272267 if (ret) {
273268 test_err("could not remove free space");
274269 return ret;
275270 }
276271
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,
278273 alignment);
279274 if (ret) {
280275 test_err("could not add free space");
....@@ -282,7 +277,7 @@
282277 }
283278
284279 ret = __add_to_free_space_tree(trans, cache, path,
285
- cache->key.objectid + alignment,
280
+ cache->start + alignment,
286281 alignment);
287282 if (ret) {
288283 test_err("could not add free space");
....@@ -295,25 +290,24 @@
295290
296291 static int test_merge_right(struct btrfs_trans_handle *trans,
297292 struct btrfs_fs_info *fs_info,
298
- struct btrfs_block_group_cache *cache,
293
+ struct btrfs_block_group *cache,
299294 struct btrfs_path *path,
300295 u32 alignment)
301296 {
302297 const struct free_space_extent extents[] = {
303
- {cache->key.objectid + alignment, 2 * alignment},
298
+ {cache->start + alignment, 2 * alignment},
304299 };
305300 int ret;
306301
307302 ret = __remove_from_free_space_tree(trans, cache, path,
308
- cache->key.objectid,
309
- cache->key.offset);
303
+ cache->start, cache->length);
310304 if (ret) {
311305 test_err("could not remove free space");
312306 return ret;
313307 }
314308
315309 ret = __add_to_free_space_tree(trans, cache, path,
316
- cache->key.objectid + 2 * alignment,
310
+ cache->start + 2 * alignment,
317311 alignment);
318312 if (ret) {
319313 test_err("could not add free space");
....@@ -321,7 +315,7 @@
321315 }
322316
323317 ret = __add_to_free_space_tree(trans, cache, path,
324
- cache->key.objectid + alignment,
318
+ cache->start + alignment,
325319 alignment);
326320 if (ret) {
327321 test_err("could not add free space");
....@@ -334,24 +328,23 @@
334328
335329 static int test_merge_both(struct btrfs_trans_handle *trans,
336330 struct btrfs_fs_info *fs_info,
337
- struct btrfs_block_group_cache *cache,
331
+ struct btrfs_block_group *cache,
338332 struct btrfs_path *path,
339333 u32 alignment)
340334 {
341335 const struct free_space_extent extents[] = {
342
- {cache->key.objectid, 3 * alignment},
336
+ {cache->start, 3 * alignment},
343337 };
344338 int ret;
345339
346340 ret = __remove_from_free_space_tree(trans, cache, path,
347
- cache->key.objectid,
348
- cache->key.offset);
341
+ cache->start, cache->length);
349342 if (ret) {
350343 test_err("could not remove free space");
351344 return ret;
352345 }
353346
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,
355348 alignment);
356349 if (ret) {
357350 test_err("could not add free space");
....@@ -359,16 +352,14 @@
359352 }
360353
361354 ret = __add_to_free_space_tree(trans, cache, path,
362
- cache->key.objectid + 2 * alignment,
363
- alignment);
355
+ cache->start + 2 * alignment, alignment);
364356 if (ret) {
365357 test_err("could not add free space");
366358 return ret;
367359 }
368360
369361 ret = __add_to_free_space_tree(trans, cache, path,
370
- cache->key.objectid + alignment,
371
- alignment);
362
+ cache->start + alignment, alignment);
372363 if (ret) {
373364 test_err("could not add free space");
374365 return ret;
....@@ -380,26 +371,25 @@
380371
381372 static int test_merge_none(struct btrfs_trans_handle *trans,
382373 struct btrfs_fs_info *fs_info,
383
- struct btrfs_block_group_cache *cache,
374
+ struct btrfs_block_group *cache,
384375 struct btrfs_path *path,
385376 u32 alignment)
386377 {
387378 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},
391382 };
392383 int ret;
393384
394385 ret = __remove_from_free_space_tree(trans, cache, path,
395
- cache->key.objectid,
396
- cache->key.offset);
386
+ cache->start, cache->length);
397387 if (ret) {
398388 test_err("could not remove free space");
399389 return ret;
400390 }
401391
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,
403393 alignment);
404394 if (ret) {
405395 test_err("could not add free space");
....@@ -407,16 +397,14 @@
407397 }
408398
409399 ret = __add_to_free_space_tree(trans, cache, path,
410
- cache->key.objectid + 4 * alignment,
411
- alignment);
400
+ cache->start + 4 * alignment, alignment);
412401 if (ret) {
413402 test_err("could not add free space");
414403 return ret;
415404 }
416405
417406 ret = __add_to_free_space_tree(trans, cache, path,
418
- cache->key.objectid + 2 * alignment,
419
- alignment);
407
+ cache->start + 2 * alignment, alignment);
420408 if (ret) {
421409 test_err("could not add free space");
422410 return ret;
....@@ -428,7 +416,7 @@
428416
429417 typedef int (*test_func_t)(struct btrfs_trans_handle *,
430418 struct btrfs_fs_info *,
431
- struct btrfs_block_group_cache *,
419
+ struct btrfs_block_group *,
432420 struct btrfs_path *,
433421 u32 alignment);
434422
....@@ -437,21 +425,21 @@
437425 {
438426 struct btrfs_fs_info *fs_info;
439427 struct btrfs_root *root = NULL;
440
- struct btrfs_block_group_cache *cache = NULL;
428
+ struct btrfs_block_group *cache = NULL;
441429 struct btrfs_trans_handle trans;
442430 struct btrfs_path *path = NULL;
443431 int ret;
444432
445433 fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
446434 if (!fs_info) {
447
- test_err("couldn't allocate dummy fs info");
435
+ test_std_err(TEST_ALLOC_FS_INFO);
448436 ret = -ENOMEM;
449437 goto out;
450438 }
451439
452440 root = btrfs_alloc_dummy_root(fs_info);
453441 if (IS_ERR(root)) {
454
- test_err("couldn't allocate dummy root");
442
+ test_std_err(TEST_ALLOC_ROOT);
455443 ret = PTR_ERR(root);
456444 goto out;
457445 }
....@@ -463,7 +451,7 @@
463451
464452 root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
465453 if (IS_ERR(root->node)) {
466
- test_err("couldn't allocate dummy buffer");
454
+ test_std_err(TEST_ALLOC_EXTENT_BUFFER);
467455 ret = PTR_ERR(root->node);
468456 goto out;
469457 }
....@@ -473,7 +461,7 @@
473461
474462 cache = btrfs_alloc_dummy_block_group(fs_info, 8 * alignment);
475463 if (!cache) {
476
- test_err("couldn't allocate dummy block group cache");
464
+ test_std_err(TEST_ALLOC_BLOCK_GROUP);
477465 ret = -ENOMEM;
478466 goto out;
479467 }
....@@ -486,7 +474,7 @@
486474
487475 path = btrfs_alloc_path();
488476 if (!path) {
489
- test_err("couldn't allocate path");
477
+ test_std_err(TEST_ALLOC_ROOT);
490478 ret = -ENOMEM;
491479 goto out;
492480 }
....@@ -539,7 +527,7 @@
539527 ret = run_test(test_func, 0, sectorsize, nodesize, alignment);
540528 if (ret) {
541529 test_err(
542
- "%pf failed with extents, sectorsize=%u, nodesize=%u, alignment=%u",
530
+ "%ps failed with extents, sectorsize=%u, nodesize=%u, alignment=%u",
543531 test_func, sectorsize, nodesize, alignment);
544532 test_ret = ret;
545533 }
....@@ -547,7 +535,7 @@
547535 ret = run_test(test_func, 1, sectorsize, nodesize, alignment);
548536 if (ret) {
549537 test_err(
550
- "%pf failed with bitmaps, sectorsize=%u, nodesize=%u, alignment=%u",
538
+ "%ps failed with bitmaps, sectorsize=%u, nodesize=%u, alignment=%u",
551539 test_func, sectorsize, nodesize, alignment);
552540 test_ret = ret;
553541 }