Lines Matching defs:qgroup

23 #include "qgroup.h"
53 * Helpers to access qgroup reservation
58 static u64 qgroup_rsv_total(const struct btrfs_qgroup *qgroup)
64 ret += qgroup->rsv.values[i];
83 struct btrfs_qgroup *qgroup, u64 num_bytes,
86 trace_qgroup_update_reserve(fs_info, qgroup, num_bytes, type);
87 qgroup->rsv.values[type] += num_bytes;
91 struct btrfs_qgroup *qgroup, u64 num_bytes,
94 trace_qgroup_update_reserve(fs_info, qgroup, -(s64)num_bytes, type);
95 if (qgroup->rsv.values[type] >= num_bytes) {
96 qgroup->rsv.values[type] -= num_bytes;
101 "qgroup %llu %s reserved space underflow, have %llu to free %llu",
102 qgroup->qgroupid, qgroup_rsv_type_str(type),
103 qgroup->rsv.values[type], num_bytes);
105 qgroup->rsv.values[type] = 0;
178 struct btrfs_qgroup *qgroup;
181 qgroup = rb_entry(n, struct btrfs_qgroup, node);
182 if (qgroup->qgroupid < qgroupid)
184 else if (qgroup->qgroupid > qgroupid)
187 return qgroup;
193 * Add qgroup to the filesystem's qgroup tree.
206 struct btrfs_qgroup *qgroup;
213 qgroup = rb_entry(parent, struct btrfs_qgroup, node);
215 if (qgroup->qgroupid < qgroupid) {
217 } else if (qgroup->qgroupid > qgroupid) {
221 return qgroup;
225 qgroup = prealloc;
226 qgroup->qgroupid = qgroupid;
227 INIT_LIST_HEAD(&qgroup->groups);
228 INIT_LIST_HEAD(&qgroup->members);
229 INIT_LIST_HEAD(&qgroup->dirty);
230 INIT_LIST_HEAD(&qgroup->iterator);
231 INIT_LIST_HEAD(&qgroup->nested_iterator);
233 rb_link_node(&qgroup->node, parent, p);
234 rb_insert_color(&qgroup->node, &fs_info->qgroup_tree);
236 return qgroup;
240 struct btrfs_qgroup *qgroup)
244 list_del(&qgroup->dirty);
245 while (!list_empty(&qgroup->groups)) {
246 list = list_first_entry(&qgroup->groups,
253 while (!list_empty(&qgroup->members)) {
254 list = list_first_entry(&qgroup->members,
265 struct btrfs_qgroup *qgroup = find_qgroup_rb(fs_info, qgroupid);
267 if (!qgroup)
270 rb_erase(&qgroup->node, &fs_info->qgroup_tree);
271 __del_qgroup_rb(fs_info, qgroup);
303 * Add relation specified by two qgroup ids.
352 struct btrfs_qgroup *qgroup;
354 qgroup = find_qgroup_rb(fs_info, qgroupid);
355 if (!qgroup)
357 if (qgroup->rfer != rfer || qgroup->excl != excl)
419 * pass 1: read status, all qgroup infos and limits
429 struct btrfs_qgroup *qgroup;
444 "old qgroup version, quota disabled");
453 "qgroup generation mismatch, marked as inconsistent");
463 qgroup = find_qgroup_rb(fs_info, found_key.offset);
464 if ((qgroup && found_key.type == BTRFS_QGROUP_INFO_KEY) ||
465 (!qgroup && found_key.type == BTRFS_QGROUP_LIMIT_KEY)) {
466 btrfs_err(fs_info, "inconsistent qgroup config");
469 if (!qgroup) {
477 qgroup = add_qgroup_rb(fs_info, prealloc, found_key.offset);
479 ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);
489 qgroup->rfer = btrfs_qgroup_info_rfer(l, ptr);
490 qgroup->rfer_cmpr = btrfs_qgroup_info_rfer_cmpr(l, ptr);
491 qgroup->excl = btrfs_qgroup_info_excl(l, ptr);
492 qgroup->excl_cmpr = btrfs_qgroup_info_excl_cmpr(l, ptr);
501 qgroup->lim_flags = btrfs_qgroup_limit_flags(l, ptr);
502 qgroup->max_rfer = btrfs_qgroup_limit_max_rfer(l, ptr);
503 qgroup->max_excl = btrfs_qgroup_limit_max_excl(l, ptr);
504 qgroup->rsv_rfer = btrfs_qgroup_limit_rsv_rfer(l, ptr);
505 qgroup->rsv_excl = btrfs_qgroup_limit_rsv_excl(l, ptr);
519 * pass 2: read all qgroup relations
553 "orphan qgroup relation 0x%llx->0x%llx",
599 * Since we're unmounting, there is no race and no need to grab qgroup
604 struct btrfs_qgroup *qgroup;
607 qgroup = rb_entry(node, struct btrfs_qgroup, node);
609 if (qgroup->rsv.values[i]) {
612 "qgroup %hu/%llu has unreleased space, type %d rsv %llu",
613 btrfs_qgroup_level(qgroup->qgroupid),
614 btrfs_qgroup_subvolid(qgroup->qgroupid),
615 i, qgroup->rsv.values[i]);
631 struct btrfs_qgroup *qgroup;
634 qgroup = rb_entry(n, struct btrfs_qgroup, node);
636 __del_qgroup_rb(fs_info, qgroup);
637 btrfs_sysfs_del_one_qgroup(fs_info, qgroup);
638 kfree(qgroup);
820 struct btrfs_qgroup *qgroup)
832 key.offset = qgroup->qgroupid;
848 btrfs_set_qgroup_limit_flags(l, qgroup_limit, qgroup->lim_flags);
849 btrfs_set_qgroup_limit_max_rfer(l, qgroup_limit, qgroup->max_rfer);
850 btrfs_set_qgroup_limit_max_excl(l, qgroup_limit, qgroup->max_excl);
851 btrfs_set_qgroup_limit_rsv_rfer(l, qgroup_limit, qgroup->rsv_rfer);
852 btrfs_set_qgroup_limit_rsv_excl(l, qgroup_limit, qgroup->rsv_excl);
862 struct btrfs_qgroup *qgroup)
878 key.offset = qgroup->qgroupid;
895 btrfs_set_qgroup_info_rfer(l, qgroup_info, qgroup->rfer);
896 btrfs_set_qgroup_info_rfer_cmpr(l, qgroup_info, qgroup->rfer_cmpr);
897 btrfs_set_qgroup_info_excl(l, qgroup_info, qgroup->excl);
898 btrfs_set_qgroup_info_excl_cmpr(l, qgroup_info, qgroup->excl_cmpr);
1005 struct btrfs_qgroup *qgroup = NULL;
1164 qgroup = add_qgroup_rb(fs_info, prealloc, found_key.offset);
1166 if (IS_ERR(qgroup)) {
1167 ret = PTR_ERR(qgroup);
1171 ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);
1214 qgroup = add_qgroup_rb(fs_info, prealloc, BTRFS_FS_TREE_OBJECTID);
1216 ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);
1227 * a deadlock with tasks concurrently doing other qgroup operations, such
1228 * adding/removing qgroups or adding/deleting qgroup relations for example,
1229 * because all qgroup operations first start or join a transaction and then
1310 * - enable simple quotas (qgroup rsv are all 0)
1363 * Request qgroup rescan worker to complete and wait for it. This wait
1365 * deadlock with transaction by the qgroup rescan worker.
1444 struct btrfs_qgroup *qgroup)
1446 if (list_empty(&qgroup->dirty))
1447 list_add(&qgroup->dirty, &fs_info->dirty_qgroups);
1450 static void qgroup_iterator_add(struct list_head *head, struct btrfs_qgroup *qgroup)
1452 if (!list_empty(&qgroup->iterator))
1455 list_add_tail(&qgroup->iterator, head);
1461 struct btrfs_qgroup *qgroup;
1463 qgroup = list_first_entry(head, struct btrfs_qgroup, iterator);
1464 list_del_init(&qgroup->iterator);
1469 * The easy accounting, we're updating qgroup relationship whose child qgroup
1475 * So is qgroup reservation space, which should also be added/removed to
1485 struct btrfs_qgroup *qgroup;
1491 qgroup = find_qgroup_rb(fs_info, ref_root);
1492 if (!qgroup)
1495 qgroup_iterator_add(&qgroup_list, qgroup);
1499 qgroup->rfer += sign * num_bytes;
1500 qgroup->rfer_cmpr += sign * num_bytes;
1502 WARN_ON(sign < 0 && qgroup->excl < num_bytes);
1503 qgroup->excl += sign * num_bytes;
1504 qgroup->excl_cmpr += sign * num_bytes;
1507 qgroup_rsv_add_by_qgroup(fs_info, qgroup, src);
1509 qgroup_rsv_release_by_qgroup(fs_info, qgroup, src);
1510 qgroup_dirty(fs_info, qgroup);
1513 list_for_each_entry(glist, &qgroup->groups, next_group)
1524 * Quick path for updating qgroup with only excl refs.
1537 struct btrfs_qgroup *qgroup;
1541 qgroup = find_qgroup_rb(fs_info, src);
1542 if (!qgroup)
1544 if (qgroup->excl == qgroup->rfer) {
1546 err = __qgroup_excl_accounting(fs_info, dst, qgroup, sign);
1583 /* check if such qgroup relation exist firstly */
1646 /* check if such qgroup relation exist firstly */
1693 struct btrfs_qgroup *qgroup;
1706 qgroup = find_qgroup_rb(fs_info, qgroupid);
1707 if (qgroup) {
1723 qgroup = add_qgroup_rb(fs_info, prealloc, qgroupid);
1727 ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);
1734 static bool qgroup_has_usage(struct btrfs_qgroup *qgroup)
1736 return (qgroup->rfer > 0 || qgroup->rfer_cmpr > 0 ||
1737 qgroup->excl > 0 || qgroup->excl_cmpr > 0 ||
1738 qgroup->rsv.values[BTRFS_QGROUP_RSV_DATA] > 0 ||
1739 qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PREALLOC] > 0 ||
1740 qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PERTRANS] > 0);
1746 struct btrfs_qgroup *qgroup;
1756 qgroup = find_qgroup_rb(fs_info, qgroupid);
1757 if (!qgroup) {
1762 if (is_fstree(qgroupid) && qgroup_has_usage(qgroup)) {
1767 /* Check if there are no children of this qgroup */
1768 if (!list_empty(&qgroup->members)) {
1777 while (!list_empty(&qgroup->groups)) {
1778 list = list_first_entry(&qgroup->groups,
1791 * Remove the qgroup from sysfs now without holding the qgroup_lock
1795 btrfs_sysfs_del_one_qgroup(fs_info, qgroup);
1796 kfree(qgroup);
1806 struct btrfs_qgroup *qgroup;
1808 /* Sometimes we would want to clear the limit on this qgroup.
1810 * which tell kernel to clear the limit on this qgroup.
1820 qgroup = find_qgroup_rb(fs_info, qgroupid);
1821 if (!qgroup) {
1829 qgroup->lim_flags &= ~BTRFS_QGROUP_LIMIT_MAX_RFER;
1831 qgroup->max_rfer = 0;
1833 qgroup->max_rfer = limit->max_rfer;
1838 qgroup->lim_flags &= ~BTRFS_QGROUP_LIMIT_MAX_EXCL;
1840 qgroup->max_excl = 0;
1842 qgroup->max_excl = limit->max_excl;
1847 qgroup->lim_flags &= ~BTRFS_QGROUP_LIMIT_RSV_RFER;
1849 qgroup->rsv_rfer = 0;
1851 qgroup->rsv_rfer = limit->rsv_rfer;
1856 qgroup->lim_flags &= ~BTRFS_QGROUP_LIMIT_RSV_EXCL;
1858 qgroup->rsv_excl = 0;
1860 qgroup->rsv_excl = limit->rsv_excl;
1863 qgroup->lim_flags |= limit->flags;
1867 ret = update_qgroup_limit_item(trans, qgroup);
1880 * Inform qgroup to trace one dirty extent, its info is recorded in @record.
1881 * So qgroup can account it at transaction committing time.
1931 * NOTE: Current qgroup does the expensive backref walk at transaction
1947 * transaction committing, but not now as qgroup accounting will be wrong again.
2005 * Inform qgroup to trace one dirty extent, specified by @bytenr and
2007 * So qgroup can account it at commit trans time.
2047 * Inform qgroup to trace all leaf items of data
2073 /* filter out non qgroup-accountable extents */
2179 * reach OO(c), then mark both OO(c) and NN(c) as qgroup dirty.
2188 * 2) Mark the final tree blocks in @src_path and @dst_path qgroup dirty
2189 * NOTE: In above case, OO(a) and NN(a) won't be marked qgroup dirty.
2281 * blocks for qgroup accounting.
2321 * We will iterate through tree blocks NN(b), NN(d) and info qgroup to trace
2483 * Inform qgroup to trace a whole subtree, including all its child tree
2519 * mark qgroup inconsistent.
2618 static void qgroup_iterator_nested_add(struct list_head *head, struct btrfs_qgroup *qgroup)
2620 if (!list_empty(&qgroup->nested_iterator))
2623 list_add_tail(&qgroup->nested_iterator, head);
2629 struct btrfs_qgroup *qgroup;
2631 qgroup = list_first_entry(head, struct btrfs_qgroup, nested_iterator);
2632 list_del_init(&qgroup->nested_iterator);
2679 * Update qgroup rfer/excl counters.
2855 /* Quick exit, either not fs tree roots, or won't affect any qgroup */
2933 * Old roots should be searched when inserting qgroup
2998 * Called by the transaction commit path and the qgroup assign ioctl.
3006 * In case we are called from the qgroup assign ioctl, assert that we
3018 struct btrfs_qgroup *qgroup;
3019 qgroup = list_first_entry(&fs_info->dirty_qgroups,
3021 list_del_init(&qgroup->dirty);
3023 ret = update_qgroup_info_item(trans, qgroup);
3026 ret = update_qgroup_limit_item(trans, qgroup);
3057 * also disable it in kernel, as this behavior is known to mark qgroup
3078 struct btrfs_qgroup *qgroup;
3085 qgroup = find_qgroup_rb(fs_info, qgroupid);
3086 if (!qgroup) {
3141 * Return <0 for fatal errors (like srcid/parentid has no qgroup).
3161 * Source has no parent qgroup, but our new qgroup would have one.
3173 * More than one parent qgroup, we can't be sure about accounting
3227 * The other one in create_pending_snapshot() where no other qgroup
3283 * add qgroup to all inherited groups
3362 * If the source qgroup has parent but the new one doesn't,
3470 struct btrfs_qgroup *qgroup;
3490 qgroup = find_qgroup_rb(fs_info, ref_root);
3491 if (!qgroup)
3494 qgroup_iterator_add(&qgroup_list, qgroup);
3495 list_for_each_entry(qgroup, &qgroup_list, iterator) {
3498 if (enforce && !qgroup_check_limits(qgroup, num_bytes)) {
3503 list_for_each_entry(glist, &qgroup->groups, next_group)
3511 list_for_each_entry(qgroup, &qgroup_list, iterator)
3512 qgroup_rsv_add(fs_info, qgroup, num_bytes, type);
3521 * Free @num_bytes of reserved space with @type for qgroup. (Normally level 0
3522 * qgroup).
3524 * Will handle all higher level qgroup too.
3526 * NOTE: If @num_bytes is (u64)-1, this means to free all bytes of this qgroup.
3533 struct btrfs_qgroup *qgroup;
3551 qgroup = find_qgroup_rb(fs_info, ref_root);
3552 if (!qgroup)
3558 * level 0 qgroup as real num_bytes to free.
3560 num_bytes = qgroup->rsv.values[type];
3562 qgroup_iterator_add(&qgroup_list, qgroup);
3563 list_for_each_entry(qgroup, &qgroup_list, iterator) {
3566 qgroup_rsv_release(fs_info, qgroup, num_bytes, type);
3567 list_for_each_entry(glist, &qgroup->groups, next_group) {
3720 * should be recorded by qgroup
3756 * qgroup info, and only if we did any actual work. This also prevents
3782 btrfs_err(fs_info, "fail to update qgroup status: %d",
3797 btrfs_info(fs_info, "qgroup scan paused");
3799 btrfs_info(fs_info, "qgroup scan cancelled");
3801 btrfs_info(fs_info, "qgroup scan completed%s",
3804 btrfs_err(fs_info, "qgroup scan failed with %d", err);
3819 btrfs_warn(fs_info, "qgroup rescan init failed, running in simple mode");
3824 /* we're resuming qgroup rescan at mount time */
3828 "qgroup rescan init failed, qgroup rescan is not queued");
3833 "qgroup rescan init failed, qgroup is not enabled");
3846 "qgroup rescan is already in progress");
3851 "qgroup rescan init failed, qgroup is not enabled");
3882 struct btrfs_qgroup *qgroup;
3885 /* clear all current qgroup tracking information */
3887 qgroup = rb_entry(n, struct btrfs_qgroup, node);
3888 qgroup->rfer = 0;
3889 qgroup->rfer_cmpr = 0;
3890 qgroup->excl = 0;
3891 qgroup->excl_cmpr = 0;
3892 qgroup_dirty(fs_info, qgroup);
4043 * Try to free some space for qgroup.
4045 * For qgroup, there are only 3 ways to free qgroup space:
4058 * In theory this shouldn't provide much space, but any more qgroup space
4116 /* @reserved parameter is mandatory for qgroup */
4154 * Reserve qgroup space for range [start, start + len).
4218 * However as long as we free qgroup reserved according to
4304 * Since new qgroup accounting framework will only update qgroup numbers at
4444 struct btrfs_qgroup *qgroup;
4453 qgroup = find_qgroup_rb(fs_info, ref_root);
4454 if (!qgroup)
4457 qgroup_iterator_add(&qgroup_list, qgroup);
4458 list_for_each_entry(qgroup, &qgroup_list, iterator) {
4461 qgroup_rsv_release(fs_info, qgroup, num_bytes,
4464 qgroup_rsv_add(fs_info, qgroup, num_bytes,
4467 list_for_each_entry(glist, &qgroup->groups, next_group)
4498 * Check qgroup reserved space leaking, normally at destroy inode
4517 "leaking qgroup reserved space, ino: %llu, start: %llu, end: %llu",
4541 * Every record here means we skipped a full subtree scan for qgroup.
4629 * no one else can modify tree blocks thus we qgroup will not change
4662 * Marking qgroup inconsistent should be enough
4685 * delayed subtree trace for qgroup.
4804 struct btrfs_qgroup *qgroup;
4822 qgroup = find_qgroup_rb(fs_info, root);
4823 if (!qgroup) {
4829 qgroup_iterator_add(&qgroup_list, qgroup);