From patchwork Tue Feb 27 09:12:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10244545 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 BBEFF60362 for ; Tue, 27 Feb 2018 09:13:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD5612A5CB for ; Tue, 27 Feb 2018 09:13:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1ECD2A5FD; Tue, 27 Feb 2018 09:13:39 +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 38E052A5CB for ; Tue, 27 Feb 2018 09:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752581AbeB0JN1 (ORCPT ); Tue, 27 Feb 2018 04:13:27 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:58236 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752382AbeB0JNO (ORCPT ); Tue, 27 Feb 2018 04:13:14 -0500 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Tue, 27 Feb 2018 02:13:04 -0700 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 2/4] btrfs-progs: check: Fix data csum check return value Date: Tue, 27 Feb 2018 17:12:57 +0800 Message-Id: <20180227091259.10877-3-wqu@suse.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180227091259.10877-1-wqu@suse.com> References: <20180227091259.10877-1-wqu@suse.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 When --check-data-csum option found csum mismatch, btrfs check still return 0. Fix it so log-replay could automatically pause when found csum error. Signed-off-by: Qu Wenruo --- check/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/check/main.c b/check/main.c index f25fdc765d63..15b3c402c9f5 100644 --- a/check/main.c +++ b/check/main.c @@ -5356,6 +5356,13 @@ static int check_space_cache(struct btrfs_root *root) return error ? -EINVAL : 0; } +/* + * Check data checksum for [@bytenr, @bytenr + @num_bytes). + * + * Return <0 for fatal error (fails to read checksum/data or allocate memory). + * Return >0 for csum mismatch for *ANY* copy. + * Return 0 if everything is OK. + */ static int check_extent_csums(struct btrfs_root *root, u64 bytenr, u64 num_bytes, unsigned long leaf_offset, struct extent_buffer *eb) @@ -5373,6 +5380,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr, int ret = 0; int mirror; int num_copies; + bool csum_mismatch = false; if (num_bytes % fs_info->sectorsize) return -EINVAL; @@ -5405,11 +5413,13 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr, tmp / fs_info->sectorsize * csum_size; read_extent_buffer(eb, (char *)&csum_expected, csum_offset, csum_size); - if (csum != csum_expected) + if (csum != csum_expected) { + csum_mismatch = true; fprintf(stderr, "mirror %d bytenr %llu csum %u expected csum %u\n", mirror, bytenr + tmp, csum, csum_expected); + } data_checked += fs_info->sectorsize; } } @@ -5417,6 +5427,8 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr, } out: free(data); + if (!ret && csum_mismatch) + ret = 1; return ret; } @@ -5625,6 +5637,8 @@ static int check_csums(struct btrfs_root *root) */ if (ret < 0) break; + if (ret > 0) + errors++; skip_csum_check: if (!num_bytes) { offset = key.offset;