From patchwork Fri Sep 29 01:37:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9977003 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 0007060365 for ; Fri, 29 Sep 2017 01:37:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6C7E297AF for ; Fri, 29 Sep 2017 01:37:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBADA297B1; Fri, 29 Sep 2017 01:37:28 +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 8B6DE297AF for ; Fri, 29 Sep 2017 01:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbdI2BhW (ORCPT ); Thu, 28 Sep 2017 21:37:22 -0400 Received: from mout.gmx.net ([212.227.17.21]:60454 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbdI2BhV (ORCPT ); Thu, 28 Sep 2017 21:37:21 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M0LtB-1d3JdF1GVJ-00uYcp; Fri, 29 Sep 2017 03:37:13 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, nborisov@suse.com Subject: [PATCH v2 3/5] btrfs: tree-checker: Enhance output for btrfs_check_leaf Date: Fri, 29 Sep 2017 10:37:00 +0900 Message-Id: <20170929013702.17814-4-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170929013702.17814-1-quwenruo.btrfs@gmx.com> References: <20170929013702.17814-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:lAfP0GpcX4wFzz84lSF0vERwtKLcL7zBkQnnebEkFs1iPLyti/c vuGD4NMJqUsGPaY7WzIy60Ipd2EJookPbWKGkoo816zGTr+wP8dguWS6xUMO+fapUZd8yFo iC9qNL54ZcmHPL0A4JSaSed8ZXc5gCtNFPCtgoB+IZnaSkN+6c9YPf/Uzp2bOl6EMhi/ppT gvBN5psMCj4A78aptgM/A== X-UI-Out-Filterresults: notjunk:1; V01:K0:bkA30TBXBwA=:5tiU0pCCpTeLQXlXBqHk+1 dz2sZVSWUs59m3l9omJHTQScpuNEytnC+/lsoIu1BSjJL6MzSGX0GMZIRoO0Mn2Ct0NCBR9+1 oUYebio//dj7P9FU/W5LrSuMzWruWJtndgWXJJ0zvuJRFZY4wk1YKDBpDMobD9zeJvbfGvQ1W nLQRnhuoBIQuZNqeFWcOlmfW6ngvuKvrgw0lFo3WTrTUEEN/G2/g/B+pA85T+3F0C6sL+BAdg kz2sd7qSvBF0bD3XQOsJ4qHu14zwqx4cDy5bx+bHOaZgf9uaK7Q/dMp3qkicA8G+XcOg4Xaml ACExNbHfgq6dGD2P8UCiP9o0U8ooUvGbi14NDuXKp9/4Cjw6kOR+bscfBcS3uYZdMV9uAm3X+ fHh39kEoL5+5YWCcGd4nkfiO15Yzd69nmehMfJtEzBhh9/3ItyZ7xp0hVplPbwBDEmnGPYHJj UOr1tz+flfT4auNdYFF/HvglDo+W12P419ZWg3ss0gF175Qp0+p3oQBmzib/MPEanD18BiYiy 9Gtu5Y7ArDtIH6hEAquKSa/GR5wQ8d+M/xoWqAdvQcoAkrsumll/T160kFDP4hHflK2DQpC6u Md/2y/thEb6g/lxOX4+bjY8wPtgA0WyfKipSTPNjDv+46Uxo+57QuPv95B1GmMcRKHNGbNRzi txx1Ul3nraCZ2SR4IsjI1aP0AAwhWYZE2aUEDZp5AhL5rS63VWHDjwk2MEhAZiJ7h/+G+lXEF 9GK8bK6Md+xsjXRr24+9QrnSvZ367lf25B1MpJgiauF5Am0eJDb+Pr/y1VRkz606LzsHTIEjh /hO9OWIBT4/8tCqEZ2L6A7F3re2Dg== 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 a51f2503acc4..94027f4215e9 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; }