diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2015-09-08 17:08:37 +0800 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-10-21 18:37:47 -0700 |
commit | 297d750b9f8d7e6f2dbdf8abc5aa3b5c656affdc (patch) | |
tree | bd755d89f3c4d7f9c47751772aea2221761d76a2 /fs/btrfs/inode.c | |
parent | f64d5ca868214f9beb60108c82fcb96940132bfb (diff) | |
download | linux-297d750b9f8d7e6f2dbdf8abc5aa3b5c656affdc.tar.bz2 |
btrfs: delayed_ref: release and free qgroup reserved at proper timing
Qgroup reserved space needs to be released from inode dirty map and get
freed at different timing:
1) Release when the metadata is written into tree
After corresponding metadata is written into tree, any newer write will
be COWed(don't include NOCOW case yet).
So we must release its range from inode dirty range map, or we will
forget to reserve needed range, causing accounting exceeding the limit.
2) Free reserved bytes when delayed ref is run
When delayed refs are run, qgroup accounting will follow soon and turn
the reserved bytes into rfer/excl numbers.
As run_delayed_refs and qgroup accounting are all done at
commit_transaction() time, we are safe to free reserved space in
run_delayed_ref time().
With these timing to release/free reserved space, we should be able to
resolve the long existing qgroup reserve space leak problem.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5ce55f6eefce..c21ed7b14691 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2119,6 +2119,16 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ret = btrfs_alloc_reserved_file_extent(trans, root, root->root_key.objectid, btrfs_ino(inode), file_pos, &ins); + if (ret < 0) + goto out; + /* + * Release the reserved range from inode dirty range map, and + * move it to delayed ref codes, as now accounting only happens at + * commit_transaction() time. + */ + btrfs_qgroup_release_data(inode, file_pos, ram_bytes); + ret = btrfs_add_delayed_qgroup_reserve(root->fs_info, trans, + root->objectid, disk_bytenr, ram_bytes); out: btrfs_free_path(path); |