hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/fs/btrfs/tests/qgroup-tests.c
....@@ -32,7 +32,7 @@
3232
3333 path = btrfs_alloc_path();
3434 if (!path) {
35
- test_err("couldn't allocate path");
35
+ test_std_err(TEST_ALLOC_ROOT);
3636 return -ENOMEM;
3737 }
3838
....@@ -82,7 +82,7 @@
8282
8383 path = btrfs_alloc_path();
8484 if (!path) {
85
- test_err("couldn't allocate path");
85
+ test_std_err(TEST_ALLOC_ROOT);
8686 return -ENOMEM;
8787 }
8888
....@@ -132,7 +132,7 @@
132132
133133 path = btrfs_alloc_path();
134134 if (!path) {
135
- test_err("couldn't allocate path");
135
+ test_std_err(TEST_ALLOC_ROOT);
136136 return -ENOMEM;
137137 }
138138 path->leave_spinning = 1;
....@@ -166,7 +166,7 @@
166166
167167 path = btrfs_alloc_path();
168168 if (!path) {
169
- test_err("couldn't allocate path");
169
+ test_std_err(TEST_ALLOC_ROOT);
170170 return -ENOMEM;
171171 }
172172
....@@ -215,7 +215,7 @@
215215
216216 btrfs_init_dummy_trans(&trans, fs_info);
217217
218
- test_msg("qgroup basic add");
218
+ test_msg("running qgroup add/remove tests");
219219 ret = btrfs_create_qgroup(&trans, BTRFS_FS_TREE_OBJECTID);
220220 if (ret) {
221221 test_err("couldn't create a qgroup %d", ret);
....@@ -230,21 +230,21 @@
230230 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
231231 false);
232232 if (ret) {
233
- ulist_free(old_roots);
234233 test_err("couldn't find old roots: %d", ret);
235234 return ret;
236235 }
237236
238237 ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
239238 BTRFS_FS_TREE_OBJECTID);
240
- if (ret)
239
+ if (ret) {
240
+ ulist_free(old_roots);
241241 return ret;
242
+ }
242243
243244 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
244245 false);
245246 if (ret) {
246247 ulist_free(old_roots);
247
- ulist_free(new_roots);
248248 test_err("couldn't find old roots: %d", ret);
249249 return ret;
250250 }
....@@ -256,31 +256,33 @@
256256 return ret;
257257 }
258258
259
+ /* btrfs_qgroup_account_extent() always frees the ulists passed to it. */
260
+ old_roots = NULL;
261
+ new_roots = NULL;
262
+
259263 if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
260264 nodesize, nodesize)) {
261265 test_err("qgroup counts didn't match expected values");
262266 return -EINVAL;
263267 }
264
- old_roots = NULL;
265
- new_roots = NULL;
266268
267269 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
268270 false);
269271 if (ret) {
270
- ulist_free(old_roots);
271272 test_err("couldn't find old roots: %d", ret);
272273 return ret;
273274 }
274275
275276 ret = remove_extent_item(root, nodesize, nodesize);
276
- if (ret)
277
+ if (ret) {
278
+ ulist_free(old_roots);
277279 return -EINVAL;
280
+ }
278281
279282 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
280283 false);
281284 if (ret) {
282285 ulist_free(old_roots);
283
- ulist_free(new_roots);
284286 test_err("couldn't find old roots: %d", ret);
285287 return ret;
286288 }
....@@ -316,7 +318,7 @@
316318
317319 btrfs_init_dummy_trans(&trans, fs_info);
318320
319
- test_msg("qgroup multiple refs test");
321
+ test_msg("running qgroup multiple refs test");
320322
321323 /*
322324 * We have BTRFS_FS_TREE_OBJECTID created already from the
....@@ -331,21 +333,21 @@
331333 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
332334 false);
333335 if (ret) {
334
- ulist_free(old_roots);
335336 test_err("couldn't find old roots: %d", ret);
336337 return ret;
337338 }
338339
339340 ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
340341 BTRFS_FS_TREE_OBJECTID);
341
- if (ret)
342
+ if (ret) {
343
+ ulist_free(old_roots);
342344 return ret;
345
+ }
343346
344347 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
345348 false);
346349 if (ret) {
347350 ulist_free(old_roots);
348
- ulist_free(new_roots);
349351 test_err("couldn't find old roots: %d", ret);
350352 return ret;
351353 }
....@@ -366,21 +368,21 @@
366368 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
367369 false);
368370 if (ret) {
369
- ulist_free(old_roots);
370371 test_err("couldn't find old roots: %d", ret);
371372 return ret;
372373 }
373374
374375 ret = add_tree_ref(root, nodesize, nodesize, 0,
375376 BTRFS_FIRST_FREE_OBJECTID);
376
- if (ret)
377
+ if (ret) {
378
+ ulist_free(old_roots);
377379 return ret;
380
+ }
378381
379382 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
380383 false);
381384 if (ret) {
382385 ulist_free(old_roots);
383
- ulist_free(new_roots);
384386 test_err("couldn't find old roots: %d", ret);
385387 return ret;
386388 }
....@@ -407,21 +409,21 @@
407409 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
408410 false);
409411 if (ret) {
410
- ulist_free(old_roots);
411412 test_err("couldn't find old roots: %d", ret);
412413 return ret;
413414 }
414415
415416 ret = remove_extent_ref(root, nodesize, nodesize, 0,
416417 BTRFS_FIRST_FREE_OBJECTID);
417
- if (ret)
418
+ if (ret) {
419
+ ulist_free(old_roots);
418420 return ret;
421
+ }
419422
420423 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
421424 false);
422425 if (ret) {
423426 ulist_free(old_roots);
424
- ulist_free(new_roots);
425427 test_err("couldn't find old roots: %d", ret);
426428 return ret;
427429 }
....@@ -457,13 +459,13 @@
457459
458460 fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
459461 if (!fs_info) {
460
- test_err("couldn't allocate dummy fs info");
462
+ test_std_err(TEST_ALLOC_FS_INFO);
461463 return -ENOMEM;
462464 }
463465
464466 root = btrfs_alloc_dummy_root(fs_info);
465467 if (IS_ERR(root)) {
466
- test_err("couldn't allocate root");
468
+ test_std_err(TEST_ALLOC_ROOT);
467469 ret = PTR_ERR(root);
468470 goto out;
469471 }
....@@ -495,7 +497,7 @@
495497
496498 tmp_root = btrfs_alloc_dummy_root(fs_info);
497499 if (IS_ERR(tmp_root)) {
498
- test_err("couldn't allocate a fs root");
500
+ test_std_err(TEST_ALLOC_ROOT);
499501 ret = PTR_ERR(tmp_root);
500502 goto out;
501503 }
....@@ -507,10 +509,11 @@
507509 test_err("couldn't insert fs root %d", ret);
508510 goto out;
509511 }
512
+ btrfs_put_root(tmp_root);
510513
511514 tmp_root = btrfs_alloc_dummy_root(fs_info);
512515 if (IS_ERR(tmp_root)) {
513
- test_err("couldn't allocate a fs root");
516
+ test_std_err(TEST_ALLOC_ROOT);
514517 ret = PTR_ERR(tmp_root);
515518 goto out;
516519 }
....@@ -521,6 +524,7 @@
521524 test_err("couldn't insert fs root %d", ret);
522525 goto out;
523526 }
527
+ btrfs_put_root(tmp_root);
524528
525529 test_msg("running qgroup tests");
526530 ret = test_no_shared_qgroup(root, sectorsize, nodesize);