ext4: clear DISCARD flag if device does not support discard
authorDiangang Li <lidiangang@bytedance.com>
Tue, 11 Mar 2025 02:13:10 +0000 (10:13 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 18 Mar 2025 04:15:25 +0000 (00:15 -0400)
commit 79add3a3f795e ("ext4: notify when discard is not supported")
noted that keeping the DISCARD flag is for possibility that the underlying
device might change in future even without file system remount. However,
this scenario has rarely occurred in practice on the device side. Even if
it does occur, it can be resolved with remount. Clearing the DISCARD flag
not only prevents confusion caused by mount options but also avoids
sending unnecessary discard commands.

Signed-off-by: Diangang Li <lidiangang@bytedance.com>
Link: https://patch.msgid.link/20250311021310.669524-1-lidiangang@bytedance.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/super.c

index fec729bc287ed4720e3f9fe0dae8d6f30dc9ee53..4768770715cae56b060869659444f63e88be410f 100644 (file)
@@ -5620,9 +5620,11 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
                        goto failed_mount9;
        }
 
-       if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(sb->s_bdev))
+       if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(sb->s_bdev)) {
                ext4_msg(sb, KERN_WARNING,
                         "mounting with \"discard\" option, but the device does not support discard");
+               clear_opt(sb, DISCARD);
+       }
 
        if (es->s_error_count)
                mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */