blob: 686b60f60b617e4948c8e369c8a1e35f9fbca753 [file] [log] [blame]
Josef Bacikfcebe452014-05-13 17:30:47 -07001/*
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 Wenruo3368d002015-04-16 14:34:17 +080022#include "ulist.h"
23#include "delayed-ref.h"
24
Josef Bacikfcebe452014-05-13 17:30:47 -070025/*
Qu Wenruo3368d002015-04-16 14:34:17 +080026 * Record a dirty extent, and info qgroup to update quota on it
27 * TODO: Use kmem cache to alloc it.
28 */
29struct btrfs_qgroup_extent_record {
30 struct rb_node node;
31 u64 bytenr;
32 u64 num_bytes;
33 struct ulist *old_roots;
34};
35
Qu Wenruo81fb6f72015-09-28 16:57:53 +080036/*
37 * For qgroup event trace points only
38 */
39#define QGROUP_RESERVE (1<<0)
40#define QGROUP_RELEASE (1<<1)
41#define QGROUP_FREE (1<<2)
42
Josef Bacikfcebe452014-05-13 17:30:47 -070043int btrfs_quota_enable(struct btrfs_trans_handle *trans,
44 struct btrfs_fs_info *fs_info);
45int btrfs_quota_disable(struct btrfs_trans_handle *trans,
46 struct btrfs_fs_info *fs_info);
47int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
48void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info);
49int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info);
50int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
51 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
52int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
53 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
54int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
Dongsheng Yang4087cf22015-01-18 10:59:23 -050055 struct btrfs_fs_info *fs_info, u64 qgroupid);
Josef Bacikfcebe452014-05-13 17:30:47 -070056int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
57 struct btrfs_fs_info *fs_info, u64 qgroupid);
58int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
59 struct btrfs_fs_info *fs_info, u64 qgroupid,
60 struct btrfs_qgroup_limit *limit);
61int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
62void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
63struct btrfs_delayed_extent_op;
Qu Wenruo3b7d00f2015-04-16 16:40:39 +080064int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
65 struct btrfs_fs_info *fs_info);
Qu Wenruo3368d002015-04-16 14:34:17 +080066struct btrfs_qgroup_extent_record
67*btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
68 struct btrfs_qgroup_extent_record *record);
Qu Wenruo442244c2015-04-16 17:18:36 +080069int
70btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
71 struct btrfs_fs_info *fs_info,
72 u64 bytenr, u64 num_bytes,
73 struct ulist *old_roots, struct ulist *new_roots);
Qu Wenruo550d7a22015-04-16 15:37:33 +080074int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
75 struct btrfs_fs_info *fs_info);
Josef Bacikfcebe452014-05-13 17:30:47 -070076int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
77 struct btrfs_fs_info *fs_info);
78int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
79 struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
80 struct btrfs_qgroup_inherit *inherit);
Qu Wenruo297d7502015-09-08 17:08:37 +080081void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info,
82 u64 ref_root, u64 num_bytes);
Qu Wenruo297d7502015-09-08 17:08:37 +080083/*
84 * TODO: Add proper trace point for it, as btrfs_qgroup_free() is
85 * called by everywhere, can't provide good trace for delayed ref case.
86 */
87static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
88 u64 ref_root, u64 num_bytes)
89{
90 btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes);
Qu Wenruo81fb6f72015-09-28 16:57:53 +080091 trace_btrfs_qgroup_free_delayed_ref(ref_root, num_bytes);
Qu Wenruo297d7502015-09-08 17:08:37 +080092}
Josef Bacikfcebe452014-05-13 17:30:47 -070093void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
94
95#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
96int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
97 u64 rfer, u64 excl);
98#endif
99
Qu Wenruo52472552015-10-12 16:05:40 +0800100/* New io_tree based accurate qgroup reserve API */
101int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len);
Qu Wenruof695fdc2015-10-12 16:28:06 +0800102int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len);
103int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len);
Qu Wenruo55eeaf02015-09-08 17:08:38 +0800104
105int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes);
106void btrfs_qgroup_free_meta_all(struct btrfs_root *root);
107void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes);
Josef Bacikfcebe452014-05-13 17:30:47 -0700108#endif /* __BTRFS_QGROUP__ */