ext4: add EXT4_FLAGS_EMERGENCY_RO bit
authorBaokun Li <libaokun1@huawei.com>
Wed, 22 Jan 2025 11:41:25 +0000 (19:41 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 13 Mar 2025 14:16:34 +0000 (10:16 -0400)
EXT4_FLAGS_EMERGENCY_RO Indicates that the current file system has become
read-only due to some error. Compared to SB_RDONLY, setting it does not
require a lock because we won't clear it, which avoids over-coupling with
vfs freeze. Also, add a helper function ext4_emergency_ro() to check if
the bit is set.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://patch.msgid.link/20250122114130.229709-3-libaokun@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h

index 8f6bfa25fa6f917daa44e7bf01c2d152a327541a..81cb16b5f8dac89722303737b20d3a996085b4bf 100644 (file)
@@ -2239,6 +2239,7 @@ enum {
        EXT4_FLAGS_RESIZING,    /* Avoid superblock update and resize race */
        EXT4_FLAGS_SHUTDOWN,    /* Prevent access to the file system */
        EXT4_FLAGS_BDEV_IS_DAX, /* Current block device support DAX */
+       EXT4_FLAGS_EMERGENCY_RO,/* Emergency read-only due to fs errors */
 };
 
 static inline int ext4_forced_shutdown(struct super_block *sb)
@@ -2246,6 +2247,11 @@ static inline int ext4_forced_shutdown(struct super_block *sb)
        return test_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags);
 }
 
+static inline int ext4_emergency_ro(struct super_block *sb)
+{
+       return test_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags);
+}
+
 /*
  * Default values for user and/or group using reserved blocks
  */