Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1361823ybl; Tue, 3 Dec 2019 06:06:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxiIL70gkre4wTG5S8rq/Y3CoVGegNUrVe68POqTLu2I87Uq8xqiyxWzWjsCm5gZ+cUpWW9 X-Received: by 2002:a05:6830:14d3:: with SMTP id t19mr3308925otq.278.1575381996032; Tue, 03 Dec 2019 06:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575381996; cv=none; d=google.com; s=arc-20160816; b=Nr41+1sq/E2ZP4nYifHWR03NPpT5lNhl5e8FjozL/m53WEqqMloZ6TaCnqcruTOC1a C5e3A+VZ6+qbOtKv8C16NyKD4PZvGQgFD0c4Jpw8qZuzX0iEkDfSpTImTQu1Qd8CtUsN TSS3wNvU/nZPwjLm8WJkf8712HRVjg6gSlMGps2+o8HkOh4Tj9cDRYm/k9ksUT8+179I dqzNRblGKiV62d2r8CK28kJ9D1lGwrb3UAkGMhhvkVdeAKjPE0iQp1V3FXHbGy5uK3we /kR+kfi7Z5ermCaK87mc95YgaPLtGWXyBpK5fA63tLehjBeV5ZetzJxBdMLiw8HZLdlI LULg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=iRKH5l5yKQl7Q8HDiyf8l1rbbfV/pVJNkvuI+QFm5X4=; b=qB4wgtfPHBU5kxeNR/tOoT2HpUH4gYJYmAOB05h1Seq/4+c7OUkrsZrYLdrC3gNd8V LiFsoT5oVDX+xdC7SPLLlyhIMSljHKFbHT3Dpdj4DJCcpyJj1u/o6k6Ea+6zjcAExXtA dgeJbce0W1SJfizXgZGBldm6EFjeP8EGkRLb5nMmeV9cyAf6A6QkC/64DkA3/3kjo133 LUcnLbzjCcZGKPOAGBPey8sonxfNig8uypxlQLZxk20xkkHagRRfoqS3SgVhsG/jSx8D aY0MjiNF+wCiGx3/k0DNeKta0XN09RusIreKIgUx/vaoiappmiD5QIT9khu38FYG/WJl UeJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si1315471otq.141.2019.12.03.06.06.10; Tue, 03 Dec 2019 06:06:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726115AbfLCOGI (ORCPT + 99 others); Tue, 3 Dec 2019 09:06:08 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:56724 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726098AbfLCOGI (ORCPT ); Tue, 3 Dec 2019 09:06:08 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id BAF78FE5C9ED4561F2BD; Tue, 3 Dec 2019 22:06:05 +0800 (CST) Received: from [127.0.0.1] (10.173.220.179) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Tue, 3 Dec 2019 22:05:56 +0800 Subject: Re: [PATCH v2 3/4] Partially revert "ext4: pass -ESHUTDOWN code to jbd2 layer" To: Jan Kara CC: , , , , , References: <20191203092756.26129-1-yi.zhang@huawei.com> <20191203092756.26129-4-yi.zhang@huawei.com> <20191203122312.GD8206@quack2.suse.cz> From: "zhangyi (F)" Message-ID: <982c155e-1495-5a8f-70c4-41da7e047e12@huawei.com> Date: Tue, 3 Dec 2019 22:05:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191203122312.GD8206@quack2.suse.cz> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.220.179] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 2019/12/3 20:23, Jan Kara wrote: > On Tue 03-12-19 17:27:55, zhangyi (F) wrote: >> This partially reverts commit fb7c02445c497943e7296cd3deee04422b63acb8. >> >> Commit fb7c02445c49 ("ext4: pass -ESHUTDOWN code to jbd2 layer") want to >> allow jbd2 layer to distinguish shutdown journal abort from other error >> cases, but this patch seems unnecessary because we distinguished those >> cases well through a zero errno parameter when shutting down, thus the >> jbd2 aborting peocess will not record the errno. So partially reverts >> this commit and keep the proper locking. >> >> Signed-off-by: zhangyi (F) > > Ted has written this so he'll have the definitive answer but I think the idea > of ESHUTDOWN is that if the filesystem was shutdown, we want ESHUTDOWN to > be recorded in the journal sb and not some other error. That's why there's > logic in __journal_abort_soft() making sure that ESHUTDOWN takes precedence > over any other error. Because it can happen that after EXT4_FLAGS_SHUTDOWN > flag is set, some other place records different error in journal > superblock before we get to jbd2_journal_abort() and record ESHUTDOWN... > Thanks for the explanation, I understand now, we need to prevent record errno in journal superblock and keep the filesystem just as it is after EXT4_FLAGS_SHUTDOWN is set. So there is a bug now because it only overwrite errno if it was 0, I will fix it together. Thanks, Yi > >> --- >> fs/ext4/ioctl.c | 4 ++-- >> fs/jbd2/journal.c | 22 +++++++--------------- >> 2 files changed, 9 insertions(+), 17 deletions(-) >> >> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c >> index 0b7f316fd30f..f99eeba5767d 100644 >> --- a/fs/ext4/ioctl.c >> +++ b/fs/ext4/ioctl.c >> @@ -597,13 +597,13 @@ static int ext4_shutdown(struct super_block *sb, unsigned long arg) >> set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); >> if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) { >> (void) ext4_force_commit(sb); >> - jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN); >> + jbd2_journal_abort(sbi->s_journal, 0); >> } >> break; >> case EXT4_GOING_FLAGS_NOLOGFLUSH: >> set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); >> if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) >> - jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN); >> + jbd2_journal_abort(sbi->s_journal, 0); >> break; >> default: >> return -EINVAL; >> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c >> index a78b07841080..f3f9e0b994ef 100644 >> --- a/fs/jbd2/journal.c >> +++ b/fs/jbd2/journal.c >> @@ -1475,14 +1475,11 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op) >> void jbd2_journal_update_sb_errno(journal_t *journal) >> { >> journal_superblock_t *sb = journal->j_superblock; >> - int errcode; >> >> lock_buffer(journal->j_sb_buffer); >> - errcode = journal->j_errno; >> - if (errcode == -ESHUTDOWN) >> - errcode = 0; >> - jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", errcode); >> - sb->s_errno = cpu_to_be32(errcode); >> + jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", >> + journal->j_errno); >> + sb->s_errno = cpu_to_be32(journal->j_errno); >> >> jbd2_write_superblock(journal, REQ_SYNC | REQ_FUA); >> } >> @@ -2100,20 +2097,15 @@ void __jbd2_journal_abort_hard(journal_t *journal) >> * but don't do any other IO. */ >> static void __journal_abort_soft (journal_t *journal, int errno) >> { >> - int old_errno; >> - >> write_lock(&journal->j_state_lock); >> - old_errno = journal->j_errno; >> - if (!journal->j_errno || errno == -ESHUTDOWN) >> - journal->j_errno = errno; >> - >> if (journal->j_flags & JBD2_ABORT) { >> write_unlock(&journal->j_state_lock); >> - if (!old_errno && old_errno != -ESHUTDOWN && >> - errno == -ESHUTDOWN) >> - jbd2_journal_update_sb_errno(journal); >> return; >> } >> + >> + if (!journal->j_errno) >> + journal->j_errno = errno; >> + >> write_unlock(&journal->j_state_lock); >> >> __jbd2_journal_abort_hard(journal); >> -- >> 2.17.2 >>