From patchwork Fri Sep 29 06:48:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9977133 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 6E65960365 for ; Fri, 29 Sep 2017 06:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61C01297E1 for ; Fri, 29 Sep 2017 06:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56961297E8; Fri, 29 Sep 2017 06:49:40 +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,FREEMAIL_FROM, 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 E6345297E1 for ; Fri, 29 Sep 2017 06:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752030AbdI2Gtf (ORCPT ); Fri, 29 Sep 2017 02:49:35 -0400 Received: from mout.gmx.net ([212.227.17.20]:65150 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751037AbdI2Gtd (ORCPT ); Fri, 29 Sep 2017 02:49:33 -0400 Received: from localhost.localdomain ([104.207.157.105]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LvQkh-1dFrZK20Sh-010Z96; Fri, 29 Sep 2017 08:48:57 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, nborisov@suse.com Subject: [PATCH v3 3/5] btrfs: tree-checker: Enhance output for btrfs_check_leaf Date: Fri, 29 Sep 2017 06:48:47 +0000 Message-Id: <20170929064849.15086-4-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20170929064849.15086-1-quwenruo.btrfs@gmx.com> References: <20170929064849.15086-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:T9Ue7L2iMORC9Pqe6AcB2XdpORoV7DGsOB4m9Gx9zIAXQSlG5yW J2cLEF+YndnuZ7/Vlj3rfHZOE/uzyx+JC1XGH6lQ9ehUGIIVFACpee0G7fMzyb1xw9AAncK Y2+4rr/il2/OTwA1RedjHuMki9XDxHFNSi98zS6P+Ed6cLYzYL8j174fyl7HDQzX2r3FZqs 83/rIMEwpaR9bYG8UWItA== X-UI-Out-Filterresults: notjunk:1; V01:K0:NmmNM7YYZiE=:yy0OsPmZ3LK4uegCAvLO1w vuL5xc2TxJUh+BouXDFp8r49K3A0LoLEb1wNtxUhOMUISDoSRmxaW9Lu0QE01un8FSFWIpgE6 YZ+K5z8HV0Hm+5/pNxhuGMWCpdYDViZt0YqgbS9HGVcAo0rJ+JjuVPVhRq0bKq8+MLC3A064i xDXqPZlaGDCSfXM4r8AeDwLlf06QEOhBscEgdGD0bi/rYOXOZqZfMqtzxCpvTCz276s2ja9it Dkd+KQoXYcet1VcWp9nQ4eGY5JtWaM+HPs2w5hkm2Yldgmo6aoL8mCJRyPGGgyY9ddbBbCHeP eCFZlapMYy7YK47zsKBYw1VF1gmPuCnKwCqUag6OgxlB0WAwU4F5vUBIL/vieHALHh1blzJjv E+dlte9FRpJbiAe3ubIZ3MJLd3Ph3xKBg71v5tOBYE6Xk42r0pDo9kqjCGwkQoDr/pI4vNb5v s4IbFzW5y6xS11XhZy3XKzCispAhO4Pi3bHdCzkm5CSx6QQVkXcOFfFZTu74sG3vbRkg9kZPS pgv9hRs09zPijX1rwoUAjm4tMqxZgYpCSSMJkfAEyV/9OltLejGQf3RSpFynK34Ikd4DGErS3 kxFKYvTQpS5sDb4UlZZ37OGsrTtP25644OWni097zYmM1tmaI2a+deZyxfGOGKRTd85PeyWrp ZkB1jdXJIvCQ0zRSvW85M+JyC0gOpfC9pEhkNzbdH8t5mr0N4ZEQdwpedlZYUcxwY/11A0d18 XBa/Ygu8RvBHgQNhFDlj5vwJb0PjxY99h5Z3w+8LnOEGNUUBedb5q406F9Q0CqKVK2AKnXHbM QMviQ491EvJP+tCGvD8UG/dqwT/TQ== 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 Enhance the output to print: 1) Reason 2) Bad value If reason can't explain enough 3) Good value (range) Signed-off-by: Qu Wenruo --- fs/btrfs/tree-checker.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 94acf3f5d6fd..183ff7faa218 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -232,8 +232,9 @@ int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf) eb = btrfs_root_node(check_root); /* if leaf is the root, then it's fine */ if (leaf != eb) { - CORRUPT("non-root leaf's nritems is 0", - leaf, check_root, 0); + generic_err(check_root, leaf, 0, + "invalid nritems, have %u shouldn't be 0 for non-root leaf", + nritems); free_extent_buffer(eb); return -EUCLEAN; } @@ -264,7 +265,11 @@ int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf) /* Make sure the keys are in the right order */ if (btrfs_comp_cpu_keys(&prev_key, &key) >= 0) { - CORRUPT("bad key order", leaf, root, slot); + generic_err(root, leaf, slot, + "bad key order, prev key (%llu %u %llu) current key (%llu %u %llu)", + prev_key.objectid, prev_key.type, + prev_key.offset, key.objectid, key.type, + key.offset); return -EUCLEAN; } @@ -279,7 +284,10 @@ int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf) item_end_expected = btrfs_item_offset_nr(leaf, slot - 1); if (btrfs_item_end_nr(leaf, slot) != item_end_expected) { - CORRUPT("slot offset bad", leaf, root, slot); + generic_err(root, leaf, slot, + "discontinious item end, have %u expect %u", + btrfs_item_end_nr(leaf, slot), + item_end_expected); return -EUCLEAN; } @@ -290,14 +298,21 @@ int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf) */ if (btrfs_item_end_nr(leaf, slot) > BTRFS_LEAF_DATA_SIZE(fs_info)) { - CORRUPT("slot end outside of leaf", leaf, root, slot); + generic_err(root, leaf, slot, + "slot end outside of leaf, have %u expect range [0, %u]", + btrfs_item_end_nr(leaf, slot), + BTRFS_LEAF_DATA_SIZE(fs_info)); return -EUCLEAN; } /* Also check if the item pointer overlaps with btrfs item. */ if (btrfs_item_nr_offset(slot) + sizeof(struct btrfs_item) > btrfs_item_ptr_offset(leaf, slot)) { - CORRUPT("slot overlap with its data", leaf, root, slot); + generic_err(root, leaf, slot, + "slot overlap with its data, item end %lu data start %lu", + btrfs_item_nr_offset(slot) + + sizeof(struct btrfs_item), + btrfs_item_ptr_offset(leaf, slot)); return -EUCLEAN; }