Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663436pxb; Tue, 5 Apr 2022 17:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxitsEbkcLjxqfpT+kw9pn2Q2AheZajCqU1udthLXuNCCXQA69Z5YxaDyKcsGt2m73upw6C X-Received: by 2002:a17:906:6a1a:b0:6e1:87a:151f with SMTP id qw26-20020a1709066a1a00b006e1087a151fmr5851227ejc.715.1649206252952; Tue, 05 Apr 2022 17:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206252; cv=none; d=google.com; s=arc-20160816; b=vg5ygbTNJq6NNA1PqHeFgNBN53JvMhKNFguADaZ129Ubkprw8Z3gmwSWN5GJ/1l5eZ ndh0A2S1NaDeO0R60Lw4tNfe8o8IBKUSG3rYdoxO3UjUceTiHEUUHQYgXBVjqTLJzPZJ h7XTmUanHXgGTVGj6o4ZGocvHyA3m2Bi+Mq+4eblBKLveJ/HcNOSgqF10CiGul+o5DVA atXx5b6KEsnDLbH54D+iSk1jvk9Z+fTGznHcBpSmjwAxgOeJkQkF3wv4JmrI4jpU+kJn EMdAlr8zBBPl6ReqZFLkLBM7B01G1OHZhH1Tsiixzm+ZqCQev/idZal47R2P4XzmQz/v hTBA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OuZDTenqbv5YKzm3SXwJ0WDf1hcEAxgu0WSYpqumhpA=; b=p6D7nC4r6MrqzFZVqozgHi4Xe14xFOM6QDkmNxx8f3GVhYR896rwr0FyE4nZpc4c7+ bERACmlvjUdi6PGh1pyUAyrp7bO/e2QcBSQO3K2ble0EhAlglq7oEK5FzIpN+dLWfMi2 Nz091aDUutrLW717BQa47soHuDaOJmCIe7TVCGQfJnmiXijmO/XRfPAdJ5a2AfNnYFnv j/C6euQp2AEbH/iqUfdpCQo0NzDFouFcn3zVWbysm9EHtOaDFudKElAMlkmwPPEfMKpe 1Hf/pMU8JMisBkZ5yYnTiO0gV8gkvZmym1rTOAB3WOlAnVJTQoNvQi8+pMz2XmXSs1Yx p7yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cwB1UwFd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t26-20020a1709060c5a00b006e7fc055cfasi4832762ejf.507.2022.04.05.17.50.27; Tue, 05 Apr 2022 17:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cwB1UwFd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237824AbiDENxm (ORCPT + 99 others); Tue, 5 Apr 2022 09:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345005AbiDEJWI (ORCPT ); Tue, 5 Apr 2022 05:22:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59F8266B; Tue, 5 Apr 2022 02:08:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C719361577; Tue, 5 Apr 2022 09:08:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D759CC385A2; Tue, 5 Apr 2022 09:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149738; bh=PSAWW/Nw9gcKd2tq0UOU4St9E3PTIIk5kU+nkR20mk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cwB1UwFdO2uXKMgun+88xp+r+A0gJy3B2GRI3nQYuRBz4xPt829sSgNdGRE9jDjVO 5InL9xjUj6/EdpxvDHCJ0Jae5xSj9glju7rGe9GY6mdIiiSoDiioGXS/RyHwZUULzb lIJvSI5Ui5o1YRQ1Nkt+R6VjZHQm8NLLcih3H0yU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.16 0796/1017] btrfs: handle csum lookup errors properly on reads Date: Tue, 5 Apr 2022 09:28:29 +0200 Message-Id: <20220405070417.878940354@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Josef Bacik [ Upstream commit 1784b7d502a94b561eae58249adde5f72c26eb3c ] Currently any error we get while trying to lookup csums during reads shows up as a missing csum, and then on the read completion side we print an error saying there was a csum mismatch and we increase the device corruption count. However we could have gotten an EIO from the lookup. We could also be inside of a memory constrained container and gotten a ENOMEM while trying to do the read. In either case we don't want to make this look like a file system corruption problem, we want to make it look like the actual error it is. Capture any negative value, convert it to the appropriate blk_status_t, free the csum array if we have one and bail. Note: a possible improvement would be to make the relocation code look up the owning inode and see if it's marked as NODATASUM and set EXTENT_NODATASUM there, that way if there's corruption and there isn't a checksum when we want it we can fail here rather than later. Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file-item.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 91ae1caa1bdb..a68d9cab12ea 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -366,6 +366,7 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; + struct btrfs_bio *bbio = NULL; struct btrfs_path *path; const u32 sectorsize = fs_info->sectorsize; const u32 csum_size = fs_info->csum_size; @@ -375,6 +376,7 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst u8 *csum; const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits; int count = 0; + blk_status_t ret = BLK_STS_OK; if (!fs_info->csum_root || (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) return BLK_STS_OK; @@ -397,7 +399,7 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst return BLK_STS_RESOURCE; if (!dst) { - struct btrfs_bio *bbio = btrfs_bio(bio); + bbio = btrfs_bio(bio); if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) { bbio->csum = kmalloc_array(nblocks, csum_size, GFP_NOFS); @@ -453,21 +455,27 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst count = search_csum_tree(fs_info, path, cur_disk_bytenr, search_len, csum_dst); - if (count <= 0) { - /* - * Either we hit a critical error or we didn't find - * the csum. - * Either way, we put zero into the csums dst, and skip - * to the next sector. - */ + if (count < 0) { + ret = errno_to_blk_status(count); + if (bbio) + btrfs_bio_free_csum(bbio); + break; + } + + /* + * We didn't find a csum for this range. We need to make sure + * we complain loudly about this, because we are not NODATASUM. + * + * However for the DATA_RELOC inode we could potentially be + * relocating data extents for a NODATASUM inode, so the inode + * itself won't be marked with NODATASUM, but the extent we're + * copying is in fact NODATASUM. If we don't find a csum we + * assume this is the case. + */ + if (count == 0) { memset(csum_dst, 0, csum_size); count = 1; - /* - * For data reloc inode, we need to mark the range - * NODATASUM so that balance won't report false csum - * error. - */ if (BTRFS_I(inode)->root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) { u64 file_offset; @@ -488,7 +496,7 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst } btrfs_free_path(path); - return BLK_STS_OK; + return ret; } int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, -- 2.34.1