All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: Fariya F <fariya.fatima03@gmail.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	stable@kernel.org
Subject: [PATCH 2/3] ext4: force overhead calculation if the s_overhead_cluster makes no sense
Date: Thu, 14 Apr 2022 22:54:39 -0400	[thread overview]
Message-ID: <20220415025440.2342107-2-tytso@mit.edu> (raw)
In-Reply-To: <20220415025440.2342107-1-tytso@mit.edu>

If the file system does not use bigalloc, calculating the overhead is
cheap, so force the recalculation of the overhead so we don't have to
trust the precalculated overhead in the superblock.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
---
 fs/ext4/super.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 23a9b2c086ed..d08820fdfdee 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5289,9 +5289,18 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	 * Get the # of file system overhead blocks from the
 	 * superblock if present.
 	 */
-	if (es->s_overhead_clusters)
-		sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
-	else {
+	sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
+	/* ignore the precalculated value if it is ridiculous */
+	if (sbi->s_overhead > ext4_blocks_count(es))
+		sbi->s_overhead = 0;
+	/*
+	 * If the bigalloc feature is not enabled recalculating the
+	 * overhead doesn't take long, so we might as well just redo
+	 * it to make sure we are using the correct value.
+	 */
+	if (!ext4_has_feature_bigalloc(sb))
+		sbi->s_overhead = 0;
+	if (sbi->s_overhead == 0) {
 		err = ext4_calculate_overhead(sb);
 		if (err)
 			goto failed_mount_wq;
-- 
2.31.0


  reply	other threads:[~2022-04-15  2:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  6:42 df returns incorrect size of partition due to huge overhead block count in ext4 partition Fariya F
2022-03-25 22:11 ` Theodore Ts'o
2022-03-28 16:08   ` Fariya F
2022-03-29 13:08     ` Theodore Ts'o
2022-04-12  8:56       ` Fariya F
2022-04-15  2:54         ` [PATCH 1/3] ext4: fix overhead calculation to account for the reserved gdt blocks Theodore Ts'o
2022-04-15  2:54           ` Theodore Ts'o [this message]
2022-04-15  2:54           ` [PATCH 3/3] ext4: update the cached overhead value in the superblock Theodore Ts'o
2022-04-15 14:41         ` df returns incorrect size of partition due to huge overhead block count in ext4 partition 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=20220415025440.2342107-2-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=fariya.fatima03@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=stable@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 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.