ext4文件系统错误处理机制

更新时间:2023-05-23 09:15:22 阅读: 评论:0

ext4⽂件系统错误处理机制
ext4⽂件系统错误处理机制
4⽉ 23rd, 2013 | Filed under FileSystem发表评论
⽬前内核对ext4⽂件系统错误处理机制分为三种:1.不处理;2.内核panic;3.错误分区remount成只读形式。
处理机制的设定是在两个地⽅处理的,⼀个是在⽂件系统物理分区上设置,通过设置ext4⽂件系统分区的超级块中的“Errors
behavior”参数,可以配置错误处理⽅式,⼀般默认处理⽅式是Continue(不处理),具体配置通过tune2fs搞定:
oen@oen ~ $ sudo tune2fs -l /dev/sda3 | head -n 10
tune2fs 1.42.5 (29-Jul-2012)</pre>
Filesystem flags: signed_directory_hash
Default mount options: ur_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
oen@oen ~ $ sudo tune2fs -l /dev/sda3 | head -n 10
tune2fs 1.42.5 (29-Jul-2012)</pre>
Filesystem flags: signed_directory_hash
Default mount options: ur_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
另外⼀种⽅式则是通过配置mount参数搞定,参看man⼿册:
errors=continue / errors=remount-ro / errors=panic
Define the behaviour when an error is encountered. (Either ignore errors
and just mark the file system erroneous and continue, or remount the file
system read-only, or panic and halt the system.) The default is t in
the filesystem superblock, and can be changed using tune2fs(8).
errors=continue / errors=remount-ro / errors=panic
Define the behaviour when an error is encountered. (Either ignore errors
and just mark the file system erroneous and continue, or remount the fileantialiasing
system read-only, or panic and halt the system.) The default is t in
the filesystem superblock, and can be changed using tune2fs(8).
mount参数通常情况下在fstab中mount参数中直接设定,⼀般情况下服务器环境中的系统分区都是通过mount设置错误处理参数,⼀般都要设定为errors=panic,如此宁可让系统重启,让双机保持系统稳定,也不能让业务进程挂死在只读分区上。
但很多情况下,没有设置挂载参数,最后⽂件系统错误也导致了分区只读,具体就要分析内核的实现了。
⽂件系统问题出错最终都要有ext4_handle_error函数处理:
give me
static void ext4_handle_error(struct super_block *sb)
{
if (sb->s_flags & MS_RDONLY)
return;
if (!test_opt(sb, ERRORS_CONT)) {
journal_t *journal = EXT4_SB(sb)->s_journal;
pack it for me
EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
if (journal)
jbd2_journal_abort(journal, -EIO);
}
if (test_opt(sb, ERRORS_RO)) {
ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
sb->s_flags |= MS_RDONLY;
}
if (test_opt(sb, ERRORS_PANIC))
panic("EXT4-fs (device %s): panic forced after errorn",
dependentsb->s_id);
}
static void ext4_handle_error(struct super_block *sb)
{
if (sb->s_flags & MS_RDONLY)
return;
if (!test_opt(sb, ERRORS_CONT)) {
journal_t *journal = EXT4_SB(sb)->s_journal;
EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
if (journal)
jbd2_journal_abort(journal, -EIO);
}
if (test_opt(sb, ERRORS_RO)) {
ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
sb->s_flags |= MS_RDONLY;
}
if (test_opt(sb, ERRORS_PANIC))
体育教育考研panic("EXT4-fs (device %s): panic forced after errorn",
sb->s_id);
}
在代码第6⾏的判断中,如果系统默认不处理,则将journal置为aborted状态,然后结束;如果是挂载⽅式是只读,则将超级块的挂载标志位为MS_RDONLY;如果是panic,则打印panic告警并复位。
虽然系统默认不处理的情况下ext4_handle_error处理函数完美结束,但系统还在正常运⾏,如果系统需要对问题分区写⼊⼀些⽂件,此时IO会⾛JBD,获取handle原⼦操作,在ext4_journal_start_sb中判
断journal状态,如果是aborted,则进⼊ext4_abort。
journal = EXT4_SB(sb)->s_journal;
if (is_journal_aborted(journal)) {
ext4_abort(sb, __func__,
"Detected aborted journal");
return ERR_PTR(-EROFS);
}
journal = EXT4_SB(sb)->s_journal;
if (is_journal_aborted(journal)) {
ext4_abort(sb, __func__,
"Detected aborted journal");
翻译器中文翻英文
return ERR_PTR(-EROFS);
}
在ext4_abort中,如果分区状态不是只读,则将其分区置为只读。
void __ext4_abort(struct super_block *sb, )
{
if ((sb->s_flags & MS_RDONLY) == 0) {
ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
sb->s_flags |= MS_RDONLY;
EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
if (EXT4_SB(sb)->s_journal)
jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
save_error_info(sb, function, line);
}
if(test_opt(sb, ERRORS_PANIC))
panic("EXT4-fs panic from previous errorn");gct是什么
}
void__ext4_abort(struct super_block *sb, )
{
if((sb->s_flags & MS_RDONLY) == 0) {
ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
sb->s_flags |= MS_RDONLY;
EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
已知
if (EXT4_SB(sb)->s_journal)
jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
save_error_info(sb, function, line);
j开头的女英文名
}
dwfif(test_opt(sb, ERRORS_PANIC))
panic("EXT4-fs panic from previous errorn");
}
真正⼯作中,⽂件系统的读写次数⾮常⾼,如果挂着参数不是panic,则⽂件系统出现bug,内核会将其置为只读状态。—结束—

本文发布于:2023-05-23 09:15:22,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/119371.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:系统   分区   只读   处理   设置   参数   情况
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图