Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 13/23] ext4: propagate ext4_alloc_group_tables() errors from ext4_resize_fs()
Date: Wed, 11 Nov 2026 23:47:02 -0500	[thread overview]
Message-ID: <20261112044712.1577296-14-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>

When ext4_alloc_group_tables() cannot place the bitmaps and inode
tables of the next flex group, ext4_resize_fs() just breaks out of its
loop without recording the error.  err is still 0 (from its
initialization or from the previous successful ext4_flex_group_add()),
so:

 - EXT4_IOC_RESIZE_FS returns success to resize2fs although the file
   system was not grown to the requested size, and

 - if the first pass was capped by the reserved GDT blocks
   (n_blocks_count_retry != 0), the "!err && n_blocks_count_retry" test
   jumps back to retry and carries on as if nothing had happened.

Ignoring the failure was introduced to avoid a BUG_ON() when the last
block group was too small for its metadata.  That case has since been
handled up front by trimming such a final group in ext4_resize_fs()
(commit f0a459dec549 ("ext4: fix online resize's handling of a
too-small final block group")), so a failure here is a real error that
should be reported.  Store the return value in err.

Fixes: 03c1c29053f6 ("ext4: ignore last group w/o enough space when resizing instead of BUG'ing")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/resize-test.c | 24 ++++++++++++++++++++++++
 fs/ext4/resize.c      |  3 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/resize-test.c b/fs/ext4/resize-test.c
index 4a08a47b3481..0fd097d58a59 100644
--- a/fs/ext4/resize-test.c
+++ b/fs/ext4/resize-test.c
@@ -1408,6 +1408,29 @@ static void test_resize_fs_flex_group_straddles_first_meta_bg(struct kunit *test
 			  ext4_group_first_block_no(sb, 49) + 2));
 }
 
+/*
+ * Test 10: ext4_resize_fs() must report a failure of ext4_alloc_group_tables()
+ * instead of returning success without growing the file system.  With one
+ * reserved GDT block, sparse group 3 has 1021 usable blocks, which cannot
+ * hold two bitmaps plus a 1020-block inode table.
+ */
+static void test_resize_fs_alloc_group_tables_enospc(struct kunit *test)
+{
+	struct resize_test_ctx *ctx = test->priv;
+	struct super_block *sb = ctx->sb;
+	ext4_fsblk_t o_blks, target_blks;
+
+	resize_configure_fs(test, 3, 1, 0, RESIZE_TEST_BLOCKS_PER_GRP);
+	ctx->sbi.s_itb_per_group = 1020;
+	o_blks = ext4_blocks_count(ctx->es);
+	target_blks = RESIZE_TEST_FIRST_DATA_BLK +
+		      5ULL * RESIZE_TEST_BLOCKS_PER_GRP;
+
+	KUNIT_EXPECT_EQ(test, ext4_resize_fs(sb, target_blks), -ENOSPC);
+	KUNIT_EXPECT_EQ(test, ctx->sbi.s_groups_count, 3U);
+	KUNIT_EXPECT_EQ(test, ext4_blocks_count(ctx->es), o_blks);
+}
+
 static struct kunit_case ext4_resize_test_cases[] = {
 	KUNIT_CASE(test_resize_begin_and_end_guards),
 	KUNIT_CASE(test_list_backups_and_verify_reserved_gdb),
@@ -1418,6 +1441,7 @@ static struct kunit_case ext4_resize_test_cases[] = {
 	KUNIT_CASE(test_convert_meta_bg_validation_and_conversion),
 	KUNIT_CASE(test_resize_fs_across_resize_inode_to_meta_bg),
 	KUNIT_CASE(test_resize_fs_flex_group_straddles_first_meta_bg),
+	KUNIT_CASE(test_resize_fs_alloc_group_tables_enospc),
 	{}
 };
 
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 5e3b4e9f99f8..d3507b175382 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -2190,7 +2190,8 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 					 ext4_blocks_count(es));
 			last_update_time = jiffies;
 		}
-		if (ext4_alloc_group_tables(sb, flex_gd, flexbg_size) != 0)
+		err = ext4_alloc_group_tables(sb, flex_gd, flexbg_size);
+		if (err)
 			break;
 		err = ext4_flex_group_add(sb, resize_inode, flex_gd);
 		if (unlikely(err))
-- 
2.56.0.542.g3ef89b7020-goog


  parent reply	other threads:[~2026-11-12  4:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:46 [PATCH 00/23] ext4: lots of misc bug fixes Theodore Ts'o
2026-11-12  4:46 ` [PATCH 01/23] ext4: only update s_mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is set Theodore Ts'o
2026-11-12  4:46 ` [PATCH 02/23] ext4: return -EFSBADCRC when skipping a corrupt backup superblock Theodore Ts'o
2026-11-12  4:46 ` [PATCH 03/23] ext4: don't allow enabling casefold via EXT4_IOC_SET_TUNE_SB_PARAM Theodore Ts'o
2026-11-12  4:46 ` [PATCH 04/23] ext4: persist the htree hash seed when enabling dir_index online Theodore Ts'o
2026-11-12  4:46 ` [PATCH 05/23] ext4: enforce feature prerequisites when tuning a mounted fs Theodore Ts'o
2026-11-12  4:46 ` [PATCH 06/23] ext4: handle s_lastcheck_hi in the get/set tune superblock ioctls Theodore Ts'o
2026-11-12  4:46 ` [PATCH 07/23] ext4: pass missing ioctls through ext4_compat_ioctl Theodore Ts'o
2026-11-12  4:46 ` [PATCH 08/23] ext4: fix inverted err_report_sec check in ext4_update_super() Theodore Ts'o
2026-11-12  4:46 ` [PATCH 09/23] ext4: fix err_report_sec_store() timer and value handling Theodore Ts'o
2026-11-12  4:46 ` [PATCH 10/23] ext4: fix inode table accounting in count_overhead() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 11/23] ext4: handle flex groups straddling s_first_meta_bg in online resize Theodore Ts'o
2026-11-12  4:47 ` [PATCH 12/23] ext4: reject EXT4_IOC_GROUP_ADD inputs larger than a block group Theodore Ts'o
2026-11-12  4:47 ` Theodore Ts'o [this message]
2026-11-12  4:47 ` [PATCH 14/23] ext4: reject online shrink before probing the device size Theodore Ts'o
2026-11-12  4:47 ` [PATCH 15/23] ext4: cap migrated extents at EXT_INIT_MAX_LEN Theodore Ts'o
2026-11-12  4:47 ` [PATCH 16/23] ext4: don't treat a handle restart as an error in finish_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 17/23] ext4: don't clobber the migration result in ext4_ext_migrate() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 18/23] ext4: fix EOF clamping of the range in mext_check_adjust_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 19/23] ext4: bound the MMP update and check intervals Theodore Ts'o
2026-11-12  4:47 ` [PATCH 20/23] ext4: fix MMP claim of a cleanly unmounted filesystem Theodore Ts'o
2026-11-12  4:47 ` [PATCH 21/23] ext4: fix device comparison overflow in ext4_getfsmap_dev_compare() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 22/23] ext4: don't allocate over indirect branches that failed to load Theodore Ts'o
2026-11-12  4:47 ` [PATCH 23/23] ext4: don't stop EXT4_IOC_GET_ES_CACHE at uncached ranges Theodore Ts'o

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=20261112044712.1577296-14-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox