diff mbox series

[9/9] btrfs: free qgroup rsv on io failure

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

Commit Message

Boris Burkov May 3, 2023, 12:59 a.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.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/ordered-data.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index a9778a91511e..e6803587a13c 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -426,8 +426,12 @@  void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode,
 			entry->bytes_left -= len;
 		}
 
-		if (!uptodate)
+		if (!uptodate) {
 			set_bit(BTRFS_ORDERED_IOERR, &entry->flags);
+			btrfs_qgroup_free_refroot(fs_info, inode->root->root_key.objectid,
+						  entry->qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
+			entry->qgroup_rsv = 0;
+		}
 
 		/*
 		 * All the IO of the ordered extent is finished, we need to queue