Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3608291rwb; Tue, 8 Nov 2022 06:31:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM528dKVVoVJGoIIny6ydVsHv4TvFpkMZOwu7Olq7+603Sk7hGGKAGG6Wcj6A03lbqq34aWY X-Received: by 2002:a17:906:844b:b0:7a9:f67e:a5d4 with SMTP id e11-20020a170906844b00b007a9f67ea5d4mr52259397ejy.136.1667917873555; Tue, 08 Nov 2022 06:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667917873; cv=none; d=google.com; s=arc-20160816; b=TLc2OxxPBNSmDztmS1LmNPmUxQSjwhB/EcIO9ZGMh+g/OqZbM/PhBS4FfMiTSfxAq9 9mIldgcOmDyUTUcCTsTKWB0rspxZdEGnO96i4T8yLQNFUCso98hOpUSPXlPoRGuYi4xC yT95G4tuXnLRYiRFVEKK+W/1106ZavaPAkX8M7av6E60Gl97kWhD+ZI33uPyPIXJJyvg rc2dKXNVXfBZ/Lar3BRWb+ToGDc6nzQoOSe8ga/mvCNxNSjdj9Qc3gLQ07X0M3Qgg9d5 ZI4rZg74kdnwwHlvlxCX8KmWZ83ZeNSgRbwocGNOz92OBtQQw7j3y1wYoWOwWiMmi8lp QFMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wa8rpiFlbXkjV7d7D//ITAwfwBDluJGj5OKPJUa3dns=; b=t3Dghjmw7R5bgg4hMv/VMUUUFzQwo3rtBPsqCzt7MKclzps9Qp/a0omca8iM+KywHA ZMt30FZYkaF/4B0mA7SC3+EEvu8cMRvTPLkLG0ROHeZvoVTPbYgYKs1boJaGjbep+bod wkksSGuop5/b5rA/cB71CqrbjzJbH7cQrv2pLMVo2juQzEdHKWnEk6i5BeiaPS5dmWoj TVRlrZ/I85uqWinrCYX/oeNNtu85EM/7c0FEP+Q66CXgZ+HTkc7D+3Qy97TRy2auX8jg PZHteFgEJZef62Sc3a1rTl/5pZxnWRcjS8g9BC5lhAibbQdg9is/Unbv0E+STpPAWyUn 09wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho42-20020a1709070eaa00b007add5af39f6si13772509ejc.929.2022.11.08.06.30.48; Tue, 08 Nov 2022 06:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234515AbiKHO0y (ORCPT + 99 others); Tue, 8 Nov 2022 09:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234116AbiKHO0N (ORCPT ); Tue, 8 Nov 2022 09:26:13 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0808A5C743 for ; Tue, 8 Nov 2022 06:24:55 -0800 (PST) Received: from canpemm500005.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N69N92MfgzmV6l; Tue, 8 Nov 2022 22:24:41 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 22:24:53 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH 11/12] ext4: add journal related fault injection Date: Tue, 8 Nov 2022 22:46:16 +0800 Message-ID: <20221108144617.4159381-12-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108144617.4159381-1-yi.zhang@huawei.com> References: <20221108144617.4159381-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500005.china.huawei.com (7.192.104.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add journal start, getting create/write access, and dirty metadata fault injection. The journal start fault injections return -ENOMEM directly, other 3 injections will abort the journal and return -EROFS. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 12 ++++++++++++ fs/ext4/ext4_jbd2.c | 22 ++++++++++++++++------ fs/ext4/ext4_jbd2.h | 5 +++++ fs/ext4/sysfs.c | 5 +++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 813127cfd3c0..96b805992ea5 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1526,6 +1526,12 @@ enum ext4_fault_bits { EXT4_FAULT_DIRBLOCK_EIO, /* directory block */ EXT4_FAULT_XATTR_EIO, /* xattr block */ EXT4_FAULT_SYMLINK_EIO, /* symlink block */ + /* journal error */ + EXT4_FAULT_JOURNAL_START, /* journal start inode */ + EXT4_FAULT_JOURNAL_START_SB, /* journal start sb */ + EXT4_FAULT_JOURNAL_CREATE_ACCESS, /* journal get create access */ + EXT4_FAULT_JOURNAL_WRITE_ACCESS, /* journal get write access */ + EXT4_FAULT_JOURNAL_DIRTY_METADATA, /* journal dirty meta data */ EXT4_FAULT_MAX }; @@ -1633,6 +1639,12 @@ EXT4_FAULT_INODE_LBLOCK_FN(DIRBLOCK_EIO, dirblock_io, -EIO) EXT4_FAULT_INODE_FN(XATTR_EIO, xattr_io, -EIO) EXT4_FAULT_INODE_FN(SYMLINK_EIO, symlink_io, -EIO) +EXT4_FAULT_INODE_FN(JOURNAL_START, journal_start, -ENOMEM) +EXT4_FAULT_FN(JOURNAL_START_SB, journal_start_sb, -ENOMEM) +EXT4_FAULT_INODE_PBLOCK_FN(JOURNAL_CREATE_ACCESS, journal_create_access, -EROFS) +EXT4_FAULT_INODE_PBLOCK_FN(JOURNAL_WRITE_ACCESS, journal_write_access, -EROFS) +EXT4_FAULT_INODE_PBLOCK_FN(JOURNAL_DIRTY_METADATA, journal_dirty_metadata, -EROFS) + /* * fourth extended-fs super-block data in memory */ diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 8e1fb18f465e..e0972dea7463 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -95,6 +95,9 @@ handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line, trace_ext4_journal_start(sb, blocks, rsv_blocks, revoke_creds, _RET_IP_); + err = ext4_fault_journal_start_sb(sb); + if (err) + return ERR_PTR(err); err = ext4_journal_check_start(sb); if (err < 0) return ERR_PTR(err); @@ -232,7 +235,9 @@ int __ext4_journal_get_write_access(const char *where, unsigned int line, ext4_check_bdev_write_error(bh->b_bdev->bd_super); if (ext4_handle_valid(handle)) { - err = jbd2_journal_get_write_access(handle, bh); + err = ext4_fault_journal_write_access(sb, 0, bh->b_blocknr); + if (!err) + err = jbd2_journal_get_write_access(handle, bh); if (err) { ext4_journal_abort_handle(where, line, __func__, bh, handle, err); @@ -320,7 +325,9 @@ int __ext4_journal_get_create_access(const char *where, unsigned int line, if (!ext4_handle_valid(handle)) return 0; - err = jbd2_journal_get_create_access(handle, bh); + err = ext4_fault_journal_create_access(sb, 0, bh->b_blocknr); + if (!err) + err = jbd2_journal_get_create_access(handle, bh); if (err) { ext4_journal_abort_handle(where, line, __func__, bh, handle, err); @@ -338,7 +345,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, handle_t *handle, struct inode *inode, struct buffer_head *bh) { - int err = 0; + int err = 0, fa_err = 0; might_sleep(); @@ -346,9 +353,12 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, set_buffer_prio(bh); set_buffer_uptodate(bh); if (ext4_handle_valid(handle)) { - err = jbd2_journal_dirty_metadata(handle, bh); - /* Errors can only happen due to aborted journal or a nasty bug */ - if (!is_handle_aborted(handle) && WARN_ON_ONCE(err)) { + if (bh->b_bdev->bd_super) + fa_err = ext4_fault_journal_dirty_metadata(bh->b_bdev->bd_super, + 0, bh->b_blocknr); + if (!fa_err) + err = jbd2_journal_dirty_metadata(handle, bh); + if (!is_handle_aborted(handle) && (WARN_ON_ONCE(err) || fa_err)) { ext4_journal_abort_handle(where, line, __func__, bh, handle, err); if (inode == NULL) { diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index db2ae4a2b38d..b0a996f306bb 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -323,6 +323,11 @@ static inline handle_t *__ext4_journal_start(struct inode *inode, int blocks, int rsv_blocks, int revoke_creds) { + int err; + + err = ext4_fault_journal_start(inode->i_sb, inode->i_ino); + if (err) + return ERR_PTR(err); return __ext4_journal_start_sb(inode->i_sb, line, type, blocks, rsv_blocks, revoke_creds); } diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index aca91ab5b506..57deb90f3e42 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -585,6 +585,11 @@ char *ext4_fault_names[EXT4_FAULT_MAX] = { "dir_block_eio", /* EXT4_FAULT_DIRBLOCK_EIO */ "xattr_block_eio", /* EXT4_FAULT_XATTR_EIO */ "symlink_block_eio", /* EXT4_FAULT_SYMLINK_EIO */ + "journal_start", /* EXT4_FAULT_JOURNAL_START */ + "journal_start_sb", /* EXT4_FAULT_JOURNAL_START_SB */ + "journal_get_create_access", /* EXT4_FAULT_JOURNAL_CREATE_ACCESS */ + "journal_get_write_access", /* EXT4_FAULT_JOURNAL_WRITE_ACCESS */ + "journal_dirty_metadata", /* EXT4_FAULT_JOURNAL_DIRTY_METADATA */ }; static int ext4_fault_available_show(struct seq_file *m, void *v) -- 2.31.1