1
2
3
4
5
6#ifndef BTRFS_QGROUP_H
7#define BTRFS_QGROUP_H
8
9#include "ulist.h"
10#include "delayed-ref.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44struct btrfs_qgroup_extent_record {
45 struct rb_node node;
46 u64 bytenr;
47 u64 num_bytes;
48 struct ulist *old_roots;
49};
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72enum btrfs_qgroup_rsv_type {
73 BTRFS_QGROUP_RSV_DATA = 0,
74 BTRFS_QGROUP_RSV_META_PERTRANS,
75 BTRFS_QGROUP_RSV_META_PREALLOC,
76 BTRFS_QGROUP_RSV_LAST,
77};
78
79
80
81
82
83
84
85
86
87
88
89struct btrfs_qgroup_rsv {
90 u64 values[BTRFS_QGROUP_RSV_LAST];
91};
92
93
94
95
96struct btrfs_qgroup {
97 u64 qgroupid;
98
99
100
101
102 u64 rfer;
103 u64 rfer_cmpr;
104 u64 excl;
105 u64 excl_cmpr;
106
107
108
109
110 u64 lim_flags;
111 u64 max_rfer;
112 u64 max_excl;
113 u64 rsv_rfer;
114 u64 rsv_excl;
115
116
117
118
119 struct btrfs_qgroup_rsv rsv;
120
121
122
123
124 struct list_head groups;
125 struct list_head members;
126 struct list_head dirty;
127 struct rb_node node;
128
129
130
131
132
133 u64 old_refcnt;
134 u64 new_refcnt;
135};
136
137
138
139
140#define QGROUP_RESERVE (1<<0)
141#define QGROUP_RELEASE (1<<1)
142#define QGROUP_FREE (1<<2)
143
144int btrfs_quota_enable(struct btrfs_trans_handle *trans,
145 struct btrfs_fs_info *fs_info);
146int btrfs_quota_disable(struct btrfs_trans_handle *trans,
147 struct btrfs_fs_info *fs_info);
148int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
149void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info);
150int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
151 bool interruptible);
152int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
153 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
154int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
155 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
156int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
157 struct btrfs_fs_info *fs_info, u64 qgroupid);
158int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
159 struct btrfs_fs_info *fs_info, u64 qgroupid);
160int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
161 struct btrfs_fs_info *fs_info, u64 qgroupid,
162 struct btrfs_qgroup_limit *limit);
163int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
164void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
165struct btrfs_delayed_extent_op;
166
167
168
169
170
171
172
173
174
175
176
177
178int btrfs_qgroup_trace_extent_nolock(
179 struct btrfs_fs_info *fs_info,
180 struct btrfs_delayed_ref_root *delayed_refs,
181 struct btrfs_qgroup_extent_record *record);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info,
205 struct btrfs_qgroup_extent_record *qrecord);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans,
221 struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes,
222 gfp_t gfp_flag);
223
224
225
226
227
228
229
230int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans,
231 struct btrfs_fs_info *fs_info,
232 struct extent_buffer *eb);
233
234
235
236
237
238
239
240
241
242
243int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
244 struct btrfs_root *root,
245 struct extent_buffer *root_eb,
246 u64 root_gen, int root_level);
247int
248btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
249 struct btrfs_fs_info *fs_info,
250 u64 bytenr, u64 num_bytes,
251 struct ulist *old_roots, struct ulist *new_roots);
252int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans);
253int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
254 struct btrfs_fs_info *fs_info);
255int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
256 struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
257 struct btrfs_qgroup_inherit *inherit);
258void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info,
259 u64 ref_root, u64 num_bytes,
260 enum btrfs_qgroup_rsv_type type);
261static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
262 u64 ref_root, u64 num_bytes)
263{
264 trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
265 btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes,
266 BTRFS_QGROUP_RSV_DATA);
267}
268
269#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
270int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
271 u64 rfer, u64 excl);
272#endif
273
274
275int btrfs_qgroup_reserve_data(struct inode *inode,
276 struct extent_changeset **reserved, u64 start, u64 len);
277int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len);
278int btrfs_qgroup_free_data(struct inode *inode,
279 struct extent_changeset *reserved, u64 start, u64 len);
280
281int __btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,
282 enum btrfs_qgroup_rsv_type type, bool enforce);
283
284static inline int btrfs_qgroup_reserve_meta_pertrans(struct btrfs_root *root,
285 int num_bytes, bool enforce)
286{
287 return __btrfs_qgroup_reserve_meta(root, num_bytes,
288 BTRFS_QGROUP_RSV_META_PERTRANS, enforce);
289}
290static inline int btrfs_qgroup_reserve_meta_prealloc(struct btrfs_root *root,
291 int num_bytes, bool enforce)
292{
293 return __btrfs_qgroup_reserve_meta(root, num_bytes,
294 BTRFS_QGROUP_RSV_META_PREALLOC, enforce);
295}
296
297void __btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes,
298 enum btrfs_qgroup_rsv_type type);
299
300
301static inline void btrfs_qgroup_free_meta_pertrans(struct btrfs_root *root,
302 int num_bytes)
303{
304 __btrfs_qgroup_free_meta(root, num_bytes,
305 BTRFS_QGROUP_RSV_META_PERTRANS);
306}
307
308
309static inline void btrfs_qgroup_free_meta_prealloc(struct btrfs_root *root,
310 int num_bytes)
311{
312 __btrfs_qgroup_free_meta(root, num_bytes,
313 BTRFS_QGROUP_RSV_META_PREALLOC);
314}
315
316
317
318
319
320void btrfs_qgroup_free_meta_all_pertrans(struct btrfs_root *root);
321
322
323
324
325
326
327
328void btrfs_qgroup_convert_reserved_meta(struct btrfs_root *root, int num_bytes);
329
330void btrfs_qgroup_check_reserved_leak(struct inode *inode);
331
332#endif
333