From patchwork Thu Sep 28 03:36:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9975247 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 F35EC603F2 for ; Thu, 28 Sep 2017 03:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E446B2933B for ; Thu, 28 Sep 2017 03:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D927329412; Thu, 28 Sep 2017 03:36:31 +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.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM 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 82F712933B for ; Thu, 28 Sep 2017 03:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752555AbdI1Dg1 (ORCPT ); Wed, 27 Sep 2017 23:36:27 -0400 Received: from mout.gmx.net ([212.227.17.21]:62148 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752545AbdI1DgW (ORCPT ); Wed, 27 Sep 2017 23:36:22 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LjuR3-1dMQ7024ZF-00btpo; Thu, 28 Sep 2017 05:36:20 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 3/5] btrfs: tree-checker: Enhance output for btrfs_check_leaf Date: Thu, 28 Sep 2017 12:36:08 +0900 Message-Id: <20170928033610.16882-4-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170928033610.16882-1-quwenruo.btrfs@gmx.com> References: <20170928033610.16882-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:jQu942oRxEV2jMk6CIUXl2NPcbMxuHS1qxnaK2V26dpRMeazbZt TcC5Ky/8drYpiatDbXVHP/Qh6dH3Z4vM8oxmGSd8WgxA9qCWTdWBY+JkMyIyIMOzmf5pdpp 4Pj9yffinYu+2n6FugxgJ+C0M06YfX1q8JuKCr986dzv5i1vRJaHrNWeQ4mbFk716ALryor t8E4SxJTR6WOsYFRexhbw== X-UI-Out-Filterresults: notjunk:1; V01:K0:PoQtrZvnCIk=:2CMHNwaTgneTnkQeaH6Xz4 rS7Q8ic/Fn++muRFqWliYD5GQdepf95yhorELqVEiCiNlBSA+PSn052J9NDZWWNe/8ohMU/ln XLmLuhHGVKEvObu58T4mLpEDvmSt5bhZKCXMBqJCEjSFVLsgA4lbw4Ld0xYePXqBliYa7OGJk D8JBrNNw1KKfWMmLkcoUHHCbsAFpc5NQvW7AmUqVB6LB3LgfGCmZRe3wn0gkFMK9s5ccw27zS lRqoIe7QQkqqGjQAmLWPH4wqMOTqMlSxk2m1r3WzISaTOzNN3oepPOU3a2uP12dkKcdmBu9en DgdSuFz7Rdwt/QUWEVlj5/rx5tcALdfc7alBMYt8WTRV3s/J4CiXQ+X6Xrqq9RJLf3lDePI/N Aat9B8Dl6a71CCxUxoLml/hCxlPuwtf5kAGaCay3K6DRteLZi9B6hY+302N+PL9Xel1KVLAQo KCYf3qj/bZTgHCV6/IUn1IOvpvcNM3KpRGEvapofk0G0KofgrzjdKDzOhCMK3jnS7WcC5AMpx sAaZG3AZTvNIm3D/bIx7Qm9SAtVsCn5RGHXAyUoZgzQSNXBRhyXmrlrwSLffKexhzpxU77S15 mLxsV1pi014ahRDzAUox5GLRNcc9VD2oGxwP1TmInq7qs3HZZNI2tPF41PkFBL3N70z5tFMhe WvHBq48UvQJh7VQGI2mXmciodaTf3KC7px9zwCokNBdy/JFEPpawTUEWblsmzKEimv++rug+F L3Spz77ukTBk7V06Cc/1hWqjKqaIIPgrgy3aI4IWV24kpuT0C+3vmymuWs3gSgrYWm2q6nvQO w/eco5OOgcLs+4EQTMwojeUQInImA== 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 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 4b615beb0ca9..4f847955fdc6 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -216,8 +216,8 @@ 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, + "non-root leaf's nritems is 0"); free_extent_buffer(eb); return -EUCLEAN; } @@ -248,7 +248,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; } @@ -263,7 +267,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, + "uncontinuous item end, have %u expect %u", + btrfs_item_end_nr(leaf, slot), + item_end_expected); return -EUCLEAN; } @@ -274,14 +281,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; }