Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp155895pxf; Wed, 17 Mar 2021 01:42:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqbiglpOSLIOYOuYjNq2an9/30kqWwo9llJ73NucE5zzTF2n58I7V2xDI7JNPV+5pUnE2b X-Received: by 2002:a17:906:5611:: with SMTP id f17mr34605747ejq.208.1615970564355; Wed, 17 Mar 2021 01:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615970564; cv=none; d=google.com; s=arc-20160816; b=J5qEJ2NvI8iuiPioH2jGe1DsyeiGNqU5AjpDBsklNv7q/JeyUr/rVmNRAjDeMZzLUe lOAgT4u03ryzyPyEQR7L76+YBBhrBZduI+V2iOwmOan/o4d4Expim7it6nWei+0y1Z8V NPEWQUKSRkvnLmCArPUC3MqfSBM3qS2X/rMnFrFBwoCeAkO6WD2MyuNGP2QjWUYGhd0E ar1tTq2ptEOKRrJvAQQCxLgEPvmGzcXZspXBbGDJ5VhO1koCYeaQFtE62uhcOqxzbIcl DVdIcW0ygP7P72MvLTqGIc3IoDiO0X/43lUInohbvbe8LJMSy6z+REWErRpo8HCzaSmt /qWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:message-id:cc:to:subject:from; bh=H9+jL35GudIabIcrkEKz8r/LRVBSRc5GTFrVwU7cHSs=; b=bIpYxsESf0kO8KrYWFtn/HgLgrj9AZ2e+6BzwvUUj0Om5A34+4ztis4ettSX+y0tSb rtFN/MXWz7w5ykXPBqkxczILUFPbLoS3nSIlBj1vfYe5IrrRXjPTuDrlb6st0ITe/ceS sGgGYfVRAk3TW1z74wcFBTdAwKYExluSXUQtqylZvFc0xSh+UhRtkH43+9tNlZXZLBpw K3vYbpAile8AfM6dqWacmyrEom0gLVNtn/75iW5zJkcb4ITPVqiVIJTzENTOZwtBSA/k XvmnN0fIUYkek0pGU5gisgA4hG2I9b5f+y7kYgPRfIdnl8TwVUjpN/9VmLTPe3ccZvDZ uzSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss27si16468708ejb.322.2021.03.17.01.42.21; Wed, 17 Mar 2021 01:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbhCQIlD (ORCPT + 99 others); Wed, 17 Mar 2021 04:41:03 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14076 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbhCQIkl (ORCPT ); Wed, 17 Mar 2021 04:40:41 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F0k716RFCz17M3p; Wed, 17 Mar 2021 16:37:33 +0800 (CST) Received: from [10.174.177.93] (10.174.177.93) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Wed, 17 Mar 2021 16:39:20 +0800 From: Haotian Li Subject: [PATCH v3] e2fsck: Avoid changes on recovery flags when jbd2_journal_recover() failed To: Ext4 Developers List CC: "Theodore Y. Ts'o" , "harshad shirwadkar," , "liuzhiqiang (I)" , linfeilong , Message-ID: <05892183-327b-837c-c81c-da920db77e00@huawei.com> Date: Wed, 17 Mar 2021 16:39:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.93] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org jbd2_journal_recover() may fail when some error occers such as ENOMEM and EIO. However, jsb->s_start is still cleared by func e2fsck_journal_release(). This may break consistency between metadata and data in disk. Sometimes, failure in jbd2_journal_recover() is temporary but retry e2fsck will skip the journal recovery when the temporary problem is fixed. Following harshad shirwadkar's suggestion??we add an option "recovery_error_behavior" with default value "continue" to e2fsck.conf. User may set it to "retry" or "exit" to adopt different behavior when such journal recovery errors occur. Reported-by: Liangyun Signed-off-by: Haotian Li Signed-off-by: Zhiqiang Liu Reviewed-by: Harshad Shirwadkar --- e2fsck/e2fsck.h | 11 +++++++++++ e2fsck/journal.c | 33 +++++++++++++++++++++++++++++++-- e2fsck/unix.c | 13 ++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 15d043ee..22f9ad11 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -451,6 +451,9 @@ struct e2fsck_struct { /* Fast commit replay state */ struct e2fsck_fc_replay_state fc_replay_state; + + /* Behavior when journal recovery fails */ + int recovery_error_behavior; }; /* Data structures to evaluate whether an extent tree needs rebuilding. */ @@ -474,6 +477,14 @@ typedef struct region_struct *region_t; extern int e2fsck_strnlen(const char * s, int count); #endif +/* Different behaviors when journal recovery fails */ +#define RECOVERY_ERROR_CONTINUE 0 +#define RECOVERY_ERROR_RETRY 1 +#define RECOVERY_ERROR_EXIT 2 + +/* Journal retry times if RECOVERY_ERROR_RETRY is set*/ +#define RECOVERY_TIMES_LIMIT 3 + /* * Procedure declarations */ diff --git a/e2fsck/journal.c b/e2fsck/journal.c index a425bbd1..c1c6f6ee 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -1600,11 +1600,26 @@ no_has_journal: return retval; } +static void set_recovery_error_behavior(e2fsck_t ctx, const char *recovery_behavior) +{ + if (!recovery_behavior) { + ctx->recovery_error_behavior = RECOVERY_ERROR_CONTINUE; + return; + } + if (strcmp(recovery_behavior, "retry") == 0) + ctx->recovery_error_behavior = RECOVERY_ERROR_RETRY; + else if (strcmp(recovery_behavior, "exit") == 0) + ctx->recovery_error_behavior = RECOVERY_ERROR_EXIT; + else + ctx->recovery_error_behavior = RECOVERY_ERROR_CONTINUE; +} + static errcode_t recover_ext3_journal(e2fsck_t ctx) { struct problem_context pctx; journal_t *journal; errcode_t retval; + char *recovery_behavior = 0; clear_problem_context(&pctx); @@ -1629,8 +1644,12 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx) goto errout; retval = -jbd2_journal_recover(journal); - if (retval) + if (retval) { + profile_get_string(ctx->profile, "options", "recovery_error_behavior", + 0, "continue", &recovery_behavior); + set_recovery_error_behavior(ctx, recovery_behavior); goto errout; + } if (journal->j_failed_commit) { pctx.ino = journal->j_failed_commit; @@ -1645,7 +1664,15 @@ errout: jbd2_journal_destroy_revoke(journal); jbd2_journal_destroy_revoke_record_cache(); jbd2_journal_destroy_revoke_table_cache(); - e2fsck_journal_release(ctx, journal, 1, 0); + if (retval == 0 || ctx->recovery_error_behavior == RECOVERY_ERROR_CONTINUE) + e2fsck_journal_release(ctx, journal, 1, 0); + if (retval && ctx->recovery_error_behavior == RECOVERY_ERROR_EXIT) { + ctx->fs->flags &= ~EXT2_FLAG_VALID; + com_err(ctx->program_name, 0, + _("Journal recovery failed " + "on %s\n"), ctx->device_name); + fatal_error(ctx, 0); + } return retval; } @@ -1697,6 +1724,8 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx) /* Set the superblock flags */ e2fsck_clear_recover(ctx, recover_retval != 0); + if (recover_retval != 0 && ctx->recovery_error_behavior == RECOVERY_ERROR_RETRY) + ext2fs_set_feature_journal_needs_recovery(ctx->fs->super); /* * Do one last sanity check, and propagate journal->s_errno to diff --git a/e2fsck/unix.c b/e2fsck/unix.c index c5f9e441..2c605bff 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1068,6 +1068,8 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) if (c) ctx->options |= E2F_OPT_ICOUNT_FULLMAP; + ctx->recovery_error_behavior = RECOVERY_ERROR_CONTINUE; + if (ctx->readahead_kb == ~0ULL) { profile_get_integer(ctx->profile, "options", "readahead_mem_pct", 0, -1, &c); @@ -1776,6 +1778,7 @@ failure: "doing a read-only filesystem check.\n")); io_channel_flush(ctx->fs->io); } else { + int recovery_retry_times = 0; if (ctx->flags & E2F_FLAG_RESTARTED) { /* * Whoops, we attempted to run the @@ -1788,7 +1791,15 @@ failure: "on %s\n"), ctx->device_name); fatal_error(ctx, 0); } - retval = e2fsck_run_ext3_journal(ctx); + while (recovery_retry_times++ < RECOVERY_TIMES_LIMIT) { + retval = e2fsck_run_ext3_journal(ctx); + if (retval && ctx->recovery_error_behavior == RECOVERY_ERROR_RETRY) { + log_out(ctx, _("Try to recovery Journal again in %s\n"), + ctx->device_name); + } else { + break; + } + } if (retval == EFSBADCRC) { log_out(ctx, _("Journal checksum error " "found in %s\n"), -- 2.23.0