This is a note to let you know that I've just added the patch titled xfs: attach dquots and reserve quota blocks during unwritten conversion to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xfs-attach-dquots-and-reserve-quota-blocks-during-unwritten-conversion.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Mon Sep 26 08:48:28 AM CEST 2022 From: Chandan Babu R <chandan.babu@xxxxxxxxxx> Date: Sat, 24 Sep 2022 18:26:44 +0530 Subject: xfs: attach dquots and reserve quota blocks during unwritten conversion To: gregkh@xxxxxxxxxxxxxxxxxxx Cc: sashal@xxxxxxxxxx, mcgrof@xxxxxxxxxx, linux-xfs@xxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx, djwong@xxxxxxxxxx, chandan.babu@xxxxxxxxxx, amir73il@xxxxxxxxx, leah.rumancik@xxxxxxxxx Message-ID: <20220924125656.101069-8-chandan.babu@xxxxxxxxxx> From: "Darrick J. Wong" <darrick.wong@xxxxxxxxxx> 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@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Acked-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Chandan Babu R <chandan.babu@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/xfs/xfs_iomap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -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. */ Patches currently in stable-queue which might be from chandan.babu@xxxxxxxxxx are queue-5.4/xfs-refactor-agfl-length-computation-function.patch queue-5.4/xfs-use-bitops-interface-for-buf-log-item-ail-flag-check.patch queue-5.4/xfs-fix-an-abba-deadlock-in-xfs_rename.patch queue-5.4/maintainers-add-chandan-as-xfs-maintainer-for-5.4.y.patch queue-5.4/xfs-split-the-sunit-parameter-update-into-two-parts.patch queue-5.4/xfs-slightly-tweak-an-assert-in-xfs_fs_map_blocks.patch queue-5.4/xfs-fix-use-after-free-when-aborting-corrupt-attr-inactivation.patch queue-5.4/xfs-stabilize-insert-range-start-boundary-to-avoid-cow-writeback-race.patch queue-5.4/iomap-iomap-that-extends-beyond-eof-should-be-marked-dirty.patch queue-5.4/xfs-constify-the-buffer-pointer-arguments-to-error-functions.patch queue-5.4/xfs-attach-dquots-and-reserve-quota-blocks-during-unwritten-conversion.patch queue-5.4/xfs-range-check-ri_cnt-when-recovering-log-items.patch queue-5.4/xfs-fix-deadlock-between-agi-and-agf-when-target_ip-exists-in-xfs_rename.patch queue-5.4/xfs-replace-eio-with-efscorrupted-for-corrupt-metadata.patch queue-5.4/xfs-convert-eio-to-efscorrupted-when-log-contents-are-invalid.patch queue-5.4/xfs-add-missing-assert-in-xfs_fsmap_owner_from_rmap.patch queue-5.4/xfs-always-log-corruption-errors.patch queue-5.4/xfs-fix-some-memory-leaks-in-log-recovery.patch queue-5.4/xfs-don-t-commit-sunit-swidth-updates-to-disk-if-that-would-cause-repair-failures.patch