aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ext4.h
diff options
context:
space:
mode:
authorBaokun Li <libaokun1@huawei.com>2025-01-22 19:41:26 +0800
committerTheodore Ts'o <tytso@mit.edu>2025-03-13 10:16:34 -0400
commit0a1b2f5ea98764221ccc1043b8dc27a8c0225476 (patch)
tree715683e257162a67e33521799ab6b1222823b72e /fs/ext4/ext4.h
parentext4: add EXT4_FLAGS_EMERGENCY_RO bit (diff)
downloadlinux-0a1b2f5ea98764221ccc1043b8dc27a8c0225476.tar.gz
linux-0a1b2f5ea98764221ccc1043b8dc27a8c0225476.zip
ext4: add ext4_emergency_state() helper function
Since both SHUTDOWN and EMERGENCY_RO are emergency states of the ext4 file system, and they are checked in similar locations, we have added a helper function, ext4_emergency_state(), to determine whether the current file system is in one of these two emergency states. Then, replace calls to ext4_forced_shutdown() with ext4_emergency_state() in those functions that could potentially trigger write operations. 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-4-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ext4.h')
-rw-r--r--fs/ext4/ext4.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 81cb16b5f8da..87a8282e5d86 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2252,6 +2252,15 @@ static inline int ext4_emergency_ro(struct super_block *sb)
return test_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags);
}
+static inline int ext4_emergency_state(struct super_block *sb)
+{
+ if (unlikely(ext4_forced_shutdown(sb)))
+ return -EIO;
+ if (unlikely(ext4_emergency_ro(sb)))
+ return -EROFS;
+ return 0;
+}
+
/*
* Default values for user and/or group using reserved blocks
*/