From patchwork Mon Jan 23 09:13:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9531947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C72F56042F for ; Mon, 23 Jan 2017 09:16:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBEBD205FB for ; Mon, 23 Jan 2017 09:16:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFA402833C; Mon, 23 Jan 2017 09:16:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3043E205FB for ; Mon, 23 Jan 2017 09:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751097AbdAWJQG (ORCPT ); Mon, 23 Jan 2017 04:16:06 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:18859 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750889AbdAWJPN (ORCPT ); Mon, 23 Jan 2017 04:15:13 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="15006282" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Jan 2017 17:14:17 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id AADEF47B1502; Mon, 23 Jan 2017 17:14:17 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 23 Jan 2017 17:14:22 +0800 From: Qu Wenruo To: CC: , , Subject: [PATCH 4/9] btrfs-progs: lowmem check: Fix false alert in checking data extent pointing to prealloc extent Date: Mon, 23 Jan 2017 17:13:53 +0800 Message-ID: <20170123091359.21390-5-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170123091359.21390-1-quwenruo@cn.fujitsu.com> References: <20170123091359.21390-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: AADEF47B1502.A2957 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Btrfs lowmem check can report false csum error like: ERROR: root 5 EXTENT_DATA[257 0] datasum missing ERROR: root 5 EXTENT_DATA[257 4096] prealloc shouldn't have datasum This is because lowmem check code always compare the found csum size with the whole extent which data extents points to. Normally it's OK, but when prealloc extent is written, or reflink is done, data extent can points to part of a larger extent, making the csum check wrong. The fix changes the csum check part to the data extent size, other than the disk_bytenr/disk_num_bytes which points to a larger extent. Reported-by: Chris Murphy Signed-off-by: Qu Wenruo --- cmds-check.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index f158daf9..fd176b76 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -4695,6 +4695,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey, u64 disk_bytenr; u64 disk_num_bytes; u64 extent_num_bytes; + u64 extent_offset; u64 found; unsigned int extent_type; unsigned int is_hole; @@ -4731,17 +4732,28 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey, disk_bytenr = btrfs_file_extent_disk_bytenr(node, fi); disk_num_bytes = btrfs_file_extent_disk_num_bytes(node, fi); extent_num_bytes = btrfs_file_extent_num_bytes(node, fi); + extent_offset = btrfs_file_extent_offset(node, fi); is_hole = (disk_bytenr == 0) && (disk_num_bytes == 0); - /* Check EXTENT_DATA datasum */ - ret = count_csum_range(root, disk_bytenr, disk_num_bytes, &found); + /* + * Check EXTENT_DATA datasum + * + * We should only check the range we're referring to, as it's possible + * that part of prealloc extent has been written, and has csum: + * + * |<------- Original large preallocate extent A -------->| + * |<- Prealloc File Extent ->|<- Regular Extent ->| + * No csum Has csum + */ + ret = count_csum_range(root, disk_bytenr + extent_offset, + extent_num_bytes, &found); if (found > 0 && nodatasum) { err |= ODD_CSUM_ITEM; error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum", root->objectid, fkey->objectid, fkey->offset); } else if (extent_type == BTRFS_FILE_EXTENT_REG && !nodatasum && !is_hole && - (ret < 0 || found == 0 || found < disk_num_bytes)) { + (ret < 0 || found == 0 || found < extent_num_bytes)) { err |= CSUM_ITEM_MISSING; error("root %llu EXTENT_DATA[%llu %llu] datasum missing", root->objectid, fkey->objectid, fkey->offset);