From: Alexey Kuznetsov <kuznet@virtuozzo.com>
To: devel@openvz.org, khorenko@virtuozzo.com, kui.liu@virtuozzo.com,
azaitsev@virtuozzo.com
Subject: [Devel] [PATCH hci-8.1 v2 4/5] fs/ext4: the swapext ioctl could fail with -ENOSPC and a jbd2 WARN
Date: Wed, 18 Nov 2026 01:00:26 +0800 [thread overview]
Message-ID: <avyIKgg5rngH5g5F@mops2> (raw)
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
reply other threads:[~2026-11-17 17:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avyIKgg5rngH5g5F@mops2 \
--to=kuznet@virtuozzo.com \
--cc=azaitsev@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=kui.liu@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.