diff mbox series

[2/3] xfs: attach dquots and reserve quota blocks during unwritten conversion

Message ID 157343510780.1948946.16275987302017348487.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs: various fixes | expand

Commit Message

Darrick J. Wong Nov. 11, 2019, 1:18 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

In xfs_iomap_write_unwritten, we need to ensure that dquots are attached
to the inode and quota blocks reserved so that we capture in the quota
counters any blocks allocated to handle a bmbt split.  This can happen
on the first unwritten extent conversion to a preallocated sparse file
on a fresh mount.

This was found by running generic/311 with quotas enabled.  The bug
seems to have been introduced in "[XFS] rework iocore infrastructure,
remove some code and make it more" from ~2002?

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_iomap.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Christoph Hellwig Nov. 11, 2019, 7:59 a.m. UTC | #1
On Sun, Nov 10, 2019 at 05:18:27PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In xfs_iomap_write_unwritten, we need to ensure that dquots are attached
> to the inode and quota blocks reserved so that we capture in the quota
> counters any blocks allocated to handle a bmbt split.  This can happen
> on the first unwritten extent conversion to a preallocated sparse file
> on a fresh mount.
> 
> This was found by running generic/311 with quotas enabled.  The bug
> seems to have been introduced in "[XFS] rework iocore infrastructure,
> remove some code and make it more" from ~2002?

Wow.  The fix looks correct, but I can't see how we got away with that
for so long..

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index f234929b4f15..97dbe3b2aec0 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -539,6 +539,11 @@  xfs_iomap_write_unwritten(
 	 */
 	resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
 
+	/* Attach dquots so that bmbt splits are accounted correctly. */
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		return error;
+
 	do {
 		/*
 		 * Set up a transaction to convert the range of extents
@@ -557,6 +562,11 @@  xfs_iomap_write_unwritten(
 		xfs_ilock(ip, XFS_ILOCK_EXCL);
 		xfs_trans_ijoin(tp, ip, 0);
 
+		error = xfs_trans_reserve_quota_nblks(tp, ip, resblks, 0,
+				XFS_QMOPT_RES_REGBLKS);
+		if (error)
+			goto error_on_bmapi_transaction;
+
 		/*
 		 * Modify the unwritten extent state of the buffer.
 		 */