aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2020-05-17 23:05:11 -0400
committerTheodore Ts'o <tytso@mit.edu>2020-05-17 23:05:11 -0400
commit6338a8467564c3a0a12e9fcb08bdd748d736ac2f (patch)
treecd2511da350e0e1ef27c8d8c29fabdf8c15dc947
parent86d6153417ddaccbe3d1f4466a374716006581f4 (diff)
downloade2fsprogs-6338a8467564c3a0a12e9fcb08bdd748d736ac2f.tar.gz
libext2fs: retry reading superblock on open when checksum is bad
When opening a file system which is mounted, it's possible that when ext2fs_open2() is racing with the kernel modifying the orphaned inode list, the superblock's checksum could be incorrect. So retry reading the superblock in the hopes that the problem will self-correct. Google-Bug-Id: 151453112 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--lib/ext2fs/openfs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 51b54a449..ae54870e5 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -134,6 +134,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
int j;
#endif
char *time_env;
+ int csum_retries = 0;
EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER);
@@ -221,6 +222,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
if (retval)
goto cleanup;
}
+retry:
retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE,
fs->super);
if (retval)
@@ -232,8 +234,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
retval = 0;
if (!ext2fs_verify_csum_type(fs, fs->super))
retval = EXT2_ET_UNKNOWN_CSUM;
- if (!ext2fs_superblock_csum_verify(fs, fs->super))
+ if (!ext2fs_superblock_csum_verify(fs, fs->super)) {
+ if (csum_retries++ < 3)
+ goto retry;
retval = EXT2_ET_SB_CSUM_INVALID;
+ }
}
#ifdef WORDS_BIGENDIAN