Commit | Line | Data |
---|---|---|
fcebe456 JB |
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 | ||
3368d001 QW |
22 | #include "ulist.h" |
23 | #include "delayed-ref.h" | |
24 | ||
1d2beaa9 QW |
25 | /* |
26 | * Btrfs qgroup overview | |
27 | * | |
28 | * Btrfs qgroup splits into 3 main part: | |
29 | * 1) Reserve | |
30 | * Reserve metadata/data space for incoming operations | |
31 | * Affect how qgroup limit works | |
32 | * | |
33 | * 2) Trace | |
34 | * Tell btrfs qgroup to trace dirty extents. | |
35 | * | |
36 | * Dirty extents including: | |
37 | * - Newly allocated extents | |
38 | * - Extents going to be deleted (in this trans) | |
39 | * - Extents whose owner is going to be modified | |
40 | * | |
41 | * This is the main part affects whether qgroup numbers will stay | |
42 | * consistent. | |
43 | * Btrfs qgroup can trace clean extents and won't cause any problem, | |
44 | * but it will consume extra CPU time, it should be avoided if possible. | |
45 | * | |
46 | * 3) Account | |
47 | * Btrfs qgroup will updates its numbers, based on dirty extents traced | |
48 | * in previous step. | |
49 | * | |
50 | * Normally at qgroup rescan and transaction commit time. | |
51 | */ | |
52 | ||
3368d001 QW |
53 | /* |
54 | * Record a dirty extent, and info qgroup to update quota on it | |
55 | * TODO: Use kmem cache to alloc it. | |
56 | */ | |
57 | struct btrfs_qgroup_extent_record { | |
58 | struct rb_node node; | |
59 | u64 bytenr; | |
60 | u64 num_bytes; | |
61 | struct ulist *old_roots; | |
62 | }; | |
63 | ||
81fb6f77 QW |
64 | /* |
65 | * For qgroup event trace points only | |
66 | */ | |
67 | #define QGROUP_RESERVE (1<<0) | |
68 | #define QGROUP_RELEASE (1<<1) | |
69 | #define QGROUP_FREE (1<<2) | |
70 | ||
fcebe456 JB |
71 | int btrfs_quota_enable(struct btrfs_trans_handle *trans, |
72 | struct btrfs_fs_info *fs_info); | |
73 | int btrfs_quota_disable(struct btrfs_trans_handle *trans, | |
74 | struct btrfs_fs_info *fs_info); | |
75 | int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info); | |
76 | void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info); | |
d06f23d6 JM |
77 | int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info, |
78 | bool interruptible); | |
fcebe456 JB |
79 | int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, |
80 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); | |
81 | int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, | |
82 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); | |
83 | int btrfs_create_qgroup(struct btrfs_trans_handle *trans, | |
4087cf24 | 84 | struct btrfs_fs_info *fs_info, u64 qgroupid); |
fcebe456 JB |
85 | int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, |
86 | struct btrfs_fs_info *fs_info, u64 qgroupid); | |
87 | int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, | |
88 | struct btrfs_fs_info *fs_info, u64 qgroupid, | |
89 | struct btrfs_qgroup_limit *limit); | |
90 | int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info); | |
91 | void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); | |
92 | struct btrfs_delayed_extent_op; | |
3b7d00f9 QW |
93 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, |
94 | struct btrfs_fs_info *fs_info); | |
cb93b52c QW |
95 | /* |
96 | * Insert one dirty extent record into @delayed_refs, informing qgroup to | |
97 | * account that extent at commit trans time. | |
98 | * | |
99 | * No lock version, caller must acquire delayed ref lock and allocate memory. | |
100 | * | |
101 | * Return 0 for success insert | |
102 | * Return >0 for existing record, caller can free @record safely. | |
103 | * Error is not possible | |
104 | */ | |
105 | int btrfs_qgroup_insert_dirty_extent_nolock( | |
106 | struct btrfs_fs_info *fs_info, | |
107 | struct btrfs_delayed_ref_root *delayed_refs, | |
108 | struct btrfs_qgroup_extent_record *record); | |
109 | ||
110 | /* | |
111 | * Insert one dirty extent record into @delayed_refs, informing qgroup to | |
112 | * account that extent at commit trans time. | |
113 | * | |
114 | * Better encapsulated version. | |
115 | * | |
116 | * Return 0 if the operation is done. | |
117 | * Return <0 for error, like memory allocation failure or invalid parameter | |
118 | * (NULL trans) | |
119 | */ | |
120 | int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, | |
121 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, | |
122 | gfp_t gfp_flag); | |
123 | ||
442244c9 QW |
124 | int |
125 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, | |
126 | struct btrfs_fs_info *fs_info, | |
127 | u64 bytenr, u64 num_bytes, | |
128 | struct ulist *old_roots, struct ulist *new_roots); | |
550d7a2e QW |
129 | int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans, |
130 | struct btrfs_fs_info *fs_info); | |
fcebe456 JB |
131 | int btrfs_run_qgroups(struct btrfs_trans_handle *trans, |
132 | struct btrfs_fs_info *fs_info); | |
133 | int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, | |
134 | struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid, | |
135 | struct btrfs_qgroup_inherit *inherit); | |
297d750b QW |
136 | void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info, |
137 | u64 ref_root, u64 num_bytes); | |
297d750b QW |
138 | /* |
139 | * TODO: Add proper trace point for it, as btrfs_qgroup_free() is | |
140 | * called by everywhere, can't provide good trace for delayed ref case. | |
141 | */ | |
142 | static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info, | |
143 | u64 ref_root, u64 num_bytes) | |
144 | { | |
145 | btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes); | |
bc074524 | 146 | trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes); |
297d750b | 147 | } |
fcebe456 JB |
148 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); |
149 | ||
150 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | |
151 | int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid, | |
152 | u64 rfer, u64 excl); | |
153 | #endif | |
154 | ||
52472553 QW |
155 | /* New io_tree based accurate qgroup reserve API */ |
156 | int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len); | |
f695fdce QW |
157 | int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len); |
158 | int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len); | |
55eeaf05 QW |
159 | |
160 | int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes); | |
161 | void btrfs_qgroup_free_meta_all(struct btrfs_root *root); | |
162 | void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes); | |
56fa9d07 | 163 | void btrfs_qgroup_check_reserved_leak(struct inode *inode); |
fcebe456 | 164 | #endif /* __BTRFS_QGROUP__ */ |