aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/qgroup.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/qgroup.c')
-rw-r--r--fs/btrfs/qgroup.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index ded5c601d916..48b60dbf807f 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -539,10 +539,9 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
539 struct extent_buffer *leaf; 539 struct extent_buffer *leaf;
540 struct btrfs_key key; 540 struct btrfs_key key;
541 541
542#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 542 if (btrfs_test_is_dummy_root(quota_root))
543 if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &quota_root->state)))
544 return 0; 543 return 0;
545#endif 544
546 path = btrfs_alloc_path(); 545 path = btrfs_alloc_path();
547 if (!path) 546 if (!path)
548 return -ENOMEM; 547 return -ENOMEM;
@@ -551,9 +550,15 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
551 key.type = BTRFS_QGROUP_INFO_KEY; 550 key.type = BTRFS_QGROUP_INFO_KEY;
552 key.offset = qgroupid; 551 key.offset = qgroupid;
553 552
553 /*
554 * Avoid a transaction abort by catching -EEXIST here. In that
555 * case, we proceed by re-initializing the existing structure
556 * on disk.
557 */
558
554 ret = btrfs_insert_empty_item(trans, quota_root, path, &key, 559 ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
555 sizeof(*qgroup_info)); 560 sizeof(*qgroup_info));
556 if (ret) 561 if (ret && ret != -EEXIST)
557 goto out; 562 goto out;
558 563
559 leaf = path->nodes[0]; 564 leaf = path->nodes[0];
@@ -572,7 +577,7 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
572 key.type = BTRFS_QGROUP_LIMIT_KEY; 577 key.type = BTRFS_QGROUP_LIMIT_KEY;
573 ret = btrfs_insert_empty_item(trans, quota_root, path, &key, 578 ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
574 sizeof(*qgroup_limit)); 579 sizeof(*qgroup_limit));
575 if (ret) 580 if (ret && ret != -EEXIST)
576 goto out; 581 goto out;
577 582
578 leaf = path->nodes[0]; 583 leaf = path->nodes[0];
@@ -692,10 +697,9 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans,
692 int ret; 697 int ret;
693 int slot; 698 int slot;
694 699
695#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 700 if (btrfs_test_is_dummy_root(root))
696 if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
697 return 0; 701 return 0;
698#endif 702
699 key.objectid = 0; 703 key.objectid = 0;
700 key.type = BTRFS_QGROUP_INFO_KEY; 704 key.type = BTRFS_QGROUP_INFO_KEY;
701 key.offset = qgroup->qgroupid; 705 key.offset = qgroup->qgroupid;
@@ -1335,6 +1339,8 @@ int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans,
1335 INIT_LIST_HEAD(&oper->elem.list); 1339 INIT_LIST_HEAD(&oper->elem.list);
1336 oper->elem.seq = 0; 1340 oper->elem.seq = 0;
1337 1341
1342 trace_btrfs_qgroup_record_ref(oper);
1343
1338 if (type == BTRFS_QGROUP_OPER_SUB_SUBTREE) { 1344 if (type == BTRFS_QGROUP_OPER_SUB_SUBTREE) {
1339 /* 1345 /*
1340 * If any operation for this bytenr/ref_root combo 1346 * If any operation for this bytenr/ref_root combo
@@ -2077,6 +2083,8 @@ static int btrfs_qgroup_account(struct btrfs_trans_handle *trans,
2077 2083
2078 ASSERT(is_fstree(oper->ref_root)); 2084 ASSERT(is_fstree(oper->ref_root));
2079 2085
2086 trace_btrfs_qgroup_account(oper);
2087
2080 switch (oper->type) { 2088 switch (oper->type) {
2081 case BTRFS_QGROUP_OPER_ADD_EXCL: 2089 case BTRFS_QGROUP_OPER_ADD_EXCL:
2082 case BTRFS_QGROUP_OPER_SUB_EXCL: 2090 case BTRFS_QGROUP_OPER_SUB_EXCL:
@@ -2237,7 +2245,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2237 if (srcid) { 2245 if (srcid) {
2238 struct btrfs_root *srcroot; 2246 struct btrfs_root *srcroot;
2239 struct btrfs_key srckey; 2247 struct btrfs_key srckey;
2240 int srcroot_level;
2241 2248
2242 srckey.objectid = srcid; 2249 srckey.objectid = srcid;
2243 srckey.type = BTRFS_ROOT_ITEM_KEY; 2250 srckey.type = BTRFS_ROOT_ITEM_KEY;
@@ -2249,8 +2256,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2249 } 2256 }
2250 2257
2251 rcu_read_lock(); 2258 rcu_read_lock();
2252 srcroot_level = btrfs_header_level(srcroot->node); 2259 level_size = srcroot->nodesize;
2253 level_size = btrfs_level_size(srcroot, srcroot_level);
2254 rcu_read_unlock(); 2260 rcu_read_unlock();
2255 } 2261 }
2256 2262
@@ -2566,7 +2572,7 @@ qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
2566 found.type != BTRFS_METADATA_ITEM_KEY) 2572 found.type != BTRFS_METADATA_ITEM_KEY)
2567 continue; 2573 continue;
2568 if (found.type == BTRFS_METADATA_ITEM_KEY) 2574 if (found.type == BTRFS_METADATA_ITEM_KEY)
2569 num_bytes = fs_info->extent_root->leafsize; 2575 num_bytes = fs_info->extent_root->nodesize;
2570 else 2576 else
2571 num_bytes = found.offset; 2577 num_bytes = found.offset;
2572 2578