All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.1 v2 4/5] fs/ext4: the swapext ioctl could fail with -ENOSPC and a jbd2 WARN
@ 2026-11-17 17:00 Alexey Kuznetsov
  0 siblings, 0 replies; only message in thread
From: Alexey Kuznetsov @ 2026-11-17 17:00 UTC (permalink / raw)
  To: devel, khorenko, kui.liu, azaitsev

Cap amount of credits allocated for transaction handle
to avoid failure on large fragmented ranges.

Note, this fix is possible due to previous patch
"fs/ext4: ensure ext4 transaction credits while swapext",
which allows to split swapext over multiple transactions.

Note, this is not necessary for expose_one_extent(),
credits required always fit to the limit.

Fixes: 1a3d440e7fbc ("fs/ext4: swapext ioctl")
Affects: #VSTOR-155600
https://virtuozzo.atlassian.net/browse/VSTOR-155600

Signed-off-by: Alexey Kuznetsov <kuznet@virtuozzo.com>

Feature: ext4: swapext ioctl: swap range of blocks between two files
---
 fs/ext4/move_extent.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index cd07efaa1f30..b25f2865df89 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -728,6 +728,22 @@ swap_one_extent(struct file *o_filp, struct inode *donor_inode,
 	 * fragmented area, up to len pages.
 	 */
 	jblocks = ext4_chunk_trans_blocks(donor_inode, len) + nexts;
+	/*
+	 * nexts grows with fragmentation of the orig range and can exceed
+	 * the maximal handle size, then the handle cannot be started at all.
+	 * Cap it: ext4_swap_extents_2() checks credits before every pass but
+	 * the first one and returns -EAGAIN to continue in a new transaction.
+	 */
+	if (EXT4_SB(sb)->s_journal) {
+		journal_t *journal = EXT4_SB(sb)->s_journal;
+		int limit = (journal->j_max_transaction_buffers -
+			     journal->j_transaction_overhead_buffers) / 2;
+
+		jblocks = min(jblocks, limit);
+	}
+	/* The first pass is not checked, it must always be covered */
+	jblocks = max(jblocks, ext4_chunk_trans_blocks(donor_inode, 1) +
+			       ext4_chunk_trans_blocks(orig_inode, 1));
 	handle = ext4_journal_start(orig_inode, EXT4_HT_MOVE_EXTENTS, jblocks);
 	if (IS_ERR(handle)) {
 		*err = PTR_ERR(handle);
-- 
2.47.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17 17:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 17:00 [Devel] [PATCH hci-8.1 v2 4/5] fs/ext4: the swapext ioctl could fail with -ENOSPC and a jbd2 WARN Alexey Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.