Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp755295pxb; Tue, 5 Apr 2022 21:56:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQshoG1JWwO1Sw7FEdsMyQWb3alM2aPqfylQBKqp70OGDwY745CXsyL2BDxdUxUiIIIcjp X-Received: by 2002:a05:6a00:10cc:b0:4fe:3f1c:2d1 with SMTP id d12-20020a056a0010cc00b004fe3f1c02d1mr7287861pfu.0.1649220965350; Tue, 05 Apr 2022 21:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649220965; cv=none; d=google.com; s=arc-20160816; b=oED2ZA093hARXzpgK0Xd13mY7rSCwNC8pHXHMXb9CSyGdW1XqsAVuE203EGlA/qJUn Focqf8EIRPuXW0X3w8FpYaheO3oBQyg4dsJDFjOrtYoMU7JyxlkrAquNe2P8vNeXEU3x uelXDNRT4BnmPoDT4Yg2tWdxvtOocWQw+F4aabfQkewd1gvdEQ6N+vhOd0ThUIA6BwQ0 rm7ogymOmCj9Qc89HDibbnICgMcbt26uUfdH6PYK5c4QlYK0YTch+1hQVPX1A18v8j1e wGhEBrb70PTYwO0mZL28A4jQPkmVqnaCacHvPYLuOc+hoDsIMGdyZlnnb5s0hFhkSIJT XsRQ== 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=jbhcGJkgUAaxo6kuPUfIWLdGoMktyr23AnJSX6qyTqU=; b=YoVqsNDrXCGDnXevDhRCD9tabU5MNGktGKBTCNmxbQyHDc1TXgvf0BQfNjnx24UAg8 2Nr/YtUK9jtc72mleVLbME/W3kfBI897E/e25o9Exd07O4XXktUTnEaxBvqrok44M5SB 2rIo/01ag852NFyy2cwtkONBHTWdi6cNZkrOT4+i5LNXcsy2dCvFwQihe7vCJVjkPtbJ 3BAx5di/MDpKbIP5Vray7l7arI1f5e4wxPJTvGp3vzlcnjDWGdyw0kmDKCH8J14tgX+Z WnrXw99oCrhWDu4+y6PrpNtVb+jlMX/7mPN02KdkfKg2sXxqzFOE9sLMhjeckAlKlrlx kNXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xwl2beqE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l3-20020a63ba43000000b00382b21d7ab8si15121993pgu.761.2022.04.05.21.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:56:05 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xwl2beqE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 147F3D3733; Tue, 5 Apr 2022 20:16:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352342AbiDEKE2 (ORCPT + 99 others); Tue, 5 Apr 2022 06:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237375AbiDEI3S (ORCPT ); Tue, 5 Apr 2022 04:29:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6139E1A077; Tue, 5 Apr 2022 01:21:18 -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 B134A60FF5; Tue, 5 Apr 2022 08:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA89CC385A0; Tue, 5 Apr 2022 08:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146877; bh=3YRw8iYUHTrJPyUg6ycWpIr1pqDiLYZGPxuK8HPfmRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xwl2beqEF/B7u5RaQFEsRb1YjJ1Pt9QVqe3CyVgGAvDr7hxeElh1PN7VY88mw5fBs J8BXmdDjDYZoA3121nRqBC0NlHiyZVMDIwx27sRySx0yeQSN87bq6YU9MgUqJGUzQV UEsUSecjelFrtB0APxS2oFU3hCWhm3BeFQyxlTBQ= 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.17 0882/1126] btrfs: handle csum lookup errors properly on reads Date: Tue, 5 Apr 2022 09:27:09 +0200 Message-Id: <20220405070433.421300388@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 435c895015a2..77c8f298f52e 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -368,6 +368,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; @@ -377,6 +378,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 ((BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) || test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)) @@ -400,7 +402,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); @@ -456,21 +458,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; @@ -491,7 +499,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