| @@ -1547,6 +1547,23 @@ out: · 1546 unmodified lines |
| 1547 | return ret; | 1547 | return ret; |
| 1548 | } | 1548 | } |
| 1549 | | 1549 | |
| | 1550 | static void free_head_ref_squota_rsv(struct btrfs_fs_info *fs_info, |
| | 1551 | struct btrfs_delayed_ref_head *href) |
| | 1552 | { |
| | 1553 | u64 root = href->owning_root; |
| | 1554 | |
| | 1555 | /* |
| | 1556 | * Don't check must_insert_reserved, as this is called from contexts |
| | 1557 | * where it has already been unset. |
| | 1558 | */ |
| | 1559 | if (btrfs_qgroup_mode(fs_info) != BTRFS_QGROUP_MODE_SIMPLE || |
| | 1560 | !href->is_data || !is_fstree(root)) |
| | 1561 | return; |
| | 1562 | |
| | 1563 | btrfs_qgroup_free_refroot(fs_info, root, href->reserved_bytes, |
| | 1564 | BTRFS_QGROUP_RSV_DATA); |
| | 1565 | } |
| | 1566 | |
| 1550 | static int run_delayed_data_ref(struct btrfs_trans_handle *trans, | 1567 | static int run_delayed_data_ref(struct btrfs_trans_handle *trans, |
| 1551 | struct btrfs_delayed_ref_head *href, | 1568 | struct btrfs_delayed_ref_head *href, |
| 1552 | struct btrfs_delayed_ref_node *node, | 1569 | struct btrfs_delayed_ref_node *node, |
| @@ -1569,7 +1586,6 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, · 16 unmodified lines |
| 1569 | struct btrfs_squota_delta delta = { | 1586 | struct btrfs_squota_delta delta = { |
| 1570 | .root = href->owning_root, | 1587 | .root = href->owning_root, |
| 1571 | .num_bytes = node->num_bytes, | 1588 | .num_bytes = node->num_bytes, |
| 1572 | .rsv_bytes = href->reserved_bytes, | | |
| 1573 | .is_data = true, | 1589 | .is_data = true, |
| 1574 | .is_inc = true, | 1590 | .is_inc = true, |
| 1575 | .generation = trans->transid, | 1591 | .generation = trans->transid, |
| @@ -1586,11 +1602,9 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, · 10 unmodified lines |
| 1586 | flags, ref->objectid, | 1602 | flags, ref->objectid, |
| 1587 | ref->offset, &key, | 1603 | ref->offset, &key, |
| 1588 | node->ref_mod, href->owning_root); | 1604 | node->ref_mod, href->owning_root); |
| | 1605 | free_head_ref_squota_rsv(trans->fs_info, href); |
| 1589 | if (!ret) | 1606 | if (!ret) |
| 1590 | ret = btrfs_record_squota_delta(trans->fs_info, &delta); | 1607 | ret = btrfs_record_squota_delta(trans->fs_info, &delta); |
| 1591 | else | | |
| 1592 | btrfs_qgroup_free_refroot(trans->fs_info, delta.root, | | |
| 1593 | delta.rsv_bytes, BTRFS_QGROUP_RSV_DATA); | | |
| 1594 | } else if (node->action == BTRFS_ADD_DELAYED_REF) { | 1608 | } else if (node->action == BTRFS_ADD_DELAYED_REF) { |
| 1595 | ret = __btrfs_inc_extent_ref(trans, node, parent, ref->root, | 1609 | ret = __btrfs_inc_extent_ref(trans, node, parent, ref->root, |
| 1596 | ref->objectid, ref->offset, | 1610 | ref->objectid, ref->offset, |
| @@ -1742,7 +1756,6 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, · 145 unmodified lines |
| 1742 | struct btrfs_squota_delta delta = { | 1756 | struct btrfs_squota_delta delta = { |
| 1743 | .root = href->owning_root, | 1757 | .root = href->owning_root, |
| 1744 | .num_bytes = fs_info->nodesize, | 1758 | .num_bytes = fs_info->nodesize, |
| 1745 | .rsv_bytes = 0, | | |
| 1746 | .is_data = false, | 1759 | .is_data = false, |
| 1747 | .is_inc = true, | 1760 | .is_inc = true, |
| 1748 | .generation = trans->transid, | 1761 | .generation = trans->transid, |
| @@ -1774,8 +1787,10 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans, · 25 unmodified lines |
| 1774 | int ret = 0; | 1787 | int ret = 0; |
| 1775 | | 1788 | |
| 1776 | if (TRANS_ABORTED(trans)) { | 1789 | if (TRANS_ABORTED(trans)) { |
| 1777 | if (insert_reserved) | 1790 | if (insert_reserved) { |
| 1778 | btrfs_pin_extent(trans, node->bytenr, node->num_bytes, 1); | 1791 | btrfs_pin_extent(trans, node->bytenr, node->num_bytes, 1); |
| | 1792 | free_head_ref_squota_rsv(trans->fs_info, href); |
| | 1793 | } |
| 1779 | return 0; | 1794 | return 0; |
| 1780 | } | 1795 | } |
| 1781 | | 1796 | |
| @@ -1871,6 +1886,8 @@ u64 btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, · 89 unmodified lines |
| 1871 | struct btrfs_delayed_ref_root *delayed_refs, | 1886 | struct btrfs_delayed_ref_root *delayed_refs, |
| 1872 | struct btrfs_delayed_ref_head *head) | 1887 | struct btrfs_delayed_ref_head *head) |
| 1873 | { | 1888 | { |
| | 1889 | u64 ret = 0; |
| | 1890 | |
| 1874 | /* | 1891 | /* |
| 1875 | * We had csum deletions accounted for in our delayed refs rsv, we need | 1892 | * We had csum deletions accounted for in our delayed refs rsv, we need |
| 1876 | * to drop the csum leaves for this update from our delayed_refs_rsv. | 1893 | * to drop the csum leaves for this update from our delayed_refs_rsv. |
| @@ -1885,14 +1902,13 @@ u64 btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, · 8 unmodified lines |
| 1885 | | 1902 | |
| 1886 | btrfs_delayed_refs_rsv_release(fs_info, 0, nr_csums); | 1903 | btrfs_delayed_refs_rsv_release(fs_info, 0, nr_csums); |
| 1887 | | 1904 | |
| 1888 | return btrfs_calc_delayed_ref_csum_bytes(fs_info, nr_csums); | 1905 | ret = btrfs_calc_delayed_ref_csum_bytes(fs_info, nr_csums); |
| 1889 | } | 1906 | } |
| 1890 | if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_SIMPLE && | 1907 | /* must_insert_reserved can be set only if we didn't run the head ref. */ |
| 1891 | head->must_insert_reserved && head->is_data) | 1908 | if (head->must_insert_reserved) |
| 1892 | btrfs_qgroup_free_refroot(fs_info, head->owning_root, | 1909 | free_head_ref_squota_rsv(fs_info, head); |
| 1893 | head->reserved_bytes, BTRFS_QGROUP_RSV_DATA); | | |
| 1894 | | 1910 | |
| 1895 | return 0; | 1911 | return ret; |
| 1896 | } | 1912 | } |
| 1897 | | 1913 | |
| 1898 | static int cleanup_ref_head(struct btrfs_trans_handle *trans, | 1914 | static int cleanup_ref_head(struct btrfs_trans_handle *trans, |
| @@ -2033,6 +2049,12 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, · 134 unmodified lines |
| 2033 | * spin lock. | 2049 | * spin lock. |
| 2034 | */ | 2050 | */ |
| 2035 | must_insert_reserved = locked_ref->must_insert_reserved; | 2051 | must_insert_reserved = locked_ref->must_insert_reserved; |
| | 2052 | /* |
| | 2053 | * Unsetting this on the head ref relinquishes ownership of |
| | 2054 | * the rsv_bytes, so it is critical that every possible code |
| | 2055 | * path from here forward frees all reserves including qgroup |
| | 2056 | * reserve. |
| | 2057 | */ |
| 2036 | locked_ref->must_insert_reserved = false; | 2058 | locked_ref->must_insert_reserved = false; |
| 2037 | | 2059 | |
| 2038 | extent_op = locked_ref->extent_op; | 2060 | extent_op = locked_ref->extent_op; |
| @@ -3292,7 +3314,6 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, · 1253 unmodified lines |
| 3292 | struct btrfs_squota_delta delta = { | 3314 | struct btrfs_squota_delta delta = { |
| 3293 | .root = delayed_ref_root, | 3315 | .root = delayed_ref_root, |
| 3294 | .num_bytes = num_bytes, | 3316 | .num_bytes = num_bytes, |
| 3295 | .rsv_bytes = 0, | | |
| 3296 | .is_data = is_data, | 3317 | .is_data = is_data, |
| 3297 | .is_inc = false, | 3318 | .is_inc = false, |
| 3298 | .generation = btrfs_extent_generation(leaf, ei), | 3319 | .generation = btrfs_extent_generation(leaf, ei), |
| @@ -4937,7 +4958,6 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, · 1638 unmodified lines |
| 4937 | .root = root_objectid, | 4958 | .root = root_objectid, |
| 4938 | .num_bytes = ins->offset, | 4959 | .num_bytes = ins->offset, |
| 4939 | .generation = trans->transid, | 4960 | .generation = trans->transid, |
| 4940 | .rsv_bytes = 0, | | |
| 4941 | .is_data = true, | 4961 | .is_data = true, |
| 4942 | .is_inc = true, | 4962 | .is_inc = true, |
| 4943 | }; | 4963 | }; |