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 | /* |
Qu Wenruo | 3368d00 | 2015-04-16 14:34:17 +0800 | [diff] [blame] | 26 | * Record a dirty extent, and info qgroup to update quota on it |
| 27 | * TODO: Use kmem cache to alloc it. |
| 28 | */ |
| 29 | struct btrfs_qgroup_extent_record { |
| 30 | struct rb_node node; |
| 31 | u64 bytenr; |
| 32 | u64 num_bytes; |
| 33 | struct ulist *old_roots; |
| 34 | }; |
| 35 | |
Qu Wenruo | 81fb6f7 | 2015-09-28 16:57:53 +0800 | [diff] [blame] | 36 | /* |
| 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 Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 43 | int btrfs_quota_enable(struct btrfs_trans_handle *trans, |
| 44 | struct btrfs_fs_info *fs_info); |
| 45 | int btrfs_quota_disable(struct btrfs_trans_handle *trans, |
| 46 | struct btrfs_fs_info *fs_info); |
| 47 | int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info); |
| 48 | void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info); |
Jeff Mahoney | d06f23d | 2016-08-08 22:08:06 -0400 | [diff] [blame] | 49 | int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info, |
| 50 | bool interruptible); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 51 | int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, |
| 52 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); |
| 53 | int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, |
| 54 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); |
| 55 | int btrfs_create_qgroup(struct btrfs_trans_handle *trans, |
Dongsheng Yang | 4087cf2 | 2015-01-18 10:59:23 -0500 | [diff] [blame] | 56 | struct btrfs_fs_info *fs_info, u64 qgroupid); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 57 | int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, |
| 58 | struct btrfs_fs_info *fs_info, u64 qgroupid); |
| 59 | int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, |
| 60 | struct btrfs_fs_info *fs_info, u64 qgroupid, |
| 61 | struct btrfs_qgroup_limit *limit); |
| 62 | int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info); |
| 63 | void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); |
| 64 | struct btrfs_delayed_extent_op; |
Qu Wenruo | 3b7d00f | 2015-04-16 16:40:39 +0800 | [diff] [blame] | 65 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, |
| 66 | struct btrfs_fs_info *fs_info); |
Qu Wenruo | cb93b52 | 2016-08-15 10:36:50 +0800 | [diff] [blame] | 67 | /* |
| 68 | * Insert one dirty extent record into @delayed_refs, informing qgroup to |
| 69 | * account that extent at commit trans time. |
| 70 | * |
| 71 | * No lock version, caller must acquire delayed ref lock and allocate memory. |
| 72 | * |
| 73 | * Return 0 for success insert |
| 74 | * Return >0 for existing record, caller can free @record safely. |
| 75 | * Error is not possible |
| 76 | */ |
| 77 | int btrfs_qgroup_insert_dirty_extent_nolock( |
| 78 | struct btrfs_fs_info *fs_info, |
| 79 | struct btrfs_delayed_ref_root *delayed_refs, |
| 80 | struct btrfs_qgroup_extent_record *record); |
| 81 | |
| 82 | /* |
| 83 | * Insert one dirty extent record into @delayed_refs, informing qgroup to |
| 84 | * account that extent at commit trans time. |
| 85 | * |
| 86 | * Better encapsulated version. |
| 87 | * |
| 88 | * Return 0 if the operation is done. |
| 89 | * Return <0 for error, like memory allocation failure or invalid parameter |
| 90 | * (NULL trans) |
| 91 | */ |
| 92 | int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, |
| 93 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, |
| 94 | gfp_t gfp_flag); |
| 95 | |
Qu Wenruo | 442244c | 2015-04-16 17:18:36 +0800 | [diff] [blame] | 96 | int |
| 97 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, |
| 98 | struct btrfs_fs_info *fs_info, |
| 99 | u64 bytenr, u64 num_bytes, |
| 100 | struct ulist *old_roots, struct ulist *new_roots); |
Qu Wenruo | 550d7a2 | 2015-04-16 15:37:33 +0800 | [diff] [blame] | 101 | int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans, |
| 102 | struct btrfs_fs_info *fs_info); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 103 | int btrfs_run_qgroups(struct btrfs_trans_handle *trans, |
| 104 | struct btrfs_fs_info *fs_info); |
| 105 | int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, |
| 106 | struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid, |
| 107 | struct btrfs_qgroup_inherit *inherit); |
Qu Wenruo | 297d750 | 2015-09-08 17:08:37 +0800 | [diff] [blame] | 108 | void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info, |
| 109 | u64 ref_root, u64 num_bytes); |
Qu Wenruo | 297d750 | 2015-09-08 17:08:37 +0800 | [diff] [blame] | 110 | /* |
| 111 | * TODO: Add proper trace point for it, as btrfs_qgroup_free() is |
| 112 | * called by everywhere, can't provide good trace for delayed ref case. |
| 113 | */ |
| 114 | static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info, |
| 115 | u64 ref_root, u64 num_bytes) |
| 116 | { |
| 117 | btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes); |
Jeff Mahoney | bc07452 | 2016-06-09 17:27:55 -0400 | [diff] [blame] | 118 | trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes); |
Qu Wenruo | 297d750 | 2015-09-08 17:08:37 +0800 | [diff] [blame] | 119 | } |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 120 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); |
| 121 | |
| 122 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
| 123 | int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid, |
| 124 | u64 rfer, u64 excl); |
| 125 | #endif |
| 126 | |
Qu Wenruo | 5247255 | 2015-10-12 16:05:40 +0800 | [diff] [blame] | 127 | /* New io_tree based accurate qgroup reserve API */ |
| 128 | int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len); |
Qu Wenruo | f695fdc | 2015-10-12 16:28:06 +0800 | [diff] [blame] | 129 | int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len); |
| 130 | int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len); |
Qu Wenruo | 55eeaf0 | 2015-09-08 17:08:38 +0800 | [diff] [blame] | 131 | |
| 132 | int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes); |
| 133 | void btrfs_qgroup_free_meta_all(struct btrfs_root *root); |
| 134 | void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes); |
Qu Wenruo | 56fa9d0 | 2015-10-13 09:53:10 +0800 | [diff] [blame] | 135 | void btrfs_qgroup_check_reserved_leak(struct inode *inode); |
Josef Bacik | fcebe45 | 2014-05-13 17:30:47 -0700 | [diff] [blame] | 136 | #endif /* __BTRFS_QGROUP__ */ |