Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism.

Since the self test transaction don't have delayed_ref_roots, so use
find_all_roots() and export btrfs_qgroup_account_extent() to simulate it

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Qu Wenruo and committed by
Chris Mason
442244c9 0ed4792a

+89 -27
+1 -1
fs/btrfs/qgroup.c
··· 2455 2455 return ret; 2456 2456 } 2457 2457 2458 - static int 2458 + int 2459 2459 btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, 2460 2460 struct btrfs_fs_info *fs_info, 2461 2461 u64 bytenr, u64 num_bytes,
+5
fs/btrfs/qgroup.h
··· 103 103 struct btrfs_qgroup_extent_record 104 104 *btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs, 105 105 struct btrfs_qgroup_extent_record *record); 106 + int 107 + btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, 108 + struct btrfs_fs_info *fs_info, 109 + u64 bytenr, u64 num_bytes, 110 + struct ulist *old_roots, struct ulist *new_roots); 106 111 int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans, 107 112 struct btrfs_fs_info *fs_info); 108 113 int btrfs_delayed_qgroup_accounting(struct btrfs_trans_handle *trans,
+83 -26
fs/btrfs/tests/qgroup-tests.c
··· 21 21 #include "../transaction.h" 22 22 #include "../disk-io.h" 23 23 #include "../qgroup.h" 24 + #include "../backref.h" 24 25 25 26 static void init_dummy_trans(struct btrfs_trans_handle *trans) 26 27 { ··· 228 227 { 229 228 struct btrfs_trans_handle trans; 230 229 struct btrfs_fs_info *fs_info = root->fs_info; 230 + struct ulist *old_roots = NULL; 231 + struct ulist *new_roots = NULL; 231 232 int ret; 232 233 233 234 init_dummy_trans(&trans); ··· 241 238 return ret; 242 239 } 243 240 244 - ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096, 245 - BTRFS_QGROUP_OPER_ADD_EXCL, 0); 241 + /* 242 + * Since the test trans doesn't havee the complicated delayed refs, 243 + * we can only call btrfs_qgroup_account_extent() directly to test 244 + * quota. 245 + */ 246 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); 246 247 if (ret) { 247 - test_msg("Couldn't add space to a qgroup %d\n", ret); 248 + ulist_free(old_roots); 249 + test_msg("Couldn't find old roots: %d\n", ret); 248 250 return ret; 249 251 } 250 252 ··· 257 249 if (ret) 258 250 return ret; 259 251 260 - ret = btrfs_delayed_qgroup_accounting(&trans, fs_info); 252 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); 261 253 if (ret) { 262 - test_msg("Delayed qgroup accounting failed %d\n", ret); 254 + ulist_free(old_roots); 255 + ulist_free(new_roots); 256 + test_msg("Couldn't find old roots: %d\n", ret); 257 + return ret; 258 + } 259 + 260 + ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, 261 + old_roots, new_roots); 262 + if (ret) { 263 + test_msg("Couldn't account space for a qgroup %d\n", ret); 263 264 return ret; 264 265 } 265 266 ··· 276 259 test_msg("Qgroup counts didn't match expected values\n"); 277 260 return -EINVAL; 278 261 } 262 + old_roots = NULL; 263 + new_roots = NULL; 264 + 265 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); 266 + if (ret) { 267 + ulist_free(old_roots); 268 + test_msg("Couldn't find old roots: %d\n", ret); 269 + return ret; 270 + } 279 271 280 272 ret = remove_extent_item(root, 4096, 4096); 281 273 if (ret) 282 274 return -EINVAL; 283 275 284 - ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096, 285 - BTRFS_QGROUP_OPER_SUB_EXCL, 0); 276 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); 286 277 if (ret) { 287 - test_msg("Couldn't remove space from the qgroup %d\n", ret); 288 - return -EINVAL; 278 + ulist_free(old_roots); 279 + ulist_free(new_roots); 280 + test_msg("Couldn't find old roots: %d\n", ret); 281 + return ret; 289 282 } 290 283 291 - ret = btrfs_delayed_qgroup_accounting(&trans, fs_info); 284 + ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, 285 + old_roots, new_roots); 292 286 if (ret) { 293 - test_msg("Qgroup accounting failed %d\n", ret); 287 + test_msg("Couldn't account space for a qgroup %d\n", ret); 294 288 return -EINVAL; 295 289 } 296 290 ··· 322 294 { 323 295 struct btrfs_trans_handle trans; 324 296 struct btrfs_fs_info *fs_info = root->fs_info; 297 + struct ulist *old_roots = NULL; 298 + struct ulist *new_roots = NULL; 325 299 int ret; 326 300 327 301 init_dummy_trans(&trans); ··· 337 307 return ret; 338 308 } 339 309 310 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); 311 + if (ret) { 312 + ulist_free(old_roots); 313 + test_msg("Couldn't find old roots: %d\n", ret); 314 + return ret; 315 + } 316 + 340 317 ret = insert_normal_tree_ref(root, 4096, 4096, 0, 5); 341 318 if (ret) 342 319 return ret; 343 320 344 - ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096, 345 - BTRFS_QGROUP_OPER_ADD_EXCL, 0); 321 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); 346 322 if (ret) { 347 - test_msg("Couldn't add space to a qgroup %d\n", ret); 323 + ulist_free(old_roots); 324 + ulist_free(new_roots); 325 + test_msg("Couldn't find old roots: %d\n", ret); 348 326 return ret; 349 327 } 350 328 351 - ret = btrfs_delayed_qgroup_accounting(&trans, fs_info); 329 + ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, 330 + old_roots, new_roots); 352 331 if (ret) { 353 - test_msg("Delayed qgroup accounting failed %d\n", ret); 332 + test_msg("Couldn't account space for a qgroup %d\n", ret); 354 333 return ret; 355 334 } 356 335 ··· 368 329 return -EINVAL; 369 330 } 370 331 332 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); 333 + if (ret) { 334 + ulist_free(old_roots); 335 + test_msg("Couldn't find old roots: %d\n", ret); 336 + return ret; 337 + } 338 + 371 339 ret = add_tree_ref(root, 4096, 4096, 0, 256); 372 340 if (ret) 373 341 return ret; 374 342 375 - ret = btrfs_qgroup_record_ref(&trans, fs_info, 256, 4096, 4096, 376 - BTRFS_QGROUP_OPER_ADD_SHARED, 0); 343 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); 377 344 if (ret) { 378 - test_msg("Qgroup record ref failed %d\n", ret); 345 + ulist_free(old_roots); 346 + ulist_free(new_roots); 347 + test_msg("Couldn't find old roots: %d\n", ret); 379 348 return ret; 380 349 } 381 350 382 - ret = btrfs_delayed_qgroup_accounting(&trans, fs_info); 351 + ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, 352 + old_roots, new_roots); 383 353 if (ret) { 384 - test_msg("Qgroup accounting failed %d\n", ret); 354 + test_msg("Couldn't account space for a qgroup %d\n", ret); 385 355 return ret; 386 356 } 387 357 ··· 404 356 return -EINVAL; 405 357 } 406 358 359 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); 360 + if (ret) { 361 + ulist_free(old_roots); 362 + test_msg("Couldn't find old roots: %d\n", ret); 363 + return ret; 364 + } 365 + 407 366 ret = remove_extent_ref(root, 4096, 4096, 0, 256); 408 367 if (ret) 409 368 return ret; 410 369 411 - ret = btrfs_qgroup_record_ref(&trans, fs_info, 256, 4096, 4096, 412 - BTRFS_QGROUP_OPER_SUB_SHARED, 0); 370 + ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); 413 371 if (ret) { 414 - test_msg("Qgroup record ref failed %d\n", ret); 372 + ulist_free(old_roots); 373 + ulist_free(new_roots); 374 + test_msg("Couldn't find old roots: %d\n", ret); 415 375 return ret; 416 376 } 417 377 418 - ret = btrfs_delayed_qgroup_accounting(&trans, fs_info); 378 + ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, 379 + old_roots, new_roots); 419 380 if (ret) { 420 - test_msg("Qgroup accounting failed %d\n", ret); 381 + test_msg("Couldn't account space for a qgroup %d\n", ret); 421 382 return ret; 422 383 } 423 384