]> git.itanic.dy.fi Git - linux-stable/commitdiff
xfs: attach dquots and reserve quota blocks during unwritten conversion
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 24 Sep 2022 12:56:44 +0000 (18:26 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2022 09:04:10 +0000 (11:04 +0200)
commit 2815a16d7ff6230a8e37928829d221bb075aa160 upstream.

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/xfs_iomap.c

index 26cf811f3d962f5af12cfe3197688965b1f665ff..b6f85e488d5c133c08772040537182c3abaa604b 100644 (file)
@@ -765,6 +765,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
@@ -783,6 +788,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.
                 */