From patchwork Mon Oct 9 01:51:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9992099 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 5DFDB602D7 for ; Mon, 9 Oct 2017 01:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53BB928635 for ; Mon, 9 Oct 2017 01:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 483BB28641; Mon, 9 Oct 2017 01:51:29 +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 C476328635 for ; Mon, 9 Oct 2017 01:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751987AbdJIBv0 (ORCPT ); Sun, 8 Oct 2017 21:51:26 -0400 Received: from mout.gmx.net ([212.227.17.20]:60622 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbdJIBvX (ORCPT ); Sun, 8 Oct 2017 21:51:23 -0400 Received: from localhost.localdomain ([104.207.157.105]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MVrQS-1dlvqO33lY-00X1hZ; Mon, 09 Oct 2017 03:51:17 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, nborisov@suse.com Subject: [PATCH v4 3/5] btrfs: tree-checker: Enhance output for btrfs_check_leaf Date: Mon, 9 Oct 2017 01:51:04 +0000 Message-Id: <20171009015106.9711-4-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171009015106.9711-1-quwenruo.btrfs@gmx.com> References: <20171009015106.9711-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:rBkXzH+1CdPuB9ld27WOkqQWcBDWjMb8JL65I9Wiak0c1qcWeg6 tLrlo5xhxMkYPwf11AIe9uzHJA1XUKu81+mHuysvTuWBf1IPgYar7eKz33djDUGAKm6Yver PrlrkYyo7YLTAgopGNdDRGC3XAFKMiJUsc9jfsuAtXProGWAhpkQuVkVSfSlZ3vAEeYk/aF c7y90zj1gNYw0/xMvzvAA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ip20bgc86NM=:iFxRb15w3Ch8+XiZtSvD4U KNzoB1kvHCYRMI88CU9Qng9FG3f63oim/U3/75nIqba5f/SMOVV8wNL68SVc1gK+vMy67mGQB Mx7pUhFvCVlrF+q2jcNZyMWwyQaQyHXV2UB5Li4xA4bEg/wyWQGnaXtltxGNL8zxP8cIjOpkR Go463YphQmn+aaEazU6zRpA9cbvV3oLQDXVGmHWBAveqXQjXrXVkfOYLqZpMsWSMQfSC6+sYQ /3k3pIEksN9hwj3vLyeDtGtzgCcKcsNcDJaJHjp/hWq3QA1DbtqlS57iLMIXYkhy2y7nl1Leo r5RBhjnx0/e9jOy+GkUfow+g8O2pEEufSplbz5FMuNx9xau+Jil3CUOU5klPWyz0AtfkfFW/4 j9Ij8f4t8rBWX8w/xp/VY/narJD0k1+fN54snmiKxXSqNYgmXdRCVs4ReqlQVz7w/FTrHFZB3 vDF7kpr4XbbPFDI2DZ0egPADM5F2TWEx/cBRbMLEba1EiEaKmxmcRMUSTzwqGZYoReSjVDIke aFQZH8xRNdljSNJLT9WBPHfMMYJ6W1VtdL6ZjiO5YdqWa9t1q8MV7jDT6uUCRDwWh4RAsH87w UrJF/jJDjSQLGP+xHt0BFDpCwvmCcmzgo583HEAzsV8VQY+yE47KhkJ5Hhpq67XlIHy0INeG6 LyAu3fLAPkBxY7j5vR+7SiEj6moMAUpxQYtaKVUh5K6laCGLTv7PnB5sZI5+tSV48tF+F1HHz 4S3yQ3CpN4Tb0nNqKoadzrnqYR76NMcGrDHRuv6AdWozQ0/BrETW1AzqRAkhVRsh3v25LV6Nt axU/QoaJYMKXxhXRAWqfQfW4nbJxA== 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 b4ced8d3ce2a..7bba195ecc8b 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -233,8 +233,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; } @@ -265,7 +266,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; } @@ -280,7 +285,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; } @@ -291,14 +299,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; }