| .. | .. |
|---|
| 32 | 32 | |
|---|
| 33 | 33 | path = btrfs_alloc_path(); |
|---|
| 34 | 34 | if (!path) { |
|---|
| 35 | | - test_err("couldn't allocate path"); |
|---|
| 35 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 36 | 36 | return -ENOMEM; |
|---|
| 37 | 37 | } |
|---|
| 38 | 38 | |
|---|
| .. | .. |
|---|
| 82 | 82 | |
|---|
| 83 | 83 | path = btrfs_alloc_path(); |
|---|
| 84 | 84 | if (!path) { |
|---|
| 85 | | - test_err("couldn't allocate path"); |
|---|
| 85 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 86 | 86 | return -ENOMEM; |
|---|
| 87 | 87 | } |
|---|
| 88 | 88 | |
|---|
| .. | .. |
|---|
| 132 | 132 | |
|---|
| 133 | 133 | path = btrfs_alloc_path(); |
|---|
| 134 | 134 | if (!path) { |
|---|
| 135 | | - test_err("couldn't allocate path"); |
|---|
| 135 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 136 | 136 | return -ENOMEM; |
|---|
| 137 | 137 | } |
|---|
| 138 | 138 | path->leave_spinning = 1; |
|---|
| .. | .. |
|---|
| 166 | 166 | |
|---|
| 167 | 167 | path = btrfs_alloc_path(); |
|---|
| 168 | 168 | if (!path) { |
|---|
| 169 | | - test_err("couldn't allocate path"); |
|---|
| 169 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 170 | 170 | return -ENOMEM; |
|---|
| 171 | 171 | } |
|---|
| 172 | 172 | |
|---|
| .. | .. |
|---|
| 215 | 215 | |
|---|
| 216 | 216 | btrfs_init_dummy_trans(&trans, fs_info); |
|---|
| 217 | 217 | |
|---|
| 218 | | - test_msg("qgroup basic add"); |
|---|
| 218 | + test_msg("running qgroup add/remove tests"); |
|---|
| 219 | 219 | ret = btrfs_create_qgroup(&trans, BTRFS_FS_TREE_OBJECTID); |
|---|
| 220 | 220 | if (ret) { |
|---|
| 221 | 221 | test_err("couldn't create a qgroup %d", ret); |
|---|
| .. | .. |
|---|
| 230 | 230 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, |
|---|
| 231 | 231 | false); |
|---|
| 232 | 232 | if (ret) { |
|---|
| 233 | | - ulist_free(old_roots); |
|---|
| 234 | 233 | test_err("couldn't find old roots: %d", ret); |
|---|
| 235 | 234 | return ret; |
|---|
| 236 | 235 | } |
|---|
| 237 | 236 | |
|---|
| 238 | 237 | ret = insert_normal_tree_ref(root, nodesize, nodesize, 0, |
|---|
| 239 | 238 | BTRFS_FS_TREE_OBJECTID); |
|---|
| 240 | | - if (ret) |
|---|
| 239 | + if (ret) { |
|---|
| 240 | + ulist_free(old_roots); |
|---|
| 241 | 241 | return ret; |
|---|
| 242 | + } |
|---|
| 242 | 243 | |
|---|
| 243 | 244 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, |
|---|
| 244 | 245 | false); |
|---|
| 245 | 246 | if (ret) { |
|---|
| 246 | 247 | ulist_free(old_roots); |
|---|
| 247 | | - ulist_free(new_roots); |
|---|
| 248 | 248 | test_err("couldn't find old roots: %d", ret); |
|---|
| 249 | 249 | return ret; |
|---|
| 250 | 250 | } |
|---|
| .. | .. |
|---|
| 256 | 256 | return ret; |
|---|
| 257 | 257 | } |
|---|
| 258 | 258 | |
|---|
| 259 | + /* btrfs_qgroup_account_extent() always frees the ulists passed to it. */ |
|---|
| 260 | + old_roots = NULL; |
|---|
| 261 | + new_roots = NULL; |
|---|
| 262 | + |
|---|
| 259 | 263 | if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID, |
|---|
| 260 | 264 | nodesize, nodesize)) { |
|---|
| 261 | 265 | test_err("qgroup counts didn't match expected values"); |
|---|
| 262 | 266 | return -EINVAL; |
|---|
| 263 | 267 | } |
|---|
| 264 | | - old_roots = NULL; |
|---|
| 265 | | - new_roots = NULL; |
|---|
| 266 | 268 | |
|---|
| 267 | 269 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, |
|---|
| 268 | 270 | false); |
|---|
| 269 | 271 | if (ret) { |
|---|
| 270 | | - ulist_free(old_roots); |
|---|
| 271 | 272 | test_err("couldn't find old roots: %d", ret); |
|---|
| 272 | 273 | return ret; |
|---|
| 273 | 274 | } |
|---|
| 274 | 275 | |
|---|
| 275 | 276 | ret = remove_extent_item(root, nodesize, nodesize); |
|---|
| 276 | | - if (ret) |
|---|
| 277 | + if (ret) { |
|---|
| 278 | + ulist_free(old_roots); |
|---|
| 277 | 279 | return -EINVAL; |
|---|
| 280 | + } |
|---|
| 278 | 281 | |
|---|
| 279 | 282 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, |
|---|
| 280 | 283 | false); |
|---|
| 281 | 284 | if (ret) { |
|---|
| 282 | 285 | ulist_free(old_roots); |
|---|
| 283 | | - ulist_free(new_roots); |
|---|
| 284 | 286 | test_err("couldn't find old roots: %d", ret); |
|---|
| 285 | 287 | return ret; |
|---|
| 286 | 288 | } |
|---|
| .. | .. |
|---|
| 316 | 318 | |
|---|
| 317 | 319 | btrfs_init_dummy_trans(&trans, fs_info); |
|---|
| 318 | 320 | |
|---|
| 319 | | - test_msg("qgroup multiple refs test"); |
|---|
| 321 | + test_msg("running qgroup multiple refs test"); |
|---|
| 320 | 322 | |
|---|
| 321 | 323 | /* |
|---|
| 322 | 324 | * We have BTRFS_FS_TREE_OBJECTID created already from the |
|---|
| .. | .. |
|---|
| 331 | 333 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, |
|---|
| 332 | 334 | false); |
|---|
| 333 | 335 | if (ret) { |
|---|
| 334 | | - ulist_free(old_roots); |
|---|
| 335 | 336 | test_err("couldn't find old roots: %d", ret); |
|---|
| 336 | 337 | return ret; |
|---|
| 337 | 338 | } |
|---|
| 338 | 339 | |
|---|
| 339 | 340 | ret = insert_normal_tree_ref(root, nodesize, nodesize, 0, |
|---|
| 340 | 341 | BTRFS_FS_TREE_OBJECTID); |
|---|
| 341 | | - if (ret) |
|---|
| 342 | + if (ret) { |
|---|
| 343 | + ulist_free(old_roots); |
|---|
| 342 | 344 | return ret; |
|---|
| 345 | + } |
|---|
| 343 | 346 | |
|---|
| 344 | 347 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, |
|---|
| 345 | 348 | false); |
|---|
| 346 | 349 | if (ret) { |
|---|
| 347 | 350 | ulist_free(old_roots); |
|---|
| 348 | | - ulist_free(new_roots); |
|---|
| 349 | 351 | test_err("couldn't find old roots: %d", ret); |
|---|
| 350 | 352 | return ret; |
|---|
| 351 | 353 | } |
|---|
| .. | .. |
|---|
| 366 | 368 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, |
|---|
| 367 | 369 | false); |
|---|
| 368 | 370 | if (ret) { |
|---|
| 369 | | - ulist_free(old_roots); |
|---|
| 370 | 371 | test_err("couldn't find old roots: %d", ret); |
|---|
| 371 | 372 | return ret; |
|---|
| 372 | 373 | } |
|---|
| 373 | 374 | |
|---|
| 374 | 375 | ret = add_tree_ref(root, nodesize, nodesize, 0, |
|---|
| 375 | 376 | BTRFS_FIRST_FREE_OBJECTID); |
|---|
| 376 | | - if (ret) |
|---|
| 377 | + if (ret) { |
|---|
| 378 | + ulist_free(old_roots); |
|---|
| 377 | 379 | return ret; |
|---|
| 380 | + } |
|---|
| 378 | 381 | |
|---|
| 379 | 382 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, |
|---|
| 380 | 383 | false); |
|---|
| 381 | 384 | if (ret) { |
|---|
| 382 | 385 | ulist_free(old_roots); |
|---|
| 383 | | - ulist_free(new_roots); |
|---|
| 384 | 386 | test_err("couldn't find old roots: %d", ret); |
|---|
| 385 | 387 | return ret; |
|---|
| 386 | 388 | } |
|---|
| .. | .. |
|---|
| 407 | 409 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, |
|---|
| 408 | 410 | false); |
|---|
| 409 | 411 | if (ret) { |
|---|
| 410 | | - ulist_free(old_roots); |
|---|
| 411 | 412 | test_err("couldn't find old roots: %d", ret); |
|---|
| 412 | 413 | return ret; |
|---|
| 413 | 414 | } |
|---|
| 414 | 415 | |
|---|
| 415 | 416 | ret = remove_extent_ref(root, nodesize, nodesize, 0, |
|---|
| 416 | 417 | BTRFS_FIRST_FREE_OBJECTID); |
|---|
| 417 | | - if (ret) |
|---|
| 418 | + if (ret) { |
|---|
| 419 | + ulist_free(old_roots); |
|---|
| 418 | 420 | return ret; |
|---|
| 421 | + } |
|---|
| 419 | 422 | |
|---|
| 420 | 423 | ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, |
|---|
| 421 | 424 | false); |
|---|
| 422 | 425 | if (ret) { |
|---|
| 423 | 426 | ulist_free(old_roots); |
|---|
| 424 | | - ulist_free(new_roots); |
|---|
| 425 | 427 | test_err("couldn't find old roots: %d", ret); |
|---|
| 426 | 428 | return ret; |
|---|
| 427 | 429 | } |
|---|
| .. | .. |
|---|
| 457 | 459 | |
|---|
| 458 | 460 | fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); |
|---|
| 459 | 461 | if (!fs_info) { |
|---|
| 460 | | - test_err("couldn't allocate dummy fs info"); |
|---|
| 462 | + test_std_err(TEST_ALLOC_FS_INFO); |
|---|
| 461 | 463 | return -ENOMEM; |
|---|
| 462 | 464 | } |
|---|
| 463 | 465 | |
|---|
| 464 | 466 | root = btrfs_alloc_dummy_root(fs_info); |
|---|
| 465 | 467 | if (IS_ERR(root)) { |
|---|
| 466 | | - test_err("couldn't allocate root"); |
|---|
| 468 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 467 | 469 | ret = PTR_ERR(root); |
|---|
| 468 | 470 | goto out; |
|---|
| 469 | 471 | } |
|---|
| .. | .. |
|---|
| 495 | 497 | |
|---|
| 496 | 498 | tmp_root = btrfs_alloc_dummy_root(fs_info); |
|---|
| 497 | 499 | if (IS_ERR(tmp_root)) { |
|---|
| 498 | | - test_err("couldn't allocate a fs root"); |
|---|
| 500 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 499 | 501 | ret = PTR_ERR(tmp_root); |
|---|
| 500 | 502 | goto out; |
|---|
| 501 | 503 | } |
|---|
| .. | .. |
|---|
| 507 | 509 | test_err("couldn't insert fs root %d", ret); |
|---|
| 508 | 510 | goto out; |
|---|
| 509 | 511 | } |
|---|
| 512 | + btrfs_put_root(tmp_root); |
|---|
| 510 | 513 | |
|---|
| 511 | 514 | tmp_root = btrfs_alloc_dummy_root(fs_info); |
|---|
| 512 | 515 | if (IS_ERR(tmp_root)) { |
|---|
| 513 | | - test_err("couldn't allocate a fs root"); |
|---|
| 516 | + test_std_err(TEST_ALLOC_ROOT); |
|---|
| 514 | 517 | ret = PTR_ERR(tmp_root); |
|---|
| 515 | 518 | goto out; |
|---|
| 516 | 519 | } |
|---|
| .. | .. |
|---|
| 521 | 524 | test_err("couldn't insert fs root %d", ret); |
|---|
| 522 | 525 | goto out; |
|---|
| 523 | 526 | } |
|---|
| 527 | + btrfs_put_root(tmp_root); |
|---|
| 524 | 528 | |
|---|
| 525 | 529 | test_msg("running qgroup tests"); |
|---|
| 526 | 530 | ret = test_no_shared_qgroup(root, sectorsize, nodesize); |
|---|