1From 491c2dea43a9c9f33c5feb9ccd9b91d04a24b6f7 Mon Sep 17 00:00:00 2001 2From: Haotian <lihaotian9@huawei.com> 3Date: Wed, 17 Mar 2021 17:34:14 +0800 4Subject: [PATCH] e2fsck: add env param E2FS_UNRELIABLE_IO to fix 5 unreliable io case 6 7Func write_primary_superblock() has two way to wirte disk. One is 1k block, 8the other is byte by byte as default. On unreliable IO case such as flaky 9network, the byte-by-byte method may lost some data of ext4-superblock. 10Then, the superblock may lose consistency and the sb checksum error will 11occur. 12 13We provide the env param E2FS_UNRELIABLE_IO for users to choose if it's 14necessary to take 1k block way on writing disk. 15 16Fix issue:https://gitee.com/src-openeuler/e2fsprogs/issues/I4RZVX?from=project-issue 17 18Signed-off-by: Haotian Li <lihaotian9@huawei.com> 19Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> 20--- 21 lib/ext2fs/closefs.c | 3 ++- 22 1 file changed, 2 insertions(+), 1 deletion(-) 23 24diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c 25index 1d4d5b7..1893fb6 100644 26--- a/lib/ext2fs/closefs.c 27+++ b/lib/ext2fs/closefs.c 28@@ -195,8 +195,9 @@ static errcode_t write_primary_superblock(ext2_filsys fs, 29 __u16 *old_super, *new_super; 30 int check_idx, write_idx, size; 31 errcode_t retval; 32+ int is_unreliable_io = getenv("E2FS_UNRELIABLE_IO") ? 1 : 0; 33 34- if (!fs->io->manager->write_byte || !fs->orig_super) { 35+ if (!fs->io->manager->write_byte || !fs->orig_super || is_unreliable_io) { 36 fallback: 37 io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET); 38 retval = io_channel_write_blk64(fs->io, 1, -SUPERBLOCK_SIZE, 39-- 402.21.1 (Apple Git-122.3) 41 42