diff mbox series

[v3,01/20] btrfs: free qgroup rsv on io failure

Message ID a260b7a8e02aa9deca066f9dcc53b2ba028f6d42.1689955162.git.boris@bur.io (mailing list archive)
State New, archived
Headers show
Series btrfs: simple quotas | expand

Commit Message

Boris Burkov July 21, 2023, 4:02 p.m. UTC
If we do a write whose bio suffers an error, we will never reclaim the
qgroup reserved space for it. We allocate the space in the write_iter
codepath, then release the reservation as we allocate the ordered
extent, but we only create a delayed ref if the ordered extent finishes.
If it has an error, we simply leak the rsv. This is apparent in running
any error injecting (dmerror) fstests like btrfs/146 or btrfs/160. Such
tests fail due to dmesg on umount complaining about the leaked qgroup
data space.

When we clean up other aspects of space on failed ordered_extents, also
free the qgroup rsv.

Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

David Sterba July 21, 2023, 11:09 p.m. UTC | #1
On Fri, Jul 21, 2023 at 09:02:06AM -0700, Boris Burkov wrote:
> If we do a write whose bio suffers an error, we will never reclaim the
> qgroup reserved space for it. We allocate the space in the write_iter
> codepath, then release the reservation as we allocate the ordered
> extent, but we only create a delayed ref if the ordered extent finishes.
> If it has an error, we simply leak the rsv. This is apparent in running
> any error injecting (dmerror) fstests like btrfs/146 or btrfs/160. Such
> tests fail due to dmesg on umount complaining about the leaked qgroup
> data space.
> 
> When we clean up other aspects of space on failed ordered_extents, also
> free the qgroup rsv.
> 
> Signed-off-by: Boris Burkov <boris@bur.io>
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>

This and patch 2 are fixes unrealted to squota so I'll merge them now,
they could have been sent separately. Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ebe70ed96f25..6daaa4fd69f2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3358,6 +3358,13 @@  int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 			btrfs_free_reserved_extent(fs_info,
 					ordered_extent->disk_bytenr,
 					ordered_extent->disk_num_bytes, 1);
+			/*
+			 * Actually free the qgroup rsv which was released when
+			 * the ordered extent was created.
+			 */
+			btrfs_qgroup_free_refroot(fs_info, inode->root->root_key.objectid,
+						  ordered_extent->qgroup_rsv,
+						  BTRFS_QGROUP_RSV_DATA);
 		}
 	}