From 79cc33628256e817610e921ddf600f72e4f879e1 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Fri, 10 Oct 2008 17:14:08 -0500 Subject: [PATCH] e2fsck: exit from preenhalt if IO errors were encountered If a block device is read-only, e2fsck -p gets into an infinite loop trying to preenhalt, closing and flushing the fs, which tries to flush the cache, which gets a write error and calls preenhalt which tries to close and flush the fs ... ad infinitum. Per Ted's suggestion just flag the ctx as "exiting" and short-circuit the infinite loop. Tested by running e2fsck -p on a block device set read-only by BLKROSET. Thanks to Vlado Potisk for reporting this. Addresses-Red-Hat-Bugzilla: #465679 Signed-off-by: Eric Sandeen Signed-off-by: Theodore Ts'o --- e2fsck/e2fsck.h | 1 + e2fsck/ehandler.c | 5 ++++- e2fsck/util.c | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 53c8f54..9833248 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -174,6 +174,7 @@ struct resource_track { #define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */ #define E2F_FLAG_RESIZE_INODE 0x0400 /* Request to recreate resize inode */ #define E2F_FLAG_GOT_DEVSIZE 0x0800 /* Device size has been fetched */ +#define E2F_FLAG_EXITING 0x1000 /* E2fsck exiting due to errors */ /* * Defines for indicating the e2fsck pass number diff --git a/e2fsck/ehandler.c b/e2fsck/ehandler.c index 7bae4ab..f9021f0 100644 --- a/e2fsck/ehandler.c +++ b/e2fsck/ehandler.c @@ -33,7 +33,8 @@ static errcode_t e2fsck_handle_read_error(io_channel channel, e2fsck_t ctx; ctx = (e2fsck_t) fs->priv_data; - + if (ctx->flags & E2F_FLAG_EXITING) + return 0; /* * If more than one block was read, try reading each block * separately. We could use the actual bytes read to figure @@ -79,6 +80,8 @@ static errcode_t e2fsck_handle_write_error(io_channel channel, e2fsck_t ctx; ctx = (e2fsck_t) fs->priv_data; + if (ctx->flags & E2F_FLAG_EXITING) + return 0; /* * If more than one block was written, try writing each block diff --git a/e2fsck/util.c b/e2fsck/util.c index 256100c..efaea4d 100644 --- a/e2fsck/util.c +++ b/e2fsck/util.c @@ -257,6 +257,7 @@ void preenhalt(e2fsck_t ctx) fprintf(stderr, _("\n\n%s: UNEXPECTED INCONSISTENCY; " "RUN fsck MANUALLY.\n\t(i.e., without -a or -p options)\n"), ctx->device_name); + ctx->flags |= E2F_FLAG_EXITING; if (fs != NULL) { fs->super->s_state |= EXT2_ERROR_FS; ext2fs_mark_super_dirty(fs); -- 1.8.3.1