diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2015-09-08 11:08:38 +0200 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-10-22 03:37:47 +0200 |
commit | 55eeaf0578038c40baaf3cf9408c23e42cd2a2b8 (patch) | |
tree | 3539d0575ebba0c079cc293b9cf884a402688d1b /fs/btrfs/qgroup.c | |
parent | btrfs: delayed_ref: release and free qgroup reserved at proper timing (diff) | |
download | linux-55eeaf0578038c40baaf3cf9408c23e42cd2a2b8.tar.xz linux-55eeaf0578038c40baaf3cf9408c23e42cd2a2b8.zip |
btrfs: qgroup: Introduce new functions to reserve/free metadata
Introduce new functions btrfs_qgroup_reserve/free_meta() to reserve/free
metadata reserved space.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/qgroup.c')
-rw-r--r-- | fs/btrfs/qgroup.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 75d8e584c3e5..897a49d71638 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2594,3 +2594,43 @@ int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len) { return __btrfs_qgroup_release_data(inode, start, len, 0); } + +int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes) +{ + int ret; + + if (!root->fs_info->quota_enabled || !is_fstree(root->objectid) || + num_bytes == 0) + return 0; + + BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); + ret = btrfs_qgroup_reserve(root, num_bytes); + if (ret < 0) + return ret; + atomic_add(num_bytes, &root->qgroup_meta_rsv); + return ret; +} + +void btrfs_qgroup_free_meta_all(struct btrfs_root *root) +{ + int reserved; + + if (!root->fs_info->quota_enabled || !is_fstree(root->objectid)) + return; + + reserved = atomic_xchg(&root->qgroup_meta_rsv, 0); + if (reserved == 0) + return; + btrfs_qgroup_free(root, reserved); +} + +void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes) +{ + if (!root->fs_info->quota_enabled || !is_fstree(root->objectid)) + return; + + BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); + WARN_ON(atomic_read(&root->qgroup_meta_rsv) < num_bytes); + atomic_sub(num_bytes, &root->qgroup_meta_rsv); + btrfs_qgroup_free(root, num_bytes); +} |