Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Facebook. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public |
| 6 | * License v2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public |
| 14 | * License along with this program; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 021110-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __BTRFS_QGROUP__ |
| 20 | #define __BTRFS_QGROUP__ |
| 21 | |
Qu Wenruo | 3368d00 | 2015-04-16 14:34:17 +0800 | [diff] [blame^] | 22 | #include "ulist.h" |
| 23 | #include "delayed-ref.h" |
| 24 | |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 25 | /* |
| 26 | * A description of the operations, all of these operations only happen when we |
| 27 | * are adding the 1st reference for that subvolume in the case of adding space |
| 28 | * or on the last reference delete in the case of subtraction. The only |
| 29 | * exception is the last one, which is added for confusion. |
| 30 | * |
| 31 | * BTRFS_QGROUP_OPER_ADD_EXCL: adding bytes where this subvolume is the only |
| 32 | * one pointing at the bytes we are adding. This is called on the first |
| 33 | * allocation. |
| 34 | * |
| 35 | * BTRFS_QGROUP_OPER_ADD_SHARED: adding bytes where this bytenr is going to be |
| 36 | * shared between subvols. This is called on the creation of a ref that already |
| 37 | * has refs from a different subvolume, so basically reflink. |
| 38 | * |
| 39 | * BTRFS_QGROUP_OPER_SUB_EXCL: removing bytes where this subvolume is the only |
| 40 | * one referencing the range. |
| 41 | * |
| 42 | * BTRFS_QGROUP_OPER_SUB_SHARED: removing bytes where this subvolume shares with |
| 43 | * refs with other subvolumes. |
| 44 | */ |
| 45 | enum btrfs_qgroup_operation_type { |
| 46 | BTRFS_QGROUP_OPER_ADD_EXCL, |
| 47 | BTRFS_QGROUP_OPER_ADD_SHARED, |
| 48 | BTRFS_QGROUP_OPER_SUB_EXCL, |
| 49 | BTRFS_QGROUP_OPER_SUB_SHARED, |
Mark Fasheh | 1152651 | 2014-07-17 12:39:01 -0700 | [diff] [blame] | 50 | BTRFS_QGROUP_OPER_SUB_SUBTREE, |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct btrfs_qgroup_operation { |
| 54 | u64 ref_root; |
| 55 | u64 bytenr; |
| 56 | u64 num_bytes; |
| 57 | u64 seq; |
| 58 | enum btrfs_qgroup_operation_type type; |
| 59 | struct seq_list elem; |
| 60 | struct rb_node n; |
| 61 | struct list_head list; |
| 62 | }; |
| 63 | |
Qu Wenruo | 3368d00 | 2015-04-16 14:34:17 +0800 | [diff] [blame^] | 64 | /* |
| 65 | * Record a dirty extent, and info qgroup to update quota on it |
| 66 | * TODO: Use kmem cache to alloc it. |
| 67 | */ |
| 68 | struct btrfs_qgroup_extent_record { |
| 69 | struct rb_node node; |
| 70 | u64 bytenr; |
| 71 | u64 num_bytes; |
| 72 | struct ulist *old_roots; |
| 73 | }; |
| 74 | |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 75 | int btrfs_quota_enable(struct btrfs_trans_handle *trans, |
| 76 | struct btrfs_fs_info *fs_info); |
| 77 | int btrfs_quota_disable(struct btrfs_trans_handle *trans, |
| 78 | struct btrfs_fs_info *fs_info); |
| 79 | int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info); |
| 80 | void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info); |
| 81 | int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info); |
| 82 | int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, |
| 83 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); |
| 84 | int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, |
| 85 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); |
| 86 | int btrfs_create_qgroup(struct btrfs_trans_handle *trans, |
Dongsheng Yang | 4087cf2 | 2015-01-18 10:59:23 -0500 | [diff] [blame] | 87 | struct btrfs_fs_info *fs_info, u64 qgroupid); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 88 | int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, |
| 89 | struct btrfs_fs_info *fs_info, u64 qgroupid); |
| 90 | int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, |
| 91 | struct btrfs_fs_info *fs_info, u64 qgroupid, |
| 92 | struct btrfs_qgroup_limit *limit); |
| 93 | int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info); |
| 94 | void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); |
| 95 | struct btrfs_delayed_extent_op; |
| 96 | int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans, |
| 97 | struct btrfs_fs_info *fs_info, u64 ref_root, |
| 98 | u64 bytenr, u64 num_bytes, |
| 99 | enum btrfs_qgroup_operation_type type, |
| 100 | int mod_seq); |
Qu Wenruo | 3368d00 | 2015-04-16 14:34:17 +0800 | [diff] [blame^] | 101 | struct btrfs_qgroup_extent_record |
| 102 | *btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs, |
| 103 | struct btrfs_qgroup_extent_record *record); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 104 | int btrfs_delayed_qgroup_accounting(struct btrfs_trans_handle *trans, |
| 105 | struct btrfs_fs_info *fs_info); |
| 106 | void btrfs_remove_qgroup_operation(struct btrfs_trans_handle *trans, |
| 107 | struct btrfs_fs_info *fs_info, |
| 108 | struct btrfs_qgroup_operation *oper); |
| 109 | int btrfs_run_qgroups(struct btrfs_trans_handle *trans, |
| 110 | struct btrfs_fs_info *fs_info); |
| 111 | int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, |
| 112 | struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid, |
| 113 | struct btrfs_qgroup_inherit *inherit); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 114 | int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes); |
| 115 | void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes); |
| 116 | |
| 117 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); |
| 118 | |
| 119 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| 120 | int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid, |
| 121 | u64 rfer, u64 excl); |
| 122 | #endif |
| 123 | |
| 124 | #endif /* __BTRFS_QGROUP__ */ |