From patchwork Thu Sep 28 03:36:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9975249 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 B98D8603F2 for ; Thu, 28 Sep 2017 03:36:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA05C2933B for ; Thu, 28 Sep 2017 03:36:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F23029413; Thu, 28 Sep 2017 03:36:34 +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 18E5E2933B for ; Thu, 28 Sep 2017 03:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbdI1Dg0 (ORCPT ); Wed, 27 Sep 2017 23:36:26 -0400 Received: from mout.gmx.net ([212.227.17.21]:51511 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752555AbdI1DgW (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 0MIPhr-1duvJm3wHX-004DFG; Thu, 28 Sep 2017 05:36:18 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 2/5] btrfs: tree-checker: Enhance btrfs_check_node output Date: Thu, 28 Sep 2017 12:36:07 +0900 Message-Id: <20170928033610.16882-3-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:Ljv/h2ovZiIQdRtvF2weMPvqq+5usvYM/TZAWDLiP96Dg3JR4I0 FoMDvtCQv0lLPi3FloJomCgRMbkAEWKVYir/E6gO1dqfh95pW9Cbs2ueSjToURAoxN2luGk uNxgCxse8JrniHAoJXysvTu7v1mLulxTrEEolwwi/VsT0Mc06RaS8IaCLfZmHnMG0VDSI5E 2IAntT7+MRfdseeqDIWbQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:p1HeLQMxx3s=:pylTTDg6nhlUdhBZbIo+C/ t9mrE2Pla4gYWeO2tG3CDAgKm/UkIEdpj8t/dnGGIJbQlRfYIQ1MQdD6fXMOz2HHkAguUMVe8 NeQ2kksWZKFp/0VmzHRdTHn6PaG6nGn0puqU9rHNvQTQfMEDbtnu1dL0QmPQ5xw5uiIH69mQO hil0eTFadBEW8zDXx377rRkvs61mgTAveRBekNCA8CN3YyLYrTOymc0YVJ5A3m0iWB0TVFj61 7RUPA77fH3aIvrshlAEBi7n/dTFXGFKGp1oUfxJuph7EG657FI5I5AMDslhe3+vOtUhUeEp+C jhZoRgH4/jS0kAmiYdZKHHM4XepFJBR4MI3a15H+soh2Te67tiGueWokE2FJ9kRPQxAjxsA+d VloIPQRwz371yHCbHdpG3oMD54vJ1QvENI1kfNQL+QxeRvTlbE1OLc4Y2zEDYfegI8yQGSQD2 DUv6vJDWwGlK+69ybZgmYmVmfqdSESirhO6ttVNkL6/6vnCORHZpRVM+jbi+M3IO4LRB2v+hx LJFmfAAifHkmN7BfR7r9nugf1j00yL0FDkNOQel/H0oNXQmn1+lqwwaDi4PvUGtj0ujZjzeNH Cygzuj85QNS/79Dod8Y6BDiJZUqB5yvP2Ooqapw52yFXZtjPbmd7807sqNXl60J6nukTam8C6 cSqv1Yl1EH460gYfnKAJvDmWpXrIVJkeVx+WmcOToW559+xxAEItbBffzLW5S7WC36bAHHAym 09XHMXPYKx17X79MsqvplL39n74iPTtmyRXmmq0Ej+vVnRbqwsNMxGS4AvvN3u74z+ijUBTi4 uA5K1GNZ3+hpULnhr8KWfV6xsn45w== 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 Use inline function to replace macro since we don't need stringification. (Macro still exist until all caller get updated) And add more info about the error. For nr_items error, report if it's too large or too small, and output valid value range. For blk pointer, added a new alignment checker. For key order, also output the next key to make the problem more obvious. Signed-off-by: Qu Wenruo --- fs/btrfs/tree-checker.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 301243a69dea..4b615beb0ca9 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -37,6 +37,32 @@ btrfs_header_level(eb) == 0 ? "leaf" : "node", \ reason, btrfs_header_bytenr(eb), root->objectid, slot) +/* + * Append the generic "corrupt leaf/node root=%llu block=%llu slot=%d: " to + * @fmt. + * Allowing user to customize their output. + */ +__printf(4, 5) +static void generic_err(const struct btrfs_root *root, + const struct extent_buffer *eb, + int slot, const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + btrfs_crit(root->fs_info, + "corrupt %s root=%llu block=%llu slot=%d: %pV", + btrfs_header_level(eb) == 0 ? "leaf" : "node", + root->objectid, btrfs_header_bytenr(eb), slot, + &vaf); + va_end(args); +} + static int check_extent_data_item(struct btrfs_root *root, struct extent_buffer *leaf, struct btrfs_key *key, int slot) @@ -282,8 +308,10 @@ int btrfs_check_node(struct btrfs_root *root, struct extent_buffer *node) if (nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)) { btrfs_crit(root->fs_info, - "corrupt node: block %llu root %llu nritems %lu", - node->start, root->objectid, nr); + "corrupt node: root=%llu block=%llu nritems too %s, have %lu, range [1,%u]", + root->objectid, node->start, + nr == 0 ? "small" : "large", nr, + BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)); return -EIO; } @@ -293,13 +321,25 @@ int btrfs_check_node(struct btrfs_root *root, struct extent_buffer *node) btrfs_node_key_to_cpu(node, &next_key, slot + 1); if (!bytenr) { - CORRUPT("invalid item slot", node, root, slot); + generic_err(root, node, slot, + "invalid node pointer, shouldn't point to zero"); ret = -EIO; goto out; } + if (!IS_ALIGNED(bytenr, root->fs_info->sectorsize)) { + generic_err(root, node, slot, + "unaligned pointer, have %llu, should be aligned to %u", + bytenr, root->fs_info->sectorsize); + ret = -EUCLEAN; + goto out; + } if (btrfs_comp_cpu_keys(&key, &next_key) >= 0) { - CORRUPT("bad key order", node, root, slot); + generic_err(root, node, slot, + "bad key order, current key (%llu %u %llu) next key (%llu %u %llu)", + key.objectid, key.type, key.offset, + next_key.objectid, next_key.type, + next_key.offset); ret = -EIO; goto out; }