btrfs: delayed_ref: release and free qgroup reserved at proper timing
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Tue, 8 Sep 2015 09:08:37 +0000 (17:08 +0800)
committerChris Mason <clm@fb.com>
Thu, 22 Oct 2015 01:37:47 +0000 (18:37 -0700)
commit297d750b9f8d7e6f2dbdf8abc5aa3b5c656affdc
treebd755d89f3c4d7f9c47751772aea2221761d76a2
parentf64d5ca868214f9beb60108c82fcb96940132bfb
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>
fs/btrfs/extent-tree.c
fs/btrfs/inode.c
fs/btrfs/qgroup.c
fs/btrfs/qgroup.h